Skip to content

Commit 4b22e87

Browse files
committed
Ensure every catch block is protected
1 parent 24c724d commit 4b22e87

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/transformer.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,30 @@ function transformer(args, body, isAsync, isGenerator, filename) {
113113
if (nodeType === 'CatchClause') {
114114
const param = node.param;
115115
if (param) {
116-
if (param.type === 'ObjectPattern') {
116+
if (param.type === 'Identifier') {
117+
const name = assertType(param, 'Identifier').name;
118+
const cBody = assertType(node.body, 'BlockStatement');
119+
if (cBody.body.length > 0) {
120+
insertions.push({
121+
__proto__: null,
122+
pos: cBody.body[0].start,
123+
order: TO_LEFT,
124+
coder: () => `${name}=${INTERNAL_STATE_NAME}.handleException(${name});`
125+
});
126+
}
127+
} else {
117128
insertions.push({
118129
__proto__: null,
119130
pos: node.start,
120131
order: TO_RIGHT,
121-
coder: () => `catch(${tmpname}){try{throw(${tmpname}=${INTERNAL_STATE_NAME}.handleException(${tmpname}));}`
132+
coder: () => `catch(${tmpname}){${tmpname}=${INTERNAL_STATE_NAME}.handleException(${tmpname});try{throw ${tmpname};}`
122133
});
123134
insertions.push({
124135
__proto__: null,
125136
pos: node.body.end,
126137
order: TO_LEFT,
127138
coder: () => `}`
128139
});
129-
} else {
130-
const name = assertType(param, 'Identifier').name;
131-
const cBody = assertType(node.body, 'BlockStatement');
132-
if (cBody.body.length > 0) {
133-
insertions.push({
134-
__proto__: null,
135-
pos: cBody.body[0].start,
136-
order: TO_LEFT,
137-
coder: () => `${name}=${INTERNAL_STATE_NAME}.handleException(${name});`
138-
});
139-
}
140140
}
141141
}
142142
} else if (nodeType === 'WithStatement') {

0 commit comments

Comments
 (0)