From 81718769c46376a75bb7e80ff1c7b16c5de8c6b8 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Thu, 10 Dec 2020 11:14:44 -0800 Subject: [PATCH] refactor(compiler-cli): rename ignore marker and helpers to be more clear (#40071) The ignore marker is only used to ignore certain nodes in the TCB for the purposes of diagnostics. The marker itself has been renamed as well as the helper function to see if the marker is present. Both now indicate that the marker is specifically for diagnostics. PR Close #40071 --- .../compiler-cli/src/ngtsc/typecheck/src/comments.ts | 9 +++++---- .../compiler-cli/src/ngtsc/typecheck/src/tcb_util.ts | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/comments.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/comments.ts index 10b6c59dda..7007b1a33c 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/comments.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/comments.ts @@ -53,7 +53,7 @@ export function addExpressionIdentifier(node: ts.Node, identifier: ExpressionIde /* hasTrailingNewLine */ false); } -const IGNORE_MARKER = `${CommentTriviaType.DIAGNOSTIC}:ignore`; +const IGNORE_FOR_DIAGNOSTICS_MARKER = `${CommentTriviaType.DIAGNOSTIC}:ignore`; /** * Tag the `ts.Node` with an indication that any errors arising from the evaluation of the node @@ -61,17 +61,18 @@ const IGNORE_MARKER = `${CommentTriviaType.DIAGNOSTIC}:ignore`; */ export function markIgnoreDiagnostics(node: ts.Node): void { ts.addSyntheticTrailingComment( - node, ts.SyntaxKind.MultiLineCommentTrivia, IGNORE_MARKER, /* hasTrailingNewLine */ false); + node, ts.SyntaxKind.MultiLineCommentTrivia, IGNORE_FOR_DIAGNOSTICS_MARKER, + /* hasTrailingNewLine */ false); } /** Returns true if the node has a marker that indicates diagnostics errors should be ignored. */ -export function hasIgnoreMarker(node: ts.Node, sourceFile: ts.SourceFile): boolean { +export function hasIgnoreForDiagnosticsMarker(node: ts.Node, sourceFile: ts.SourceFile): boolean { return ts.forEachTrailingCommentRange(sourceFile.text, node.getEnd(), (pos, end, kind) => { if (kind !== ts.SyntaxKind.MultiLineCommentTrivia) { return null; } const commentText = sourceFile.text.substring(pos + 2, end - 2); - return commentText === IGNORE_MARKER; + return commentText === IGNORE_FOR_DIAGNOSTICS_MARKER; }) === true; } diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/tcb_util.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/tcb_util.ts index b7d56a00a5..7bdc189dcb 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/tcb_util.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/tcb_util.ts @@ -13,7 +13,7 @@ import * as ts from 'typescript'; import {getTokenAtPosition} from '../../util/src/typescript'; import {FullTemplateMapping, SourceLocation, TemplateId, TemplateSourceMapping} from '../api'; -import {hasIgnoreMarker, readSpanComment} from './comments'; +import {hasIgnoreForDiagnosticsMarker, readSpanComment} from './comments'; import {checkIfClassIsExported, checkIfGenericTypesAreUnbound} from './ts_util'; /** @@ -89,7 +89,7 @@ export function findTypeCheckBlock(file: ts.SourceFile, id: TemplateId): ts.Node export function findSourceLocation(node: ts.Node, sourceFile: ts.SourceFile): SourceLocation|null { // Search for comments until the TCB's function declaration is encountered. while (node !== undefined && !ts.isFunctionDeclaration(node)) { - if (hasIgnoreMarker(node, sourceFile)) { + if (hasIgnoreForDiagnosticsMarker(node, sourceFile)) { // There's an ignore marker on this node, so the diagnostic should not be reported. return null; } @@ -114,7 +114,7 @@ export function findSourceLocation(node: ts.Node, sourceFile: ts.SourceFile): So function getTemplateId(node: ts.Node, sourceFile: ts.SourceFile): TemplateId|null { // Walk up to the function declaration of the TCB, the file information is attached there. while (!ts.isFunctionDeclaration(node)) { - if (hasIgnoreMarker(node, sourceFile)) { + if (hasIgnoreForDiagnosticsMarker(node, sourceFile)) { // There's an ignore marker on this node, so the diagnostic should not be reported. return null; }