Skip to content

Commit

Permalink
fix: use a new includedLabels in the body of the LabeledStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
TrickyPi committed Dec 13, 2023
1 parent 62b648e commit 1c97b0a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ast/nodes/LabeledStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ export default class LabeledStatement extends StatementBase {

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
const brokenFlow = context.brokenFlow;
const { brokenFlow, includedLabels } = context;
context.includedLabels = new Set<string>();
this.body.include(context, includeChildrenRecursively);
// eslint-disable-next-line unicorn/consistent-destructuring
if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
this.label.include();
// eslint-disable-next-line unicorn/consistent-destructuring
context.includedLabels.delete(this.label.name);
context.brokenFlow = brokenFlow;
}
// eslint-disable-next-line unicorn/consistent-destructuring
context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
}

render(code: MagicString, options: RenderOptions): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ outer: {
console.log('retained');
}

outer: {
switch (globalThis.unknown) {
case 1:
(() => {
console.log('retained');
})();
case 2:
break outer;
}
}

function withConsequentReturn() {
{
inner: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ outer: {
console.log('retained');
}

outer: {
switch (globalThis.unknown) {
case 1:
(() => {
outer: console.log('retained');
})();
case 2:
break outer;
}
}

function withConsequentReturn() {
outer: {
inner: {
Expand Down

0 comments on commit 1c97b0a

Please sign in to comment.