Skip to content

Commit 7aef98b

Browse files
authored
fix: support declare in classes (#218)
1 parent 7bbaf46 commit 7aef98b

4 files changed

Lines changed: 42 additions & 25 deletions

File tree

src/index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,25 @@ module.exports = {
3434
loader: 'babel-loader-8',
3535
options: {
3636
plugins: [
37-
// Transpile class properties
38-
// @see https://github.com/typed-ember/ember-cli-typescript/blob/b2e75abc98beefe635b6cfd8808c887813acb44e/ts/addon.ts#L99
39-
require.resolve('@babel/plugin-proposal-class-properties'),
37+
// https://github.com/babel/ember-cli-babel/blob/036723709e26aba68eee1d5a9df49f97944e435b/index.js#L359-L385
38+
[
39+
require.resolve('@babel/plugin-transform-typescript'),
40+
{ allowDeclareFields: true }
41+
],
42+
43+
// https://github.com/babel/ember-cli-babel/blob/036723709e26aba68eee1d5a9df49f97944e435b/index.js#L403-L409
44+
[
45+
require.resolve('@babel/plugin-proposal-decorators'),
46+
{ legacy: true }
47+
],
4048

41-
// Transpile new syntax, which is apparently not yet handled by
42-
// `@babel/preset-env`.
43-
// @see https://github.com/typed-ember/ember-cli-typescript/blob/b2e75abc98beefe635b6cfd8808c887813acb44e/ts/addon.ts#L89-L94
44-
require.resolve('@babel/plugin-proposal-optional-chaining'),
45-
require.resolve(
46-
'@babel/plugin-proposal-nullish-coalescing-operator'
47-
)
49+
// https://github.com/babel/ember-cli-babel/blob/036723709e26aba68eee1d5a9df49f97944e435b/index.js#L420-L426
50+
[
51+
require.resolve('@babel/plugin-proposal-class-properties'),
52+
{ loose: true }
53+
]
4854
],
4955
presets: [
50-
// Transpile TypeScript
51-
require.resolve('@babel/preset-typescript'),
5256
// Transpile incompatible syntax for project build targets
5357
[
5458
require.resolve('@babel/preset-env'),

src/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
"lint:js": "eslint --ext ts,js ."
1717
},
1818
"dependencies": {
19-
"@babel/plugin-proposal-class-properties": "^7.10.4",
20-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
21-
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
22-
"@babel/preset-env": "^7.12.1",
23-
"@babel/preset-typescript": "^7.12.1"
19+
"@babel/plugin-proposal-class-properties": "^7.12.1",
20+
"@babel/plugin-proposal-decorators": "^7.12.1",
21+
"@babel/plugin-transform-typescript": "^7.12.1",
22+
"@babel/preset-env": "^7.12.1"
2423
},
2524
"devDependencies": {
2625
"@clark/eslint-config-node": "^1.28.2",

tests/ts-module-a/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ export enum SomeEnum {
99
Bar
1010
}
1111

12+
export class SomeClass {
13+
someProperty = true;
14+
private somePrivateProperty = true;
15+
declare someDeclaredProperty: true;
16+
}
17+
1218
export type { SomeType } from './types-only';

yarn.lock

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@
407407
"@babel/helper-plugin-utils" "^7.10.4"
408408
"@babel/plugin-syntax-decorators" "^7.10.4"
409409

410+
"@babel/plugin-proposal-decorators@^7.12.1":
411+
version "7.12.1"
412+
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.12.1.tgz#59271439fed4145456c41067450543aee332d15f"
413+
integrity sha512-knNIuusychgYN8fGJHONL0RbFxLGawhXOJNLBk75TniTsZZeA+wdkDuv6wp4lGwzQEKjZi6/WYtnb3udNPmQmQ==
414+
dependencies:
415+
"@babel/helper-create-class-features-plugin" "^7.12.1"
416+
"@babel/helper-plugin-utils" "^7.10.4"
417+
"@babel/plugin-syntax-decorators" "^7.12.1"
418+
410419
"@babel/plugin-proposal-dynamic-import@^7.12.1":
411420
version "7.12.1"
412421
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.12.1.tgz#43eb5c2a3487ecd98c5c8ea8b5fdb69a2749b2dc"
@@ -518,6 +527,13 @@
518527
dependencies:
519528
"@babel/helper-plugin-utils" "^7.10.4"
520529

530+
"@babel/plugin-syntax-decorators@^7.12.1":
531+
version "7.12.1"
532+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.12.1.tgz#81a8b535b284476c41be6de06853a8802b98c5dd"
533+
integrity sha512-ir9YW5daRrTYiy9UJ2TzdNIJEZu8KclVzDcfSt4iEmOtwQ4llPtWInNKJyKnVXp1vE4bbVd5S31M/im3mYMO1w==
534+
dependencies:
535+
"@babel/helper-plugin-utils" "^7.10.4"
536+
521537
"@babel/plugin-syntax-dynamic-import@^7.2.0", "@babel/plugin-syntax-dynamic-import@^7.8.0":
522538
version "7.8.0"
523539
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.0.tgz#3a6c1cd36af923db602df83c5aa72e08bb14353a"
@@ -977,14 +993,6 @@
977993
"@babel/types" "^7.4.4"
978994
esutils "^2.0.2"
979995

980-
"@babel/preset-typescript@^7.12.1":
981-
version "7.12.1"
982-
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.12.1.tgz#86480b483bb97f75036e8864fe404cc782cc311b"
983-
integrity sha512-hNK/DhmoJPsksdHuI/RVrcEws7GN5eamhi28JkO52MqIxU8Z0QpmiSOQxZHWOHV7I3P4UjHV97ay4TcamMA6Kw==
984-
dependencies:
985-
"@babel/helper-plugin-utils" "^7.10.4"
986-
"@babel/plugin-transform-typescript" "^7.12.1"
987-
988996
"@babel/runtime@^7.12.0", "@babel/runtime@^7.8.4":
989997
version "7.12.1"
990998
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.1.tgz#b4116a6b6711d010b2dad3b7b6e43bf1b9954740"

0 commit comments

Comments
 (0)