Update prettier, eslint + plugins, flow, husky and lint-staged (#6183)
This commit is contained in:
@@ -51,7 +51,7 @@ const JSX_TAG = /^[a-z][\w-]*$/i;
|
||||
* RegExp to test for the three types of brackets.
|
||||
*/
|
||||
|
||||
const BRACKET = /^[()\[\]{}]$/;
|
||||
const BRACKET = /^[()[\]{}]$/;
|
||||
|
||||
/**
|
||||
* Get the type of token, specifying punctuator type.
|
||||
@@ -94,7 +94,10 @@ function highlight(defs: Object, text: string) {
|
||||
const type = getTokenType(args);
|
||||
const colorize = defs[type];
|
||||
if (colorize) {
|
||||
return args[0].split(NEWLINE).map(str => colorize(str)).join("\n");
|
||||
return args[0]
|
||||
.split(NEWLINE)
|
||||
.map(str => colorize(str))
|
||||
.join("\n");
|
||||
} else {
|
||||
return args[0];
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ import path from "path";
|
||||
const debug = buildDebug("babel:config:loading:files:plugins");
|
||||
|
||||
const EXACT_RE = /^module:/;
|
||||
const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/\/]+[/\/]|babel-plugin-)/;
|
||||
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/\/]+[/\/]|babel-preset-)/;
|
||||
const BABEL_PLUGIN_ORG_RE = /^(@babel[/\/])(?!plugin-|[^/\/]+[/\/])/;
|
||||
const BABEL_PRESET_ORG_RE = /^(@babel[/\/])(?!preset-|[^/\/]+[/\/])/;
|
||||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel[/\/])[^/\/]+[/\/])(?!babel-plugin-|[^/\/]+[/\/])/;
|
||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel[/\/])[^/\/]+[/\/])(?!babel-preset-|[^/\/]+[/\/])/;
|
||||
const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/;
|
||||
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
|
||||
const BABEL_PLUGIN_ORG_RE = /^(@babel\/)(?!plugin-|[^/]+\/)/;
|
||||
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/;
|
||||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-plugin-|[^/]+\/)/;
|
||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-preset-|[^/]+\/)/;
|
||||
|
||||
export function resolvePlugin(name: string, dirname: string): string | null {
|
||||
return resolveStandardizedName("plugin", name, dirname);
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function({ types: t, template }) {
|
||||
}
|
||||
}
|
||||
|
||||
function pushMutatorDefine({ objId, body, getMutatorId, scope }, prop) {
|
||||
function pushMutatorDefine({ body, getMutatorId, scope }, prop) {
|
||||
let key =
|
||||
!prop.computed && t.isIdentifier(prop.key)
|
||||
? t.stringLiteral(prop.key.name)
|
||||
|
||||
@@ -16,7 +16,10 @@ export default function(code: string, opts?: Object): Function {
|
||||
} catch (error) {
|
||||
if (error.stack) {
|
||||
// error.stack does not exists in IE <= 9
|
||||
stack = error.stack.split("\n").slice(1).join("\n");
|
||||
stack = error.stack
|
||||
.split("\n")
|
||||
.slice(1)
|
||||
.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,9 @@ export function ConditionalExpression() {
|
||||
}
|
||||
|
||||
export function SequenceExpression() {
|
||||
return this.get("expressions").pop().getTypeAnnotation();
|
||||
return this.get("expressions")
|
||||
.pop()
|
||||
.getTypeAnnotation();
|
||||
}
|
||||
|
||||
export function AssignmentExpression() {
|
||||
|
||||
@@ -243,7 +243,10 @@ export default class Scope {
|
||||
*/
|
||||
|
||||
generateUid(name: string = "temp") {
|
||||
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
||||
name = t
|
||||
.toIdentifier(name)
|
||||
.replace(/^_+/, "")
|
||||
.replace(/[0-9]+$/g, "");
|
||||
|
||||
let uid;
|
||||
let i = 0;
|
||||
|
||||
@@ -18,14 +18,18 @@ describe("evaluation", function() {
|
||||
describe("evaluateTruthy", function() {
|
||||
it("it should work with null", function() {
|
||||
assert.strictEqual(
|
||||
getPath("false || a.length === 0;").get("body")[0].evaluateTruthy(),
|
||||
getPath("false || a.length === 0;")
|
||||
.get("body")[0]
|
||||
.evaluateTruthy(),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it("it should not mistake lack of confidence for falsy", function() {
|
||||
assert.strictEqual(
|
||||
getPath("foo || 'bar'").get("body")[0].evaluate().value,
|
||||
getPath("foo || 'bar'")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
@@ -100,12 +104,15 @@ describe("evaluation", function() {
|
||||
const input =
|
||||
"var a = 5; function x() { var a = 5; var b = a + 1; } var b = a + 2";
|
||||
assert.strictEqual(
|
||||
getPath(input).get("body.1.body.body.1.declarations.0.init").evaluate()
|
||||
.value,
|
||||
getPath(input)
|
||||
.get("body.1.body.body.1.declarations.0.init")
|
||||
.evaluate().value,
|
||||
6,
|
||||
);
|
||||
assert.strictEqual(
|
||||
getPath(input).get("body.2.declarations.0.init").evaluate().value,
|
||||
getPath(input)
|
||||
.get("body.2.declarations.0.init")
|
||||
.evaluate().value,
|
||||
7,
|
||||
);
|
||||
});
|
||||
@@ -120,11 +127,15 @@ describe("evaluation", function() {
|
||||
const constExample =
|
||||
"const d = true; if (d && true || false) { const d = false; d && 5; }";
|
||||
assert.strictEqual(
|
||||
getPath(constExample).get("body.1.test").evaluate().value,
|
||||
getPath(constExample)
|
||||
.get("body.1.test")
|
||||
.evaluate().value,
|
||||
true,
|
||||
);
|
||||
assert.strictEqual(
|
||||
getPath(constExample).get("body.1.consequent.body.1").evaluate().value,
|
||||
getPath(constExample)
|
||||
.get("body.1.consequent.body.1")
|
||||
.evaluate().value,
|
||||
false,
|
||||
);
|
||||
const test_alternate = "var y = (3 < 4)? 3 + 4: 3 + 4;";
|
||||
@@ -153,15 +164,21 @@ describe("evaluation", function() {
|
||||
|
||||
it("should evaluate undefined, NaN and Infinity", () => {
|
||||
assert.strictEqual(
|
||||
getPath("undefined").get("body.0.expression").evaluate().confident,
|
||||
getPath("undefined")
|
||||
.get("body.0.expression")
|
||||
.evaluate().confident,
|
||||
true,
|
||||
);
|
||||
assert.strictEqual(
|
||||
getPath("NaN").get("body.0.expression").evaluate().confident,
|
||||
getPath("NaN")
|
||||
.get("body.0.expression")
|
||||
.evaluate().confident,
|
||||
true,
|
||||
);
|
||||
assert.strictEqual(
|
||||
getPath("Infinity").get("body.0.expression").evaluate().confident,
|
||||
getPath("Infinity")
|
||||
.get("body.0.expression")
|
||||
.evaluate().confident,
|
||||
true,
|
||||
);
|
||||
});
|
||||
@@ -186,12 +203,16 @@ describe("evaluation", function() {
|
||||
|
||||
it("should work with String.raw", function() {
|
||||
assert.strictEqual(
|
||||
getPath("String.raw`\\d`").get("body")[0].evaluate().value,
|
||||
getPath("String.raw`\\d`")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
"\\d",
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
getPath("`${String.raw`\\d`}`").get("body")[0].evaluate().value,
|
||||
getPath("`${String.raw`\\d`}`")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
"\\d",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -64,28 +64,36 @@ describe("inference", function() {
|
||||
});
|
||||
describe("getTypeAnnotation", function() {
|
||||
it("should infer from type cast", function() {
|
||||
const path = getPath("(x: number)").get("body")[0].get("expression");
|
||||
const path = getPath("(x: number)")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isNumberTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be number",
|
||||
);
|
||||
});
|
||||
it("should infer string from template literal", function() {
|
||||
const path = getPath("`hey`").get("body")[0].get("expression");
|
||||
const path = getPath("`hey`")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isStringTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be string",
|
||||
);
|
||||
});
|
||||
it("should infer number from +x", function() {
|
||||
const path = getPath("+x").get("body")[0].get("expression");
|
||||
const path = getPath("+x")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isNumberTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be number",
|
||||
);
|
||||
});
|
||||
it("should infer T from new T", function() {
|
||||
const path = getPath("new T").get("body")[0].get("expression");
|
||||
const path = getPath("new T")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "T",
|
||||
@@ -93,49 +101,63 @@ describe("inference", function() {
|
||||
);
|
||||
});
|
||||
it("should infer number from ++x", function() {
|
||||
const path = getPath("++x").get("body")[0].get("expression");
|
||||
const path = getPath("++x")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isNumberTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be number",
|
||||
);
|
||||
});
|
||||
it("should infer number from --x", function() {
|
||||
const path = getPath("--x").get("body")[0].get("expression");
|
||||
const path = getPath("--x")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isNumberTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be number",
|
||||
);
|
||||
});
|
||||
it("should infer void from void x", function() {
|
||||
const path = getPath("void x").get("body")[0].get("expression");
|
||||
const path = getPath("void x")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isVoidTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be void",
|
||||
);
|
||||
});
|
||||
it("should infer string from typeof x", function() {
|
||||
const path = getPath("typeof x").get("body")[0].get("expression");
|
||||
const path = getPath("typeof x")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isStringTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be string",
|
||||
);
|
||||
});
|
||||
it("should infer boolean from !x", function() {
|
||||
const path = getPath("!x").get("body")[0].get("expression");
|
||||
const path = getPath("!x")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isBooleanTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be boolean",
|
||||
);
|
||||
});
|
||||
it("should infer type of sequence expression", function() {
|
||||
const path = getPath("a,1").get("body")[0].get("expression");
|
||||
const path = getPath("a,1")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
assert.ok(
|
||||
t.isNumberTypeAnnotation(path.getTypeAnnotation()),
|
||||
"should be number",
|
||||
);
|
||||
});
|
||||
it("should infer type of logical expression", function() {
|
||||
const path = getPath("'a' && 1").get("body")[0].get("expression");
|
||||
const path = getPath("'a' && 1")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isUnionTypeAnnotation(type), "should be a union");
|
||||
assert.ok(
|
||||
@@ -148,7 +170,9 @@ describe("inference", function() {
|
||||
);
|
||||
});
|
||||
it("should infer type of conditional expression", function() {
|
||||
const path = getPath("q ? true : 0").get("body")[0].get("expression");
|
||||
const path = getPath("q ? true : 0")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isUnionTypeAnnotation(type), "should be a union");
|
||||
assert.ok(
|
||||
@@ -161,7 +185,9 @@ describe("inference", function() {
|
||||
);
|
||||
});
|
||||
it("should infer RegExp from RegExp literal", function() {
|
||||
const path = getPath("/.+/").get("body")[0].get("expression");
|
||||
const path = getPath("/.+/")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "RegExp",
|
||||
@@ -169,7 +195,9 @@ describe("inference", function() {
|
||||
);
|
||||
});
|
||||
it("should infer Object from object expression", function() {
|
||||
const path = getPath("({ a: 5 })").get("body")[0].get("expression");
|
||||
const path = getPath("({ a: 5 })")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "Object",
|
||||
@@ -177,7 +205,9 @@ describe("inference", function() {
|
||||
);
|
||||
});
|
||||
it("should infer Array from array expression", function() {
|
||||
const path = getPath("[ 5 ]").get("body")[0].get("expression");
|
||||
const path = getPath("[ 5 ]")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "Array",
|
||||
@@ -222,22 +252,30 @@ describe("inference", function() {
|
||||
);
|
||||
});
|
||||
it("should infer number from x/y", function() {
|
||||
const path = getPath("x/y").get("body")[0].get("expression");
|
||||
const path = getPath("x/y")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isNumberTypeAnnotation(type), "should be number");
|
||||
});
|
||||
it("should infer boolean from x instanceof y", function() {
|
||||
const path = getPath("x instanceof y").get("body")[0].get("expression");
|
||||
const path = getPath("x instanceof y")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isBooleanTypeAnnotation(type), "should be boolean");
|
||||
});
|
||||
it("should infer number from 1 + 2", function() {
|
||||
const path = getPath("1 + 2").get("body")[0].get("expression");
|
||||
const path = getPath("1 + 2")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isNumberTypeAnnotation(type), "should be number");
|
||||
});
|
||||
it("should infer string|number from x + y", function() {
|
||||
const path = getPath("x + y").get("body")[0].get("expression");
|
||||
const path = getPath("x + y")
|
||||
.get("body")[0]
|
||||
.get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isUnionTypeAnnotation(type), "should be a union");
|
||||
assert.ok(
|
||||
|
||||
@@ -24,7 +24,10 @@ describe("removal", function() {
|
||||
describe("ArrowFunction", function() {
|
||||
it("remove body", function() {
|
||||
const rootPath = getPath("x = () => b;");
|
||||
const path = rootPath.get("body")[0].get("expression").get("right");
|
||||
const path = rootPath
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.get("right");
|
||||
const body = path.get("body");
|
||||
body.remove();
|
||||
|
||||
|
||||
@@ -75,11 +75,22 @@ describe("scope", function() {
|
||||
|
||||
it("purity", function() {
|
||||
assert.ok(
|
||||
getPath("({ x: 1 })").get("body")[0].get("expression").isPure(),
|
||||
getPath("({ x: 1 })")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
);
|
||||
assert.ok(!getPath("`${a}`").get("body")[0].get("expression").isPure());
|
||||
assert.ok(
|
||||
getPath("let a = 1; `${a}`").get("body")[1].get("expression").isPure(),
|
||||
!getPath("`${a}`")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
);
|
||||
assert.ok(
|
||||
getPath("let a = 1; `${a}`")
|
||||
.get("body")[1]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
);
|
||||
assert.ok(
|
||||
!getPath("let a = 1; `${a++}`")
|
||||
@@ -88,10 +99,16 @@ describe("scope", function() {
|
||||
.isPure(),
|
||||
);
|
||||
assert.ok(
|
||||
!getPath("tagged`foo`").get("body")[0].get("expression").isPure(),
|
||||
!getPath("tagged`foo`")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
);
|
||||
assert.ok(
|
||||
getPath("String.raw`foo`").get("body")[0].get("expression").isPure(),
|
||||
getPath("String.raw`foo`")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
2
packages/babel-types/src/react.js
vendored
2
packages/babel-types/src/react.js
vendored
@@ -3,7 +3,7 @@ import * as t from "./index";
|
||||
export const isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
|
||||
export function isCompatTag(tagName?: string): boolean {
|
||||
return !!tagName && /^[a-z]|\-/.test(tagName);
|
||||
return !!tagName && /^[a-z]|-/.test(tagName);
|
||||
}
|
||||
|
||||
function cleanJSXElementLiteralChild(
|
||||
|
||||
Reference in New Issue
Block a user