From eb1ce8c73004f7d231a27bd100e7b47e29c86aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E9=81=93?= Date: Wed, 31 Aug 2022 18:49:56 +0800 Subject: [PATCH] support catch without error (#58) --- index.js | 2 +- test/fixtures/catch-without-error.js | 1 + test/index.js | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/catch-without-error.js diff --git a/index.js b/index.js index 232cbe4..0bbf023 100644 --- a/index.js +++ b/index.js @@ -132,7 +132,7 @@ function findGlobals(source, options) { }, 'Class': declareClass, 'TryStatement': function (node) { - if (node.handler === null) return; + if (node.handler === null || node.handler.param === null) return; node.handler.locals = node.handler.locals || Object.create(null); declarePattern(node.handler.param, node.handler); }, diff --git a/test/fixtures/catch-without-error.js b/test/fixtures/catch-without-error.js new file mode 100644 index 0000000..30fa5a4 --- /dev/null +++ b/test/fixtures/catch-without-error.js @@ -0,0 +1 @@ +try{}catch{} diff --git a/test/index.js b/test/index.js index fb1a9d1..de8b97a 100644 --- a/test/index.js +++ b/test/index.js @@ -43,6 +43,9 @@ test('assign_implicit.js - assign from an implicit global', function () { test('catch-pattern.js - pattern in catch', function () { assert.deepEqual(detect(read('catch-pattern.js')), []); }); +test('catch-without-error.js - catch without error', function () { + assert.deepEqual(detect(read('catch-without-error.js')), []); +}); test('class.js - ES2015 classes', function () { assert.deepEqual(detect(read('class.js')).map(nameOf), ['G', 'OtherClass_', 'SuperClass', 'this'].sort()); });