add more plugins, rename some
This commit is contained in:
3
packages/babel-plugin-transform-jscript/.npmignore
Normal file
3
packages/babel-plugin-transform-jscript/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
*.log
|
||||
src
|
||||
35
packages/babel-plugin-transform-jscript/README.md
Normal file
35
packages/babel-plugin-transform-jscript/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# babel-plugin-transform-jscript
|
||||
|
||||
Babel plugin to fix buggy JScript named function expressions
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install babel-plugin-transform-jscript
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-jscript"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
$ babel --plugins transform-jscript script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["transform-jscript"]
|
||||
});
|
||||
```
|
||||
11
packages/babel-plugin-transform-jscript/package.json
Normal file
11
packages/babel-plugin-transform-jscript/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "babel-plugin-transform-jscript",
|
||||
"version": "1.0.4",
|
||||
"description": "Babel plugin to fix buggy JScript named function expressions",
|
||||
"repository": "babel/babel",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
]
|
||||
}
|
||||
20
packages/babel-plugin-transform-jscript/src/index.js
Normal file
20
packages/babel-plugin-transform-jscript/src/index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
FunctionExpression: {
|
||||
exit(node) {
|
||||
if (!node.id) return;
|
||||
node._ignoreUserWhitespace = true;
|
||||
|
||||
return t.callExpression(
|
||||
t.functionExpression(null, [], t.blockStatement([
|
||||
t.toStatement(node),
|
||||
t.returnStatement(node.id)
|
||||
])),
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user