mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
useDefineForClassFields skips emit of ambient properties
Previously:
```ts
class C {
declare p
}
```
would incorrectly emit
```js
class C {
constructor() {
Object.defineProperty(this, "p", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
}
```
when useDefineForClassFields was turned on (for targets <ESNext).
This commit is contained in:
@@ -314,7 +314,7 @@ namespace ts {
|
||||
*/
|
||||
function isInitializedOrStaticProperty(member: ClassElement, requireInitializer: boolean, isStatic: boolean) {
|
||||
return isPropertyDeclaration(member)
|
||||
&& (!!member.initializer || !requireInitializer)
|
||||
&& (!!member.initializer || !requireInitializer && !(getOriginalNode(member).flags & NodeFlags.Ambient))
|
||||
&& hasStaticModifier(member) === isStatic;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ class A {
|
||||
["computed"] = 13
|
||||
;[x] = 14
|
||||
m() { }
|
||||
declare notEmitted: boolean;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,5 +21,8 @@ class A {
|
||||
|
||||
m() { }
|
||||
>m : Symbol(A.m, Decl(definePropertyES5.ts, 5, 13))
|
||||
|
||||
declare notEmitted: boolean;
|
||||
>notEmitted : Symbol(A.notEmitted, Decl(definePropertyES5.ts, 6, 11))
|
||||
}
|
||||
|
||||
|
||||
@@ -25,5 +25,8 @@ class A {
|
||||
|
||||
m() { }
|
||||
>m : () => void
|
||||
|
||||
declare notEmitted: boolean;
|
||||
>notEmitted : boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@ class A {
|
||||
["computed"] = 13
|
||||
;[x] = 14
|
||||
m() { }
|
||||
declare notEmitted: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user