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
This commit is contained in:
parent
b08fd0c18c
commit
81718769c4
|
@ -53,7 +53,7 @@ export function addExpressionIdentifier(node: ts.Node, identifier: ExpressionIde
|
||||||
/* hasTrailingNewLine */ false);
|
/* 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
|
* 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 {
|
export function markIgnoreDiagnostics(node: ts.Node): void {
|
||||||
ts.addSyntheticTrailingComment(
|
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. */
|
/** 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) => {
|
return ts.forEachTrailingCommentRange(sourceFile.text, node.getEnd(), (pos, end, kind) => {
|
||||||
if (kind !== ts.SyntaxKind.MultiLineCommentTrivia) {
|
if (kind !== ts.SyntaxKind.MultiLineCommentTrivia) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const commentText = sourceFile.text.substring(pos + 2, end - 2);
|
const commentText = sourceFile.text.substring(pos + 2, end - 2);
|
||||||
return commentText === IGNORE_MARKER;
|
return commentText === IGNORE_FOR_DIAGNOSTICS_MARKER;
|
||||||
}) === true;
|
}) === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import * as ts from 'typescript';
|
||||||
import {getTokenAtPosition} from '../../util/src/typescript';
|
import {getTokenAtPosition} from '../../util/src/typescript';
|
||||||
import {FullTemplateMapping, SourceLocation, TemplateId, TemplateSourceMapping} from '../api';
|
import {FullTemplateMapping, SourceLocation, TemplateId, TemplateSourceMapping} from '../api';
|
||||||
|
|
||||||
import {hasIgnoreMarker, readSpanComment} from './comments';
|
import {hasIgnoreForDiagnosticsMarker, readSpanComment} from './comments';
|
||||||
import {checkIfClassIsExported, checkIfGenericTypesAreUnbound} from './ts_util';
|
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 {
|
export function findSourceLocation(node: ts.Node, sourceFile: ts.SourceFile): SourceLocation|null {
|
||||||
// Search for comments until the TCB's function declaration is encountered.
|
// Search for comments until the TCB's function declaration is encountered.
|
||||||
while (node !== undefined && !ts.isFunctionDeclaration(node)) {
|
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.
|
// There's an ignore marker on this node, so the diagnostic should not be reported.
|
||||||
return null;
|
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 {
|
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.
|
// Walk up to the function declaration of the TCB, the file information is attached there.
|
||||||
while (!ts.isFunctionDeclaration(node)) {
|
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.
|
// There's an ignore marker on this node, so the diagnostic should not be reported.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue