Skip to content

Commit 287232b

Browse files
Exterskybrettz9
authored andcommitted
fix: only modify window variable when browserEnv option is enabled
1 parent 71aeacf commit 287232b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/exportParser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ createSymbol = function (node, globals, value, scope) {
159159
};
160160

161161
// Creates variables from variable definitions
162-
const initVariables = function (node, globals) {
162+
const initVariables = function (node, globals, opts) {
163163
switch (node.type) {
164164
case 'Program': {
165165
node.body.forEach((childNode) => {
166-
initVariables(childNode, globals);
166+
initVariables(childNode, globals, opts);
167167
});
168168
break;
169169
} case 'ExpressionStatement': {
170-
initVariables(node.expression, globals);
170+
initVariables(node.expression, globals, opts);
171171
break;
172172
} case 'VariableDeclaration': {
173173
node.declarations.forEach((declaration) => {
174174
// let and const
175175
const symbol = createSymbol(declaration.id, globals, null, globals);
176-
if (node.kind === 'var' && globals.props.window) {
176+
if (opts.initWindow && node.kind === 'var' && globals.props.window) {
177177
// If var, also add to window
178178
globals.props.window.props[declaration.id.name] = symbol;
179179
}
@@ -315,7 +315,7 @@ const parse = function (ast, opt) {
315315
if (opts.initWindow) {
316316
globalVars.props.window = globalVars;
317317
}
318-
initVariables(ast, globalVars);
318+
initVariables(ast, globalVars, opts);
319319
mapVariables(ast, globalVars);
320320

321321
return {

0 commit comments

Comments
 (0)