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 12, 2023
1 parent 62b648e commit d55788a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ast/nodes/LabeledStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ export default class LabeledStatement extends StatementBase {

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
const brokenFlow = context.brokenFlow;
this.body.include(context, includeChildrenRecursively);
if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
const { brokenFlow, includedLabels } = context;
const nestContext = { ...context, includedLabels: new Set<string>() };
this.body.include(nestContext, includeChildrenRecursively);
if (includeChildrenRecursively || nestContext.includedLabels.has(this.label.name)) {
this.label.include();
context.includedLabels.delete(this.label.name);
nestContext.includedLabels.delete(this.label.name);
context.brokenFlow = brokenFlow;
} else {
context.brokenFlow = nestContext.brokenFlow;
}
context.includedLabels = new Set([...includedLabels, ...nestContext.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 d55788a

Please sign in to comment.