Skip to content

Commit 0c6efc1

Browse files
committed
fix: uses a fresh Set of included labels when checking effects of children
1 parent 4319406 commit 0c6efc1

6 files changed

Lines changed: 35 additions & 23 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ module.exports = {
140140
}
141141
],
142142
'sort-keys': ['error', 'asc', { caseSensitive: false }],
143+
'unicorn/consistent-destructuring': 'off',
143144
'unicorn/filename-case': 'off',
144145
'unicorn/no-array-callback-reference': 'off',
145146
'unicorn/no-array-reduce': 'off',

src/Chunk.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,16 +1021,16 @@ export default class Chunk {
10211021
facadeChunk: this.facadeChunkByModule.get(resolution),
10221022
node,
10231023
resolution
1024-
}
1024+
}
10251025
: resolution instanceof ExternalModule
1026-
? {
1026+
? {
10271027
chunk: null,
10281028
externalChunk: this.externalChunkByModule.get(resolution)!,
10291029
facadeChunk: null,
10301030
node,
10311031
resolution
1032-
}
1033-
: { chunk: null, externalChunk: null, facadeChunk: null, node, resolution }
1032+
}
1033+
: { chunk: null, externalChunk: null, facadeChunk: null, node, resolution }
10341034
);
10351035
}
10361036
}
@@ -1233,7 +1233,6 @@ export default class Chunk {
12331233
!renderOptions.accessedDocumentCurrentScript &&
12341234
formatsMaybeAccessDocumentCurrentScript.includes(format)
12351235
) {
1236-
// eslint-disable-next-line unicorn/consistent-destructuring
12371236
this.accessedGlobalsByScope.get(module.scope)?.delete(DOCUMENT_CURRENT_SCRIPT);
12381237
}
12391238
renderOptions.accessedDocumentCurrentScript = false;
@@ -1273,7 +1272,6 @@ export default class Chunk {
12731272

12741273
if (hoistedSource) magicString.prepend(hoistedSource + n + n);
12751274

1276-
// eslint-disable-next-line unicorn/consistent-destructuring
12771275
if (this.needsExportsShim) {
12781276
magicString.prepend(`${n}${cnst} ${MISSING_EXPORT_SHIM_VARIABLE}${_}=${_}void 0;${n}${n}`);
12791277
}

src/ast/nodes/IfStatement.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ export default class IfStatement extends StatementBase implements DeoptimizableE
4040
if (typeof testValue === 'symbol') {
4141
const { brokenFlow } = context;
4242
if (this.consequent.hasEffects(context)) return true;
43-
// eslint-disable-next-line unicorn/consistent-destructuring
4443
const consequentBrokenFlow = context.brokenFlow;
4544
context.brokenFlow = brokenFlow;
4645
if (this.alternate === null) return false;
4746
if (this.alternate.hasEffects(context)) return true;
48-
// eslint-disable-next-line unicorn/consistent-destructuring
4947
context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
5048
return false;
5149
}
@@ -166,13 +164,11 @@ export default class IfStatement extends StatementBase implements DeoptimizableE
166164
let consequentBrokenFlow = false;
167165
if (this.consequent.shouldBeIncluded(context)) {
168166
this.consequent.include(context, false, { asSingleStatement: true });
169-
// eslint-disable-next-line unicorn/consistent-destructuring
170167
consequentBrokenFlow = context.brokenFlow;
171168
context.brokenFlow = brokenFlow;
172169
}
173170
if (this.alternate?.shouldBeIncluded(context)) {
174171
this.alternate.include(context, false, { asSingleStatement: true });
175-
// eslint-disable-next-line unicorn/consistent-destructuring
176172
context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
177173
}
178174
}

src/ast/nodes/LabeledStatement.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,33 @@ export default class LabeledStatement extends StatementBase {
1515
declare type: NodeType.tLabeledStatement;
1616

1717
hasEffects(context: HasEffectsContext): boolean {
18-
const brokenFlow = context.brokenFlow;
18+
const { brokenFlow, includedLabels } = context;
1919
context.ignore.labels.add(this.label.name);
20-
if (this.body.hasEffects(context)) return true;
21-
context.ignore.labels.delete(this.label.name);
22-
if (context.includedLabels.has(this.label.name)) {
23-
context.includedLabels.delete(this.label.name);
24-
context.brokenFlow = brokenFlow;
20+
context.includedLabels = new Set<string>();
21+
let bodyHasEffects = false;
22+
if (this.body.hasEffects(context)) {
23+
bodyHasEffects = true;
24+
} else {
25+
context.ignore.labels.delete(this.label.name);
26+
if (context.includedLabels.has(this.label.name)) {
27+
context.includedLabels.delete(this.label.name);
28+
context.brokenFlow = brokenFlow;
29+
}
2530
}
26-
return false;
31+
context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
32+
return bodyHasEffects;
2733
}
2834

2935
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
3036
this.included = true;
3137
const { brokenFlow, includedLabels } = context;
3238
context.includedLabels = new Set<string>();
3339
this.body.include(context, includeChildrenRecursively);
34-
// eslint-disable-next-line unicorn/consistent-destructuring
3540
if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
3641
this.label.include();
37-
// eslint-disable-next-line unicorn/consistent-destructuring
3842
context.includedLabels.delete(this.label.name);
3943
context.brokenFlow = brokenFlow;
4044
}
41-
// eslint-disable-next-line unicorn/consistent-destructuring
4245
context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
4346
}
4447

src/ast/nodes/SwitchStatement.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export default class SwitchStatement extends StatementBase {
3434
let onlyHasBrokenFlow = true;
3535
for (const switchCase of this.cases) {
3636
if (switchCase.hasEffects(context)) return true;
37-
// eslint-disable-next-line unicorn/consistent-destructuring
3837
onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
3938
context.hasBreak = false;
4039
context.brokenFlow = brokenFlow;
@@ -68,7 +67,6 @@ export default class SwitchStatement extends StatementBase {
6867
}
6968
if (isCaseIncluded) {
7069
switchCase.include(context, includeChildrenRecursively);
71-
// eslint-disable-next-line unicorn/consistent-destructuring
7270
onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
7371
context.hasBreak = false;
7472
context.brokenFlow = brokenFlow;

test/form/samples/break-control-flow/break-statement-labels/main.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ outer: {
2020
}
2121

2222
outer: {
23-
inner:/* retained comment */ {
23+
inner: /* retained comment */ {
2424
console.log('retained');
2525
break outer;
2626
console.log('removed');
@@ -59,6 +59,22 @@ outer: {
5959
}
6060
}
6161

62+
// removed
63+
outer: {
64+
if (globalThis.unknown) {
65+
break outer;
66+
} else {
67+
(() => {
68+
inner: {
69+
outer: {
70+
break inner;
71+
}
72+
console.log('removed');
73+
}
74+
})();
75+
}
76+
}
77+
6278
function withConsequentReturn() {
6379
outer: {
6480
inner: {

0 commit comments

Comments
 (0)