Skip to content

Commit 02d2178

Browse files
committed
PR Feedback
1 parent 15780a9 commit 02d2178

6 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/compiler/comments.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,22 @@ namespace ts {
6868
emitDetachedComments,
6969
};
7070

71+
function getLeadingComments(range: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): CommentRange[];
72+
function getLeadingComments(range: TextRange): CommentRange[];
7173
function getLeadingComments(range: TextRange | Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean) {
7274
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(<Node>range)) {
73-
// If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node,
74-
// unless it is a triple slash comment at the top of the file.
75+
// If the node will not be emitted in JS, remove all the comments (normal,
76+
// pinned and `///`) associated with the node, unless it is a triple slash
77+
// comment at the top of the file.
78+
//
7579
// For Example:
7680
// /// <reference-path ...>
7781
// declare var x;
7882
// /// <reference-path ...>
7983
// interface F {}
80-
// The first /// will NOT be removed while the second one will be removed even though both nodes will not be emitted
84+
//
85+
// The first `///` will NOT be removed while the second one will be removed
86+
// even though both nodes will not be emitted.
8187
if (range.pos === 0) {
8288
return filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
8389
}
@@ -104,6 +110,8 @@ namespace ts {
104110
return false;
105111
}
106112

113+
function getTrailingComments(range: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): CommentRange[];
114+
function getTrailingComments(range: TextRange): CommentRange[];
107115
function getTrailingComments(range: TextRange | Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean) {
108116
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(<Node>range)) {
109117
return undefined;

src/compiler/transformers/es6.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ namespace ts {
183183

184184
function transformSourceFile(node: SourceFile) {
185185
currentSourceFile = node;
186-
enclosingBlockScopeContainer = node;
187-
currentNode = node;
188-
return visitEachChild(node, visitor, context);
186+
return visitNode(node, visitor, isSourceFile);
189187
}
190188

191189
function visitor(node: Node): VisitResult<Node> {

src/compiler/transformers/ts.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ namespace ts {
208208
*/
209209
function visitTypeScript(node: Node): VisitResult<Node> {
210210
if (hasModifier(node, ModifierFlags.Ambient)) {
211-
// TypeScript ambient declarations are elided.
211+
// TypeScript ambient declarations are elided, but some comments may be preserved.
212+
// See the implementation of `getLeadingComments` in comments.ts for more details.
212213
return isStatement(node)
213214
? createNotEmittedStatement(node)
214215
: undefined;
@@ -268,7 +269,8 @@ namespace ts {
268269
return undefined;
269270

270271
case SyntaxKind.InterfaceDeclaration:
271-
// TypeScript interfaces are elided, but pinned comments are preserved.
272+
// TypeScript interfaces are elided, but some comments may be preserved.
273+
// See the implementation of `getLeadingComments` in comments.ts for more details.
272274
return createNotEmittedStatement(node);
273275

274276
case SyntaxKind.ClassDeclaration:

src/compiler/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,6 @@ namespace ts {
727727
_indexSignatureDeclarationBrand: any;
728728
}
729729

730-
// Represents a member of a class element or object literal that is elided as part of a
731-
// transformation to emit comments on a not-emitted node.
732-
// @internal
733-
// @kind(SyntaxKind.NotEmittedMember)
734-
export interface NotEmittedMember extends ClassElement, ObjectLiteralElement {
735-
}
736-
737730
// @kind(SyntaxKind.AnyKeyword)
738731
// @kind(SyntaxKind.NumberKeyword)
739732
// @kind(SyntaxKind.BooleanKeyword)

src/compiler/utilities.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,12 +3344,11 @@ namespace ts {
33443344
return node.kind === SyntaxKind.PartiallyEmittedExpression;
33453345
}
33463346

3347-
export function isNotEmittedStatement(node: Node): node is NotEmittedMember | NotEmittedStatement {
3347+
export function isNotEmittedStatement(node: Node): node is NotEmittedStatement {
33483348
return node.kind === SyntaxKind.NotEmittedStatement;
33493349
}
33503350

3351-
export function isNotEmittedOrPartiallyEmittedNode(node: Node): node is NotEmittedMember | NotEmittedStatement | PartiallyEmittedExpression {
3352-
const kind = node.kind;
3351+
export function isNotEmittedOrPartiallyEmittedNode(node: Node): node is NotEmittedStatement | PartiallyEmittedExpression {
33533352
return isNotEmittedStatement(node)
33543353
|| isPartiallyEmittedExpression(node);
33553354
}
@@ -3589,6 +3588,11 @@ namespace ts {
35893588
export function isEnumMember(node: Node): node is EnumMember {
35903589
return node.kind === SyntaxKind.EnumMember;
35913590
}
3591+
3592+
// Top-level nodes
3593+
export function isSourceFile(node: Node): node is SourceFile {
3594+
return node.kind === SyntaxKind.SourceFile;
3595+
}
35923596
}
35933597

35943598
namespace ts {

src/harness/fourslash.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,8 @@ namespace FourSlash {
22452245

22462246
const diagnostics = ts.getPreEmitDiagnostics(program, sourceFile);
22472247
if (diagnostics.length > 0) {
2248-
throw new Error(`Error compiling ${fileName}: ${diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, Harness.IO.newLine())).join("\r\n")}`);
2248+
const diagnosticText = diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, Harness.IO.newLine())).join("\r\n");
2249+
throw new Error(`Error compiling ${fileName}: ${diagnosticText}`);
22492250
}
22502251

22512252
program.emit(sourceFile);

0 commit comments

Comments
 (0)