Add optionality to catch bindings (#5956)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
@@ -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)
|
||||
@@ -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": {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function() {
|
||||
return {
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("optionalCatchBinding");
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user