From 232d05080dbca7729b65d7903d320398e88af219 Mon Sep 17 00:00:00 2001 From: uzmoi Date: Sun, 5 May 2024 12:38:42 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BD=8D=E7=BD=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/parser.peggy | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/parser/parser.peggy b/src/parser/parser.peggy index 4aacdbeb..7a95e63e 100644 --- a/src/parser/parser.peggy +++ b/src/parser/parser.peggy @@ -28,9 +28,8 @@ PreprocessPart / . Comment - = "//" (!EOL .)* { return ''; } - / "/*" (!"*/" .)* "*/" { return ''; } - + = "//" (!EOL .)* { return ' '.repeat(text().length); } + / "/*" (!"*/" .)* "*/" { return text().replace(/[^\n]/g, ' '); } // // main parser From ce9fec1bdd4466cb8dc5df5132058fc72c69f79f Mon Sep 17 00:00:00 2001 From: uzmoi Date: Sun, 5 May 2024 12:39:06 +0900 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65c55b48..5ef6934a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # 未リリース分 - `Date:year`系の関数に0を渡すと現在時刻になる問題を修正 +- シンタックスエラーなどの位置情報を修正 # 0.18.0 - `Core:abort`でプログラムを緊急停止できるように @@ -128,4 +129,4 @@ - 空の関数を定義できない問題を修正 - 空のスクリプトが許可されていない問題を修正 - ネームスペース付き変数のインクリメント、デクリメントを修正 -- ネームスペース付き変数への代入ができない問題を修正 +- ネームスペース付き変数への代入ができない問題を修正 From 7ae0774b5b9ce998467bc98fb04aba4e23e994e2 Mon Sep 17 00:00:00 2001 From: uzmoi Date: Sun, 5 May 2024 12:41:59 +0900 Subject: [PATCH 3/3] add test for location --- test/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/index.ts b/test/index.ts index 29873c4c..fed26c01 100644 --- a/test/index.ts +++ b/test/index.ts @@ -2399,6 +2399,20 @@ describe('Location', () => { if (!node.loc) assert.fail(); assert.deepEqual(node.loc, { start: 3, end: 13 }); }); + test.concurrent('comment', async () => { + let node: Ast.Node; + const parser = new Parser(); + const nodes = parser.parse(` + /* + */ + // hoge + @f(a) { a } + `); + assert.equal(nodes.length, 1); + node = nodes[0]; + if (!node.loc) assert.fail(); + assert.deepEqual(node.loc, { start: 23, end: 33 }); + }); }); describe('Variable declaration', () => {