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

Add support for decorators #5659

Merged
merged 2 commits into from
Nov 1, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/babel-preset-react-app/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ module.exports = function(api, opts, env) {
// in practice some other transforms (such as object-rest-spread)
// don't work without it: https://github.com/babel/babel/issues/7215
require('@babel/plugin-transform-destructuring').default,
// Turn on legacy decorators for TypeScript files
isTypeScriptEnabled && [
require('@babel/plugin-proposal-decorators').default,
false,
],
// class { handleClick = () => { } }
// Enable loose mode to use assignment instead of defineProperty
// See discussion in https://github.com/facebook/create-react-app/issues/4263
Expand Down Expand Up @@ -166,5 +171,16 @@ module.exports = function(api, opts, env) {
// Transform dynamic import to require
require('babel-plugin-dynamic-import-node'),
].filter(Boolean),
overrides: [
isTypeScriptEnabled && {
test: /\.tsx?$/,
plugins: [
[
require('@babel/plugin-proposal-decorators').default,
{ legacy: true },
],
],
},
].filter(Boolean),
};
};
1 change: 1 addition & 0 deletions packages/babel-preset-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@babel/core": "7.1.0",
"@babel/plugin-proposal-class-properties": "7.1.0",
"@babel/plugin-proposal-decorators": "7.1.2",
"@babel/plugin-proposal-object-rest-spread": "7.0.0",
"@babel/plugin-syntax-dynamic-import": "7.0.0",
"@babel/plugin-transform-classes": "7.1.0",
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/typescript/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ interface MyType {

type MyObject = Pick<MyType, 'bar' | 'baz'>;

@annotation
class App {
static foo: MyObject = { bar: true, baz: { n: 123 } };
n = App.foo.baz!.n;
}

function annotation(target: any) {
target.annotated = true;
}

export default App;
5 changes: 5 additions & 0 deletions test/fixtures/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}