Skip to content

Commit

Permalink
refactor(compiler-cli): rename ignore marker and helpers to be more c…
Browse files Browse the repository at this point in the history
…lear (angular#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 angular#40071
  • Loading branch information
atscott authored and alxhub committed Dec 11, 2020
1 parent b08fd0c commit 8171876
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/compiler-cli/src/ngtsc/typecheck/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,26 @@ 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
* should be ignored.
*/
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;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-cli/src/ngtsc/typecheck/src/tcb_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 8171876

Please sign in to comment.