22
33declare const USE_ESM : boolean ;
44
5- import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators" ;
6- import syntaxClassProperties from "@babel/plugin-syntax-class-properties" ;
7- import syntaxClassStaticBlock from "@babel/plugin-syntax-class-static-block" ;
8- import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import" ;
9- import syntaxExportNamespaceFrom from "@babel/plugin-syntax-export-namespace-from" ;
105import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" ;
116import syntaxImportAttributes from "@babel/plugin-syntax-import-attributes" ;
12- import syntaxImportMeta from "@babel/plugin-syntax-import-meta" ;
13- import syntaxJsonStrings from "@babel/plugin-syntax-json-strings" ;
14- import syntaxLogicalAssignmentOperators from "@babel/plugin-syntax-logical-assignment-operators" ;
15- import syntaxNullishCoalescingOperator from "@babel/plugin-syntax-nullish-coalescing-operator" ;
16- import syntaxNumericSeparator from "@babel/plugin-syntax-numeric-separator" ;
17- import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread" ;
18- import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding" ;
19- import syntaxOptionalChaining from "@babel/plugin-syntax-optional-chaining" ;
20- import syntaxPrivatePropertyInObject from "@babel/plugin-syntax-private-property-in-object" ;
21- import syntaxTopLevelAwait from "@babel/plugin-syntax-top-level-await" ;
7+
228import proposalAsyncGeneratorFunctions from "@babel/plugin-transform-async-generator-functions" ;
239import proposalClassProperties from "@babel/plugin-transform-class-properties" ;
2410import proposalClassStaticBlock from "@babel/plugin-transform-class-static-block" ;
@@ -77,7 +63,8 @@ import bugfixSafariForShadowing from "@babel/preset-modules/lib/plugins/transfor
7763import bugfixSafariIdDestructuringCollisionInFunctionExpression from "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression" ;
7864import bugfixV8SpreadParametersInOptionalChaining from "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining" ;
7965
80- export default {
66+ export { availablePlugins as default } ;
67+ const availablePlugins = {
8168 "bugfix/transform-async-arrows-in-class" : ( ) => bugfixAsyncArrowsInClass ,
8269 "bugfix/transform-edge-default-parameters" : ( ) => bugfixEdgeDefaultParameters ,
8370 "bugfix/transform-edge-function-name" : ( ) => bugfixEdgeFunctionName ,
@@ -88,37 +75,8 @@ export default {
8875 "bugfix/transform-tagged-template-caching" : ( ) => bugfixTaggedTemplateCaching ,
8976 "bugfix/transform-v8-spread-parameters-in-optional-chaining" : ( ) =>
9077 bugfixV8SpreadParametersInOptionalChaining ,
91- "syntax-async-generators" : ( ) => syntaxAsyncGenerators ,
92- "syntax-class-properties" : ( ) => syntaxClassProperties ,
93- "syntax-class-static-block" : ( ) => syntaxClassStaticBlock ,
94- "syntax-dynamic-import" : ( ) => syntaxDynamicImport ,
95- "syntax-export-namespace-from" : ( ) => syntaxExportNamespaceFrom ,
9678 "syntax-import-assertions" : ( ) => syntaxImportAssertions ,
9779 "syntax-import-attributes" : ( ) => syntaxImportAttributes ,
98- "syntax-import-meta" : ( ) => syntaxImportMeta ,
99- "syntax-json-strings" : ( ) => syntaxJsonStrings ,
100- "syntax-logical-assignment-operators" : ( ) => syntaxLogicalAssignmentOperators ,
101- "syntax-nullish-coalescing-operator" : ( ) => syntaxNullishCoalescingOperator ,
102- "syntax-numeric-separator" : ( ) => syntaxNumericSeparator ,
103- "syntax-object-rest-spread" : ( ) => syntaxObjectRestSpread ,
104- "syntax-optional-catch-binding" : ( ) => syntaxOptionalCatchBinding ,
105- "syntax-optional-chaining" : ( ) => syntaxOptionalChaining ,
106- "syntax-private-property-in-object" : ( ) => syntaxPrivatePropertyInObject ,
107- "syntax-top-level-await" : ( ) => syntaxTopLevelAwait ,
108- // This is a CJS plugin that depends on a package from the monorepo, so it
109- // breaks using ESM. Given that ESM builds are new enough to have this
110- // syntax enabled by default, we can safely skip enabling it.
111- "syntax-unicode-sets-regex" : USE_ESM
112- ? null
113- : // We cannot use the require call when bundling, because this is an ESM file.
114- // Babel standalone uses a modern parser, so just include a known noop plugin.
115- // Use `bind` so that it's not detected as a duplicate plugin when using it
116- // together with the TLA
117- IS_STANDALONE
118- ? // @ts -expect-error syntaxTopLevelAwait is a function when bundled
119- ( ) => syntaxTopLevelAwait . bind ( )
120- : // eslint-disable-next-line no-restricted-globals
121- ( ) => require ( "@babel/plugin-syntax-unicode-sets-regex" ) ,
12280 "transform-arrow-functions" : ( ) => transformArrowFunctions ,
12381 "transform-async-generator-functions" : ( ) => proposalAsyncGeneratorFunctions ,
12482 "transform-async-to-generator" : ( ) => transformAsyncToGenerator ,
@@ -173,10 +131,50 @@ export default {
173131 "transform-unicode-sets-regex" : ( ) => transformUnicodeSetsRegex ,
174132} ;
175133
176- export const minVersions = {
177- "bugfix/transform-safari-id-destructuring-collision-in-function-expression" :
178- "7.16.0" ,
179- "syntax-import-attributes" : "7.22.0" ,
180- "transform-class-static-block" : "7.12.0" ,
181- "transform-private-property-in-object" : "7.10.0" ,
182- } ;
134+ export const minVersions = { } ;
135+
136+ if ( ! process . env . BABEL_8_BREAKING ) {
137+ Object . assign ( minVersions , {
138+ "bugfix/transform-safari-id-destructuring-collision-in-function-expression" :
139+ "7.16.0" ,
140+ "syntax-import-attributes" : "7.22.0" ,
141+ "transform-class-static-block" : "7.12.0" ,
142+ "transform-private-property-in-object" : "7.10.0" ,
143+ } ) ;
144+
145+ const emptyPlugin = ( ) => ( { } ) ;
146+
147+ const babel7SyntaxPlugin = ( name : string ) => {
148+ // We cannot use the require call in ESM and when bundling.
149+ // Babel standalone uses a modern parser, so just include a noop plugin.
150+ // Use `bind` so that it's not detected as a duplicate plugin when using it.
151+ // @ts -expect-error key not recognized in the object
152+ availablePlugins [ `syntax-${ name } ` ] = USE_ESM
153+ ? ( ) => emptyPlugin . bind ( null )
154+ : IS_STANDALONE
155+ ? ( ) => emptyPlugin . bind ( null )
156+ : // eslint-disable-next-line no-restricted-globals
157+ ( ) => require ( `@babel/plugin-syntax-${ name } ` ) ;
158+ } ;
159+
160+ babel7SyntaxPlugin ( "async-generators" ) ;
161+ babel7SyntaxPlugin ( "class-properties" ) ;
162+ babel7SyntaxPlugin ( "class-static-block" ) ;
163+ babel7SyntaxPlugin ( "dynamic-import" ) ;
164+ babel7SyntaxPlugin ( "export-namespace-from" ) ;
165+ babel7SyntaxPlugin ( "import-meta" ) ;
166+ babel7SyntaxPlugin ( "json-strings" ) ;
167+ babel7SyntaxPlugin ( "logical-assignment-operators" ) ;
168+ babel7SyntaxPlugin ( "nullish-coalescing-operator" ) ;
169+ babel7SyntaxPlugin ( "numeric-separator" ) ;
170+ babel7SyntaxPlugin ( "object-rest-spread" ) ;
171+ babel7SyntaxPlugin ( "optional-catch-binding" ) ;
172+ babel7SyntaxPlugin ( "optional-chaining" ) ;
173+ babel7SyntaxPlugin ( "private-property-in-object" ) ;
174+ babel7SyntaxPlugin ( "top-level-await" ) ;
175+
176+ // This is a CJS plugin that depends on a package from the monorepo, so it
177+ // breaks using ESM. Given that ESM builds are new enough to have this
178+ // syntax enabled by default, we can safely skip enabling it.
179+ if ( ! USE_ESM ) babel7SyntaxPlugin ( "unicode-sets-regex" ) ;
180+ }
0 commit comments