Skip to content

Commit

Permalink
Merge pull request #1478 from rollup/gh-1462
Browse files Browse the repository at this point in the history
fix catch clause scopes
  • Loading branch information
Rich-Harris committed Jul 10, 2017
2 parents 875cd37 + f5bbea8 commit 88470f2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ast/nodes/CatchClause.js
@@ -0,0 +1,10 @@
import Node from '../Node.js';

export default class CatchClause extends Node {
initialise ( scope ) {
this.body.createScope( scope );
this.scope = this.body.scope;

this.body.initialise( this.scope );
}
}
2 changes: 2 additions & 0 deletions src/ast/nodes/index.js
Expand Up @@ -4,6 +4,7 @@ import AssignmentExpression from './AssignmentExpression.js';
import BinaryExpression from './BinaryExpression.js';
import BlockStatement from './BlockStatement.js';
import CallExpression from './CallExpression.js';
import CatchClause from './CatchClause.js';
import ClassDeclaration from './ClassDeclaration.js';
import ClassExpression from './ClassExpression.js';
import ConditionalExpression from './ConditionalExpression.js';
Expand Down Expand Up @@ -42,6 +43,7 @@ export default {
BinaryExpression,
BlockStatement,
CallExpression,
CatchClause,
ClassDeclaration,
ClassExpression,
ConditionalExpression,
Expand Down
6 changes: 6 additions & 0 deletions test/function/preserves-catch-argument/_config.js
@@ -0,0 +1,6 @@
module.exports = {
description: 'does not replace argument to catch block (#1462)',
options: {
external: ['path']
}
};
12 changes: 12 additions & 0 deletions test/function/preserves-catch-argument/main.js
@@ -0,0 +1,12 @@
import { dirname as i } from 'path';

function foo (path) {
const dir = i(path);
try {
throw new Error('something went wrong');
} catch (i) {
assert.equal(i.message, 'something went wrong');
}
}

foo('');

0 comments on commit 88470f2

Please sign in to comment.