-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: TransformsRelates to the public transform APIRelates to the public transform APIEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 3.2.0-dev.20181011
Search Terms: computed property expression
Code
const classes = [];
for (let i = 0; i <= 10; ++i) {
classes.push(
class A {
[i] = "my property";
}
);
}
for (const clazz of classes) {
console.log(Object.getOwnPropertyNames(new clazz()));
}
Expected behavior: The log statements indicate that each class in classes
has a different property name (i
should be evaluated at the time of the class evaluation and all instances of that class should have a property name corresponding to that evaluation of i
).
Actual behavior: Compiled code logs:
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
[ '10' ]
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: TransformsRelates to the public transform APIRelates to the public transform APIEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
Activity
mheiber commentedon Oct 12, 2018
There's a type error on the line with the computed property:
However
DanielRosenwasser commentedon Oct 12, 2018
Taking PRs and marking it as moderate (assuming you are familiar with spec-reading and the transform pipeline).
mheiber commentedon Oct 13, 2018
What are the implications of getting rid of the type error? Will allowing arbitrary string and symbol values in computed field declarations affect inference?
Neuroboy23 commentedon Oct 16, 2018
Type errors aside, here's one possible emit that works correctly. I haven't seen any other cases of invoking an IIFE with parameters like this. Are there any?
mheiber commentedon Oct 18, 2018
Maybe we can lean on the iife stuff that's already done to transpile
let
andconst
.The currently generated code for Joey's example when targeting ES2015 is:
If we move
_a
and_b
into the containing scope of the class and uselet
then the output is correct:Kingwl commentedon Oct 23, 2018
the special temporary variable and hoist is happened in ts transformer before es2015
perhaps we need a block level hoist?
Fix microsoft#27864
mheiber commentedon Oct 26, 2018
@Kingwl agreed.
we're trying that approach in joeywatts#15used that approach in #28708
22 remaining items