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
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
"/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also ignore this file in our linter config as long as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't completely turn off lint for this file in the hope of learning about new errors. |
||
) | ||
); | ||
|
||
return Promise.all(tasks); | ||
} | ||
|
||
function copyDts(packages) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,84 @@ | ||
/* 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> | ||
|
@@ -8,20 +89,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. | ||
|
@@ -125,91 +206,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 }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's about to export There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liuxingbaoyu @nicolo-ribaudo WDYT? |
There was a problem hiding this comment.
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.