You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,33 @@
60
60
61
61
This fix was contributed by [@magic-akari](https://github.com/magic-akari).
62
62
63
+
* Allow `declare` class fields to be initialized ([#2380](https://github.com/evanw/esbuild/issues/2380))
64
+
65
+
This release fixes an oversight in the TypeScript parser that disallowed initializers for `declare` class fields. TypeScript actually allows the following limited initializer expressions for `readonly` fields:
66
+
67
+
```ts
68
+
declare const enum a { b = 0 }
69
+
70
+
class Foo {
71
+
// These are allowed by TypeScript
72
+
declare readonly a = 0
73
+
declare readonly b = -0
74
+
declare readonly c = 0n
75
+
declare readonly d = -0n
76
+
declare readonly e = 'x'
77
+
declare readonly f = `x`
78
+
declare readonly g = a.b
79
+
declare readonly h = a['b']
80
+
81
+
// These are not allowed by TypeScript
82
+
declare readonly x = (0)
83
+
declare readonly y = null
84
+
declare readonly z = -a.b
85
+
}
86
+
```
87
+
88
+
So with this release, esbuild now allows initializers for `declare` class fields too. To future-proof this in case TypeScript allows more expressions as initializers in the future (such as `null`), esbuild will allow any expression as an initializer and will leave the specifics of TypeScript's special-casing here to the TypeScript type checker.
89
+
63
90
* Fix a bug in esbuild's feature compatibility table generator ([#2365](https://github.com/evanw/esbuild/issues/2365))
64
91
65
92
Passing specific JavaScript engines to esbuild's `--target` flag restricts esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates. The data for this feature is automatically derived from this compatibility table with a script: https://kangax.github.io/compat-table/.
0 commit comments