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,47 @@
# @babel/plugin-proposal-throw-expressions
This plugin transforms Throw Expressions into an IIFE.
## Example
```js
function test(param = throw new Error('required!')) {
const test = param === true || throw new Error('Falsey!');
}
```
## Installation
```sh
npm install --save-dev @babel/plugin-proposal-throw-expressions
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["@babel/proposal-throw-expressions"]
}
```
### Via CLI
```sh
babel --plugins @babel/proposal-throw-expressions script.js
```
### Via Node API
```javascript
require("@babel/core").transform("code", {
plugins: ["@babel/proposal-throw-expressions"]
});
```
## References
* [Proposal: Numeric Separators](https://github.com/tc39/proposal-throw-expressions)

View File

@@ -0,0 +1,20 @@
{
"name": "@babel/plugin-proposal-throw-expressions",
"version": "7.0.0-beta.3",
"description": "Wraps Throw Expressions in an IIFE",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-throw-expressions",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/plugin-syntax-throw-expressions": "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,23 @@
import syntaxThrowExpressions from "@babel/plugin-syntax-throw-expressions";
export default function({ types: t }) {
return {
inherits: syntaxThrowExpressions,
visitor: {
UnaryExpression(path) {
const { operator, argument } = path.node;
if (operator !== "throw") return;
const arg = t.identifier("e");
const arrow = t.functionExpression(
null,
[arg],
t.blockStatement([t.throwStatement(arg)]),
);
path.replaceWith(t.callExpression(arrow, [argument]));
},
},
};
}

View File

@@ -0,0 +1,3 @@
function* test() {
(throw new Error(...arguments));
}

View File

@@ -0,0 +1,5 @@
function* test() {
(function (e) {
throw e;
})(new Error(...arguments));
}

View File

@@ -0,0 +1,3 @@
async function test() {
(throw new Error(await 'test'));
}

View File

@@ -0,0 +1,5 @@
async function test() {
(function (e) {
throw e;
})(new Error((await 'test')));
}

View File

@@ -0,0 +1,3 @@
function test() {
(throw new Error('test'));
}

View File

@@ -0,0 +1,5 @@
function test() {
(function (e) {
throw e;
})(new Error('test'));
}

View File

@@ -0,0 +1,3 @@
(function (e) {
throw e;
})(new Error('test'));

View File

@@ -0,0 +1 @@
(throw new Error('test'), new Error('2'));

View File

@@ -0,0 +1,3 @@
(function (e) {
throw e;
})(new Error('test')), new Error('2');

View File

@@ -0,0 +1 @@
true && throw new Error('test');

View File

@@ -0,0 +1,3 @@
true && function (e) {
throw e;
}(new Error('test'));

View File

@@ -0,0 +1,2 @@
function test(a = throw new Error('test')) {
}

View File

@@ -0,0 +1,3 @@
function test(a = function (e) {
throw e;
}(new Error('test'))) {}

View File

@@ -0,0 +1 @@
test((throw new Error('test'), 1));

View File

@@ -0,0 +1,3 @@
test((function (e) {
throw e;
}(new Error('test')), 1));

View File

@@ -0,0 +1,3 @@
function* test() {
(throw new Error(function.sent));
}

View File

@@ -0,0 +1,5 @@
function* test() {
(function (e) {
throw e;
})(new Error(function.sent));
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["proposal-throw-expressions", "syntax-function-sent"]
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["proposal-throw-expressions"]
}

View File

@@ -0,0 +1,3 @@
function* test() {
(throw new Error(this));
}

View File

@@ -0,0 +1,5 @@
function* test() {
(function (e) {
throw e;
})(new Error(this));
}

View File

@@ -0,0 +1,3 @@
function test() {
throw new Error('test');
}

View File

@@ -0,0 +1,3 @@
function test() {
throw new Error('test');
}

View File

@@ -0,0 +1,3 @@
function* test() {
(throw new Error(yield 'test'));
}

View File

@@ -0,0 +1,5 @@
function* test() {
(function (e) {
throw e;
})(new Error((yield 'test')));
}

View File

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