diff --git a/README.md b/README.md index c6fb4cdb..695d60cd 100644 --- a/README.md +++ b/README.md @@ -35,18 +35,20 @@ So that you can use babel to transform proposals which are current in stage 0-2 ## Enabled proposal plugins -1. [class-static-block](https://www.npmjs.com/package/@babel/plugin-proposal-class-static-block) -2. [class-properties](https://www.npmjs.com/package/@babel/plugin-proposal-class-properties) -3. [do-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-do-expressions) -4. [function-bind](https://www.npmjs.com/package/@babel/plugin-proposal-function-bind) -5. [function-sent](https://www.npmjs.com/package/@babel/plugin-proposal-function-sent) -6. [json-strings](https://www.npmjs.com/package/@babel/plugin-proposal-json-strings) -7. [partial-application](https://www.npmjs.com/package/@babel/plugin-proposal-partial-application) -8. [pipeline-operator](https://www.npmjs.com/package/@babel/plugin-proposal-pipeline-operator) -9. [private-methods](https://www.npmjs.com/package/@babel/plugin-proposal-private-methods) -10. [private-property-in-object](https://www.npmjs.com/package/@babel/plugin-proposal-private-property-in-object) -11. [throw-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-throw-expressions) -12. [v8intrinsic](./src/v8intrinsic.ts) - [Further Detail](https://babeljs.io/blog/2019/09/05/7.6.0#v8-intrinsic-runtime-functions-parsing-10148-https-githubcom-babel-babel-pull-10148) +1. [async-do-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-async-do-expressions) +2. [class-properties](https://www.npmjs.com/package/@babel/plugin-proposal-class-properties) +3. [class-static-block](https://www.npmjs.com/package/@babel/plugin-proposal-class-static-block) +4. [do-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-do-expressions) +5. [function-bind](https://www.npmjs.com/package/@babel/plugin-proposal-function-bind) +6. [function-sent](https://www.npmjs.com/package/@babel/plugin-proposal-function-sent) +7. [json-strings](https://www.npmjs.com/package/@babel/plugin-proposal-json-strings) +8. [partial-application](https://www.npmjs.com/package/@babel/plugin-proposal-partial-application) +9. [pipeline-operator](https://www.npmjs.com/package/@babel/plugin-proposal-pipeline-operator) +10. [private-methods](https://www.npmjs.com/package/@babel/plugin-proposal-private-methods) +11. [private-property-in-object](https://www.npmjs.com/package/@babel/plugin-proposal-private-property-in-object) +12. [record-and-tuple](https://www.npmjs.com/package/@babel/plugin-proposal-record-and-tuple) +13. [throw-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-throw-expressions) +14. [v8intrinsic](./src/v8intrinsic.ts) - [Further Detail](https://babeljs.io/blog/2019/09/05/7.6.0#v8-intrinsic-runtime-functions-parsing-10148-https-githubcom-babel-babel-pull-10148) ## Install @@ -62,16 +64,18 @@ npm i -D babel-preset-proposal-typescript | option | description | defaults | | ------------------------ | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | -| `classLoose` | whether to use loose mode for class properties and private methods | `true` | +| `classLoose` | whether to use loose mode for `class-static-block`, `class-properties` and `private-methods` | `undefined` | | `decoratorsBeforeExport` | See [Babel Document](https://babeljs.io/docs/en/babel-plugin-proposal-decorators#decoratorsbeforeexport) | `undefined` | | `decoratorsLegacy` | whether to use legacy decorators semantic | `true` | | `isTSX` | whether to enable `jsx` plugin with `typescript` | `false`, but `true` for `/\.[jt]sx$/` | | `pipelineOperator` | implementation of pipeline operator, `minimal`, `smart` or `fsharp` | `minimal` | -| `recordTuplePolyfill` | whether to enable import record-tuple plugin and polyfill, or specific the polyfill module name | `true` for Node>=14.6, it represents `@bloomberg/record-tuple-polyfill` | +| `recordTuplePolyfill` | whether to enable import `record-tuple` plugin and polyfill, or specific the polyfill module name | `true` for Node>=14.6, it represents `@bloomberg/record-tuple-polyfill` | | `recordTupleSyntaxType` | record-tuple syntax, `hash` or `bar` | `hash` | ## Usage +Note that unlike plugins, the presets are applied in an order of last to first (), so please make sure `proposal-typescript` is used at the last. + ### Via `.babelrc` (Recommended) **.babelrc** @@ -105,7 +109,7 @@ loader = { test: /\.[jt]sx?$/, loader: 'babel-loader', options: { - presets: ['proposal-typescript', '@babel/typescript'], + presets: ['@babel/typescript', 'proposal-typescript'], }, } diff --git a/babel.config.js b/babel.config.js index ef131da3..b1bd17ac 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,17 +2,16 @@ const { compare } = require('compare-versions') module.exports = { presets: [ - 'proposal-typescript', - '@babel/typescript', [ '@babel/env', { - loose: true, targets: { node: true, }, }, ], + '@babel/typescript', + 'proposal-typescript', ], plugins: compare(process.versions.node, '14.6', '<') ? [ diff --git a/package.json b/package.json index 5c2e8918..f94f6a0b 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "@babel/plugin-proposal-record-and-tuple": "^7.13.0", "@babel/plugin-proposal-throw-expressions": "^7.12.13", "@babel/plugin-syntax-decorators": "^7.12.13", - "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-typescript": "^7.12.13", "@bloomberg/record-tuple-polyfill": "^0.0.3", "compare-versions": "^3.6.0" diff --git a/src/index.ts b/src/index.ts index 22b643a0..8345be84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,6 @@ import proposalPrivatePropertyInObject from '@babel/plugin-proposal-private-prop import proposalRecordAndTuple from '@babel/plugin-proposal-record-and-tuple' import proposalThrowExpression from '@babel/plugin-proposal-throw-expressions' import syntaxDecorators from '@babel/plugin-syntax-decorators' -import syntaxDynamicImport from '@babel/plugin-syntax-dynamic-import' import syntaxTypeScript from '@babel/plugin-syntax-typescript' import syntaxV8intrinsic from './v8intrinsic' @@ -34,7 +33,7 @@ export default declare( ( api: ConfigAPI, { - classLoose = true, + classLoose, decoratorsBeforeExport, decoratorsLegacy = true, isTSX, @@ -53,7 +52,6 @@ export default declare( legacy: decoratorsLegacy, }, ], - syntaxDynamicImport, [ syntaxTypeScript, {