Rename all proposal plugins to -proposal- from -transform- (#6570)

This commit is contained in:
Henry Zhu
2017-10-27 15:26:38 -04:00
committed by GitHub
parent a94aa54230
commit c41abd79a1
599 changed files with 372 additions and 372 deletions

View File

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

View File

@@ -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)

View File

@@ -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"
}
}

View File

@@ -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);
}
},
},
};
}

View File

@@ -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());

View File

@@ -0,0 +1,5 @@
try {
throw 0;
} catch (err) {
console.log("it failed, but this code executes");
}

View File

@@ -0,0 +1,5 @@
try {
throw 0;
} catch (err) {
console.log("it failed, but this code executes");
}

View File

@@ -0,0 +1,5 @@
try {
throw 0;
} catch {
console.log("it failed, but this code executes");
}

View File

@@ -0,0 +1,5 @@
try {
throw 0;
} catch (_unused) {
console.log("it failed, but this code executes");
}

View File

@@ -0,0 +1,7 @@
try {
throw 0;
} catch (err) {
console.log("it failed, but this code executes");
} finally {
console.log("this code also executes");
}

View File

@@ -0,0 +1,7 @@
try {
throw 0;
} catch (err) {
console.log("it failed, but this code executes");
} finally {
console.log("this code also executes");
}

View File

@@ -0,0 +1,7 @@
try {
throw 0;
} catch {
console.log("it failed, but this code executes");
} finally {
console.log("this code also executes");
}

View File

@@ -0,0 +1,7 @@
try {
throw 0;
} catch (_unused) {
console.log("it failed, but this code executes");
} finally {
console.log("this code also executes");
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["proposal-optional-catch-binding"]
}

View File

@@ -0,0 +1,3 @@
import runner from "@babel/helper-plugin-test-runner";
runner(__dirname);