Skip to content

Commit 60e1ae0

Browse files
committed
PR Feedback
1 parent 80224d2 commit 60e1ae0

5 files changed

Lines changed: 106 additions & 105 deletions

File tree

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ namespace ts {
22732273

22742274
// If the parameter's name is 'this', then it is TypeScript syntax.
22752275
if (subtreeFlags & TransformFlags.ContainsDecorators
2276-
|| (node.name && isIdentifier(node.name) && (node.name as Identifier).originalKeywordKind === SyntaxKind.ThisKeyword)) {
2276+
|| (node.name && isIdentifier(node.name) && node.name.originalKeywordKind === SyntaxKind.ThisKeyword)) {
22772277
transformFlags |= TransformFlags.AssertTypeScript;
22782278
}
22792279

@@ -2430,7 +2430,7 @@ namespace ts {
24302430
let transformFlags = TransformFlags.None;
24312431

24322432
// A VariableDeclaration with a binding pattern is ES6 syntax.
2433-
if (isBindingPattern((<VariableDeclaration>node).name)) {
2433+
if (isBindingPattern(node.name)) {
24342434
transformFlags = TransformFlags.AssertES6 | TransformFlags.ContainsBindingPattern;
24352435
}
24362436

src/compiler/comments.ts

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ namespace ts {
55
export interface CommentWriter {
66
reset(): void;
77
setSourceFile(sourceFile: SourceFile): void;
8-
getLeadingComments(range: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): CommentRange[];
98
getLeadingComments(range: TextRange): CommentRange[];
9+
getLeadingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[];
1010
getLeadingCommentsOfPosition(pos: number): CommentRange[];
11-
getTrailingComments(range: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): CommentRange[];
1211
getTrailingComments(range: TextRange): CommentRange[];
12+
getTrailingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[];
1313
getTrailingCommentsOfPosition(pos: number): CommentRange[];
14-
emitLeadingComments(range: Node, comments: CommentRange[], getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): void;
1514
emitLeadingComments(range: TextRange, comments: CommentRange[]): void;
15+
emitLeadingComments(range: TextRange, comments: CommentRange[], contextNode: Node, getTextRangeCallback: (contextNode: Node) => TextRange): void;
1616
emitTrailingComments(range: TextRange, comments: CommentRange[]): void;
1717
emitLeadingDetachedComments(range: TextRange): void;
18-
emitLeadingDetachedComments(range: TextRange, contextNode: Node, shouldSkipCommentsForNodeCallback: (node: Node) => boolean): void;
18+
emitLeadingDetachedComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean): void;
1919
emitTrailingDetachedComments(range: TextRange): void;
20-
emitTrailingDetachedComments(range: TextRange, contextNode: Node, shouldSkipCommentsForNodeCallback: (node: Node) => boolean): void;
20+
emitTrailingDetachedComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean): void;
2121
}
2222

2323
export function createCommentWriter(host: EmitHost, writer: EmitTextWriter, sourceMap: SourceMapWriter): CommentWriter {
@@ -44,18 +44,18 @@ namespace ts {
4444
return {
4545
reset,
4646
setSourceFile,
47-
getLeadingComments(range: TextRange, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): CommentRange[] { return undefined; },
47+
getLeadingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange): CommentRange[] { return undefined; },
4848
getLeadingCommentsOfPosition(pos: number): CommentRange[] { return undefined; },
49-
getTrailingComments(range: TextRange, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): CommentRange[] { return undefined; },
49+
getTrailingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange): CommentRange[] { return undefined; },
5050
getTrailingCommentsOfPosition(pos: number): CommentRange[] { return undefined; },
51-
emitLeadingComments(range: Node | TextRange, comments: CommentRange[], getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): void { },
51+
emitLeadingComments(range: TextRange, comments: CommentRange[], contextNode?: Node, getTextRangeCallback?: (contextNode: Node) => TextRange): void { },
5252
emitTrailingComments(range: TextRange, comments: CommentRange[]): void { },
5353
emitLeadingDetachedComments,
54-
emitTrailingDetachedComments(node: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {}
54+
emitTrailingDetachedComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean): void {}
5555
};
5656

57-
function emitLeadingDetachedComments(node: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {
58-
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(contextNode)) {
57+
function emitLeadingDetachedComments(node: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean): void {
58+
if (ignoreNodeCallback && ignoreNodeCallback(contextNode)) {
5959
return;
6060
}
6161

@@ -79,33 +79,32 @@ namespace ts {
7979
};
8080

8181
function getLeadingComments(range: TextRange): CommentRange[];
82-
function getLeadingComments(node: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): CommentRange[];
83-
function getLeadingComments(nodeOrRange: TextRange | Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange) {
84-
let range = nodeOrRange;
85-
if (getCustomTextRangeForNodeCallback) {
86-
range = getCustomTextRangeForNodeCallback(<Node>nodeOrRange) || range;
87-
}
82+
function getLeadingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[];
83+
function getLeadingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange) {
84+
if (contextNode) {
85+
range = getTextRangeCallback(contextNode) || range;
86+
if (ignoreNodeCallback(contextNode)) {
87+
// If the node will not be emitted in JS, remove all the comments (normal,
88+
// pinned and `///`) associated with the node, unless it is a triple slash
89+
// comment at the top of the file.
90+
//
91+
// For Example:
92+
// /// <reference-path ...>
93+
// declare var x;
94+
// /// <reference-path ...>
95+
// interface F {}
96+
//
97+
// The first `///` will NOT be removed while the second one will be removed
98+
// even though both nodes will not be emitted.
99+
if (range.pos === 0) {
100+
return filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
101+
}
88102

89-
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(<Node>nodeOrRange)) {
90-
// If the node will not be emitted in JS, remove all the comments (normal,
91-
// pinned and `///`) associated with the node, unless it is a triple slash
92-
// comment at the top of the file.
93-
//
94-
// For Example:
95-
// /// <reference-path ...>
96-
// declare var x;
97-
// /// <reference-path ...>
98-
// interface F {}
99-
//
100-
// The first `///` will NOT be removed while the second one will be removed
101-
// even though both nodes will not be emitted.
102-
if (range.pos === 0) {
103-
return filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
103+
return undefined;
104104
}
105-
106-
return undefined;
107105
}
108106

107+
109108
return getLeadingCommentsOfPosition(range.pos);
110109
}
111110

@@ -126,15 +125,14 @@ namespace ts {
126125
}
127126

128127
function getTrailingComments(range: TextRange): CommentRange[];
129-
function getTrailingComments(node: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): CommentRange[];
130-
function getTrailingComments(nodeOrRange: TextRange | Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean, getCustomTextRangeForNodeCallback?: (node: Node) => TextRange) {
131-
let range = <TextRange>nodeOrRange;
132-
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(<Node>nodeOrRange)) {
133-
return undefined;
134-
}
128+
function getTrailingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[];
129+
function getTrailingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange) {
130+
if (contextNode) {
131+
if (ignoreNodeCallback(contextNode)) {
132+
return undefined;
133+
}
135134

136-
if (getCustomTextRangeForNodeCallback) {
137-
range = getCustomTextRangeForNodeCallback(<Node>nodeOrRange) || range;
135+
range = getTextRangeCallback(contextNode) || range;
138136
}
139137

140138
return getTrailingCommentsOfPosition(range.end);
@@ -162,13 +160,12 @@ namespace ts {
162160
return consumeCommentRanges(comments);
163161
}
164162

165-
function emitLeadingComments(range: Node, comments: CommentRange[], getCustomTextRangeForNodeCallback?: (node: Node) => TextRange): void;
166163
function emitLeadingComments(range: TextRange, comments: CommentRange[]): void;
167-
function emitLeadingComments(nodeOrRange: Node | TextRange, comments: CommentRange[], getCustomTextRangeForNodeCallback?: (node: Node) => TextRange) {
164+
function emitLeadingComments(range: TextRange, comments: CommentRange[], contextNode: Node, getTextRangeCallback: (contextNode: Node) => TextRange): void;
165+
function emitLeadingComments(range: TextRange, comments: CommentRange[], contextNode?: Node, getTextRangeCallback?: (contextNode: Node) => TextRange) {
168166
if (comments && comments.length > 0) {
169-
let range = <TextRange>nodeOrRange;
170-
if (getCustomTextRangeForNodeCallback) {
171-
range = getCustomTextRangeForNodeCallback(<Node>nodeOrRange);
167+
if (contextNode) {
168+
range = getTextRangeCallback(contextNode) || range;
172169
}
173170

174171
emitNewLineBeforeLeadingComments(currentLineMap, writer, range, comments);
@@ -183,16 +180,20 @@ namespace ts {
183180
emitComments(currentText, currentLineMap, writer, comments, /*leadingSeparator*/ true, /*trailingSeparator*/ false, newLine, writeComment);
184181
}
185182

186-
function emitLeadingDetachedComments(range: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {
187-
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(contextNode)) {
183+
function emitLeadingDetachedComments(range: TextRange): void;
184+
function emitLeadingDetachedComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (node: Node) => boolean): void;
185+
function emitLeadingDetachedComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (node: Node) => boolean): void {
186+
if (contextNode && ignoreNodeCallback(contextNode)) {
188187
return;
189188
}
190189

191190
emitDetachedCommentsAndUpdateCommentsInfo(range, /*removeComments*/ false);
192191
}
193192

194-
function emitTrailingDetachedComments(range: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {
195-
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(contextNode)) {
193+
function emitTrailingDetachedComments(range: TextRange): void;
194+
function emitTrailingDetachedComments(range: TextRange, contextNode: Node, ignoreNodeCallback?: (node: Node) => boolean): void;
195+
function emitTrailingDetachedComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (node: Node) => boolean): void {
196+
if (contextNode && ignoreNodeCallback(contextNode)) {
196197
return;
197198
}
198199

src/compiler/printer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ const _super = (function (geti, seti) {
344344

345345
function emitNodeWithWorker(node: Node, emitWorker: (node: Node) => void) {
346346
if (node) {
347-
const leadingComments = getLeadingComments(node, shouldSkipLeadingCommentsForNode, getCommentRange);
348-
const trailingComments = getTrailingComments(node, shouldSkipTrailingCommentsForNode, getCommentRange);
349-
emitLeadingComments(node, leadingComments, getCommentRange);
347+
const leadingComments = getLeadingComments(/*range*/ node, /*contextNode*/ node, shouldSkipLeadingCommentsForNode, getCommentRange);
348+
const trailingComments = getTrailingComments(/*range*/ node, /*contextNode*/ node, shouldSkipTrailingCommentsForNode, getCommentRange);
349+
emitLeadingComments(/*range*/ node, leadingComments, /*contextNode*/ node, getCommentRange);
350350
emitStart(/*range*/ node, /*contextNode*/ node, shouldSkipLeadingSourceMapForNode, shouldSkipSourceMapForChildren, getSourceMapRange);
351351
emitWorker(node);
352352
emitEnd(/*range*/ node, /*contextNode*/ node, shouldSkipTrailingSourceMapForNode, shouldSkipSourceMapForChildren, getSourceMapRange);
@@ -1996,7 +1996,7 @@ const _super = (function (geti, seti) {
19961996
// "comment1" is not considered to be leading comment for node.initializer
19971997
// but rather a trailing comment on the previous node.
19981998
if (!shouldSkipLeadingCommentsForNode(node.initializer)) {
1999-
emitLeadingComments(node.initializer, getTrailingComments(collapseRangeToStart(node.initializer)), getCommentRange);
1999+
emitLeadingComments(/*range*/ node.initializer, getTrailingComments(collapseRangeToStart(node.initializer)), /*contextNode*/ node.initializer, getCommentRange);
20002000
}
20012001
emitExpression(node.initializer);
20022002
}
@@ -2360,7 +2360,7 @@ const _super = (function (geti, seti) {
23602360
}
23612361

23622362
if (shouldEmitInterveningComments) {
2363-
emitLeadingComments(child, getTrailingCommentsOfPosition(child.pos), getCommentRange);
2363+
emitLeadingComments(/*node*/ child, getTrailingCommentsOfPosition(child.pos), /*contextNode*/ child, getCommentRange);
23642364
}
23652365
else {
23662366
shouldEmitInterveningComments = true;

0 commit comments

Comments
 (0)