Re-queue remapped imports so they are re-traversed - fixes T6863

This commit is contained in:
Logan Smyth 2016-02-21 23:34:52 -08:00
parent 01003b954a
commit 0a0407be41
4 changed files with 40 additions and 3 deletions

View File

@ -63,6 +63,7 @@ export default function () {
} else {
path.replaceWith(remap);
}
this.requeueInParent(path);
},
AssignmentExpression(path) {
@ -86,6 +87,7 @@ export default function () {
}
path.replaceWith(node);
this.requeueInParent(path);
},
UpdateExpression(path) {
@ -102,7 +104,9 @@ export default function () {
let node = t.assignmentExpression(path.node.operator[0] + "=", arg.node, t.numericLiteral(1));
if ((path.parentPath.isExpressionStatement() && !path.isCompletionRecord()) || path.node.prefix) {
return path.replaceWith(node);
path.replaceWith(node);
this.requeueInParent(path);
return;
}
let nodes = [];
@ -116,7 +120,8 @@ export default function () {
}
nodes.push(t.binaryExpression(operator, arg.node, t.numericLiteral(1)));
path.replaceWithMultiple(t.sequenceExpression(nodes));
let newPaths = path.replaceWithMultiple(t.sequenceExpression(nodes));
for (const newPath of newPaths) this.requeueInParent(newPath);
}
};
@ -426,7 +431,12 @@ export default function () {
}
path.unshiftContainer("body", topNodes);
path.traverse(reassignmentVisitor, { remaps, scope, exports });
path.traverse(reassignmentVisitor, {
remaps,
scope,
exports,
requeueInParent: (newPath) => path.requeue(newPath),
});
}
}
}

View File

@ -0,0 +1,5 @@
import foo from 'foo';
console.log(foo);
export default 5;

View File

@ -0,0 +1,15 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _foo = require('foo');
var _foo2 = _interopRequireDefault(_foo);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
console.log(_foo2['default']);
exports['default'] = 5;

View File

@ -0,0 +1,7 @@
{
"plugins": [
"transform-es2015-modules-commonjs",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}