MCPcopy Create free account
hub / github.com/nodejs/node / checkGrammarBreakOrContinueStatement

Function checkGrammarBreakOrContinueStatement

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

Source from the content-addressed store, hash-verified

88673 }
88674 }
88675 function checkGrammarBreakOrContinueStatement(node) {
88676 var current = node;
88677 while (current) {
88678 if (ts.isFunctionLikeOrClassStaticBlockDeclaration(current)) {
88679 return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
88680 }
88681 switch (current.kind) {
88682 case 250 /* SyntaxKind.LabeledStatement */:
88683 if (node.label && current.label.escapedText === node.label.escapedText) {
88684 // found matching label - verify that label usage is correct
88685 // continue can only target labels that are on iteration statements
88686 var isMisplacedContinueLabel = node.kind === 245 /* SyntaxKind.ContinueStatement */
88687 && !ts.isIterationStatement(current.statement, /*lookInLabeledStatement*/ true);
88688 if (isMisplacedContinueLabel) {
88689 return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
88690 }
88691 return false;
88692 }
88693 break;
88694 case 249 /* SyntaxKind.SwitchStatement */:
88695 if (node.kind === 246 /* SyntaxKind.BreakStatement */ && !node.label) {
88696 // unlabeled break within switch statement - ok
88697 return false;
88698 }
88699 break;
88700 default:
88701 if (ts.isIterationStatement(current, /*lookInLabeledStatement*/ false) && !node.label) {
88702 // unlabeled break or continue within iteration statement - ok
88703 return false;
88704 }
88705 break;
88706 }
88707 current = current.parent;
88708 }
88709 if (node.label) {
88710 var message = node.kind === 246 /* SyntaxKind.BreakStatement */
88711 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement
88712 : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
88713 return grammarErrorOnNode(node, message);
88714 }
88715 else {
88716 var message = node.kind === 246 /* SyntaxKind.BreakStatement */
88717 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement
88718 : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
88719 return grammarErrorOnNode(node, message);
88720 }
88721 }
88722 function checkGrammarBindingElement(node) {
88723 if (node.dotDotDotToken) {
88724 var elements = node.parent.elements;

Callers 1

Calls 1

grammarErrorOnNodeFunction · 0.85

Tested by

no test coverage detected