Skip to content

Commit 1479823

Browse files
committed
Fix emit issues
1 parent 6178abe commit 1479823

File tree

8 files changed

+211
-213
lines changed

8 files changed

+211
-213
lines changed

Diff for: src/compiler/factory.ts

+12
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,18 @@ namespace ts {
31183118
return node.emitNode;
31193119
}
31203120

3121+
/**
3122+
* Sets `EmitFlags.NoComments` on a node and removes any leading and trailing synthetic comments.
3123+
* @internal
3124+
*/
3125+
export function removeAllComments<T extends Node>(node: T): T {
3126+
const emitNode = getOrCreateEmitNode(node);
3127+
emitNode.flags |= EmitFlags.NoComments;
3128+
emitNode.leadingComments = undefined;
3129+
emitNode.trailingComments = undefined;
3130+
return node;
3131+
}
3132+
31213133
export function setTextRange<T extends TextRange>(range: T, location: TextRange | undefined): T {
31223134
if (location) {
31233135
range.pos = location.pos;

Diff for: src/compiler/transformers/classFields.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ namespace ts {
9090
case SyntaxKind.ComputedPropertyName:
9191
return visitComputedPropertyName(node as ComputedPropertyName);
9292

93-
default:
93+
case SyntaxKind.SemicolonClassElement:
9494
return node;
95+
96+
default:
97+
return visitor(node);
9598
}
9699
}
97100

@@ -138,28 +141,30 @@ namespace ts {
138141
if (!forEach(node.members, isPropertyDeclaration)) {
139142
return visitEachChild(node, visitor, context);
140143
}
144+
141145
const savedPendingExpressions = pendingExpressions;
142-
pendingExpressions = undefined;
146+
pendingExpressions = undefined!;
143147

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

147151
const statements: Statement[] = [
148152
updateClassDeclaration(
149153
node,
150-
node.decorators,
154+
/*decorators*/ undefined,
151155
node.modifiers,
152156
node.name,
153-
node.typeParameters,
154-
node.heritageClauses,
157+
/*typeParameters*/ undefined,
158+
visitNodes(node.heritageClauses, visitor, isHeritageClause),
155159
transformClassMembers(node, isDerivedClass)
156160
)
157161
];
158162

159163
// Write any pending expressions from elided or moved computed property names
160164
if (some(pendingExpressions)) {
161-
statements.push(createExpressionStatement(inlineExpressions(pendingExpressions!)));
165+
statements.push(createExpressionStatement(inlineExpressions(pendingExpressions)));
162166
}
167+
163168
pendingExpressions = savedPendingExpressions;
164169

165170
// Emit static property assignment. Because classDeclaration is lexically evaluated,
@@ -199,7 +204,7 @@ namespace ts {
199204
node,
200205
node.modifiers,
201206
node.name,
202-
node.typeParameters,
207+
/*typeParameters*/ undefined,
203208
visitNodes(node.heritageClauses, visitor, isHeritageClause),
204209
transformClassMembers(node, isDerivedClass)
205210
);
@@ -329,6 +334,21 @@ namespace ts {
329334
// this.x = 1;
330335
// }
331336
//
337+
if (constructor && constructor.body) {
338+
let parameterPropertyDeclarationCount = 0;
339+
for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) {
340+
if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]))) {
341+
parameterPropertyDeclarationCount++;
342+
}
343+
else {
344+
break;
345+
}
346+
}
347+
if (parameterPropertyDeclarationCount > 0) {
348+
addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount));
349+
indexOfFirstStatement += parameterPropertyDeclarationCount;
350+
}
351+
}
332352
addInitializedPropertyStatements(statements, properties, createThis());
333353

334354
// Add existing statements, skipping the initial super call.

Diff for: src/compiler/transformers/es2015.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ namespace ts {
15671567
break;
15681568

15691569
default:
1570-
Debug.failBadSyntaxKind(node);
1570+
Debug.failBadSyntaxKind(member, currentSourceFile && currentSourceFile.fileName);
15711571
break;
15721572
}
15731573
}

0 commit comments

Comments
 (0)