Rename all proposal plugins to -proposal- from -transform- (#6570)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
@@ -0,0 +1,60 @@
|
||||
# @babel/plugin-proposal-optional-catch-binding
|
||||
|
||||
> Optional catch binding enables the catch block to execute whether or not an argument is passed to the catch statement (CatchClause).
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
try {
|
||||
throw 0;
|
||||
} catch {
|
||||
doSomethingWhichDoesntCareAboutTheValueThrown();
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
try {
|
||||
throw 0;
|
||||
} catch {
|
||||
doSomethingWhichDoesntCareAboutTheValueThrown();
|
||||
} finally {
|
||||
doSomeCleanup();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-proposal-optional-catch-binding
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@babel/proposal-optional-catch-binding"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins @babel/proposal-optional-catch-binding script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["@babel/proposal-optional-catch-binding"]
|
||||
});
|
||||
```
|
||||
|
||||
## References
|
||||
- [Proposal: Optional Catch Binding for ECMAScript](https://github.com/babel/proposals/issues/7)
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@babel/plugin-proposal-optional-catch-binding",
|
||||
"version": "7.0.0-beta.3",
|
||||
"description": "Compile optional catch bindings",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-optional-catch-binding",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-beta.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
||||
|
||||
export default function() {
|
||||
return {
|
||||
inherits: syntaxOptionalCatchBinding,
|
||||
|
||||
visitor: {
|
||||
CatchClause(path) {
|
||||
if (!path.node.param) {
|
||||
const uid = path.scope.generateUidIdentifier("unused");
|
||||
const paramPath = path.get("param");
|
||||
paramPath.replaceWith(uid);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
const test = () => {
|
||||
try {
|
||||
throw 0;
|
||||
}
|
||||
catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
assert(test());
|
||||
|
||||
const test2 = () => {
|
||||
try {
|
||||
throw 0;
|
||||
}
|
||||
catch (err) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
assert(test2());
|
||||
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch (err) {
|
||||
console.log("it failed, but this code executes");
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch (err) {
|
||||
console.log("it failed, but this code executes");
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch {
|
||||
console.log("it failed, but this code executes");
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch (_unused) {
|
||||
console.log("it failed, but this code executes");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch (err) {
|
||||
console.log("it failed, but this code executes");
|
||||
} finally {
|
||||
console.log("this code also executes");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch (err) {
|
||||
console.log("it failed, but this code executes");
|
||||
} finally {
|
||||
console.log("this code also executes");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch {
|
||||
console.log("it failed, but this code executes");
|
||||
} finally {
|
||||
console.log("this code also executes");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
try {
|
||||
throw 0;
|
||||
} catch (_unused) {
|
||||
console.log("it failed, but this code executes");
|
||||
} finally {
|
||||
console.log("this code also executes");
|
||||
}
|
||||
3
packages/babel-plugin-proposal-optional-catch-binding/test/fixtures/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-optional-catch-binding/test/fixtures/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["proposal-optional-catch-binding"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(__dirname);
|
||||
Reference in New Issue
Block a user