fix queueing of nested paths being pushed onto the priority queue

This commit is contained in:
Sebastian McKenzie 2015-11-13 03:37:15 -08:00
parent 02e4dcdbe2
commit 688dcec6a3
10 changed files with 29 additions and 84 deletions

View File

@ -1,28 +0,0 @@
var _ = require('underscore'),
React = require('react');
class Hello extends React.Component
{
state = {
hello: 1
};
/*
constructor() {
super();
}
*/
render() {
var props = _.omit(this.props, 'children');
return (
<p className="1" {... props}>Hello</p>
);
}
foo(param = 1) {
this.param = param;
}
}
module.exports = Hello;

View File

@ -1,46 +0,0 @@
'use strict';
var _ = require('underscore'),
React = require('react');
var Hello = (function (_React$Component) {
babelHelpers.inherits(Hello, _React$Component);
function Hello() {
var _temp, _this;
babelHelpers.classCallCheck(this, Hello);
return babelHelpers.possibleConstructorReturn(_this, (_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Hello).apply(this, arguments)), _this), _this.state = {
hello: 1
}, _temp));
}
babelHelpers.createClass(Hello, [{
key: 'render',
/*
constructor() {
super();
}
*/
value: function render() {
var props = _.omit(this.props, 'children');
return React.createElement(
'p',
babelHelpers.extends({ className: '1' }, props),
'Hello'
);
}
}, {
key: 'foo',
value: function foo() {
var param = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
this.param = param;
}
}]);
return Hello;
})(React.Component);
module.exports = Hello;

View File

@ -1,10 +1,8 @@
var _Object$getPrototypeO;
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
var _babelHelpers$get;
var _Object$getPrototypeO, _babelHelpers$get;
babelHelpers.classCallCheck(this, Test);

View File

@ -82,6 +82,7 @@ export default function () {
for (let reid of exports) {
node = buildExportsAssignment(reid, node).expression;
}
path.replaceWith(node);
},

View File

@ -13,6 +13,7 @@
"babel-runtime": "^5.0.0",
"babel-types": "^6.1.18",
"babylon": "^6.1.18",
"debug": "^2.2.0",
"globals": "^8.3.0",
"invariant": "^2.1.0",
"lodash": "^3.10.1",

View File

@ -53,13 +53,17 @@ export default class TraversalContext {
});
}
maybeQueue(path) {
maybeQueue(path, notPriority?: boolean) {
if (this.trap) {
throw new Error("Infinite cycle detected");
}
if (this.queue) {
this.priorityQueue.push(path);
if (notPriority) {
this.queue.push(path);
} else {
this.priorityQueue.push(path);
}
}
}

View File

@ -7,6 +7,8 @@ import traverse from "../index";
export function call(key): boolean {
let opts = this.opts;
this.debug(() => key);
if (this.node) {
if (this._call(opts[key])) return true;
}
@ -28,7 +30,7 @@ export function _call(fns?: Array<Function>): boolean {
if (!node) return true;
let ret = fn.call(this.state, this, this.state);
if (ret) throw new Error("Unexpected return value from visitor method " + fn);
if (ret) throw new Error(`Unexpected return value from visitor method ${fn}`);
// node has been replaced, it will have been requeued
if (this.node !== node) return true;
@ -58,9 +60,11 @@ export function visit(): boolean {
}
if (this.call("enter") || this.shouldSkip) {
this.debug(() => "Skip...");
return this.shouldStop;
}
this.debug(() => "Recursing into...");
traverse.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
this.call("exit");

View File

@ -3,6 +3,7 @@
import type Hub from "../hub";
import type TraversalContext from "../context";
import * as virtualTypes from "./lib/virtual-types";
import buildDebug from "debug";
import { PATH_CACHE_KEY } from "./constants";
import invariant from "invariant";
import traverse from "../index";
@ -10,6 +11,8 @@ import assign from "lodash/object/assign";
import Scope from "../scope";
import * as t from "babel-types";
let debug = buildDebug("babel");
export default class NodePath {
constructor(hub: Hub, parent: Object) {
this.parent = parent;
@ -141,7 +144,7 @@ export default class NodePath {
this.node[key] = node;
}
dump() {
getPathLocation(): string {
let parts = [];
let path = this;
do {
@ -149,7 +152,12 @@ export default class NodePath {
if (path.inList) key = `${path.listKey}[${key}]`;
parts.unshift(key);
} while(path = path.parentPath);
console.log(parts.join("."));
return parts.join(".");
}
debug(buildMessage: Function) {
if (!debug.enabled) return;
debug(`${this.getPathLocation()} ${this.type}: ${buildMessage()}`);
}
}

View File

@ -69,9 +69,10 @@ export function _containerInsert(from, nodes) {
for (let path of paths) {
path.setScope();
path.debug(() => "Inserted.");
for (let context of contexts) {
context.maybeQueue(path);
context.maybeQueue(path, true);
}
}

View File

@ -164,6 +164,8 @@ export function _replaceWith(node) {
t.validate(this.parent, this.key, node);
}
this.debug(() => `Replace with ${node && node.type}`);
this.node = this.container[this.key] = node;
}