Skip to content

Commit

Permalink
Merge pull request #1389 from 43081j/format
Browse files Browse the repository at this point in the history
chore: run format
  • Loading branch information
eventualbuddha authored Mar 3, 2024
2 parents d7f404e + 3bc8b70 commit 2a9a88b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 118 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
test:
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
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]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}

- name: npm install, build and test
run: |
npm install
npm run build --if-present
npm test
- name: npm install, build and test
run: |
npm install
npm run build --if-present
npm run format:check
npm test
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
*.d.ts
test/data/
/example

# output files
/main.js
/lib/**/*.js
/parsers/**/*.js
/test/**/*.js
13 changes: 4 additions & 9 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
return concat(parts);

case "ClassAccessorProperty": {
parts.push(
...printClassMemberModifiers(n),
"accessor ",
);
parts.push(...printClassMemberModifiers(n), "accessor ");

if (n.computed) {
parts.push("[", path.call(print, "key"), "]");
Expand Down Expand Up @@ -2236,7 +2233,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
return member.concat(";");
}
return member;
})
}),
);

if (members.isEmpty()) {
Expand Down Expand Up @@ -2289,8 +2286,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
return concat([path.call(print, "left"), ".", path.call(print, "right")]);

case "TSAsExpression":
case "TSSatisfiesExpression":
{
case "TSSatisfiesExpression": {
const expression = path.call(print, "expression");
parts.push(
expression,
Expand Down Expand Up @@ -2478,7 +2474,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {
return element.concat(";");
}
return element;
})
}),
);
if (lines.isEmpty()) {
return fromString("{}", options);
Expand Down Expand Up @@ -2585,7 +2581,6 @@ function genericPrintNoParens(path: any, options: any, print: any) {
return concat(parts);
}


// https://github.com/babel/babel/pull/10148
case "V8IntrinsicIdentifier":
return concat(["%", path.call(print, "name")]);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build": "npm run clean && tsc",
"lint": "eslint --ext .ts .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"clean": "tsc --build --clean",
"prepare": "npm run build",
"postpack": "npm run clean"
Expand Down
28 changes: 15 additions & 13 deletions test/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,27 +454,32 @@ describe("Babel", function () {
["class A {", " declare public readonly x;", "}"].join(eol),
);
});

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);

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(
recast.print(ast).code,
'!(options || !options.bidirectional);',
"!(options || !options.bidirectional);",
);
});

it("should use single quotes", function () {
const code = 'const a = 1;';
const code = "const a = 1;";
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(
recast.print(ast, {quote: 'single'}).code,
recast.print(ast, { quote: "single" }).code,
`'use strict';\nconst a = 1;`,
);
});
Expand All @@ -490,9 +495,6 @@ describe("Babel", function () {
];
const ast = recast.parse(code.join(eol), parseOptions);

assert.strictEqual(
recast.prettyPrint(ast).code,
code.join(eol),
);
assert.strictEqual(recast.prettyPrint(ast).code, code.join(eol));
});
});
58 changes: 11 additions & 47 deletions test/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,7 @@ describe("printer", function () {
});

it("prints class property initializers with type annotations correctly", function () {
const code = [
"class A {",
" foo = (a: b): void => {};",
"}",
].join(eol);
const code = ["class A {", " foo = (a: b): void => {};", "}"].join(eol);

const arg = b.identifier("a");
arg.typeAnnotation = b.typeAnnotation(
Expand All @@ -1204,11 +1200,7 @@ describe("printer", function () {
});

it("prints ClassProperty correctly", function () {
const code = [
"class A {",
" foo: Type = Bar;",
"}",
].join(eol);
const code = ["class A {", " foo: Type = Bar;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1234,11 +1226,7 @@ describe("printer", function () {
});

it("prints 'definite' ClassProperty correctly", function () {
const code = [
"class A {",
" foo!: string;",
"}",
].join(eol);
const code = ["class A {", " foo!: string;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1265,11 +1253,7 @@ describe("printer", function () {
});

it("prints static ClassProperty correctly", function () {
const code = [
"class A {",
" static foo = Bar;",
"}",
].join(eol);
const code = ["class A {", " static foo = Bar;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1289,11 +1273,7 @@ describe("printer", function () {
});

it("prints ClassAccessorProperty correctly", function () {
const code = [
"class A {",
" accessor foo: Type = Bar;",
"}",
].join(eol);
const code = ["class A {", " accessor foo: Type = Bar;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1304,8 +1284,8 @@ describe("printer", function () {
value: b.identifier("Bar"),
typeAnnotation: b.tsTypeAnnotation(
b.tsTypeReference(b.identifier("Type")),
)
})
),
}),
]),
),
]);
Expand All @@ -1319,11 +1299,7 @@ describe("printer", function () {
});

it("prints 'definite' ClassAccessorProperty correctly", function () {
const code = [
"class A {",
" accessor foo!: string;",
"}",
].join(eol);
const code = ["class A {", " accessor foo!: string;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1347,11 +1323,7 @@ describe("printer", function () {
});

it("prints static ClassAccessorProperty correctly", function () {
const code = [
"class A {",
" static accessor foo = Bar;",
"}",
].join(eol);
const code = ["class A {", " static accessor foo = Bar;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1375,11 +1347,7 @@ describe("printer", function () {
});

it("prints abstract ClassAccessorProperty correctly", function () {
const code = [
"class A {",
" abstract accessor foo = Bar;",
"}",
].join(eol);
const code = ["class A {", " abstract accessor foo = Bar;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand All @@ -1403,11 +1371,7 @@ describe("printer", function () {
});

it("prints override ClassAccessorProperty correctly", function () {
const code = [
"class A {",
" override accessor foo = Bar;",
"}",
].join(eol);
const code = ["class A {", " override accessor foo = Bar;", "}"].join(eol);

const ast = b.program([
b.classDeclaration(
Expand Down
2 changes: 1 addition & 1 deletion test/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
assert.ok(hasOwn.call(typeNames, name), "unhandled type: " + name);
assert.strictEqual(name, typeNames[name]);
Expand Down
41 changes: 10 additions & 31 deletions test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,13 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
check([
"class Dog extends Animal {",
" protected override getSound() {",
" return \"bark\";",
' return "bark";',
" }",
"}",
])

check([
"export interface S {",
" i(s: string): boolean;",
"}"
]);

check(["export interface S {", " i(s: string): boolean;", "}"]);

check([
"namespace Validation {",
" export interface S {",
Expand All @@ -297,17 +293,9 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"}",
]);

check([
"export interface S {",
" i(j: string): boolean;",
"}",
]);
check(["export interface S {", " i(j: string): boolean;", "}"]);

check([
"declare namespace D3 {",
" export const f: number;",
"}",
]);
check(["declare namespace D3 {", " export const f: number;", "}"]);

check(["declare function foo<K, V>(arg: T = getDefault()): R"]);

Expand All @@ -317,13 +305,7 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"}",
]);

check([
"function myFunction(",
" {",
" param1",
" }: Params",
") {}",
]);
check(["function myFunction(", " {", " param1", " }: Params", ") {}"]);

check([
'const unqualified: import("package") = 1;',
Expand Down Expand Up @@ -354,8 +336,8 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
check([
"type alias = boolean;",
"const value = 0;",
"export { type alias, value };"
])
"export { type alias, value };",
]);
});

it("InterfaceBody: duplicate semicolon", function () {
Expand Down Expand Up @@ -461,11 +443,8 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);

const ast = recast.parse(code, { parser });

assert.strictEqual(
recast.prettyPrint(ast).code,
code
);
})
assert.strictEqual(recast.prettyPrint(ast).code, code);
});
});

testReprinting(
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@
"importHelpers": true,
"stripInternal": true
},
"exclude": [
"node_modules",
"test/data"
]
"exclude": ["node_modules", "test/data"]
}

0 comments on commit 2a9a88b

Please sign in to comment.