Make babel-standalone an ESModule and enable flow (#9025)
* Make babel-standalone an ESModule and enable flow * autogenerate plugin list * Make config an array
This commit is contained in:
parent
d8a5329834
commit
fb81e8f8b4
1
Makefile
1
Makefile
@ -11,6 +11,7 @@ SOURCES = packages codemods
|
|||||||
|
|
||||||
build: clean clean-lib
|
build: clean clean-lib
|
||||||
./node_modules/.bin/gulp build
|
./node_modules/.bin/gulp build
|
||||||
|
node ./packages/babel-standalone/scripts/generate.js
|
||||||
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
||||||
# call build again as the generated files might need to be compiled again.
|
# call build again as the generated files might need to be compiled again.
|
||||||
./node_modules/.bin/gulp build
|
./node_modules/.bin/gulp build
|
||||||
|
|||||||
37
packages/babel-standalone/scripts/generate.js
Normal file
37
packages/babel-standalone/scripts/generate.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// @flow
|
||||||
|
const pluginConfig = require("./pluginConfig.json");
|
||||||
|
const path = require("path");
|
||||||
|
const chalk = require("chalk");
|
||||||
|
const camelCase = require("lodash/camelCase");
|
||||||
|
const format = require("../../../scripts/utils/formatCode");
|
||||||
|
const writeFile = require("../../../scripts/utils/writeFileAndMkDir");
|
||||||
|
|
||||||
|
const outputFile = path.join(__dirname, "../src/generated/plugins.js");
|
||||||
|
|
||||||
|
console.log("Generating @babel/standalone files");
|
||||||
|
|
||||||
|
let imports = "";
|
||||||
|
let list = "";
|
||||||
|
let allList = "";
|
||||||
|
|
||||||
|
for (const plugin of pluginConfig) {
|
||||||
|
const camelPlugin = camelCase(plugin);
|
||||||
|
imports += `import ${camelPlugin} from "@babel/plugin-${plugin}";`;
|
||||||
|
list += `${camelPlugin},`;
|
||||||
|
allList += `"${plugin}": ${camelPlugin},`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileContent = `// @flow
|
||||||
|
/*
|
||||||
|
* This file is auto-generated! Do not modify it directly.
|
||||||
|
* To re-generate run 'make build'
|
||||||
|
*/
|
||||||
|
${imports}
|
||||||
|
|
||||||
|
export {${list}};
|
||||||
|
|
||||||
|
export const all = {${allList}};
|
||||||
|
`;
|
||||||
|
|
||||||
|
writeFile(outputFile, format(fileContent, outputFile));
|
||||||
|
console.log(` ${chalk.green("✔")} Generated plugin list`);
|
||||||
85
packages/babel-standalone/scripts/pluginConfig.json
Normal file
85
packages/babel-standalone/scripts/pluginConfig.json
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
[
|
||||||
|
"external-helpers",
|
||||||
|
"syntax-async-generators",
|
||||||
|
"syntax-class-properties",
|
||||||
|
"syntax-decorators",
|
||||||
|
"syntax-do-expressions",
|
||||||
|
"syntax-dynamic-import",
|
||||||
|
"syntax-export-default-from",
|
||||||
|
"syntax-export-namespace-from",
|
||||||
|
"syntax-flow",
|
||||||
|
"syntax-function-bind",
|
||||||
|
"syntax-function-sent",
|
||||||
|
"syntax-import-meta",
|
||||||
|
"syntax-jsx",
|
||||||
|
"syntax-object-rest-spread",
|
||||||
|
"syntax-optional-catch-binding",
|
||||||
|
"syntax-pipeline-operator",
|
||||||
|
"syntax-typescript",
|
||||||
|
"proposal-async-generator-functions",
|
||||||
|
"proposal-class-properties",
|
||||||
|
"proposal-decorators",
|
||||||
|
"proposal-do-expressions",
|
||||||
|
"proposal-export-default-from",
|
||||||
|
"proposal-export-namespace-from",
|
||||||
|
"proposal-function-bind",
|
||||||
|
"proposal-function-sent",
|
||||||
|
"proposal-json-strings",
|
||||||
|
"proposal-logical-assignment-operators",
|
||||||
|
"proposal-nullish-coalescing-operator",
|
||||||
|
"proposal-numeric-separator",
|
||||||
|
"proposal-object-rest-spread",
|
||||||
|
"proposal-optional-catch-binding",
|
||||||
|
"proposal-optional-chaining",
|
||||||
|
"proposal-pipeline-operator",
|
||||||
|
"proposal-private-methods",
|
||||||
|
"proposal-throw-expressions",
|
||||||
|
"proposal-unicode-property-regex",
|
||||||
|
"transform-async-to-generator",
|
||||||
|
"transform-arrow-functions",
|
||||||
|
"transform-block-scoped-functions",
|
||||||
|
"transform-block-scoping",
|
||||||
|
"transform-classes",
|
||||||
|
"transform-computed-properties",
|
||||||
|
"transform-destructuring",
|
||||||
|
"transform-dotall-regex",
|
||||||
|
"transform-duplicate-keys",
|
||||||
|
"transform-exponentiation-operator",
|
||||||
|
"transform-flow-comments",
|
||||||
|
"transform-flow-strip-types",
|
||||||
|
"transform-for-of",
|
||||||
|
"transform-function-name",
|
||||||
|
"transform-instanceof",
|
||||||
|
"transform-jscript",
|
||||||
|
"transform-literals",
|
||||||
|
"transform-member-expression-literals",
|
||||||
|
"transform-modules-amd",
|
||||||
|
"transform-modules-commonjs",
|
||||||
|
"transform-modules-systemjs",
|
||||||
|
"transform-modules-umd",
|
||||||
|
"transform-new-target",
|
||||||
|
"transform-object-assign",
|
||||||
|
"transform-object-super",
|
||||||
|
"transform-object-set-prototype-of-to-assign",
|
||||||
|
"transform-parameters",
|
||||||
|
"transform-property-literals",
|
||||||
|
"transform-property-mutators",
|
||||||
|
"transform-proto-to-assign",
|
||||||
|
"transform-react-constant-elements",
|
||||||
|
"transform-react-display-name",
|
||||||
|
"transform-react-inline-elements",
|
||||||
|
"transform-react-jsx",
|
||||||
|
"transform-react-jsx-compat",
|
||||||
|
"transform-react-jsx-self",
|
||||||
|
"transform-react-jsx-source",
|
||||||
|
"transform-regenerator",
|
||||||
|
"transform-runtime",
|
||||||
|
"transform-shorthand-properties",
|
||||||
|
"transform-spread",
|
||||||
|
"transform-sticky-regex",
|
||||||
|
"transform-strict-mode",
|
||||||
|
"transform-template-literals",
|
||||||
|
"transform-typeof-symbol",
|
||||||
|
"transform-typescript",
|
||||||
|
"transform-unicode-regex"
|
||||||
|
]
|
||||||
256
packages/babel-standalone/src/generated/plugins.js
Normal file
256
packages/babel-standalone/src/generated/plugins.js
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
// @flow
|
||||||
|
import externalHelpers from "@babel/plugin-external-helpers";
|
||||||
|
import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
|
||||||
|
import syntaxClassProperties from "@babel/plugin-syntax-class-properties";
|
||||||
|
import syntaxDecorators from "@babel/plugin-syntax-decorators";
|
||||||
|
import syntaxDoExpressions from "@babel/plugin-syntax-do-expressions";
|
||||||
|
import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";
|
||||||
|
import syntaxExportDefaultFrom from "@babel/plugin-syntax-export-default-from";
|
||||||
|
import syntaxExportNamespaceFrom from "@babel/plugin-syntax-export-namespace-from";
|
||||||
|
import syntaxFlow from "@babel/plugin-syntax-flow";
|
||||||
|
import syntaxFunctionBind from "@babel/plugin-syntax-function-bind";
|
||||||
|
import syntaxFunctionSent from "@babel/plugin-syntax-function-sent";
|
||||||
|
import syntaxImportMeta from "@babel/plugin-syntax-import-meta";
|
||||||
|
import syntaxJsx from "@babel/plugin-syntax-jsx";
|
||||||
|
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
||||||
|
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
||||||
|
import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator";
|
||||||
|
import syntaxTypescript from "@babel/plugin-syntax-typescript";
|
||||||
|
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
|
||||||
|
import proposalClassProperties from "@babel/plugin-proposal-class-properties";
|
||||||
|
import proposalDecorators from "@babel/plugin-proposal-decorators";
|
||||||
|
import proposalDoExpressions from "@babel/plugin-proposal-do-expressions";
|
||||||
|
import proposalExportDefaultFrom from "@babel/plugin-proposal-export-default-from";
|
||||||
|
import proposalExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from";
|
||||||
|
import proposalFunctionBind from "@babel/plugin-proposal-function-bind";
|
||||||
|
import proposalFunctionSent from "@babel/plugin-proposal-function-sent";
|
||||||
|
import proposalJsonStrings from "@babel/plugin-proposal-json-strings";
|
||||||
|
import proposalLogicalAssignmentOperators from "@babel/plugin-proposal-logical-assignment-operators";
|
||||||
|
import proposalNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator";
|
||||||
|
import proposalNumericSeparator from "@babel/plugin-proposal-numeric-separator";
|
||||||
|
import proposalObjectRestSpread from "@babel/plugin-proposal-object-rest-spread";
|
||||||
|
import proposalOptionalCatchBinding from "@babel/plugin-proposal-optional-catch-binding";
|
||||||
|
import proposalOptionalChaining from "@babel/plugin-proposal-optional-chaining";
|
||||||
|
import proposalPipelineOperator from "@babel/plugin-proposal-pipeline-operator";
|
||||||
|
import proposalPrivateMethods from "@babel/plugin-proposal-private-methods";
|
||||||
|
import proposalThrowExpressions from "@babel/plugin-proposal-throw-expressions";
|
||||||
|
import proposalUnicodePropertyRegex from "@babel/plugin-proposal-unicode-property-regex";
|
||||||
|
import transformAsyncToGenerator from "@babel/plugin-transform-async-to-generator";
|
||||||
|
import transformArrowFunctions from "@babel/plugin-transform-arrow-functions";
|
||||||
|
import transformBlockScopedFunctions from "@babel/plugin-transform-block-scoped-functions";
|
||||||
|
import transformBlockScoping from "@babel/plugin-transform-block-scoping";
|
||||||
|
import transformClasses from "@babel/plugin-transform-classes";
|
||||||
|
import transformComputedProperties from "@babel/plugin-transform-computed-properties";
|
||||||
|
import transformDestructuring from "@babel/plugin-transform-destructuring";
|
||||||
|
import transformDotallRegex from "@babel/plugin-transform-dotall-regex";
|
||||||
|
import transformDuplicateKeys from "@babel/plugin-transform-duplicate-keys";
|
||||||
|
import transformExponentiationOperator from "@babel/plugin-transform-exponentiation-operator";
|
||||||
|
import transformFlowComments from "@babel/plugin-transform-flow-comments";
|
||||||
|
import transformFlowStripTypes from "@babel/plugin-transform-flow-strip-types";
|
||||||
|
import transformForOf from "@babel/plugin-transform-for-of";
|
||||||
|
import transformFunctionName from "@babel/plugin-transform-function-name";
|
||||||
|
import transformInstanceof from "@babel/plugin-transform-instanceof";
|
||||||
|
import transformJscript from "@babel/plugin-transform-jscript";
|
||||||
|
import transformLiterals from "@babel/plugin-transform-literals";
|
||||||
|
import transformMemberExpressionLiterals from "@babel/plugin-transform-member-expression-literals";
|
||||||
|
import transformModulesAmd from "@babel/plugin-transform-modules-amd";
|
||||||
|
import transformModulesCommonjs from "@babel/plugin-transform-modules-commonjs";
|
||||||
|
import transformModulesSystemjs from "@babel/plugin-transform-modules-systemjs";
|
||||||
|
import transformModulesUmd from "@babel/plugin-transform-modules-umd";
|
||||||
|
import transformNewTarget from "@babel/plugin-transform-new-target";
|
||||||
|
import transformObjectAssign from "@babel/plugin-transform-object-assign";
|
||||||
|
import transformObjectSuper from "@babel/plugin-transform-object-super";
|
||||||
|
import transformObjectSetPrototypeOfToAssign from "@babel/plugin-transform-object-set-prototype-of-to-assign";
|
||||||
|
import transformParameters from "@babel/plugin-transform-parameters";
|
||||||
|
import transformPropertyLiterals from "@babel/plugin-transform-property-literals";
|
||||||
|
import transformPropertyMutators from "@babel/plugin-transform-property-mutators";
|
||||||
|
import transformProtoToAssign from "@babel/plugin-transform-proto-to-assign";
|
||||||
|
import transformReactConstantElements from "@babel/plugin-transform-react-constant-elements";
|
||||||
|
import transformReactDisplayName from "@babel/plugin-transform-react-display-name";
|
||||||
|
import transformReactInlineElements from "@babel/plugin-transform-react-inline-elements";
|
||||||
|
import transformReactJsx from "@babel/plugin-transform-react-jsx";
|
||||||
|
import transformReactJsxCompat from "@babel/plugin-transform-react-jsx-compat";
|
||||||
|
import transformReactJsxSelf from "@babel/plugin-transform-react-jsx-self";
|
||||||
|
import transformReactJsxSource from "@babel/plugin-transform-react-jsx-source";
|
||||||
|
import transformRegenerator from "@babel/plugin-transform-regenerator";
|
||||||
|
import transformRuntime from "@babel/plugin-transform-runtime";
|
||||||
|
import transformShorthandProperties from "@babel/plugin-transform-shorthand-properties";
|
||||||
|
import transformSpread from "@babel/plugin-transform-spread";
|
||||||
|
import transformStickyRegex from "@babel/plugin-transform-sticky-regex";
|
||||||
|
import transformStrictMode from "@babel/plugin-transform-strict-mode";
|
||||||
|
import transformTemplateLiterals from "@babel/plugin-transform-template-literals";
|
||||||
|
import transformTypeofSymbol from "@babel/plugin-transform-typeof-symbol";
|
||||||
|
import transformTypescript from "@babel/plugin-transform-typescript";
|
||||||
|
import transformUnicodeRegex from "@babel/plugin-transform-unicode-regex";
|
||||||
|
|
||||||
|
export {
|
||||||
|
externalHelpers,
|
||||||
|
syntaxAsyncGenerators,
|
||||||
|
syntaxClassProperties,
|
||||||
|
syntaxDecorators,
|
||||||
|
syntaxDoExpressions,
|
||||||
|
syntaxDynamicImport,
|
||||||
|
syntaxExportDefaultFrom,
|
||||||
|
syntaxExportNamespaceFrom,
|
||||||
|
syntaxFlow,
|
||||||
|
syntaxFunctionBind,
|
||||||
|
syntaxFunctionSent,
|
||||||
|
syntaxImportMeta,
|
||||||
|
syntaxJsx,
|
||||||
|
syntaxObjectRestSpread,
|
||||||
|
syntaxOptionalCatchBinding,
|
||||||
|
syntaxPipelineOperator,
|
||||||
|
syntaxTypescript,
|
||||||
|
proposalAsyncGeneratorFunctions,
|
||||||
|
proposalClassProperties,
|
||||||
|
proposalDecorators,
|
||||||
|
proposalDoExpressions,
|
||||||
|
proposalExportDefaultFrom,
|
||||||
|
proposalExportNamespaceFrom,
|
||||||
|
proposalFunctionBind,
|
||||||
|
proposalFunctionSent,
|
||||||
|
proposalJsonStrings,
|
||||||
|
proposalLogicalAssignmentOperators,
|
||||||
|
proposalNullishCoalescingOperator,
|
||||||
|
proposalNumericSeparator,
|
||||||
|
proposalObjectRestSpread,
|
||||||
|
proposalOptionalCatchBinding,
|
||||||
|
proposalOptionalChaining,
|
||||||
|
proposalPipelineOperator,
|
||||||
|
proposalPrivateMethods,
|
||||||
|
proposalThrowExpressions,
|
||||||
|
proposalUnicodePropertyRegex,
|
||||||
|
transformAsyncToGenerator,
|
||||||
|
transformArrowFunctions,
|
||||||
|
transformBlockScopedFunctions,
|
||||||
|
transformBlockScoping,
|
||||||
|
transformClasses,
|
||||||
|
transformComputedProperties,
|
||||||
|
transformDestructuring,
|
||||||
|
transformDotallRegex,
|
||||||
|
transformDuplicateKeys,
|
||||||
|
transformExponentiationOperator,
|
||||||
|
transformFlowComments,
|
||||||
|
transformFlowStripTypes,
|
||||||
|
transformForOf,
|
||||||
|
transformFunctionName,
|
||||||
|
transformInstanceof,
|
||||||
|
transformJscript,
|
||||||
|
transformLiterals,
|
||||||
|
transformMemberExpressionLiterals,
|
||||||
|
transformModulesAmd,
|
||||||
|
transformModulesCommonjs,
|
||||||
|
transformModulesSystemjs,
|
||||||
|
transformModulesUmd,
|
||||||
|
transformNewTarget,
|
||||||
|
transformObjectAssign,
|
||||||
|
transformObjectSuper,
|
||||||
|
transformObjectSetPrototypeOfToAssign,
|
||||||
|
transformParameters,
|
||||||
|
transformPropertyLiterals,
|
||||||
|
transformPropertyMutators,
|
||||||
|
transformProtoToAssign,
|
||||||
|
transformReactConstantElements,
|
||||||
|
transformReactDisplayName,
|
||||||
|
transformReactInlineElements,
|
||||||
|
transformReactJsx,
|
||||||
|
transformReactJsxCompat,
|
||||||
|
transformReactJsxSelf,
|
||||||
|
transformReactJsxSource,
|
||||||
|
transformRegenerator,
|
||||||
|
transformRuntime,
|
||||||
|
transformShorthandProperties,
|
||||||
|
transformSpread,
|
||||||
|
transformStickyRegex,
|
||||||
|
transformStrictMode,
|
||||||
|
transformTemplateLiterals,
|
||||||
|
transformTypeofSymbol,
|
||||||
|
transformTypescript,
|
||||||
|
transformUnicodeRegex,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const all = {
|
||||||
|
"external-helpers": externalHelpers,
|
||||||
|
"syntax-async-generators": syntaxAsyncGenerators,
|
||||||
|
"syntax-class-properties": syntaxClassProperties,
|
||||||
|
"syntax-decorators": syntaxDecorators,
|
||||||
|
"syntax-do-expressions": syntaxDoExpressions,
|
||||||
|
"syntax-dynamic-import": syntaxDynamicImport,
|
||||||
|
"syntax-export-default-from": syntaxExportDefaultFrom,
|
||||||
|
"syntax-export-namespace-from": syntaxExportNamespaceFrom,
|
||||||
|
"syntax-flow": syntaxFlow,
|
||||||
|
"syntax-function-bind": syntaxFunctionBind,
|
||||||
|
"syntax-function-sent": syntaxFunctionSent,
|
||||||
|
"syntax-import-meta": syntaxImportMeta,
|
||||||
|
"syntax-jsx": syntaxJsx,
|
||||||
|
"syntax-object-rest-spread": syntaxObjectRestSpread,
|
||||||
|
"syntax-optional-catch-binding": syntaxOptionalCatchBinding,
|
||||||
|
"syntax-pipeline-operator": syntaxPipelineOperator,
|
||||||
|
"syntax-typescript": syntaxTypescript,
|
||||||
|
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
|
||||||
|
"proposal-class-properties": proposalClassProperties,
|
||||||
|
"proposal-decorators": proposalDecorators,
|
||||||
|
"proposal-do-expressions": proposalDoExpressions,
|
||||||
|
"proposal-export-default-from": proposalExportDefaultFrom,
|
||||||
|
"proposal-export-namespace-from": proposalExportNamespaceFrom,
|
||||||
|
"proposal-function-bind": proposalFunctionBind,
|
||||||
|
"proposal-function-sent": proposalFunctionSent,
|
||||||
|
"proposal-json-strings": proposalJsonStrings,
|
||||||
|
"proposal-logical-assignment-operators": proposalLogicalAssignmentOperators,
|
||||||
|
"proposal-nullish-coalescing-operator": proposalNullishCoalescingOperator,
|
||||||
|
"proposal-numeric-separator": proposalNumericSeparator,
|
||||||
|
"proposal-object-rest-spread": proposalObjectRestSpread,
|
||||||
|
"proposal-optional-catch-binding": proposalOptionalCatchBinding,
|
||||||
|
"proposal-optional-chaining": proposalOptionalChaining,
|
||||||
|
"proposal-pipeline-operator": proposalPipelineOperator,
|
||||||
|
"proposal-private-methods": proposalPrivateMethods,
|
||||||
|
"proposal-throw-expressions": proposalThrowExpressions,
|
||||||
|
"proposal-unicode-property-regex": proposalUnicodePropertyRegex,
|
||||||
|
"transform-async-to-generator": transformAsyncToGenerator,
|
||||||
|
"transform-arrow-functions": transformArrowFunctions,
|
||||||
|
"transform-block-scoped-functions": transformBlockScopedFunctions,
|
||||||
|
"transform-block-scoping": transformBlockScoping,
|
||||||
|
"transform-classes": transformClasses,
|
||||||
|
"transform-computed-properties": transformComputedProperties,
|
||||||
|
"transform-destructuring": transformDestructuring,
|
||||||
|
"transform-dotall-regex": transformDotallRegex,
|
||||||
|
"transform-duplicate-keys": transformDuplicateKeys,
|
||||||
|
"transform-exponentiation-operator": transformExponentiationOperator,
|
||||||
|
"transform-flow-comments": transformFlowComments,
|
||||||
|
"transform-flow-strip-types": transformFlowStripTypes,
|
||||||
|
"transform-for-of": transformForOf,
|
||||||
|
"transform-function-name": transformFunctionName,
|
||||||
|
"transform-instanceof": transformInstanceof,
|
||||||
|
"transform-jscript": transformJscript,
|
||||||
|
"transform-literals": transformLiterals,
|
||||||
|
"transform-member-expression-literals": transformMemberExpressionLiterals,
|
||||||
|
"transform-modules-amd": transformModulesAmd,
|
||||||
|
"transform-modules-commonjs": transformModulesCommonjs,
|
||||||
|
"transform-modules-systemjs": transformModulesSystemjs,
|
||||||
|
"transform-modules-umd": transformModulesUmd,
|
||||||
|
"transform-new-target": transformNewTarget,
|
||||||
|
"transform-object-assign": transformObjectAssign,
|
||||||
|
"transform-object-super": transformObjectSuper,
|
||||||
|
"transform-object-set-prototype-of-to-assign": transformObjectSetPrototypeOfToAssign,
|
||||||
|
"transform-parameters": transformParameters,
|
||||||
|
"transform-property-literals": transformPropertyLiterals,
|
||||||
|
"transform-property-mutators": transformPropertyMutators,
|
||||||
|
"transform-proto-to-assign": transformProtoToAssign,
|
||||||
|
"transform-react-constant-elements": transformReactConstantElements,
|
||||||
|
"transform-react-display-name": transformReactDisplayName,
|
||||||
|
"transform-react-inline-elements": transformReactInlineElements,
|
||||||
|
"transform-react-jsx": transformReactJsx,
|
||||||
|
"transform-react-jsx-compat": transformReactJsxCompat,
|
||||||
|
"transform-react-jsx-self": transformReactJsxSelf,
|
||||||
|
"transform-react-jsx-source": transformReactJsxSource,
|
||||||
|
"transform-regenerator": transformRegenerator,
|
||||||
|
"transform-runtime": transformRuntime,
|
||||||
|
"transform-shorthand-properties": transformShorthandProperties,
|
||||||
|
"transform-spread": transformSpread,
|
||||||
|
"transform-sticky-regex": transformStickyRegex,
|
||||||
|
"transform-strict-mode": transformStrictMode,
|
||||||
|
"transform-template-literals": transformTemplateLiterals,
|
||||||
|
"transform-typeof-symbol": transformTypeofSymbol,
|
||||||
|
"transform-typescript": transformTypescript,
|
||||||
|
"transform-unicode-regex": transformUnicodeRegex,
|
||||||
|
};
|
||||||
@ -4,12 +4,26 @@
|
|||||||
* plugins, instead explicitly registering all the available plugins and
|
* plugins, instead explicitly registering all the available plugins and
|
||||||
* presets, and requiring custom ones to be registered through `registerPlugin`
|
* presets, and requiring custom ones to be registered through `registerPlugin`
|
||||||
* and `registerPreset` respectively.
|
* and `registerPreset` respectively.
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global VERSION */
|
/* global VERSION */
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
|
|
||||||
import * as Babel from "@babel/core";
|
import {
|
||||||
|
transformFromAst as babelTransformFromAst,
|
||||||
|
transform as babelTransform,
|
||||||
|
buildExternalHelpers as babelBuildExternalHelpers,
|
||||||
|
} from "@babel/core";
|
||||||
|
import { all } from "./generated/plugins";
|
||||||
|
import preset2015 from "./preset-es2015";
|
||||||
|
import presetStage0 from "./preset-stage-0";
|
||||||
|
import presetStage1 from "./preset-stage-1";
|
||||||
|
import presetStage2 from "./preset-stage-2";
|
||||||
|
import presetStage3 from "./preset-stage-3";
|
||||||
|
import presetReact from "@babel/preset-react";
|
||||||
|
import presetFlow from "@babel/preset-flow";
|
||||||
|
import presetTypescript from "@babel/preset-typescript";
|
||||||
|
|
||||||
import { runScripts } from "./transformScriptTags";
|
import { runScripts } from "./transformScriptTags";
|
||||||
|
|
||||||
@ -84,20 +98,20 @@ function processOptions(options) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transform(code, options) {
|
export function transform(code: string, options: Object) {
|
||||||
return Babel.transform(code, processOptions(options));
|
return babelTransform(code, processOptions(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformFromAst(ast, code, options) {
|
export function transformFromAst(ast: Object, code: string, options: Object) {
|
||||||
return Babel.transformFromAst(ast, code, processOptions(options));
|
return babelTransformFromAst(ast, code, processOptions(options));
|
||||||
}
|
}
|
||||||
export const availablePlugins = {};
|
export const availablePlugins = {};
|
||||||
export const availablePresets = {};
|
export const availablePresets = {};
|
||||||
export const buildExternalHelpers = Babel.buildExternalHelpers;
|
export const buildExternalHelpers = babelBuildExternalHelpers;
|
||||||
/**
|
/**
|
||||||
* Registers a named plugin for use with Babel.
|
* Registers a named plugin for use with Babel.
|
||||||
*/
|
*/
|
||||||
export function registerPlugin(name, plugin) {
|
export function registerPlugin(name: string, plugin: Object | Function): void {
|
||||||
if (availablePlugins.hasOwnProperty(name)) {
|
if (availablePlugins.hasOwnProperty(name)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`A plugin named "${name}" is already registered, it will be overridden`,
|
`A plugin named "${name}" is already registered, it will be overridden`,
|
||||||
@ -109,7 +123,9 @@ export function registerPlugin(name, plugin) {
|
|||||||
* Registers multiple plugins for use with Babel. `newPlugins` should be an object where the key
|
* Registers multiple plugins for use with Babel. `newPlugins` should be an object where the key
|
||||||
* is the name of the plugin, and the value is the plugin itself.
|
* is the name of the plugin, and the value is the plugin itself.
|
||||||
*/
|
*/
|
||||||
export function registerPlugins(newPlugins) {
|
export function registerPlugins(newPlugins: {
|
||||||
|
[string]: Object | Function,
|
||||||
|
}): void {
|
||||||
Object.keys(newPlugins).forEach(name =>
|
Object.keys(newPlugins).forEach(name =>
|
||||||
registerPlugin(name, newPlugins[name]),
|
registerPlugin(name, newPlugins[name]),
|
||||||
);
|
);
|
||||||
@ -118,7 +134,7 @@ export function registerPlugins(newPlugins) {
|
|||||||
/**
|
/**
|
||||||
* Registers a named preset for use with Babel.
|
* Registers a named preset for use with Babel.
|
||||||
*/
|
*/
|
||||||
export function registerPreset(name, preset) {
|
export function registerPreset(name: string, preset: Object | Function): void {
|
||||||
if (availablePresets.hasOwnProperty(name)) {
|
if (availablePresets.hasOwnProperty(name)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`A preset named "${name}" is already registered, it will be overridden`,
|
`A preset named "${name}" is already registered, it will be overridden`,
|
||||||
@ -130,7 +146,9 @@ export function registerPreset(name, preset) {
|
|||||||
* Registers multiple presets for use with Babel. `newPresets` should be an object where the key
|
* Registers multiple presets for use with Babel. `newPresets` should be an object where the key
|
||||||
* is the name of the preset, and the value is the preset itself.
|
* is the name of the preset, and the value is the preset itself.
|
||||||
*/
|
*/
|
||||||
export function registerPresets(newPresets) {
|
export function registerPresets(newPresets: {
|
||||||
|
[string]: Object | Function,
|
||||||
|
}): void {
|
||||||
Object.keys(newPresets).forEach(name =>
|
Object.keys(newPresets).forEach(name =>
|
||||||
registerPreset(name, newPresets[name]),
|
registerPreset(name, newPresets[name]),
|
||||||
);
|
);
|
||||||
@ -139,90 +157,13 @@ export function registerPresets(newPresets) {
|
|||||||
// All the plugins we should bundle
|
// All the plugins we should bundle
|
||||||
// Want to get rid of this long whitelist of plugins?
|
// Want to get rid of this long whitelist of plugins?
|
||||||
// Wait! Please read https://github.com/babel/babel/pull/6177 first.
|
// Wait! Please read https://github.com/babel/babel/pull/6177 first.
|
||||||
registerPlugins({
|
registerPlugins(all);
|
||||||
"external-helpers": require("@babel/plugin-external-helpers"),
|
|
||||||
"syntax-async-generators": require("@babel/plugin-syntax-async-generators"),
|
|
||||||
"syntax-class-properties": require("@babel/plugin-syntax-class-properties"),
|
|
||||||
"syntax-decorators": require("@babel/plugin-syntax-decorators"),
|
|
||||||
"syntax-do-expressions": require("@babel/plugin-syntax-do-expressions"),
|
|
||||||
"syntax-dynamic-import": require("@babel/plugin-syntax-dynamic-import"),
|
|
||||||
"syntax-export-default-from": require("@babel/plugin-syntax-export-default-from"),
|
|
||||||
"syntax-export-namespace-from": require("@babel/plugin-syntax-export-namespace-from"),
|
|
||||||
"syntax-flow": require("@babel/plugin-syntax-flow"),
|
|
||||||
"syntax-function-bind": require("@babel/plugin-syntax-function-bind"),
|
|
||||||
"syntax-function-sent": require("@babel/plugin-syntax-function-sent"),
|
|
||||||
"syntax-import-meta": require("@babel/plugin-syntax-import-meta"),
|
|
||||||
"syntax-jsx": require("@babel/plugin-syntax-jsx"),
|
|
||||||
"syntax-object-rest-spread": require("@babel/plugin-syntax-object-rest-spread"),
|
|
||||||
"syntax-optional-catch-binding": require("@babel/plugin-syntax-optional-catch-binding"),
|
|
||||||
"syntax-pipeline-operator": require("@babel/plugin-syntax-pipeline-operator"),
|
|
||||||
"syntax-typescript": require("@babel/plugin-syntax-typescript"),
|
|
||||||
"transform-async-to-generator": require("@babel/plugin-transform-async-to-generator"),
|
|
||||||
"proposal-async-generator-functions": require("@babel/plugin-proposal-async-generator-functions"),
|
|
||||||
"proposal-class-properties": require("@babel/plugin-proposal-class-properties"),
|
|
||||||
"proposal-decorators": require("@babel/plugin-proposal-decorators"),
|
|
||||||
"proposal-do-expressions": require("@babel/plugin-proposal-do-expressions"),
|
|
||||||
"proposal-export-default-from": require("@babel/plugin-proposal-export-default-from"),
|
|
||||||
"proposal-export-namespace-from": require("@babel/plugin-proposal-export-namespace-from"),
|
|
||||||
"proposal-pipeline-operator": require("@babel/plugin-proposal-pipeline-operator"),
|
|
||||||
"proposal-private-methods": require("@babel/plugin-proposal-private-methods"),
|
|
||||||
"transform-arrow-functions": require("@babel/plugin-transform-arrow-functions"),
|
|
||||||
"transform-block-scoped-functions": require("@babel/plugin-transform-block-scoped-functions"),
|
|
||||||
"transform-block-scoping": require("@babel/plugin-transform-block-scoping"),
|
|
||||||
"transform-classes": require("@babel/plugin-transform-classes"),
|
|
||||||
"transform-computed-properties": require("@babel/plugin-transform-computed-properties"),
|
|
||||||
"transform-destructuring": require("@babel/plugin-transform-destructuring"),
|
|
||||||
"transform-dotall-regex": require("@babel/plugin-transform-dotall-regex"),
|
|
||||||
"transform-duplicate-keys": require("@babel/plugin-transform-duplicate-keys"),
|
|
||||||
"transform-for-of": require("@babel/plugin-transform-for-of"),
|
|
||||||
"transform-function-name": require("@babel/plugin-transform-function-name"),
|
|
||||||
"transform-instanceof": require("@babel/plugin-transform-instanceof"),
|
|
||||||
"transform-literals": require("@babel/plugin-transform-literals"),
|
|
||||||
"transform-modules-amd": require("@babel/plugin-transform-modules-amd"),
|
|
||||||
"transform-modules-commonjs": require("@babel/plugin-transform-modules-commonjs"),
|
|
||||||
"transform-modules-systemjs": require("@babel/plugin-transform-modules-systemjs"),
|
|
||||||
"transform-modules-umd": require("@babel/plugin-transform-modules-umd"),
|
|
||||||
"transform-object-super": require("@babel/plugin-transform-object-super"),
|
|
||||||
"transform-parameters": require("@babel/plugin-transform-parameters"),
|
|
||||||
"transform-shorthand-properties": require("@babel/plugin-transform-shorthand-properties"),
|
|
||||||
"transform-spread": require("@babel/plugin-transform-spread"),
|
|
||||||
"transform-sticky-regex": require("@babel/plugin-transform-sticky-regex"),
|
|
||||||
"transform-template-literals": require("@babel/plugin-transform-template-literals"),
|
|
||||||
"transform-typeof-symbol": require("@babel/plugin-transform-typeof-symbol"),
|
|
||||||
"transform-typescript": require("@babel/plugin-transform-typescript"),
|
|
||||||
"transform-unicode-regex": require("@babel/plugin-transform-unicode-regex"),
|
|
||||||
"transform-member-expression-literals": require("@babel/plugin-transform-member-expression-literals"),
|
|
||||||
"transform-property-literals": require("@babel/plugin-transform-property-literals"),
|
|
||||||
"transform-property-mutators": require("@babel/plugin-transform-property-mutators"),
|
|
||||||
"transform-exponentiation-operator": require("@babel/plugin-transform-exponentiation-operator"),
|
|
||||||
"transform-flow-comments": require("@babel/plugin-transform-flow-comments"),
|
|
||||||
"transform-flow-strip-types": require("@babel/plugin-transform-flow-strip-types"),
|
|
||||||
"proposal-function-bind": require("@babel/plugin-proposal-function-bind"),
|
|
||||||
"transform-jscript": require("@babel/plugin-transform-jscript"),
|
|
||||||
"transform-new-target": require("@babel/plugin-transform-new-target"),
|
|
||||||
"transform-object-assign": require("@babel/plugin-transform-object-assign"),
|
|
||||||
"proposal-object-rest-spread": require("@babel/plugin-proposal-object-rest-spread"),
|
|
||||||
"transform-object-set-prototype-of-to-assign": require("@babel/plugin-transform-object-set-prototype-of-to-assign"),
|
|
||||||
"proposal-optional-catch-binding": require("@babel/plugin-proposal-optional-catch-binding"),
|
|
||||||
"transform-proto-to-assign": require("@babel/plugin-transform-proto-to-assign"),
|
|
||||||
"transform-react-constant-elements": require("@babel/plugin-transform-react-constant-elements"),
|
|
||||||
"transform-react-display-name": require("@babel/plugin-transform-react-display-name"),
|
|
||||||
"transform-react-inline-elements": require("@babel/plugin-transform-react-inline-elements"),
|
|
||||||
"transform-react-jsx": require("@babel/plugin-transform-react-jsx"),
|
|
||||||
"transform-react-jsx-compat": require("@babel/plugin-transform-react-jsx-compat"),
|
|
||||||
"transform-react-jsx-self": require("@babel/plugin-transform-react-jsx-self"),
|
|
||||||
"transform-react-jsx-source": require("@babel/plugin-transform-react-jsx-source"),
|
|
||||||
"transform-regenerator": require("@babel/plugin-transform-regenerator"),
|
|
||||||
"transform-runtime": require("@babel/plugin-transform-runtime"),
|
|
||||||
"transform-strict-mode": require("@babel/plugin-transform-strict-mode"),
|
|
||||||
"proposal-unicode-property-regex": require("@babel/plugin-proposal-unicode-property-regex"),
|
|
||||||
});
|
|
||||||
|
|
||||||
// All the presets we should bundle
|
// All the presets we should bundle
|
||||||
// Want to get rid of this whitelist of presets?
|
// Want to get rid of this whitelist of presets?
|
||||||
// Wait! Please read https://github.com/babel/babel/pull/6177 first.
|
// Wait! Please read https://github.com/babel/babel/pull/6177 first.
|
||||||
registerPresets({
|
registerPresets({
|
||||||
es2015: require("./preset-es2015"),
|
es2015: preset2015,
|
||||||
es2016: () => {
|
es2016: () => {
|
||||||
return {
|
return {
|
||||||
plugins: [availablePlugins["transform-exponentiation-operator"]],
|
plugins: [availablePlugins["transform-exponentiation-operator"]],
|
||||||
@ -233,22 +174,23 @@ registerPresets({
|
|||||||
plugins: [availablePlugins["transform-async-to-generator"]],
|
plugins: [availablePlugins["transform-async-to-generator"]],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
react: require("@babel/preset-react"),
|
react: presetReact,
|
||||||
"stage-0": require("./preset-stage-0"),
|
"stage-0": presetStage0,
|
||||||
"stage-1": require("./preset-stage-1"),
|
"stage-1": presetStage1,
|
||||||
"stage-2": require("./preset-stage-2"),
|
"stage-2": presetStage2,
|
||||||
"stage-3": require("./preset-stage-3"),
|
"stage-3": presetStage3,
|
||||||
"es2015-loose": {
|
"es2015-loose": {
|
||||||
presets: [[require("./preset-es2015"), { loose: true }]],
|
presets: [[preset2015, { loose: true }]],
|
||||||
},
|
},
|
||||||
// ES2015 preset with es2015-modules-commonjs removed
|
// ES2015 preset with es2015-modules-commonjs removed
|
||||||
"es2015-no-commonjs": {
|
"es2015-no-commonjs": {
|
||||||
presets: [[require("./preset-es2015"), { modules: false }]],
|
presets: [[preset2015, { modules: false }]],
|
||||||
},
|
},
|
||||||
typescript: require("@babel/preset-typescript"),
|
typescript: presetTypescript,
|
||||||
flow: require("@babel/preset-flow"),
|
flow: presetFlow,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// $FlowIgnore
|
||||||
export const version = VERSION;
|
export const version = VERSION;
|
||||||
|
|
||||||
function onDOMContentLoaded() {
|
function onDOMContentLoaded() {
|
||||||
@ -265,7 +207,7 @@ if (typeof window !== "undefined" && window && window.addEventListener) {
|
|||||||
* Transform <script> tags with "text/babel" type.
|
* Transform <script> tags with "text/babel" type.
|
||||||
* @param {Array} scriptTags specify script tags to transform, transform all in the <head> if not given
|
* @param {Array} scriptTags specify script tags to transform, transform all in the <head> if not given
|
||||||
*/
|
*/
|
||||||
export function transformScriptTags(scriptTags) {
|
export function transformScriptTags(scriptTags?: Array<any>) {
|
||||||
runScripts(transform, scriptTags);
|
runScripts(transform, scriptTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,7 @@
|
|||||||
import transformES2015TemplateLiterals from "@babel/plugin-transform-template-literals";
|
// @flow
|
||||||
import transformES2015Literals from "@babel/plugin-transform-literals";
|
import * as babelPlugins from "./generated/plugins";
|
||||||
import transformES2015FunctionName from "@babel/plugin-transform-function-name";
|
|
||||||
import transformES2015ArrowFunctions from "@babel/plugin-transform-arrow-functions";
|
|
||||||
import transformES2015BlockScopedFunctions from "@babel/plugin-transform-block-scoped-functions";
|
|
||||||
import transformES2015Classes from "@babel/plugin-transform-classes";
|
|
||||||
import transformES2015ObjectSuper from "@babel/plugin-transform-object-super";
|
|
||||||
import transformES2015ShorthandProperties from "@babel/plugin-transform-shorthand-properties";
|
|
||||||
import transformES2015DuplicateKeys from "@babel/plugin-transform-duplicate-keys";
|
|
||||||
import transformES2015ComputedProperties from "@babel/plugin-transform-computed-properties";
|
|
||||||
import transformES2015ForOf from "@babel/plugin-transform-for-of";
|
|
||||||
import transformES2015StickyRegex from "@babel/plugin-transform-sticky-regex";
|
|
||||||
import transformES2015UnicodeRegex from "@babel/plugin-transform-unicode-regex";
|
|
||||||
import transformES2015Spread from "@babel/plugin-transform-spread";
|
|
||||||
import transformES2015Parameters from "@babel/plugin-transform-parameters";
|
|
||||||
import transformES2015Destructuring from "@babel/plugin-transform-destructuring";
|
|
||||||
import transformES2015BlockScoping from "@babel/plugin-transform-block-scoping";
|
|
||||||
import transformES2015TypeofSymbol from "@babel/plugin-transform-typeof-symbol";
|
|
||||||
import transformES2015ModulesCommonJS from "@babel/plugin-transform-modules-commonjs";
|
|
||||||
import transformES2015ModulesSystemJS from "@babel/plugin-transform-modules-systemjs";
|
|
||||||
import transformES2015ModulesAMD from "@babel/plugin-transform-modules-amd";
|
|
||||||
import transformES2015ModulesUMD from "@babel/plugin-transform-modules-umd";
|
|
||||||
import transformES2015Instanceof from "@babel/plugin-transform-instanceof";
|
|
||||||
import transformRegenerator from "@babel/plugin-transform-regenerator";
|
|
||||||
|
|
||||||
export default (_, opts) => {
|
export default (_: any, opts: Object): Object => {
|
||||||
let loose = false;
|
let loose = false;
|
||||||
let modules = "commonjs";
|
let modules = "commonjs";
|
||||||
let spec = false;
|
let spec = false;
|
||||||
@ -39,33 +17,39 @@ export default (_, opts) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
plugins: [
|
plugins: [
|
||||||
[transformES2015TemplateLiterals, { loose, spec }],
|
[babelPlugins.transformTemplateLiterals, { loose, spec }],
|
||||||
transformES2015Literals,
|
babelPlugins.transformLiterals,
|
||||||
transformES2015FunctionName,
|
babelPlugins.transformFunctionName,
|
||||||
[transformES2015ArrowFunctions, { spec }],
|
[babelPlugins.transformArrowFunctions, { spec }],
|
||||||
transformES2015BlockScopedFunctions,
|
babelPlugins.transformBlockScopedFunctions,
|
||||||
[transformES2015Classes, optsLoose],
|
[babelPlugins.transformClasses, optsLoose],
|
||||||
transformES2015ObjectSuper,
|
babelPlugins.transformObjectSuper,
|
||||||
transformES2015ShorthandProperties,
|
babelPlugins.transformShorthandProperties,
|
||||||
transformES2015DuplicateKeys,
|
babelPlugins.transformDuplicateKeys,
|
||||||
[transformES2015ComputedProperties, optsLoose],
|
[babelPlugins.transformComputedProperties, optsLoose],
|
||||||
[transformES2015ForOf, optsLoose],
|
[babelPlugins.transformForOf, optsLoose],
|
||||||
transformES2015StickyRegex,
|
babelPlugins.transformStickyRegex,
|
||||||
transformES2015UnicodeRegex,
|
babelPlugins.transformUnicodeRegex,
|
||||||
[transformES2015Spread, optsLoose],
|
[babelPlugins.transformSpread, optsLoose],
|
||||||
[transformES2015Parameters, optsLoose],
|
[babelPlugins.transformParameters, optsLoose],
|
||||||
[transformES2015Destructuring, optsLoose],
|
[babelPlugins.transformDestructuring, optsLoose],
|
||||||
transformES2015BlockScoping,
|
babelPlugins.transformBlockScoping,
|
||||||
transformES2015TypeofSymbol,
|
babelPlugins.transformTypeofSymbol,
|
||||||
transformES2015Instanceof,
|
babelPlugins.transformInstanceof,
|
||||||
(modules === "commonjs" || modules === "cjs") && [
|
(modules === "commonjs" || modules === "cjs") && [
|
||||||
transformES2015ModulesCommonJS,
|
babelPlugins.transformModulesCommonjs,
|
||||||
optsLoose,
|
optsLoose,
|
||||||
],
|
],
|
||||||
modules === "systemjs" && [transformES2015ModulesSystemJS, optsLoose],
|
modules === "systemjs" && [
|
||||||
modules === "amd" && [transformES2015ModulesAMD, optsLoose],
|
babelPlugins.transformModulesSystemjs,
|
||||||
modules === "umd" && [transformES2015ModulesUMD, optsLoose],
|
optsLoose,
|
||||||
[transformRegenerator, { async: false, asyncGenerators: false }],
|
],
|
||||||
|
modules === "amd" && [babelPlugins.transformModulesAmd, optsLoose],
|
||||||
|
modules === "umd" && [babelPlugins.transformModulesUmd, optsLoose],
|
||||||
|
[
|
||||||
|
babelPlugins.transformRegenerator,
|
||||||
|
{ async: false, asyncGenerators: false },
|
||||||
|
],
|
||||||
].filter(Boolean), // filter out falsy values
|
].filter(Boolean), // filter out falsy values
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
|
// @flow
|
||||||
import presetStage1 from "./preset-stage-1";
|
import presetStage1 from "./preset-stage-1";
|
||||||
|
import { proposalFunctionBind } from "./generated/plugins";
|
||||||
|
|
||||||
import transformFunctionBind from "@babel/plugin-proposal-function-bind";
|
export default (_: any, opts: Object = {}) => {
|
||||||
|
|
||||||
export default (_, opts = {}) => {
|
|
||||||
const {
|
const {
|
||||||
loose = false,
|
loose = false,
|
||||||
useBuiltIns = false,
|
useBuiltIns = false,
|
||||||
@ -24,6 +24,6 @@ export default (_, opts = {}) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
plugins: [transformFunctionBind],
|
plugins: [proposalFunctionBind],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,13 +1,8 @@
|
|||||||
|
// @flow
|
||||||
import presetStage2 from "./preset-stage-2";
|
import presetStage2 from "./preset-stage-2";
|
||||||
|
import * as babelPlugins from "./generated/plugins";
|
||||||
|
|
||||||
import transformExportDefaultFrom from "@babel/plugin-proposal-export-default-from";
|
export default (_: any, opts: Object = {}) => {
|
||||||
import transformLogicalAssignmentOperators from "@babel/plugin-proposal-logical-assignment-operators";
|
|
||||||
import transformOptionalChaining from "@babel/plugin-proposal-optional-chaining";
|
|
||||||
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 (_, opts = {}) => {
|
|
||||||
const {
|
const {
|
||||||
loose = false,
|
loose = false,
|
||||||
useBuiltIns = false,
|
useBuiltIns = false,
|
||||||
@ -24,12 +19,12 @@ export default (_, opts = {}) => {
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
transformExportDefaultFrom,
|
babelPlugins.proposalExportDefaultFrom,
|
||||||
transformLogicalAssignmentOperators,
|
babelPlugins.proposalLogicalAssignmentOperators,
|
||||||
[transformOptionalChaining, { loose }],
|
[babelPlugins.proposalOptionalChaining, { loose }],
|
||||||
[transformPipelineOperator, { proposal: pipelineProposal }],
|
[babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],
|
||||||
[transformNullishCoalescingOperator, { loose }],
|
[babelPlugins.proposalNullishCoalescingOperator, { loose }],
|
||||||
transformDoExpressions,
|
babelPlugins.proposalDoExpressions,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,12 +1,8 @@
|
|||||||
|
// @flow
|
||||||
import presetStage3 from "./preset-stage-3";
|
import presetStage3 from "./preset-stage-3";
|
||||||
|
import * as babelPlugins from "./generated/plugins";
|
||||||
|
|
||||||
import transformDecorators from "@babel/plugin-proposal-decorators";
|
export default (_: any, opts: Object = {}) => {
|
||||||
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 (_, opts = {}) => {
|
|
||||||
const {
|
const {
|
||||||
loose = false,
|
loose = false,
|
||||||
useBuiltIns = false,
|
useBuiltIns = false,
|
||||||
@ -18,13 +14,13 @@ export default (_, opts = {}) => {
|
|||||||
presets: [[presetStage3, { loose, useBuiltIns }]],
|
presets: [[presetStage3, { loose, useBuiltIns }]],
|
||||||
plugins: [
|
plugins: [
|
||||||
[
|
[
|
||||||
transformDecorators,
|
babelPlugins.proposalDecorators,
|
||||||
{ legacy: decoratorsLegacy, decoratorsBeforeExport },
|
{ legacy: decoratorsLegacy, decoratorsBeforeExport },
|
||||||
],
|
],
|
||||||
transformFunctionSent,
|
babelPlugins.proposalFunctionSent,
|
||||||
transformExportNamespaceFrom,
|
babelPlugins.proposalExportNamespaceFrom,
|
||||||
transformNumericSeparator,
|
babelPlugins.proposalNumericSeparator,
|
||||||
transformThrowExpressions,
|
babelPlugins.proposalThrowExpressions,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";
|
// @flow
|
||||||
import syntaxImportMeta from "@babel/plugin-syntax-import-meta";
|
import * as babelPlugins from "./generated/plugins";
|
||||||
import transformClassProperties from "@babel/plugin-proposal-class-properties";
|
|
||||||
import transformJsonStrings from "@babel/plugin-proposal-json-strings";
|
|
||||||
import transformPrivateMethods from "@babel/plugin-proposal-private-methods";
|
|
||||||
|
|
||||||
export default (_, opts) => {
|
export default (_: any, opts: Object) => {
|
||||||
let loose = false;
|
let loose = false;
|
||||||
|
|
||||||
if (opts !== undefined) {
|
if (opts !== undefined) {
|
||||||
@ -13,11 +10,11 @@ export default (_, opts) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
plugins: [
|
plugins: [
|
||||||
syntaxDynamicImport,
|
babelPlugins.syntaxDynamicImport,
|
||||||
syntaxImportMeta,
|
babelPlugins.syntaxImportMeta,
|
||||||
[transformClassProperties, { loose }],
|
[babelPlugins.proposalClassProperties, { loose }],
|
||||||
transformJsonStrings,
|
babelPlugins.proposalJsonStrings,
|
||||||
[transformPrivateMethods, { loose }],
|
[babelPlugins.proposalPrivateMethods, { loose }],
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,39 +1,29 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
const generateBuilders = require("./generators/generateBuilders");
|
const generateBuilders = require("./generators/generateBuilders");
|
||||||
const generateValidators = require("./generators/generateValidators");
|
const generateValidators = require("./generators/generateValidators");
|
||||||
const generateAsserts = require("./generators/generateAsserts");
|
const generateAsserts = require("./generators/generateAsserts");
|
||||||
const generateConstants = require("./generators/generateConstants");
|
const generateConstants = require("./generators/generateConstants");
|
||||||
const format = require("./utils/formatCode");
|
const format = require("../../../scripts/utils/formatCode");
|
||||||
|
const writeFile = require("../../../scripts/utils/writeFileAndMkDir");
|
||||||
|
|
||||||
const baseDir = path.join(__dirname, "../src");
|
const baseDir = path.join(__dirname, "../src");
|
||||||
|
|
||||||
function writeFile(content, location) {
|
|
||||||
const file = path.join(baseDir, location);
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(path.dirname(file));
|
|
||||||
} catch (error) {
|
|
||||||
if (error.code !== "EEXIST") {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(file, format(content, file));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Generating @babel/types dynamic functions");
|
console.log("Generating @babel/types dynamic functions");
|
||||||
|
|
||||||
writeFile(generateBuilders(), "builders/generated/index.js");
|
const buildersFile = path.join(baseDir, "builders/generated/index.js");
|
||||||
|
writeFile(buildersFile, format(generateBuilders(), buildersFile));
|
||||||
console.log(` ${chalk.green("✔")} Generated builders`);
|
console.log(` ${chalk.green("✔")} Generated builders`);
|
||||||
|
|
||||||
writeFile(generateValidators(), "validators/generated/index.js");
|
const validatorsFile = path.join(baseDir, "validators/generated/index.js");
|
||||||
|
writeFile(validatorsFile, format(generateValidators(), validatorsFile));
|
||||||
console.log(` ${chalk.green("✔")} Generated validators`);
|
console.log(` ${chalk.green("✔")} Generated validators`);
|
||||||
|
|
||||||
writeFile(generateAsserts(), "asserts/generated/index.js");
|
const assertsFile = path.join(baseDir, "asserts/generated/index.js");
|
||||||
|
writeFile(assertsFile, format(generateAsserts(), assertsFile));
|
||||||
console.log(` ${chalk.green("✔")} Generated asserts`);
|
console.log(` ${chalk.green("✔")} Generated asserts`);
|
||||||
|
|
||||||
writeFile(generateConstants(), "constants/generated/index.js");
|
const constantsFile = path.join(baseDir, "constants/generated/index.js");
|
||||||
|
writeFile(constantsFile, format(generateConstants(), constantsFile));
|
||||||
console.log(` ${chalk.green("✔")} Generated constants`);
|
console.log(` ${chalk.green("✔")} Generated constants`);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module.exports = function formatCode(code, filename) {
|
|||||||
filename = filename || __filename;
|
filename = filename || __filename;
|
||||||
const prettierConfig = prettier.resolveConfig.sync(filename);
|
const prettierConfig = prettier.resolveConfig.sync(filename);
|
||||||
prettierConfig.filepath = filename;
|
prettierConfig.filepath = filename;
|
||||||
prettierConfig.parser = "babylon";
|
prettierConfig.parser = "babel";
|
||||||
|
|
||||||
return prettier.format(code, prettierConfig);
|
return prettier.format(code, prettierConfig);
|
||||||
};
|
};
|
||||||
14
scripts/utils/writeFileAndMkDir.js
Normal file
14
scripts/utils/writeFileAndMkDir.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
module.exports = function writeFileAndMkDir(file, content) {
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.dirname(file));
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== "EEXIST") {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(file, content);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user