Skip to content

Commit

Permalink
fix #3021: add support for const in object types
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 26, 2023
1 parent 72c8379 commit 079eca4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 { <const T>(): T }
type Bar = { new <const T>(): 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!
Expand Down
2 changes: 1 addition & 1 deletion internal/js_parser/ts_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions internal/js_parser/ts_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func TestTSTypes(t *testing.T) {
expectPrintedTS(t, "foo = function <const T>() {}", "foo = function() {\n};\n")
expectPrintedTS(t, "foo = function bar<const T>() {}", "foo = function bar() {\n};\n")
expectPrintedTS(t, "class Foo { bar<const T>() {} }", "class Foo {\n bar() {\n }\n}\n")
expectPrintedTS(t, "interface Foo { bar<const T>(): T }", "")
expectPrintedTS(t, "interface Foo { new bar<const T>(): T }", "")
expectPrintedTS(t, "let x: { bar<const T>(): T }", "let x;\n")
expectPrintedTS(t, "let x: { new bar<const T>(): T }", "let x;\n")
expectPrintedTS(t, "foo = { bar<const T>() {} }", "foo = { bar() {\n} };\n")
expectPrintedTS(t, "x = <const>(y)", "x = y;\n")
expectPrintedTS(t, "<const T>() => {}", "() => {\n};\n")
Expand Down

0 comments on commit 079eca4

Please sign in to comment.