diff --git a/Gulpfile.mjs b/Gulpfile.mjs index 2abc07253411..b46f664da6e1 100644 --- a/Gulpfile.mjs +++ b/Gulpfile.mjs @@ -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", + "// 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) { diff --git a/package.json b/package.json index fb1ebf702ec2..ca990c351970 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index 03a00fc61016..b806352dbb35 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/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 @@ -8,20 +90,20 @@ /** * Parse the provided code as an entire ECMAScript program. */ -export function parse( +declare function parse( input: string, options?: ParserOptions -): ParseResult; +): ParseResult<_babel_types.File>; /** * Parse the provided code as a single expression. */ -export function parseExpression( +declare function parseExpression( input: string, options?: ParserOptions -): ParseResult; +): 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. @@ -125,87 +207,15 @@ 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; } @@ -213,3 +223,5 @@ export interface ParseError { type ParseResult = Result & { errors: ParseError[]; }; + +export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes }; diff --git a/packages/babel-parser/typings/babel-parser.source.d.ts b/packages/babel-parser/typings/babel-parser.source.d.ts new file mode 100644 index 000000000000..0bcbefe602ab --- /dev/null +++ b/packages/babel-parser/typings/babel-parser.source.d.ts @@ -0,0 +1,151 @@ +// Type definitions for @babel/parser +// Project: https://github.com/babel/babel/tree/main/packages/babel-parser +// Definitions by: Troy Gerwien +// Marvin Hagemeister +// Avi Vahl +// TypeScript Version: 2.9 + +/** + * Parse the provided code as an entire ECMAScript program. + */ +export function parse( + input: string, + options?: ParserOptions +): ParseResult; + +/** + * Parse the provided code as a single expression. + */ +export function parseExpression( + input: string, + options?: ParserOptions +): ParseResult; + +export 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. + */ + allowImportExportEverywhere?: boolean; + + /** + * By default, await use is not allowed outside of an async function. + * Set this to true to accept such code. + */ + allowAwaitOutsideFunction?: boolean; + + /** + * By default, a return statement at the top level raises an error. + * Set this to true to accept such code. + */ + allowReturnOutsideFunction?: boolean; + + allowSuperOutsideMethod?: boolean; + + /** + * By default, exported identifiers must refer to a declared variable. + * Set this to true to allow export statements to reference undeclared variables. + */ + allowUndeclaredExports?: boolean; + + /** + * By default, Babel attaches comments to adjacent AST nodes. + * When this option is set to false, comments are not attached. + * It can provide up to 30% performance improvement when the input code has many comments. + * @babel/eslint-parser will set it for you. + * It is not recommended to use attachComment: false with Babel transform, + * as doing so removes all the comments in output code, and renders annotations such as + * /* istanbul ignore next *\/ nonfunctional. + */ + attachComment?: boolean; + + /** + * By default, Babel always throws an error when it finds some invalid code. + * When this option is set to true, it will store the parsing error and + * try to continue parsing the invalid input file. + */ + errorRecovery?: boolean; + + /** + * Indicate the mode the code should be parsed in. + * Can be one of "script", "module", or "unambiguous". Defaults to "script". + * "unambiguous" will make @babel/parser attempt to guess, based on the presence + * of ES6 import or export statements. + * Files with ES6 imports and exports are considered "module" and are otherwise "script". + */ + sourceType?: "script" | "module" | "unambiguous"; + + /** + * Correlate output AST nodes with their source filename. + * Useful when generating code and source maps from the ASTs of multiple input files. + */ + sourceFilename?: string; + + /** + * By default, the first line of code parsed is treated as line 1. + * You can provide a line number to alternatively start with. + * Useful for integration with other source tools. + */ + startLine?: number; + + /** + * By default, the parsed code is treated as if it starts from line 1, column 0. + * You can provide a column number to alternatively start with. + * Useful for integration with other source tools. + */ + startColumn?: number; + + /** + * Array containing the plugins that you want to enable. + */ + plugins?: ParserPlugin[]; + + /** + * Should the parser work in strict mode. + * Defaults to true if sourceType === 'module'. Otherwise, false. + */ + strictMode?: boolean; + + /** + * Adds a ranges property to each node: [node.start, node.end] + */ + ranges?: boolean; + + /** + * Adds all parsed tokens to a tokens property on the File node. + */ + tokens?: boolean; + + /** + * By default, the parser adds information about parentheses by setting + * `extra.parenthesized` to `true` as needed. + * When this option is `true` the parser creates `ParenthesizedExpression` + * AST nodes instead of using the `extra` property. + */ + createParenthesizedExpressions?: boolean; +} + +export type ParserPlugin = import("../src/typings").PluginConfig; + +export type { + ParserPluginWithOptions, + DecoratorsPluginOptions, + PipelineOperatorPluginOptions, + RecordAndTuplePluginOptions, + FlowPluginOptions, + TypeScriptPluginOptions, +} from "../src/typings"; + +export const tokTypes: { + // todo(flow->ts) real token type + [name: string]: any; +}; + +export interface ParseError { + code: string; + reasonCode: string; +} + +type ParseResult = Result & { + errors: ParseError[]; +}; diff --git a/yarn.lock b/yarn.lock index 3bcd979bbf3a..e39c093fc9ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5964,7 +5964,7 @@ __metadata: 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 @@ -11172,12 +11172,12 @@ fsevents@^1.2.7: languageName: node linkType: hard -"magic-string@npm:^0.26.1": - version: 0.26.1 - resolution: "magic-string@npm:0.26.1" +"magic-string@npm:^0.26.7": + version: 0.26.7 + resolution: "magic-string@npm:0.26.7" dependencies: sourcemap-codec: ^1.4.8 - checksum: 23f21f5734346ddfbabd7b9834e3ecda3521e3e1db81166c1513b45b729489bbed1eafa8cd052c7db7fdc7c68ebc5c03bc00dd5a23697edda15dbecaf8c98397 + checksum: 89b0d60cbb32bbf3d1e23c46ea93db082d18a8230b972027aecb10a40bba51be519ecce0674f995571e3affe917b76b09f59d8dbc9a1b2c9c4102a2b6e8a2b01 languageName: node linkType: hard @@ -13231,19 +13231,19 @@ fsevents@^1.2.7: languageName: node linkType: hard -"rollup-plugin-dts@npm:^4.2.2": - version: 4.2.2 - resolution: "rollup-plugin-dts@npm:4.2.2" +"rollup-plugin-dts@npm:^5.0.0": + version: 5.0.0 + resolution: "rollup-plugin-dts@npm:5.0.0" dependencies: - "@babel/code-frame": ^7.16.7 - magic-string: ^0.26.1 + "@babel/code-frame": ^7.18.6 + magic-string: ^0.26.7 peerDependencies: - rollup: ^2.55 + rollup: ^3.0.0 typescript: ^4.1 dependenciesMeta: "@babel/code-frame": optional: true - checksum: cf4b45f6cca442a5f44af0f0fb567c8fc540ecb792c763571d1bcda9bf495803bcc8d4eaef451a2dd32f7f391eb822e2b96cc6b86b096db54a4d3935236fd8da + checksum: feb2d614528c255ee698120be0fd404b0a4fa312362a3d687d76551157464decc66be6dfecb624c42bc64a9e6298ed21e13e689dc9b144acab8294cd08a53455 languageName: node linkType: hard