diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 23:32:20 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 23:32:20 +0800 |
commit | 4cad0fbeb52a1e71a82155045ce00076208013f5 (patch) | |
tree | 98290c18ffea75e2547f5c3c6f6bf82d2ccf11aa /babel-import-promise | |
parent | 431e4fc9d1657a50ebc34b8ac24f9bfaea06417f (diff) | |
download | SoopyV2-4cad0fbeb52a1e71a82155045ce00076208013f5.tar.gz SoopyV2-4cad0fbeb52a1e71a82155045ce00076208013f5.tar.bz2 SoopyV2-4cad0fbeb52a1e71a82155045ce00076208013f5.zip |
FINALLY ITS WORKING
Diffstat (limited to 'babel-import-promise')
-rw-r--r-- | babel-import-promise/babel-import-promise.mjs | 31 | ||||
-rw-r--r-- | babel-import-promise/package.json | 5 |
2 files changed, 36 insertions, 0 deletions
diff --git a/babel-import-promise/babel-import-promise.mjs b/babel-import-promise/babel-import-promise.mjs new file mode 100644 index 0000000..bdde752 --- /dev/null +++ b/babel-import-promise/babel-import-promise.mjs @@ -0,0 +1,31 @@ +export default function ({ types: t }) { + return { + visitor: { + Program(path, state) { + let shouldAdd = false + const MyVisitor = { + Function: { + enter: function enter(path) { + if (path.node.async) { + shouldAdd = true + } + } + }, + Identifier(path) { + if (path.node.name === "Promise") { + shouldAdd = true + } + } + }; + path.traverse(MyVisitor) + if (shouldAdd) { + let depth = state.filename.replace(state.cwd, "").split("\\").length - 2 + const identifier = t.identifier('Promise'); + const importDefaultSpecifier = t.importDefaultSpecifier(identifier); + const importDeclaration = t.importDeclaration([importDefaultSpecifier], t.stringLiteral("../".repeat(depth) + 'PromiseV2')); + path.unshiftContainer('body', importDeclaration); + } + } + } + }; +};
\ No newline at end of file diff --git a/babel-import-promise/package.json b/babel-import-promise/package.json new file mode 100644 index 0000000..e43c0c5 --- /dev/null +++ b/babel-import-promise/package.json @@ -0,0 +1,5 @@ +{ + "name": "babel-import-promise", + "version": "1.0.0", + "module": "babel-import-promise.mjs" +}
\ No newline at end of file |