Skip to content

Commit 079eca4

Browse files
committed
fix #3021: add support for const in object types
1 parent 72c8379 commit 079eca4

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
* Allow the TypeScript 5.0 `const` modifier in object type declarations ([#3021](https://github.com/evanw/esbuild/issues/3021))
6+
7+
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:
8+
9+
```ts
10+
interface Foo { <const T>(): T }
11+
type Bar = { new <const T>(): T }
12+
```
13+
514
* Implement preliminary lowering for CSS nesting ([#1945](https://github.com/evanw/esbuild/issues/1945))
615
716
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!

internal/js_parser/ts_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ func (p *parser) skipTypeScriptObjectType() {
599599
}
600600

601601
// Type parameters come right after the optional mark
602-
p.skipTypeScriptTypeParameters(0)
602+
p.skipTypeScriptTypeParameters(allowConstModifier)
603603

604604
switch p.lexer.Token {
605605
case js_lexer.TColon:

internal/js_parser/ts_parser_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ func TestTSTypes(t *testing.T) {
391391
expectPrintedTS(t, "foo = function <const T>() {}", "foo = function() {\n};\n")
392392
expectPrintedTS(t, "foo = function bar<const T>() {}", "foo = function bar() {\n};\n")
393393
expectPrintedTS(t, "class Foo { bar<const T>() {} }", "class Foo {\n bar() {\n }\n}\n")
394+
expectPrintedTS(t, "interface Foo { bar<const T>(): T }", "")
395+
expectPrintedTS(t, "interface Foo { new bar<const T>(): T }", "")
396+
expectPrintedTS(t, "let x: { bar<const T>(): T }", "let x;\n")
397+
expectPrintedTS(t, "let x: { new bar<const T>(): T }", "let x;\n")
394398
expectPrintedTS(t, "foo = { bar<const T>() {} }", "foo = { bar() {\n} };\n")
395399
expectPrintedTS(t, "x = <const>(y)", "x = y;\n")
396400
expectPrintedTS(t, "<const T>() => {}", "() => {\n};\n")

0 commit comments

Comments
 (0)