Merge pull request #3368 from loganfsmyth/es3-transform-fixes
Fix the module plugin to properly requeue so the ES3 transforms can work
This commit is contained in:
commit
bf05b1b3bc
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@ -125,6 +130,11 @@ export default function () {
|
||||
|
||||
visitor: {
|
||||
ThisExpression(path, state) {
|
||||
// If other plugins run after this plugin's Program#exit handler, we allow them to
|
||||
// insert top-level `this` values. This allows the AMD and UMD plugins to
|
||||
// function properly.
|
||||
if (this.ranCommonJS) return;
|
||||
|
||||
if (
|
||||
state.opts.allowTopLevelThis !== true &&
|
||||
!path.findParent((path) => !path.is("shadow") &&
|
||||
@ -136,6 +146,8 @@ export default function () {
|
||||
|
||||
Program: {
|
||||
exit(path) {
|
||||
this.ranCommonJS = true;
|
||||
|
||||
let strict = !!this.opts.strict;
|
||||
|
||||
let { scope } = path;
|
||||
@ -419,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),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
|
||||
import foo from 'foo';
|
||||
console.log(foo);
|
||||
|
||||
export default 5;
|
||||
@ -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;
|
||||
@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-es2015-modules-commonjs",
|
||||
"transform-es3-member-expression-literals",
|
||||
"transform-es3-property-literals"
|
||||
]
|
||||
}
|
||||
@ -208,10 +208,22 @@ export function setKey(key) {
|
||||
this.type = this.node && this.node.type;
|
||||
}
|
||||
|
||||
export function requeue(path = this) {
|
||||
if (path.removed) return;
|
||||
export function requeue(pathToQueue = this) {
|
||||
if (pathToQueue.removed) return;
|
||||
|
||||
for (let context of this.contexts) {
|
||||
context.maybeQueue(path);
|
||||
let contexts = this._getQueueContexts();
|
||||
|
||||
for (let context of contexts) {
|
||||
context.maybeQueue(pathToQueue);
|
||||
}
|
||||
}
|
||||
|
||||
export function _getQueueContexts(){
|
||||
let path = this;
|
||||
let contexts = this.contexts;
|
||||
while (!contexts.length) {
|
||||
path = path.parentPath;
|
||||
contexts = path.contexts;
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
@ -60,12 +60,7 @@ export function _containerInsert(from, nodes) {
|
||||
}
|
||||
}
|
||||
|
||||
let contexts = this.contexts;
|
||||
let path = this;
|
||||
while (!contexts.length) {
|
||||
path = path.parentPath;
|
||||
contexts = path.contexts;
|
||||
}
|
||||
let contexts = this._getQueueContexts();
|
||||
|
||||
for (let path of paths) {
|
||||
path.setScope();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user