Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser/syntaxes/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ function parseAtom(s: ITokenStream, isStatic: boolean): Ast.Expression {
return expr;
}
case TokenKind.Sharp: {
if (isStatic) break;
return parseExprWithLabel(s);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/aison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 11 additions & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
10 changes: 9 additions & 1 deletion test/syntax.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -1115,6 +1115,14 @@ describe('meta', () => {
assert.fail();
});
});

describe('Labeled expression', () => {
test.concurrent('invalid', async () => {
expect(() => getMeta(`
### x #label: eval { 1 }
`)).toThrow();
});
});
});

describe('namespace', () => {
Expand Down
1 change: 1 addition & 0 deletions unreleased/fix-labeled-exprs-are-allowed-in-static-expr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix: メタデータ構文や属性、AiSONにラベル付きの式を記述してもエラーが発生しない問題を修正
Loading