fix queueing of nested paths being pushed onto the priority queue
This commit is contained in:
parent
02e4dcdbe2
commit
688dcec6a3
@ -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;
|
|
||||||
@ -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;
|
|
||||||
@ -1,10 +1,8 @@
|
|||||||
var _Object$getPrototypeO;
|
|
||||||
|
|
||||||
var Test = (function (_Foo) {
|
var Test = (function (_Foo) {
|
||||||
babelHelpers.inherits(Test, _Foo);
|
babelHelpers.inherits(Test, _Foo);
|
||||||
|
|
||||||
function Test() {
|
function Test() {
|
||||||
var _babelHelpers$get;
|
var _Object$getPrototypeO, _babelHelpers$get;
|
||||||
|
|
||||||
babelHelpers.classCallCheck(this, Test);
|
babelHelpers.classCallCheck(this, Test);
|
||||||
|
|
||||||
|
|||||||
@ -82,6 +82,7 @@ export default function () {
|
|||||||
for (let reid of exports) {
|
for (let reid of exports) {
|
||||||
node = buildExportsAssignment(reid, node).expression;
|
node = buildExportsAssignment(reid, node).expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
path.replaceWith(node);
|
path.replaceWith(node);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
"babel-runtime": "^5.0.0",
|
"babel-runtime": "^5.0.0",
|
||||||
"babel-types": "^6.1.18",
|
"babel-types": "^6.1.18",
|
||||||
"babylon": "^6.1.18",
|
"babylon": "^6.1.18",
|
||||||
|
"debug": "^2.2.0",
|
||||||
"globals": "^8.3.0",
|
"globals": "^8.3.0",
|
||||||
"invariant": "^2.1.0",
|
"invariant": "^2.1.0",
|
||||||
"lodash": "^3.10.1",
|
"lodash": "^3.10.1",
|
||||||
|
|||||||
@ -53,13 +53,17 @@ export default class TraversalContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeQueue(path) {
|
maybeQueue(path, notPriority?: boolean) {
|
||||||
if (this.trap) {
|
if (this.trap) {
|
||||||
throw new Error("Infinite cycle detected");
|
throw new Error("Infinite cycle detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.queue) {
|
if (this.queue) {
|
||||||
this.priorityQueue.push(path);
|
if (notPriority) {
|
||||||
|
this.queue.push(path);
|
||||||
|
} else {
|
||||||
|
this.priorityQueue.push(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import traverse from "../index";
|
|||||||
export function call(key): boolean {
|
export function call(key): boolean {
|
||||||
let opts = this.opts;
|
let opts = this.opts;
|
||||||
|
|
||||||
|
this.debug(() => key);
|
||||||
|
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
if (this._call(opts[key])) return true;
|
if (this._call(opts[key])) return true;
|
||||||
}
|
}
|
||||||
@ -28,7 +30,7 @@ export function _call(fns?: Array<Function>): boolean {
|
|||||||
if (!node) return true;
|
if (!node) return true;
|
||||||
|
|
||||||
let ret = fn.call(this.state, this, this.state);
|
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
|
// node has been replaced, it will have been requeued
|
||||||
if (this.node !== node) return true;
|
if (this.node !== node) return true;
|
||||||
@ -58,9 +60,11 @@ export function visit(): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.call("enter") || this.shouldSkip) {
|
if (this.call("enter") || this.shouldSkip) {
|
||||||
|
this.debug(() => "Skip...");
|
||||||
return this.shouldStop;
|
return this.shouldStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.debug(() => "Recursing into...");
|
||||||
traverse.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
traverse.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
||||||
|
|
||||||
this.call("exit");
|
this.call("exit");
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
import type Hub from "../hub";
|
import type Hub from "../hub";
|
||||||
import type TraversalContext from "../context";
|
import type TraversalContext from "../context";
|
||||||
import * as virtualTypes from "./lib/virtual-types";
|
import * as virtualTypes from "./lib/virtual-types";
|
||||||
|
import buildDebug from "debug";
|
||||||
import { PATH_CACHE_KEY } from "./constants";
|
import { PATH_CACHE_KEY } from "./constants";
|
||||||
import invariant from "invariant";
|
import invariant from "invariant";
|
||||||
import traverse from "../index";
|
import traverse from "../index";
|
||||||
@ -10,6 +11,8 @@ import assign from "lodash/object/assign";
|
|||||||
import Scope from "../scope";
|
import Scope from "../scope";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
|
let debug = buildDebug("babel");
|
||||||
|
|
||||||
export default class NodePath {
|
export default class NodePath {
|
||||||
constructor(hub: Hub, parent: Object) {
|
constructor(hub: Hub, parent: Object) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@ -141,7 +144,7 @@ export default class NodePath {
|
|||||||
this.node[key] = node;
|
this.node[key] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
dump() {
|
getPathLocation(): string {
|
||||||
let parts = [];
|
let parts = [];
|
||||||
let path = this;
|
let path = this;
|
||||||
do {
|
do {
|
||||||
@ -149,7 +152,12 @@ export default class NodePath {
|
|||||||
if (path.inList) key = `${path.listKey}[${key}]`;
|
if (path.inList) key = `${path.listKey}[${key}]`;
|
||||||
parts.unshift(key);
|
parts.unshift(key);
|
||||||
} while(path = path.parentPath);
|
} while(path = path.parentPath);
|
||||||
console.log(parts.join("."));
|
return parts.join(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(buildMessage: Function) {
|
||||||
|
if (!debug.enabled) return;
|
||||||
|
debug(`${this.getPathLocation()} ${this.type}: ${buildMessage()}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,9 +69,10 @@ export function _containerInsert(from, nodes) {
|
|||||||
|
|
||||||
for (let path of paths) {
|
for (let path of paths) {
|
||||||
path.setScope();
|
path.setScope();
|
||||||
|
path.debug(() => "Inserted.");
|
||||||
|
|
||||||
for (let context of contexts) {
|
for (let context of contexts) {
|
||||||
context.maybeQueue(path);
|
context.maybeQueue(path, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -164,6 +164,8 @@ export function _replaceWith(node) {
|
|||||||
t.validate(this.parent, this.key, node);
|
t.validate(this.parent, this.key, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.debug(() => `Replace with ${node && node.type}`);
|
||||||
|
|
||||||
this.node = this.container[this.key] = node;
|
this.node = this.container[this.key] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user