Add "decoratorsLegacy" to presets

This commit is contained in:
Nicolò Ribaudo 2018-04-15 10:54:46 +02:00 committed by Brian Ng
parent 96316dcf88
commit 2679d6775c
No known key found for this signature in database
GPG Key ID: 3F2380E1E1508CA9
8 changed files with 68 additions and 29 deletions

View File

@ -47,3 +47,9 @@ Enable "loose" transformations for any plugins in this preset that allow them.
`boolean`, defaults to `false`.
Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
### `decoratorsLegacy`
`boolean`, defaults to `false`.
Use the legacy (stage 1) decorators syntax and behavior.

View File

@ -3,16 +3,10 @@ import presetStage1 from "@babel/preset-stage-1";
import transformFunctionBind from "@babel/plugin-proposal-function-bind";
export default declare((api, opts) => {
export default declare((api, opts = {}) => {
api.assertVersion(7);
let loose = false;
let useBuiltIns = false;
if (opts !== undefined) {
if (opts.loose !== undefined) loose = opts.loose;
if (opts.useBuiltIns !== undefined) useBuiltIns = opts.useBuiltIns;
}
const { loose = false, useBuiltIns = false, decoratorsLegacy = false } = opts;
if (typeof loose !== "boolean") {
throw new Error("@babel/preset-stage-0 'loose' option must be a boolean.");
@ -22,9 +16,22 @@ export default declare((api, opts) => {
"@babel/preset-stage-0 'useBuiltIns' option must be a boolean.",
);
}
if (typeof decoratorsLegacy !== "boolean") {
throw new Error(
"@babel/preset-stage-0 'decoratorsLegacy' option must be a boolean.",
);
}
if (decoratorsLegacy !== true) {
throw new Error(
"The new decorators proposal is not supported yet." +
' You muse pass the `"decoratorsLegacy": true` option to' +
" @babel/preset-stage-0",
);
}
return {
presets: [[presetStage1, { loose, useBuiltIns }]],
presets: [[presetStage1, { loose, useBuiltIns, decoratorsLegacy }]],
plugins: [transformFunctionBind],
};
});

View File

@ -58,6 +58,12 @@ Enable "loose" transformations for any plugins in this preset that allow them.
Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
### `decoratorsLegacy`
`boolean`, defaults to `false`.
Use the legacy (stage 1) decorators syntax and behavior.
## References
- Chapter "[The TC39 process for ECMAScript features](http://exploringjs.com/es2016-es2017/ch_tc39-process.html)" in "Exploring ES2016 and ES2017" by Axel Rauschmayer

View File

@ -9,7 +9,6 @@
"main": "lib/index.js",
"dependencies": {
"@babel/helper-plugin-utils": "7.0.0-beta.44",
"@babel/plugin-proposal-decorators": "7.0.0-beta.44",
"@babel/plugin-proposal-do-expressions": "7.0.0-beta.44",
"@babel/plugin-proposal-export-default-from": "7.0.0-beta.44",
"@babel/plugin-proposal-logical-assignment-operators": "7.0.0-beta.44",

View File

@ -1,7 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import presetStage2 from "@babel/preset-stage-2";
import transformDecorators from "@babel/plugin-proposal-decorators";
import transformExportDefaultFrom from "@babel/plugin-proposal-export-default-from";
import transformLogicalAssignmentOperators from "@babel/plugin-proposal-logical-assignment-operators";
import transformOptionalChaining from "@babel/plugin-proposal-optional-chaining";
@ -9,16 +8,10 @@ import transformPipelineOperator from "@babel/plugin-proposal-pipeline-operator"
import transformNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator";
import transformDoExpressions from "@babel/plugin-proposal-do-expressions";
export default declare((api, opts) => {
export default declare((api, opts = {}) => {
api.assertVersion(7);
let loose = false;
let useBuiltIns = false;
if (opts !== undefined) {
if (opts.loose !== undefined) loose = opts.loose;
if (opts.useBuiltIns !== undefined) useBuiltIns = opts.useBuiltIns;
}
const { loose = false, useBuiltIns = false, decoratorsLegacy = false } = opts;
if (typeof loose !== "boolean") {
throw new Error("@babel/preset-stage-1 'loose' option must be a boolean.");
@ -28,11 +21,23 @@ export default declare((api, opts) => {
"@babel/preset-stage-1 'useBuiltIns' option must be a boolean.",
);
}
if (typeof decoratorsLegacy !== "boolean") {
throw new Error(
"@babel/preset-stage-1 'decoratorsLegacy' option must be a boolean.",
);
}
if (decoratorsLegacy !== true) {
throw new Error(
"The new decorators proposal is not supported yet." +
' You muse pass the `"decoratorsLegacy": true` option to' +
" @babel/preset-stage-1",
);
}
return {
presets: [[presetStage2, { loose, useBuiltIns }]],
presets: [[presetStage2, { loose, useBuiltIns, decoratorsLegacy }]],
plugins: [
[transformDecorators, { legacy: true }],
transformExportDefaultFrom,
transformLogicalAssignmentOperators,
[transformOptionalChaining, { loose }],

View File

@ -58,6 +58,12 @@ Enable "loose" transformations for any plugins in this preset that allow them.
Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
### `decoratorsLegacy`
`boolean`, defaults to `false`.
Use the legacy (stage 1) decorators syntax and behavior.
## References
- Chapter "[The TC39 process for ECMAScript features](http://exploringjs.com/es2016-es2017/ch_tc39-process.html)" in "Exploring ES2016 and ES2017" by Axel Rauschmayer

View File

@ -9,6 +9,7 @@
"main": "lib/index.js",
"dependencies": {
"@babel/helper-plugin-utils": "7.0.0-beta.44",
"@babel/plugin-proposal-decorators": "7.0.0-beta.44",
"@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.44",
"@babel/plugin-proposal-function-sent": "7.0.0-beta.44",
"@babel/plugin-proposal-numeric-separator": "7.0.0-beta.44",

View File

@ -1,21 +1,16 @@
import { declare } from "@babel/helper-plugin-utils";
import presetStage3 from "@babel/preset-stage-3";
import transformDecorators from "@babel/plugin-proposal-decorators";
import transformFunctionSent from "@babel/plugin-proposal-function-sent";
import transformExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from";
import transformNumericSeparator from "@babel/plugin-proposal-numeric-separator";
import transformThrowExpressions from "@babel/plugin-proposal-throw-expressions";
export default declare((api, opts) => {
export default declare((api, opts = {}) => {
api.assertVersion(7);
let loose = false;
let useBuiltIns = false;
if (opts !== undefined) {
if (opts.loose !== undefined) loose = opts.loose;
if (opts.useBuiltIns !== undefined) useBuiltIns = opts.useBuiltIns;
}
const { loose = false, useBuiltIns = false, decoratorsLegacy = false } = opts;
if (typeof loose !== "boolean") {
throw new Error("@babel/preset-stage-2 'loose' option must be a boolean.");
@ -25,10 +20,24 @@ export default declare((api, opts) => {
"@babel/preset-stage-2 'useBuiltIns' option must be a boolean.",
);
}
if (typeof decoratorsLegacy !== "boolean") {
throw new Error(
"@babel/preset-stage-2 'decoratorsLegacy' option must be a boolean.",
);
}
if (decoratorsLegacy !== true) {
throw new Error(
"The new decorators proposal is not supported yet." +
' You muse pass the `"decoratorsLegacy": true` option to' +
" @babel/preset-stage-2",
);
}
return {
presets: [[presetStage3, { loose, useBuiltIns }]],
plugins: [
[transformDecorators, { legacy: decoratorsLegacy }],
transformFunctionSent,
transformExportNamespaceFrom,
transformNumericSeparator,