From 91ce2e47013f18e85a08bc9d368130673b67f6ea Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Sun, 18 Sep 2022 08:54:52 +0800 Subject: + make babel add fetch import + reduce hot reload cooldown --- babel-import-promise/babel-import-promise.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'babel-import-promise') diff --git a/babel-import-promise/babel-import-promise.mjs b/babel-import-promise/babel-import-promise.mjs index 10aee6a..24cc28f 100644 --- a/babel-import-promise/babel-import-promise.mjs +++ b/babel-import-promise/babel-import-promise.mjs @@ -25,6 +25,23 @@ export default function ({ types: t }) { const importDeclaration = t.importDeclaration([importDefaultSpecifier], t.stringLiteral("../".repeat(depth) + 'PromiseV2')); path.unshiftContainer('body', importDeclaration); } + + let shouldAdd2 = false + const MyVisitor2 = { + Identifier(path) { + if (path.node.name === "fetch") { + shouldAdd = true + } + } + }; + path.traverse(MyVisitor2) + if (shouldAdd2) { + let depth = state.filename.replace(state.cwd, "").split(/[\\/]/g).length - 3 + const identifier = t.identifier('fetch'); + const importDefaultSpecifier = t.importDefaultSpecifier(identifier); + const importDeclaration = t.importDeclaration([importDefaultSpecifier], t.stringLiteral("../".repeat(depth) + 'utils/networkUtils')); + path.unshiftContainer('body', importDeclaration); + } } } }; -- cgit