Add optionality to catch bindings (#5956)

This commit is contained in:
MarckK
2017-07-25 15:38:48 +01:00
committed by Brian Ng
parent 51a293601b
commit 9fc910d8c0
29 changed files with 360 additions and 9 deletions

View File

@@ -0,0 +1,3 @@
src
test
*.log

View File

@@ -0,0 +1,52 @@
# babel-plugin-syntax-optional-catch-binding
> This plugin allows Babel to parse optional catch bindings.
## Example
**Syntax**
```javascript
try {
throw 0;
} catch {
doSomethingWhichDoesntCareAboutTheValueThrown();
console.log("Yay, code executes!");
}
```
## Installation
```sh
npm install --save-dev babel-plugin-syntax-optional-catch-binding
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["syntax-optional-catch-binding"]
}
```
### Via CLI
```sh
babel --plugins syntax-optional-catch-binding script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["syntax-optional-catch-binding"]
});
```
## References
* [Proposal: Optional Catch Binding for ECMAScript](https://github.com/babel/proposals/issues/7)

View File

@@ -0,0 +1,13 @@
{
"name": "babel-plugin-syntax-optional-catch-binding",
"version": "7.0.0-alpha.15",
"description": "Allow parsing of optional catch bindings",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-optional-catch-binding",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {},
"devDependencies": {}
}

View File

@@ -0,0 +1,7 @@
export default function() {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push("optionalCatchBinding");
},
};
}