Skip to content

Commit

Permalink
Do no fail if the source attribute is undefined in an unused named …
Browse files Browse the repository at this point in the history
…export (#3211)
  • Loading branch information
lukastaegert committed Nov 2, 2019
1 parent 5cbfdee commit 33b15cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Module.ts
Expand Up @@ -703,7 +703,7 @@ export default class Module {
const source = node.source.value;
this.sources.add(source);
this.exportAllSources.add(source);
} else if (node.source !== null) {
} else if (node.source instanceof Literal) {
// export { name } from './other'

const source = node.source.value;
Expand Down
15 changes: 15 additions & 0 deletions test/function/samples/handle-missing-export-source/_config.js
@@ -0,0 +1,15 @@
module.exports = {
description:
'does not fail if a pre-generated AST is omitting the source property of an unused named export (#3210)',
options: {
plugins: {
transform(code, id) {
if (id.endsWith('foo.js')) {
const ast = this.parse(code);
delete ast.body.find(node => node.type === 'ExportNamedDeclaration').source;
return { code, ast };
}
}
}
}
};
1 change: 1 addition & 0 deletions test/function/samples/handle-missing-export-source/foo.js
@@ -0,0 +1 @@
export const unused = 42;
3 changes: 3 additions & 0 deletions test/function/samples/handle-missing-export-source/main.js
@@ -0,0 +1,3 @@
import './foo.js';

export const foo = 42;

0 comments on commit 33b15cd

Please sign in to comment.