Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track updates of globals that are exported as default #3550

Merged
merged 3 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# rollup changelog

## 2.9.1
*2020-05-11*

### Bug Fixes
* Do not create unintended live-bindings or invalid reexports when reexporting global variables (#3550)

### Pull Requests
* [#3550](https://github.com/rollup/rollup/pull/3550): Track updates of globals that are exported as default (@lukastaegert)

## 2.9.0
*2020-05-10*

Expand Down
8 changes: 2 additions & 6 deletions src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ export default class Module {
} else if (variable instanceof ExportDefaultVariable) {
variable = variable.getOriginalVariable();
}
if (variable.module) {
relevantDependencies.add(variable.module);
}
relevantDependencies.add(variable.module!);
}
if (
this.isEntryPoint ||
Expand All @@ -363,9 +361,7 @@ export default class Module {
} else if (variable instanceof ExportDefaultVariable) {
variable = variable.getOriginalVariable();
}
if (variable.module) {
relevantDependencies.add(variable.module);
}
relevantDependencies.add(variable.module!);
}
}
if (this.graph.treeshakingOptions) {
Expand Down
2 changes: 2 additions & 0 deletions src/ast/variables/GlobalVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ObjectPath } from '../utils/PathTracker';
import Variable from './Variable';

export default class GlobalVariable extends Variable {
isReassigned = true;

hasEffectsWhenAccessedAtPath(path: ObjectPath) {
return !isGlobalMember([this.name, ...path]);
}
Expand Down
3 changes: 0 additions & 3 deletions test/chunking-form/samples/export-default-global/_config.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions test/cli/samples/watch/bundle-error/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module.exports = {
fs.writeFileSync(mainFile, '<=>');
},
after() {
fs.unlinkSync(mainFile);
setTimeout(() => fs.unlinkSync(mainFile), 300);
},
abortOnStderr(data) {
if (data.includes('Error: Unexpected token')) {
setTimeout(() => fs.writeFileSync(mainFile, 'export default 42;'), 200);
setTimeout(() => fs.writeFileSync(mainFile, 'export default 42;'), 300);
return false;
}
if (data.includes('created _actual')) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/watch/watch-config-early-update/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
`
);
fs.writeFileSync(messageFile, 'loaded');
}, 500);
}, 300);
}
});
},
Expand All @@ -69,7 +69,7 @@ module.exports = {
},
abortOnStderr(data) {
if (reloadTriggered && data.includes('created _actual')) {
return true;
return new Promise(resolve => setTimeout(() => resolve(true), 300));
} else if (data.includes('Reloading updated config')) {
reloadTriggered = true;
return false;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/export-default-global/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
description: 'handles default exporting global variables',
options: { output: { name: 'bundle' } }
};
9 changes: 9 additions & 0 deletions test/form/samples/export-default-global/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define(function () { 'use strict';

var value = global;

console.log(value);

return value;

});
7 changes: 7 additions & 0 deletions test/form/samples/export-default-global/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

var value = global;

console.log(value);

module.exports = value;
5 changes: 5 additions & 0 deletions test/form/samples/export-default-global/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var value = global;

console.log(value);

export default value;
10 changes: 10 additions & 0 deletions test/form/samples/export-default-global/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var bundle = (function () {
'use strict';

var value = global;

console.log(value);

return value;

}());
12 changes: 12 additions & 0 deletions test/form/samples/export-default-global/_expected/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
System.register('bundle', [], function (exports) {
'use strict';
return {
execute: function () {

var value = exports('default', global);

console.log(value);

}
};
});
13 changes: 13 additions & 0 deletions test/form/samples/export-default-global/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.bundle = factory());
}(this, (function () { 'use strict';

var value = global;

console.log(value);

return value;

})));
8 changes: 8 additions & 0 deletions test/function/samples/default-exported-global/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const assert = require('assert');

module.exports = {
description: 'Tracks updates of default exported globals',
exports(exports) {
assert.deepStrictEqual(exports, { original: 1, updated: 2 });
}
};
5 changes: 5 additions & 0 deletions test/function/samples/default-exported-global/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global.myGlobal = 1;
export default myGlobal;
global.myGlobal = 2;
export const updated = myGlobal;
delete global.myGlobal;
1 change: 1 addition & 0 deletions test/function/samples/default-exported-global/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as original, updated } from './lib';