File tree Expand file tree Collapse file tree 5 files changed +64
-95
lines changed Expand file tree Collapse file tree 5 files changed +64
-95
lines changed Original file line number Diff line number Diff line change 3
3
import { isIdentifierStart , isIdentifierChar } from 'acorn' ;
4
4
import fragment from './state/fragment.js' ;
5
5
import { regex_whitespace } from '../patterns.js' ;
6
- import { reserved } from '../../../constants.js' ;
7
6
import full_char_code_at from './utils/full_char_code_at.js' ;
8
7
import * as e from '../../errors.js' ;
9
8
import { create_fragment } from './utils/create.js' ;
10
9
import read_options from './read/options.js' ;
10
+ import { is_reserved } from '../../../utils.js' ;
11
11
12
12
const regex_position_indicator = / \( \d + : \d + \) $ / ;
13
13
@@ -219,7 +219,7 @@ export class Parser {
219
219
220
220
const identifier = this . template . slice ( this . index , ( this . index = i ) ) ;
221
221
222
- if ( ! allow_reserved && reserved . includes ( identifier ) ) {
222
+ if ( ! allow_reserved && is_reserved ( identifier ) ) {
223
223
e . unexpected_reserved_word ( start , identifier ) ;
224
224
}
225
225
Original file line number Diff line number Diff line change @@ -188,43 +188,3 @@ export const EventModifiers = [
188
188
'self' ,
189
189
'trusted'
190
190
] ;
191
-
192
- export const JsKeywords = [
193
- 'class' ,
194
- 'break' ,
195
- 'const' ,
196
- 'let' ,
197
- 'var' ,
198
- 'continue' ,
199
- 'if' ,
200
- 'for' ,
201
- 'while' ,
202
- 'do' ,
203
- 'new' ,
204
- 'static' ,
205
- 'true' ,
206
- 'false' ,
207
- 'void' ,
208
- 'with' ,
209
- 'yield' ,
210
- 'await' ,
211
- 'typeof' ,
212
- 'throw' ,
213
- 'throws' ,
214
- 'null' ,
215
- 'delete' ,
216
- 'default' ,
217
- 'catch' ,
218
- 'debugger' ,
219
- 'case' ,
220
- 'arguments' ,
221
- 'else' ,
222
- 'extends' ,
223
- 'export' ,
224
- 'import' ,
225
- 'extends' ,
226
- 'switch' ,
227
- 'instanceof' ,
228
- 'return' ,
229
- 'this'
230
- ] ;
Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ import {
12
12
object ,
13
13
unwrap_pattern
14
14
} from '../utils/ast.js' ;
15
- import { JsKeywords , Runes } from './constants.js' ;
15
+ import { Runes } from './constants.js' ;
16
+ import { is_reserved } from '../../utils.js' ;
16
17
17
18
export class Scope {
18
19
/** @type {ScopeRoot } */
@@ -148,7 +149,7 @@ export class Scope {
148
149
this . references . has ( name ) ||
149
150
this . declarations . has ( name ) ||
150
151
this . root . conflicts . has ( name ) ||
151
- JsKeywords . includes ( name )
152
+ is_reserved ( name )
152
153
) {
153
154
name = `${ preferred_name } _${ n ++ } ` ;
154
155
}
Original file line number Diff line number Diff line change @@ -129,57 +129,6 @@ export function is_capture_event(name, mode = 'exclude-on') {
129
129
: name !== 'ongotpointercapture' && name !== 'onlostpointercapture' ;
130
130
}
131
131
132
- export const reserved = [
133
- 'arguments' ,
134
- 'await' ,
135
- 'break' ,
136
- 'case' ,
137
- 'catch' ,
138
- 'class' ,
139
- 'const' ,
140
- 'continue' ,
141
- 'debugger' ,
142
- 'default' ,
143
- 'delete' ,
144
- 'do' ,
145
- 'else' ,
146
- 'enum' ,
147
- 'eval' ,
148
- 'export' ,
149
- 'extends' ,
150
- 'false' ,
151
- 'finally' ,
152
- 'for' ,
153
- 'function' ,
154
- 'if' ,
155
- 'implements' ,
156
- 'import' ,
157
- 'in' ,
158
- 'instanceof' ,
159
- 'interface' ,
160
- 'let' ,
161
- 'new' ,
162
- 'null' ,
163
- 'package' ,
164
- 'private' ,
165
- 'protected' ,
166
- 'public' ,
167
- 'return' ,
168
- 'static' ,
169
- 'super' ,
170
- 'switch' ,
171
- 'this' ,
172
- 'throw' ,
173
- 'true' ,
174
- 'try' ,
175
- 'typeof' ,
176
- 'var' ,
177
- 'void' ,
178
- 'while' ,
179
- 'with' ,
180
- 'yield'
181
- ] ;
182
-
183
132
// we use a list of ignorable runtime warnings because not every runtime warning
184
133
// can be ignored and we want to keep the validation for svelte-ignore in place
185
134
export const IGNORABLE_RUNTIME_WARNINGS = /** @type {const } */ ( [
Original file line number Diff line number Diff line change @@ -39,3 +39,62 @@ const VOID_ELEMENT_NAMES = [
39
39
export function is_void ( name ) {
40
40
return VOID_ELEMENT_NAMES . includes ( name ) || name . toLowerCase ( ) === '!doctype' ;
41
41
}
42
+
43
+ const RESERVED_WORDS = [
44
+ 'arguments' ,
45
+ 'await' ,
46
+ 'break' ,
47
+ 'case' ,
48
+ 'catch' ,
49
+ 'class' ,
50
+ 'const' ,
51
+ 'continue' ,
52
+ 'debugger' ,
53
+ 'default' ,
54
+ 'delete' ,
55
+ 'do' ,
56
+ 'else' ,
57
+ 'enum' ,
58
+ 'eval' ,
59
+ 'export' ,
60
+ 'extends' ,
61
+ 'false' ,
62
+ 'finally' ,
63
+ 'for' ,
64
+ 'function' ,
65
+ 'if' ,
66
+ 'implements' ,
67
+ 'import' ,
68
+ 'in' ,
69
+ 'instanceof' ,
70
+ 'interface' ,
71
+ 'let' ,
72
+ 'new' ,
73
+ 'null' ,
74
+ 'package' ,
75
+ 'private' ,
76
+ 'protected' ,
77
+ 'public' ,
78
+ 'return' ,
79
+ 'static' ,
80
+ 'super' ,
81
+ 'switch' ,
82
+ 'this' ,
83
+ 'throw' ,
84
+ 'true' ,
85
+ 'try' ,
86
+ 'typeof' ,
87
+ 'var' ,
88
+ 'void' ,
89
+ 'while' ,
90
+ 'with' ,
91
+ 'yield'
92
+ ] ;
93
+
94
+ /**
95
+ * Returns `true` if `word` is a reserved JavaScript keyword
96
+ * @param {string } word
97
+ */
98
+ export function is_reserved ( word ) {
99
+ return RESERVED_WORDS . includes ( word ) ;
100
+ }
You can’t perform that action at this time.
0 commit comments