babel-plugin-onex-utils
Advanced tools
| import { NodePath } from '@babel/core'; | ||
| export declare function AddDefaultImported(path: NodePath<any>, packageName: string, imported: string, local?: string): any; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.AddDefaultImported = void 0; | ||
| const helper_module_imports_1 = require("@babel/helper-module-imports"); | ||
| function AddDefaultImported(path, packageName, imported, local) { | ||
| let source = packageName; | ||
| if (imported && imported !== 'default') { | ||
| source = `${source}/build/${imported}`; | ||
| } | ||
| else { | ||
| source = `${source}/${imported}`; | ||
| } | ||
| return helper_module_imports_1.addDefault(path, source, { | ||
| nameHint: local || imported, | ||
| }); | ||
| } | ||
| exports.AddDefaultImported = AddDefaultImported; |
+11
-0
@@ -6,2 +6,13 @@ # Change Log | ||
| # [0.2.0](https://github.com/unity-template/onex-utils-packages/compare/babel-plugin-onex-utils@0.1.0...babel-plugin-onex-utils@0.2.0) (2021-01-28) | ||
| ### Features | ||
| * 🎸 构建添加build前缀 ([4790e47](https://github.com/unity-template/onex-utils-packages/commit/4790e4775b25f3ba670bdce3a49f7e4cdc6ddda1)) | ||
| # 0.1.0 (2021-01-24) | ||
@@ -8,0 +19,0 @@ |
+5
-5
@@ -28,3 +28,3 @@ "use strict"; | ||
| const traverse_1 = __importDefault(require("@babel/traverse")); | ||
| const module_import_1 = require("./utils/module-import"); | ||
| const importModule_1 = require("./utils/importModule"); | ||
| const findImportList_1 = require("./utils/findImportList"); | ||
@@ -70,3 +70,3 @@ const const_1 = require("./const"); | ||
| if (imported && imported !== 'default') { | ||
| const INode = module_import_1.AddDefaultImported(refPath, source, imported, local); | ||
| const INode = importModule_1.AddDefaultImported(refPath, source, imported, local); | ||
| refPath.replaceWith(INode); | ||
@@ -82,3 +82,3 @@ } | ||
| return; | ||
| const INode = module_import_1.AddDefaultImported(refPath, source, key); | ||
| const INode = importModule_1.AddDefaultImported(refPath, source, key); | ||
| parentPath.replaceWith(INode); | ||
@@ -89,3 +89,3 @@ } | ||
| // BUG: 直接使用default相关处理 | ||
| const INode = module_import_1.AddDefaultImported(refPath, source, 'default'); | ||
| const INode = importModule_1.AddDefaultImported(refPath, source, 'default'); | ||
| refPath.replaceWith(INode); | ||
@@ -120,3 +120,3 @@ } | ||
| const importName = types.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value; | ||
| const result = module_import_1.AddDefaultImported(path, packageName, importName, spec.local.name); | ||
| const result = importModule_1.AddDefaultImported(path, packageName, importName, spec.local.name); | ||
| spec.local = result; | ||
@@ -123,0 +123,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
| /** | ||
| * @remarks default类型的处理 | ||
| * @remarks default类型引用的处理 | ||
| * ```ts | ||
@@ -31,0 +31,0 @@ * import utils from 'onex-utils'; |
+2
-2
| { | ||
| "name": "babel-plugin-onex-utils", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "> TODO: description", | ||
@@ -37,3 +37,3 @@ "author": "云墨 <lg208143@alibaba-inc.com>", | ||
| }, | ||
| "gitHead": "697502670773d7b0adfb4c7e8764ad8e4dc68742" | ||
| "gitHead": "14a4061d5bc2784e2595038c8594edd164198673" | ||
| } |
+2
-2
@@ -26,5 +26,5 @@ # [babel-plugin-onex-utils](https://www.npmjs.com/package/babel-plugin-onex-utils) | ||
| var _map2 = _interopRequireDefault(require("onex-utils/map")); | ||
| var _map2 = _interopRequireDefault(require("onex-utils/build/map")); | ||
| var _capitalize2 = _interopRequireDefault(require("onex-utils/capitalize")); | ||
| var _capitalize2 = _interopRequireDefault(require("onex-utils/build/capitalize")); | ||
@@ -31,0 +31,0 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
| import { NodePath } from '@babel/core'; | ||
| export declare function AddDefaultImported(path: NodePath<any>, packageName: string, imported: string, local?: string): any; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.AddDefaultImported = void 0; | ||
| const helper_module_imports_1 = require("@babel/helper-module-imports"); | ||
| function AddDefaultImported(path, packageName, imported, local) { | ||
| const source = `${packageName}/${imported}`; | ||
| return helper_module_imports_1.addDefault(path, source, { | ||
| nameHint: local || imported, | ||
| }); | ||
| } | ||
| exports.AddDefaultImported = AddDefaultImported; |
15087
3.19%285
2.15%