├── .eslintignore ├── .eslintrc ├── .fatherrc.js ├── .gitignore ├── .npmignore ├── LICENSE ├── README.CN.md ├── README.md ├── coverage ├── clover.xml ├── coverage-final.json ├── lcov-report │ ├── Plugin.js.html │ ├── base.css │ ├── block-navigation.js │ ├── index.html │ ├── index.js.html │ ├── prettify.css │ ├── prettify.js │ ├── sort-arrow-sprite.png │ └── sorter.js └── lcov.info ├── package-lock.json ├── package.json ├── src ├── Plugin.js ├── index.js ├── index.mdx └── index.module.less ├── test ├── fixtures │ ├── array-expression │ │ ├── actual.js │ │ └── expected.js │ ├── as-arguments-identifier │ │ ├── actual.js │ │ └── expected.js │ ├── as-arguments │ │ ├── actual.js │ │ └── expected.js │ ├── binary-expression │ │ ├── actual.js │ │ └── expected.js │ ├── camel2-dash-name-lower │ │ ├── actual.js │ │ └── expected.js │ ├── conditions │ │ ├── actual.js │ │ └── expected.js │ ├── custom-name-source-file │ │ ├── actual.js │ │ ├── customName.js │ │ └── expected.js │ ├── custom-name │ │ ├── actual.js │ │ └── expected.js │ ├── custom-style-name │ │ ├── actual.js │ │ └── expected.js │ ├── custom-style-path-ignore │ │ ├── actual.js │ │ └── expected.js │ ├── custom-style-path │ │ ├── actual.js │ │ └── expected.js │ ├── execute-direct │ │ ├── actual.js │ │ └── expected.js │ ├── execute-member │ │ ├── actual.js │ │ └── expected.js │ ├── export-import │ │ ├── actual.js │ │ └── expected.js │ ├── expression-statement │ │ ├── actual.js │ │ └── expected.js │ ├── file-name │ │ ├── actual.js │ │ └── expected.js │ ├── import-alias │ │ ├── actual.js │ │ └── expected.js │ ├── import-css │ │ ├── actual.js │ │ └── expected.js │ ├── keep-named-import │ │ ├── actual.js │ │ └── expected.js │ ├── material-ui │ │ ├── actual.js │ │ └── expected.js │ ├── member-expression │ │ ├── actual.js │ │ └── expected.js │ ├── modules-false │ │ ├── actual.js │ │ └── expected.js │ ├── multiple-libraries-hilojs │ │ ├── actual.js │ │ └── expected.js │ ├── multiple-libraries │ │ ├── actual.js │ │ └── expected.js │ ├── multiple-words │ │ ├── actual.js │ │ └── expected.js │ ├── new-expression │ │ ├── actual.js │ │ └── expected.js │ ├── object-shorthand │ │ ├── actual.js │ │ └── expected.js │ ├── property │ │ ├── actual.js │ │ └── expected.js │ ├── react-element │ │ ├── actual.js │ │ └── expected.js │ ├── react-toolbox │ │ ├── actual.js │ │ └── expected.js │ ├── return │ │ ├── actual.js │ │ └── expected.js │ ├── specifier-alias │ │ ├── actual.js │ │ └── expected.js │ ├── style-library-name │ │ ├── actual.js │ │ └── expected.js │ ├── super-class │ │ ├── actual.js │ │ └── expected.js │ ├── switch │ │ ├── actual.js │ │ └── expected.js │ ├── transform-to-default-import-array │ │ ├── actual.js │ │ └── expected.js │ ├── use-multiple-times │ │ ├── actual.js │ │ └── expected.js │ ├── variable-declarator-renamed-import │ │ ├── actual.js │ │ └── expected.js │ ├── variable-declarator │ │ ├── actual.js │ │ └── expected.js │ └── variable-scope │ │ ├── actual.js │ │ └── expected.js └── index.test.js └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | **/*/__tests__ 2 | test 3 | .docz 4 | node_modules 5 | .eslintignore 6 | .eslintrc 7 | .fatherrc.js 8 | .gitgnore 9 | package.json 10 | package-lock.json 11 | yarn.lock 12 | .prettierrc 13 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "node": true, 5 | "es6": true 6 | }, 7 | "parserOptions": { 8 | "ecmaVersion": 2020, 9 | "sourceType": "module" 10 | }, 11 | "extends": ["eslint:recommended", "plugin:prettier/recommended"], 12 | "rules": { 13 | "no-console": [0], 14 | "prettier/prettier": 2, 15 | "global-require": 0, 16 | "func-names": 0 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.fatherrc.js: -------------------------------------------------------------------------------- 1 | export default { 2 | entry: 'src/index.js', 3 | // ejs: 'rollup', 4 | esm: { 5 | type: 'rollup', 6 | }, 7 | cjs: 'rollup', 8 | // umd: { 9 | // name: 'treasure', 10 | // }, 11 | }; 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .docz 4 | yarn-error.log -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | tmp 3 | node_modules 4 | coverage 5 | __tests__ 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 袋鼠云 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.CN.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-treasure 2 | 3 | ![NPM version](https://img.shields.io/badge/npm-v0.9.0-blue) ![Build Status](https://img.shields.io/badge/build-passing-orange) ![Coverage Status](https://img.shields.io/badge/coverage-97%25-brightgreen) ![License Status](https://img.shields.io/badge/license-MIT-lightgrey) 4 | 基于 babel-plugin-import 致力于实现统一库的 AST 优化要求,应对各种 AST 节点修改操作的诉求。目前用于统一式便捷解决任何组件库的按需加载需求 5 | 6 | --- 7 | 8 | - [English Instruction](./README.md) 9 | - [中文说明](./README.CN.md) 10 | 11 | ## 与 babel-plugin-import 的区别 12 | 13 | ### 优化点 14 | 15 | - 无破坏性改动,兼容原本 babel-plugin-import 的所有 API 16 | - 支持组件名或者方法名大小驼峰名称转换 17 | - 支持以对象的形式输入自定义路径节点 18 | - 支持导出入口是部分 default 属性的组件 19 | - 支持 react17+ jsx 新转换 20 | 21 | ### 修复点 22 | 23 | - 修复 babel-plugin-import 未对 switch 相关 AST 树进行转换的错误 24 | 25 | ## 安装 26 | 27 | ```javascript 28 | // 使用 npm 29 | npm i babel-plugin-treasure --save-dev 30 | 31 | // 使用 yarn 32 | yarn add babel-plugin-treasure -D 33 | ``` 34 | 35 | ## 使用说明 36 | 37 | 可通过以下两种途径进行使用 38 | 39 | - [babelrc](https://babeljs.io/docs/usage/babelrc/) 40 | - [babel-loader](https://github.com/babel/babel-loader) 41 | 42 | 添加到 `.babelrc` 或 babel-loader. 43 | 44 | ```js 45 | { 46 | "plugins": [["treasure", options]] 47 | } 48 | ``` 49 | 50 | ### 配置 51 | 52 | `options` 可以是一个对象. 53 | 54 | ```javascript 55 | { 56 | "libraryName": "dt-react-component", 57 | "style": true, // or 'css' 58 | } 59 | ``` 60 | 61 | `options` 可以是一个数组,但不支持在 babel@7+ 环境中设置 62 | 63 | ```javascript 64 | [ 65 | { 66 | libraryName: 'dt-react-component', 67 | style: true, // or 'css' 68 | }, 69 | ]; 70 | ``` 71 | 72 | `options` 在 babel@7+环境中不能是数组,但是你可以给插件添加一个名字来支持复用. 73 | 74 | 比如: 75 | 76 | ```javascrit 77 | // .babelrc 78 | "plugins": [ 79 | ["treasure", { "libraryName": "dt-react-component", "libraryDirectory": "lib"}, "dtcomponent"], 80 | ["treasure", { "libraryName": "lodash", "libraryDirectory": "lib"}, "lodash"] 81 | ] 82 | ``` 83 | 84 | ### 按需加载库 85 | 86 | 当你在项目中单纯引入库时,你只需要添加如下配置即可。 例如配置 dt-react-component: 87 | 88 | ```javascript 89 | "plugins": [ 90 | [ 91 | "treasure", 92 | { 93 | "libraryName": "dt-react-component", 94 | "libraryDirectory": "lib", 95 | "camel2DashComponentName": "lower", 96 | "style": "css" 97 | } 98 | ] 99 | ] 100 | ``` 101 | 102 | 注意:当你开发的项目中有多个库均需要使用按需加载,可以加一个别名已进行区分,例如 dt-react-component 与 antd 一起使用: 103 | 104 | ```javascript 105 | "plugins": [ 106 | [ 107 | "treasure", 108 | { 109 | "libraryName": "antd", 110 | "libraryDirectory": "lib", 111 | "style": "css" 112 | }, 113 | "antd" 114 | ], 115 | [ 116 | "treasure", 117 | { 118 | "libraryName": "dt-react-component", 119 | "libraryDirectory": "lib", 120 | "camel2DashComponentName": "lower", 121 | "style": "css" 122 | }, 123 | "dt-react-component" 124 | ] 125 | ] 126 | ``` 127 | 128 | ## 插件 API 列表 129 | 130 | ### libraryName 131 | 132 | 需要按需引入 library 的名称,必填。 133 | 134 | #### `{ "libraryName": "dt-react-component" }` 135 | 136 | ### libraryDirectory 137 | 138 | 制定 library 的包格式目录,一般有 lib, es, esm, umd 等,由包开发者制定。此选项默认值为 lib 139 | 140 | #### `{ libraryDirectory: "lib" }` 141 | 142 | ### style 143 | 144 | 是否需要按需加载 css 文件,默认不开启 145 | Note : 当设置 style 为 true 的时候加载 css 预编译文件(less/scss),设置为 css 时加载 css 文件. 146 | 147 | 加载 css 预编译文件: 148 | 149 | #### `{ libraryDirectory: true }` 150 | 151 | 加载 css 文件: 152 | 153 | #### `{ libraryDirectory: "css" }` 154 | 155 | ### styleLibraryDirectory 156 | 157 | 制定 css 文件的 library 的包,一般不需要写 158 | 159 | #### `{ styleLibraryDirectory: "lib" }` 160 | 161 | ### camel2DashComponentName 162 | 163 | 制定组件名的转换,参数有四种,默认为 true。转换规则如下所示: 164 | 165 | ```js 166 | import { ChromeDownload } from 'dt-react-component' 167 | 168 | ↓ ↓ ↓ ↓ ↓ ↓ 169 | 170 | // 当 camel2DashComponentName: true 171 | ChromeDownload → chrome-download 172 | 173 | // 当 camel2DashComponentName: false 174 | ChromeDownload → ChromeDownload // 不做改动 175 | 176 | // 当 camel2DashComponentName: "lower" 177 | ChromeDownload → chromeDownload // 转换小驼峰 178 | 179 | // 当 camel2DashComponentName: "upper" 180 | ChromeDownload → ChromeDownload // 转换大驼峰 181 | ``` 182 | 183 | ### camel2UnderlineComponentName 184 | 185 | 处理多词构成的组件以\_进行单词分割 186 | 187 | ```js 188 | import { ChromeDownload } from 'dt-react-component' 189 | 190 | ↓ ↓ ↓ ↓ ↓ ↓ 191 | 192 | ChromeDownload → chrome_download 193 | ``` 194 | 195 | ### transformToDefaultImport 196 | 197 | 处理默认导入库的属性,默认为 true。你可以给予一个数组,在数组中的组件,最后不会以默认形式进行导出。 198 | 如果你的库完全没有默认导入,请把选项设置为 false 199 | 举例: 200 | 201 | ```js 202 | // 设置 transformToDefaultImport:[ChromeDownload] 203 | import { ChromeDownload, Circle } from 'dt-react-component' 204 | 205 | ↓ ↓ ↓ ↓ ↓ ↓ 206 | 207 | import _Circle from "dt-react-component/lib/circle"; 208 | import { ChromeDownload as _ChromeDownload } from "dt-react-component/lib/chromeDownload"; 209 | ``` 210 | 211 | ### customName 212 | 213 | 处理个别不统一规则的序列,支持函数,对象与路径导入 214 | 215 | ```js 216 | // 函数形式 217 | [ 218 | 'treasure', 219 | { 220 | libraryName: 'dt-react-component', 221 | customName: (name: string) => { 222 | if (name === 'go-back') { 223 | return 'antd/lib/go-back'; 224 | } 225 | return `antd/lib/${name}`; 226 | }, 227 | }, 228 | ]; 229 | ``` 230 | 231 | 通过处理后,会变成这样 232 | 233 | ```js 234 | import { GoBack } from "antd" 235 | 236 | ↓ ↓ ↓ ↓ ↓ ↓ 237 | 238 | var _button = require('antd/lib/go-back'); 239 | ``` 240 | 241 | ```js 242 | // 对象形式 243 | [ 244 | 'treasure', 245 | { 246 | libraryName: 'dt-react-component', 247 | customName: { 248 | GoBack: 'dt-react-component/lib/go-back', 249 | }, 250 | }, 251 | ]; 252 | ``` 253 | 254 | 说明:当你使用函数时,函数形参是经过 styleLibraryDirectory 或 camel2DashComponentName 转换后的的名称,当你使用对象作为参数时,对象的 key 不会经过特殊转换,customStyleName 同理。 255 | 除此之外,你还可以选择引用路径: 256 | 257 | ```js 258 | // 引用路径 259 | [ 260 | 'treasure', 261 | { 262 | libraryName: 'dt-react-component', 263 | customName: { 264 | GoBack: require('path').resolve(__dirname, './customName.js'), 265 | }, 266 | }, 267 | ]; 268 | ``` 269 | 270 | `customName.js`类似: 271 | 272 | ```js 273 | module.exports = function customName(name) { 274 | return `dt-react-component/lib/${name}`; 275 | }; 276 | ``` 277 | 278 | #### customStyleName 279 | 280 | 与 customName 同理,只是用于处理 style 文件路径 281 | 282 | #### fileName 283 | 284 | 处理链接到具体的文件,例如: 285 | 286 | ```js 287 | // 对象形式 288 | [ 289 | "treasure", 290 | { 291 | "libraryName": "dt-react-component", 292 | "fileName": "example" 293 | "customName": { 294 | "GoBack": "dt-react-component/lib/go-back", 295 | } 296 | } 297 | ] 298 | ``` 299 | 300 | 转换后结果如下: 301 | 302 | ```js 303 | import { ChromeDownload } from 'dt-react-component' 304 | 305 | ↓ ↓ ↓ ↓ ↓ ↓ 306 | 307 | import 'dt-react-component/lib/chrome-download/exmaple' 308 | ``` 309 | 310 | ## 路线图 311 | 312 | - 随着各类库的变革做出及时更新 313 | - 支持更多的 AST 类型操作 314 | - 根据 treasure IDE 动态配置 AST 操作功能类型 315 | 316 | ## 执照 317 | 318 | [MIT](./LICENSE) 319 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-treasure 2 | 3 | ![NPM version](https://img.shields.io/badge/npm-v0.9.0-blue) ![Build Status](https://img.shields.io/badge/build-passing-orange) ![Coverage Status](https://img.shields.io/badge/coverage-97%25-brightgreen) ![License Status](https://img.shields.io/badge/license-MIT-lightgrey) 4 | Based on babel-plugin-import, we are committed to realizing the AST optimization requirements of the unified library and responding to the requirements of various AST node modification operations. Currently used in a unified and convenient way to solve the on-demand loading requirements of any component library 5 | 6 | --- 7 | 8 | - [English Instruction](./README.md) 9 | - [中文说明](./README.CN.md) 10 | 11 | ## Difference with babel-plugin-import 12 | 13 | ### Optimization points 14 | 15 | - No destructive changes, compatible with all APIs of the original babel-plugin-import 16 | - Support component name or method name size conversion 17 | - Support inputting custom path nodes in the form of objects 18 | - Support exporting components whose entry is part of the default attribute 19 | - Support react17+ jsx new conversion 20 | 21 | ### Fix point 22 | 23 | - Fixed the bug that babel-plugin-import did not convert the switch related AST tree 24 | 25 | ## Install 26 | 27 | ```javascript 28 | // use npm 29 | npm i babel-plugin-treasure --save-dev 30 | 31 | // use yarn 32 | yarn add babel-plugin-treasure -D 33 | ``` 34 | 35 | ## Usage 36 | 37 | Can be used in the following two ways 38 | 39 | - [babelrc](https://babeljs.io/docs/usage/babelrc/) 40 | - [babel-loader](https://github.com/babel/babel-loader) 41 | 42 | Add to `.babelrc` or babel-loader. 43 | 44 | ```js 45 | { 46 | "plugins": [["treasure", options]] 47 | } 48 | ``` 49 | 50 | ### Configuration 51 | 52 | ʻOptions` can be an object. 53 | 54 | ```javascript 55 | { 56 | "libraryName": "dt-react-component", 57 | "style": true, // or'css' 58 | } 59 | ``` 60 | 61 | ʻOptions` can be an array, but it does not support setting in the babel@7+ environment 62 | 63 | ```javascript 64 | [ 65 | { 66 | libraryName: 'dt-react-component', 67 | style: true, // or'css' 68 | }, 69 | ]; 70 | ``` 71 | 72 | ʻOptions` cannot be an array in the babel@7+ environment, but you can add a name to the plugin to support reuse. 73 | 74 | such as: 75 | 76 | ```javascrit 77 | // .babelrc 78 | "plugins": [ 79 | ["treasure", {"libraryName": "dt-react-component", "libraryDirectory": "lib"}, "dtcomponent"], 80 | ["treasure", {"libraryName": "lodash", "libraryDirectory": "lib"}, "lodash"] 81 | ] 82 | ``` 83 | 84 | ### Load libraries on demand 85 | 86 | When you simply import the library in the project, you only need to add the following configuration. For example, configure dt-react-component: 87 | 88 | ```javascript 89 | "plugins": [ 90 | [ 91 | "treasure", 92 | { 93 | "libraryName": "dt-react-component", 94 | "libraryDirectory": "lib", 95 | "camel2DashComponentName": "lower", 96 | "style": "css" 97 | } 98 | ] 99 | ] 100 | ``` 101 | 102 | Note: When you have multiple libraries in your development project that need to be loaded on demand, you can add an alias to distinguish it, for example, dt-react-component is used with antd: 103 | 104 | ```javascript 105 | "plugins": [ 106 | [ 107 | "treasure", 108 | { 109 | "libraryName": "antd", 110 | "libraryDirectory": "lib", 111 | "style": "css" 112 | }, 113 | "antd" 114 | ], 115 | [ 116 | "treasure", 117 | { 118 | "libraryName": "dt-react-component", 119 | "libraryDirectory": "lib", 120 | "camel2DashComponentName": "lower", 121 | "style": "css" 122 | }, 123 | "dt-react-component" 124 | ] 125 | ] 126 | ``` 127 | 128 | ## API 129 | 130 | ### libraryName 131 | 132 | The name of the library needs to be imported as required, which is required. 133 | 134 | #### `{ "libraryName": "dt-react-component" }` 135 | 136 | ### libraryDirectory 137 | 138 | Formulate the package format directory of the library, generally lib, es, esm, umd, etc., which are determined by the package developer. The default value of this option is lib 139 | 140 | #### `{ libraryDirectory: "lib" }` 141 | 142 | ### style 143 | 144 | Do you need to load css files on demand, not enabled by default Note: Load the css precompiled file (less/scss) when the style is set to true, and load the css file when it is set to css. 145 | 146 | Load the css precompiled file: 147 | 148 | #### `{ libraryDirectory: true }` 149 | 150 | Load the css file: 151 | 152 | #### `{ libraryDirectory: "css" }` 153 | 154 | ### styleLibraryDirectory 155 | 156 | The library package for making css files, generally does not need to be written 157 | 158 | #### `{ styleLibraryDirectory: "lib" }` 159 | 160 | ### camel2DashComponentName 161 | 162 | There are four parameters for the conversion of the component name, and the default is true. The conversion rules are as follows: 163 | 164 | ```js 165 | import {ChromeDownload} from'dt-react-component' 166 | 167 | ↓ ↓ ↓ ↓ ↓ ↓ 168 | 169 | // When camel2DashComponentName: true 170 | ChromeDownload → chrome-download 171 | 172 | // When camel2DashComponentName: false 173 | ChromeDownload → ChromeDownload // No changes 174 | 175 | // When camel2DashComponentName: "lower" 176 | ChromeDownload → chromeDownload // convert lower camel 177 | 178 | // When camel2DashComponentName: "upper" 179 | ChromeDownload → ChromeDownload // convert upper camel 180 | ``` 181 | 182 | ### camel2UnderlineComponentName 183 | 184 | Handle multi-word components with \_ for word segmentation 185 | 186 | ```js 187 | import { ChromeDownload } from'dt-react-component' 188 | 189 | ↓ ↓ ↓ ↓ ↓ ↓ 190 | 191 | ChromeDownload → chrome_download 192 | ``` 193 | 194 | ### transformToDefaultImport 195 | 196 | Process the attributes of the default import library, the default is true. You can give an array, and the components in the array will not be exported in the default form. If your library is not imported by default at all, please set the option to false For example: 197 | 198 | ```js 199 | // Set transformToDefaultImport: [ChromeDownload] 200 | import { ChromeDownload, Circle } from'dt-react-component' 201 | 202 | ↓ ↓ ↓ ↓ ↓ ↓ 203 | 204 | import _Circle from "dt-react-component/lib/circle"; 205 | import { ChromeDownload as _ChromeDownload } from "dt-react-component/lib/chromeDownload"; 206 | ``` 207 | 208 | ### customName 209 | 210 | Handle individual sequences with irregular rules, support function, object and path import 211 | 212 | ```js 213 | // Function form 214 | [ 215 | 'treasure', 216 | { 217 | libraryName: 'dt-react-component', 218 | customName: (name: string) => { 219 | if (name === 'go-back') { 220 | return 'antd/lib/go-back'; 221 | } 222 | return `antd/lib/${name}`; 223 | }, 224 | }, 225 | ]; 226 | ``` 227 | 228 | After processing, it will become like this 229 | 230 | ```js 231 | import {GoBack} from "antd" 232 | 233 | ↓ ↓ ↓ ↓ ↓ ↓ 234 | 235 | var _button = require('antd/lib/go-back'); 236 | ``` 237 | 238 | ```js 239 | // Object form 240 | [ 241 | 'treasure', 242 | { 243 | libraryName: 'dt-react-component', 244 | customName: { 245 | GoBack: 'dt-react-component/lib/go-back', 246 | }, 247 | }, 248 | ]; 249 | ``` 250 | 251 | Note: When you use a function, the function parameter is the name converted by styleLibraryDirectory or camel2DashComponentName. When you use an object as a parameter, the key of the object will not undergo a special conversion. The same is true for customStyleName. In addition, you can also choose the reference path: 252 | 253 | ```js 254 | // reference path 255 | [ 256 | 'treasure', 257 | { 258 | libraryName: 'dt-react-component', 259 | customName: { 260 | GoBack: require('path').resolve(__dirname, './customName.js'), 261 | }, 262 | }, 263 | ]; 264 | ``` 265 | 266 | `customName.js` is similar: 267 | 268 | ```js 269 | module.exports = function customName(name) { 270 | return `dt-react-component/lib/${name}`; 271 | }; 272 | ``` 273 | 274 | #### customStyleName 275 | 276 | Same as customName, but used to process the style file path 277 | 278 | #### fileName 279 | 280 | Process links to specific files, such as: 281 | 282 | ```js 283 | // Object form 284 | [ 285 | "treasure", 286 | { 287 | "libraryName": "dt-react-component", 288 | "fileName": "example" 289 | "customName": { 290 | "GoBack": "dt-react-component/lib/go-back", 291 | } 292 | } 293 | ] 294 | ``` 295 | 296 | The result after conversion is as follows: 297 | 298 | ```js 299 | import {ChromeDownload} from'dt-react-component' 300 | 301 | ↓ ↓ ↓ ↓ ↓ ↓ 302 | 303 | import'dt-react-component/lib/chrome-download/exmaple' 304 | ``` 305 | 306 | ## Roadmap 307 | 308 | - Make timely updates with changes in various libraries 309 | - Support more AST type operations 310 | - Dynamic configuration of AST operation function type according to treasure IDE 311 | 312 | ## License 313 | 314 | [MIT](./LICENSE) 315 | -------------------------------------------------------------------------------- /coverage/clover.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /coverage/coverage-final.json: -------------------------------------------------------------------------------- 1 | {"/Users/libowen/Desktop/Code/gitlab.prod.dtstack.cn/dt-insight-front/infrastructure/babel-plugin-treasure/src/Plugin.js": {"path":"/Users/libowen/Desktop/Code/gitlab.prod.dtstack.cn/dt-insight-front/infrastructure/babel-plugin-treasure/src/Plugin.js","statementMap":{"0":{"start":{"line":5,"column":2},"end":{"line":10,"column":3}},"1":{"start":{"line":6,"column":31},"end":{"line":6,"column":56}},"2":{"start":{"line":7,"column":4},"end":{"line":9,"column":35}},"3":{"start":{"line":11,"column":2},"end":{"line":11,"column":26}},"4":{"start":{"line":15,"column":2},"end":{"line":15,"column":35}},"5":{"start":{"line":19,"column":2},"end":{"line":23,"column":3}},"6":{"start":{"line":20,"column":4},"end":{"line":22,"column":47}},"7":{"start":{"line":24,"column":14},"end":{"line":24,"column":52}},"8":{"start":{"line":25,"column":2},"end":{"line":25,"column":72}},"9":{"start":{"line":25,"column":40},"end":{"line":25,"column":70}},"10":{"start":{"line":43,"column":4},"end":{"line":43,"column":35}},"11":{"start":{"line":44,"column":4},"end":{"line":44,"column":95}},"12":{"start":{"line":45,"column":4},"end":{"line":45,"column":32}},"13":{"start":{"line":46,"column":4},"end":{"line":46,"column":55}},"14":{"start":{"line":47,"column":4},"end":{"line":48,"column":86}},"15":{"start":{"line":49,"column":4},"end":{"line":50,"column":88}},"16":{"start":{"line":51,"column":4},"end":{"line":51,"column":54}},"17":{"start":{"line":52,"column":4},"end":{"line":52,"column":64}},"18":{"start":{"line":53,"column":4},"end":{"line":53,"column":69}},"19":{"start":{"line":54,"column":4},"end":{"line":54,"column":35}},"20":{"start":{"line":55,"column":4},"end":{"line":55,"column":23}},"21":{"start":{"line":56,"column":4},"end":{"line":56,"column":54}},"22":{"start":{"line":60,"column":4},"end":{"line":63,"column":5}},"23":{"start":{"line":62,"column":6},"end":{"line":62,"column":38}},"24":{"start":{"line":64,"column":4},"end":{"line":64,"column":38}},"25":{"start":{"line":68,"column":24},"end":{"line":68,"column":50}},"26":{"start":{"line":69,"column":4},"end":{"line":69,"column":48}},"27":{"start":{"line":70,"column":4},"end":{"line":70,"column":50}},"28":{"start":{"line":71,"column":4},"end":{"line":71,"column":54}},"29":{"start":{"line":72,"column":4},"end":{"line":72,"column":35}},"30":{"start":{"line":86,"column":4},"end":{"line":86,"column":84}},"31":{"start":{"line":86,"column":58},"end":{"line":86,"column":82}},"32":{"start":{"line":94,"column":21},"end":{"line":94,"column":25}},"33":{"start":{"line":97,"column":4},"end":{"line":97,"column":22}},"34":{"start":{"line":97,"column":15},"end":{"line":97,"column":22}},"35":{"start":{"line":101,"column":8},"end":{"line":101,"column":12}},"36":{"start":{"line":102,"column":35},"end":{"line":102,"column":39}},"37":{"start":{"line":103,"column":24},"end":{"line":103,"column":50}},"38":{"start":{"line":105,"column":4},"end":{"line":114,"column":5}},"39":{"start":{"line":106,"column":6},"end":{"line":112,"column":9}},"40":{"start":{"line":107,"column":8},"end":{"line":111,"column":9}},"41":{"start":{"line":108,"column":10},"end":{"line":108,"column":70}},"42":{"start":{"line":110,"column":10},"end":{"line":110,"column":58}},"43":{"start":{"line":113,"column":6},"end":{"line":113,"column":43}},"44":{"start":{"line":118,"column":21},"end":{"line":118,"column":25}},"45":{"start":{"line":119,"column":17},"end":{"line":119,"column":47}},"46":{"start":{"line":120,"column":21},"end":{"line":120,"column":32}},"47":{"start":{"line":121,"column":22},"end":{"line":121,"column":26}},"48":{"start":{"line":122,"column":24},"end":{"line":122,"column":50}},"49":{"start":{"line":123,"column":4},"end":{"line":128,"column":5}},"50":{"start":{"line":125,"column":6},"end":{"line":127,"column":7}},"51":{"start":{"line":126,"column":8},"end":{"line":126,"column":88}},"52":{"start":{"line":129,"column":4},"end":{"line":139,"column":7}},"53":{"start":{"line":130,"column":32},"end":{"line":130,"column":35}},"54":{"start":{"line":131,"column":6},"end":{"line":137,"column":7}},"55":{"start":{"line":136,"column":8},"end":{"line":136,"column":84}},"56":{"start":{"line":138,"column":6},"end":{"line":138,"column":17}},"57":{"start":{"line":144,"column":4},"end":{"line":201,"column":5}},"58":{"start":{"line":154,"column":10},"end":{"line":154,"column":14}},"59":{"start":{"line":155,"column":36},"end":{"line":161,"column":20}},"60":{"start":{"line":166,"column":19},"end":{"line":173,"column":7}},"61":{"start":{"line":177,"column":6},"end":{"line":182,"column":66}},"62":{"start":{"line":183,"column":6},"end":{"line":200,"column":7}},"63":{"start":{"line":184,"column":26},"end":{"line":184,"column":78}},"64":{"start":{"line":185,"column":8},"end":{"line":185,"column":49}},"65":{"start":{"line":186,"column":13},"end":{"line":200,"column":7}},"66":{"start":{"line":187,"column":26},"end":{"line":189,"column":9}},"67":{"start":{"line":190,"column":8},"end":{"line":190,"column":49}},"68":{"start":{"line":191,"column":13},"end":{"line":200,"column":7}},"69":{"start":{"line":192,"column":8},"end":{"line":192,"column":50}},"70":{"start":{"line":193,"column":13},"end":{"line":200,"column":7}},"71":{"start":{"line":194,"column":8},"end":{"line":194,"column":54}},"72":{"start":{"line":195,"column":13},"end":{"line":200,"column":7}},"73":{"start":{"line":196,"column":26},"end":{"line":196,"column":43}},"74":{"start":{"line":197,"column":8},"end":{"line":199,"column":9}},"75":{"start":{"line":198,"column":10},"end":{"line":198,"column":46}},"76":{"start":{"line":202,"column":4},"end":{"line":202,"column":58}},"77":{"start":{"line":206,"column":21},"end":{"line":206,"column":25}},"78":{"start":{"line":207,"column":4},"end":{"line":207,"column":62}},"79":{"start":{"line":214,"column":21},"end":{"line":214,"column":25}},"80":{"start":{"line":215,"column":17},"end":{"line":215,"column":47}},"81":{"start":{"line":216,"column":24},"end":{"line":216,"column":50}},"82":{"start":{"line":217,"column":4},"end":{"line":217,"column":36}},"83":{"start":{"line":217,"column":29},"end":{"line":217,"column":36}},"84":{"start":{"line":219,"column":4},"end":{"line":239,"column":5}},"85":{"start":{"line":220,"column":6},"end":{"line":220,"column":81}},"86":{"start":{"line":221,"column":11},"end":{"line":239,"column":5}},"87":{"start":{"line":222,"column":24},"end":{"line":222,"column":63}},"88":{"start":{"line":228,"column":6},"end":{"line":238,"column":7}},"89":{"start":{"line":230,"column":26},"end":{"line":230,"column":65}},"90":{"start":{"line":231,"column":8},"end":{"line":237,"column":9}},"91":{"start":{"line":232,"column":10},"end":{"line":236,"column":12}},"92":{"start":{"line":243,"column":21},"end":{"line":243,"column":25}},"93":{"start":{"line":244,"column":4},"end":{"line":244,"column":67}},"94":{"start":{"line":249,"column":21},"end":{"line":249,"column":25}},"95":{"start":{"line":250,"column":4},"end":{"line":250,"column":88}},"96":{"start":{"line":254,"column":21},"end":{"line":254,"column":25}},"97":{"start":{"line":255,"column":4},"end":{"line":255,"column":65}},"98":{"start":{"line":259,"column":21},"end":{"line":259,"column":25}},"99":{"start":{"line":260,"column":4},"end":{"line":260,"column":61}},"100":{"start":{"line":261,"column":4},"end":{"line":261,"column":75}},"101":{"start":{"line":265,"column":21},"end":{"line":265,"column":25}},"102":{"start":{"line":266,"column":4},"end":{"line":266,"column":70}},"103":{"start":{"line":270,"column":21},"end":{"line":270,"column":25}},"104":{"start":{"line":271,"column":4},"end":{"line":271,"column":61}},"105":{"start":{"line":275,"column":21},"end":{"line":275,"column":25}},"106":{"start":{"line":276,"column":18},"end":{"line":276,"column":57}},"107":{"start":{"line":276,"column":51},"end":{"line":276,"column":56}},"108":{"start":{"line":277,"column":4},"end":{"line":277,"column":67}},"109":{"start":{"line":281,"column":21},"end":{"line":281,"column":25}},"110":{"start":{"line":282,"column":4},"end":{"line":282,"column":76}},"111":{"start":{"line":286,"column":21},"end":{"line":286,"column":25}},"112":{"start":{"line":287,"column":22},"end":{"line":287,"column":26}},"113":{"start":{"line":288,"column":4},"end":{"line":290,"column":5}},"114":{"start":{"line":289,"column":6},"end":{"line":289,"column":75}},"115":{"start":{"line":294,"column":21},"end":{"line":294,"column":25}},"116":{"start":{"line":295,"column":4},"end":{"line":295,"column":68}},"117":{"start":{"line":299,"column":21},"end":{"line":299,"column":25}},"118":{"start":{"line":300,"column":4},"end":{"line":300,"column":70}},"119":{"start":{"line":304,"column":21},"end":{"line":304,"column":25}},"120":{"start":{"line":305,"column":4},"end":{"line":305,"column":69}},"121":{"start":{"line":309,"column":21},"end":{"line":309,"column":25}},"122":{"start":{"line":310,"column":4},"end":{"line":310,"column":61}},"123":{"start":{"line":315,"column":17},"end":{"line":315,"column":47}},"124":{"start":{"line":316,"column":22},"end":{"line":316,"column":26}},"125":{"start":{"line":317,"column":24},"end":{"line":317,"column":50}},"126":{"start":{"line":319,"column":4},"end":{"line":328,"column":7}},"127":{"start":{"line":320,"column":6},"end":{"line":320,"column":50}},"128":{"start":{"line":320,"column":43},"end":{"line":320,"column":50}},"129":{"start":{"line":321,"column":6},"end":{"line":327,"column":7}},"130":{"start":{"line":326,"column":8},"end":{"line":326,"column":98}}},"fnMap":{"0":{"name":"normalizeCustomName","decl":{"start":{"line":4,"column":9},"end":{"line":4,"column":28}},"loc":{"start":{"line":4,"column":47},"end":{"line":12,"column":1}},"line":4},"1":{"name":"winPath","decl":{"start":{"line":14,"column":9},"end":{"line":14,"column":16}},"loc":{"start":{"line":14,"column":23},"end":{"line":16,"column":1}},"line":14},"2":{"name":"transCamel","decl":{"start":{"line":18,"column":9},"end":{"line":18,"column":19}},"loc":{"start":{"line":18,"column":34},"end":{"line":26,"column":1}},"line":18},"3":{"name":"(anonymous_3)","decl":{"start":{"line":25,"column":34},"end":{"line":25,"column":35}},"loc":{"start":{"line":25,"column":40},"end":{"line":25,"column":70}},"line":25},"4":{"name":"(anonymous_4)","decl":{"start":{"line":29,"column":2},"end":{"line":29,"column":3}},"loc":{"start":{"line":42,"column":4},"end":{"line":57,"column":3}},"line":42},"5":{"name":"(anonymous_5)","decl":{"start":{"line":59,"column":2},"end":{"line":59,"column":3}},"loc":{"start":{"line":59,"column":24},"end":{"line":65,"column":3}},"line":59},"6":{"name":"(anonymous_6)","decl":{"start":{"line":67,"column":2},"end":{"line":67,"column":3}},"loc":{"start":{"line":67,"column":25},"end":{"line":83,"column":3}},"line":67},"7":{"name":"(anonymous_7)","decl":{"start":{"line":85,"column":2},"end":{"line":85,"column":3}},"loc":{"start":{"line":85,"column":24},"end":{"line":88,"column":3}},"line":85},"8":{"name":"(anonymous_8)","decl":{"start":{"line":86,"column":53},"end":{"line":86,"column":54}},"loc":{"start":{"line":86,"column":58},"end":{"line":86,"column":82}},"line":86},"9":{"name":"(anonymous_9)","decl":{"start":{"line":93,"column":2},"end":{"line":93,"column":3}},"loc":{"start":{"line":93,"column":33},"end":{"line":115,"column":3}},"line":93},"10":{"name":"(anonymous_10)","decl":{"start":{"line":106,"column":30},"end":{"line":106,"column":31}},"loc":{"start":{"line":106,"column":38},"end":{"line":112,"column":7}},"line":106},"11":{"name":"(anonymous_11)","decl":{"start":{"line":117,"column":2},"end":{"line":117,"column":3}},"loc":{"start":{"line":117,"column":30},"end":{"line":140,"column":3}},"line":117},"12":{"name":"(anonymous_12)","decl":{"start":{"line":129,"column":40},"end":{"line":129,"column":41}},"loc":{"start":{"line":129,"column":47},"end":{"line":139,"column":5}},"line":129},"13":{"name":"(anonymous_13)","decl":{"start":{"line":143,"column":2},"end":{"line":143,"column":3}},"loc":{"start":{"line":143,"column":46},"end":{"line":203,"column":3}},"line":143},"14":{"name":"(anonymous_14)","decl":{"start":{"line":205,"column":2},"end":{"line":205,"column":3}},"loc":{"start":{"line":205,"column":24},"end":{"line":208,"column":3}},"line":205},"15":{"name":"(anonymous_15)","decl":{"start":{"line":213,"column":2},"end":{"line":213,"column":3}},"loc":{"start":{"line":213,"column":32},"end":{"line":240,"column":3}},"line":213},"16":{"name":"(anonymous_16)","decl":{"start":{"line":242,"column":2},"end":{"line":242,"column":3}},"loc":{"start":{"line":242,"column":32},"end":{"line":245,"column":3}},"line":242},"17":{"name":"(anonymous_17)","decl":{"start":{"line":247,"column":2},"end":{"line":247,"column":3}},"loc":{"start":{"line":247,"column":37},"end":{"line":251,"column":3}},"line":247},"18":{"name":"(anonymous_18)","decl":{"start":{"line":253,"column":2},"end":{"line":253,"column":3}},"loc":{"start":{"line":253,"column":31},"end":{"line":256,"column":3}},"line":253},"19":{"name":"(anonymous_19)","decl":{"start":{"line":258,"column":2},"end":{"line":258,"column":3}},"loc":{"start":{"line":258,"column":27},"end":{"line":262,"column":3}},"line":258},"20":{"name":"(anonymous_20)","decl":{"start":{"line":264,"column":2},"end":{"line":264,"column":3}},"loc":{"start":{"line":264,"column":32},"end":{"line":267,"column":3}},"line":264},"21":{"name":"(anonymous_21)","decl":{"start":{"line":269,"column":2},"end":{"line":269,"column":3}},"loc":{"start":{"line":269,"column":34},"end":{"line":272,"column":3}},"line":269},"22":{"name":"(anonymous_22)","decl":{"start":{"line":274,"column":2},"end":{"line":274,"column":3}},"loc":{"start":{"line":274,"column":31},"end":{"line":278,"column":3}},"line":274},"23":{"name":"(anonymous_23)","decl":{"start":{"line":276,"column":37},"end":{"line":276,"column":38}},"loc":{"start":{"line":276,"column":51},"end":{"line":276,"column":56}},"line":276},"24":{"name":"(anonymous_24)","decl":{"start":{"line":280,"column":2},"end":{"line":280,"column":3}},"loc":{"start":{"line":280,"column":29},"end":{"line":283,"column":3}},"line":280},"25":{"name":"(anonymous_25)","decl":{"start":{"line":285,"column":2},"end":{"line":285,"column":3}},"loc":{"start":{"line":285,"column":35},"end":{"line":291,"column":3}},"line":285},"26":{"name":"(anonymous_26)","decl":{"start":{"line":293,"column":2},"end":{"line":293,"column":3}},"loc":{"start":{"line":293,"column":40},"end":{"line":296,"column":3}},"line":293},"27":{"name":"(anonymous_27)","decl":{"start":{"line":298,"column":2},"end":{"line":298,"column":3}},"loc":{"start":{"line":298,"column":33},"end":{"line":301,"column":3}},"line":298},"28":{"name":"(anonymous_28)","decl":{"start":{"line":303,"column":2},"end":{"line":303,"column":3}},"loc":{"start":{"line":303,"column":31},"end":{"line":306,"column":3}},"line":303},"29":{"name":"(anonymous_29)","decl":{"start":{"line":308,"column":2},"end":{"line":308,"column":3}},"loc":{"start":{"line":308,"column":26},"end":{"line":311,"column":3}},"line":308},"30":{"name":"(anonymous_30)","decl":{"start":{"line":314,"column":2},"end":{"line":314,"column":3}},"loc":{"start":{"line":314,"column":51},"end":{"line":329,"column":3}},"line":314},"31":{"name":"(anonymous_31)","decl":{"start":{"line":319,"column":18},"end":{"line":319,"column":19}},"loc":{"start":{"line":319,"column":26},"end":{"line":328,"column":5}},"line":319}},"branchMap":{"0":{"loc":{"start":{"line":5,"column":2},"end":{"line":10,"column":3}},"type":"if","locations":[{"start":{"line":5,"column":2},"end":{"line":10,"column":3}},{"start":{"line":5,"column":2},"end":{"line":10,"column":3}}],"line":5},"1":{"loc":{"start":{"line":7,"column":11},"end":{"line":9,"column":34}},"type":"cond-expr","locations":[{"start":{"line":8,"column":8},"end":{"line":8,"column":26}},{"start":{"line":9,"column":8},"end":{"line":9,"column":34}}],"line":7},"2":{"loc":{"start":{"line":19,"column":2},"end":{"line":23,"column":3}},"type":"if","locations":[{"start":{"line":19,"column":2},"end":{"line":23,"column":3}},{"start":{"line":19,"column":2},"end":{"line":23,"column":3}}],"line":19},"3":{"loc":{"start":{"line":19,"column":6},"end":{"line":19,"column":46}},"type":"binary-expr","locations":[{"start":{"line":19,"column":6},"end":{"line":19,"column":24}},{"start":{"line":19,"column":28},"end":{"line":19,"column":46}}],"line":19},"4":{"loc":{"start":{"line":20,"column":11},"end":{"line":22,"column":46}},"type":"cond-expr","locations":[{"start":{"line":21,"column":8},"end":{"line":21,"column":46}},{"start":{"line":22,"column":8},"end":{"line":22,"column":46}}],"line":20},"5":{"loc":{"start":{"line":41,"column":4},"end":{"line":41,"column":13}},"type":"default-arg","locations":[{"start":{"line":41,"column":12},"end":{"line":41,"column":13}}],"line":41},"6":{"loc":{"start":{"line":44,"column":28},"end":{"line":44,"column":94}},"type":"cond-expr","locations":[{"start":{"line":44,"column":70},"end":{"line":44,"column":75}},{"start":{"line":44,"column":78},"end":{"line":44,"column":94}}],"line":44},"7":{"loc":{"start":{"line":45,"column":17},"end":{"line":45,"column":31}},"type":"binary-expr","locations":[{"start":{"line":45,"column":17},"end":{"line":45,"column":22}},{"start":{"line":45,"column":26},"end":{"line":45,"column":31}}],"line":45},"8":{"loc":{"start":{"line":48,"column":6},"end":{"line":48,"column":85}},"type":"cond-expr","locations":[{"start":{"line":48,"column":55},"end":{"line":48,"column":59}},{"start":{"line":48,"column":62},"end":{"line":48,"column":85}}],"line":48},"9":{"loc":{"start":{"line":50,"column":6},"end":{"line":50,"column":87}},"type":"cond-expr","locations":[{"start":{"line":50,"column":56},"end":{"line":50,"column":60}},{"start":{"line":50,"column":63},"end":{"line":50,"column":87}}],"line":50},"10":{"loc":{"start":{"line":54,"column":20},"end":{"line":54,"column":34}},"type":"binary-expr","locations":[{"start":{"line":54,"column":20},"end":{"line":54,"column":28}},{"start":{"line":54,"column":32},"end":{"line":54,"column":34}}],"line":54},"11":{"loc":{"start":{"line":60,"column":4},"end":{"line":63,"column":5}},"type":"if","locations":[{"start":{"line":60,"column":4},"end":{"line":63,"column":5}},{"start":{"line":60,"column":4},"end":{"line":63,"column":5}}],"line":60},"12":{"loc":{"start":{"line":86,"column":58},"end":{"line":86,"column":82}},"type":"binary-expr","locations":[{"start":{"line":86,"column":58},"end":{"line":86,"column":68}},{"start":{"line":86,"column":72},"end":{"line":86,"column":82}}],"line":86},"13":{"loc":{"start":{"line":97,"column":4},"end":{"line":97,"column":22}},"type":"if","locations":[{"start":{"line":97,"column":4},"end":{"line":97,"column":22}},{"start":{"line":97,"column":4},"end":{"line":97,"column":22}}],"line":97},"14":{"loc":{"start":{"line":105,"column":4},"end":{"line":114,"column":5}},"type":"if","locations":[{"start":{"line":105,"column":4},"end":{"line":114,"column":5}},{"start":{"line":105,"column":4},"end":{"line":114,"column":5}}],"line":105},"15":{"loc":{"start":{"line":107,"column":8},"end":{"line":111,"column":9}},"type":"if","locations":[{"start":{"line":107,"column":8},"end":{"line":111,"column":9}},{"start":{"line":107,"column":8},"end":{"line":111,"column":9}}],"line":107},"16":{"loc":{"start":{"line":119,"column":17},"end":{"line":119,"column":47}},"type":"binary-expr","locations":[{"start":{"line":119,"column":17},"end":{"line":119,"column":32}},{"start":{"line":119,"column":36},"end":{"line":119,"column":47}}],"line":119},"17":{"loc":{"start":{"line":123,"column":4},"end":{"line":128,"column":5}},"type":"if","locations":[{"start":{"line":123,"column":4},"end":{"line":128,"column":5}},{"start":{"line":123,"column":4},"end":{"line":128,"column":5}}],"line":123},"18":{"loc":{"start":{"line":125,"column":6},"end":{"line":127,"column":7}},"type":"if","locations":[{"start":{"line":125,"column":6},"end":{"line":127,"column":7}},{"start":{"line":125,"column":6},"end":{"line":127,"column":7}}],"line":125},"19":{"loc":{"start":{"line":131,"column":6},"end":{"line":137,"column":7}},"type":"if","locations":[{"start":{"line":131,"column":6},"end":{"line":137,"column":7}},{"start":{"line":131,"column":6},"end":{"line":137,"column":7}}],"line":131},"20":{"loc":{"start":{"line":132,"column":8},"end":{"line":134,"column":68}},"type":"binary-expr","locations":[{"start":{"line":132,"column":8},"end":{"line":132,"column":38}},{"start":{"line":133,"column":8},"end":{"line":133,"column":38}},{"start":{"line":134,"column":8},"end":{"line":134,"column":68}}],"line":132},"21":{"loc":{"start":{"line":144,"column":4},"end":{"line":201,"column":5}},"type":"if","locations":[{"start":{"line":144,"column":4},"end":{"line":201,"column":5}},{"start":{"line":144,"column":4},"end":{"line":201,"column":5}}],"line":144},"22":{"loc":{"start":{"line":155,"column":36},"end":{"line":161,"column":20}},"type":"cond-expr","locations":[{"start":{"line":156,"column":10},"end":{"line":156,"column":37}},{"start":{"line":157,"column":10},"end":{"line":161,"column":20}}],"line":155},"23":{"loc":{"start":{"line":157,"column":10},"end":{"line":161,"column":20}},"type":"cond-expr","locations":[{"start":{"line":158,"column":10},"end":{"line":158,"column":37}},{"start":{"line":159,"column":10},"end":{"line":161,"column":20}}],"line":157},"24":{"loc":{"start":{"line":159,"column":10},"end":{"line":161,"column":20}},"type":"cond-expr","locations":[{"start":{"line":160,"column":10},"end":{"line":160,"column":57}},{"start":{"line":161,"column":10},"end":{"line":161,"column":20}}],"line":159},"25":{"loc":{"start":{"line":159,"column":10},"end":{"line":159,"column":84}},"type":"binary-expr","locations":[{"start":{"line":159,"column":10},"end":{"line":159,"column":45}},{"start":{"line":159,"column":49},"end":{"line":159,"column":84}}],"line":159},"26":{"loc":{"start":{"line":167,"column":8},"end":{"line":172,"column":80}},"type":"cond-expr","locations":[{"start":{"line":168,"column":12},"end":{"line":171,"column":53}},{"start":{"line":172,"column":12},"end":{"line":172,"column":80}}],"line":167},"27":{"loc":{"start":{"line":168,"column":12},"end":{"line":171,"column":53}},"type":"cond-expr","locations":[{"start":{"line":169,"column":14},"end":{"line":170,"column":82}},{"start":{"line":171,"column":14},"end":{"line":171,"column":53}}],"line":168},"28":{"loc":{"start":{"line":169,"column":14},"end":{"line":170,"column":82}},"type":"binary-expr","locations":[{"start":{"line":169,"column":14},"end":{"line":169,"column":36}},{"start":{"line":170,"column":14},"end":{"line":170,"column":82}}],"line":169},"29":{"loc":{"start":{"line":178,"column":8},"end":{"line":182,"column":65}},"type":"cond-expr","locations":[{"start":{"line":181,"column":12},"end":{"line":181,"column":49}},{"start":{"line":182,"column":12},"end":{"line":182,"column":65}}],"line":178},"30":{"loc":{"start":{"line":178,"column":8},"end":{"line":180,"column":62}},"type":"binary-expr","locations":[{"start":{"line":178,"column":8},"end":{"line":178,"column":42}},{"start":{"line":179,"column":9},"end":{"line":179,"column":48}},{"start":{"line":180,"column":10},"end":{"line":180,"column":61}}],"line":178},"31":{"loc":{"start":{"line":183,"column":6},"end":{"line":200,"column":7}},"type":"if","locations":[{"start":{"line":183,"column":6},"end":{"line":200,"column":7}},{"start":{"line":183,"column":6},"end":{"line":200,"column":7}}],"line":183},"32":{"loc":{"start":{"line":186,"column":13},"end":{"line":200,"column":7}},"type":"if","locations":[{"start":{"line":186,"column":13},"end":{"line":200,"column":7}},{"start":{"line":186,"column":13},"end":{"line":200,"column":7}}],"line":186},"33":{"loc":{"start":{"line":191,"column":13},"end":{"line":200,"column":7}},"type":"if","locations":[{"start":{"line":191,"column":13},"end":{"line":200,"column":7}},{"start":{"line":191,"column":13},"end":{"line":200,"column":7}}],"line":191},"34":{"loc":{"start":{"line":193,"column":13},"end":{"line":200,"column":7}},"type":"if","locations":[{"start":{"line":193,"column":13},"end":{"line":200,"column":7}},{"start":{"line":193,"column":13},"end":{"line":200,"column":7}}],"line":193},"35":{"loc":{"start":{"line":195,"column":13},"end":{"line":200,"column":7}},"type":"if","locations":[{"start":{"line":195,"column":13},"end":{"line":200,"column":7}},{"start":{"line":195,"column":13},"end":{"line":200,"column":7}}],"line":195},"36":{"loc":{"start":{"line":197,"column":8},"end":{"line":199,"column":9}},"type":"if","locations":[{"start":{"line":197,"column":8},"end":{"line":199,"column":9}},{"start":{"line":197,"column":8},"end":{"line":199,"column":9}}],"line":197},"37":{"loc":{"start":{"line":215,"column":17},"end":{"line":215,"column":47}},"type":"binary-expr","locations":[{"start":{"line":215,"column":17},"end":{"line":215,"column":32}},{"start":{"line":215,"column":36},"end":{"line":215,"column":47}}],"line":215},"38":{"loc":{"start":{"line":217,"column":4},"end":{"line":217,"column":36}},"type":"if","locations":[{"start":{"line":217,"column":4},"end":{"line":217,"column":36}},{"start":{"line":217,"column":4},"end":{"line":217,"column":36}}],"line":217},"39":{"loc":{"start":{"line":219,"column":4},"end":{"line":239,"column":5}},"type":"if","locations":[{"start":{"line":219,"column":4},"end":{"line":239,"column":5}},{"start":{"line":219,"column":4},"end":{"line":239,"column":5}}],"line":219},"40":{"loc":{"start":{"line":221,"column":11},"end":{"line":239,"column":5}},"type":"if","locations":[{"start":{"line":221,"column":11},"end":{"line":239,"column":5}},{"start":{"line":221,"column":11},"end":{"line":239,"column":5}}],"line":221},"41":{"loc":{"start":{"line":221,"column":15},"end":{"line":221,"column":97}},"type":"binary-expr","locations":[{"start":{"line":221,"column":15},"end":{"line":221,"column":54}},{"start":{"line":221,"column":58},"end":{"line":221,"column":97}}],"line":221},"42":{"loc":{"start":{"line":228,"column":6},"end":{"line":238,"column":7}},"type":"if","locations":[{"start":{"line":228,"column":6},"end":{"line":238,"column":7}},{"start":{"line":228,"column":6},"end":{"line":238,"column":7}}],"line":228},"43":{"loc":{"start":{"line":231,"column":8},"end":{"line":237,"column":9}},"type":"if","locations":[{"start":{"line":231,"column":8},"end":{"line":237,"column":9}},{"start":{"line":231,"column":8},"end":{"line":237,"column":9}}],"line":231},"44":{"loc":{"start":{"line":288,"column":4},"end":{"line":290,"column":5}},"type":"if","locations":[{"start":{"line":288,"column":4},"end":{"line":290,"column":5}},{"start":{"line":288,"column":4},"end":{"line":290,"column":5}}],"line":288},"45":{"loc":{"start":{"line":315,"column":17},"end":{"line":315,"column":47}},"type":"binary-expr","locations":[{"start":{"line":315,"column":17},"end":{"line":315,"column":32}},{"start":{"line":315,"column":36},"end":{"line":315,"column":47}}],"line":315},"46":{"loc":{"start":{"line":320,"column":6},"end":{"line":320,"column":50}},"type":"if","locations":[{"start":{"line":320,"column":6},"end":{"line":320,"column":50}},{"start":{"line":320,"column":6},"end":{"line":320,"column":50}}],"line":320},"47":{"loc":{"start":{"line":321,"column":6},"end":{"line":327,"column":7}},"type":"if","locations":[{"start":{"line":321,"column":6},"end":{"line":327,"column":7}},{"start":{"line":321,"column":6},"end":{"line":327,"column":7}}],"line":321},"48":{"loc":{"start":{"line":322,"column":8},"end":{"line":323,"column":76}},"type":"binary-expr","locations":[{"start":{"line":322,"column":8},"end":{"line":322,"column":46}},{"start":{"line":323,"column":8},"end":{"line":323,"column":76}}],"line":322}},"s":{"0":84,"1":1,"2":1,"3":83,"4":46,"5":43,"6":3,"7":40,"8":40,"9":3,"10":42,"11":42,"12":42,"13":42,"14":42,"15":42,"16":42,"17":42,"18":42,"19":42,"20":42,"21":42,"22":952,"23":42,"24":952,"25":42,"26":42,"27":42,"28":42,"29":42,"30":42,"31":40,"32":111,"33":111,"34":0,"35":111,"36":111,"37":111,"38":111,"39":40,"40":44,"41":43,"42":1,"43":40,"44":219,"45":219,"46":219,"47":219,"48":219,"49":219,"50":132,"51":8,"52":219,"53":321,"54":321,"55":17,"56":304,"57":63,"58":44,"59":44,"60":44,"61":44,"62":44,"63":1,"64":1,"65":43,"66":1,"67":1,"68":42,"69":4,"70":38,"71":2,"72":36,"73":3,"74":3,"75":2,"76":63,"77":57,"78":57,"79":210,"80":210,"81":210,"82":210,"83":2,"84":208,"85":1,"86":207,"87":8,"88":8,"89":4,"90":4,"91":4,"92":1,"93":1,"94":39,"95":39,"96":56,"97":56,"98":16,"99":16,"100":16,"101":6,"102":6,"103":84,"104":84,"105":3,"106":3,"107":3,"108":3,"109":1,"110":1,"111":57,"112":57,"113":57,"114":5,"115":1,"116":1,"117":40,"118":40,"119":1,"120":1,"121":2,"122":2,"123":328,"124":328,"125":328,"126":328,"127":469,"128":296,"129":173,"130":33},"f":{"0":84,"1":46,"2":43,"3":3,"4":42,"5":952,"6":42,"7":42,"8":40,"9":111,"10":44,"11":219,"12":321,"13":63,"14":57,"15":210,"16":1,"17":39,"18":56,"19":16,"20":6,"21":84,"22":3,"23":3,"24":1,"25":57,"26":1,"27":40,"28":1,"29":2,"30":328,"31":469},"b":{"0":[1,83],"1":[0,1],"2":[3,40],"3":[43,42],"4":[1,2],"5":[42],"6":[41,1],"7":[42,36],"8":[39,3],"9":[40,2],"10":[42,41],"11":[42,910],"12":[40,40],"13":[0,111],"14":[40,71],"15":[43,1],"16":[219,0],"17":[132,87],"18":[8,124],"19":[17,304],"20":[321,18,18],"21":[44,19],"22":[1,43],"23":[39,4],"24":[3,1],"25":[4,3],"26":[6,38],"27":[2,4],"28":[2,1],"29":[3,41],"30":[44,42,1],"31":[1,43],"32":[1,42],"33":[4,38],"34":[2,36],"35":[3,33],"36":[2,1],"37":[210,0],"38":[2,208],"39":[1,207],"40":[8,199],"41":[207,8],"42":[4,4],"43":[4,0],"44":[5,52],"45":[328,0],"46":[296,173],"47":[33,140],"48":[173,43]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"091e5cf83419d59b2170d033db452bdea1d9f539"} 2 | ,"/Users/libowen/Desktop/Code/gitlab.prod.dtstack.cn/dt-insight-front/infrastructure/babel-plugin-treasure/src/index.js": {"path":"/Users/libowen/Desktop/Code/gitlab.prod.dtstack.cn/dt-insight-front/infrastructure/babel-plugin-treasure/src/index.js","statementMap":{"0":{"start":{"line":5,"column":16},"end":{"line":5,"column":20}},"1":{"start":{"line":11,"column":2},"end":{"line":13,"column":4}},"2":{"start":{"line":12,"column":4},"end":{"line":12,"column":19}},"3":{"start":{"line":20,"column":4},"end":{"line":24,"column":5}},"4":{"start":{"line":21,"column":6},"end":{"line":23,"column":7}},"5":{"start":{"line":22,"column":8},"end":{"line":22,"column":57}},"6":{"start":{"line":31,"column":18},"end":{"line":93,"column":3}},"7":{"start":{"line":33,"column":6},"end":{"line":86,"column":7}},"8":{"start":{"line":34,"column":8},"end":{"line":85,"column":9}},"9":{"start":{"line":35,"column":10},"end":{"line":67,"column":12}},"10":{"start":{"line":51,"column":14},"end":{"line":51,"column":68}},"11":{"start":{"line":52,"column":14},"end":{"line":65,"column":16}},"12":{"start":{"line":69,"column":10},"end":{"line":69,"column":69}},"13":{"start":{"line":70,"column":10},"end":{"line":84,"column":12}},"14":{"start":{"line":87,"column":6},"end":{"line":87,"column":53}},"15":{"start":{"line":91,"column":6},"end":{"line":91,"column":52}},"16":{"start":{"line":95,"column":18},"end":{"line":113,"column":3}},"17":{"start":{"line":115,"column":14},"end":{"line":117,"column":3}},"18":{"start":{"line":119,"column":2},"end":{"line":124,"column":3}},"19":{"start":{"line":120,"column":4},"end":{"line":123,"column":6}},"20":{"start":{"line":122,"column":6},"end":{"line":122,"column":52}},"21":{"start":{"line":126,"column":2},"end":{"line":126,"column":13}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":15},"end":{"line":4,"column":16}},"loc":{"start":{"line":4,"column":35},"end":{"line":127,"column":1}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":11,"column":38},"end":{"line":11,"column":39}},"loc":{"start":{"line":11,"column":44},"end":{"line":13,"column":3}},"line":11},"2":{"name":"applyInstance","decl":{"start":{"line":18,"column":11},"end":{"line":18,"column":24}},"loc":{"start":{"line":18,"column":48},"end":{"line":25,"column":3}},"line":18},"3":{"name":"(anonymous_3)","decl":{"start":{"line":32,"column":4},"end":{"line":32,"column":5}},"loc":{"start":{"line":32,"column":31},"end":{"line":88,"column":5}},"line":32},"4":{"name":"(anonymous_4)","decl":{"start":{"line":36,"column":12},"end":{"line":36,"column":13}},"loc":{"start":{"line":50,"column":17},"end":{"line":66,"column":13}},"line":50},"5":{"name":"(anonymous_5)","decl":{"start":{"line":89,"column":4},"end":{"line":89,"column":5}},"loc":{"start":{"line":89,"column":11},"end":{"line":92,"column":5}},"line":89},"6":{"name":"(anonymous_6)","decl":{"start":{"line":120,"column":26},"end":{"line":120,"column":27}},"loc":{"start":{"line":120,"column":37},"end":{"line":123,"column":5}},"line":120}},"branchMap":{"0":{"loc":{"start":{"line":21,"column":6},"end":{"line":23,"column":7}},"type":"if","locations":[{"start":{"line":21,"column":6},"end":{"line":23,"column":7}},{"start":{"line":21,"column":6},"end":{"line":23,"column":7}}],"line":21},"1":{"loc":{"start":{"line":32,"column":18},"end":{"line":32,"column":27}},"type":"default-arg","locations":[{"start":{"line":32,"column":25},"end":{"line":32,"column":27}}],"line":32},"2":{"loc":{"start":{"line":33,"column":6},"end":{"line":86,"column":7}},"type":"if","locations":[{"start":{"line":33,"column":6},"end":{"line":86,"column":7}},{"start":{"line":33,"column":6},"end":{"line":86,"column":7}}],"line":33},"3":{"loc":{"start":{"line":34,"column":8},"end":{"line":85,"column":9}},"type":"if","locations":[{"start":{"line":34,"column":8},"end":{"line":85,"column":9}},{"start":{"line":34,"column":8},"end":{"line":85,"column":9}}],"line":34}},"s":{"0":42,"1":42,"2":40,"3":988,"4":988,"5":988,"6":42,"7":42,"8":42,"9":0,"10":0,"11":0,"12":42,"13":42,"14":42,"15":42,"16":42,"17":42,"18":42,"19":714,"20":904,"21":42},"f":{"0":42,"1":40,"2":988,"3":42,"4":0,"5":42,"6":904},"b":{"0":[988,0],"1":[0],"2":[42,0],"3":[0,42]},"_coverageSchema":"43e27e138ebf9cfc5966b082cf9a028302ed4184","hash":"b465d3625ffe4fda36b54b7ab0652a345b82d0a3"} 3 | } 4 | -------------------------------------------------------------------------------- /coverage/lcov-report/base.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin:0; padding: 0; 3 | height: 100%; 4 | } 5 | body { 6 | font-family: Helvetica Neue, Helvetica, Arial; 7 | font-size: 14px; 8 | color:#333; 9 | } 10 | .small { font-size: 12px; } 11 | *, *:after, *:before { 12 | -webkit-box-sizing:border-box; 13 | -moz-box-sizing:border-box; 14 | box-sizing:border-box; 15 | } 16 | h1 { font-size: 20px; margin: 0;} 17 | h2 { font-size: 14px; } 18 | pre { 19 | font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; 20 | margin: 0; 21 | padding: 0; 22 | -moz-tab-size: 2; 23 | -o-tab-size: 2; 24 | tab-size: 2; 25 | } 26 | a { color:#0074D9; text-decoration:none; } 27 | a:hover { text-decoration:underline; } 28 | .strong { font-weight: bold; } 29 | .space-top1 { padding: 10px 0 0 0; } 30 | .pad2y { padding: 20px 0; } 31 | .pad1y { padding: 10px 0; } 32 | .pad2x { padding: 0 20px; } 33 | .pad2 { padding: 20px; } 34 | .pad1 { padding: 10px; } 35 | .space-left2 { padding-left:55px; } 36 | .space-right2 { padding-right:20px; } 37 | .center { text-align:center; } 38 | .clearfix { display:block; } 39 | .clearfix:after { 40 | content:''; 41 | display:block; 42 | height:0; 43 | clear:both; 44 | visibility:hidden; 45 | } 46 | .fl { float: left; } 47 | @media only screen and (max-width:640px) { 48 | .col3 { width:100%; max-width:100%; } 49 | .hide-mobile { display:none!important; } 50 | } 51 | 52 | .quiet { 53 | color: #7f7f7f; 54 | color: rgba(0,0,0,0.5); 55 | } 56 | .quiet a { opacity: 0.7; } 57 | 58 | .fraction { 59 | font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; 60 | font-size: 10px; 61 | color: #555; 62 | background: #E8E8E8; 63 | padding: 4px 5px; 64 | border-radius: 3px; 65 | vertical-align: middle; 66 | } 67 | 68 | div.path a:link, div.path a:visited { color: #333; } 69 | table.coverage { 70 | border-collapse: collapse; 71 | margin: 10px 0 0 0; 72 | padding: 0; 73 | } 74 | 75 | table.coverage td { 76 | margin: 0; 77 | padding: 0; 78 | vertical-align: top; 79 | } 80 | table.coverage td.line-count { 81 | text-align: right; 82 | padding: 0 5px 0 20px; 83 | } 84 | table.coverage td.line-coverage { 85 | text-align: right; 86 | padding-right: 10px; 87 | min-width:20px; 88 | } 89 | 90 | table.coverage td span.cline-any { 91 | display: inline-block; 92 | padding: 0 5px; 93 | width: 100%; 94 | } 95 | .missing-if-branch { 96 | display: inline-block; 97 | margin-right: 5px; 98 | border-radius: 3px; 99 | position: relative; 100 | padding: 0 4px; 101 | background: #333; 102 | color: yellow; 103 | } 104 | 105 | .skip-if-branch { 106 | display: none; 107 | margin-right: 10px; 108 | position: relative; 109 | padding: 0 4px; 110 | background: #ccc; 111 | color: white; 112 | } 113 | .missing-if-branch .typ, .skip-if-branch .typ { 114 | color: inherit !important; 115 | } 116 | .coverage-summary { 117 | border-collapse: collapse; 118 | width: 100%; 119 | } 120 | .coverage-summary tr { border-bottom: 1px solid #bbb; } 121 | .keyline-all { border: 1px solid #ddd; } 122 | .coverage-summary td, .coverage-summary th { padding: 10px; } 123 | .coverage-summary tbody { border: 1px solid #bbb; } 124 | .coverage-summary td { border-right: 1px solid #bbb; } 125 | .coverage-summary td:last-child { border-right: none; } 126 | .coverage-summary th { 127 | text-align: left; 128 | font-weight: normal; 129 | white-space: nowrap; 130 | } 131 | .coverage-summary th.file { border-right: none !important; } 132 | .coverage-summary th.pct { } 133 | .coverage-summary th.pic, 134 | .coverage-summary th.abs, 135 | .coverage-summary td.pct, 136 | .coverage-summary td.abs { text-align: right; } 137 | .coverage-summary td.file { white-space: nowrap; } 138 | .coverage-summary td.pic { min-width: 120px !important; } 139 | .coverage-summary tfoot td { } 140 | 141 | .coverage-summary .sorter { 142 | height: 10px; 143 | width: 7px; 144 | display: inline-block; 145 | margin-left: 0.5em; 146 | background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; 147 | } 148 | .coverage-summary .sorted .sorter { 149 | background-position: 0 -20px; 150 | } 151 | .coverage-summary .sorted-desc .sorter { 152 | background-position: 0 -10px; 153 | } 154 | .status-line { height: 10px; } 155 | /* yellow */ 156 | .cbranch-no { background: yellow !important; color: #111; } 157 | /* dark red */ 158 | .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } 159 | .low .chart { border:1px solid #C21F39 } 160 | .highlighted, 161 | .highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{ 162 | background: #C21F39 !important; 163 | } 164 | /* medium red */ 165 | .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } 166 | /* light red */ 167 | .low, .cline-no { background:#FCE1E5 } 168 | /* light green */ 169 | .high, .cline-yes { background:rgb(230,245,208) } 170 | /* medium green */ 171 | .cstat-yes { background:rgb(161,215,106) } 172 | /* dark green */ 173 | .status-line.high, .high .cover-fill { background:rgb(77,146,33) } 174 | .high .chart { border:1px solid rgb(77,146,33) } 175 | /* dark yellow (gold) */ 176 | .status-line.medium, .medium .cover-fill { background: #f9cd0b; } 177 | .medium .chart { border:1px solid #f9cd0b; } 178 | /* light yellow */ 179 | .medium { background: #fff4c2; } 180 | 181 | .cstat-skip { background: #ddd; color: #111; } 182 | .fstat-skip { background: #ddd; color: #111 !important; } 183 | .cbranch-skip { background: #ddd !important; color: #111; } 184 | 185 | span.cline-neutral { background: #eaeaea; } 186 | 187 | .coverage-summary td.empty { 188 | opacity: .5; 189 | padding-top: 4px; 190 | padding-bottom: 4px; 191 | line-height: 1; 192 | color: #888; 193 | } 194 | 195 | .cover-fill, .cover-empty { 196 | display:inline-block; 197 | height: 12px; 198 | } 199 | .chart { 200 | line-height: 0; 201 | } 202 | .cover-empty { 203 | background: white; 204 | } 205 | .cover-full { 206 | border-right: none !important; 207 | } 208 | pre.prettyprint { 209 | border: none !important; 210 | padding: 0 !important; 211 | margin: 0 !important; 212 | } 213 | .com { color: #999 !important; } 214 | .ignore-none { color: #999; font-weight: normal; } 215 | 216 | .wrapper { 217 | min-height: 100%; 218 | height: auto !important; 219 | height: 100%; 220 | margin: 0 auto -48px; 221 | } 222 | .footer, .push { 223 | height: 48px; 224 | } 225 | -------------------------------------------------------------------------------- /coverage/lcov-report/block-navigation.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | var jumpToCode = (function init() { 3 | // Classes of code we would like to highlight in the file view 4 | var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no']; 5 | 6 | // Elements to highlight in the file listing view 7 | var fileListingElements = ['td.pct.low']; 8 | 9 | // We don't want to select elements that are direct descendants of another match 10 | var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > ` 11 | 12 | // Selecter that finds elements on the page to which we can jump 13 | var selector = 14 | fileListingElements.join(', ') + 15 | ', ' + 16 | notSelector + 17 | missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b` 18 | 19 | // The NodeList of matching elements 20 | var missingCoverageElements = document.querySelectorAll(selector); 21 | 22 | var currentIndex; 23 | 24 | function toggleClass(index) { 25 | missingCoverageElements 26 | .item(currentIndex) 27 | .classList.remove('highlighted'); 28 | missingCoverageElements.item(index).classList.add('highlighted'); 29 | } 30 | 31 | function makeCurrent(index) { 32 | toggleClass(index); 33 | currentIndex = index; 34 | missingCoverageElements.item(index).scrollIntoView({ 35 | behavior: 'smooth', 36 | block: 'center', 37 | inline: 'center' 38 | }); 39 | } 40 | 41 | function goToPrevious() { 42 | var nextIndex = 0; 43 | if (typeof currentIndex !== 'number' || currentIndex === 0) { 44 | nextIndex = missingCoverageElements.length - 1; 45 | } else if (missingCoverageElements.length > 1) { 46 | nextIndex = currentIndex - 1; 47 | } 48 | 49 | makeCurrent(nextIndex); 50 | } 51 | 52 | function goToNext() { 53 | var nextIndex = 0; 54 | 55 | if ( 56 | typeof currentIndex === 'number' && 57 | currentIndex < missingCoverageElements.length - 1 58 | ) { 59 | nextIndex = currentIndex + 1; 60 | } 61 | 62 | makeCurrent(nextIndex); 63 | } 64 | 65 | return function jump(event) { 66 | switch (event.which) { 67 | case 78: // n 68 | case 74: // j 69 | goToNext(); 70 | break; 71 | case 66: // b 72 | case 75: // k 73 | case 80: // p 74 | goToPrevious(); 75 | break; 76 | } 77 | }; 78 | })(); 79 | window.addEventListener('keydown', jumpToCode); 80 | -------------------------------------------------------------------------------- /coverage/lcov-report/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Code coverage report for All files 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 |
20 |
21 |

All files

22 |
23 | 24 |
25 | 97.39% 26 | Statements 27 | 149/153 28 |
29 | 30 | 31 |
32 | 90.57% 33 | Branches 34 | 96/106 35 |
36 | 37 | 38 |
39 | 97.44% 40 | Functions 41 | 38/39 42 |
43 | 44 | 45 |
46 | 97.96% 47 | Lines 48 | 144/147 49 |
50 | 51 | 52 |
53 |

54 | Press n or j to go to the next uncovered block, b, p or k for the previous block. 55 |

56 |
57 |
58 |
59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
FileStatementsBranchesFunctionsLines
Plugin.js 77 |
78 |
99.24%130/13193.94%93/99100%32/32100%125/125
index.js 92 |
93 |
86.36%19/2242.86%3/785.71%6/786.36%19/22
106 |
107 |
108 |
109 | 114 | 115 | 116 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /coverage/lcov-report/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Code coverage report for index.js 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 |
20 |
21 |

All files index.js

22 |
23 | 24 |
25 | 86.36% 26 | Statements 27 | 19/22 28 |
29 | 30 | 31 |
32 | 42.86% 33 | Branches 34 | 3/7 35 |
36 | 37 | 38 |
39 | 85.71% 40 | Functions 41 | 6/7 42 |
43 | 44 | 45 |
46 | 86.36% 47 | Lines 48 | 19/22 49 |
50 | 51 | 52 |
53 |

54 | Press n or j to go to the next uncovered block, b, p or k for the previous block. 55 |

56 |
57 |
58 |

 59 | 
1 60 | 2 61 | 3 62 | 4 63 | 5 64 | 6 65 | 7 66 | 8 67 | 9 68 | 10 69 | 11 70 | 12 71 | 13 72 | 14 73 | 15 74 | 16 75 | 17 76 | 18 77 | 19 78 | 20 79 | 21 80 | 22 81 | 23 82 | 24 83 | 25 84 | 26 85 | 27 86 | 28 87 | 29 88 | 30 89 | 31 90 | 32 91 | 33 92 | 34 93 | 35 94 | 36 95 | 37 96 | 38 97 | 39 98 | 40 99 | 41 100 | 42 101 | 43 102 | 44 103 | 45 104 | 46 105 | 47 106 | 48 107 | 49 108 | 50 109 | 51 110 | 52 111 | 53 112 | 54 113 | 55 114 | 56 115 | 57 116 | 58 117 | 59 118 | 60 119 | 61 120 | 62 121 | 63 122 | 64 123 | 65 124 | 66 125 | 67 126 | 68 127 | 69 128 | 70 129 | 71 130 | 72 131 | 73 132 | 74 133 | 75 134 | 76 135 | 77 136 | 78 137 | 79 138 | 80 139 | 81 140 | 82 141 | 83 142 | 84 143 | 85 144 | 86 145 | 87 146 | 88 147 | 89 148 | 90 149 | 91 150 | 92 151 | 93 152 | 94 153 | 95 154 | 96 155 | 97 156 | 98 157 | 99 158 | 100 159 | 101 160 | 102 161 | 103 162 | 104 163 | 105 164 | 106 165 | 107 166 | 108 167 | 109 168 | 110 169 | 111 170 | 112 171 | 113 172 | 114 173 | 115 174 | 116 175 | 117 176 | 118 177 | 119 178 | 120 179 | 121 180 | 122 181 | 123 182 | 124 183 | 125 184 | 126 185 | 127 186 | 128  187 |   188 |   189 |   190 | 42x 191 |   192 |   193 |   194 |   195 |   196 | 42x 197 | 40x 198 |   199 |   200 |   201 |   202 |   203 |   204 |   205 | 988x 206 | 988x 207 | 988x 208 |   209 |   210 |   211 |   212 |   213 |   214 |   215 |   216 | 42x 217 |   218 | 42x 219 | 42x 220 |   221 |   222 |   223 |   224 |   225 |   226 |   227 |   228 |   229 |   230 |   231 |   232 |   233 |   234 |   235 |   236 |   237 |   238 |   239 |   240 |   241 |   242 |   243 |   244 |   245 |   246 |   247 |   248 |   249 |   250 |   251 |   252 |   253 |   254 | 42x 255 | 42x 256 |   257 |   258 |   259 |   260 |   261 |   262 |   263 |   264 |   265 |   266 |   267 |   268 |   269 |   270 |   271 |   272 | 42x 273 |   274 |   275 |   276 | 42x 277 |   278 |   279 |   280 | 42x 281 |   282 |   283 |   284 |   285 |   286 |   287 |   288 |   289 |   290 |   291 |   292 |   293 |   294 |   295 |   296 |   297 |   298 |   299 |   300 | 42x 301 |   302 |   303 |   304 | 42x 305 | 714x 306 |   307 | 904x 308 |   309 |   310 |   311 | 42x 312 |   313 |  
import assert from 'assert';
314 | import Plugin from './Plugin';
315 |  
316 | export default function({ types }) {
317 |   let plugins = null;
318 |  
319 |   /**
320 |    * 用于单测初始化插件
321 |    */
322 |   // eslint-disable-next-line no-underscore-dangle
323 |   global.__clearBabelTreasurePlugin = () => {
324 |     plugins = null;
325 |   };
326 |  
327 |   /**
328 |    * 从类中继承方法与参数
329 |    */
330 |   function applyInstance(method, args, context) {
331 |     // eslint-disable-next-line no-restricted-syntax
332 |     for (const plugin of plugins) {
333 |       Eif (plugin[method]) {
334 |         plugin[method].apply(plugin, [...args, context]);
335 |       }
336 |     }
337 |   }
338 |  
339 |   /**
340 |    * Program入口初始化数据结构
341 |    * 出口删除处理完毕的标记节点
342 |    */
343 |   const Program = {
344 |     enter(path, { opts = {} }) {
345 |       Eif (!plugins) {
346 |         Iif (Array.isArray(opts)) {
347 |           plugins = opts.map(
348 |             (
349 |               {
350 |                 libraryName,
351 |                 libraryDirectory,
352 |                 style,
353 |                 styleLibraryDirectory,
354 |                 customStyleName,
355 |                 camel2DashComponentName,
356 |                 camel2UnderlineComponentName,
357 |                 fileName,
358 |                 customName,
359 |                 transformToDefaultImport,
360 |               },
361 |               index,
362 |             ) => {
363 |               assert(libraryName, 'libraryName should be provided');
364 |               return new Plugin(
365 |                 libraryName,
366 |                 libraryDirectory,
367 |                 style,
368 |                 styleLibraryDirectory,
369 |                 customStyleName,
370 |                 camel2DashComponentName,
371 |                 camel2UnderlineComponentName,
372 |                 fileName,
373 |                 customName,
374 |                 transformToDefaultImport,
375 |                 types,
376 |                 index,
377 |               );
378 |             },
379 |           );
380 |         } else {
381 |           assert(opts.libraryName, 'libraryName should be provided');
382 |           plugins = [
383 |             new Plugin(
384 |               opts.libraryName,
385 |               opts.libraryDirectory,
386 |               opts.style,
387 |               opts.styleLibraryDirectory,
388 |               opts.customStyleName,
389 |               opts.camel2DashComponentName,
390 |               opts.camel2UnderlineComponentName,
391 |               opts.fileName,
392 |               opts.customName,
393 |               opts.transformToDefaultImport,
394 |               types,
395 |             ),
396 |           ];
397 |         }
398 |       }
399 |       applyInstance('ProgramEnter', arguments, this); // eslint-disable-line
400 |     },
401 |     exit() {
402 |       // eslint-disable-next-line prefer-rest-params
403 |       applyInstance('ProgramExit', arguments, this);
404 |     },
405 |   };
406 |  
407 |   const methods = [
408 |     'ImportDeclaration',
409 |     'CallExpression',
410 |     'MemberExpression',
411 |     'ClassDeclaration',
412 |     'Property',
413 |     'ConditionalExpression',
414 |     'ReturnStatement',
415 |     'IfStatement',
416 |     'BinaryExpression',
417 |     'VariableDeclarator',
418 |     'ArrayExpression',
419 |     'NewExpression',
420 |     'ExportDefaultDeclaration',
421 |     'ExpressionStatement',
422 |     'LogicalExpression',
423 |     'SwitchStatement',
424 |     'SwitchCase',
425 |   ];
426 |  
427 |   const ret = {
428 |     visitor: { Program }, // 对整棵AST树的入口进行初始化操作
429 |   };
430 |   // eslint-disable-next-line no-restricted-syntax
431 |   for (const method of methods) {
432 |     ret.visitor[method] = function() {
433 |       // eslint-disable-next-line prefer-rest-params
434 |       applyInstance(method, arguments, ret.visitor);
435 |     };
436 |   }
437 |  
438 |   return ret;
439 | }
440 |  
441 | 442 |
443 |
444 | 449 | 450 | 451 | 456 | 457 | 458 | 459 | 460 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /coverage/lcov-report/sort-arrow-sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DTStack/babel-plugin-treasure/29c007ca702eebec57b33d4dde260b9d545340cb/coverage/lcov-report/sort-arrow-sprite.png -------------------------------------------------------------------------------- /coverage/lcov-report/sorter.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | var addSorting = (function() { 3 | 'use strict'; 4 | var cols, 5 | currentSort = { 6 | index: 0, 7 | desc: false 8 | }; 9 | 10 | // returns the summary table element 11 | function getTable() { 12 | return document.querySelector('.coverage-summary'); 13 | } 14 | // returns the thead element of the summary table 15 | function getTableHeader() { 16 | return getTable().querySelector('thead tr'); 17 | } 18 | // returns the tbody element of the summary table 19 | function getTableBody() { 20 | return getTable().querySelector('tbody'); 21 | } 22 | // returns the th element for nth column 23 | function getNthColumn(n) { 24 | return getTableHeader().querySelectorAll('th')[n]; 25 | } 26 | 27 | // loads all columns 28 | function loadColumns() { 29 | var colNodes = getTableHeader().querySelectorAll('th'), 30 | colNode, 31 | cols = [], 32 | col, 33 | i; 34 | 35 | for (i = 0; i < colNodes.length; i += 1) { 36 | colNode = colNodes[i]; 37 | col = { 38 | key: colNode.getAttribute('data-col'), 39 | sortable: !colNode.getAttribute('data-nosort'), 40 | type: colNode.getAttribute('data-type') || 'string' 41 | }; 42 | cols.push(col); 43 | if (col.sortable) { 44 | col.defaultDescSort = col.type === 'number'; 45 | colNode.innerHTML = 46 | colNode.innerHTML + ''; 47 | } 48 | } 49 | return cols; 50 | } 51 | // attaches a data attribute to every tr element with an object 52 | // of data values keyed by column name 53 | function loadRowData(tableRow) { 54 | var tableCols = tableRow.querySelectorAll('td'), 55 | colNode, 56 | col, 57 | data = {}, 58 | i, 59 | val; 60 | for (i = 0; i < tableCols.length; i += 1) { 61 | colNode = tableCols[i]; 62 | col = cols[i]; 63 | val = colNode.getAttribute('data-value'); 64 | if (col.type === 'number') { 65 | val = Number(val); 66 | } 67 | data[col.key] = val; 68 | } 69 | return data; 70 | } 71 | // loads all row data 72 | function loadData() { 73 | var rows = getTableBody().querySelectorAll('tr'), 74 | i; 75 | 76 | for (i = 0; i < rows.length; i += 1) { 77 | rows[i].data = loadRowData(rows[i]); 78 | } 79 | } 80 | // sorts the table using the data for the ith column 81 | function sortByIndex(index, desc) { 82 | var key = cols[index].key, 83 | sorter = function(a, b) { 84 | a = a.data[key]; 85 | b = b.data[key]; 86 | return a < b ? -1 : a > b ? 1 : 0; 87 | }, 88 | finalSorter = sorter, 89 | tableBody = document.querySelector('.coverage-summary tbody'), 90 | rowNodes = tableBody.querySelectorAll('tr'), 91 | rows = [], 92 | i; 93 | 94 | if (desc) { 95 | finalSorter = function(a, b) { 96 | return -1 * sorter(a, b); 97 | }; 98 | } 99 | 100 | for (i = 0; i < rowNodes.length; i += 1) { 101 | rows.push(rowNodes[i]); 102 | tableBody.removeChild(rowNodes[i]); 103 | } 104 | 105 | rows.sort(finalSorter); 106 | 107 | for (i = 0; i < rows.length; i += 1) { 108 | tableBody.appendChild(rows[i]); 109 | } 110 | } 111 | // removes sort indicators for current column being sorted 112 | function removeSortIndicators() { 113 | var col = getNthColumn(currentSort.index), 114 | cls = col.className; 115 | 116 | cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); 117 | col.className = cls; 118 | } 119 | // adds sort indicators for current column being sorted 120 | function addSortIndicators() { 121 | getNthColumn(currentSort.index).className += currentSort.desc 122 | ? ' sorted-desc' 123 | : ' sorted'; 124 | } 125 | // adds event listeners for all sorter widgets 126 | function enableUI() { 127 | var i, 128 | el, 129 | ithSorter = function ithSorter(i) { 130 | var col = cols[i]; 131 | 132 | return function() { 133 | var desc = col.defaultDescSort; 134 | 135 | if (currentSort.index === i) { 136 | desc = !currentSort.desc; 137 | } 138 | sortByIndex(i, desc); 139 | removeSortIndicators(); 140 | currentSort.index = i; 141 | currentSort.desc = desc; 142 | addSortIndicators(); 143 | }; 144 | }; 145 | for (i = 0; i < cols.length; i += 1) { 146 | if (cols[i].sortable) { 147 | // add the click event handler on the th so users 148 | // dont have to click on those tiny arrows 149 | el = getNthColumn(i).querySelector('.sorter').parentElement; 150 | if (el.addEventListener) { 151 | el.addEventListener('click', ithSorter(i)); 152 | } else { 153 | el.attachEvent('onclick', ithSorter(i)); 154 | } 155 | } 156 | } 157 | } 158 | // adds sorting functionality to the UI 159 | return function() { 160 | if (!getTable()) { 161 | return; 162 | } 163 | cols = loadColumns(); 164 | loadData(); 165 | addSortIndicators(); 166 | enableUI(); 167 | }; 168 | })(); 169 | 170 | window.addEventListener('load', addSorting); 171 | -------------------------------------------------------------------------------- /coverage/lcov.info: -------------------------------------------------------------------------------- 1 | TN: 2 | SF:/Users/libowen/Desktop/Code/gitlab.prod.dtstack.cn/dt-insight-front/infrastructure/babel-plugin-treasure/src/Plugin.js 3 | FN:4,normalizeCustomName 4 | FN:14,winPath 5 | FN:18,transCamel 6 | FN:25,(anonymous_3) 7 | FN:29,(anonymous_4) 8 | FN:59,(anonymous_5) 9 | FN:67,(anonymous_6) 10 | FN:85,(anonymous_7) 11 | FN:86,(anonymous_8) 12 | FN:93,(anonymous_9) 13 | FN:106,(anonymous_10) 14 | FN:117,(anonymous_11) 15 | FN:129,(anonymous_12) 16 | FN:143,(anonymous_13) 17 | FN:205,(anonymous_14) 18 | FN:213,(anonymous_15) 19 | FN:242,(anonymous_16) 20 | FN:247,(anonymous_17) 21 | FN:253,(anonymous_18) 22 | FN:258,(anonymous_19) 23 | FN:264,(anonymous_20) 24 | FN:269,(anonymous_21) 25 | FN:274,(anonymous_22) 26 | FN:276,(anonymous_23) 27 | FN:280,(anonymous_24) 28 | FN:285,(anonymous_25) 29 | FN:293,(anonymous_26) 30 | FN:298,(anonymous_27) 31 | FN:303,(anonymous_28) 32 | FN:308,(anonymous_29) 33 | FN:314,(anonymous_30) 34 | FN:319,(anonymous_31) 35 | FNF:32 36 | FNH:32 37 | FNDA:84,normalizeCustomName 38 | FNDA:46,winPath 39 | FNDA:43,transCamel 40 | FNDA:3,(anonymous_3) 41 | FNDA:42,(anonymous_4) 42 | FNDA:952,(anonymous_5) 43 | FNDA:42,(anonymous_6) 44 | FNDA:42,(anonymous_7) 45 | FNDA:40,(anonymous_8) 46 | FNDA:111,(anonymous_9) 47 | FNDA:44,(anonymous_10) 48 | FNDA:219,(anonymous_11) 49 | FNDA:321,(anonymous_12) 50 | FNDA:63,(anonymous_13) 51 | FNDA:57,(anonymous_14) 52 | FNDA:210,(anonymous_15) 53 | FNDA:1,(anonymous_16) 54 | FNDA:39,(anonymous_17) 55 | FNDA:56,(anonymous_18) 56 | FNDA:16,(anonymous_19) 57 | FNDA:6,(anonymous_20) 58 | FNDA:84,(anonymous_21) 59 | FNDA:3,(anonymous_22) 60 | FNDA:3,(anonymous_23) 61 | FNDA:1,(anonymous_24) 62 | FNDA:57,(anonymous_25) 63 | FNDA:1,(anonymous_26) 64 | FNDA:40,(anonymous_27) 65 | FNDA:1,(anonymous_28) 66 | FNDA:2,(anonymous_29) 67 | FNDA:328,(anonymous_30) 68 | FNDA:469,(anonymous_31) 69 | DA:5,84 70 | DA:6,1 71 | DA:7,1 72 | DA:11,83 73 | DA:15,46 74 | DA:19,43 75 | DA:20,3 76 | DA:24,40 77 | DA:25,40 78 | DA:43,42 79 | DA:44,42 80 | DA:45,42 81 | DA:46,42 82 | DA:47,42 83 | DA:49,42 84 | DA:51,42 85 | DA:52,42 86 | DA:53,42 87 | DA:54,42 88 | DA:55,42 89 | DA:56,42 90 | DA:60,952 91 | DA:62,42 92 | DA:64,952 93 | DA:68,42 94 | DA:69,42 95 | DA:70,42 96 | DA:71,42 97 | DA:72,42 98 | DA:86,42 99 | DA:94,111 100 | DA:97,111 101 | DA:101,111 102 | DA:102,111 103 | DA:103,111 104 | DA:105,111 105 | DA:106,40 106 | DA:107,44 107 | DA:108,43 108 | DA:110,1 109 | DA:113,40 110 | DA:118,219 111 | DA:119,219 112 | DA:120,219 113 | DA:121,219 114 | DA:122,219 115 | DA:123,219 116 | DA:125,132 117 | DA:126,8 118 | DA:129,219 119 | DA:130,321 120 | DA:131,321 121 | DA:136,17 122 | DA:138,304 123 | DA:144,63 124 | DA:154,44 125 | DA:155,44 126 | DA:166,44 127 | DA:177,44 128 | DA:183,44 129 | DA:184,1 130 | DA:185,1 131 | DA:186,43 132 | DA:187,1 133 | DA:190,1 134 | DA:191,42 135 | DA:192,4 136 | DA:193,38 137 | DA:194,2 138 | DA:195,36 139 | DA:196,3 140 | DA:197,3 141 | DA:198,2 142 | DA:202,63 143 | DA:206,57 144 | DA:207,57 145 | DA:214,210 146 | DA:215,210 147 | DA:216,210 148 | DA:217,210 149 | DA:219,208 150 | DA:220,1 151 | DA:221,207 152 | DA:222,8 153 | DA:228,8 154 | DA:230,4 155 | DA:231,4 156 | DA:232,4 157 | DA:243,1 158 | DA:244,1 159 | DA:249,39 160 | DA:250,39 161 | DA:254,56 162 | DA:255,56 163 | DA:259,16 164 | DA:260,16 165 | DA:261,16 166 | DA:265,6 167 | DA:266,6 168 | DA:270,84 169 | DA:271,84 170 | DA:275,3 171 | DA:276,3 172 | DA:277,3 173 | DA:281,1 174 | DA:282,1 175 | DA:286,57 176 | DA:287,57 177 | DA:288,57 178 | DA:289,5 179 | DA:294,1 180 | DA:295,1 181 | DA:299,40 182 | DA:300,40 183 | DA:304,1 184 | DA:305,1 185 | DA:309,2 186 | DA:310,2 187 | DA:315,328 188 | DA:316,328 189 | DA:317,328 190 | DA:319,328 191 | DA:320,469 192 | DA:321,173 193 | DA:326,33 194 | LF:125 195 | LH:125 196 | BRDA:5,0,0,1 197 | BRDA:5,0,1,83 198 | BRDA:7,1,0,0 199 | BRDA:7,1,1,1 200 | BRDA:19,2,0,3 201 | BRDA:19,2,1,40 202 | BRDA:19,3,0,43 203 | BRDA:19,3,1,42 204 | BRDA:20,4,0,1 205 | BRDA:20,4,1,2 206 | BRDA:41,5,0,42 207 | BRDA:44,6,0,41 208 | BRDA:44,6,1,1 209 | BRDA:45,7,0,42 210 | BRDA:45,7,1,36 211 | BRDA:48,8,0,39 212 | BRDA:48,8,1,3 213 | BRDA:50,9,0,40 214 | BRDA:50,9,1,2 215 | BRDA:54,10,0,42 216 | BRDA:54,10,1,41 217 | BRDA:60,11,0,42 218 | BRDA:60,11,1,910 219 | BRDA:86,12,0,40 220 | BRDA:86,12,1,40 221 | BRDA:97,13,0,0 222 | BRDA:97,13,1,111 223 | BRDA:105,14,0,40 224 | BRDA:105,14,1,71 225 | BRDA:107,15,0,43 226 | BRDA:107,15,1,1 227 | BRDA:119,16,0,219 228 | BRDA:119,16,1,0 229 | BRDA:123,17,0,132 230 | BRDA:123,17,1,87 231 | BRDA:125,18,0,8 232 | BRDA:125,18,1,124 233 | BRDA:131,19,0,17 234 | BRDA:131,19,1,304 235 | BRDA:132,20,0,321 236 | BRDA:132,20,1,18 237 | BRDA:132,20,2,18 238 | BRDA:144,21,0,44 239 | BRDA:144,21,1,19 240 | BRDA:155,22,0,1 241 | BRDA:155,22,1,43 242 | BRDA:157,23,0,39 243 | BRDA:157,23,1,4 244 | BRDA:159,24,0,3 245 | BRDA:159,24,1,1 246 | BRDA:159,25,0,4 247 | BRDA:159,25,1,3 248 | BRDA:167,26,0,6 249 | BRDA:167,26,1,38 250 | BRDA:168,27,0,2 251 | BRDA:168,27,1,4 252 | BRDA:169,28,0,2 253 | BRDA:169,28,1,1 254 | BRDA:178,29,0,3 255 | BRDA:178,29,1,41 256 | BRDA:178,30,0,44 257 | BRDA:178,30,1,42 258 | BRDA:178,30,2,1 259 | BRDA:183,31,0,1 260 | BRDA:183,31,1,43 261 | BRDA:186,32,0,1 262 | BRDA:186,32,1,42 263 | BRDA:191,33,0,4 264 | BRDA:191,33,1,38 265 | BRDA:193,34,0,2 266 | BRDA:193,34,1,36 267 | BRDA:195,35,0,3 268 | BRDA:195,35,1,33 269 | BRDA:197,36,0,2 270 | BRDA:197,36,1,1 271 | BRDA:215,37,0,210 272 | BRDA:215,37,1,0 273 | BRDA:217,38,0,2 274 | BRDA:217,38,1,208 275 | BRDA:219,39,0,1 276 | BRDA:219,39,1,207 277 | BRDA:221,40,0,8 278 | BRDA:221,40,1,199 279 | BRDA:221,41,0,207 280 | BRDA:221,41,1,8 281 | BRDA:228,42,0,4 282 | BRDA:228,42,1,4 283 | BRDA:231,43,0,4 284 | BRDA:231,43,1,0 285 | BRDA:288,44,0,5 286 | BRDA:288,44,1,52 287 | BRDA:315,45,0,328 288 | BRDA:315,45,1,0 289 | BRDA:320,46,0,296 290 | BRDA:320,46,1,173 291 | BRDA:321,47,0,33 292 | BRDA:321,47,1,140 293 | BRDA:322,48,0,173 294 | BRDA:322,48,1,43 295 | BRF:99 296 | BRH:93 297 | end_of_record 298 | TN: 299 | SF:/Users/libowen/Desktop/Code/gitlab.prod.dtstack.cn/dt-insight-front/infrastructure/babel-plugin-treasure/src/index.js 300 | FN:4,(anonymous_0) 301 | FN:11,(anonymous_1) 302 | FN:18,applyInstance 303 | FN:32,(anonymous_3) 304 | FN:36,(anonymous_4) 305 | FN:89,(anonymous_5) 306 | FN:120,(anonymous_6) 307 | FNF:7 308 | FNH:6 309 | FNDA:42,(anonymous_0) 310 | FNDA:40,(anonymous_1) 311 | FNDA:988,applyInstance 312 | FNDA:42,(anonymous_3) 313 | FNDA:0,(anonymous_4) 314 | FNDA:42,(anonymous_5) 315 | FNDA:904,(anonymous_6) 316 | DA:5,42 317 | DA:11,42 318 | DA:12,40 319 | DA:20,988 320 | DA:21,988 321 | DA:22,988 322 | DA:31,42 323 | DA:33,42 324 | DA:34,42 325 | DA:35,0 326 | DA:51,0 327 | DA:52,0 328 | DA:69,42 329 | DA:70,42 330 | DA:87,42 331 | DA:91,42 332 | DA:95,42 333 | DA:115,42 334 | DA:119,42 335 | DA:120,714 336 | DA:122,904 337 | DA:126,42 338 | LF:22 339 | LH:19 340 | BRDA:21,0,0,988 341 | BRDA:21,0,1,0 342 | BRDA:32,1,0,0 343 | BRDA:33,2,0,42 344 | BRDA:33,2,1,0 345 | BRDA:34,3,0,0 346 | BRDA:34,3,1,42 347 | BRF:7 348 | BRH:3 349 | end_of_record 350 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-treasure", 3 | "version": "0.9.0", 4 | "repository": "https://github.com/DTStack/babel-plugin-treasure", 5 | "description": "a babel plugin for the special demand", 6 | "main": "dist/index.js", 7 | "module": "dist/index.esm.js", 8 | "scripts": { 9 | "build": "father build --cjs", 10 | "dev": "father doc dev", 11 | "lint": "eslint --ext .js src", 12 | "test": "father test --coverage" 13 | }, 14 | "keywords": [ 15 | "babel", 16 | "babel-plugin", 17 | "dtstack" 18 | ], 19 | "husky": { 20 | "hooks": { 21 | "lint-staged": "lint-staged" 22 | } 23 | }, 24 | "lint-staged": { 25 | "*.js": [ 26 | "eslint", 27 | "prettier --write" 28 | ] 29 | }, 30 | "author": "chenfeng", 31 | "license": "MIT", 32 | "devDependencies": { 33 | "@babel/core": "^7.11.6", 34 | "@babel/preset-env": "^7.11.5", 35 | "@babel/preset-react": "^7.10.4", 36 | "@babel/register": "^7.11.5", 37 | "@babel/types": "^7.11.5", 38 | "babel-preset-umi": "^1.8.4", 39 | "eslint": "^7.9.0", 40 | "eslint-config-airbnb": "^18.2.0", 41 | "eslint-config-prettier": "^6.11.0", 42 | "eslint-plugin-import": "^2.22.0", 43 | "eslint-plugin-prettier": "^3.1.4", 44 | "father": "^2.29.10", 45 | "husky": "^4.3.0", 46 | "np": "^6.5.0" 47 | }, 48 | "dependencies": { 49 | "@babel/helper-module-imports": "^7.10.4", 50 | "@babel/runtime": "^7.11.2" 51 | }, 52 | "babel": { 53 | "presets": [ 54 | "@babel/preset-env", 55 | "@babel/preset-react" 56 | ] 57 | } 58 | } -------------------------------------------------------------------------------- /src/Plugin.js: -------------------------------------------------------------------------------- 1 | import { join } from 'path'; 2 | import { addNamed, addDefault, addSideEffect } from '@babel/helper-module-imports'; 3 | 4 | function normalizeCustomName(originCustomName) { 5 | if (typeof originCustomName === 'string') { 6 | const customeNameExports = require(originCustomName); 7 | return typeof customeNameExports === 'function' 8 | ? customeNameExports 9 | : customeNameExports.default; 10 | } 11 | return originCustomName; 12 | } 13 | 14 | function winPath(path) { 15 | return path?.replace(/\\/g, '/'); 16 | } 17 | 18 | function transCamel(_str, symbol) { 19 | if (symbol === 'upper' || symbol === 'lower') { 20 | return symbol === 'upper' 21 | ? _str[0].toUpperCase() + _str.substr(1) 22 | : _str[0].toLowerCase() + _str.substr(1); 23 | } 24 | const str = _str[0].toLowerCase() + _str.substr(1); 25 | return str?.replace(/([A-Z])/g, $1 => `${symbol}${$1.toLowerCase()}`); 26 | } 27 | 28 | export default class Plugin { 29 | constructor( 30 | libraryName, 31 | libraryDirectory, 32 | style, 33 | styleLibraryDirectory, 34 | customStyleName, 35 | camel2DashComponentName, 36 | camel2UnderlineComponentName, 37 | fileName, 38 | customName, 39 | transformToDefaultImport, 40 | types, // babel-types 41 | index = 0, // 标记符,具体作用后续补充 42 | ) { 43 | this.libraryName = libraryName; // 库名 44 | this.libraryDirectory = typeof libraryDirectory === 'undefined' ? 'lib' : libraryDirectory; // 包路径 45 | this.style = style || false; // 是否加载style 46 | this.styleLibraryDirectory = styleLibraryDirectory; // style包路径 47 | this.camel2DashComponentName = 48 | typeof camel2DashComponentName === 'undefined' ? true : camel2DashComponentName; // 组件名转换为大 /小驼峰【upper/lower】 49 | this.transformToDefaultImport = 50 | typeof transformToDefaultImport === 'undefined' ? true : transformToDefaultImport; // 处理默认导入,暂不知为何默认为true 51 | this.customName = normalizeCustomName(customName); // 处理转换结果的函数或路径 52 | this.customStyleName = normalizeCustomName(customStyleName); // 处理转换结果的函数或路径 53 | this.camel2UnderlineComponentName = camel2UnderlineComponentName; // 处理成类似time_picker的形式 54 | this.fileName = fileName || ''; // 链接到具体的文件,例如antd/lib/button/[abc.js] 55 | this.types = types; // babel-types 56 | this.pluginStateKey = `importPluginState${index}`; 57 | } 58 | 59 | getPluginState(state) { 60 | if (!state[this.pluginStateKey]) { 61 | // eslint-disable-next-line no-param-reassign 62 | state[this.pluginStateKey] = {}; // 初始化标示 63 | } 64 | return state[this.pluginStateKey]; // 返回标示 65 | } 66 | 67 | ProgramEnter(_, state) { 68 | const pluginState = this.getPluginState(state); 69 | pluginState.specified = Object.create(null); // 导入对象集合 70 | pluginState.libraryObjs = Object.create(null); // 库对象集合(非module导入的内容) 71 | pluginState.selectedMethods = Object.create(null); // 存放经过importMethod之后的节点 72 | pluginState.pathsToRemove = []; // 存储需要删除的节点,在 73 | /** 74 | * state:{ 75 | * importPluginState「Number」: { 76 | * specified:{}, 77 | * libraryObjs:{}, 78 | * select:{}, 79 | * pathToRemovw:[] 80 | * }, 81 | * } 82 | */ 83 | } 84 | 85 | ProgramExit(_, state) { 86 | this.getPluginState(state).pathsToRemove.forEach(p => !p.removed && p.remove()); // 未删除为false 87 | // 退出AST时候删除节点,这也是整个工作树的最后一步 88 | } 89 | 90 | /** 91 | * 主目标,收集依赖 92 | */ 93 | ImportDeclaration(path, state) { 94 | const { node } = path; 95 | 96 | // path maybe removed by prev instances.都这样写,但待验证 97 | if (!node) return; 98 | 99 | const { 100 | source: { value }, 101 | } = node; 102 | const { libraryName, types } = this; 103 | const pluginState = this.getPluginState(state); 104 | 105 | if (value === libraryName) { 106 | node.specifiers.forEach(spec => { 107 | if (types.isImportSpecifier(spec)) { 108 | pluginState.specified[spec.local.name] = spec.imported.name; 109 | } else { 110 | pluginState.libraryObjs[spec.local.name] = true; 111 | } 112 | }); 113 | pluginState.pathsToRemove.push(path); // 取值完毕的节点添加进预删除数组 114 | } 115 | } 116 | 117 | CallExpression(path, state) { 118 | const { node } = path; 119 | const file = path?.hub?.file || state?.file; 120 | const { name } = node.callee; 121 | const { types } = this; 122 | const pluginState = this.getPluginState(state); 123 | if (types.isIdentifier(node.callee)) { 124 | // 对应一般的调用表达式 125 | if (pluginState.specified[name]) { 126 | node.callee = this.importMethod(pluginState.specified[name], file, pluginState); 127 | } 128 | } 129 | node.arguments = node.arguments.map(arg => { 130 | const { name: argName } = arg; 131 | if ( 132 | pluginState.specified[argName] && 133 | path.scope.hasBinding(argName) && 134 | types.isImportSpecifier(path.scope.getBinding(argName).path) 135 | ) { 136 | return this.importMethod(pluginState.specified[argName], file, pluginState); // 替换了引用,help/import插件返回节点类型与名称 137 | } 138 | return arg; 139 | }); 140 | } // 转换react.createElement 141 | 142 | // 组件原始名称 , sub.file , 导入依赖项 143 | importMethod(methodName, file, pluginState) { 144 | if (!pluginState.selectedMethods[methodName]) { 145 | const { 146 | libraryName, 147 | style, 148 | libraryDirectory, 149 | camel2UnderlineComponentName, 150 | camel2DashComponentName, 151 | transformToDefaultImport, 152 | customName, 153 | fileName, 154 | } = this; 155 | const transformedMethodName = camel2UnderlineComponentName 156 | ? transCamel(methodName, '_') 157 | : camel2DashComponentName === true 158 | ? transCamel(methodName, '-') 159 | : camel2DashComponentName === 'upper' || camel2DashComponentName === 'lower' 160 | ? transCamel(methodName, camel2DashComponentName) 161 | : methodName; 162 | /** 163 | * 转换路径,优先按照用户定义的customName进行转换,如果没有提供就按照常规拼接路径 164 | */ 165 | 166 | const path = winPath( 167 | customName 168 | ? typeof customName === 'object' 169 | ? customName[methodName] || 170 | join(libraryName, libraryDirectory, transformedMethodName, fileName) 171 | : customName(transformedMethodName, file) 172 | : join(libraryName, libraryDirectory, transformedMethodName, fileName), 173 | ); 174 | /** 175 | * 根据是否是默认引入对最终路径做处理,并没有对namespace做处理 176 | */ 177 | pluginState.selectedMethods[methodName] = 178 | transformToDefaultImport === false || 179 | (Array.isArray(transformToDefaultImport) && 180 | transformToDefaultImport.indexOf(methodName) !== -1) 181 | ? addNamed(file.path, methodName, path) 182 | : addDefault(file.path, path, { nameHint: methodName }); 183 | if (this.customStyleName) { 184 | const stylePath = winPath(this.customStyleName(transformedMethodName)); 185 | addSideEffect(file.path, `${stylePath}`); 186 | } else if (this.styleLibraryDirectory) { 187 | const stylePath = winPath( 188 | join(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName), 189 | ); 190 | addSideEffect(file.path, `${stylePath}`); 191 | } else if (style === true) { 192 | addSideEffect(file.path, `${path}/style`); 193 | } else if (style === 'css') { 194 | addSideEffect(file.path, `${path}/style/css`); 195 | } else if (typeof style === 'function') { 196 | const stylePath = style(path, file); 197 | if (stylePath) { 198 | addSideEffect(file.path, stylePath); 199 | } 200 | } 201 | } 202 | return { ...pluginState.selectedMethods[methodName] }; 203 | } 204 | 205 | Property(path, state) { 206 | const { node } = path; 207 | this.buildExpressionHandler(node, ['value'], path, state); // 可以测什么实例经过它 208 | } 209 | 210 | /** 211 | * 区块分界线 212 | **/ 213 | MemberExpression(path, state) { 214 | const { node } = path; 215 | const file = path?.hub?.file || state?.file; 216 | const pluginState = this.getPluginState(state); 217 | if (!node?.object?.name) return; 218 | 219 | if (pluginState.libraryObjs[node.object.name]) { 220 | path.replaceWith(this.importMethod(node.property.name, file, pluginState)); 221 | } else if (pluginState.specified[node.object.name] && path.scope.hasBinding(node.object.name)) { 222 | const { scope } = path.scope.getBinding(node.object.name); 223 | 224 | /** 225 | * 替换全局变量,具体例子:console.log(Input.debounce()) 226 | **/ 227 | 228 | if (scope.path.parent.type === 'File') { 229 | // 对于在file scope中的全局变量进行处理 230 | const { scope } = path.scope.getBinding(node.object.name); 231 | if (scope.path.parent.type === 'File') { 232 | node.object = this.importMethod( 233 | pluginState.specified[node.object.name], 234 | file, 235 | pluginState, 236 | ); 237 | } 238 | } 239 | } 240 | } /**例如: console.log(lodash.debounce()) */ 241 | 242 | ClassDeclaration(path, state) { 243 | const { node } = path; 244 | this.buildExpressionHandler(node, ['superClass'], path, state); // 不明白为啥叫superClass 245 | } // 例如 class emaple extends Antd {...} 246 | 247 | ConditionalExpression(path, state) { 248 | // 取三元表达式的条件与结果 249 | const { node } = path; 250 | this.buildExpressionHandler(node, ['test', 'consequent', 'alternate'], path, state); 251 | } // 例如 lodash ? 'some code' : 'some code' 252 | 253 | ReturnStatement(path, state) { 254 | const { node } = path; 255 | this.buildExpressionHandler(node, ['argument'], path, state); // 取return AST 结构的argument 256 | } // 例如 return lodash 257 | 258 | IfStatement(path, state) { 259 | const { node } = path; 260 | this.buildExpressionHandler(node, ['test'], path, state); 261 | this.buildExpressionHandler(node.test, ['left', 'right'], path, state); //未知 262 | } // 待补充实例,有两种转换 263 | 264 | BinaryExpression(path, state) { 265 | const { node } = path; 266 | this.buildExpressionHandler(node, ['left', 'right'], path, state); 267 | } // 例如 lodash > '22' 268 | 269 | VariableDeclarator(path, state) { 270 | const { node } = path; 271 | this.buildExpressionHandler(node, ['init'], path, state); 272 | } // 例如 const a=lodash 273 | 274 | ArrayExpression(path, state) { 275 | const { node } = path; 276 | const props = node?.elements.map((_, index) => index); 277 | this.buildExpressionHandler(node.elements, props, path, state); 278 | } // 例如 [antd,lodash] 279 | 280 | NewExpression(path, state) { 281 | const { node } = path; 282 | this.buildExpressionHandler(node, ['callee', 'arguments'], path, state); 283 | } // 例如 new Antd(xx) 284 | 285 | ExpressionStatement(path, state) { 286 | const { node } = path; 287 | const { types } = this; 288 | if (types.isAssignmentExpression(node.expression)) { 289 | this.buildExpressionHandler(node.expression, ['right'], path, state); 290 | } 291 | } // 例如 module.export ={antd} 292 | 293 | ExportDefaultDeclaration(path, state) { 294 | const { node } = path; 295 | this.buildExpressionHandler(node, ['declaration'], path, state); 296 | } // 例如 export default antd 297 | 298 | LogicalExpression(path, state) { 299 | const { node } = path; 300 | this.buildExpressionHandler(node, ['left', 'right'], path, state); 301 | } // 例如 antd && [some code] 302 | 303 | SwitchStatement(path, state) { 304 | const { node } = path; 305 | this.buildExpressionHandler(node, ['discriminant'], path, state); 306 | } // 例如 switch(antd.Button) 307 | 308 | SwitchCase(path, state) { 309 | const { node } = path; 310 | this.buildExpressionHandler(node, ['test'], path, state); 311 | } // 例如 case antd.Button: 312 | 313 | // 处理“基层”转换,套娃的结构交给其他的node处理 314 | buildExpressionHandler(node, props, path, state) { 315 | const file = path?.hub?.file || state?.file; // 具体原因待补充,和help/import有关 316 | const { types } = this; 317 | const pluginState = this.getPluginState(state); 318 | // console.log('都是啥!', props); 319 | props.forEach(prop => { 320 | if (!types.isIdentifier(node[prop])) return; // 不是Identifier就结束 321 | if ( 322 | pluginState.specified[node[prop].name] && // node[prop].name别名,看看用了没,如果用了 323 | types.isImportSpecifier(path.scope.getBinding(node[prop].name).path) //根据作用域回溯,看看是不是一个import节点 324 | ) { 325 | // 替换AST节点 326 | node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); 327 | } 328 | }); 329 | } 330 | } 331 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert'; 2 | import Plugin from './Plugin'; 3 | 4 | export default function({ types }) { 5 | let plugins = null; 6 | 7 | /** 8 | * 用于单测初始化插件 9 | */ 10 | // eslint-disable-next-line no-underscore-dangle 11 | global.__clearBabelTreasurePlugin = () => { 12 | plugins = null; 13 | }; 14 | 15 | /** 16 | * 从类中继承方法与参数 17 | */ 18 | function applyInstance(method, args, context) { 19 | // eslint-disable-next-line no-restricted-syntax 20 | for (const plugin of plugins) { 21 | if (plugin[method]) { 22 | plugin[method].apply(plugin, [...args, context]); 23 | } 24 | } 25 | } 26 | 27 | /** 28 | * Program入口初始化数据结构 29 | * 出口删除处理完毕的标记节点 30 | */ 31 | const Program = { 32 | enter(path, { opts = {} }) { 33 | if (!plugins) { 34 | if (Array.isArray(opts)) { 35 | plugins = opts.map( 36 | ( 37 | { 38 | libraryName, 39 | libraryDirectory, 40 | style, 41 | styleLibraryDirectory, 42 | customStyleName, 43 | camel2DashComponentName, 44 | camel2UnderlineComponentName, 45 | fileName, 46 | customName, 47 | transformToDefaultImport, 48 | }, 49 | index, 50 | ) => { 51 | assert(libraryName, 'libraryName should be provided'); 52 | return new Plugin( 53 | libraryName, 54 | libraryDirectory, 55 | style, 56 | styleLibraryDirectory, 57 | customStyleName, 58 | camel2DashComponentName, 59 | camel2UnderlineComponentName, 60 | fileName, 61 | customName, 62 | transformToDefaultImport, 63 | types, 64 | index, 65 | ); 66 | }, 67 | ); 68 | } else { 69 | assert(opts.libraryName, 'libraryName should be provided'); 70 | plugins = [ 71 | new Plugin( 72 | opts.libraryName, 73 | opts.libraryDirectory, 74 | opts.style, 75 | opts.styleLibraryDirectory, 76 | opts.customStyleName, 77 | opts.camel2DashComponentName, 78 | opts.camel2UnderlineComponentName, 79 | opts.fileName, 80 | opts.customName, 81 | opts.transformToDefaultImport, 82 | types, 83 | ), 84 | ]; 85 | } 86 | } 87 | applyInstance('ProgramEnter', arguments, this); // eslint-disable-line 88 | }, 89 | exit() { 90 | // eslint-disable-next-line prefer-rest-params 91 | applyInstance('ProgramExit', arguments, this); 92 | }, 93 | }; 94 | 95 | const methods = [ 96 | 'ImportDeclaration', 97 | 'CallExpression', 98 | 'MemberExpression', 99 | 'ClassDeclaration', 100 | 'Property', 101 | 'ConditionalExpression', 102 | 'ReturnStatement', 103 | 'IfStatement', 104 | 'BinaryExpression', 105 | 'VariableDeclarator', 106 | 'ArrayExpression', 107 | 'NewExpression', 108 | 'ExportDefaultDeclaration', 109 | 'ExpressionStatement', 110 | 'LogicalExpression', 111 | 'SwitchStatement', 112 | 'SwitchCase', 113 | ]; 114 | 115 | const ret = { 116 | visitor: { Program }, // 对整棵AST树的入口进行初始化操作 117 | }; 118 | // eslint-disable-next-line no-restricted-syntax 119 | for (const method of methods) { 120 | ret.visitor[method] = function() { 121 | // eslint-disable-next-line prefer-rest-params 122 | applyInstance(method, arguments, ret.visitor); 123 | }; 124 | } 125 | 126 | return ret; 127 | } 128 | -------------------------------------------------------------------------------- /src/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | route: / 3 | name: 快速开始 4 | --- 5 | 6 | ## babel-plugin-treasure 7 | 8 | 欢迎来到 babel 插件百宝箱,这里专门实现关于 AST 的定制服务。 9 | -------------------------------------------------------------------------------- /src/index.module.less: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DTStack/babel-plugin-treasure/29c007ca702eebec57b33d4dde260b9d545340cb/src/index.module.less -------------------------------------------------------------------------------- /test/fixtures/array-expression/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | 3 | var a = [Button]; 4 | var b = { test: [Button] }; 5 | [Button].map(function() {}); 6 | -------------------------------------------------------------------------------- /test/fixtures/array-expression/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var a = [_button["default"]]; 8 | var b = { 9 | test: [_button["default"]] 10 | }; 11 | [_button["default"]].map(function () {}); -------------------------------------------------------------------------------- /test/fixtures/as-arguments-identifier/actual.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _antd = require("antd"); 4 | 5 | var _Modal = bind()(_antd.Modal); -------------------------------------------------------------------------------- /test/fixtures/as-arguments-identifier/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _antd = require("antd"); 4 | 5 | var _Modal = bind()(_antd.Modal); -------------------------------------------------------------------------------- /test/fixtures/as-arguments/actual.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _antd = require("antd"); 4 | 5 | var _Modal = bind({})(_antd.Modal); -------------------------------------------------------------------------------- /test/fixtures/as-arguments/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _antd = require("antd"); 4 | 5 | var _Modal = bind({})(_antd.Modal); -------------------------------------------------------------------------------- /test/fixtures/binary-expression/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | const extraProps = undefined === Button ? { type: 'primary' } : {}; 3 | console.log(extraProps); 4 | -------------------------------------------------------------------------------- /test/fixtures/binary-expression/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var extraProps = undefined === _button["default"] ? { 8 | type: 'primary' 9 | } : {}; 10 | console.log(extraProps); -------------------------------------------------------------------------------- /test/fixtures/camel2-dash-name-lower/actual.js: -------------------------------------------------------------------------------- 1 | import { GoBack, Circle } from 'dt-react-component'; 2 | 3 | ReactDOM.render( 4 | <> 5 |
6 | 返回 7 | 8 |
9 | , 10 | document.getElementById('react-container'), 11 | ); 12 | -------------------------------------------------------------------------------- /test/fixtures/camel2-dash-name-lower/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("dt-react-component/lib/circle/style/css"); 4 | 5 | var _circle = _interopRequireDefault(require("dt-react-component/lib/circle")); 6 | 7 | require("dt-react-component/lib/go-back/style/css"); 8 | 9 | var _goBack = _interopRequireDefault(require("dt-react-component/lib/go-back")); 10 | 11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 12 | 13 | ReactDOM.render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_goBack["default"], { 14 | type: "running" 15 | }, "\u8FD4\u56DE"), /*#__PURE__*/React.createElement(_circle["default"], null))), document.getElementById('react-container')); -------------------------------------------------------------------------------- /test/fixtures/conditions/actual.js: -------------------------------------------------------------------------------- 1 | import { Select } from 'antd'; 2 | 3 | if (a === Select) {} 4 | if (Select) {} 5 | 6 | Select ? 'a' : 'b'; 7 | a ? Select : 2; 8 | 9 | Select || 'a'; 10 | a || Select; 11 | -------------------------------------------------------------------------------- /test/fixtures/conditions/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _select = _interopRequireDefault(require("antd/lib/select")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | if (a === _select["default"]) {} 8 | 9 | if (_select["default"]) {} 10 | 11 | _select["default"] ? 'a' : 'b'; 12 | a ? _select["default"] : 2; 13 | _select["default"] || 'a'; 14 | a || _select["default"]; -------------------------------------------------------------------------------- /test/fixtures/custom-name-source-file/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'plat/antd'; 2 | 3 | ReactDOM.render(
); 4 | -------------------------------------------------------------------------------- /test/fixtures/custom-name-source-file/customName.js: -------------------------------------------------------------------------------- 1 | export default function customName(name) { 2 | return `antd/lib/${name}`; 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/custom-name-source-file/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | ReactDOM.render( /*#__PURE__*/React.createElement("div", { 8 | component: _button["default"] 9 | })); -------------------------------------------------------------------------------- /test/fixtures/custom-name/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'plat/antd'; 2 | 3 | ReactDOM.render(
); 4 | -------------------------------------------------------------------------------- /test/fixtures/custom-name/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | ReactDOM.render( /*#__PURE__*/React.createElement("div", { 8 | component: _button["default"] 9 | })); -------------------------------------------------------------------------------- /test/fixtures/custom-style-name/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'element-ui'; 2 | 3 | ReactDOM.render(
4 | 5 |
); 6 | -------------------------------------------------------------------------------- /test/fixtures/custom-style-name/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("element-ui/lib/theme-light/button"); 4 | 5 | var _button2 = _interopRequireDefault(require("element-ui/lib/button")); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 8 | 9 | ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_button2["default"], null, "xxxx"))); -------------------------------------------------------------------------------- /test/fixtures/custom-style-path-ignore/actual.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDom from "react-dom"; 3 | import { Animation, Button } from "antd"; 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("react-container") 10 | ); 11 | -------------------------------------------------------------------------------- /test/fixtures/custom-style-path-ignore/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _animation = _interopRequireDefault(require("antd/lib/animation")); 4 | 5 | require("antd/lib/button/style/2x"); 6 | 7 | var _button = _interopRequireDefault(require("antd/lib/button")); 8 | 9 | var _react = _interopRequireDefault(require("react")); 10 | 11 | var _reactDom = _interopRequireDefault(require("react-dom")); 12 | 13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 14 | 15 | ReactDOM.render( /*#__PURE__*/_react["default"].createElement(_animation["default"], null, /*#__PURE__*/_react["default"].createElement(_button["default"], null, "xxxx")), document.getElementById("react-container")); -------------------------------------------------------------------------------- /test/fixtures/custom-style-path/actual.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDom from 'react-dom'; 3 | import { Button } from 'antd'; 4 | 5 | ReactDOM.render(
6 | 7 |
, document.getElementById('react-container')); 8 | -------------------------------------------------------------------------------- /test/fixtures/custom-style-path/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("antd/lib/button/style/2x"); 4 | 5 | var _button = _interopRequireDefault(require("antd/lib/button")); 6 | 7 | var _react = _interopRequireDefault(require("react")); 8 | 9 | var _reactDom = _interopRequireDefault(require("react-dom")); 10 | 11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 12 | 13 | ReactDOM.render( /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_button["default"], null, "xxxx")), document.getElementById('react-container')); -------------------------------------------------------------------------------- /test/fixtures/execute-direct/actual.js: -------------------------------------------------------------------------------- 1 | import { message } from 'antd'; 2 | 3 | message('xxx'); 4 | -------------------------------------------------------------------------------- /test/fixtures/execute-direct/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _message2 = _interopRequireDefault(require("antd/lib/message")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | (0, _message2["default"])('xxx'); -------------------------------------------------------------------------------- /test/fixtures/execute-member/actual.js: -------------------------------------------------------------------------------- 1 | import { message } from 'antd'; 2 | 3 | message.success('xxx'); 4 | -------------------------------------------------------------------------------- /test/fixtures/execute-member/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _message2 = _interopRequireDefault(require("antd/lib/message")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | _message2["default"].success('xxx'); -------------------------------------------------------------------------------- /test/fixtures/export-import/actual.js: -------------------------------------------------------------------------------- 1 | import { DatePicker } from 'antd'; 2 | export default DatePicker; 3 | 4 | -------------------------------------------------------------------------------- /test/fixtures/export-import/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports["default"] = void 0; 7 | 8 | var _datePicker = _interopRequireDefault(require("antd/lib/date-picker")); 9 | 10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 11 | 12 | var _default = _datePicker["default"]; 13 | exports["default"] = _default; -------------------------------------------------------------------------------- /test/fixtures/expression-statement/actual.js: -------------------------------------------------------------------------------- 1 | import {Toast} from 'antd-mobile'; 2 | window.Toast = Toast; 3 | Toast.success('test'); -------------------------------------------------------------------------------- /test/fixtures/expression-statement/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _antdMobile = require("antd-mobile"); 4 | 5 | window.Toast = _antdMobile.Toast; 6 | 7 | _antdMobile.Toast.success('test'); -------------------------------------------------------------------------------- /test/fixtures/file-name/actual.js: -------------------------------------------------------------------------------- 1 | import { Select } from 'antd-mobile-fake-2.0'; 2 | 3 | if (Select) {} 4 | 5 | console.log(Select); 6 | -------------------------------------------------------------------------------- /test/fixtures/file-name/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _index = _interopRequireDefault(require("antd-mobile-fake-2.0/lib/select/index.native")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | if (_index["default"]) {} 8 | 9 | console.log(_index["default"]); -------------------------------------------------------------------------------- /test/fixtures/import-alias/actual.js: -------------------------------------------------------------------------------- 1 | import { Select as AntdSelect } from 'antd'; 2 | 3 | if (AntdSelect) { 4 | console.log('foo'); 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/import-alias/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _select = _interopRequireDefault(require("antd/lib/select")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | if (_select["default"]) { 8 | console.log('foo'); 9 | } -------------------------------------------------------------------------------- /test/fixtures/import-css/actual.js: -------------------------------------------------------------------------------- 1 | import { message } from 'antd'; 2 | import { Button } from 'antd'; 3 | 4 | message('xxx'); 5 | ReactDOM.render(
6 | 7 |
); 8 | -------------------------------------------------------------------------------- /test/fixtures/import-css/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("antd/lib/button/style"); 4 | 5 | var _button = _interopRequireDefault(require("antd/lib/button")); 6 | 7 | require("antd/lib/message/style"); 8 | 9 | var _message2 = _interopRequireDefault(require("antd/lib/message")); 10 | 11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 12 | 13 | (0, _message2["default"])('xxx'); 14 | ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_button["default"], null, "xxxx"))); -------------------------------------------------------------------------------- /test/fixtures/keep-named-import/actual.js: -------------------------------------------------------------------------------- 1 | import { start, end } from 'stream'; 2 | 3 | start(); 4 | end(); 5 | -------------------------------------------------------------------------------- /test/fixtures/keep-named-import/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _end2 = require("stream/lib/end"); 4 | 5 | var _start2 = require("stream/lib/start"); 6 | 7 | (0, _start2.start)(); 8 | (0, _end2.end)(); -------------------------------------------------------------------------------- /test/fixtures/material-ui/actual.js: -------------------------------------------------------------------------------- 1 | import { Toolbar } from 'material-ui'; 2 | 3 | Toolbar('xxx'); 4 | -------------------------------------------------------------------------------- /test/fixtures/material-ui/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _Toolbar2 = _interopRequireDefault(require("material-ui/Toolbar")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | (0, _Toolbar2["default"])('xxx'); -------------------------------------------------------------------------------- /test/fixtures/member-expression/actual.js: -------------------------------------------------------------------------------- 1 | import antd from 'antd'; 2 | 3 | ReactDOM.render(
4 | Button 5 |
); 6 | -------------------------------------------------------------------------------- /test/fixtures/member-expression/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_button["default"], { 8 | type: "primary" 9 | }, "Button"))); -------------------------------------------------------------------------------- /test/fixtures/modules-false/actual.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDom from 'react-dom'; 3 | import { Button } from 'antd'; 4 | 5 | ReactDOM.render(
6 | 7 |
, document.getElementById('react-container')); -------------------------------------------------------------------------------- /test/fixtures/modules-false/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("antd/lib/button/style"); 4 | 5 | var _button = _interopRequireDefault(require("antd/lib/button")); 6 | 7 | var _react = _interopRequireDefault(require("react")); 8 | 9 | var _reactDom = _interopRequireDefault(require("react-dom")); 10 | 11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 12 | 13 | ReactDOM.render( /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_button["default"], null, "xxxx")), document.getElementById('react-container')); -------------------------------------------------------------------------------- /test/fixtures/multiple-libraries-hilojs/actual.js: -------------------------------------------------------------------------------- 1 | import { Select } from 'antd'; 2 | import { Abc, Class } from 'hilojs'; 3 | 4 | if (Select) {} 5 | if (Class && Abc) {} 6 | -------------------------------------------------------------------------------- /test/fixtures/multiple-libraries-hilojs/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _abc = _interopRequireDefault(require("hilojs/abc")); 4 | 5 | var _class = _interopRequireDefault(require("hilojs/core/class")); 6 | 7 | var _select = _interopRequireDefault(require("antd/lib/select")); 8 | 9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 10 | 11 | if (_select["default"]) {} 12 | 13 | if (_class["default"] && _abc["default"]) {} -------------------------------------------------------------------------------- /test/fixtures/multiple-libraries/actual.js: -------------------------------------------------------------------------------- 1 | import { Select } from 'antd'; 2 | import { Select as SelectMobile } from 'antd-mobile'; 3 | 4 | if (Select) {} 5 | if (SelectMobile) {} 6 | -------------------------------------------------------------------------------- /test/fixtures/multiple-libraries/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _select = _interopRequireDefault(require("antd-mobile/lib/select")); 4 | 5 | var _select2 = _interopRequireDefault(require("antd/lib/select")); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 8 | 9 | if (_select2["default"]) {} 10 | 11 | if (_select["default"]) {} -------------------------------------------------------------------------------- /test/fixtures/multiple-words/actual.js: -------------------------------------------------------------------------------- 1 | import { InputNumber } from 'antd'; 2 | 3 | ; 4 | -------------------------------------------------------------------------------- /test/fixtures/multiple-words/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _inputNumber = _interopRequireDefault(require("antd/lib/input-number")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | /*#__PURE__*/ 8 | React.createElement(_inputNumber["default"], null); -------------------------------------------------------------------------------- /test/fixtures/new-expression/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | new Button(); 3 | 4 | -------------------------------------------------------------------------------- /test/fixtures/new-expression/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | new _button["default"](); -------------------------------------------------------------------------------- /test/fixtures/object-shorthand/actual.js: -------------------------------------------------------------------------------- 1 | import { message } from 'antd'; 2 | 3 | message('xxx'); 4 | 5 | function App() { 6 | const message = 'xxx'; 7 | console.log({ message }); 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/object-shorthand/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _message2 = _interopRequireDefault(require("antd/lib/message")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | (0, _message2["default"])('xxx'); 8 | 9 | function App() { 10 | var message = 'xxx'; 11 | console.log({ 12 | message: message 13 | }); 14 | } -------------------------------------------------------------------------------- /test/fixtures/property/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | 3 | ReactDOM.render(
); 4 | -------------------------------------------------------------------------------- /test/fixtures/property/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | ReactDOM.render( /*#__PURE__*/React.createElement("div", { 8 | component: _button["default"] 9 | })); -------------------------------------------------------------------------------- /test/fixtures/react-element/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | 3 | ReactDOM.render(
4 | 5 |
); 6 | -------------------------------------------------------------------------------- /test/fixtures/react-element/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_button["default"], null, "xxxx"))); -------------------------------------------------------------------------------- /test/fixtures/react-toolbox/actual.js: -------------------------------------------------------------------------------- 1 | import { AppBar } from 'react-toolbox'; 2 | 3 | AppBar('xxx'); 4 | -------------------------------------------------------------------------------- /test/fixtures/react-toolbox/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _app_bar = _interopRequireDefault(require("react-toolbox/lib/app_bar")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | (0, _app_bar["default"])('xxx'); -------------------------------------------------------------------------------- /test/fixtures/return/actual.js: -------------------------------------------------------------------------------- 1 | import { toast } from 'antd'; 2 | 3 | function a() { 4 | return toast; 5 | } 6 | 7 | function b(toast) { 8 | return toast; 9 | } 10 | 11 | function c() { 12 | var toast = 'toast'; 13 | return toast; 14 | } 15 | 16 | function d() { 17 | var toast = 'toast'; 18 | return function () { 19 | return toast; 20 | }; 21 | } 22 | 23 | const e = () => { 24 | return toast; 25 | }; 26 | -------------------------------------------------------------------------------- /test/fixtures/return/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _toast2 = _interopRequireDefault(require("antd/lib/toast")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | function a() { 8 | return _toast2["default"]; 9 | } 10 | 11 | function b(toast) { 12 | return toast; 13 | } 14 | 15 | function c() { 16 | var toast = 'toast'; 17 | return toast; 18 | } 19 | 20 | function d() { 21 | var toast = 'toast'; 22 | return function () { 23 | return toast; 24 | }; 25 | } 26 | 27 | var e = function e() { 28 | return _toast2["default"]; 29 | }; -------------------------------------------------------------------------------- /test/fixtures/specifier-alias/actual.js: -------------------------------------------------------------------------------- 1 | import { Button as Button1 } from 'antd'; 2 | 3 | const foo = Button1.foo 4 | 5 | ReactDOM.render(
6 | xxxx 7 |
); 8 | -------------------------------------------------------------------------------- /test/fixtures/specifier-alias/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var foo = _button["default"].foo; 8 | ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_button["default"], null, "xxxx"))); -------------------------------------------------------------------------------- /test/fixtures/style-library-name/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'element-ui'; 2 | 3 | ReactDOM.render(
4 | 5 |
); 6 | -------------------------------------------------------------------------------- /test/fixtures/style-library-name/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("element-ui/lib/theme-chalk/button"); 4 | 5 | var _button2 = _interopRequireDefault(require("element-ui/lib/button")); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 8 | 9 | ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_button2["default"], null, "xxxx"))); -------------------------------------------------------------------------------- /test/fixtures/super-class/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | 3 | class MyButton extends Button {} 4 | -------------------------------------------------------------------------------- /test/fixtures/super-class/expected.js: -------------------------------------------------------------------------------- 1 | import _Button from "antd/lib/button"; 2 | 3 | class MyButton extends _Button {} -------------------------------------------------------------------------------- /test/fixtures/switch/actual.js: -------------------------------------------------------------------------------- 1 | import { Select } from 'antd'; 2 | 3 | switch(Select){ 4 | case Select: 5 | console.log('foo'); 6 | default: 7 | console.log('bar') 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/switch/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _select = _interopRequireDefault(require("antd/lib/select")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | switch (_select["default"]) { 8 | case _select["default"]: 9 | console.log('foo'); 10 | 11 | default: 12 | console.log('bar'); 13 | } -------------------------------------------------------------------------------- /test/fixtures/transform-to-default-import-array/actual.js: -------------------------------------------------------------------------------- 1 | import { Circle } from 'dt-react-component'; 2 | 3 | ReactDOM.render( 4 | <> 5 |
6 | 运行中 7 |
8 |
9 | 成功 10 |
11 | , 12 | document.getElementById('react-container'), 13 | ); 14 | -------------------------------------------------------------------------------- /test/fixtures/transform-to-default-import-array/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | require("dt-react-component/lib/Circle/style"); 4 | 5 | var _Circle2 = require("dt-react-component/lib/Circle"); 6 | 7 | ReactDOM.render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Circle2.Circle, { 8 | type: "running" 9 | }), " \u8FD0\u884C\u4E2D"), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Circle2.Circle, { 10 | type: "finished", 11 | className: "status_finished" 12 | }), " \u6210\u529F")), document.getElementById('react-container')); -------------------------------------------------------------------------------- /test/fixtures/use-multiple-times/actual.js: -------------------------------------------------------------------------------- 1 | import a from 'a'; 2 | import { Button } from 'antd-mobile'; 3 | 4 | a(Button); 5 | a(Button); 6 | -------------------------------------------------------------------------------- /test/fixtures/use-multiple-times/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd-mobile/lib/button")); 4 | 5 | var _a = _interopRequireDefault(require("a")); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 8 | 9 | (0, _a["default"])(_button["default"]); 10 | (0, _a["default"])(_button["default"]); -------------------------------------------------------------------------------- /test/fixtures/variable-declarator-renamed-import/actual.js: -------------------------------------------------------------------------------- 1 | import { Button as AntButton } from 'antd'; 2 | 3 | const Button = 'Another Button'; 4 | 5 | const a = AntButton; 6 | -------------------------------------------------------------------------------- /test/fixtures/variable-declarator-renamed-import/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var Button = 'Another Button'; 8 | var a = _button["default"]; -------------------------------------------------------------------------------- /test/fixtures/variable-declarator/actual.js: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | 3 | const a = Button; 4 | -------------------------------------------------------------------------------- /test/fixtures/variable-declarator/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _button = _interopRequireDefault(require("antd/lib/button")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var a = _button["default"]; -------------------------------------------------------------------------------- /test/fixtures/variable-scope/actual.js: -------------------------------------------------------------------------------- 1 | import { message } from 'antd'; 2 | 3 | message('xxx'); 4 | 5 | message.error('error'); 6 | 7 | const testIf = (message) => { 8 | if (message) return message 9 | } 10 | 11 | const testIf2 = () => { 12 | if (message) return message 13 | } 14 | 15 | const testExpression = message => message + 'test' 16 | const testExpression2 = () => message + 'test' 17 | 18 | const testNestFunction = message => a => message 19 | const testNestFunction2 = () => a => message 20 | const testFunction = message => { 21 | message.error('error'); 22 | return message.test; 23 | } 24 | const testFunction1 = () => message.error('error'); 25 | const testFunction2 = message => message.error('error'); 26 | const testFunction3 = message => { 27 | if(message) { 28 | message = message.test.message; 29 | for (let i = 0; i < 10; i++) { 30 | const message = i; 31 | if (message > 4) { 32 | return message; 33 | } 34 | } 35 | } 36 | message = null; 37 | return message; 38 | } 39 | 40 | function App() { 41 | const message = 'xxx'; 42 | return
{message}
; 43 | } 44 | -------------------------------------------------------------------------------- /test/fixtures/variable-scope/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _message3 = _interopRequireDefault(require("antd/lib/message")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | (0, _message3["default"])('xxx'); 8 | 9 | _message3["default"].error('error'); 10 | 11 | var testIf = function testIf(message) { 12 | if (message) return message; 13 | }; 14 | 15 | var testIf2 = function testIf2() { 16 | if (_message3["default"]) return _message3["default"]; 17 | }; 18 | 19 | var testExpression = function testExpression(message) { 20 | return message + 'test'; 21 | }; 22 | 23 | var testExpression2 = function testExpression2() { 24 | return _message3["default"] + 'test'; 25 | }; 26 | 27 | var testNestFunction = function testNestFunction(message) { 28 | return function (a) { 29 | return message; 30 | }; 31 | }; 32 | 33 | var testNestFunction2 = function testNestFunction2() { 34 | return function (a) { 35 | return _message3["default"]; 36 | }; 37 | }; 38 | 39 | var testFunction = function testFunction(message) { 40 | message.error('error'); 41 | return message.test; 42 | }; 43 | 44 | var testFunction1 = function testFunction1() { 45 | return _message3["default"].error('error'); 46 | }; 47 | 48 | var testFunction2 = function testFunction2(message) { 49 | return message.error('error'); 50 | }; 51 | 52 | var testFunction3 = function testFunction3(message) { 53 | if (message) { 54 | message = message.test.message; 55 | 56 | for (var i = 0; i < 10; i++) { 57 | var _message2 = i; 58 | 59 | if (_message2 > 4) { 60 | return _message2; 61 | } 62 | } 63 | } 64 | 65 | message = null; 66 | return message; 67 | }; 68 | 69 | function App() { 70 | var message = 'xxx'; 71 | return /*#__PURE__*/React.createElement("div", null, message); 72 | } -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | import { transformFileSync, transform } from '@babel/core'; 2 | import { join } from 'path'; 3 | import { readdirSync, readFileSync } from 'fs'; 4 | import plugin from '../src/index'; 5 | 6 | describe('index', () => { 7 | afterEach(() => { 8 | global.__clearBabelTreasurePlugin(); 9 | }); 10 | 11 | const fixturesDir = join(__dirname, 'fixtures'); 12 | let fixtures = readdirSync(fixturesDir); 13 | const onlyFixtures = fixtures.filter(fixture => fixture.indexOf('-only') > -1); 14 | 15 | if (onlyFixtures.length) { 16 | fixtures = onlyFixtures; 17 | } 18 | 19 | fixtures.map(caseName => { 20 | const fixtureDir = join(fixturesDir, caseName); 21 | const actualFile = join(fixtureDir, 'actual.js'); 22 | const expectedFile = join(fixtureDir, 'expected.js'); 23 | 24 | it(`should work with ${caseName.split('-').join(' ')}`, () => { 25 | let pluginWithOpts; 26 | caseName = caseName.replace(/-only$/, ''); 27 | if (caseName === 'import-css') { 28 | pluginWithOpts = [plugin, { libraryName: 'antd', style: true }]; 29 | } else if (caseName === 'material-ui') { 30 | pluginWithOpts = [ 31 | plugin, 32 | { libraryName: 'material-ui', libraryDirectory: '', camel2DashComponentName: false }, 33 | ]; 34 | } else if (caseName === 'keep-named-import') { 35 | pluginWithOpts = [plugin, { libraryName: 'stream', transformToDefaultImport: false }]; 36 | } else if (caseName === 'react-toolbox') { 37 | pluginWithOpts = [ 38 | plugin, 39 | { libraryName: 'react-toolbox', camel2UnderlineComponentName: true }, 40 | ]; 41 | } else if (caseName === 'use-multiple-times') { 42 | pluginWithOpts = [plugin, { libraryName: 'antd-mobile' }]; 43 | } else if (caseName === 'file-name') { 44 | pluginWithOpts = [ 45 | plugin, 46 | { 47 | libraryName: 'antd-mobile-fake-2.0', 48 | fileName: 'index.native', 49 | }, 50 | ]; 51 | } else if (caseName === 'custom-name') { 52 | pluginWithOpts = [ 53 | plugin, 54 | { 55 | libraryName: 'plat/antd', 56 | customName: name => `antd/lib/${name}`, 57 | }, 58 | ]; 59 | } else if (caseName === 'custom-name-source-file') { 60 | pluginWithOpts = [ 61 | plugin, 62 | { 63 | libraryName: 'plat/antd', 64 | customName: join(__dirname, 'fixtures', 'custom-name-source-file', 'customName.js'), 65 | }, 66 | ]; 67 | } else if (caseName === 'custom-style-path') { 68 | pluginWithOpts = [ 69 | plugin, 70 | { 71 | libraryName: 'antd', 72 | style: name => `${name}/style/2x`, 73 | }, 74 | ]; 75 | } else if (caseName === 'custom-style-path-ignore') { 76 | pluginWithOpts = [ 77 | plugin, 78 | { 79 | libraryName: 'antd', 80 | style: name => { 81 | if (name === 'antd/lib/animation') { 82 | return false; 83 | } 84 | return `${name}/style/2x`; 85 | }, 86 | }, 87 | ]; 88 | } else if (caseName === 'style-library-name') { 89 | pluginWithOpts = [ 90 | plugin, 91 | { 92 | libraryName: 'element-ui', 93 | styleLibraryDirectory: 'lib/theme-chalk', 94 | }, 95 | ]; 96 | } else if (caseName === 'custom-style-name') { 97 | pluginWithOpts = [ 98 | plugin, 99 | { 100 | libraryName: 'element-ui', 101 | customStyleName: name => `element-ui/lib/theme-light/${name}`, 102 | }, 103 | ]; 104 | } else { 105 | pluginWithOpts = [plugin, { libraryName: 'antd' }]; 106 | } 107 | 108 | const actual = (function() { 109 | if (caseName === 'modules-false') { 110 | return transform(readFileSync(actualFile), { 111 | presets: ['@babel/preset-env', '@babel/preset-react'], 112 | plugins: [[plugin, { libraryName: 'antd', style: true }]], 113 | }).code; 114 | } else if (caseName === 'multiple-libraries') { 115 | return transformFileSync(actualFile, { 116 | presets: ['@babel/preset-react'], 117 | plugins: [ 118 | [plugin, { libraryName: 'antd' }, 'antd'], 119 | [plugin, { libraryName: 'antd-mobile' }, 'antd-mobile'], 120 | ], 121 | }).code; 122 | } else if (caseName === 'multiple-libraries-hilojs') { 123 | return transformFileSync(actualFile, { 124 | presets: ['@babel/preset-react'], 125 | plugins: [ 126 | [plugin, { libraryName: 'antd' }, 'antd'], 127 | [ 128 | plugin, 129 | { 130 | libraryName: 'hilojs', 131 | customName(name) { 132 | switch (name) { 133 | case 'class': 134 | return `hilojs/core/${name}`; 135 | default: 136 | return `hilojs/${name}`; 137 | } 138 | }, 139 | }, 140 | 'hilojs', 141 | ], 142 | ], 143 | }).code; 144 | } else if (caseName === 'transform-to-default-import-array') { 145 | return transformFileSync(actualFile, { 146 | presets: ['@babel/preset-env', '@babel/preset-react'], 147 | plugins: [ 148 | [ 149 | plugin, 150 | { 151 | libraryName: 'dt-react-component', 152 | transformToDefaultImport: ['Circle'], 153 | camel2DashComponentName: 'upper', 154 | 155 | style: true, 156 | }, 157 | ], 158 | ], 159 | }).code; 160 | } else if (caseName === 'camel2-dash-name-lower') { 161 | return transformFileSync(actualFile, { 162 | presets: ['@babel/preset-env', '@babel/preset-react'], 163 | plugins: [ 164 | [ 165 | plugin, 166 | { 167 | libraryName: 'dt-react-component', 168 | style: 'css', 169 | camel2DashComponentName: 'lower', 170 | customName: { 171 | GoBack: 'dt-react-component/lib/go-back', 172 | }, 173 | }, 174 | ], 175 | ], 176 | }).code; 177 | } else if (caseName === 'super-class') { 178 | return transformFileSync(actualFile, { 179 | plugins: [[plugin, { libraryName: 'antd' }]], 180 | babelrc: false, 181 | }).code; 182 | } else { 183 | return transformFileSync(actualFile, { 184 | presets: ['@babel/preset-react'], 185 | plugins: [pluginWithOpts || plugin], 186 | }).code; 187 | } 188 | })(); 189 | 190 | if (onlyFixtures.length) { 191 | console.warn(); 192 | console.warn(actual); 193 | } 194 | 195 | const expected = readFileSync(expectedFile, 'utf-8'); 196 | expect(actual.trim()).toEqual(expected.trim()); 197 | }); 198 | }); 199 | }); 200 | --------------------------------------------------------------------------------