Skip to content

Commit b47dcfe

Browse files
committed
使用中、使用予定の予約語のエラーを共通に
1 parent c8dc631 commit b47dcfe

1 file changed

Lines changed: 26 additions & 29 deletions

File tree

src/parser/plugins/validate-keyword.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ import type * as Ast from '../../node.js';
77
// - 文脈キーワードは識別子に利用できるため除外
88

99
const reservedWord = [
10+
// 使用中の語
11+
'null',
12+
'true',
13+
'false',
14+
'each',
15+
'for',
16+
'loop',
17+
'do',
18+
'while',
19+
'break',
20+
'continue',
21+
'match',
22+
'case',
23+
'default',
24+
'if',
25+
'elif',
26+
'else',
27+
'return',
28+
'eval',
29+
'var',
30+
'let',
31+
'exists',
32+
33+
// 使用予定の語
1034
'as',
1135
'async',
1236
'attr',
@@ -52,36 +76,9 @@ const reservedWord = [
5276
'new',
5377
];
5478

55-
const keywords = [
56-
'null',
57-
'true',
58-
'false',
59-
'each',
60-
'for',
61-
'loop',
62-
'do',
63-
'while',
64-
'break',
65-
'continue',
66-
'match',
67-
'case',
68-
'default',
69-
'if',
70-
'elif',
71-
'else',
72-
'return',
73-
'eval',
74-
'var',
75-
'let',
76-
'exists',
77-
];
78-
7979
function validateName(name: string, pos: Ast.Pos): void {
8080
if (reservedWord.includes(name)) {
81-
throw new AiScriptSyntaxError(`Reserved word "${name}" cannot be used as identifier.`, pos);
82-
}
83-
if (keywords.includes(name)) {
84-
throw new AiScriptSyntaxError(`Keyword "${name}" cannot be used as identifier.`, pos);
81+
throwReservedWordError(name, pos);
8582
}
8683
}
8784

@@ -92,7 +89,7 @@ function validateTypeName(name: string, pos: Ast.Pos): void {
9289
validateName(name, pos);
9390
}
9491

95-
function throwReservedWordError(name: string, pos: Ast.Pos): void {
92+
function throwReservedWordError(name: string, pos: Ast.Pos): never {
9693
throw new AiScriptSyntaxError(`Reserved word "${name}" cannot be used as variable name.`, pos);
9794
}
9895

0 commit comments

Comments
 (0)