Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fix incorrect emit for accessing static property in static propertyDe…
…claration
  • Loading branch information
Kanchalai Tanglertsampan committed May 11, 2016
commit 9d26a945876868320ec0aff37063f2cf3fd13760
40 changes: 33 additions & 7 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
return false;
}

function nameOfClassExpressionInPropertyAccessInStaticPropertyDeclaration(node: Identifier) {
if (languageVersion >= ScriptTarget.ES6) {
let parent = node.parent;
if (parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>parent).expression === node) {
parent = parent.parent;
while (parent && !isDeclaration(parent)) {
parent = parent.parent;
}
return parent && parent.kind === SyntaxKind.PropertyDeclaration && (parent.flags & NodeFlags.Static) !== 0 &&
parent.parent.kind === SyntaxKind.ClassExpression ? parent.parent : undefined;
}
}
return undefined;
}

function emitIdentifier(node: Identifier) {
if (convertedLoopState) {
if (node.text == "arguments" && resolver.isArgumentsLocalBinding(node)) {
Expand All @@ -1685,6 +1700,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
write(node.text);
}
else if (isExpressionIdentifier(node)) {
const classExpression = nameOfClassExpressionInPropertyAccessInStaticPropertyDeclaration(node);
if (classExpression) {
const declaration = resolver.getReferencedValueDeclaration(node);
if (declaration == classExpression) {
write(getGeneratedNameForNode(declaration.name));
return;
}
}
emitExpressionIdentifier(node);
}
else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) {
Expand Down Expand Up @@ -5029,13 +5052,13 @@ const _super = (function (geti, seti) {
}
}

function emitPropertyDeclaration(node: ClassLikeDeclaration, property: PropertyDeclaration, receiver?: Identifier, isExpression?: boolean) {
function emitPropertyDeclaration(node: ClassLikeDeclaration, property: PropertyDeclaration, receiver?: string, isExpression?: boolean) {
writeLine();
emitLeadingComments(property);
emitStart(property);
emitStart(property.name);
if (receiver) {
emit(receiver);
write(receiver);
}
else {
if (property.flags & NodeFlags.Static) {
Expand Down Expand Up @@ -5454,13 +5477,16 @@ const _super = (function (geti, seti) {
// of it have been initialized by the time it is used.
const staticProperties = getInitializedProperties(node, /*isStatic*/ true);
const isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === SyntaxKind.ClassExpression;
let tempVariable: Identifier;
let generatedName: string;

if (isClassExpressionWithStaticProperties) {
tempVariable = createAndRecordTempVariable(TempFlags.Auto);
generatedName = getGeneratedNameForNode(node.name);
const synthesizedNode = <Identifier>createSynthesizedNode(SyntaxKind.Identifier);
synthesizedNode.text = generatedName;
recordTempDeclaration(synthesizedNode);
write("(");
increaseIndent();
emit(tempVariable);
emit(synthesizedNode);
write(" = ");
}

Expand Down Expand Up @@ -5504,11 +5530,11 @@ const _super = (function (geti, seti) {
for (const property of staticProperties) {
write(",");
writeLine();
emitPropertyDeclaration(node, property, /*receiver*/ tempVariable, /*isExpression*/ true);
emitPropertyDeclaration(node, property, /*receiver*/ generatedName, /*isExpression*/ true);
}
write(",");
writeLine();
emit(tempVariable);
write(generatedName);
decreaseIndent();
write(")");
}
Expand Down