Rename all proposal plugins to -proposal- from -transform- (#6570)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
47
packages/babel-plugin-proposal-throw-expressions/README.md
Normal file
47
packages/babel-plugin-proposal-throw-expressions/README.md
Normal 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)
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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]));
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function* test() {
|
||||
(throw new Error(...arguments));
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function* test() {
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error(...arguments));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
async function test() {
|
||||
(throw new Error(await 'test'));
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
async function test() {
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error((await 'test')));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function test() {
|
||||
(throw new Error('test'));
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function test() {
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error('test'));
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
(throw new Error('test'));
|
||||
@@ -0,0 +1,3 @@
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error('test'));
|
||||
@@ -0,0 +1 @@
|
||||
(throw new Error('test'), new Error('2'));
|
||||
@@ -0,0 +1,3 @@
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error('test')), new Error('2');
|
||||
@@ -0,0 +1 @@
|
||||
true && throw new Error('test');
|
||||
@@ -0,0 +1,3 @@
|
||||
true && function (e) {
|
||||
throw e;
|
||||
}(new Error('test'));
|
||||
@@ -0,0 +1,2 @@
|
||||
function test(a = throw new Error('test')) {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function test(a = function (e) {
|
||||
throw e;
|
||||
}(new Error('test'))) {}
|
||||
@@ -0,0 +1 @@
|
||||
test((throw new Error('test'), 1));
|
||||
@@ -0,0 +1,3 @@
|
||||
test((function (e) {
|
||||
throw e;
|
||||
}(new Error('test')), 1));
|
||||
@@ -0,0 +1,3 @@
|
||||
function* test() {
|
||||
(throw new Error(function.sent));
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function* test() {
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error(function.sent));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["proposal-throw-expressions", "syntax-function-sent"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["proposal-throw-expressions"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function* test() {
|
||||
(throw new Error(this));
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function* test() {
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error(this));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function test() {
|
||||
throw new Error('test');
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function test() {
|
||||
throw new Error('test');
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function* test() {
|
||||
(throw new Error(yield 'test'));
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function* test() {
|
||||
(function (e) {
|
||||
throw e;
|
||||
})(new Error((yield 'test')));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(__dirname);
|
||||
Reference in New Issue
Block a user