Skip to content

Commit

Permalink
fix(processing/script/transformers/location): handle class property d…
Browse files Browse the repository at this point in the history
…efinitions (#3033)

The transformers generates wrong (and invalid) JavaScript if a class contains a
property named `locations`.

The generated code currently is `class C{ __get$Loc(location) }`.
  • Loading branch information
sorin-davidoi authored Dec 13, 2024
1 parent f959eb7 commit 04e27ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/processing/script/transformers/location-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ const transformer: Transformer<Identifier> = {
if (parent.type === Syntax.MethodDefinition)
return false;

// Skip: class X { location }
// @ts-ignore
if (parent.type === Syntax.PropertyDefinition)
return false;

// Skip: class location { x () {} }
if (parent.type === Syntax.ClassDeclaration)
return false;
Expand Down
5 changes: 5 additions & 0 deletions test/server/script-processor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ describe('Script processor', () => {
'? function(){var _hh$temp0 = newLocation; return __set$Loc(location,_hh$temp0)||(location=_hh$temp0);}.call(this)' +
': function(){var _hh$temp1 = "#123"; return __set$Loc(location,_hh$temp1)||(location=_hh$temp1);}.call(this);',
},
{
src: 'class C { location }',

expected: 'class C { location }',
},
{
src: 'if (location) { location = newLocation; } else location = "#123";',

Expand Down

0 comments on commit 04e27ba

Please sign in to comment.