diff --git a/src/Module.ts b/src/Module.ts index 4f1965c2113..a3ac07031fa 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -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; diff --git a/test/function/samples/handle-missing-export-source/_config.js b/test/function/samples/handle-missing-export-source/_config.js new file mode 100644 index 00000000000..0488306701a --- /dev/null +++ b/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 }; + } + } + } + } +}; diff --git a/test/function/samples/handle-missing-export-source/foo.js b/test/function/samples/handle-missing-export-source/foo.js new file mode 100644 index 00000000000..c6c4de856d9 --- /dev/null +++ b/test/function/samples/handle-missing-export-source/foo.js @@ -0,0 +1 @@ +export const unused = 42; diff --git a/test/function/samples/handle-missing-export-source/main.js b/test/function/samples/handle-missing-export-source/main.js new file mode 100644 index 00000000000..112bd622218 --- /dev/null +++ b/test/function/samples/handle-missing-export-source/main.js @@ -0,0 +1,3 @@ +import './foo.js'; + +export const foo = 42;