From 42d3b2fdfa1ea0afbea2932fb853e6aa31944279 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sun, 19 Feb 2023 11:30:27 -0500 Subject: [PATCH] fix #2937: parse rest bindings in TypeScript types --- CHANGELOG.md | 10 ++++++++++ internal/js_parser/ts_parser.go | 5 +++++ internal/js_parser/ts_parser_test.go | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 633eafd7af..50826b4330 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## Unreleased +* Parse rest bindings in TypeScript types ([#2937](https://github.com/evanw/esbuild/issues/2937)) + + Previously esbuild was unable to parse the following valid TypeScript code: + + ```ts + let tuple: (...[e1, e2, ...es]: any) => any + ``` + + This release includes support for parsing code like this. + * Fix TypeScript code translation for certain computed `declare` class fields ([#2914](https://github.com/evanw/esbuild/issues/2914)) In TypeScript, the key of a computed `declare` class field should only be preserved if there are no decorators for that field. Previously esbuild always preserved the key, but esbuild will now remove the key to match the output of the TypeScript compiler: diff --git a/internal/js_parser/ts_parser.go b/internal/js_parser/ts_parser.go index 64e95636e0..4cfd3a4cb5 100644 --- a/internal/js_parser/ts_parser.go +++ b/internal/js_parser/ts_parser.go @@ -30,6 +30,11 @@ func (p *parser) skipTypeScriptBinding() { // "[a, b]" for p.lexer.Token != js_lexer.TCloseBracket { + // "[...a]" + if p.lexer.Token == js_lexer.TDotDotDot { + p.lexer.Next() + } + p.skipTypeScriptBinding() if p.lexer.Token != js_lexer.TComma { break diff --git a/internal/js_parser/ts_parser_test.go b/internal/js_parser/ts_parser_test.go index d489e9e44c..46551245db 100644 --- a/internal/js_parser/ts_parser_test.go +++ b/internal/js_parser/ts_parser_test.go @@ -183,6 +183,12 @@ func TestTSTypes(t *testing.T) { expectPrintedTS(t, "type Foo = {} extends (infer T extends {}) ? A : never", "") expectPrintedTS(t, "let x: A extends B ? D : never", "let x;\n") expectPrintedTS(t, "let x: A extends B ? D : never", "let x;\n") + expectPrintedTS(t, "let x: ([e1, e2, ...es]: any) => any", "let x;\n") + expectPrintedTS(t, "let x: (...[e1, e2, es]: any) => any", "let x;\n") + expectPrintedTS(t, "let x: (...[e1, e2, ...es]: any) => any", "let x;\n") + expectPrintedTS(t, "let x: (y, [e1, e2, ...es]: any) => any", "let x;\n") + expectPrintedTS(t, "let x: (y, ...[e1, e2, es]: any) => any", "let x;\n") + expectPrintedTS(t, "let x: (y, ...[e1, e2, ...es]: any) => any", "let x;\n") expectPrintedTS(t, "let x: A.B", "let x;\n") expectPrintedTS(t, "let x: A.B=2", "let x = 2;\n")