mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Revised emit for computed property names, including with decorators (#19430)
* Revised emit for computed property names * Fix downlevel name generation scopes * Accept slightly more conservative baseline * First feedback pass * Reduce number of nonrequired variable declarations and assignments * Remove side-effect-free identifier references * skip partially emitted expressions * Comments, move starsOnNewLine to emitNode * Put expressions on newlines when inlined in class expressions for consistency * Update new ref * Fix typo in comment
This commit is contained in:
191
tests/cases/compiler/decoratorsOnComputedProperties.ts
Normal file
191
tests/cases/compiler/decoratorsOnComputedProperties.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
// @target: es6
|
||||
// @experimentalDecorators: true
|
||||
function x(o: object, k: PropertyKey) { }
|
||||
let i = 0;
|
||||
function foo(): string { return ++i + ""; }
|
||||
|
||||
const fieldNameA: string = "fieldName1";
|
||||
const fieldNameB: string = "fieldName2";
|
||||
const fieldNameC: string = "fieldName3";
|
||||
|
||||
class A {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
@x [fieldNameC]: any = null;
|
||||
}
|
||||
|
||||
void class B {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
@x [fieldNameC]: any = null;
|
||||
};
|
||||
|
||||
class C {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
@x [fieldNameC]: any = null;
|
||||
["some" + "method"]() {}
|
||||
}
|
||||
|
||||
void class D {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
@x [fieldNameC]: any = null;
|
||||
["some" + "method"]() {}
|
||||
};
|
||||
|
||||
class E {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
["some" + "method"]() {}
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
@x [fieldNameC]: any = null;
|
||||
}
|
||||
|
||||
void class F {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
["some" + "method"]() {}
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
@x [fieldNameC]: any = null;
|
||||
};
|
||||
|
||||
class G {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
["some" + "method"]() {}
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
["some" + "method2"]() {}
|
||||
@x [fieldNameC]: any = null;
|
||||
}
|
||||
|
||||
void class H {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
["some" + "method"]() {}
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
["some" + "method2"]() {}
|
||||
@x [fieldNameC]: any = null;
|
||||
};
|
||||
|
||||
class I {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
@x ["some" + "method"]() {}
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
["some" + "method2"]() {}
|
||||
@x [fieldNameC]: any = null;
|
||||
}
|
||||
|
||||
void class J {
|
||||
@x ["property"]: any;
|
||||
@x [Symbol.toStringTag]: any;
|
||||
@x ["property2"]: any = 2;
|
||||
@x [Symbol.iterator]: any = null;
|
||||
["property3"]: any;
|
||||
[Symbol.isConcatSpreadable]: any;
|
||||
["property4"]: any = 2;
|
||||
[Symbol.match]: any = null;
|
||||
[foo()]: any;
|
||||
@x [foo()]: any;
|
||||
@x [foo()]: any = null;
|
||||
@x ["some" + "method"]() {}
|
||||
[fieldNameA]: any;
|
||||
@x [fieldNameB]: any;
|
||||
["some" + "method2"]() {}
|
||||
@x [fieldNameC]: any = null;
|
||||
};
|
||||
Reference in New Issue
Block a user