Skip to content

Commit

Permalink
Make sure default exports snapshot synthetic named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 1, 2021
1 parent 683cc6a commit 8aab31b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/ast/variables/ExportDefaultVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export default class ExportDefaultVariable extends LocalVariable {
(this.hasId ||
!(
this.originalId.variable.isReassigned ||
this.originalId.variable instanceof UndefinedVariable
this.originalId.variable instanceof UndefinedVariable ||
// this avoids a circular dependency
'syntheticNamespace' in this.originalId.variable
))
? this.originalId.variable
: null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { named } from './lib-reexport2.js';
console.log('side-effect', named);
export default named;
export { named as default };
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { named } from './lib.js';
console.log('side-effect', named);
export default named;
export { named as default };
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ module.exports = {
}
]
},
generateError: {
error: {
code: 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT',
id: path.join(__dirname, 'main.js'),
message: `Module "main.js" that is marked with 'syntheticNamedExports: "__synthetic"' needs an export named "__synthetic" that does not reexport an unresolved named export of the same module.`
message: `Module "main.js" that is marked with 'syntheticNamedExports: "__synthetic"' needs an export named "__synthetic" that does not reexport an unresolved named export of the same module.`,
watchFiles: [path.join(__dirname, 'main.js'), path.join(__dirname, 'dep.js')]
}
};
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import { foo } from './main.js';
export default foo;
export { foo as default } from './main.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
description: 'makes sure default exports of synthetic named exports are snapshots',
options: {
plugins: {
transform() {
return { syntheticNamedExports: '__synthetic' };
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { foo } from './synthetic';
export default foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import foo from './dep';
import { update } from './synthetic';

assert.strictEqual(foo, 'original');
update();
assert.strictEqual(foo, 'original');
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const __synthetic = { foo: 'original' };
export const update = () => (__synthetic.foo = 'reassigned');

0 comments on commit 8aab31b

Please sign in to comment.