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

Function checkNode

test/fixtures/snapshot/typescript.js:160311–160495  ·  view source on GitHub ↗
(nodeToCheck)

Source from the content-addressed store, hash-verified

160309 }
160310 // Verifies whether we can actually extract this node or not.
160311 function checkNode(nodeToCheck) {
160312 var PermittedJumps;
160313 (function (PermittedJumps) {
160314 PermittedJumps[PermittedJumps["None"] = 0] = "None";
160315 PermittedJumps[PermittedJumps["Break"] = 1] = "Break";
160316 PermittedJumps[PermittedJumps["Continue"] = 2] = "Continue";
160317 PermittedJumps[PermittedJumps["Return"] = 4] = "Return";
160318 })(PermittedJumps || (PermittedJumps = {}));
160319 // We believe it's true because the node is from the (unmodified) tree.
160320 ts.Debug.assert(nodeToCheck.pos <= nodeToCheck.end, "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809 (1)");
160321 // For understanding how skipTrivia functioned:
160322 ts.Debug.assert(!ts.positionIsSynthesized(nodeToCheck.pos), "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809 (2)");
160323 if (!ts.isStatement(nodeToCheck) && !(ts.isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck)) && !isStringLiteralJsxAttribute(nodeToCheck)) {
160324 return [ts.createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
160325 }
160326 if (nodeToCheck.flags & 16777216 /* NodeFlags.Ambient */) {
160327 return [ts.createDiagnosticForNode(nodeToCheck, Messages.cannotExtractAmbientBlock)];
160328 }
160329 // If we're in a class, see whether we're in a static region (static property initializer, static method, class constructor parameter default)
160330 var containingClass = ts.getContainingClass(nodeToCheck);
160331 if (containingClass) {
160332 checkForStaticContext(nodeToCheck, containingClass);
160333 }
160334 var errors;
160335 var permittedJumps = 4 /* PermittedJumps.Return */;
160336 var seenLabels;
160337 visit(nodeToCheck);
160338 if (rangeFacts & RangeFacts.UsesThis) {
160339 var container = ts.getThisContainer(nodeToCheck, /** includeArrowFunctions */ false);
160340 if (container.kind === 256 /* SyntaxKind.FunctionDeclaration */ ||
160341 (container.kind === 169 /* SyntaxKind.MethodDeclaration */ && container.parent.kind === 205 /* SyntaxKind.ObjectLiteralExpression */) ||
160342 container.kind === 213 /* SyntaxKind.FunctionExpression */) {
160343 rangeFacts |= RangeFacts.UsesThisInFunction;
160344 }
160345 }
160346 return errors;
160347 function visit(node) {
160348 if (errors) {
160349 // already found an error - can stop now
160350 return true;
160351 }
160352 if (ts.isDeclaration(node)) {
160353 var declaringNode = (node.kind === 254 /* SyntaxKind.VariableDeclaration */) ? node.parent.parent : node;
160354 if (ts.hasSyntacticModifier(declaringNode, 1 /* ModifierFlags.Export */)) {
160355 // TODO: GH#18217 Silly to use `errors ||` since it's definitely not defined (see top of `visit`)
160356 // Also, if we're only pushing one error, just use `let error: Diagnostic | undefined`!
160357 // Also TODO: GH#19956
160358 (errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.cannotExtractExportedEntity));
160359 return true;
160360 }
160361 declarations.push(node.symbol);
160362 }
160363 // Some things can't be extracted in certain situations
160364 switch (node.kind) {
160365 case 266 /* SyntaxKind.ImportDeclaration */:
160366 (errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.cannotExtractImport));
160367 return true;
160368 case 271 /* SyntaxKind.ExportAssignment */:

Callers 1

getRangeToExtractFunction · 0.85

Calls 5

isExtractableExpressionFunction · 0.85
checkForStaticContextFunction · 0.85
visitFunction · 0.85
assertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…