babel-preset-react-app 5.0.4 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +12 -9
  2. package/create.js +22 -0
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -32,19 +32,22 @@ Then create a file named `.babelrc` with following contents in the root folder o
32
32
 
33
33
  This preset uses the `useBuiltIns` option with [transform-object-rest-spread](http://babeljs.io/docs/plugins/transform-object-rest-spread/) and [transform-react-jsx](http://babeljs.io/docs/plugins/transform-react-jsx/), which assumes that `Object.assign` is available or polyfilled.
34
34
 
35
- ## Usage with TypeScript
35
+ ## Usage with Flow
36
+
37
+ Flow is enabled by default. Make sure you have a `.flowconfig` file at the root directory. You can also use the `flow` option on `.babelrc`:
38
+
39
+ ```
40
+ {
41
+ "presets": [["react-app", { "flow": true, "typescript": false }]]
42
+ }
43
+ ```
36
44
 
37
- To use this package with [`@babel/preset-typescript`](https://www.npmjs.com/package/@babel/preset-typescript), you need to disable `@babel/preset-flow` first.
45
+ ## Usage with TypeScript
38
46
 
39
- You can achieve this by doing:
47
+ TypeScript is enabled by default. Make sure you have a `tsconfig.json` file at the root directory. You can also use the `typescript` option on `.babelrc`:
40
48
 
41
49
  ```
42
50
  {
43
- "presets": [
44
- ["react-app", {
45
- "flow": false
46
- }],
47
- "@babel/typescript"
48
- ]
51
+ "presets": [["react-app", { "flow": false, "typescript": true }]]
49
52
  }
50
53
  ```
package/create.js CHANGED
@@ -30,6 +30,11 @@ module.exports = function(api, opts, env) {
30
30
  var isEnvTest = env === 'test';
31
31
 
32
32
  var isFlowEnabled = validateBoolOption('flow', opts.flow, true);
33
+ var isTypeScriptEnabled = validateBoolOption(
34
+ 'typescript',
35
+ opts.typescript,
36
+ true
37
+ );
33
38
  var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, true);
34
39
  var useAbsoluteRuntime = validateBoolOption(
35
40
  'absoluteRuntime',
@@ -97,6 +102,7 @@ module.exports = function(api, opts, env) {
97
102
  useBuiltIns: true,
98
103
  },
99
104
  ],
105
+ isTypeScriptEnabled && [require('@babel/preset-typescript').default],
100
106
  ].filter(Boolean),
101
107
  plugins: [
102
108
  // Strip flow types before any other transform, emulating the behavior
@@ -111,6 +117,11 @@ module.exports = function(api, opts, env) {
111
117
  // in practice some other transforms (such as object-rest-spread)
112
118
  // don't work without it: https://github.com/babel/babel/issues/7215
113
119
  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
+ ],
114
125
  // class { handleClick = () => { } }
115
126
  // Enable loose mode to use assignment instead of defineProperty
116
127
  // See discussion in https://github.com/facebook/create-react-app/issues/4263
@@ -160,5 +171,16 @@ module.exports = function(api, opts, env) {
160
171
  // Transform dynamic import to require
161
172
  require('babel-plugin-dynamic-import-node'),
162
173
  ].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),
163
185
  };
164
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-react-app",
3
- "version": "5.0.4",
3
+ "version": "6.1.0",
4
4
  "description": "Babel preset used by Create React App",
5
5
  "repository": "facebook/create-react-app",
6
6
  "license": "MIT",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@babel/core": "7.1.0",
21
21
  "@babel/plugin-proposal-class-properties": "7.1.0",
22
+ "@babel/plugin-proposal-decorators": "7.1.2",
22
23
  "@babel/plugin-proposal-object-rest-spread": "7.0.0",
23
24
  "@babel/plugin-syntax-dynamic-import": "7.0.0",
24
25
  "@babel/plugin-transform-classes": "7.1.0",
@@ -29,6 +30,7 @@
29
30
  "@babel/plugin-transform-runtime": "7.1.0",
30
31
  "@babel/preset-env": "7.1.0",
31
32
  "@babel/preset-react": "7.0.0",
33
+ "@babel/preset-typescript": "7.1.0",
32
34
  "@babel/runtime": "7.0.0",
33
35
  "babel-loader": "8.0.4",
34
36
  "babel-plugin-dynamic-import-node": "2.2.0",