@zakijs/plugin-compiler-alipay
Version:
mor complier plugin for alipay mini program
75 lines • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.templateProcessor = void 0;
const constants_1 = require("./constants");
const templateProcessorToAlipay_1 = require("./templateProcessorToAlipay");
const templateProcessorToOther_1 = require("./templateProcessorToOther");
/**
* 是否需要处理 微信 DSL => 支付宝或支付宝类似小程序
* @param options
* @returns
*/
function shouldProcessToAlipay(options) {
// 目标是 支付宝或支付宝类似小程序
// 且源码不是 支付宝 小程序
// 且当前文件不是 支付宝 DSL 源文件
if ((0, constants_1.isSimilarTarget)(options.userConfig.target) &&
options.userConfig.sourceType !== constants_1.target &&
options.fileInfo.extname !== constants_1.fileType.template) {
return true;
}
else {
return false;
}
}
/**
* 是否需要处理 支付宝 DSL => 其他小程序
*/
function shouldProcessToOther(options) {
// 目标不是 支付宝或支付宝类似小程序
// 且源码为 支付宝 小程序
// 且当前文件为 支付宝 DSL 源文件
if (!(0, constants_1.isSimilarTarget)(options.userConfig.target) &&
options.userConfig.sourceType === constants_1.target &&
options.fileInfo.extname === constants_1.fileType.template) {
return true;
}
else {
return false;
}
}
/**
* 自定义 template 处理
*/
exports.templateProcessor = {
onNode(node, options) {
if (shouldProcessToAlipay(options)) {
templateProcessorToAlipay_1.templateProcessorToAlipay.onNode(node);
}
else if (shouldProcessToOther(options)) {
templateProcessorToOther_1.templateProcessorToOther.onNode(node, options);
}
},
onNodeExit(node, options, context) {
if (shouldProcessToAlipay(options)) {
templateProcessorToAlipay_1.templateProcessorToAlipay.onNodeExit(node, options, context);
}
else if (shouldProcessToOther(options)) {
templateProcessorToOther_1.templateProcessorToOther.onNodeExit(node, options, context);
}
},
onNodeAttr(attrName, node, options, context) {
if (shouldProcessToAlipay(options)) {
templateProcessorToAlipay_1.templateProcessorToAlipay.onNodeAttr(attrName, node);
}
else if (shouldProcessToOther(options)) {
templateProcessorToOther_1.templateProcessorToOther.onNodeAttr(attrName, node, options, context);
}
},
onNodeAttrExit(attrName, node, options, context) {
if (shouldProcessToAlipay(options)) {
templateProcessorToAlipay_1.templateProcessorToAlipay.onNodeAttrExit(attrName, node, options, context);
}
}
};
//# sourceMappingURL=templateProcessor.js.map