diff --git a/src/ExpressionBuilder.ts b/src/ExpressionBuilder.ts index 313f4fe..137d553 100644 --- a/src/ExpressionBuilder.ts +++ b/src/ExpressionBuilder.ts @@ -5,7 +5,7 @@ import { parse, visit, print } from 'recast'; import { builders as b } from 'ast-types'; import type { ExpressionKind, StatementKind } from 'ast-types/lib/gen/kinds'; -import { jsVariablePolyfill } from './VariablePolyfill'; +import { globalIdentifier, jsVariablePolyfill } from './VariablePolyfill'; import type { DataNode } from './VariablePolyfill'; import { splitExpression } from './ExpressionSplitter'; import type { ExpressionCode, ExpressionText } from './ExpressionSplitter'; @@ -175,9 +175,7 @@ export const getExpressionCode = ( const chunks = getParsedExpression(expr); const newProg = b.program([ - b.variableDeclaration('var', [ - b.variableDeclarator(b.identifier('global'), b.objectExpression([])), - ]), + b.variableDeclaration('var', [b.variableDeclarator(globalIdentifier, b.objectExpression([]))]), ]); // This is what's used to access that's passed in. For compatibility we us diff --git a/src/VariablePolyfill.ts b/src/VariablePolyfill.ts index 6169b7b..ce71b86 100644 --- a/src/VariablePolyfill.ts +++ b/src/VariablePolyfill.ts @@ -11,7 +11,7 @@ function assertNever(value: never): value is never { return true; } -const globalIdentifier = b.identifier( +export const globalIdentifier = b.identifier( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore typeof window !== 'object' ? 'global' : 'window',