From 005b8583f5c744d7e8797d1072245e608196df2f Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Fri, 17 Jul 2015 10:33:07 -0700 Subject: [PATCH 1/4] remove for-loops --- src/compiler/emitter.ts | 10 ++++++++++ src/services/services.ts | 28 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9c8438565e7..6073c0c9421 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6764,6 +6764,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } + /** + * Removes all but the pinned or triple slash comments. + * @param ranges The array to be filtered + * @param onlyPinnedOrTripleSlashComments whether the filtering should be performed. + * + * This probably shouldn't be a parameter at all. It appears that in every call, the argument is + * precisely 'compilerOptions.removeComments'. + * + * How to fix this? + */ function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { // If we're removing comments, then we want to strip out all but the pinned or // triple slash comments. diff --git a/src/services/services.ts b/src/services/services.ts index c2432816f24..71dc03f35ce 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -260,26 +260,30 @@ namespace ts { } public getFirstToken(sourceFile?: SourceFile): Node { - let children = this.getChildren(); - for (let child of children) { - if (child.kind < SyntaxKind.FirstNode) { - return child; - } + let children = this.getChildren(); // why isn't sourceFile passed as an argument?? + if (!(children && children.length > 0)) { return undefined; } - return child.getFirstToken(sourceFile); + let child = children[0]; + + if (child.kind < SyntaxKind.FirstNode) { + return child; } + + return child.getFirstToken(sourceFile); } public getLastToken(sourceFile?: SourceFile): Node { let children = this.getChildren(sourceFile); - for (let i = children.length - 1; i >= 0; i--) { - let child = children[i]; - if (child.kind < SyntaxKind.FirstNode) { - return child; - } + if (!children) { return undefined; } - return child.getLastToken(sourceFile); + let child = lastOrUndefined(children); + if (!child) { return undefined; } + + if (child.kind < SyntaxKind.FirstNode) { + return child; } + + return child.getLastToken(sourceFile); } } From 4e8203d2953b6ffe44adecb480aeff4e0d9ef9a4 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Fri, 17 Jul 2015 10:48:54 -0700 Subject: [PATCH 2/4] fixed a comment --- src/compiler/emitter.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6073c0c9421..bb94bea1491 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6768,11 +6768,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * Removes all but the pinned or triple slash comments. * @param ranges The array to be filtered * @param onlyPinnedOrTripleSlashComments whether the filtering should be performed. - * - * This probably shouldn't be a parameter at all. It appears that in every call, the argument is - * precisely 'compilerOptions.removeComments'. - * - * How to fix this? */ function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { // If we're removing comments, then we want to strip out all but the pinned or From 1ca17aba260367bb56a0b1bc65ddd1ca5bef9265 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Fri, 17 Jul 2015 11:20:51 -0700 Subject: [PATCH 3/4] Addressed Daniel's Comments --- src/services/services.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 71dc03f35ce..0efab7ca149 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -260,30 +260,25 @@ namespace ts { } public getFirstToken(sourceFile?: SourceFile): Node { - let children = this.getChildren(); // why isn't sourceFile passed as an argument?? - if (!(children && children.length > 0)) { return undefined; } + let children = this.getChildren(sourceFile); + if (!(children.length > 0)) { + return undefined; + } let child = children[0]; - if (child.kind < SyntaxKind.FirstNode) { - return child; - } - - return child.getFirstToken(sourceFile); + return child.kind < SyntaxKind.FirstNode ? child : child.getFirstToken(sourceFile); } public getLastToken(sourceFile?: SourceFile): Node { let children = this.getChildren(sourceFile); - if (!children) { return undefined; } let child = lastOrUndefined(children); - if (!child) { return undefined; } - - if (child.kind < SyntaxKind.FirstNode) { - return child; + if (!child) { + return undefined; } - return child.getLastToken(sourceFile); + return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); } } From 7c024aba56621c1a578126f7d01265a6ef1cdf0b Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 27 Jul 2015 13:19:14 -0700 Subject: [PATCH 4/4] cleanup --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 4645aeb3103..8e670268498 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -262,7 +262,7 @@ namespace ts { public getFirstToken(sourceFile?: SourceFile): Node { let children = this.getChildren(sourceFile); - if (!(children.length > 0)) { + if (!children.length) { return undefined; }