MCPcopy Index your code
hub / github.com/nodejs/node / getJSSyntacticDiagnosticsForFile

Function getJSSyntacticDiagnosticsForFile

test/fixtures/snapshot/typescript.js:117706–117899  ·  view source on GitHub ↗
(sourceFile)

Source from the content-addressed store, hash-verified

117704 return -1;
117705 }
117706 function getJSSyntacticDiagnosticsForFile(sourceFile) {
117707 return runWithCancellationToken(function () {
117708 var diagnostics = [];
117709 walk(sourceFile, sourceFile);
117710 ts.forEachChildRecursively(sourceFile, walk, walkArray);
117711 return diagnostics;
117712 function walk(node, parent) {
117713 // Return directly from the case if the given node doesnt want to visit each child
117714 // Otherwise break to visit each child
117715 switch (parent.kind) {
117716 case 164 /* SyntaxKind.Parameter */:
117717 case 167 /* SyntaxKind.PropertyDeclaration */:
117718 case 169 /* SyntaxKind.MethodDeclaration */:
117719 if (parent.questionToken === node) {
117720 diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, "?"));
117721 return "skip";
117722 }
117723 // falls through
117724 case 168 /* SyntaxKind.MethodSignature */:
117725 case 171 /* SyntaxKind.Constructor */:
117726 case 172 /* SyntaxKind.GetAccessor */:
117727 case 173 /* SyntaxKind.SetAccessor */:
117728 case 213 /* SyntaxKind.FunctionExpression */:
117729 case 256 /* SyntaxKind.FunctionDeclaration */:
117730 case 214 /* SyntaxKind.ArrowFunction */:
117731 case 254 /* SyntaxKind.VariableDeclaration */:
117732 // type annotation
117733 if (parent.type === node) {
117734 diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Type_annotations_can_only_be_used_in_TypeScript_files));
117735 return "skip";
117736 }
117737 }
117738 switch (node.kind) {
117739 case 267 /* SyntaxKind.ImportClause */:
117740 if (node.isTypeOnly) {
117741 diagnostics.push(createDiagnosticForNode(parent, ts.Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, "import type"));
117742 return "skip";
117743 }
117744 break;
117745 case 272 /* SyntaxKind.ExportDeclaration */:
117746 if (node.isTypeOnly) {
117747 diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, "export type"));
117748 return "skip";
117749 }
117750 break;
117751 case 270 /* SyntaxKind.ImportSpecifier */:
117752 case 275 /* SyntaxKind.ExportSpecifier */:
117753 if (node.isTypeOnly) {
117754 diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, ts.isImportSpecifier(node) ? "import...type" : "export...type"));
117755 return "skip";
117756 }
117757 break;
117758 case 265 /* SyntaxKind.ImportEqualsDeclaration */:
117759 diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.import_can_only_be_used_in_TypeScript_files));
117760 return "skip";
117761 case 271 /* SyntaxKind.ExportAssignment */:
117762 if (node.isExportEquals) {
117763 diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.export_can_only_be_used_in_TypeScript_files));

Callers 1

Calls 2

runWithCancellationTokenFunction · 0.85
walkFunction · 0.70

Tested by

no test coverage detected