Skip to content

Commit c1197c5

Browse files
committed
Fix emit issues
1 parent 9777fb9 commit c1197c5

File tree

8 files changed

+210
-214
lines changed

8 files changed

+210
-214
lines changed

src/compiler/factory.ts

Lines changed: 12 additions & 0 deletions
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;

src/compiler/transformers/classFields.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,19 @@ namespace ts {
8282
case SyntaxKind.SetAccessor:
8383
case SyntaxKind.MethodDeclaration:
8484
// Visit the name of the member (if it's a computed property name).
85-
return visitEachChild(node, classElementVisitor, context);
85+
return visitEachChild(node, visitor, context);
8686

8787
case SyntaxKind.PropertyDeclaration:
8888
return visitPropertyDeclaration(node as PropertyDeclaration);
8989

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 Debug.failBadSyntaxKind(node);
9598
}
9699
}
97100

@@ -139,26 +142,26 @@ namespace ts {
139142
return visitEachChild(node, visitor, context);
140143
}
141144
const savedPendingExpressions = pendingExpressions;
142-
pendingExpressions = undefined;
145+
pendingExpressions = undefined!;
143146

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

147150
const statements: Statement[] = [
148151
updateClassDeclaration(
149152
node,
150-
node.decorators,
153+
/*decorators*/ undefined,
151154
node.modifiers,
152155
node.name,
153-
node.typeParameters,
154-
node.heritageClauses,
156+
/*typeParameters*/ undefined,
157+
visitNodes(node.heritageClauses, visitor, isHeritageClause),
155158
transformClassMembers(node, isDerivedClass)
156159
)
157160
];
158161

159162
// Write any pending expressions from elided or moved computed property names
160163
if (some(pendingExpressions)) {
161-
statements.push(createExpressionStatement(inlineExpressions(pendingExpressions!)));
164+
statements.push(createExpressionStatement(inlineExpressions(pendingExpressions)));
162165
}
163166
pendingExpressions = savedPendingExpressions;
164167

@@ -199,7 +202,7 @@ namespace ts {
199202
node,
200203
node.modifiers,
201204
node.name,
202-
node.typeParameters,
205+
/*typeParameters*/ undefined,
203206
visitNodes(node.heritageClauses, visitor, isHeritageClause),
204207
transformClassMembers(node, isDerivedClass)
205208
);
@@ -329,6 +332,21 @@ namespace ts {
329332
// this.x = 1;
330333
// }
331334
//
335+
if (constructor && constructor.body) {
336+
let parameterPropertyDeclarationCount = 0;
337+
for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) {
338+
if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]))) {
339+
parameterPropertyDeclarationCount++;
340+
}
341+
else {
342+
break;
343+
}
344+
}
345+
if (parameterPropertyDeclarationCount > 0) {
346+
addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount));
347+
indexOfFirstStatement += parameterPropertyDeclarationCount;
348+
}
349+
}
332350
addInitializedPropertyStatements(statements, properties, createThis());
333351

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

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ namespace ts {
15661566
break;
15671567

15681568
default:
1569-
Debug.failBadSyntaxKind(node);
1569+
Debug.failBadSyntaxKind(member, currentSourceFile && currentSourceFile.fileName);
15701570
break;
15711571
}
15721572
}

0 commit comments

Comments
 (0)