add Error to known globals, declare catch block parameter. fixes #3064

pull/3098/head
Rich Harris 6 years ago
parent f7479bc57b
commit 1fc4b1c867

@ -40,6 +40,13 @@ export function create_scopes(expression: Node) {
map.set(node, scope); map.set(node, scope);
} else if (/(Class|Variable)Declaration/.test(node.type)) { } else if (/(Class|Variable)Declaration/.test(node.type)) {
scope.add_declaration(node); scope.add_declaration(node);
} else if (node.type === 'CatchClause') {
scope = new Scope(scope, true);
map.set(node, scope);
extract_names(node.param).forEach(name => {
scope.declarations.set(name, node.param);
});
} else if (node.type === 'Identifier' && is_reference(node as ESTreeNode, parent as ESTreeNode)) { } else if (node.type === 'Identifier' && is_reference(node as ESTreeNode, parent as ESTreeNode)) {
if (!scope.has(node.name) && !globals.has(node.name)) { if (!scope.has(node.name) && !globals.has(node.name)) {
globals.set(node.name, node); globals.set(node.name, node);

@ -13,6 +13,7 @@ export const globals = new Set([
'document', 'document',
'encodeURI', 'encodeURI',
'encodeURIComponent', 'encodeURIComponent',
'Error',
'Infinity', 'Infinity',
'Intl', 'Intl',
'isFinite', 'isFinite',

@ -0,0 +1,13 @@
<script>
let value = null;
</script>
<button on:click={event => {
try {
throw new Error('foo');
} catch (error) {
value = error;
}
}}>Click to create error</button>
{String(value)}
Loading…
Cancel
Save