xhs-mp-compiler-cli 1.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +42 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +84 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.js +22 -0
- package/dist/dev-server/index.d.ts +3 -0
- package/dist/dev-server/index.js +62 -0
- package/dist/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/dev-server/lib/ensurePort.js +32 -0
- package/dist/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/dev-server/lib/openBrowser.js +23 -0
- package/dist/dev-server/lib/openChrome.applescript +78 -0
- package/dist/globalData/SjsModule.d.ts +32 -0
- package/dist/globalData/SjsModule.js +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +118 -0
- package/dist/types/index.d.ts +110 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/combineExtJson.d.ts +3 -0
- package/dist/utils/combineExtJson.js +74 -0
- package/dist/utils/common.d.ts +7 -0
- package/dist/utils/common.js +35 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/getCssSuffixName.d.ts +1 -0
- package/dist/utils/getCssSuffixName.js +9 -0
- package/dist/utils/getMlSuffixName.d.ts +1 -0
- package/dist/utils/getMlSuffixName.js +6 -0
- package/dist/utils/getPrefixName.d.ts +1 -0
- package/dist/utils/getPrefixName.js +6 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/transformAppJson.d.ts +16 -0
- package/dist/utils/transformAppJson.js +199 -0
- package/dist/utils/validateAppJson.d.ts +4 -0
- package/dist/utils/validateAppJson.js +111 -0
- package/dist/webpack-config/index.d.ts +4 -0
- package/dist/webpack-config/index.js +41 -0
- package/dist/webpack-config/lib/const.d.ts +13 -0
- package/dist/webpack-config/lib/const.js +15 -0
- package/dist/webpack-config/lib/css.d.ts +2 -0
- package/dist/webpack-config/lib/css.js +41 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +13 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.js +40 -0
- package/dist/webpack-config/lib/tagTransformMap.d.ts +35 -0
- package/dist/webpack-config/lib/tagTransformMap.js +38 -0
- package/dist/webpack-config/lib/utils.d.ts +5 -0
- package/dist/webpack-config/lib/utils.js +37 -0
- package/dist/webpack-config/loaders/component-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-loader.js +31 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +24 -0
- package/dist/webpack-config/loaders/mini-style-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/mini-style-loader.js +69 -0
- package/dist/webpack-config/loaders/ml-loader/index.d.ts +3 -0
- package/dist/webpack-config/loaders/ml-loader/index.js +66 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.js +107 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.d.ts +6 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.js +64 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.js +41 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.js +18 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.js +21 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.js +185 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.js +73 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.js +42 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.js +17 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.js +23 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js +25 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.d.ts +4 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.js +89 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.js +33 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.js +61 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.js +35 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.js +72 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.js +74 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.js +12 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.js +16 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.d.ts +10 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.js +80 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.js +41 -0
- package/dist/webpack-config/loaders/render-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/render-entry-loader.js +50 -0
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/service-entry-loader.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/index.js +93 -0
- package/dist/webpack-config/loaders/utils.d.ts +13 -0
- package/dist/webpack-config/loaders/utils.js +41 -0
- package/dist/webpack-config/loaders/wxss-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/wxss-loader.js +76 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +19 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +205 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +8 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +40 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +36 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +71 -0
- package/dist/webpack-config/presets/babel.d.ts +8 -0
- package/dist/webpack-config/presets/babel.js +57 -0
- package/dist/webpack-config/presets/common.d.ts +4 -0
- package/dist/webpack-config/presets/common.js +40 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +23 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +87 -0
- package/dist/webpack-config/presets/mp/index.d.ts +4 -0
- package/dist/webpack-config/presets/mp/index.js +48 -0
- package/dist/webpack-config/presets/prod.d.ts +4 -0
- package/dist/webpack-config/presets/prod.js +85 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +18 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +77 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +9 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +65 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +14 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +42 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +31 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.js +124 -0
- package/dist/webpack-config/presets/render/index.d.ts +4 -0
- package/dist/webpack-config/presets/render/index.js +99 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +36 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +6 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +46 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.js +65 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +27 -0
- package/dist/webpack-config/presets/service/index.d.ts +4 -0
- package/dist/webpack-config/presets/service/index.js +38 -0
- package/package.json +124 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const handleSjsEvent_1 = require("./handleSjsEvent");
|
|
6
|
+
const ML_EVENTS = [
|
|
7
|
+
'touchstart',
|
|
8
|
+
'touchend',
|
|
9
|
+
'touchmove',
|
|
10
|
+
'touchcancel',
|
|
11
|
+
'tap',
|
|
12
|
+
'longtap',
|
|
13
|
+
'longpress',
|
|
14
|
+
];
|
|
15
|
+
const animationEvents = ['transitionend', 'animationiteration', 'animationstart', 'animationend'];
|
|
16
|
+
const handleBindAttribute = (value, attribute, node, filePath, importBy) => {
|
|
17
|
+
var _a;
|
|
18
|
+
// todo bindrefresherpulling 暂不支持
|
|
19
|
+
// 考虑 bindrefresherpulling="{{refresh.onPulling}}" 转换
|
|
20
|
+
if (attribute === 'bindrefresherpulling') {
|
|
21
|
+
return delete node.attribs[attribute];
|
|
22
|
+
}
|
|
23
|
+
let eventName = '';
|
|
24
|
+
const modifiers = [];
|
|
25
|
+
if (attribute.indexOf(':') !== -1) {
|
|
26
|
+
const splitAttribute = attribute.split(':');
|
|
27
|
+
eventName = splitAttribute[1];
|
|
28
|
+
// bind:touchstart
|
|
29
|
+
// capture-bind:touchstart
|
|
30
|
+
splitAttribute[0].split('-').forEach((item) => {
|
|
31
|
+
if (item !== 'bind') {
|
|
32
|
+
if (item === 'catch') {
|
|
33
|
+
modifiers.push('stop');
|
|
34
|
+
}
|
|
35
|
+
else if (item === 'capture') {
|
|
36
|
+
modifiers.push('capture');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
eventName = attribute.substr(4);
|
|
43
|
+
}
|
|
44
|
+
if ((0, handleSjsEvent_1.isSjsEvent)(value, node, importBy, filePath)) {
|
|
45
|
+
value = (0, handleSjsEvent_1.createSjsEventDeclaration)(value, node);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if ((_a = (0, utils_1.matchMustache)(value)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
49
|
+
node.attribs[`:${xhs_mp_compiler_utils_1.CompileAddedAttrs.EventMap}:${eventName}`] = `${(0, utils_1.injectContext2Exp)(value, node, 1)}`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
node.attribs[`:${xhs_mp_compiler_utils_1.CompileAddedAttrs.EventMap}:${eventName}`] = `'${value}'`;
|
|
53
|
+
}
|
|
54
|
+
value = `(...args) => context[${(0, utils_1.injectContext2Exp)(value, node, 1)}](...args)`;
|
|
55
|
+
}
|
|
56
|
+
// ml通用事件走自定义指令的方式
|
|
57
|
+
if (ML_EVENTS.includes(eventName)) {
|
|
58
|
+
if (modifiers.length > 0) {
|
|
59
|
+
node.attribs[`v-finger:${eventName}.${modifiers.join('.')}`] = `${value}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
node.attribs[`v-finger:${eventName}`] = `${value}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (animationEvents.includes(eventName)) {
|
|
66
|
+
node.attribs[`@xhs_animate_${eventName}`] = `${value}`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
node.attribs[`@${eventName}`] = `${value}`;
|
|
70
|
+
}
|
|
71
|
+
return delete node.attribs[attribute];
|
|
72
|
+
};
|
|
73
|
+
exports.default = handleBindAttribute;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* block 特性:
|
|
3
|
+
*
|
|
4
|
+
* - block 不支持 hidden 等模板语法,为避免其影响 vue 下行为,需要删除
|
|
5
|
+
* - block 不支持 style、class 等属性
|
|
6
|
+
* - block 仅支持 xhs:for、xhs:if、xhs:else、xhs:elif slot模板语法
|
|
7
|
+
* - block 支持嵌套
|
|
8
|
+
*
|
|
9
|
+
* 解决方案:
|
|
10
|
+
* vue template 在属性存在 v-if 情况下,会提取他的内容作为条件块,因此结合 v-if = true 可以实现 block
|
|
11
|
+
*/
|
|
12
|
+
declare function handleBlockTag(node: any): void;
|
|
13
|
+
export default handleBlockTag;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getPrefixName_1 = __importDefault(require("../../../../../utils/getPrefixName"));
|
|
7
|
+
/**
|
|
8
|
+
* block 特性:
|
|
9
|
+
*
|
|
10
|
+
* - block 不支持 hidden 等模板语法,为避免其影响 vue 下行为,需要删除
|
|
11
|
+
* - block 不支持 style、class 等属性
|
|
12
|
+
* - block 仅支持 xhs:for、xhs:if、xhs:else、xhs:elif slot模板语法
|
|
13
|
+
* - block 支持嵌套
|
|
14
|
+
*
|
|
15
|
+
* 解决方案:
|
|
16
|
+
* vue template 在属性存在 v-if 情况下,会提取他的内容作为条件块,因此结合 v-if = true 可以实现 block
|
|
17
|
+
*/
|
|
18
|
+
function handleBlockTag(node) {
|
|
19
|
+
node.name = 'template';
|
|
20
|
+
Object.keys(node.attribs).forEach(key => {
|
|
21
|
+
if (![
|
|
22
|
+
`${(0, getPrefixName_1.default)()}:for-item`,
|
|
23
|
+
`${(0, getPrefixName_1.default)()}:for-index`,
|
|
24
|
+
`${(0, getPrefixName_1.default)()}:for`,
|
|
25
|
+
`${(0, getPrefixName_1.default)()}:for-items`,
|
|
26
|
+
`${(0, getPrefixName_1.default)()}:key`,
|
|
27
|
+
`${(0, getPrefixName_1.default)()}:if`,
|
|
28
|
+
`${(0, getPrefixName_1.default)()}:else`,
|
|
29
|
+
`${(0, getPrefixName_1.default)()}:elif`,
|
|
30
|
+
'slot',
|
|
31
|
+
].includes(key)) {
|
|
32
|
+
delete node.attribs[key];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (typeof node.attribs[`${(0, getPrefixName_1.default)()}:if`] === 'undefined' &&
|
|
36
|
+
typeof node.attribs[`${(0, getPrefixName_1.default)()}:else`] === 'undefined' &&
|
|
37
|
+
typeof node.attribs[`${(0, getPrefixName_1.default)()}:elif`] === 'undefined' &&
|
|
38
|
+
typeof node.attribs[`${(0, getPrefixName_1.default)()}:for`] === 'undefined') {
|
|
39
|
+
node.attribs[`v-if`] = 'true';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = handleBlockTag;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
4
|
+
const handleSjsEvent_1 = require("./handleSjsEvent");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const handleCatchAttribute = (value, attribute, node, filePath, importBy) => {
|
|
7
|
+
var _a;
|
|
8
|
+
let eventName = '';
|
|
9
|
+
if (attribute.indexOf(':') !== -1) {
|
|
10
|
+
eventName = attribute.split(':')[1];
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
eventName = attribute.substr(5);
|
|
14
|
+
}
|
|
15
|
+
if ((0, handleSjsEvent_1.isSjsEvent)(value, node, importBy, filePath)) {
|
|
16
|
+
value = (0, handleSjsEvent_1.createSjsEventDeclaration)(value, node);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if ((_a = (0, utils_1.matchMustache)(value)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
20
|
+
node.attribs[`:${xhs_mp_compiler_utils_1.CompileAddedAttrs.EventMap}:${eventName}`] = `${(0, utils_1.injectContext2Exp)(value, node, 1)}`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
node.attribs[`:${xhs_mp_compiler_utils_1.CompileAddedAttrs.EventMap}:${eventName}`] = `'${value}'`;
|
|
24
|
+
}
|
|
25
|
+
value = `(...args) => context[${(0, utils_1.injectContext2Exp)(value, node, 1)}]?.(...args)`;
|
|
26
|
+
}
|
|
27
|
+
node.attribs[`v-finger:${eventName}.stop`] = `${value}`;
|
|
28
|
+
return delete node.attribs[attribute];
|
|
29
|
+
};
|
|
30
|
+
exports.default = handleCatchAttribute;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const handleClassAttribute = (attribute, value, node) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const { CalcClass } = xhs_mp_compiler_utils_1.CompileCallRuntimeMethodsNames;
|
|
8
|
+
if ((_a = (0, utils_1.matchMustache)(value)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
9
|
+
const className = (0, utils_1.injectContext2Exp)(value, node, 1);
|
|
10
|
+
node.attribs[`:${attribute}`] = `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${CalcClass}', ${className}, 1)`;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
node.attribs[`:${attribute}`] = `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${CalcClass}', \`${value}\`, 1)`;
|
|
14
|
+
}
|
|
15
|
+
delete node.attribs[attribute];
|
|
16
|
+
};
|
|
17
|
+
exports.default = handleClassAttribute;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
const handleDataAttribute = (value, attribute, node) => {
|
|
5
|
+
const dynamicValue = (0, utils_1.matchMustache)(value);
|
|
6
|
+
if ((dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) === 1 && value.startsWith('{{') && value.endsWith('}}')) {
|
|
7
|
+
node.attribs[`:${attribute}`] = (0, utils_1.injectContext2Exp)(value, node, 3);
|
|
8
|
+
delete node.attribs[attribute];
|
|
9
|
+
}
|
|
10
|
+
else if (value === '') {
|
|
11
|
+
node.attribs[`:${attribute}`] = "true";
|
|
12
|
+
delete node.attribs[attribute];
|
|
13
|
+
}
|
|
14
|
+
else if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
|
|
15
|
+
node.attribs[`:${attribute}`] = (0, utils_1.injectContext2Exp)(value, node, 5);
|
|
16
|
+
delete node.attribs[attribute];
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
node.attribs[`:${attribute}`] = `JSON.stringify(\`${value}\`)`;
|
|
20
|
+
delete node.attribs[attribute];
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.default = handleDataAttribute;
|
package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 微信 hidden 特性:
|
|
3
|
+
* - hidden 与 style display 可以同时使用,style display 优先级高(**我们的设计**: hidden 优先级高于 style display,不建议同时使用)
|
|
4
|
+
* - hidden 不对 block 生效
|
|
5
|
+
* - hidden 对所有基础组件生效
|
|
6
|
+
* - hidden 仅隐藏 DOM 元素
|
|
7
|
+
* - hidden="" 认为不隐藏(**我们的设计**:hidden="" 认为隐藏)
|
|
8
|
+
*
|
|
9
|
+
* 解决方案:
|
|
10
|
+
* 通过 v-show 实现
|
|
11
|
+
*/
|
|
12
|
+
declare const handleHiddenAttribute: (value: any, attribute: any, node: any) => void;
|
|
13
|
+
export default handleHiddenAttribute;
|
package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
/**
|
|
5
|
+
* 微信 hidden 特性:
|
|
6
|
+
* - hidden 与 style display 可以同时使用,style display 优先级高(**我们的设计**: hidden 优先级高于 style display,不建议同时使用)
|
|
7
|
+
* - hidden 不对 block 生效
|
|
8
|
+
* - hidden 对所有基础组件生效
|
|
9
|
+
* - hidden 仅隐藏 DOM 元素
|
|
10
|
+
* - hidden="" 认为不隐藏(**我们的设计**:hidden="" 认为隐藏)
|
|
11
|
+
*
|
|
12
|
+
* 解决方案:
|
|
13
|
+
* 通过 v-show 实现
|
|
14
|
+
*/
|
|
15
|
+
const handleHiddenAttribute = (value, attribute, node) => {
|
|
16
|
+
const dynamicValue = (0, utils_1.matchMustache)(value);
|
|
17
|
+
if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
|
|
18
|
+
node.attribs['v-show'] = `!${(0, utils_1.injectContext2Exp)(value, node, 2)}`;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
node.attribs['v-show'] = false;
|
|
22
|
+
}
|
|
23
|
+
delete node.attribs[attribute];
|
|
24
|
+
};
|
|
25
|
+
exports.default = handleHiddenAttribute;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const utils_1 = require("../utils");
|
|
17
|
+
const common_1 = require("../../../../../utils/common");
|
|
18
|
+
const handleImportTag = (node_1, filePath_1, ...args_1) => __awaiter(void 0, [node_1, filePath_1, ...args_1], void 0, function* (node, filePath, importMap = {}) {
|
|
19
|
+
const targetFilePath = (0, common_1.unixResolve)(path_1.default.dirname(filePath), node.attribs.src);
|
|
20
|
+
importMap[filePath] = importMap[filePath] || [targetFilePath];
|
|
21
|
+
if (!importMap[filePath].includes(targetFilePath)) {
|
|
22
|
+
importMap[filePath].push(targetFilePath);
|
|
23
|
+
}
|
|
24
|
+
const compName = (0, utils_1.formatPathToVar)(targetFilePath);
|
|
25
|
+
node.name = 'XhsVueImportInclude';
|
|
26
|
+
node.attribs.compName = compName;
|
|
27
|
+
node.attribs[':getComp'] = 'getComp';
|
|
28
|
+
Reflect.deleteProperty(node.attribs, 'src');
|
|
29
|
+
});
|
|
30
|
+
exports.default = handleImportTag;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const utils_1 = require("../utils");
|
|
17
|
+
const common_1 = require("../../../../../utils/common");
|
|
18
|
+
const handleIncludeTag = (node, filePath, includeMap) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const targetFilePath = (0, common_1.unixResolve)(path_1.default.dirname(filePath), node.attribs.src);
|
|
20
|
+
includeMap[filePath] = includeMap[filePath] || [targetFilePath];
|
|
21
|
+
if (!includeMap[filePath].includes(targetFilePath)) {
|
|
22
|
+
includeMap[filePath].push(targetFilePath);
|
|
23
|
+
}
|
|
24
|
+
const compName = (0, utils_1.formatPathToVar)(targetFilePath);
|
|
25
|
+
node.name = 'XhsVueImportInclude';
|
|
26
|
+
node.attribs.compName = compName;
|
|
27
|
+
node.attribs[':getComp'] = 'getComp';
|
|
28
|
+
Reflect.deleteProperty(node.attribs, 'src');
|
|
29
|
+
});
|
|
30
|
+
exports.default = handleIncludeTag;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// @ts-nocheck
|
|
7
|
+
const clone_1 = __importDefault(require("clone"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const getPrefixName_1 = __importDefault(require("../../../../../utils/getPrefixName"));
|
|
10
|
+
const deleteForAttrs = (node) => {
|
|
11
|
+
;
|
|
12
|
+
[
|
|
13
|
+
`${(0, getPrefixName_1.default)()}:for-item`,
|
|
14
|
+
`${(0, getPrefixName_1.default)()}:for-index`,
|
|
15
|
+
`${(0, getPrefixName_1.default)()}:for`,
|
|
16
|
+
`${(0, getPrefixName_1.default)()}:for-items`,
|
|
17
|
+
`${(0, getPrefixName_1.default)()}:key`,
|
|
18
|
+
].forEach(attr => delete node.attribs[attr]);
|
|
19
|
+
};
|
|
20
|
+
const handleLoopAttribute = (node) => {
|
|
21
|
+
const forItem = node.attribs[`${(0, getPrefixName_1.default)()}:for-item`] || 'item';
|
|
22
|
+
const forIndex = node.attribs[`${(0, getPrefixName_1.default)()}:for-index`] || 'index';
|
|
23
|
+
const loopContext = node.loopContext ? [...node.loopContext, forItem, forIndex] : [forItem, forIndex];
|
|
24
|
+
(0, utils_1.addContextToNode)({
|
|
25
|
+
nodes: node,
|
|
26
|
+
loopContext,
|
|
27
|
+
underTemplate: node.underTemplate,
|
|
28
|
+
});
|
|
29
|
+
const forContent = (0, utils_1.injectContext2Exp)((node.attribs[`${(0, getPrefixName_1.default)()}:for`] || node.attribs[`${(0, getPrefixName_1.default)()}:for-items`]), node, 7);
|
|
30
|
+
/**
|
|
31
|
+
* v-for & v-if 不共存,https://v3.cn.vuejs.org/guide/list.html#%E5%9C%A8-template-%E4%B8%AD%E4%BD%BF%E7%94%A8-v-for
|
|
32
|
+
* 转换为:
|
|
33
|
+
* ```vue
|
|
34
|
+
* <template v-for="item in 10">
|
|
35
|
+
* <template v-if="item % 3 === 0">
|
|
36
|
+
* {{ item }}
|
|
37
|
+
* </template>
|
|
38
|
+
* </template>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
if (node.attribs[`${(0, getPrefixName_1.default)()}:if`]) {
|
|
42
|
+
const condition = node.attribs[`${(0, getPrefixName_1.default)()}:if`];
|
|
43
|
+
const cloneNode = node.cloneNode ? node.cloneNode(true) : (0, clone_1.default)(node);
|
|
44
|
+
deleteForAttrs(cloneNode);
|
|
45
|
+
(0, utils_1.addContextToNode)({
|
|
46
|
+
nodes: cloneNode,
|
|
47
|
+
loopContext,
|
|
48
|
+
underTemplate: node.underTemplate,
|
|
49
|
+
});
|
|
50
|
+
node.name = 'template';
|
|
51
|
+
node.attribs = { 'v-for': `(${forItem}, ${forIndex}) in ${forContent}` };
|
|
52
|
+
node.children = [
|
|
53
|
+
{
|
|
54
|
+
attribs: { [`${(0, getPrefixName_1.default)()}:if`]: condition },
|
|
55
|
+
type: 'tag',
|
|
56
|
+
name: 'template',
|
|
57
|
+
children: [cloneNode],
|
|
58
|
+
loopContext: node.loopContext
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let key = node.attribs[`${(0, getPrefixName_1.default)()}:key`];
|
|
64
|
+
node.attribs['v-for'] = `(${forItem}, ${forIndex}) in ${forContent}`;
|
|
65
|
+
if (key) {
|
|
66
|
+
if (key === '*this' || key === '*item') {
|
|
67
|
+
// *items 官方 demo 有这种写法
|
|
68
|
+
key = forItem;
|
|
69
|
+
}
|
|
70
|
+
else if (key === forIndex) {
|
|
71
|
+
key = forIndex;
|
|
72
|
+
}
|
|
73
|
+
else if (key.match(/{{(.*?)}}/)) {
|
|
74
|
+
// 官方 demo 还有旧的写法
|
|
75
|
+
key = key.match(/{{(.*?)}}/)[1];
|
|
76
|
+
}
|
|
77
|
+
else if (key === forItem) {
|
|
78
|
+
// xhs:key="item" 保持不变
|
|
79
|
+
key = forItem;
|
|
80
|
+
}
|
|
81
|
+
else if (!key.startsWith(`${forItem}.`)) {
|
|
82
|
+
// xhs:key="itemId" -> xhs:key="item.itemId"
|
|
83
|
+
key = `${forItem}.${key}`;
|
|
84
|
+
}
|
|
85
|
+
node.attribs[':key'] = key;
|
|
86
|
+
}
|
|
87
|
+
deleteForAttrs(node);
|
|
88
|
+
};
|
|
89
|
+
exports.default = handleLoopAttribute;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
const handleMLAttribute = (value, attribute, node) => {
|
|
5
|
+
const attrName = attribute.split(':')[1];
|
|
6
|
+
const dynamicValue = (0, utils_1.matchMustache)(value);
|
|
7
|
+
switch (attrName) {
|
|
8
|
+
case 'if':
|
|
9
|
+
if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
|
|
10
|
+
node.attribs['v-if'] = (0, utils_1.injectContext2Exp)(value, node, 2);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
node.attribs['v-if'] = `\`${value}\``;
|
|
14
|
+
}
|
|
15
|
+
delete node.attribs[attribute];
|
|
16
|
+
break;
|
|
17
|
+
case 'else':
|
|
18
|
+
node.attribs['v-else'] = null;
|
|
19
|
+
delete node.attribs[attribute];
|
|
20
|
+
break;
|
|
21
|
+
case 'elif':
|
|
22
|
+
if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
|
|
23
|
+
node.attribs['v-else-if'] = (0, utils_1.injectContext2Exp)(value, node, 2);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
node.attribs['v-if'] = `\`${value}\``;
|
|
27
|
+
}
|
|
28
|
+
delete node.attribs[attribute];
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.default = handleMLAttribute;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
7
|
+
const tagTransformMap_1 = __importDefault(require("../../../../lib/tagTransformMap"));
|
|
8
|
+
const updateTpl = (matchVal, bindChange) => `($event) => {
|
|
9
|
+
${bindChange};postMessage({
|
|
10
|
+
type: 'component',
|
|
11
|
+
event: 'twoWayBindingChange',
|
|
12
|
+
payload: {
|
|
13
|
+
propName: '${matchVal}',
|
|
14
|
+
args: {
|
|
15
|
+
value: $event.detail.value
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
cid: __$cid,
|
|
19
|
+
})
|
|
20
|
+
}`;
|
|
21
|
+
const compUpdateTpl = (matchVal) => `__$RedData__.${matchVal} = $event;
|
|
22
|
+
postMessage({
|
|
23
|
+
type: 'component',
|
|
24
|
+
event: 'twoWayBindingChange',
|
|
25
|
+
payload: {
|
|
26
|
+
propName: '${matchVal}',
|
|
27
|
+
args: {
|
|
28
|
+
value: $event,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
cid: __$cid,
|
|
32
|
+
})`;
|
|
33
|
+
const handleModelAttribute = (value, attribute, node) => {
|
|
34
|
+
const matchVal = value.replace(/{{|}}/g, '').trim();
|
|
35
|
+
const internalComponents = Object.values(tagTransformMap_1.default);
|
|
36
|
+
if (internalComponents.includes(node.name)) {
|
|
37
|
+
let valueProp = 'value';
|
|
38
|
+
if (['xhs-vue-checkbox', 'xhs-vue-switch'].includes(node.name)) {
|
|
39
|
+
valueProp = 'checked';
|
|
40
|
+
}
|
|
41
|
+
if (['xhs-vue-input'].includes(node.name)) {
|
|
42
|
+
node.attribs['@input'] = updateTpl(matchVal, '');
|
|
43
|
+
}
|
|
44
|
+
else if (node.attribs['@change']) {
|
|
45
|
+
const methodName = node.attribs['@change'].match(/context\[`(.*?)`\]/)[1];
|
|
46
|
+
node.attribs['@change'] = updateTpl(matchVal, `${methodName}($event)`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
node.attribs['@change'] = updateTpl(matchVal, '');
|
|
50
|
+
}
|
|
51
|
+
node.attribs[`:${valueProp}`] = `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${xhs_mp_compiler_utils_1.CompileCallRuntimeMethodsNames.ExecExpWithContext}', '${matchVal}', {})`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const name = attribute.split(':')[1];
|
|
55
|
+
node.attribs[`:${name}`] = `__$RedData__.${matchVal}`;
|
|
56
|
+
node.attribs[`@update:${name}`] = compUpdateTpl(matchVal);
|
|
57
|
+
node.attribs[':__xhsVModelProps__'] = `{${name}: '${matchVal}'}`;
|
|
58
|
+
}
|
|
59
|
+
delete node.attribs[attribute];
|
|
60
|
+
};
|
|
61
|
+
exports.default = handleModelAttribute;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
const handleOtherAttribute = (value, attribute, node) => {
|
|
5
|
+
const dynamicValue = (0, utils_1.matchMustache)(value);
|
|
6
|
+
/**
|
|
7
|
+
* 单个的模板语法不能改成模板字符串,否则会发生隐式转换,例如:
|
|
8
|
+
* <input :checked="`${checked}`" type="checkbox" value="first_checkbox" />
|
|
9
|
+
* checked 为 false 时变成了 `false`
|
|
10
|
+
*/
|
|
11
|
+
if ((dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) === 1 && value.startsWith('{{') && value.endsWith('}}')) {
|
|
12
|
+
node.attribs[`:${attribute}`] = (0, utils_1.injectContext2Exp)(value, node, 2);
|
|
13
|
+
delete node.attribs[attribute];
|
|
14
|
+
}
|
|
15
|
+
else if (value === '') {
|
|
16
|
+
const shouldReplaceValueToTrue = !attribute.startsWith('v-slot');
|
|
17
|
+
if (shouldReplaceValueToTrue) {
|
|
18
|
+
node.attribs[`:${attribute}`] = 'true';
|
|
19
|
+
delete node.attribs[attribute];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
/**
|
|
24
|
+
* 对其他使用模板语法 attribs 进行转换 ,例如:
|
|
25
|
+
* <navigator url="/page/component/pages/{{page}}/{{page}}" />
|
|
26
|
+
*/
|
|
27
|
+
// eslint-disable-next-line no-lonely-if
|
|
28
|
+
if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
|
|
29
|
+
// eslint-disable-line
|
|
30
|
+
node.attribs[`:${attribute}`] = (0, utils_1.injectContext2Exp)(value, node, 1);
|
|
31
|
+
delete node.attribs[attribute];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.default = handleOtherAttribute;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 当前是否使用了 sjs 的变量
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function isSjsEvent(value: string, node: any, importBy: string, filePath: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* create a function declaration character
|
|
8
|
+
* @param { value } string - expression
|
|
9
|
+
* @returns { string }
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSjsEventDeclaration(value: string, node: any): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSjsEventDeclaration = exports.isSjsEvent = void 0;
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const SjsModule_1 = __importDefault(require("../../../../../globalData/SjsModule"));
|
|
9
|
+
/**
|
|
10
|
+
* @param { exp } string - expression
|
|
11
|
+
* @param { sjsScopeNames } string[] - sjs module scopes
|
|
12
|
+
* @returns { boolean }
|
|
13
|
+
*/
|
|
14
|
+
function isSjsScopeExp(exp, sjsScopeNames) {
|
|
15
|
+
if ((0, utils_1.matchMustache)(exp)) {
|
|
16
|
+
exp = exp.replace(/{{(.*?)}}/g, (_, $1) => $1);
|
|
17
|
+
}
|
|
18
|
+
exp = exp === null || exp === void 0 ? void 0 : exp.trim();
|
|
19
|
+
return !!sjsScopeNames.find(scope => exp.indexOf(`${scope}.`) === 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 当前是否使用了 sjs 的变量
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
function isSjsEvent(value, node, importBy, filePath) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
let sjsScopeNames = null;
|
|
28
|
+
// 处理 template 模板编译场景下
|
|
29
|
+
if (node.underTemplate) {
|
|
30
|
+
if (SjsModule_1.default.templateHashToModuleName.has(importBy)) {
|
|
31
|
+
sjsScopeNames = SjsModule_1.default.templateHashToModuleName.get(importBy) || [];
|
|
32
|
+
}
|
|
33
|
+
if (!sjsScopeNames || sjsScopeNames.length === 0)
|
|
34
|
+
return false;
|
|
35
|
+
return isSjsScopeExp(value, sjsScopeNames);
|
|
36
|
+
}
|
|
37
|
+
if (!filePath || !((_a = SjsModule_1.default === null || SjsModule_1.default === void 0 ? void 0 : SjsModule_1.default.moduleMap) === null || _a === void 0 ? void 0 : _a[filePath]))
|
|
38
|
+
return false;
|
|
39
|
+
// 非 template 模板下处理
|
|
40
|
+
const sjsModuleMap = ((_b = SjsModule_1.default === null || SjsModule_1.default === void 0 ? void 0 : SjsModule_1.default.moduleMap) === null || _b === void 0 ? void 0 : _b[filePath]) || {};
|
|
41
|
+
sjsScopeNames = Object.keys(sjsModuleMap) || [];
|
|
42
|
+
if (!sjsScopeNames.length)
|
|
43
|
+
return false;
|
|
44
|
+
return isSjsScopeExp(value, sjsScopeNames);
|
|
45
|
+
}
|
|
46
|
+
exports.isSjsEvent = isSjsEvent;
|
|
47
|
+
/**
|
|
48
|
+
* create a function declaration character
|
|
49
|
+
* @param { value } string - expression
|
|
50
|
+
* @returns { string }
|
|
51
|
+
*/
|
|
52
|
+
function createSjsEventDeclaration(value, node) {
|
|
53
|
+
if (node.underTemplate) {
|
|
54
|
+
const { loopContext = [], underTemplate } = node;
|
|
55
|
+
const loopContextStr = loopContext.join(', ');
|
|
56
|
+
const templateContextStr = '...data';
|
|
57
|
+
let context = '{}';
|
|
58
|
+
if (loopContext.length && underTemplate) {
|
|
59
|
+
// 对齐微信表现,两者都存在时 loopContext 在后
|
|
60
|
+
context = `{${templateContextStr}, ${loopContextStr}}, ${underTemplate}`;
|
|
61
|
+
}
|
|
62
|
+
else if (loopContext.length && !underTemplate) {
|
|
63
|
+
context = `{${loopContextStr}}`;
|
|
64
|
+
}
|
|
65
|
+
else if (!loopContext.length && underTemplate) {
|
|
66
|
+
context = `{${templateContextStr}}, ${underTemplate}`;
|
|
67
|
+
}
|
|
68
|
+
return `(...args) => context.$handleSjsEvent(\`${value.replace(/{{(.*?)}}/g, (_, $1) => $1)}\`, args, ${context})`;
|
|
69
|
+
}
|
|
70
|
+
return `(...args) => context.$handleSjsEvent(\`${value.replace(/{{(.*?)}}/g, (_, $1) => $1)}\`, args)`;
|
|
71
|
+
}
|
|
72
|
+
exports.createSjsEventDeclaration = createSjsEventDeclaration;
|