Re-queue nodes inserted with .replaceWith and centralize logic - fixes T2817

This commit is contained in:
Logan Smyth 2016-02-21 15:02:27 -08:00
parent ab7533ed6c
commit 01003b954a
3 changed files with 24 additions and 10 deletions

View File

@ -125,6 +125,11 @@ export default function () {
visitor: { visitor: {
ThisExpression(path, state) { 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 ( if (
state.opts.allowTopLevelThis !== true && state.opts.allowTopLevelThis !== true &&
!path.findParent((path) => !path.is("shadow") && !path.findParent((path) => !path.is("shadow") &&
@ -136,6 +141,8 @@ export default function () {
Program: { Program: {
exit(path) { exit(path) {
this.ranCommonJS = true;
let strict = !!this.opts.strict; let strict = !!this.opts.strict;
let { scope } = path; let { scope } = path;

View File

@ -208,10 +208,22 @@ export function setKey(key) {
this.type = this.node && this.node.type; this.type = this.node && this.node.type;
} }
export function requeue(path = this) { export function requeue(pathToQueue = this) {
if (path.removed) return; if (pathToQueue.removed) return;
for (let context of this.contexts) { let contexts = this._getQueueContexts();
context.maybeQueue(path);
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;
}

View File

@ -60,12 +60,7 @@ export function _containerInsert(from, nodes) {
} }
} }
let contexts = this.contexts; let contexts = this._getQueueContexts();
let path = this;
while (!contexts.length) {
path = path.parentPath;
contexts = path.contexts;
}
for (let path of paths) { for (let path of paths) {
path.setScope(); path.setScope();