microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.88k stars 12.47k forks source link

Unexpected ASI after `declare` (regression since version 4.4) #54602

Open evanw opened 1 year ago

evanw commented 1 year ago

Bug Report

🔎 Search Terms

declare asi semicolon

🕗 Version & Regression Information

⏯ Playground Link

Playground link for version 4.3.5 (fine) Playground link for version 4.4.4 (problematic)

💻 Code

Some random examples that TS 5.1 considers valid syntax (not exhaustive):

declare let declare: any, foo: any
declare foo
declare let declare: any, foo: any
declare foo()
declare let declare: any, foo: any
declare {foo}

🙁 Actual behavior

TypeScript silently does automatic semicolon insertion after declare in all of these cases without generating any syntax errors.

🙂 Expected behavior

I expected these to be syntax errors. I did not expect TypeScript to silently be doing automatic semicolon insertion after declare here as if this is valid syntax.

jakebailey commented 1 year ago

FWIW this (and #54760) bisects to #43005.