Skip to content

Commit

Permalink
fix: support declare in classes (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens authored Oct 27, 2020
1 parent 7bbaf46 commit 7aef98b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
28 changes: 16 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ module.exports = {
loader: 'babel-loader-8',
options: {
plugins: [
// Transpile class properties
// @see https://github.com/typed-ember/ember-cli-typescript/blob/b2e75abc98beefe635b6cfd8808c887813acb44e/ts/addon.ts#L99
require.resolve('@babel/plugin-proposal-class-properties'),
// https://github.com/babel/ember-cli-babel/blob/036723709e26aba68eee1d5a9df49f97944e435b/index.js#L359-L385
[
require.resolve('@babel/plugin-transform-typescript'),
{ allowDeclareFields: true }
],

// https://github.com/babel/ember-cli-babel/blob/036723709e26aba68eee1d5a9df49f97944e435b/index.js#L403-L409
[
require.resolve('@babel/plugin-proposal-decorators'),
{ legacy: true }
],

// Transpile new syntax, which is apparently not yet handled by
// `@babel/preset-env`.
// @see https://github.com/typed-ember/ember-cli-typescript/blob/b2e75abc98beefe635b6cfd8808c887813acb44e/ts/addon.ts#L89-L94
require.resolve('@babel/plugin-proposal-optional-chaining'),
require.resolve(
'@babel/plugin-proposal-nullish-coalescing-operator'
)
// https://github.com/babel/ember-cli-babel/blob/036723709e26aba68eee1d5a9df49f97944e435b/index.js#L420-L426
[
require.resolve('@babel/plugin-proposal-class-properties'),
{ loose: true }
]
],
presets: [
// Transpile TypeScript
require.resolve('@babel/preset-typescript'),
// Transpile incompatible syntax for project build targets
[
require.resolve('@babel/preset-env'),
Expand Down
9 changes: 4 additions & 5 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
"lint:js": "eslint --ext ts,js ."
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1"
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-decorators": "^7.12.1",
"@babel/plugin-transform-typescript": "^7.12.1",
"@babel/preset-env": "^7.12.1"
},
"devDependencies": {
"@clark/eslint-config-node": "^1.28.2",
Expand Down
6 changes: 6 additions & 0 deletions tests/ts-module-a/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ export enum SomeEnum {
Bar
}

export class SomeClass {
someProperty = true;
private somePrivateProperty = true;
declare someDeclaredProperty: true;
}

export type { SomeType } from './types-only';
24 changes: 16 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-decorators" "^7.10.4"

"@babel/plugin-proposal-decorators@^7.12.1":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.12.1.tgz#59271439fed4145456c41067450543aee332d15f"
integrity sha512-knNIuusychgYN8fGJHONL0RbFxLGawhXOJNLBk75TniTsZZeA+wdkDuv6wp4lGwzQEKjZi6/WYtnb3udNPmQmQ==
dependencies:
"@babel/helper-create-class-features-plugin" "^7.12.1"
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-decorators" "^7.12.1"

"@babel/plugin-proposal-dynamic-import@^7.12.1":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.12.1.tgz#43eb5c2a3487ecd98c5c8ea8b5fdb69a2749b2dc"
Expand Down Expand Up @@ -518,6 +527,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"

"@babel/plugin-syntax-decorators@^7.12.1":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.12.1.tgz#81a8b535b284476c41be6de06853a8802b98c5dd"
integrity sha512-ir9YW5daRrTYiy9UJ2TzdNIJEZu8KclVzDcfSt4iEmOtwQ4llPtWInNKJyKnVXp1vE4bbVd5S31M/im3mYMO1w==
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"

"@babel/plugin-syntax-dynamic-import@^7.2.0", "@babel/plugin-syntax-dynamic-import@^7.8.0":
version "7.8.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.0.tgz#3a6c1cd36af923db602df83c5aa72e08bb14353a"
Expand Down Expand Up @@ -977,14 +993,6 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"

"@babel/preset-typescript@^7.12.1":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.12.1.tgz#86480b483bb97f75036e8864fe404cc782cc311b"
integrity sha512-hNK/DhmoJPsksdHuI/RVrcEws7GN5eamhi28JkO52MqIxU8Z0QpmiSOQxZHWOHV7I3P4UjHV97ay4TcamMA6Kw==
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-transform-typescript" "^7.12.1"

"@babel/runtime@^7.12.0", "@babel/runtime@^7.8.4":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.1.tgz#b4116a6b6711d010b2dad3b7b6e43bf1b9954740"
Expand Down

0 comments on commit 7aef98b

Please sign in to comment.