From 8dffbf19d0f628d5cc7ae0d238d3f115e39ace5c Mon Sep 17 00:00:00 2001 From: MarckK Date: Tue, 19 Sep 2017 20:38:17 +0100 Subject: [PATCH] Codemod: remove unused catch binding (#6048) * outline of plugin to remove unused catch binding, test not passing * plugin to remove unused catch binding * Edit README.md and package.json * tests for try catch finally * Add test to handle case when binding is referenced and given new TypeError (not passing) * Fix visitor to not remove catch clause param when binding being assigned a new value * Improve naming of tests and explanations * add test case for catch param not present and fix test for duplicate variable declaration * Remove binding.constantViolations filter in visitor as superfluous * Remove duplicate check that catch clause param present * Alter visitor so returns out when catch binding is not an Identifier * Created failing tests for ObjectPattern params and rewrote visitor so now passing Took out the pass in visitor when param not an Identifier, wrote case to handle when param isObjectPattern, and wrote failing tests for when param isArrayPattern * Handle case when param isArrayPattern, tests passing * Update package.json to v7.0.0-alpha.20 * Revert visitor to only consider transform if param is Identifier --- .../.npmignore | 3 + .../README.md | 60 +++++++++++++++++++ .../package.json | 17 ++++++ .../src/index.js | 24 ++++++++ .../remove-unused-catch-binding/options.json | 3 + .../actual.js | 5 ++ .../options.json | 3 + .../try-catch-block-null-binding/actual.js | 5 ++ .../try-catch-block-null-binding/expected.js | 5 ++ .../actual.js | 5 ++ .../expected.js | 5 ++ .../try-catch-block-unused-binding/actual.js | 5 ++ .../expected.js | 5 ++ .../actual.js | 7 +++ .../expected.js | 7 +++ .../actual.js | 5 ++ .../expected.js | 5 ++ .../actual.js | 5 ++ .../expected.js | 5 ++ .../try-catch-block-used-binding/actual.js | 5 ++ .../try-catch-block-used-binding/expected.js | 5 ++ .../actual.js | 7 +++ .../expected.js | 7 +++ .../actual.js | 7 +++ .../expected.js | 7 +++ .../try-catch-finally-used-binding/actual.js | 7 +++ .../expected.js | 7 +++ .../test/index.js | 3 + 28 files changed, 234 insertions(+) create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/.npmignore create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/README.md create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/package.json create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/src/index.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/options.json create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/options.json create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/actual.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/expected.js create mode 100644 packages/babel-plugin-transform-remove-unused-catch-binding/test/index.js diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/.npmignore b/packages/babel-plugin-transform-remove-unused-catch-binding/.npmignore new file mode 100644 index 0000000000..f980694583 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/.npmignore @@ -0,0 +1,3 @@ +src +test +*.log diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/README.md b/packages/babel-plugin-transform-remove-unused-catch-binding/README.md new file mode 100644 index 0000000000..8443a20b45 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/README.md @@ -0,0 +1,60 @@ +# babel-plugin-transform-remove-unused-catch-binding + +> If the argument bound to the catch block is not referenced in the catch block, that argument and the catch binding is removed. + + +## Examples + +```js +try { + throw 0; +} catch (err) { + console.log("it failed, but this code executes"); +} +``` +Is transformed to: + +```js +try { + throw 0; +} catch { + console.log("it failed, but this code executes"); +} +``` + + +## Installation + +```sh +npm install --save-dev babel-plugin-transform-remove-unused-catch-binding +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-remove-unused-catch-binding"] +} +``` + +### Via CLI + +```sh +babel --plugins transform-remove-unused-catch-binding script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-remove-unused-catch-binding"] +}); +``` + +## References +This codemod updates your source code in line with the following proposal: +- [Proposal: Optional Catch Binding for ECMAScript](https://github.com/babel/proposals/issues/7) diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/package.json b/packages/babel-plugin-transform-remove-unused-catch-binding/package.json new file mode 100644 index 0000000000..0ca650ca96 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/package.json @@ -0,0 +1,17 @@ +{ + "name": "babel-plugin-transform-remove-unused-catch-binding", + "version": "7.0.0-alpha.20", + "description": "Remove unused catch bindings", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-plugin-syntax-optional-catch-binding": "7.0.0-alpha.20" + }, + "devDependencies": { + "babel-helper-plugin-test-runner": "7.0.0-alpha.20" + } +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/src/index.js b/packages/babel-plugin-transform-remove-unused-catch-binding/src/index.js new file mode 100644 index 0000000000..66d901533e --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/src/index.js @@ -0,0 +1,24 @@ +import syntaxOptionalCatchBinding from "babel-plugin-syntax-optional-catch-binding"; + +export default function(babel) { + const { types: t } = babel; + return { + inherits: syntaxOptionalCatchBinding, + + visitor: { + CatchClause(path) { + if (path.node.param === null || !t.isIdentifier(path.node.param)) { + return; + } + const binding = path.scope.getOwnBinding(path.node.param.name); + if (binding.constantViolations.length > 0) { + return; + } + if (!binding.referenced) { + const paramPath = path.get("param"); + paramPath.remove(); + } + }, + }, + }; +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/options.json b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/options.json new file mode 100644 index 0000000000..bfd6f2e628 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-remove-unused-catch-binding"] +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/actual.js new file mode 100644 index 0000000000..520eab559f --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch (e) { + let e = new TypeError('Duplicate variable declaration; will throw an error.'); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/options.json b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/options.json new file mode 100644 index 0000000000..f451b42655 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-duplicate-variable-declaration/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Duplicate declaration \"e\"" +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/actual.js new file mode 100644 index 0000000000..1bf3a12cd8 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/expected.js new file mode 100644 index 0000000000..1bf3a12cd8 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-null-binding/expected.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/actual.js new file mode 100644 index 0000000000..89bd8f7b85 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch ([message]) { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/expected.js new file mode 100644 index 0000000000..89bd8f7b85 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-array-pattern-binding/expected.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch ([message]) { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/actual.js new file mode 100644 index 0000000000..0f989f7bdc --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch (err) { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/expected.js new file mode 100644 index 0000000000..1bf3a12cd8 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-binding/expected.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/actual.js new file mode 100644 index 0000000000..7923919210 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/actual.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch ({ + message +}) { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/expected.js new file mode 100644 index 0000000000..7923919210 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-unused-object-pattern-binding/expected.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch ({ + message +}) { + console.log("it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/actual.js new file mode 100644 index 0000000000..20dea187c0 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch ([message]) { + console.log(message); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/expected.js new file mode 100644 index 0000000000..20dea187c0 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-array-pattern-binding/expected.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch ([message]) { + console.log(message); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/actual.js new file mode 100644 index 0000000000..098cfdf7fe --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch (e) { + e = new TypeError('A new variable is not being declared or initialized; the catch binding is being referenced and cannot be removed.'); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/expected.js new file mode 100644 index 0000000000..098cfdf7fe --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding-variable/expected.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch (e) { + e = new TypeError('A new variable is not being declared or initialized; the catch binding is being referenced and cannot be removed.'); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/actual.js new file mode 100644 index 0000000000..d0335caa35 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/actual.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch (err) { + console.log(err, "it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/expected.js new file mode 100644 index 0000000000..d0335caa35 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-binding/expected.js @@ -0,0 +1,5 @@ +try { + throw 0; +} catch (err) { + console.log(err, "it failed, but this code executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/actual.js new file mode 100644 index 0000000000..5d0ec55ede --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/actual.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch ({ + message +}) { + console.log(message); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/expected.js new file mode 100644 index 0000000000..5d0ec55ede --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-block-used-object-pattern-binding/expected.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch ({ + message +}) { + console.log(message); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/actual.js new file mode 100644 index 0000000000..ba0539adf7 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/actual.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch (err) { + console.log("it failed, but this code executes"); +} finally { + console.log("this code also executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/expected.js new file mode 100644 index 0000000000..31e6ca9ff4 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-unused-binding/expected.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch { + console.log("it failed, but this code executes"); +} finally { + console.log("this code also executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/actual.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/actual.js new file mode 100644 index 0000000000..fb09c402a5 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/actual.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch (err) { + console.log(err, "it failed, but this code executes"); +} finally { + console.log("this code also executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/expected.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/expected.js new file mode 100644 index 0000000000..fb09c402a5 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/fixtures/remove-unused-catch-binding/try-catch-finally-used-binding/expected.js @@ -0,0 +1,7 @@ +try { + throw 0; +} catch (err) { + console.log(err, "it failed, but this code executes"); +} finally { + console.log("this code also executes"); +} diff --git a/packages/babel-plugin-transform-remove-unused-catch-binding/test/index.js b/packages/babel-plugin-transform-remove-unused-catch-binding/test/index.js new file mode 100644 index 0000000000..09cfbc31f5 --- /dev/null +++ b/packages/babel-plugin-transform-remove-unused-catch-binding/test/index.js @@ -0,0 +1,3 @@ +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname);