(
this: Parser,
body: N.Statement[],
directives: N.Directive[] | undefined | null,
topLevel: boolean,
end: TokenType,
afterBlockParse?: (hasStrictModeDirective: boolean) => void,
)
| 1284 | // https://tc39.es/ecma262/#prod-Block |
| 1285 | // https://tc39.es/ecma262/#prod-ModuleBody |
| 1286 | parseBlockOrModuleBlockBody( |
| 1287 | this: Parser, |
| 1288 | body: N.Statement[], |
| 1289 | directives: N.Directive[] | undefined | null, |
| 1290 | topLevel: boolean, |
| 1291 | end: TokenType, |
| 1292 | afterBlockParse?: (hasStrictModeDirective: boolean) => void, |
| 1293 | ): void { |
| 1294 | const oldStrict = this.state.strict; |
| 1295 | let hasStrictModeDirective = false; |
| 1296 | let parsedNonDirective = false; |
| 1297 | |
| 1298 | while (!this.match(end)) { |
| 1299 | const stmt = topLevel |
| 1300 | ? this.parseModuleItem() |
| 1301 | : this.parseStatementListItem(); |
| 1302 | |
| 1303 | if (directives && !parsedNonDirective) { |
| 1304 | if (this.isValidDirective(stmt)) { |
| 1305 | const directive = this.stmtToDirective(stmt); |
| 1306 | directives.push(directive); |
| 1307 | |
| 1308 | if ( |
| 1309 | !hasStrictModeDirective && |
| 1310 | directive.value.value === "use strict" |
| 1311 | ) { |
| 1312 | hasStrictModeDirective = true; |
| 1313 | this.setStrict(true); |
| 1314 | } |
| 1315 | |
| 1316 | continue; |
| 1317 | } |
| 1318 | parsedNonDirective = true; |
| 1319 | // clear strict errors since the strict mode will not change within the block |
| 1320 | this.state.strictErrors.clear(); |
| 1321 | } |
| 1322 | body.push(stmt); |
| 1323 | } |
| 1324 | |
| 1325 | afterBlockParse?.call(this, hasStrictModeDirective); |
| 1326 | |
| 1327 | if (!oldStrict) { |
| 1328 | this.setStrict(false); |
| 1329 | } |
| 1330 | |
| 1331 | this.next(); |
| 1332 | } |
| 1333 | |
| 1334 | // Parse a regular `for` loop. The disambiguation code in |
| 1335 | // `parseStatement` will already have parsed the init statement or |
nothing calls this directly
no test coverage detected