File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed
packages/svelte/src/compiler/phases Expand file tree Collapse file tree 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 = [
196196 'self' ,
197197 'trusted'
198198] ;
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';
44import * as b from '../utils/builders.js' ;
55import { error } from '../errors.js' ;
66import { extract_identifiers , extract_identifiers_from_expression } from '../utils/ast.js' ;
7- import { Runes } from './constants.js' ;
7+ import { JsKeywords , Runes } from './constants.js' ;
88
99export class Scope {
1010 /** @type {ScopeRoot } */
@@ -133,7 +133,8 @@ export class Scope {
133133 while (
134134 this . references . has ( name ) ||
135135 this . declarations . has ( name ) ||
136- this . root . conflicts . has ( name )
136+ this . root . conflicts . has ( name ) ||
137+ JsKeywords . includes ( name )
137138 ) {
138139 name = `${ preferred_name } _${ n ++ } ` ;
139140 }
You can’t perform that action at this time.
0 commit comments