Update prettier to v2 (#11579)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
parent
426acf336e
commit
4108524856
@ -57,7 +57,7 @@
|
||||
"lodash": "^4.17.13",
|
||||
"mergeiterator": "^1.2.5",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"prettier": "^1.19.1",
|
||||
"prettier": "^2.0.5",
|
||||
"pump": "^3.0.0",
|
||||
"rimraf": "^2.6.3",
|
||||
"rollup": "1.27.9",
|
||||
|
||||
@ -135,10 +135,11 @@ export default function* loadPrivatePartialConfig(
|
||||
};
|
||||
}
|
||||
|
||||
export const loadPartialConfig = gensync<[any], PartialConfig | null>(function*(
|
||||
inputOpts: mixed,
|
||||
): Handler<PartialConfig | null> {
|
||||
const result: ?PrivPartialConfig = yield* loadPrivatePartialConfig(inputOpts);
|
||||
export const loadPartialConfig = gensync<[any], PartialConfig | null>(
|
||||
function* (inputOpts: mixed): Handler<PartialConfig | null> {
|
||||
const result: ?PrivPartialConfig = yield* loadPrivatePartialConfig(
|
||||
inputOpts,
|
||||
);
|
||||
if (!result) return null;
|
||||
|
||||
const { options, babelrc, ignore, config } = result;
|
||||
@ -158,7 +159,8 @@ export const loadPartialConfig = gensync<[any], PartialConfig | null>(function*(
|
||||
ignore ? ignore.filepath : undefined,
|
||||
config ? config.filepath : undefined,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
export type { PartialConfig };
|
||||
|
||||
|
||||
@ -534,7 +534,9 @@ describe("api", function() {
|
||||
});
|
||||
|
||||
it("ast option false", function () {
|
||||
return transformAsync("foo('bar');", { ast: false }).then(function(result) {
|
||||
return transformAsync("foo('bar');", { ast: false }).then(function (
|
||||
result,
|
||||
) {
|
||||
expect(result.ast).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -294,10 +294,7 @@ export default class ImportInjector {
|
||||
builder.var(importedSource).read(importName);
|
||||
}
|
||||
} else if (isDefault) {
|
||||
builder
|
||||
.var(name)
|
||||
.defaultInterop()
|
||||
.prop(importName);
|
||||
builder.var(name).defaultInterop().prop(importName);
|
||||
} else if (isNamed) {
|
||||
builder.var(name).prop(importName);
|
||||
}
|
||||
|
||||
@ -26,8 +26,9 @@ class FixtureError extends Error {
|
||||
{ highlightCode: true },
|
||||
) +
|
||||
"\n" +
|
||||
`at fixture (${fixturePath}:${previousError.loc.line}:${previousError
|
||||
.loc.column + 1})\n`;
|
||||
`at fixture (${fixturePath}:${previousError.loc.line}:${
|
||||
previousError.loc.column + 1
|
||||
})\n`;
|
||||
}
|
||||
|
||||
this.stack =
|
||||
@ -36,10 +37,7 @@ class FixtureError extends Error {
|
||||
previousError.message +
|
||||
"\n" +
|
||||
fixtureStackFrame +
|
||||
previousError.stack
|
||||
.split("\n")
|
||||
.slice(messageLines)
|
||||
.join("\n");
|
||||
previousError.stack.split("\n").slice(messageLines).join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,10 +8,7 @@ import type { Targets } from "@babel/helper-compilation-targets";
|
||||
export const has = Object.hasOwnProperty.call.bind(Object.hasOwnProperty);
|
||||
|
||||
export function getType(target: any): string {
|
||||
return Object.prototype.toString
|
||||
.call(target)
|
||||
.slice(8, -1)
|
||||
.toLowerCase();
|
||||
return Object.prototype.toString.call(target).slice(8, -1).toLowerCase();
|
||||
}
|
||||
|
||||
export function intersection<T>(
|
||||
|
||||
@ -113,10 +113,7 @@ function extendedTrace<Arg, Result>(fn: Arg => Result): Arg => Result {
|
||||
// 'extendedTrace', and the anonymous builder function, with the final
|
||||
// stripped line being the error message itself since we threw it
|
||||
// in the first place and it doesn't matter.
|
||||
rootStack = error.stack
|
||||
.split("\n")
|
||||
.slice(3)
|
||||
.join("\n");
|
||||
rootStack = error.stack.split("\n").slice(3).join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -117,9 +117,7 @@ export function ConditionalExpression() {
|
||||
}
|
||||
|
||||
export function SequenceExpression() {
|
||||
return this.get("expressions")
|
||||
.pop()
|
||||
.getTypeAnnotation();
|
||||
return this.get("expressions").pop().getTypeAnnotation();
|
||||
}
|
||||
|
||||
export function ParenthesizedExpression() {
|
||||
|
||||
@ -17,17 +17,13 @@ describe("evaluation", function() {
|
||||
describe("evaluateTruthy", function () {
|
||||
it("it should work with null", function () {
|
||||
expect(
|
||||
getPath("false || a.length === 0;")
|
||||
.get("body")[0]
|
||||
.evaluateTruthy(),
|
||||
getPath("false || a.length === 0;").get("body")[0].evaluateTruthy(),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("it should not mistake lack of confidence for falsy", function () {
|
||||
expect(
|
||||
getPath("foo || 'bar'")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
getPath("foo || 'bar'").get("body")[0].evaluate().value,
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@ -41,26 +37,14 @@ describe("evaluation", function() {
|
||||
});
|
||||
|
||||
it("should short-circuit && and ||", function () {
|
||||
expect(
|
||||
getPath("x === 'y' || 42")
|
||||
.get("body")[0]
|
||||
.evaluate().confident,
|
||||
).toBe(false);
|
||||
expect(
|
||||
getPath("x === 'y' && 0")
|
||||
.get("body")[0]
|
||||
.evaluate().confident,
|
||||
).toBe(false);
|
||||
expect(
|
||||
getPath("42 || x === 'y'")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
).toBe(42);
|
||||
expect(
|
||||
getPath("0 && x === 'y'")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
).toBe(0);
|
||||
expect(getPath("x === 'y' || 42").get("body")[0].evaluate().confident).toBe(
|
||||
false,
|
||||
);
|
||||
expect(getPath("x === 'y' && 0").get("body")[0].evaluate().confident).toBe(
|
||||
false,
|
||||
);
|
||||
expect(getPath("42 || x === 'y'").get("body")[0].evaluate().value).toBe(42);
|
||||
expect(getPath("0 && x === 'y'").get("body")[0].evaluate().value).toBe(0);
|
||||
});
|
||||
|
||||
it("should work with repeated, indeterminate identifiers", function () {
|
||||
@ -118,14 +102,11 @@ describe("evaluation", function() {
|
||||
const input =
|
||||
"var a = 5; function x() { var a = 5; var b = a + 1; } var b = a + 2";
|
||||
expect(
|
||||
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,
|
||||
).toBe(6);
|
||||
expect(
|
||||
getPath(input)
|
||||
.get("body.2.declarations.0.init")
|
||||
.evaluate().value,
|
||||
getPath(input).get("body.2.declarations.0.init").evaluate().value,
|
||||
).toBe(7);
|
||||
});
|
||||
|
||||
@ -137,15 +118,11 @@ describe("evaluation", function() {
|
||||
).toBe(10);
|
||||
const constExample =
|
||||
"const d = true; if (d && true || false) { const d = false; d && 5; }";
|
||||
expect(getPath(constExample).get("body.1.test").evaluate().value).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
getPath(constExample)
|
||||
.get("body.1.test")
|
||||
.evaluate().value,
|
||||
).toBe(true);
|
||||
expect(
|
||||
getPath(constExample)
|
||||
.get("body.1.consequent.body.1")
|
||||
.evaluate().value,
|
||||
getPath(constExample).get("body.1.consequent.body.1").evaluate().value,
|
||||
).toBe(false);
|
||||
const test_alternate = "var y = (3 < 4)? 3 + 4: 3 + 4;";
|
||||
expect(
|
||||
@ -170,19 +147,13 @@ describe("evaluation", function() {
|
||||
|
||||
it("should evaluate undefined, NaN and Infinity", () => {
|
||||
expect(
|
||||
getPath("undefined")
|
||||
.get("body.0.expression")
|
||||
.evaluate().confident,
|
||||
getPath("undefined").get("body.0.expression").evaluate().confident,
|
||||
).toBe(true);
|
||||
expect(getPath("NaN").get("body.0.expression").evaluate().confident).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
getPath("NaN")
|
||||
.get("body.0.expression")
|
||||
.evaluate().confident,
|
||||
).toBe(true);
|
||||
expect(
|
||||
getPath("Infinity")
|
||||
.get("body.0.expression")
|
||||
.evaluate().confident,
|
||||
getPath("Infinity").get("body.0.expression").evaluate().confident,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
@ -205,16 +176,12 @@ describe("evaluation", function() {
|
||||
});
|
||||
|
||||
it("should work with String.raw", function () {
|
||||
expect(
|
||||
getPath("String.raw`\\d`")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
).toBe("\\d");
|
||||
expect(getPath("String.raw`\\d`").get("body")[0].evaluate().value).toBe(
|
||||
"\\d",
|
||||
);
|
||||
|
||||
expect(
|
||||
getPath("`${String.raw`\\d`}`")
|
||||
.get("body")[0]
|
||||
.evaluate().value,
|
||||
getPath("`${String.raw`\\d`}`").get("body")[0].evaluate().value,
|
||||
).toBe("\\d");
|
||||
});
|
||||
|
||||
|
||||
@ -63,108 +63,78 @@ 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");
|
||||
expect(t.isNumberTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isStringTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isNumberTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "T",
|
||||
).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isNumberTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isNumberTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isVoidTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isStringTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isBooleanTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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");
|
||||
expect(t.isNumberTypeAnnotation(path.getTypeAnnotation())).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(t.isUnionTypeAnnotation(type)).toBeTruthy();
|
||||
expect(t.isStringTypeAnnotation(type.types[0])).toBeTruthy();
|
||||
expect(t.isNumberTypeAnnotation(type.types[1])).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(t.isUnionTypeAnnotation(type)).toBeTruthy();
|
||||
expect(t.isBooleanTypeAnnotation(type.types[0])).toBeTruthy();
|
||||
expect(t.isNumberTypeAnnotation(type.types[1])).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "RegExp",
|
||||
).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "Object",
|
||||
).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(
|
||||
t.isGenericTypeAnnotation(type) && type.id.name === "Array",
|
||||
@ -205,30 +175,22 @@ describe("inference", function() {
|
||||
).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(t.isNumberTypeAnnotation(type)).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(t.isBooleanTypeAnnotation(type)).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(t.isNumberTypeAnnotation(type)).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
expect(t.isUnionTypeAnnotation(type)).toBeTruthy();
|
||||
expect(t.isStringTypeAnnotation(type.types[0])).toBeTruthy();
|
||||
|
||||
@ -23,10 +23,7 @@ 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();
|
||||
|
||||
|
||||
@ -215,16 +215,10 @@ describe("scope", () => {
|
||||
.isPure(),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
getPath("`${a}`")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
getPath("`${a}`").get("body")[0].get("expression").isPure(),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
getPath("let a = 1; `${a}`")
|
||||
.get("body")[1]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
getPath("let a = 1; `${a}`").get("body")[1].get("expression").isPure(),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
getPath("let a = 1; `${a++}`")
|
||||
@ -233,16 +227,10 @@ describe("scope", () => {
|
||||
.isPure(),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
getPath("tagged`foo`")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
getPath("tagged`foo`").get("body")[0].get("expression").isPure(),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
getPath("String.raw`foo`")
|
||||
.get("body")[0]
|
||||
.get("expression")
|
||||
.isPure(),
|
||||
getPath("String.raw`foo`").get("body")[0].get("expression").isPure(),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
@ -240,10 +240,7 @@ for (const type in t.FLIPPED_ALIAS_KEYS) {
|
||||
}
|
||||
|
||||
code += `\ndeclare module "@babel/types" {
|
||||
${lines
|
||||
.join("\n")
|
||||
.replace(/\n/g, "\n ")
|
||||
.trim()}
|
||||
${lines.join("\n").replace(/\n/g, "\n ").trim()}
|
||||
}\n`;
|
||||
|
||||
//
|
||||
|
||||
@ -648,8 +648,9 @@ defineType("TemplateLiteral", {
|
||||
throw new TypeError(
|
||||
`Number of ${
|
||||
node.type
|
||||
} quasis should be exactly one more than the number of expressions.\nExpected ${val.length +
|
||||
1} quasis but got ${node.quasis.length}`,
|
||||
} quasis should be exactly one more than the number of expressions.\nExpected ${
|
||||
val.length + 1
|
||||
} quasis but got ${node.quasis.length}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@ -187,9 +187,7 @@ runner
|
||||
"The following Features are not currently mapped or ignored:"
|
||||
);
|
||||
console.log(
|
||||
Array.from(unmappedFeatures)
|
||||
.join("\n")
|
||||
.replace(/^/gm, " ")
|
||||
Array.from(unmappedFeatures).join("\n").replace(/^/gm, " ")
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,4 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
// TODO: Remove this `if` in Babel 8
|
||||
// Prettier only supports Node.js 10+, so we can fallback to not formatting
|
||||
// o CI on older Node.js versions
|
||||
|
||||
if (process.env.CI && parseInt(process.versions.node, 10) < 10) {
|
||||
module.exports = function formatCode(code) {
|
||||
return code;
|
||||
};
|
||||
} else {
|
||||
const prettier = require("prettier");
|
||||
|
||||
module.exports = function formatCode(code, filename) {
|
||||
@ -9,3 +19,4 @@ module.exports = function formatCode(code, filename) {
|
||||
|
||||
return prettier.format(code, prettierConfig);
|
||||
};
|
||||
}
|
||||
|
||||
@ -8436,10 +8436,10 @@ prettier-linter-helpers@^1.0.0:
|
||||
dependencies:
|
||||
fast-diff "^1.1.2"
|
||||
|
||||
prettier@^1.19.1:
|
||||
version "1.19.1"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
|
||||
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
|
||||
prettier@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
|
||||
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
|
||||
|
||||
pretty-format@^24.9.0:
|
||||
version "24.9.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user