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

fix: parser typings for plugins #15094

Merged
merged 6 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 28 additions & 20 deletions Gulpfile.mjs
Expand Up @@ -527,29 +527,37 @@ function buildRollup(packages, buildStandalone) {
}

function buildRollupDts(packages) {
const sourcemap = process.env.NODE_ENV === "production";
return Promise.all(
packages.map(async packageName => {
const input = `${mapToDts(packageName)}/src/index.d.ts`;
const output = `${packageName}/lib/index.d.ts`;
log(`Bundling '${chalk.cyan(output)}' with rollup ...`);
async function build(input, output, banner) {
log(`Bundling '${chalk.cyan(output)}' with rollup ...`);

const bundle = await rollup({
input,
plugins: [rollupDts()],
onwarn(warning, warn) {
if (warning.code !== "CIRCULAR_DEPENDENCY") warn(warning);
},
});
const bundle = await rollup({
input,
plugins: [rollupDts()],
});

await bundle.write({
file: output,
format: "es",
sourcemap: sourcemap,
exports: "named",
});
})
await bundle.write({
file: output,
format: "es",
banner,
});
}

const tasks = packages.map(async packageName => {
const input = `${mapToDts(packageName)}/src/index.d.ts`;
const output = `${packageName}/lib/index.d.ts`;

await build(input, output);
});

tasks.push(
build(
"packages/babel-parser/typings/babel-parser.source.d.ts",
"packages/babel-parser/typings/babel-parser.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

If babel-parser.d.ts is generated, please leave a note at the top of this file. So new contributors will know this file is not supposed to be edited.

"// This file is auto-generated! Do not modify it directly.\n/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */"
)
);

return Promise.all(tasks);
}

function copyDts(packages) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -66,7 +66,7 @@
"mergeiterator": "^1.4.4",
"prettier": "^2.7.1",
"rollup": "^2.78.0",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-dts": "^5.0.0",
"rollup-plugin-polyfill-node": "^0.10.2",
"rollup-plugin-terser": "^7.0.2",
"semver": "^6.3.0",
Expand Down
172 changes: 92 additions & 80 deletions packages/babel-parser/typings/babel-parser.d.ts
@@ -1,3 +1,85 @@
// This file is auto-generated! Do not modify it directly.
/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */
import * as _babel_types from '@babel/types';

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

type ParserPluginWithOptions =
| ["decorators", DecoratorsPluginOptions]
| ["estree", { classFeatures?: boolean }]
// @deprecated
| ["moduleAttributes", { version: "may-2020" }]
| ["pipelineOperator", PipelineOperatorPluginOptions]
| ["recordAndTuple", RecordAndTuplePluginOptions]
| ["flow", FlowPluginOptions]
| ["typescript", TypeScriptPluginOptions];

type PluginConfig = Plugin | ParserPluginWithOptions;

interface DecoratorsPluginOptions {
decoratorsBeforeExport?: boolean;
allowCallParenthesized?: boolean;
}

interface PipelineOperatorPluginOptions {
proposal: "minimal" | "fsharp" | "hack" | "smart";
topicToken?: "%" | "#" | "@@" | "^^" | "^";
}

interface RecordAndTuplePluginOptions {
syntaxType: "bar" | "hash";
}

interface FlowPluginOptions {
all?: boolean;
enums?: boolean;
}

interface TypeScriptPluginOptions {
dts?: boolean;
disallowAmbiguousJSXLike?: boolean;
}

// Type definitions for @babel/parser
// Project: https://github.com/babel/babel/tree/main/packages/babel-parser
// Definitions by: Troy Gerwien <https://github.com/yortus>
Expand All @@ -8,20 +90,20 @@
/**
* Parse the provided code as an entire ECMAScript program.
*/
export function parse(
declare function parse(
input: string,
options?: ParserOptions
): ParseResult<import("@babel/types").File>;
): ParseResult<_babel_types.File>;

/**
* Parse the provided code as a single expression.
*/
export function parseExpression(
declare function parseExpression(
input: string,
options?: ParserOptions
): ParseResult<import("@babel/types").Expression>;
): ParseResult<_babel_types.Expression>;

export interface ParserOptions {
interface ParserOptions {
/**
* By default, import and export declarations can only appear at a program's top level.
* Setting this option to true allows them anywhere where a statement is allowed.
Expand Down Expand Up @@ -125,91 +207,21 @@ export interface ParserOptions {
createParenthesizedExpressions?: boolean;
}

export type ParserPlugin =
| "asyncDoExpressions"
| "asyncGenerators"
| "bigInt"
| "classPrivateMethods"
| "classPrivateProperties"
| "classProperties"
| "classStaticBlock" // Enabled by default
| "decimal"
| "decorators"
| "decorators-legacy"
| "decoratorAutoAccessors"
| "destructuringPrivate"
| "doExpressions"
| "dynamicImport"
| "estree"
| "exportDefaultFrom"
| "exportNamespaceFrom" // deprecated
| "flow"
| "flowComments"
| "functionBind"
| "functionSent"
| "importMeta"
| "jsx"
| "logicalAssignment"
| "importAssertions"
| "moduleBlocks"
| "moduleStringNames"
| "nullishCoalescingOperator"
| "numericSeparator"
| "objectRestSpread"
| "optionalCatchBinding"
| "optionalChaining"
| "partialApplication"
| "pipelineOperator"
| "placeholders"
| "privateIn" // Enabled by default
| "recordAndTuple"
| "regexpUnicodeSets"
| "throwExpressions"
| "topLevelAwait"
| "typescript"
| "v8intrinsic"
| ParserPluginWithOptions;

export type ParserPluginWithOptions =
| ["decorators", DecoratorsPluginOptions]
| ["pipelineOperator", PipelineOperatorPluginOptions]
| ["recordAndTuple", RecordAndTuplePluginOptions]
| ["flow", FlowPluginOptions]
| ["typescript", TypeScriptPluginOptions];

export interface DecoratorsPluginOptions {
decoratorsBeforeExport?: boolean;
}

export interface PipelineOperatorPluginOptions {
proposal: "minimal" | "fsharp" | "hack" | "smart";
topicToken?: "%" | "#" | "@@" | "^^" | "^";
}
type ParserPlugin = PluginConfig;

export interface RecordAndTuplePluginOptions {
syntaxType?: "bar" | "hash";
}

export interface FlowPluginOptions {
all?: boolean;
enums?: boolean;
}

export interface TypeScriptPluginOptions {
dts?: boolean;
disallowAmbiguousJSXLike?: boolean;
}

export const tokTypes: {
declare const tokTypes: {
// todo(flow->ts) real token type
[name: string]: any;
};

export interface ParseError {
interface ParseError {
code: string;
reasonCode: string;
}

type ParseResult<Result> = Result & {
errors: ParseError[];
};

export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };
Copy link
Contributor

Choose a reason for hiding this comment

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

what's about to export ParseResult?

Copy link
Contributor

Choose a reason for hiding this comment

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