Skip to content

TS parser small fixes#17888

Merged
JLHwung merged 12 commits into
babel:mainfrom
JLHwung:fix-ts-parser
Mar 25, 2026
Merged

TS parser small fixes#17888
JLHwung merged 12 commits into
babel:mainfrom
JLHwung:fix-ts-parser

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Mar 19, 2026

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

In this PR we cleaned up a few tsc parse test errors. The parser now rejects a few new productions which is also rejected by the tsc.

The typescript parser tests now also recognizes errors in the format of TestName(OptionKey=value).errors.txt, such as regExpWithOpenBracketInCharClass(target=esnext).errors.txt. Therefore, we have one more invalid case in the allowlist. This is currently expected because we don't parse regex in the Babel parser.

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories pkg: parser labels Mar 19, 2026
@JLHwung JLHwung force-pushed the fix-ts-parser branch 2 times, most recently from 9996668 to bae6d4f Compare March 20, 2026 18:55
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Mar 20, 2026

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 20, 2026

Open in StackBlitz

commit: 773b44a

@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Mar 20, 2026

/cc @fisker The following Prettier test is failing due to this PR
tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/format.test.js

Pending prettier test updates.

@JLHwung JLHwung marked this pull request as ready for review March 20, 2026 19:49
Comment thread scripts/parser-tests/typescript/error-codes.js Outdated
@fisker
Copy link
Copy Markdown
Contributor

fisker commented Mar 22, 2026

/cc @fisker The following Prettier test is failing due to this PR tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/format.test.js

Pending prettier test updates.

Thanks.

We can rm -f tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorOverloadsWithDefaultValues.ts to pass tests.

@JLHwung JLHwung requested a review from liuxingbaoyu March 23, 2026 18:01
// the parameters rather than the class method key.
this.raise(
TSErrors.DeclareFunctionHasImplementation,
this.state.lastTokEndLoc!,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might point to a space after ), this.state.startLoc would be better?
packages\babel-parser\test\fixtures\typescript\declare\module-function

Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Looks good, just a minor comment about naming.

"The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
TypeModifierIsUsedInTypeImports:
"The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
UnexpectedDeclaration: (type: "interface" | "type") =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer a name that makes it clearer that this is for TS thing, like UnexpectedTypeDeclaration (most of other TS errors have an error code that makes it clear they are about types/modifiers)

@JLHwung JLHwung merged commit 77cf673 into babel:main Mar 25, 2026
56 checks passed
@JLHwung JLHwung deleted the fix-ts-parser branch March 25, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: typescript pkg: parser PR: Spec Compliance 👓 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants