Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support type annotations on auto accessors via babel-ts #14049

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog_unreleased/typescript/14049.md
@@ -0,0 +1,10 @@
#### Support type annotations on auto accessors via `babel-ts` (#14049 by @sosukesuzuki)

[The bug that `@babel/parser` cannot parse auto accessors with type annotations](https://github.com/babel/babel/issues/15205) has been fixed. So we now support it via `babel-ts` parser.

<!-- prettier-ignore -->
```tsx
class Foo {
accessor prop: number;
}
```
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@angular/compiler": "12.2.16",
"@babel/code-frame": "7.16.7",
"@babel/parser": "7.20.1",
"@babel/parser": "7.20.7",
"@glimmer/syntax": "0.84.2",
"@iarna/toml": "2.2.5",
"@typescript-eslint/typescript-estree": "5.45.0",
Expand Down
Expand Up @@ -44,7 +44,7 @@ exports[`getter-with-parameter.js [acorn] format 1`] = `
`;

exports[`getter-with-parameter.js [babel] format 1`] = `
"A 'get' accesor must not have any formal parameters. (1:4)
"A 'get' accessor must not have any formal parameters. (1:4)
> 1 | ({ get x(a){} });
| ^
2 |"
Expand Down Expand Up @@ -108,7 +108,7 @@ exports[`setter-without-parameter.js [acorn] format 1`] = `
`;

exports[`setter-without-parameter.js [babel] format 1`] = `
"A 'set' accesor must have exactly one formal parameter. (1:4)
"A 'set' accessor must have exactly one formal parameter. (1:4)
> 1 | ({ set x(){} });
| ^
2 |"
Expand Down
57 changes: 0 additions & 57 deletions tests/format/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -406,63 +406,6 @@ class Foo {
================================================================================
`;

exports[`decorator-auto-accessors-type-annotations.ts - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
abstract class Foo {
accessor prop: number = 1;
static accessor prop2: number = 1;
accessor #prop3: number = 1;
accessor [prop4]: number = 1;
private accessor prop5: number = 1;
abstract accessor prop6: number;
}

=====================================output=====================================
abstract class Foo {
accessor prop: number = 1
static accessor prop2: number = 1
accessor #prop3: number = 1
accessor [prop4]: number = 1
private accessor prop5: number = 1
abstract accessor prop6: number
}

================================================================================
`;

exports[`decorator-auto-accessors-type-annotations.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
abstract class Foo {
accessor prop: number = 1;
static accessor prop2: number = 1;
accessor #prop3: number = 1;
accessor [prop4]: number = 1;
private accessor prop5: number = 1;
abstract accessor prop6: number;
}

=====================================output=====================================
abstract class Foo {
accessor prop: number = 1;
static accessor prop2: number = 1;
accessor #prop3: number = 1;
accessor [prop4]: number = 1;
private accessor prop5: number = 1;
abstract accessor prop6: number;
}

================================================================================
`;

exports[`invalid-modifiers.ts - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
Expand Down
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`decorator-auto-accessors-type-annotations.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
abstract class Foo {
accessor prop: number = 1;
static accessor prop2: number = 1;
accessor #prop3: number = 1;
accessor [prop4]: number = 1;
private accessor prop5: number = 1;
abstract accessor prop6: number;
}

=====================================output=====================================
abstract class Foo {
accessor prop: number = 1;
static accessor prop2: number = 1;
accessor #prop3: number = 1;
accessor [prop4]: number = 1;
private accessor prop5: number = 1;
abstract accessor prop6: number;
}

================================================================================
`;
@@ -0,0 +1 @@
run_spec(__dirname, ["typescript"]);
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -273,10 +273,10 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/parser@7.20.1", "@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9":
version "7.20.1"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.20.1.tgz#3e045a92f7b4623cafc2425eddcb8cf2e54f9cc5"
integrity sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw==
"@babel/parser@7.20.7", "@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9":
version "7.20.7"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.20.7.tgz#66fe23b3c8569220817d5feb8b9dcdc95bb4f71b"
integrity sha512-T3Z9oHybU+0vZlY9CiDSJQTD5ZapcW18ZctFMi0MOAl/4BjFF4ul7NVSARLdbGO5vDqy9eQiGTV0LtKfvCYvcg==

"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.16.7":
version "7.16.7"
Expand Down