microsoft / microsoft/TypeScript

Crash: optional chain + tagged template panics the optional-chain transform

Open
#63,965 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

flattenChain tagged template, KindTaggedTemplateExpression, "Unhandled case in Node.Expression", "isOptionalChain", optional chain tagged template crash, e?.``(

🕗 Version & Regression Information
  • This is a crash
  • This is the behavior in every version I tried: TypeScript 6.0.3 (JS) and 7.1.0-dev (main, Go)
  • I have reviewed the FAQ for entries about optional chaining and tagged templates. Those entries do not cover this compiler crash.
⏯ Playground Link

Not useful here. The crash needs ES2020 optional-chain emit. Use the CLI command below.

💻 Code
e?.``(
🙁 Actual behavior
panic: Unhandled case in Node.Expression: KindTaggedTemplateExpression [recovered, repanicked]

goroutine 13 [running]:
sync.(*WaitGroup).Go.func1.1()
        sync/waitgroup.go:251 +0x48
panic({0x10417d8e0?, 0x2b3e77a92750?})
        runtime/panic.go:860 +0x12c
github.com/microsoft/TypeScript/tsc/internal/ast.(*Node).Expression(...)
        github.com/microsoft/TypeScript/tsc/internal/ast/ast.go:383 +0x718
github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms.flattenChain(...)
        github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms/optionalchain.go:143 +0x1c4
github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms.(*optionalChainTransformer).visitOptionalExpression(...)
        github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms/optionalchain.go:151 +0x38
github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms.(*optionalChainTransformer).visitCallExpression(...)
        github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms/optionalchain.go:37 +0x190
github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms.(*optionalChainTransformer).visit(...)
        github.com/microsoft/TypeScript/tsc/internal/transformers/estransforms/optionalchain.go:20 +0xd0
github.com/microsoft/TypeScript/tsc/internal/ast.(*NodeVisitor).VisitNode(...)
        github.com/microsoft/TypeScript/tsc/internal/ast/visitor.go:51 +0x30
github.com/microsoft/TypeScript/tsc/internal/ast.(*ExpressionStatement).VisitEachChild(...)
        github.com/microsoft/TypeScript/tsc/internal/ast/ast_generated.go:1592 +0x30
... 74 lines truncated ...
github.com/microsoft/TypeScript/tsc/internal/compiler.(*emitter).emitJSFile(...)
        github.com/microsoft/TypeScript/tsc/internal/compiler/emitter.go:200 +0x198
github.com/microsoft/TypeScript/tsc/internal/compiler.(*emitter).emit(...)
        github.com/microsoft/TypeScript/tsc/internal/compiler/emitter.go:50 +0xec
github.com/microsoft/TypeScript/tsc/internal/compiler.(*Program).Emit.func2()
        github.com/microsoft/TypeScript/tsc/internal/compiler/program.go:1851 +0x1c0
🙂 Expected behavior

The compiler should not crash 😄

Additional information about the issue

Disclosure: This crash was found with a custom mutation fuzzer and AI assistance (Kimi K3). The input was minimized and then verified by hand against TypeScript 7.1.0-dev (main) and TypeScript 6.0.3.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tsc/internal/transformers/estransforms/optionalchain.go, especially flattenChain and visitOptionalExpression, then inspect the Node.Expression handling in tsc/internal/ast/ast.go. Run the minimized e?.``( example through the CLI with ES2020 optional-chain emit. Done means the compiler no longer panics on this input.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.