Skip to content

Commit e74ef85

Browse files
committed
fix(parser,decompiler): 修正
- テーブルセル内のline-breakに不要な_preservedTrailingBreakフラグを設定しない - デコンパイラで末尾line-breakの改行を保持し、正しいroundtripを実現
1 parent ec00ed0 commit e74ef85

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

packages/decompiler/src/serializer/table.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,18 @@ export function serializeTable(ctx: SerializeContext, data: TableData): void {
3434
const innerCtx = new SerializeContext({ newline: ctx.newline });
3535
innerCtx.forceLineBreakSyntax = true;
3636
serializeElements(innerCtx, cell.elements);
37-
const content = innerCtx.getOutput().replace(/\n$/, "");
37+
const raw = innerCtx.getOutput();
38+
const content = raw.replace(/\n$/, "");
3839

39-
ctx.push(`${prefix} ${content} `);
40+
// When content ends with ` _` (from a trailing line-break that was
41+
// serialised as ` _\n`), preserve the newline so the closing `||`
42+
// appears on the next line — otherwise the parser sees literal `_`.
43+
const nl = ctx.newline;
44+
if (raw.endsWith(` _${nl}`)) {
45+
ctx.push(`${prefix} ${content}${nl}`);
46+
} else {
47+
ctx.push(`${prefix} ${content} `);
48+
}
4049
}
4150
ctx.pushLine("||");
4251
}

packages/parser/src/parser/rules/block/table.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,7 @@ function parseTableCell(
332332
afterTok &&
333333
(afterTok.type === "NEWLINE" || afterTok.type === "EOF")
334334
) {
335-
const lb: Element & { _preservedTrailingBreak?: boolean } = { element: "line-break" };
336-
lb._preservedTrailingBreak = true;
337-
children.push(lb);
335+
children.push({ element: "line-break" });
338336
pos += 3;
339337
consumed += 3;
340338
continue;

tests/fixtures/table/line-break/expected.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,7 @@
669669
"data": ""
670670
},
671671
{
672-
"element": "line-break",
673-
"_preservedTrailingBreak": true
672+
"element": "line-break"
674673
},
675674
{
676675
"element": "text",

0 commit comments

Comments
 (0)