Skip to content

Commit

Permalink
fix: add variable polyfill exceptions for compatiability
Browse files Browse the repository at this point in the history
  • Loading branch information
valya committed Aug 29, 2023
1 parent caa15ff commit 2e49c9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/VariablePolyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const isInScope = (path: NodePath<types.namedTypes.Identifier>) => {
return false;
};

const polyfillExceptions = ['this', 'window', 'global'];

const polyfillVar = (
path: NodePath<types.namedTypes.Identifier>,
dataNode: DataNode,
Expand All @@ -50,6 +52,10 @@ const polyfillVar = (
return;
}
}
// For tmpl compat we ignore these identifiers
if (polyfillExceptions.includes(path.node.name)) {
return;
}
path.replace(buildGlobalSwitch(path.node, dataNode));
};

Expand Down
15 changes: 15 additions & 0 deletions test/ExpressionFixtures/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,4 +811,19 @@ line`,
tests: [],
},
{ expression: '={{ `\ntesting\ntesting\n` }}', tests: [] },
{ expression: '={{ new Date }}', tests: [] },
{ expression: '={{ new Date() }}', tests: [] },
{ expression: '={{ new Date.toISOString() }}', tests: [] },
{ expression: '={{ new Date().toISOString() }}', tests: [] },
{ expression: '={{ global.test = 3 }}', tests: [] },
{ expression: '={{ window.test = 3 }}', tests: [] },
{ expression: '={{ this.test = 3 }}', tests: [] },
{
expression: `=test
a
{{ "test" }}
{{ test }}
`,
tests: [],
},
];

0 comments on commit 2e49c9e

Please sign in to comment.