renamed Path#isPreviousType to isType
This commit is contained in:
parent
50f2f2fc98
commit
76690a3deb
@ -11,10 +11,10 @@ export function insertBefore(nodes) {
|
||||
|
||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||
return this.parentPath.insertBefore(nodes);
|
||||
} else if (this.isPreviousType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
} else if (this.isType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else if (this.isPreviousType("Statement") || !this.type) {
|
||||
} else if (this.isType("Statement") || !this.type) {
|
||||
this._maybePopFromStatements(nodes);
|
||||
if (Array.isArray(this.container)) {
|
||||
return this._containerInsertBefore(nodes);
|
||||
@ -82,14 +82,14 @@ export function insertAfter(nodes) {
|
||||
|
||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||
return this.parentPath.insertAfter(nodes);
|
||||
} else if (this.isPreviousType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
} else if (this.isType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
if (this.node) {
|
||||
var temp = this.scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
||||
nodes.push(t.expressionStatement(temp));
|
||||
}
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else if (this.isPreviousType("Statement") || !this.type) {
|
||||
} else if (this.isType("Statement") || !this.type) {
|
||||
this._maybePopFromStatements(nodes);
|
||||
if (Array.isArray(this.container)) {
|
||||
return this._containerInsertAfter(nodes);
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as removalHooks from "./lib/removal-hooks";
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Deprecated in favor of `dangerouslyRemove` as it's far more scary and more accurately portrays
|
||||
* the risk.
|
||||
*/
|
||||
|
||||
export function remove() {
|
||||
|
||||
@ -110,12 +110,12 @@ export function replaceWith(replacement, whateverAllowed) {
|
||||
}
|
||||
|
||||
// replacing a statement with an expression so wrap it in an expression statement
|
||||
if (this.isPreviousType("Statement") && t.isExpression(replacement) && !this.canHaveVariableDeclarationOrExpression()) {
|
||||
if (this.isType("Statement") && t.isExpression(replacement) && !this.canHaveVariableDeclarationOrExpression()) {
|
||||
replacement = t.expressionStatement(replacement);
|
||||
}
|
||||
|
||||
// replacing an expression with a statement so let's explode it
|
||||
if (this.isPreviousType("Expression") && t.isStatement(replacement)) {
|
||||
if (this.isType("Expression") && t.isStatement(replacement)) {
|
||||
return this.replaceExpressionWithStatements([replacement]);
|
||||
}
|
||||
|
||||
|
||||
@ -101,36 +101,36 @@ export function inferType(path: NodePath): ?Object {
|
||||
path = path.resolve();
|
||||
if (!path) return;
|
||||
|
||||
if (path.isPreviousType("RestElement") || path.parentPath.isPreviousType("RestElement") || path.isPreviousType("ArrayExpression")) {
|
||||
if (path.isType("RestElement") || path.parentPath.isType("RestElement") || path.isType("ArrayExpression")) {
|
||||
return t.genericTypeAnnotation(t.identifier("Array"));
|
||||
}
|
||||
|
||||
if (path.parentPath.isPreviousType("TypeCastExpression")) {
|
||||
if (path.parentPath.isType("TypeCastExpression")) {
|
||||
return path.parentPath.node.typeAnnotation;
|
||||
}
|
||||
|
||||
if (path.isPreviousType("TypeCastExpression")) {
|
||||
if (path.isType("TypeCastExpression")) {
|
||||
return path.node.typeAnnotation;
|
||||
}
|
||||
|
||||
if (path.isPreviousType("ObjectExpression")) {
|
||||
if (path.isType("ObjectExpression")) {
|
||||
return t.genericTypeAnnotation(t.identifier("Object"));
|
||||
}
|
||||
|
||||
if (path.isPreviousType("Function")) {
|
||||
if (path.isType("Function")) {
|
||||
return t.identifier("Function");
|
||||
}
|
||||
|
||||
if (path.isPreviousType("Literal")) {
|
||||
if (path.isType("Literal")) {
|
||||
var value = path.node.value;
|
||||
if (isString(value)) return t.stringTypeAnnotation();
|
||||
if (isNumber(value)) return t.numberTypeAnnotation();
|
||||
if (isBoolean(value)) return t.booleanTypeAnnotation();
|
||||
}
|
||||
|
||||
if (path.isPreviousType("CallExpression")) {
|
||||
if (path.isType("CallExpression")) {
|
||||
var callee = path.get("callee").resolve();
|
||||
if (callee && callee.isPreviousType("Function")) return callee.node.returnType;
|
||||
if (callee && callee.isType("Function")) return callee.node.returnType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ export function equals(key, value): boolean {
|
||||
* been removed yet we still internally know the type and need it to calculate node replacement.
|
||||
*/
|
||||
|
||||
export function isPreviousType(type: string): boolean {
|
||||
export function isType(type: string): boolean {
|
||||
return t.isType(this.type, type);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user