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 33import { isIdentifierStart , isIdentifierChar } from 'acorn' ;
44import fragment from './state/fragment.js' ;
55import { regex_whitespace } from '../patterns.js' ;
6- import { reserved } from '../../../constants.js' ;
76import full_char_code_at from './utils/full_char_code_at.js' ;
87import * as e from '../../errors.js' ;
98import { create_fragment } from './utils/create.js' ;
109import read_options from './read/options.js' ;
10+ import { is_reserved } from '../../../utils.js' ;
1111
1212const regex_position_indicator = / \( \d + : \d + \) $ / ;
1313
@@ -219,7 +219,7 @@ export class Parser {
219219
220220 const identifier = this . template . slice ( this . index , ( this . index = i ) ) ;
221221
222- if ( ! allow_reserved && reserved . includes ( identifier ) ) {
222+ if ( ! allow_reserved && is_reserved ( identifier ) ) {
223223 e . unexpected_reserved_word ( start , identifier ) ;
224224 }
225225
Original file line number Diff line number Diff line change @@ -188,43 +188,3 @@ export const EventModifiers = [
188188 'self' ,
189189 'trusted'
190190] ;
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 {
1212 object ,
1313 unwrap_pattern
1414} from '../utils/ast.js' ;
15- import { JsKeywords , Runes } from './constants.js' ;
15+ import { Runes } from './constants.js' ;
16+ import { is_reserved } from '../../utils.js' ;
1617
1718export class Scope {
1819 /** @type {ScopeRoot } */
@@ -148,7 +149,7 @@ export class Scope {
148149 this . references . has ( name ) ||
149150 this . declarations . has ( name ) ||
150151 this . root . conflicts . has ( name ) ||
151- JsKeywords . includes ( name )
152+ is_reserved ( name )
152153 ) {
153154 name = `${ preferred_name } _${ n ++ } ` ;
154155 }
Original file line number Diff line number Diff line change @@ -129,57 +129,6 @@ export function is_capture_event(name, mode = 'exclude-on') {
129129 : name !== 'ongotpointercapture' && name !== 'onlostpointercapture' ;
130130}
131131
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-
183132// we use a list of ignorable runtime warnings because not every runtime warning
184133// can be ignored and we want to keep the validation for svelte-ignore in place
185134export const IGNORABLE_RUNTIME_WARNINGS = /** @type {const } */ ( [
Original file line number Diff line number Diff line change @@ -39,3 +39,62 @@ const VOID_ELEMENT_NAMES = [
3939export function is_void ( name ) {
4040 return VOID_ELEMENT_NAMES . includes ( name ) || name . toLowerCase ( ) === '!doctype' ;
4141}
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