From ec611e7686fb2d6451cdd0b45f3e74aa01971e41 Mon Sep 17 00:00:00 2001 From: takejohn Date: Fri, 5 Dec 2025 16:04:04 +0900 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E7=9A=84=E3=81=AA=E5=BC=8F=E3=81=8C?= =?UTF-8?q?=E3=83=A9=E3=83=99=E3=83=AB=E4=BB=98=E3=81=8D=E3=81=AE=E5=BC=8F?= =?UTF-8?q?=E3=82=92=E8=A8=B1=E5=AE=B9=E3=81=99=E3=82=8B=E5=95=8F=E9=A1=8C?= =?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/syntaxes/expressions.ts | 1 + test/aison.ts | 4 ++++ test/index.ts | 12 +++++++++++- test/syntax.ts | 10 +++++++++- .../fix-labeled-exprs-are-allowed-in-static-expr.md | 1 + 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 unreleased/fix-labeled-exprs-are-allowed-in-static-expr.md diff --git a/src/parser/syntaxes/expressions.ts b/src/parser/syntaxes/expressions.ts index 48b76b36..f0a96cb5 100644 --- a/src/parser/syntaxes/expressions.ts +++ b/src/parser/syntaxes/expressions.ts @@ -288,6 +288,7 @@ function parseAtom(s: ITokenStream, isStatic: boolean): Ast.Expression { return expr; } case TokenKind.Sharp: { + if (isStatic) break; return parseExprWithLabel(s); } } diff --git a/test/aison.ts b/test/aison.ts index f4d71aff..d6fd38df 100644 --- a/test/aison.ts +++ b/test/aison.ts @@ -62,6 +62,10 @@ greet()`)).toThrow(); expect(() => AiSON.parse('{key: (3 + 5)}')).toThrow(); }); + test.concurrent('not allowed: labeled expression', () => { + expect(() => AiSON.parse('#label: eval { 1 }')).toThrow(); + }); + test.concurrent('not allowed: multiple statements (string)', () => { expect(() => AiSON.parse(`"hello" diff --git a/test/index.ts b/test/index.ts index b94fd9ac..ed7a819d 100644 --- a/test/index.ts +++ b/test/index.ts @@ -4,7 +4,7 @@ */ import * as assert from 'assert'; -import { describe, test } from 'vitest'; +import { describe, expect, test } from 'vitest'; import { Parser, Interpreter, Ast } from '../src'; import { NUM, STR, NULL, ARR, OBJ, BOOL, TRUE, FALSE, ERROR ,FN_NATIVE } from '../src/interpreter/value'; import { AiScriptSyntaxError, AiScriptRuntimeError, AiScriptIndexOutOfRangeError } from '../src/error'; @@ -948,6 +948,16 @@ describe('Attribute', () => { const attr = member.attr[0]; assert.equal(attr.name, 'test'); }); + + test.concurrent('non-static expression is not allowed', async () => { + const parser = new Parser(); + expect(() => { + parser.parse(` + #[x #label: eval { 1 }] + @f() {} + `); + }).toThrow(); + }); }); describe('Location', () => { diff --git a/test/syntax.ts b/test/syntax.ts index 628dd6cf..72dcf190 100644 --- a/test/syntax.ts +++ b/test/syntax.ts @@ -1,5 +1,5 @@ import * as assert from 'assert'; -import { describe, test } from 'vitest'; +import { describe, expect, test } from 'vitest'; import { utils } from '../src'; import { NUM, STR, NULL, ARR, OBJ, BOOL, TRUE, FALSE, ERROR ,FN_NATIVE } from '../src/interpreter/value'; import { AiScriptRuntimeError, AiScriptUnexpectedEOFError } from '../src/error'; @@ -1115,6 +1115,14 @@ describe('meta', () => { assert.fail(); }); }); + + describe('Labeled expression', () => { + test.concurrent('invalid', async () => { + expect(() => getMeta(` + ### x #label: eval { 1 } + `)).toThrow(); + }); + }); }); describe('namespace', () => { diff --git a/unreleased/fix-labeled-exprs-are-allowed-in-static-expr.md b/unreleased/fix-labeled-exprs-are-allowed-in-static-expr.md new file mode 100644 index 00000000..cf24942a --- /dev/null +++ b/unreleased/fix-labeled-exprs-are-allowed-in-static-expr.md @@ -0,0 +1 @@ +- Fix: メタデータ構文や属性、AiSONにラベル付きの式を記述してもエラーが発生しない問題を修正