Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean all always enabled parser plugins #16572

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Keep pluigins in babel-parser typings for Babel 7
  • Loading branch information
nicolo-ribaudo committed Aug 12, 2024
commit 734c1d9c979dece82a3056857d69399d89c4f150
25 changes: 15 additions & 10 deletions Gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,13 @@ function buildRollupDts(packages) {
const bundle = await rollup({
input,
plugins: [
{
transform: code =>
code.replace(
/type BABEL_8_BREAKING\s*=\s*boolean/g,
`type BABEL_8_BREAKING = ${bool(process.env.BABEL_8_BREAKING) ?? false}`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ?? false here seems to never be run?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool can return undefined. While it's ok usually, in this case undefined was included in the generated code.

),
},
bool(process.env.BABEL_8_BREAKING) ? rollupDts() : rollupDts5(),
],
external,
Expand Down Expand Up @@ -637,16 +644,14 @@ function buildRollupDts(packages) {
await build(input, output, "", packageName);
});

if (bool(process.env.BABEL_8_BREAKING)) {
tasks.push(
build(
"packages/babel-parser/typings/babel-parser.source.d.ts",
"packages/babel-parser/typings/babel-parser.d.ts",
"// This file is auto-generated! Do not modify it directly.\n/* eslint-disable @typescript-eslint/consistent-type-imports, prettier/prettier */",
"packages/babel-parser"
)
);
}
tasks.push(
build(
"packages/babel-parser/typings/babel-parser.source.d.ts",
"packages/babel-parser/typings/babel-parser.d.ts",
"// This file is auto-generated! Do not modify it directly.\n/* eslint-disable @typescript-eslint/consistent-type-imports, prettier/prettier */",
"packages/babel-parser"
)
);

return Promise.all(tasks);
}
Expand Down
24 changes: 22 additions & 2 deletions packages/babel-parser/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
type BABEL_8_BREAKING = boolean;
type IF_BABEL_7<V> = false extends BABEL_8_BREAKING ? V : never;

export type Plugin =
| "asyncDoExpressions"
| IF_BABEL_7<"asyncGenerators">
| IF_BABEL_7<"bigInt">
| IF_BABEL_7<"classPrivateMethods">
| IF_BABEL_7<"classPrivateProperties">
| IF_BABEL_7<"classProperties">
| IF_BABEL_7<"classStaticBlock">
| "decimal"
| "decorators-legacy"
| "deferredImportEvaluation"
| "decoratorAutoAccessors"
| "destructuringPrivate"
| "doExpressions"
| IF_BABEL_7<"dynamicImport">
| "explicitResourceManagement"
| "exportDefaultFrom"
| IF_BABEL_7<"exportNamespaceFrom">
| "flow"
| "flowComments"
| "functionBind"
| "functionSent"
| "importMeta"
| "jsx"
| IF_BABEL_7<"logicalAssignment">
| "importAssertions" // deprecated
| "importAttributes"
| "importReflection"
| "moduleBlocks"
| IF_BABEL_7<"moduleStringNames">
| IF_BABEL_7<"nullishCoalescingOperator">
| IF_BABEL_7<"numericSeparator">
| IF_BABEL_7<"objectRestSpread">
| IF_BABEL_7<"optionalCatchBinding">
| IF_BABEL_7<"optionalChaining">
| "partialApplication"
| "placeholders"
| IF_BABEL_7<"privateIn">
| IF_BABEL_7<"regexpUnicodeSets">
| "sourcePhaseImports"
| "throwExpressions"
| IF_BABEL_7<"topLevelAwait">
| "v8intrinsic"
| ParserPluginWithOptions[0];

export type ParserPluginWithOptions =
| ["decorators", DecoratorsPluginOptions]
| ["estree", { classFeatures?: boolean }]
| ["importAttributes", { deprecatedAssertSyntax: boolean }]
// @deprecated
| ["moduleAttributes", { version: "may-2020" }]
| IF_BABEL_7<["moduleAttributes", { version: "may-2020" }]>
| ["optionalChainingAssign", { version: "2023-07" }]
| ["pipelineOperator", PipelineOperatorPluginOptions]
| ["recordAndTuple", RecordAndTuplePluginOptions]
Expand Down
42 changes: 22 additions & 20 deletions packages/babel-parser/typings/babel-parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,59 @@
/* eslint-disable @typescript-eslint/consistent-type-imports, prettier/prettier */
import * as _babel_types from '@babel/types';

type BABEL_8_BREAKING = false;
type IF_BABEL_7<V> = false extends BABEL_8_BREAKING ? V : never;

type Plugin =
| "asyncDoExpressions"
| "asyncGenerators"
| "bigInt"
| "classPrivateMethods"
| "classPrivateProperties"
| "classProperties"
| "classStaticBlock" // Enabled by default
| IF_BABEL_7<"asyncGenerators">
| IF_BABEL_7<"bigInt">
| IF_BABEL_7<"classPrivateMethods">
| IF_BABEL_7<"classPrivateProperties">
| IF_BABEL_7<"classProperties">
| IF_BABEL_7<"classStaticBlock">
| "decimal"
| "decorators-legacy"
| "deferredImportEvaluation"
| "decoratorAutoAccessors"
| "destructuringPrivate"
| "doExpressions"
| "dynamicImport"
| IF_BABEL_7<"dynamicImport">
| "explicitResourceManagement"
| "exportDefaultFrom"
| "exportNamespaceFrom" // deprecated
| IF_BABEL_7<"exportNamespaceFrom">
| "flow"
| "flowComments"
| "functionBind"
| "functionSent"
| "importMeta"
| "jsx"
| "logicalAssignment"
| IF_BABEL_7<"logicalAssignment">
| "importAssertions" // deprecated
| "importAttributes"
| "importReflection"
| "moduleBlocks"
| "moduleStringNames"
| "nullishCoalescingOperator"
| "numericSeparator"
| "objectRestSpread"
| "optionalCatchBinding"
| "optionalChaining"
| IF_BABEL_7<"moduleStringNames">
| IF_BABEL_7<"nullishCoalescingOperator">
| IF_BABEL_7<"numericSeparator">
| IF_BABEL_7<"objectRestSpread">
| IF_BABEL_7<"optionalCatchBinding">
| IF_BABEL_7<"optionalChaining">
| "partialApplication"
| "placeholders"
| "privateIn" // Enabled by default
| "regexpUnicodeSets" // Enabled by default
| IF_BABEL_7<"privateIn">
| IF_BABEL_7<"regexpUnicodeSets">
| "sourcePhaseImports"
| "throwExpressions"
| "topLevelAwait"
| IF_BABEL_7<"topLevelAwait">
| "v8intrinsic"
| ParserPluginWithOptions[0];

type ParserPluginWithOptions =
| ["decorators", DecoratorsPluginOptions]
| ["estree", { classFeatures?: boolean }]
| ["importAttributes", { deprecatedAssertSyntax: boolean }]
// @deprecated
| ["moduleAttributes", { version: "may-2020" }]
| IF_BABEL_7<["moduleAttributes", { version: "may-2020" }]>
| ["optionalChainingAssign", { version: "2023-07" }]
| ["pipelineOperator", PipelineOperatorPluginOptions]
| ["recordAndTuple", RecordAndTuplePluginOptions]
Expand Down