diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 989935a5edb..7dfda66c965 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -72,11 +72,13 @@ namespace ts { const savedContainerEnd = containerEnd; const savedDeclarationListContainerEnd = declarationListContainerEnd; - if (!skipLeadingComments) { + if (!skipLeadingComments || (pos >= 0 && (emitFlags & EmitFlags.NoLeadingComments) !== 0)) { + // Advance the container position of comments get emitted or if they've been disabled explicitly using NoLeadingComments. containerPos = pos; } - if (!skipTrailingComments) { + if (!skipTrailingComments || (end >= 0 && (emitFlags & EmitFlags.NoTrailingComments) !== 0)) { + // As above. containerEnd = end; // To avoid invalid comment emit in a down-level binding pattern, we @@ -426,4 +428,4 @@ namespace ts { return isRecognizedTripleSlashComment(currentText, commentPos, commentEnd); } } -} \ No newline at end of file +} diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 619cc505c8b..39a659486b5 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1121,7 +1121,7 @@ namespace ts { } // Perform the capture. - captureThisForNode(statements, ctor, superCallExpression || createActualThis(), firstStatement); + captureThisForNode(statements, ctor, superCallExpression || createActualThis()); // If we're actually replacing the original statement, we need to signal this to the caller. if (superCallExpression) { @@ -1443,7 +1443,7 @@ namespace ts { } } - function captureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined, originalStatement?: Statement): void { + function captureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined): void { enableSubstitutionsForCapturedThis(); const captureThisStatement = createVariableStatement( /*modifiers*/ undefined, @@ -1456,7 +1456,6 @@ namespace ts { ]) ); setEmitFlags(captureThisStatement, EmitFlags.NoComments | EmitFlags.CustomPrologue); - setTextRange(captureThisStatement, originalStatement); setSourceMapRange(captureThisStatement, node); statements.push(captureThisStatement); }