Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/parser/syntaxes/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ function parseObject(s: ITokenStream, isStatic: boolean): Ast.Obj {
const map = new Map<string, Ast.Expression>();
while (!s.is(TokenKind.CloseBrace)) {
const k = parseObjectKey(s);
if (map.has(k)) {
throw new AiScriptSyntaxError(`Key ${k} is duplicated.`, s.getPos());
}
s.next();

s.expect(TokenKind.Colon);
Expand Down
6 changes: 6 additions & 0 deletions test/literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ describe('literal', () => {
`)).rejects.toThrow(AiScriptSyntaxError);
})

test.concurrent('obj (duplicate key)', async () => {
await expect(() => exe(`
<: { hoge: 1, hoge: 2 }
`)).rejects.toThrow(AiScriptSyntaxError);
});

test.concurrent('obj (invalid key)', async () => {
assert.rejects(() => exe(`
<: {
Expand Down
1 change: 1 addition & 0 deletions unreleased/dupe-key-to-syntax-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix: オブジェクトリテラルでキーの重複がエラーになるように修正
Loading