https://github.com/qinzhen001/babel-plugin-parcel-function
:full_moon: 一个使用if-else包裹增强函数的babel插件
https://github.com/qinzhen001/babel-plugin-parcel-function
babel babel-plugin
Last synced: about 2 months ago
JSON representation
:full_moon: 一个使用if-else包裹增强函数的babel插件
- Host: GitHub
- URL: https://github.com/qinzhen001/babel-plugin-parcel-function
- Owner: QinZhen001
- Created: 2019-08-23T05:06:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T23:46:42.000Z (over 3 years ago)
- Last Synced: 2025-06-03T14:42:09.455Z (about 1 year ago)
- Topics: babel, babel-plugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/babel-plugin-parcel-function
- Size: 357 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# babel-plugin-parcel-function
[](https://996.icu)
[](https://github.com/996icu/996.ICU/blob/master/LICENSE)
一个使用if-else包裹增强函数的babel插件
不影响原函数的使用,可以在if中注入一些黑科技方法
----
A babel plugin that uses the if-else package enhancement function
Does not affect the use of the original function, you can inject some black technology method in ifStatement
## Install
```
npm install --save-dev babel-plugin-parcel-function
```
## Usage
.babelrc
```
{
"plugins":
[
["babel-plugin-parcel-function",
{
prefixName: "global.hotUpdate",
addFileName: false
}
]
]
}
```
## Examples
```javascript
async function f(arg) {
await aaa();
await bbb();
console.log('eee');
return 'ddd';
}
```
转换后
```javascript
async function f(arg) {
if (global.hotUpdate.f) {
global.hotUpdate.f.call(this,arg);
} else {
await aaa();
await bbb();
console.log('eee');
return 'ddd';
}
}
```
### Options
| name | description | type | default |
| ----------- | ------------------------ | ------------ | ------------------ |
| prefixName | if判断和if块中的前缀 | String or Array | "global.hotUpdate" |
| addFileName | 是否将文件名添加到前缀中 | Boolean | false |
when Options
```
{
prefixName: "aaa.bbb.ccc",
addFileName: false
}
```
code
```javascript
function f(aa,bb) {
let asd = 1
asd = aa + bb
console.log("aaa")
}
```
after transform
```javascript
function f(aa, bb) {
if (aaa.bbb.ccc.f) {
aaa.bbb.ccc.f.call(this, aa, bb);
} else {
let asd = 1;
asd = aa + bb;
console.log("aaa");
}
}
```
**if中的判断和if块中的代码由 [prefixName + fileName + 函数名] 决定**