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

Function checkForOfStatement

test/fixtures/snapshot/typescript.js:82841–82894  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

82839 }
82840 }
82841 function checkForOfStatement(node) {
82842 checkGrammarForInOrForOfStatement(node);
82843 var container = ts.getContainingFunctionOrClassStaticBlock(node);
82844 if (node.awaitModifier) {
82845 if (container && ts.isClassStaticBlockDeclaration(container)) {
82846 grammarErrorOnNode(node.awaitModifier, ts.Diagnostics.For_await_loops_cannot_be_used_inside_a_class_static_block);
82847 }
82848 else {
82849 var functionFlags = ts.getFunctionFlags(container);
82850 if ((functionFlags & (4 /* FunctionFlags.Invalid */ | 2 /* FunctionFlags.Async */)) === 2 /* FunctionFlags.Async */ && languageVersion < 99 /* ScriptTarget.ESNext */) {
82851 // for..await..of in an async function or async generator function prior to ESNext requires the __asyncValues helper
82852 checkExternalEmitHelpers(node, 16384 /* ExternalEmitHelpers.ForAwaitOfIncludes */);
82853 }
82854 }
82855 }
82856 else if (compilerOptions.downlevelIteration && languageVersion < 2 /* ScriptTarget.ES2015 */) {
82857 // for..of prior to ES2015 requires the __values helper when downlevelIteration is enabled
82858 checkExternalEmitHelpers(node, 256 /* ExternalEmitHelpers.ForOfIncludes */);
82859 }
82860 // Check the LHS and RHS
82861 // If the LHS is a declaration, just check it as a variable declaration, which will in turn check the RHS
82862 // via checkRightHandSideOfForOf.
82863 // If the LHS is an expression, check the LHS, as a destructuring assignment or as a reference.
82864 // Then check that the RHS is assignable to it.
82865 if (node.initializer.kind === 255 /* SyntaxKind.VariableDeclarationList */) {
82866 checkForInOrForOfVariableDeclaration(node);
82867 }
82868 else {
82869 var varExpr = node.initializer;
82870 var iteratedType = checkRightHandSideOfForOf(node);
82871 // There may be a destructuring assignment on the left side
82872 if (varExpr.kind === 204 /* SyntaxKind.ArrayLiteralExpression */ || varExpr.kind === 205 /* SyntaxKind.ObjectLiteralExpression */) {
82873 // iteratedType may be undefined. In this case, we still want to check the structure of
82874 // varExpr, in particular making sure it's a valid LeftHandSideExpression. But we'd like
82875 // to short circuit the type relation checking as much as possible, so we pass the unknownType.
82876 checkDestructuringAssignment(varExpr, iteratedType || errorType);
82877 }
82878 else {
82879 var leftType = checkExpression(varExpr);
82880 checkReferenceExpression(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_must_be_a_variable_or_a_property_access, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access);
82881 // iteratedType will be undefined if the rightType was missing properties/signatures
82882 // required to get its iteratedType (like [Symbol.iterator] or next). This may be
82883 // because we accessed properties from anyType, or it may have led to an error inside
82884 // getElementTypeOfIterable.
82885 if (iteratedType) {
82886 checkTypeAssignableToAndOptionallyElaborate(iteratedType, leftType, varExpr, node.expression);
82887 }
82888 }
82889 }
82890 checkSourceElement(node.statement);
82891 if (node.locals) {
82892 registerForUnusedIdentifiersCheck(node);
82893 }
82894 }
82895 function checkForInStatement(node) {
82896 // Grammar checking
82897 checkGrammarForInOrForOfStatement(node);

Callers 1

checkSourceElementWorkerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…