Skip to content

Commit

Permalink
Restore labels after included try statement block (#3871)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 14, 2020
1 parent d861c91 commit 1ec3c4f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/ast/nodes/TryStatement.ts
Expand Up @@ -12,6 +12,7 @@ export default class TryStatement extends StatementBase {
type!: NodeType.tTryStatement;

private directlyIncluded = false;
private includedLabelsAfterBlock: string[] | null = null;

hasEffects(context: HasEffectsContext): boolean {
return (
Expand All @@ -33,7 +34,14 @@ export default class TryStatement extends StatementBase {
context,
tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively
);
if (context.includedLabels.size > 0) {
this.includedLabelsAfterBlock = [...context.includedLabels];
}
context.brokenFlow = brokenFlow;
} else if (this.includedLabelsAfterBlock) {
for (const label of this.includedLabelsAfterBlock) {
context.includedLabels.add(label);
}
}
if (this.handler !== null) {
this.handler.include(context, includeChildrenRecursively);
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/conditional-catch/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles conditional catch blocks (#3869)'
};
17 changes: 17 additions & 0 deletions test/function/samples/conditional-catch/main.js
@@ -0,0 +1,17 @@
function g() {
var result;
g: {
try {
break g;
} catch (_) {}
return;
}
try {
throw 'Expected';
} catch (e) {
result = e;
}
assert.strictEqual(result, 'Expected');
}

g();
17 changes: 10 additions & 7 deletions test/watch/index.js
Expand Up @@ -292,7 +292,7 @@ describe('rollup.watch', () => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
assert.deepStrictEqual(events, ['create', 'update']);
assert.deepStrictEqual(ids, expectedIds);
sander.rimrafSync(WATCHED_ID);
sander.unlinkSync(WATCHED_ID);
},
'START',
'BUNDLE_START',
Expand All @@ -308,6 +308,7 @@ describe('rollup.watch', () => {

it('correctly rewrites change event during build delay', async () => {
const WATCHED_ID = path.resolve('test/_tmp/input/watched');
const MAIN_ID = path.resolve('test/_tmp/input/main.js');
let lastEvent = null;
await sander.copydir('test/watch/samples/watch-files').to('test/_tmp/input');
await wait(100);
Expand All @@ -329,9 +330,10 @@ describe('rollup.watch', () => {
this.addWatchFile(WATCHED_ID);
},
watchChange(id, { event }) {
assert.strictEqual(lastEvent, null);
assert.strictEqual(id, WATCHED_ID);
lastEvent = event;
if (id === WATCHED_ID) {
assert.strictEqual(lastEvent, null);
lastEvent = event;
}
}
}
});
Expand All @@ -342,11 +344,10 @@ describe('rollup.watch', () => {
'BUNDLE_END',
'END',
async () => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
assert.strictEqual(lastEvent, null);
sander.writeFileSync(WATCHED_ID, 'another');
await wait(100);
sander.rimrafSync(WATCHED_ID);
sander.unlinkSync(WATCHED_ID);
},
'START',
'BUNDLE_START',
Expand All @@ -357,7 +358,9 @@ describe('rollup.watch', () => {
lastEvent = null;
sander.writeFileSync(WATCHED_ID, '123');
await wait(100);
sander.rimrafSync(WATCHED_ID);
sander.unlinkSync(WATCHED_ID);
// To ensure there is always another change to trigger a rebuild
sander.writeFileSync(MAIN_ID, 'export default 43;');
},
'START',
'BUNDLE_START',
Expand Down

0 comments on commit 1ec3c4f

Please sign in to comment.