File tree 3 files changed +48
-2
lines changed
packages/svelte/src/compiler/phases
3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: ensure generated code does not use keywords as variable names
Original file line number Diff line number Diff line change @@ -196,3 +196,43 @@ export const EventModifiers = [
196
196
'self' ,
197
197
'trusted'
198
198
] ;
199
+
200
+ export const JsKeywords = [
201
+ 'class' ,
202
+ 'break' ,
203
+ 'const' ,
204
+ 'let' ,
205
+ 'var' ,
206
+ 'continue' ,
207
+ 'if' ,
208
+ 'for' ,
209
+ 'while' ,
210
+ 'do' ,
211
+ 'new' ,
212
+ 'static' ,
213
+ 'true' ,
214
+ 'false' ,
215
+ 'void' ,
216
+ 'with' ,
217
+ 'yield' ,
218
+ 'await' ,
219
+ 'typeof' ,
220
+ 'throw' ,
221
+ 'throws' ,
222
+ 'null' ,
223
+ 'delete' ,
224
+ 'default' ,
225
+ 'catch' ,
226
+ 'debugger' ,
227
+ 'case' ,
228
+ 'arguments' ,
229
+ 'else' ,
230
+ 'extends' ,
231
+ 'export' ,
232
+ 'import' ,
233
+ 'extends' ,
234
+ 'switch' ,
235
+ 'instanceof' ,
236
+ 'return' ,
237
+ 'this'
238
+ ] ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { is_element_node } from './nodes.js';
4
4
import * as b from '../utils/builders.js' ;
5
5
import { error } from '../errors.js' ;
6
6
import { extract_identifiers , extract_identifiers_from_expression } from '../utils/ast.js' ;
7
- import { Runes } from './constants.js' ;
7
+ import { JsKeywords , Runes } from './constants.js' ;
8
8
9
9
export class Scope {
10
10
/** @type {ScopeRoot } */
@@ -133,7 +133,8 @@ export class Scope {
133
133
while (
134
134
this . references . has ( name ) ||
135
135
this . declarations . has ( name ) ||
136
- this . root . conflicts . has ( name )
136
+ this . root . conflicts . has ( name ) ||
137
+ JsKeywords . includes ( name )
137
138
) {
138
139
name = `${ preferred_name } _${ n ++ } ` ;
139
140
}
You can’t perform that action at this time.
0 commit comments