"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getHelperOutputPath=getHelperOutputPath,exports.getHelperContent=getHelperContent,exports.getHelperDeps=getHelperDeps,exports.appendHelpers=appendHelpers,exports.isValidHelperFunc=isValidHelperFunc,exports.getHelperName=getHelperName;const tslib_1=require("tslib"),path=tslib_1.__importStar(require("path")),tools_1=require("./tools"),babel_helper_1=require("./babel_helper"),swc_helper_1=require("./swc_helper"),pluginconfig_1=require("../modules/corecompiler/summer/pluginconfig");function getHelperOutputPath(e){return(0,pluginconfig_1.couldUseSWCMode)(e)?(0,swc_helper_1.getSWCOutputPath)(e):(0,babel_helper_1.getBabelOutputPath)(e)}function getHelperContent(e,t){const r=getHelperOutputPath(e);return(0,pluginconfig_1.couldUseSWCMode)(e)?(0,swc_helper_1.getHelperContent)(t,r):(0,babel_helper_1.getHelperContent)(t,r)}function getHelperDeps(e,t){const r=getHelperOutputPath(e);return(0,pluginconfig_1.couldUseSWCMode)(e)?(0,swc_helper_1.getHelperDeps)(t,r):Object.keys((0,babel_helper_1.getHelperDeps)(Array.from(t),r))}async function appendHelpers(e,t,r,p){const l=getHelperDeps(e.setting,t).map(async t=>{try{const l=await getHelperContent(e.setting,t),n=(0,tools_1.normalizePath)(path.posix.join(r,t.endsWith(".js")?""+t:t+".js"));p[n]||(p[n]=l)}catch(e){if("EEXIST"===e.code);else if("ENOENT"!==e.code)throw e}});return Promise.all(l)}function isValidHelperFunc(e){return(0,babel_helper_1.isValidBabelHelperFunc)(e)?"babel":(0,swc_helper_1.isValidSWCHelperFunc)(e)?"swc":void 0}function getHelperName(e,t){const r=getHelperOutputPath(e),p=t.substr(0,t.indexOf(r)+r.length);return t.replace(p,"").replace(/\/(helpers\/)?/,"").replace(/\.js$/,"")}