Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a8003d

Browse files
authored
Add support for decorators (#5659)
* Turn on decorators * Add decorator test
1 parent c11cc81 commit 1a8003d

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

‎packages/babel-preset-react-app/create.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ module.exports = function(api, opts, env) {
117117
// in practice some other transforms (such as object-rest-spread)
118118
// don't work without it: https://github.com/babel/babel/issues/7215
119119
require('@babel/plugin-transform-destructuring').default,
120+
// Turn on legacy decorators for TypeScript files
121+
isTypeScriptEnabled && [
122+
require('@babel/plugin-proposal-decorators').default,
123+
false,
124+
],
120125
// class { handleClick = () => { }}
121126
// Enable loose mode to use assignment instead of defineProperty
122127
// See discussion in https://github.com/facebook/create-react-app/issues/4263
@@ -166,5 +171,16 @@ module.exports = function(api, opts, env) {
166171
// Transform dynamic import to require
167172
require('babel-plugin-dynamic-import-node'),
168173
].filter(Boolean),
174+
overrides: [
175+
isTypeScriptEnabled && {
176+
test: /\.tsx?$/,
177+
plugins: [
178+
[
179+
require('@babel/plugin-proposal-decorators').default,
180+
{ legacy: true },
181+
],
182+
],
183+
},
184+
].filter(Boolean),
169185
};
170186
};

‎packages/babel-preset-react-app/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"@babel/core": "7.1.0",
2121
"@babel/plugin-proposal-class-properties": "7.1.0",
22+
"@babel/plugin-proposal-decorators": "7.1.2",
2223
"@babel/plugin-proposal-object-rest-spread": "7.0.0",
2324
"@babel/plugin-syntax-dynamic-import": "7.0.0",
2425
"@babel/plugin-transform-classes": "7.1.0",

‎test/fixtures/typescript/src/App.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ interface MyType {
66

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

9+
@annotation
910
class App {
1011
static foo: MyObject = { bar: true, baz: { n: 123 } };
1112
n = App.foo.baz!.n;
1213
}
1314

15+
function annotation(target: any) {
16+
target.annotated = true;
17+
}
18+
1419
export default App;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true
4+
}
5+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /