chore: run format
This commit is contained in:
parent
d7f404ed63
commit
ed236b84d6
7 changed files with 55 additions and 118 deletions
26
.github/workflows/main.yml
vendored
26
.github/workflows/main.yml
vendored
|
|
@ -2,9 +2,9 @@ name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
|
@ -12,18 +12,18 @@ jobs:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node_version: ['12.x', '14.x', '16.x', '18.x', '19.x', '20.x']
|
node_version: ["12.x", "14.x", "16.x", "18.x", "19.x", "20.x"]
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Use Node.js ${{ matrix.node_version }}
|
- name: Use Node.js ${{ matrix.node_version }}
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node_version }}
|
node-version: ${{ matrix.node_version }}
|
||||||
|
|
||||||
- name: npm install, build and test
|
- name: npm install, build and test
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm run build --if-present
|
npm run build --if-present
|
||||||
npm test
|
npm test
|
||||||
|
|
|
||||||
|
|
@ -1474,10 +1474,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
|
|
||||||
case "ClassAccessorProperty": {
|
case "ClassAccessorProperty": {
|
||||||
parts.push(
|
parts.push(...printClassMemberModifiers(n), "accessor ");
|
||||||
...printClassMemberModifiers(n),
|
|
||||||
"accessor ",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (n.computed) {
|
if (n.computed) {
|
||||||
parts.push("[", path.call(print, "key"), "]");
|
parts.push("[", path.call(print, "key"), "]");
|
||||||
|
|
@ -2236,7 +2233,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
|
||||||
return member.concat(";");
|
return member.concat(";");
|
||||||
}
|
}
|
||||||
return member;
|
return member;
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (members.isEmpty()) {
|
if (members.isEmpty()) {
|
||||||
|
|
@ -2289,8 +2286,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
|
||||||
return concat([path.call(print, "left"), ".", path.call(print, "right")]);
|
return concat([path.call(print, "left"), ".", path.call(print, "right")]);
|
||||||
|
|
||||||
case "TSAsExpression":
|
case "TSAsExpression":
|
||||||
case "TSSatisfiesExpression":
|
case "TSSatisfiesExpression": {
|
||||||
{
|
|
||||||
const expression = path.call(print, "expression");
|
const expression = path.call(print, "expression");
|
||||||
parts.push(
|
parts.push(
|
||||||
expression,
|
expression,
|
||||||
|
|
@ -2478,7 +2474,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
|
||||||
return element.concat(";");
|
return element.concat(";");
|
||||||
}
|
}
|
||||||
return element;
|
return element;
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
if (lines.isEmpty()) {
|
if (lines.isEmpty()) {
|
||||||
return fromString("{}", options);
|
return fromString("{}", options);
|
||||||
|
|
@ -2585,7 +2581,6 @@ function genericPrintNoParens(path: any, options: any, print: any) {
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://github.com/babel/babel/pull/10148
|
// https://github.com/babel/babel/pull/10148
|
||||||
case "V8IntrinsicIdentifier":
|
case "V8IntrinsicIdentifier":
|
||||||
return concat(["%", path.call(print, "name")]);
|
return concat(["%", path.call(print, "name")]);
|
||||||
|
|
|
||||||
|
|
@ -454,27 +454,32 @@ describe("Babel", function () {
|
||||||
["class A {", " declare public readonly x;", "}"].join(eol),
|
["class A {", " declare public readonly x;", "}"].join(eol),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should keep braces in !(a && b)", function () {
|
it("should keep braces in !(a && b)", function () {
|
||||||
const code = '(options || !options.bidirectional) ? false : true;';
|
const code = "(options || !options.bidirectional) ? false : true;";
|
||||||
const ast = recast.parse(code, parseOptions);
|
const ast = recast.parse(code, parseOptions);
|
||||||
|
|
||||||
ast.program.body[0].expression = b.unaryExpression('!', ast.program.body[0].expression.test);
|
ast.program.body[0].expression = b.unaryExpression(
|
||||||
|
"!",
|
||||||
|
ast.program.body[0].expression.test,
|
||||||
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
recast.print(ast).code,
|
recast.print(ast).code,
|
||||||
'!(options || !options.bidirectional);',
|
"!(options || !options.bidirectional);",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use single quotes", function () {
|
it("should use single quotes", function () {
|
||||||
const code = 'const a = 1;';
|
const code = "const a = 1;";
|
||||||
const ast = recast.parse(code, parseOptions);
|
const ast = recast.parse(code, parseOptions);
|
||||||
|
|
||||||
ast.program.body.unshift(b.expressionStatement(b.stringLiteral('use strict')));
|
ast.program.body.unshift(
|
||||||
|
b.expressionStatement(b.stringLiteral("use strict")),
|
||||||
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
recast.print(ast, {quote: 'single'}).code,
|
recast.print(ast, { quote: "single" }).code,
|
||||||
`'use strict';\nconst a = 1;`,
|
`'use strict';\nconst a = 1;`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -490,9 +495,6 @@ describe("Babel", function () {
|
||||||
];
|
];
|
||||||
const ast = recast.parse(code.join(eol), parseOptions);
|
const ast = recast.parse(code.join(eol), parseOptions);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(recast.prettyPrint(ast).code, code.join(eol));
|
||||||
recast.prettyPrint(ast).code,
|
|
||||||
code.join(eol),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1174,11 +1174,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints class property initializers with type annotations correctly", function () {
|
it("prints class property initializers with type annotations correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " foo = (a: b): void => {};", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" foo = (a: b): void => {};",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const arg = b.identifier("a");
|
const arg = b.identifier("a");
|
||||||
arg.typeAnnotation = b.typeAnnotation(
|
arg.typeAnnotation = b.typeAnnotation(
|
||||||
|
|
@ -1204,11 +1200,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints ClassProperty correctly", function () {
|
it("prints ClassProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " foo: Type = Bar;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" foo: Type = Bar;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1234,11 +1226,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints 'definite' ClassProperty correctly", function () {
|
it("prints 'definite' ClassProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " foo!: string;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" foo!: string;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1265,11 +1253,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints static ClassProperty correctly", function () {
|
it("prints static ClassProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " static foo = Bar;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" static foo = Bar;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1289,11 +1273,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints ClassAccessorProperty correctly", function () {
|
it("prints ClassAccessorProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " accessor foo: Type = Bar;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" accessor foo: Type = Bar;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1304,8 +1284,8 @@ describe("printer", function () {
|
||||||
value: b.identifier("Bar"),
|
value: b.identifier("Bar"),
|
||||||
typeAnnotation: b.tsTypeAnnotation(
|
typeAnnotation: b.tsTypeAnnotation(
|
||||||
b.tsTypeReference(b.identifier("Type")),
|
b.tsTypeReference(b.identifier("Type")),
|
||||||
)
|
),
|
||||||
})
|
}),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
@ -1319,11 +1299,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints 'definite' ClassAccessorProperty correctly", function () {
|
it("prints 'definite' ClassAccessorProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " accessor foo!: string;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" accessor foo!: string;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1347,11 +1323,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints static ClassAccessorProperty correctly", function () {
|
it("prints static ClassAccessorProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " static accessor foo = Bar;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" static accessor foo = Bar;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1375,11 +1347,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints abstract ClassAccessorProperty correctly", function () {
|
it("prints abstract ClassAccessorProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " abstract accessor foo = Bar;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" abstract accessor foo = Bar;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
@ -1403,11 +1371,7 @@ describe("printer", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints override ClassAccessorProperty correctly", function () {
|
it("prints override ClassAccessorProperty correctly", function () {
|
||||||
const code = [
|
const code = ["class A {", " override accessor foo = Bar;", "}"].join(eol);
|
||||||
"class A {",
|
|
||||||
" override accessor foo = Bar;",
|
|
||||||
"}",
|
|
||||||
].join(eol);
|
|
||||||
|
|
||||||
const ast = b.program([
|
const ast = b.program([
|
||||||
b.classDeclaration(
|
b.classDeclaration(
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(types.namedTypes).forEach(name => {
|
Object.keys(types.namedTypes).forEach((name) => {
|
||||||
it(name, () => {
|
it(name, () => {
|
||||||
assert.ok(hasOwn.call(typeNames, name), "unhandled type: " + name);
|
assert.ok(hasOwn.call(typeNames, name), "unhandled type: " + name);
|
||||||
assert.strictEqual(name, typeNames[name]);
|
assert.strictEqual(name, typeNames[name]);
|
||||||
|
|
|
||||||
|
|
@ -278,17 +278,13 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
||||||
check([
|
check([
|
||||||
"class Dog extends Animal {",
|
"class Dog extends Animal {",
|
||||||
" protected override getSound() {",
|
" protected override getSound() {",
|
||||||
" return \"bark\";",
|
' return "bark";',
|
||||||
" }",
|
" }",
|
||||||
"}",
|
"}",
|
||||||
])
|
|
||||||
|
|
||||||
check([
|
|
||||||
"export interface S {",
|
|
||||||
" i(s: string): boolean;",
|
|
||||||
"}"
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
check(["export interface S {", " i(s: string): boolean;", "}"]);
|
||||||
|
|
||||||
check([
|
check([
|
||||||
"namespace Validation {",
|
"namespace Validation {",
|
||||||
" export interface S {",
|
" export interface S {",
|
||||||
|
|
@ -297,17 +293,9 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
||||||
"}",
|
"}",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
check([
|
check(["export interface S {", " i(j: string): boolean;", "}"]);
|
||||||
"export interface S {",
|
|
||||||
" i(j: string): boolean;",
|
|
||||||
"}",
|
|
||||||
]);
|
|
||||||
|
|
||||||
check([
|
check(["declare namespace D3 {", " export const f: number;", "}"]);
|
||||||
"declare namespace D3 {",
|
|
||||||
" export const f: number;",
|
|
||||||
"}",
|
|
||||||
]);
|
|
||||||
|
|
||||||
check(["declare function foo<K, V>(arg: T = getDefault()): R"]);
|
check(["declare function foo<K, V>(arg: T = getDefault()): R"]);
|
||||||
|
|
||||||
|
|
@ -317,13 +305,7 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
||||||
"}",
|
"}",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
check([
|
check(["function myFunction(", " {", " param1", " }: Params", ") {}"]);
|
||||||
"function myFunction(",
|
|
||||||
" {",
|
|
||||||
" param1",
|
|
||||||
" }: Params",
|
|
||||||
") {}",
|
|
||||||
]);
|
|
||||||
|
|
||||||
check([
|
check([
|
||||||
'const unqualified: import("package") = 1;',
|
'const unqualified: import("package") = 1;',
|
||||||
|
|
@ -354,8 +336,8 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
||||||
check([
|
check([
|
||||||
"type alias = boolean;",
|
"type alias = boolean;",
|
||||||
"const value = 0;",
|
"const value = 0;",
|
||||||
"export { type alias, value };"
|
"export { type alias, value };",
|
||||||
])
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("InterfaceBody: duplicate semicolon", function () {
|
it("InterfaceBody: duplicate semicolon", function () {
|
||||||
|
|
@ -461,11 +443,8 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
||||||
|
|
||||||
const ast = recast.parse(code, { parser });
|
const ast = recast.parse(code, { parser });
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(recast.prettyPrint(ast).code, code);
|
||||||
recast.prettyPrint(ast).code,
|
});
|
||||||
code
|
|
||||||
);
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testReprinting(
|
testReprinting(
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,5 @@
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"stripInternal": true
|
"stripInternal": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["node_modules", "test/data"]
|
||||||
"node_modules",
|
|
||||||
"test/data"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue