Skip to content

[babel 8] Use @babel/types for parser's return type#17117

Merged
nicolo-ribaudo merged 3 commits intobabel:mainfrom
nicolo-ribaudo:babel-8-parser-types
Feb 14, 2025
Merged

[babel 8] Use @babel/types for parser's return type#17117
nicolo-ribaudo merged 3 commits intobabel:mainfrom
nicolo-ribaudo:babel-8-parser-types

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues? Fixes #17093
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In Babel 7 we are already using @babel/types in @babel/parser/typings/babel-parser.ts. However, Babel 8 uses package.json#exports thus that file is ignored.

By casting the type to the proper AST types in the parse() function itself, we can also use the @babel/types definitions in:

  • Babel 8
  • Local development

One day we can actually de-duplicate the definitions, but it's a lot of work and it can wait :)

@@ -1,177 +1,24 @@
// Type definitions for @babel/parser
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I left this file here to avoid accidental breaking changes, but now it's just re-exporting form the source.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Feb 7, 2025

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58687

};

export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };
export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, PluginConfig as ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note: the difference in these two lines is that before it contained , ParserPlugin,, while after it contains , PluginConfig as ParserPlugin,.

Comment on lines -258 to -266
interface ParseError {
code: string;
reasonCode: string;
}

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These two are just moved above.

options?: ParserOptions
): ParseResult<_babel_types.Expression>;

interface ParserOptions {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is also just moved above (and renamed, but then the export keeps the old name).

@nicolo-ribaudo
Copy link
Copy Markdown
Member Author

I'll merge this, release a new 8.0.0 alpha, play around with it, and see if we are finally ready for the beta :)

@nicolo-ribaudo nicolo-ribaudo merged commit 4cf5c9e into babel:main Feb 14, 2025
@nicolo-ribaudo nicolo-ribaudo deleted the babel-8-parser-types branch February 14, 2025 11:12
laine-hallot pushed a commit to laine-hallot/uwu-parser that referenced this pull request Mar 31, 2025
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 17, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

babel 8 i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[babel 8] The return type of @babel/core's parseSync is not assignable to the first arg of traverse

2 participants