From 079eca4992344201185864c9282221c917c9a3d5 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sat, 25 Mar 2023 22:33:07 -0400 Subject: [PATCH] fix #3021: add support for `const` in object types --- CHANGELOG.md | 9 +++++++++ internal/js_parser/ts_parser.go | 2 +- internal/js_parser/ts_parser_test.go | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26006381da6..1e9c4ef7a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## Unreleased +* Allow the TypeScript 5.0 `const` modifier in object type declarations ([#3021](https://github.com/evanw/esbuild/issues/3021)) + + The new TypeScript 5.0 `const` modifier was added to esbuild in version 0.17.5, and works with classes, functions, and arrow expressions. However, support for it wasn't added to object type declarations (e.g. interfaces) due to an oversight. This release adds support for these cases, so the following TypeScript 5.0 code can now be built with esbuild: + + ```ts + interface Foo { (): T } + type Bar = { new (): T } + ``` + * Implement preliminary lowering for CSS nesting ([#1945](https://github.com/evanw/esbuild/issues/1945)) Chrome has [implemented the new CSS nesting specification](https://developer.chrome.com/articles/css-nesting/) in version 112, which is currently in beta but will become stable very soon. So CSS nesting is now a part of the web platform! diff --git a/internal/js_parser/ts_parser.go b/internal/js_parser/ts_parser.go index 4521aec0a83..22bacff5aa0 100644 --- a/internal/js_parser/ts_parser.go +++ b/internal/js_parser/ts_parser.go @@ -599,7 +599,7 @@ func (p *parser) skipTypeScriptObjectType() { } // Type parameters come right after the optional mark - p.skipTypeScriptTypeParameters(0) + p.skipTypeScriptTypeParameters(allowConstModifier) switch p.lexer.Token { case js_lexer.TColon: diff --git a/internal/js_parser/ts_parser_test.go b/internal/js_parser/ts_parser_test.go index 4912beb1c09..8cdaa88783b 100644 --- a/internal/js_parser/ts_parser_test.go +++ b/internal/js_parser/ts_parser_test.go @@ -391,6 +391,10 @@ func TestTSTypes(t *testing.T) { expectPrintedTS(t, "foo = function () {}", "foo = function() {\n};\n") expectPrintedTS(t, "foo = function bar() {}", "foo = function bar() {\n};\n") expectPrintedTS(t, "class Foo { bar() {} }", "class Foo {\n bar() {\n }\n}\n") + expectPrintedTS(t, "interface Foo { bar(): T }", "") + expectPrintedTS(t, "interface Foo { new bar(): T }", "") + expectPrintedTS(t, "let x: { bar(): T }", "let x;\n") + expectPrintedTS(t, "let x: { new bar(): T }", "let x;\n") expectPrintedTS(t, "foo = { bar() {} }", "foo = { bar() {\n} };\n") expectPrintedTS(t, "x = (y)", "x = y;\n") expectPrintedTS(t, "() => {}", "() => {\n};\n")