Skip to content

Commit

Permalink
feat!: change classLoose default valule and presets order
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed May 12, 2021
1 parent a77c08e commit 1dd2ff6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
34 changes: 19 additions & 15 deletions README.md
Expand Up @@ -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

Expand All @@ -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 (<https://babeljs.io/docs/en/presets/#preset-ordering>), so please make sure `proposal-typescript` is used at the last.

### Via `.babelrc` (Recommended)

**.babelrc**
Expand Down Expand Up @@ -105,7 +109,7 @@ loader = {
test: /\.[jt]sx?$/,
loader: 'babel-loader',
options: {
presets: ['proposal-typescript', '@babel/typescript'],
presets: ['@babel/typescript', 'proposal-typescript'],
},
}

Expand Down
5 changes: 2 additions & 3 deletions babel.config.js
Expand Up @@ -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', '<')
? [
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Expand Up @@ -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'
Expand All @@ -34,7 +33,7 @@ export default declare(
(
api: ConfigAPI,
{
classLoose = true,
classLoose,
decoratorsBeforeExport,
decoratorsLegacy = true,
isTSX,
Expand All @@ -53,7 +52,6 @@ export default declare(
legacy: decoratorsLegacy,
},
],
syntaxDynamicImport,
[
syntaxTypeScript,
{
Expand Down

0 comments on commit 1dd2ff6

Please sign in to comment.