Skip to content

Commit

Permalink
feat:テンプレート埋め込み式先頭・末尾の改行を許容 (#848)
Browse files Browse the repository at this point in the history
* テンプレート埋め込み式先頭・末尾の改行を許容

* CHANGELOGの表現を変更
  • Loading branch information
takejohn authored Nov 15, 2024
1 parent dff363b commit 87e8edc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/parser/syntaxes/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ function parseAtom(s: ITokenStream, isStatic: boolean): Ast.Expression {
case TokenKind.TemplateExprElement: {
// スキャナで埋め込み式として事前に読み取っておいたトークン列をパースする
const exprStream: ITokenStream = new TokenStream(element.children!);
if (exprStream.is(TokenKind.NewLine)) {
exprStream.next();
}
const expr = parseExpr(exprStream, false);
if (exprStream.is(TokenKind.NewLine)) {
exprStream.next();
}
exprStream.expect(TokenKind.EOF);
values.push(expr);
break;
Expand Down
18 changes: 18 additions & 0 deletions test/literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,23 @@ describe('Template syntax', () => {
`);
eq(res, STR('1'));
});

test.concurrent('new line before', async () => {
const res = await exe(`
<: \`{"Hello"
// comment
}\`
`);
eq(res, STR('Hello'));
});

test.concurrent('new line after', async () => {
const res = await exe(`
<: \`{
// comment
"Hello"}\`
`);
eq(res, STR('Hello'));
});
});

1 change: 1 addition & 0 deletions unreleased/new-lines-in-template-expression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- テンプレートリテラル内に埋め込まれた式の先頭および末尾の改行が許容されるようになりました。

0 comments on commit 87e8edc

Please sign in to comment.