Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tsc/internal/transformers/estransforms/classfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,9 @@ func (tx *classFieldsTransformer) visitMethodOrAccessorDeclaration(node *ast.Nod
}

// leave invalid code untransformed
info := tx.accessPrivateIdentifier(node.Name())
info, _ := tx.getPrivateIdentifier(tx.getPrivateIdentifierEnvironment(), node.Name())
debug.Assert(info != nil, "Undeclared private name for property declaration.")
if !info.isValid {
if info.kind == printer.PrivateIdentifierKindUntransformed || !info.isValid {
return node
}

Expand Down Expand Up @@ -895,11 +895,11 @@ func (tx *classFieldsTransformer) transformAutoAccessor(node *ast.PropertyDeclar
func (tx *classFieldsTransformer) transformPrivateFieldInitializer(node *ast.PropertyDeclaration) *ast.Node {
if tx.shouldTransformClassElementToWeakMap(node.AsNode()) {
// If we are transforming private elements into WeakMap/WeakSet, we should elide the node.
info := tx.accessPrivateIdentifier(node.Name())
info, _ := tx.getPrivateIdentifier(tx.getPrivateIdentifierEnvironment(), node.Name())
debug.Assert(info != nil, "Undeclared private name for property declaration.")

// Leave invalid code untransformed
if !info.isValid {
if info.kind == printer.PrivateIdentifierKindUntransformed || !info.isValid {
return node.AsNode()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
esDecorators-classDeclaration-methods-staticPrivate.ts(14,12): error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(15,5): error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(16,5): error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(17,12): error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(18,12): error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(19,5): error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(20,5): error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(21,12): error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(22,16): error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(23,9): error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(24,9): error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(25,16): error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.


==== esDecorators-classDeclaration-methods-staticPrivate.ts (12 errors) ====
declare let dec: any;

class C {
@dec static #method1() {}
}

@dec
class D {
static #method1() {}
}

@dec
class E {
static #a() {}
~~
!!! error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
#a() {}
~~
!!! error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
#b() {}
~~
!!! error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
static #b() {}
~~
!!! error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
static #c = 0;
~~
!!! error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
#c = 0;
~~
!!! error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
#d = 0;
~~
!!! error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
static #d = 0;
~~
!!! error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
static get #e() { return 0; }
~~
!!! error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
set #e(value: number) {}
~~
!!! error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
get #f() { return 0; }
~~
!!! error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
static set #f(value: number) {}
~~
!!! error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ class C {
class D {
static #method1() {}
}

@dec
class E {
static #a() {}
#a() {}
#b() {}
static #b() {}
static #c = 0;
#c = 0;
#d = 0;
static #d = 0;
static get #e() { return 0; }
set #e(value: number) {}
get #f() { return 0; }
static set #f(value: number) {}
}


//// [esDecorators-classDeclaration-methods-staticPrivate.js]
Expand Down Expand Up @@ -51,3 +67,45 @@ let D = (() => {
})();
return D = _classThis;
})();
let E = (() => {
var _E_instances, _E_a, _E_a_1, _E_b, _E_b_1, _E_c, _E_c_1, _E_d, _E_d_1, _E_e_get, _E_e_set, _E_f_get, _E_f_set;
let _classDecorators = [dec];
let _classDescriptor;
let _classExtraInitializers = [];
let _classThis;
var E = _classThis = class {
constructor() {
_E_instances.add(this);
_E_c_1.set(this, 0);
_E_d_1 = { value: 0 };
}
static #a() { }
#a() { }
#b() { }
static #b() { }
static #c = 0;
#c = 0;
#d = 0;
static #d = 0;
static get #e() { return 0; }
set #e(value) { }
get #f() { return 0; }
static set #f(value) { }
};
_E_c_1 = new WeakMap();
_E_d = new WeakMap();
_E_instances = new WeakSet();
__setFunctionName(_classThis, "E");
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
E = _classThis = _classDescriptor.value;
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})();
_E_c_1.set(_classThis, 0);
_E_d_1 = { value: 0 };
(() => {
__runInitializers(_classThis, _classExtraInitializers);
})();
return E = _classThis;
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
esDecorators-classDeclaration-methods-staticPrivate.ts(14,12): error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(15,5): error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(16,5): error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(17,12): error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(18,12): error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(19,5): error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(20,5): error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(21,12): error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(22,16): error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(23,9): error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(24,9): error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(25,16): error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.


==== esDecorators-classDeclaration-methods-staticPrivate.ts (12 errors) ====
declare let dec: any;

class C {
@dec static #method1() {}
}

@dec
class D {
static #method1() {}
}

@dec
class E {
static #a() {}
~~
!!! error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
#a() {}
~~
!!! error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
#b() {}
~~
!!! error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
static #b() {}
~~
!!! error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
static #c = 0;
~~
!!! error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
#c = 0;
~~
!!! error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
#d = 0;
~~
!!! error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
static #d = 0;
~~
!!! error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
static get #e() { return 0; }
~~
!!! error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
set #e(value: number) {}
~~
!!! error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
get #f() { return 0; }
~~
!!! error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
static set #f(value: number) {}
~~
!!! error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ class C {
class D {
static #method1() {}
}

@dec
class E {
static #a() {}
#a() {}
#b() {}
static #b() {}
static #c = 0;
#c = 0;
#d = 0;
static #d = 0;
static get #e() { return 0; }
set #e(value: number) {}
get #f() { return 0; }
static set #f(value: number) {}
}


//// [esDecorators-classDeclaration-methods-staticPrivate.js]
Expand Down Expand Up @@ -50,3 +66,36 @@ let D = (() => {
};
return D = _classThis;
})();
let E = (() => {
var _E_a, _E_b, _E_c, _E_d, _E_e_get, _E_f_set;
let _classDecorators = [dec];
let _classDescriptor;
let _classExtraInitializers = [];
let _classThis;
var E = class {
static { _classThis = this; }
static { __setFunctionName(this, "E"); }
static {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
E = _classThis = _classDescriptor.value;
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
}
static #a() { }
#a() { }
#b() { }
static #b() { }
static #c = 0;
#c = 0;
#d = 0;
static #d = 0;
static get #e() { return 0; }
set #e(value) { }
get #f() { return 0; }
static set #f(value) { }
static {
__runInitializers(_classThis, _classExtraInitializers);
}
};
return E = _classThis;
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
esDecorators-classDeclaration-methods-staticPrivate.ts(14,12): error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(15,5): error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(16,5): error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(17,12): error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(18,12): error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(19,5): error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(20,5): error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(21,12): error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(22,16): error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(23,9): error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(24,9): error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
esDecorators-classDeclaration-methods-staticPrivate.ts(25,16): error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.


==== esDecorators-classDeclaration-methods-staticPrivate.ts (12 errors) ====
declare let dec: any;

class C {
@dec static #method1() {}
}

@dec
class D {
static #method1() {}
}

@dec
class E {
static #a() {}
~~
!!! error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
#a() {}
~~
!!! error TS2804: Duplicate identifier '#a'. Static and instance elements cannot share the same private name.
#b() {}
~~
!!! error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
static #b() {}
~~
!!! error TS2804: Duplicate identifier '#b'. Static and instance elements cannot share the same private name.
static #c = 0;
~~
!!! error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
#c = 0;
~~
!!! error TS2804: Duplicate identifier '#c'. Static and instance elements cannot share the same private name.
#d = 0;
~~
!!! error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
static #d = 0;
~~
!!! error TS2804: Duplicate identifier '#d'. Static and instance elements cannot share the same private name.
static get #e() { return 0; }
~~
!!! error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
set #e(value: number) {}
~~
!!! error TS2804: Duplicate identifier '#e'. Static and instance elements cannot share the same private name.
get #f() { return 0; }
~~
!!! error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
static set #f(value: number) {}
~~
!!! error TS2804: Duplicate identifier '#f'. Static and instance elements cannot share the same private name.
}

Loading
Loading