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

Function transformAndEmitSwitchStatement

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

Source from the content-addressed store, hash-verified

103145 }
103146 }
103147 function transformAndEmitSwitchStatement(node) {
103148 if (containsYield(node.caseBlock)) {
103149 // [source]
103150 // switch (x) {
103151 // case a:
103152 // /*caseStatements*/
103153 // case b:
103154 // /*caseStatements*/
103155 // default:
103156 // /*defaultStatements*/
103157 // }
103158 //
103159 // [intermediate]
103160 // .local _a
103161 // .switch endLabel
103162 // _a = x;
103163 // switch (_a) {
103164 // case a:
103165 // .br clauseLabels[0]
103166 // }
103167 // switch (_a) {
103168 // case b:
103169 // .br clauseLabels[1]
103170 // }
103171 // .br clauseLabels[2]
103172 // .mark clauseLabels[0]
103173 // /*caseStatements*/
103174 // .mark clauseLabels[1]
103175 // /*caseStatements*/
103176 // .mark clauseLabels[2]
103177 // /*caseStatements*/
103178 // .endswitch
103179 // .mark endLabel
103180 var caseBlock = node.caseBlock;
103181 var numClauses = caseBlock.clauses.length;
103182 var endLabel = beginSwitchBlock();
103183 var expression = cacheExpression(ts.visitNode(node.expression, visitor, ts.isExpression));
103184 // Create labels for each clause and find the index of the first default clause.
103185 var clauseLabels = [];
103186 var defaultClauseIndex = -1;
103187 for (var i = 0; i < numClauses; i++) {
103188 var clause = caseBlock.clauses[i];
103189 clauseLabels.push(defineLabel());
103190 if (clause.kind === 290 /* SyntaxKind.DefaultClause */ && defaultClauseIndex === -1) {
103191 defaultClauseIndex = i;
103192 }
103193 }
103194 // Emit switch statements for each run of case clauses either from the first case
103195 // clause or the next case clause with a `yield` in its expression, up to the next
103196 // case clause with a `yield` in its expression.
103197 var clausesWritten = 0;
103198 var pendingClauses = [];
103199 while (clausesWritten < numClauses) {
103200 var defaultClausesSkipped = 0;
103201 for (var i = clausesWritten; i < numClauses; i++) {
103202 var clause = caseBlock.clauses[i];
103203 if (clause.kind === 289 /* SyntaxKind.CaseClause */) {
103204 if (containsYield(clause.expression) && pendingClauses.length > 0) {

Callers 1

Calls 11

beginSwitchBlockFunction · 0.85
cacheExpressionFunction · 0.85
defineLabelFunction · 0.85
createInlineBreakFunction · 0.85
emitStatementFunction · 0.85
emitBreakFunction · 0.85
markLabelFunction · 0.85
endSwitchBlockFunction · 0.85
containsYieldFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…