(
this: Parser,
node: Undone<N.LabeledStatement>,
maybeName: string,
expr: N.Identifier,
flags: ParseStatementFlag,
)
| 1162 | |
| 1163 | // https://tc39.es/ecma262/#prod-LabelledStatement |
| 1164 | parseLabeledStatement( |
| 1165 | this: Parser, |
| 1166 | node: Undone<N.LabeledStatement>, |
| 1167 | maybeName: string, |
| 1168 | expr: N.Identifier, |
| 1169 | flags: ParseStatementFlag, |
| 1170 | ): N.LabeledStatement { |
| 1171 | for (const label of this.state.labels) { |
| 1172 | if (label.name === maybeName) { |
| 1173 | this.raise(Errors.LabelRedeclaration, expr, { |
| 1174 | labelName: maybeName, |
| 1175 | }); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | const kind = tokenIsLoop(this.state.type) |
| 1180 | ? LoopLabelKind.Loop |
| 1181 | : this.match(tt._switch) |
| 1182 | ? LoopLabelKind.Switch |
| 1183 | : null; |
| 1184 | for (let i = this.state.labels.length - 1; i >= 0; i--) { |
| 1185 | const label = this.state.labels[i]; |
| 1186 | if (label.statementStart === node.start) { |
| 1187 | label.statementStart = this.sourceToOffsetPos(this.state.start); |
| 1188 | label.kind = kind; |
| 1189 | } else { |
| 1190 | break; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | this.state.labels.push({ |
| 1195 | name: maybeName, |
| 1196 | kind: kind, |
| 1197 | statementStart: this.sourceToOffsetPos(this.state.start), |
| 1198 | }); |
| 1199 | // https://tc39.es/ecma262/#prod-LabelledItem |
| 1200 | node.body = |
| 1201 | flags & ParseStatementFlag.AllowLabeledFunction |
| 1202 | ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) |
| 1203 | : this.parseStatement(); |
| 1204 | |
| 1205 | this.state.labels.pop(); |
| 1206 | node.label = expr; |
| 1207 | return this.finishNode(node, "LabeledStatement"); |
| 1208 | } |
| 1209 | |
| 1210 | parseExpressionStatement( |
| 1211 | node: Undone<N.ExpressionStatement>, |
nothing calls this directly
no test coverage detected