Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore labels after included try statement block #3871

Merged
merged 1 commit into from Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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