Skip to content

Commit

Permalink
Fix emit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jun 10, 2019
1 parent 9777fb9 commit 5bd3402
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 213 deletions.
12 changes: 12 additions & 0 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3118,6 +3118,18 @@ namespace ts {
return node.emitNode;
}

/**
* Sets `EmitFlags.NoComments` on a node and removes any leading and trailing synthetic comments.
* @internal
*/
export function removeAllComments<T extends Node>(node: T): T {
const emitNode = getOrCreateEmitNode(node);
emitNode.flags |= EmitFlags.NoComments;
emitNode.leadingComments = undefined;
emitNode.trailingComments = undefined;
return node;
}

export function setTextRange<T extends TextRange>(range: T, location: TextRange | undefined): T {
if (location) {
range.pos = location.pos;
Expand Down
34 changes: 27 additions & 7 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ namespace ts {
case SyntaxKind.ComputedPropertyName:
return visitComputedPropertyName(node as ComputedPropertyName);

default:
case SyntaxKind.SemicolonClassElement:
return node;

default:
return visitor(node);
}
}

Expand Down Expand Up @@ -138,28 +141,30 @@ namespace ts {
if (!forEach(node.members, isPropertyDeclaration)) {
return visitEachChild(node, visitor, context);
}

const savedPendingExpressions = pendingExpressions;
pendingExpressions = undefined;
pendingExpressions = undefined!;

const extendsClauseElement = getEffectiveBaseTypeNode(node);
const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword);

const statements: Statement[] = [
updateClassDeclaration(
node,
node.decorators,
/*decorators*/ undefined,
node.modifiers,
node.name,
node.typeParameters,
node.heritageClauses,
/*typeParameters*/ undefined,
visitNodes(node.heritageClauses, visitor, isHeritageClause),
transformClassMembers(node, isDerivedClass)
)
];

// Write any pending expressions from elided or moved computed property names
if (some(pendingExpressions)) {
statements.push(createExpressionStatement(inlineExpressions(pendingExpressions!)));
statements.push(createExpressionStatement(inlineExpressions(pendingExpressions)));
}

pendingExpressions = savedPendingExpressions;

// Emit static property assignment. Because classDeclaration is lexically evaluated,
Expand Down Expand Up @@ -199,7 +204,7 @@ namespace ts {
node,
node.modifiers,
node.name,
node.typeParameters,
/*typeParameters*/ undefined,
visitNodes(node.heritageClauses, visitor, isHeritageClause),
transformClassMembers(node, isDerivedClass)
);
Expand Down Expand Up @@ -329,6 +334,21 @@ namespace ts {
// this.x = 1;
// }
//
if (constructor && constructor.body) {
let parameterPropertyDeclarationCount = 0;
for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) {
if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]))) {
parameterPropertyDeclarationCount++;
}
else {
break;
}
}
if (parameterPropertyDeclarationCount > 0) {
addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount));
indexOfFirstStatement += parameterPropertyDeclarationCount;
}
}
addInitializedPropertyStatements(statements, properties, createThis());

// Add existing statements, skipping the initial super call.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ namespace ts {
break;

default:
Debug.failBadSyntaxKind(node);
Debug.failBadSyntaxKind(member, currentSourceFile && currentSourceFile.fileName);
break;
}
}
Expand Down
Loading

0 comments on commit 5bd3402

Please sign in to comment.