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