Skip to content

Commit

Permalink
Track updates of globals that are exported as default
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 11, 2020
1 parent 67ebd53 commit 2d6865a
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 12 deletions.
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
define(function () { 'use strict';

console.log(global);
var value = global;

return global;
console.log(value);

return value;

});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

console.log(global);
var value = global;

module.exports = global;
console.log(value);

module.exports = value;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
console.log(global);
var value = global;

export default global;
console.log(value);

export default value;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ System.register([], function (exports) {
return {
execute: function () {

console.log(global);
var value = exports('default', global);

console.log(value);

}
};
Expand Down
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
6 changes: 3 additions & 3 deletions test/cli/samples/watch/watch-config-early-update/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
format: "es"
}
});
}, 500);
}, 300);
}
});
});
Expand All @@ -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
11 changes: 11 additions & 0 deletions test/function/samples/default-exported-global/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const assert = require('assert');

module.exports = {
description: 'Tracks updates of default exported globals',
context: {
myGlobal: 42
},
exports(exports) {
assert.deepStrictEqual(exports, { original: 42, updated: 1 });
}
};
3 changes: 3 additions & 0 deletions test/function/samples/default-exported-global/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default myGlobal;
myGlobal = 1;
export const updated = 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';

0 comments on commit 2d6865a

Please sign in to comment.