Skip to content

Commit

Permalink
Properly handles default exporting undefined (#3558)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 15, 2020
1 parent eb20e62 commit 336eca8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ast/variables/ExportDefaultVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ExportDefaultDeclaration from '../nodes/ExportDefaultDeclaration';
import FunctionDeclaration from '../nodes/FunctionDeclaration';
import Identifier, { IdentifierWithVariable } from '../nodes/Identifier';
import LocalVariable from './LocalVariable';
import UndefinedVariable from './UndefinedVariable';
import Variable from './Variable';

export default class ExportDefaultVariable extends LocalVariable {
Expand Down Expand Up @@ -61,7 +62,12 @@ export default class ExportDefaultVariable extends LocalVariable {

getOriginalVariable(): Variable {
if (this.originalVariable === null) {
if (!this.originalId || (!this.hasId && this.originalId.variable.isReassigned)) {
if (
!this.originalId ||
(!this.hasId &&
(this.originalId.variable.isReassigned ||
this.originalId.variable instanceof UndefinedVariable))
) {
this.originalVariable = this;
} else {
const assignedOriginal = this.originalId.variable;
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/undefined-default-export/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles default exporting undefined'
};
5 changes: 5 additions & 0 deletions test/form/samples/undefined-default-export/_expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var dep = undefined;

console.log(dep);

export { dep };
1 change: 1 addition & 0 deletions test/form/samples/undefined-default-export/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default undefined;
3 changes: 3 additions & 0 deletions test/form/samples/undefined-default-export/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dep from './dep.js';
console.log(dep);
export { dep };

0 comments on commit 336eca8

Please sign in to comment.