Skip to content

Commit ba3f604

Browse files
committed
allow ASI before < in typescript type parameters
1 parent 0818e03 commit ba3f604

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
The upcoming version of TypeScript adds the `moduleSuffixes` field to `tsconfig.json` that introduces more rules to import path resolution. Setting `moduleSuffixes` to `[".ios", ".native", ""]` will try to look at the the relative files `./foo.ios.ts`, `./foo.native.ts`, and finally `./foo.ts` for an import path of `./foo`. Note that the empty string `""` in `moduleSuffixes` is necessary for TypeScript to also look-up `./foo.ts`. This was announced in the [TypeScript 4.7 beta blog post](https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#resolution-customization-with-modulesuffixes).
88

9+
* Match the new ASI behavior from TypeScript nightly builds
10+
11+
This release updates esbuild to match some very recent behavior changes in the TypeScript parser regarding automatic semicolon insertion. For more information, see the following issues:
12+
13+
* https://github.com/microsoft/TypeScript/issues/48711
14+
915
## 0.14.36
1016

1117
* Revert path metadata validation for now ([#2177](https://github.com/evanw/esbuild/issues/2177))

internal/js_parser/ts_parser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ func (p *parser) skipTypeScriptTypeWithOpts(level js_ast.L, opts skipTypeOpts) {
380380
p.lexer.Next()
381381
}
382382

383-
p.skipTypeScriptTypeArguments(false /* isInsideJSXElement */)
383+
if !p.lexer.HasNewlineBefore {
384+
p.skipTypeScriptTypeArguments(false /* isInsideJSXElement */)
385+
}
384386
}
385387

386388
case js_lexer.TOpenBracket:

internal/js_parser/ts_parser_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,13 +1900,19 @@ func TestTSInstantiationExpression(t *testing.T) {
19001900
expectParseErrorTS(t, "const a8 = f<number><number>;", "<stdin>: ERROR: Unexpected \";\"\n")
19011901
expectParseErrorTS(t, "const b1 = f?.<number>;", "<stdin>: ERROR: Expected \"(\" but found \";\"\n")
19021902

1903-
// The TypeScript compiler doesn't do semicolon insertion before "<" when
1904-
// inside "typeof" but does in other situations. Was this an oversight? Not sure,
1905-
// but we replicate this behavior because it matters when JSX syntax is enabled.
1906-
expectPrintedTSX(t, "type x = typeof y\n<number>\n1", "1;\n")
1907-
expectParseErrorTS(t, "type x = typeof y\n<number>\n1\n</number>", "<stdin>: ERROR: Unterminated regular expression\n")
1908-
expectParseErrorTSX(t, "type x = y\n<number>\n1", "<stdin>: ERROR: Unexpected end of file\n")
1909-
expectPrintedTSX(t, "type x = y\n<number>\n1\n</number>", "/* @__PURE__ */ React.createElement(\"number\", null, \"1\");\n")
1903+
// See: https://github.com/microsoft/TypeScript/issues/48711
1904+
expectPrintedTS(t, "type x = y\n<number>\nz", "z;\n")
1905+
expectPrintedTSX(t, "type x = y\n<number>\nz\n</number>", "/* @__PURE__ */ React.createElement(\"number\", null, \"z\");\n")
1906+
expectPrintedTS(t, "type x = typeof y\n<number>\nz", "z;\n")
1907+
expectPrintedTSX(t, "type x = typeof y\n<number>\nz\n</number>", "/* @__PURE__ */ React.createElement(\"number\", null, \"z\");\n")
1908+
expectPrintedTS(t, "interface Foo { \n (a: number): a \n <T>(): void \n }", "")
1909+
expectPrintedTSX(t, "interface Foo { \n (a: number): a \n <T>(): void \n }", "")
1910+
expectPrintedTS(t, "interface Foo { \n (a: number): typeof a \n <T>(): void \n }", "")
1911+
expectPrintedTSX(t, "interface Foo { \n (a: number): typeof a \n <T>(): void \n }", "")
1912+
expectParseErrorTS(t, "type x = y\n<number>\nz\n</number>", "<stdin>: ERROR: Unterminated regular expression\n")
1913+
expectParseErrorTSX(t, "type x = y\n<number>\nz", "<stdin>: ERROR: Unexpected end of file\n")
1914+
expectParseErrorTS(t, "type x = typeof y\n<number>\nz\n</number>", "<stdin>: ERROR: Unterminated regular expression\n")
1915+
expectParseErrorTSX(t, "type x = typeof y\n<number>\nz", "<stdin>: ERROR: Unexpected end of file\n")
19101916
}
19111917

19121918
func TestTSExponentiation(t *testing.T) {

0 commit comments

Comments
 (0)