xhs-mp-compiler-cli 1.0.1-beta.1 → 1.0.1-beta.2

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.
Files changed (73) hide show
  1. package/dist/bin/xhs-mp-cli-build.js +0 -2
  2. package/dist/bin/xhs-mp-cli-dev.js +0 -3
  3. package/dist/index.js +7 -11
  4. package/dist/types/index.d.ts +1 -5
  5. package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +0 -1
  6. package/dist/webpack-config/lib/postcssRpx2Vw.js +12 -17
  7. package/dist/webpack-config/loaders/mini-style-loader.js +3 -3
  8. package/dist/webpack-config/loaders/sjs-loader/index.d.ts +12 -1
  9. package/dist/webpack-config/loaders/sjs-loader/index.js +602 -86
  10. package/dist/webpack-config/loaders/sjs-loader/scope.d.ts +36 -0
  11. package/dist/webpack-config/loaders/sjs-loader/scope.js +122 -0
  12. package/dist/webpack-config/loaders/sjs-loader/tranform.d.ts +2 -0
  13. package/dist/webpack-config/loaders/sjs-loader/tranform.js +31 -0
  14. package/dist/webpack-config/presets/prod.js +3 -5
  15. package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +0 -4
  16. package/dist/webpack-config/presets/render/RenderChunkPlugin.js +7 -22
  17. package/dist/webpack-config/presets/render/SjsEntryPlugin.js +47 -11
  18. package/dist/webpack-config/presets/render/index.js +12 -49
  19. package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +2 -2
  20. package/dist/webpack-config/presets/service/index.js +1 -0
  21. package/package.json +4 -4
  22. package/dist/webpack-config/loaders/ml-loader/index.d.ts +0 -3
  23. package/dist/webpack-config/loaders/ml-loader/index.js +0 -66
  24. package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.d.ts +0 -2
  25. package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.js +0 -107
  26. package/dist/webpack-config/loaders/ml-loader/ml2vue/index.d.ts +0 -6
  27. package/dist/webpack-config/loaders/ml-loader/ml2vue/index.js +0 -64
  28. package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.d.ts +0 -11
  29. package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.js +0 -41
  30. package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.d.ts +0 -2
  31. package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.js +0 -18
  32. package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.d.ts +0 -2
  33. package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.js +0 -21
  34. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.d.ts +0 -7
  35. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.js +0 -185
  36. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.d.ts +0 -2
  37. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.js +0 -73
  38. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.d.ts +0 -13
  39. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.js +0 -42
  40. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.d.ts +0 -2
  41. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.js +0 -30
  42. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.d.ts +0 -2
  43. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.js +0 -17
  44. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.d.ts +0 -2
  45. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.js +0 -23
  46. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts +0 -13
  47. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js +0 -25
  48. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.d.ts +0 -4
  49. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.js +0 -30
  50. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.d.ts +0 -2
  51. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.js +0 -30
  52. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.d.ts +0 -2
  53. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.js +0 -89
  54. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.d.ts +0 -2
  55. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.js +0 -33
  56. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.d.ts +0 -2
  57. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.js +0 -61
  58. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.d.ts +0 -2
  59. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.js +0 -35
  60. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.d.ts +0 -11
  61. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.js +0 -72
  62. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.d.ts +0 -2
  63. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.js +0 -74
  64. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.d.ts +0 -2
  65. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.js +0 -12
  66. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.d.ts +0 -2
  67. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.js +0 -16
  68. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.d.ts +0 -10
  69. package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.js +0 -80
  70. package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.d.ts +0 -7
  71. package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.js +0 -41
  72. package/dist/webpack-config/loaders/sjs-loader/frame.d.ts +0 -1
  73. package/dist/webpack-config/loaders/sjs-loader/frame.js +0 -51
@@ -1,17 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleDataAttribute: (value: any, attribute: any, node: any) => void;
2
- export default handleDataAttribute;
@@ -1,23 +0,0 @@
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;
@@ -1,13 +0,0 @@
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;
@@ -1,25 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- declare const handleImportTag: (node: any, filePath: string, importMap?: {
2
- [key: string]: string[];
3
- }) => Promise<void>;
4
- export default handleImportTag;
@@ -1,30 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleIncludeTag: (node: any, filePath: any, includeMap: any) => Promise<void>;
2
- export default handleIncludeTag;
@@ -1,30 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleLoopAttribute: (node: any) => void;
2
- export default handleLoopAttribute;
@@ -1,89 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleMLAttribute: (value: any, attribute: any, node: any) => void;
2
- export default handleMLAttribute;
@@ -1,33 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleModelAttribute: (value: any, attribute: any, node: any) => void;
2
- export default handleModelAttribute;
@@ -1,61 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleOtherAttribute: (value: any, attribute: any, node: any) => void;
2
- export default handleOtherAttribute;
@@ -1,35 +0,0 @@
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;
@@ -1,11 +0,0 @@
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;
@@ -1,72 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare const handleSlotAttribute: (node: any) => void;
2
- export default handleSlotAttribute;
@@ -1,74 +0,0 @@
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 clone_1 = __importDefault(require("clone"));
7
- const utils_1 = require("./utils");
8
- const utils_2 = require("../utils");
9
- /**
10
- * 默认不合法
11
- * 若祖先节点先出现自定义组件,合法
12
- * 若祖先节点先出现 XhsVueTemplate,不合法
13
- */
14
- const isValidSlot = node => {
15
- let parent = node.parent;
16
- let firstMet = '';
17
- while (parent === null || parent === void 0 ? void 0 : parent.name) {
18
- const parentTagName = parent.name;
19
- if (parentTagName === 'XhsVueTemplate') {
20
- firstMet = 'XhsVueTemplate';
21
- }
22
- else if ((0, utils_2.isCustomComponent)(parentTagName)) {
23
- firstMet = 'customElement';
24
- }
25
- if (firstMet === 'customElement') {
26
- return true;
27
- }
28
- if (firstMet === 'XhsVueTemplate') {
29
- return false;
30
- }
31
- parent = parent.parent;
32
- }
33
- return false;
34
- };
35
- const handleSlotAttribute = (node) => {
36
- if (!isValidSlot(node)) {
37
- delete node.attribs.slot;
38
- return;
39
- }
40
- const value = node.attribs.slot;
41
- const dynamicValue = (0, utils_1.matchMustache)(value);
42
- delete node.attribs.slot;
43
- let vSlotAttr = `v-slot:${value}`;
44
- if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
45
- vSlotAttr = `v-slot:[${(0, utils_1.injectContext2Exp)(value, node, 2)}]`.replace(/\s/g, '');
46
- }
47
- /**
48
- * 若父元素已经是 template 标签,则把 v-slot 转移到父级元素
49
- * https://eslint.vuejs.org/rules/valid-v-slot.html
50
- */
51
- if (node.parent.name === 'template') {
52
- node.parent.attribs[vSlotAttr] = '';
53
- }
54
- else {
55
- const attribs = { [vSlotAttr]: '' };
56
- const children = node.cloneNode ? node.cloneNode(true) : (0, clone_1.default)(node);
57
- (0, utils_1.addContextToNode)({
58
- // @ts-ignore
59
- nodes: children,
60
- loopContext: node.loopContext,
61
- underTemplate: node.underTemplate,
62
- });
63
- node.name = 'template';
64
- for (const [key, val] of Object.entries(node.attribs)) {
65
- if (/:if|:elif|:else/.test(key)) {
66
- attribs[key] = val;
67
- delete children.attribs[key];
68
- }
69
- }
70
- node.attribs = attribs;
71
- node.children = [children];
72
- }
73
- };
74
- exports.default = handleSlotAttribute;
@@ -1,2 +0,0 @@
1
- declare const handleSpaceAttribute: (value: string, node: any) => void;
2
- export default handleSpaceAttribute;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const validSpaces = ['ensp', 'emsp', 'nbsp'];
4
- const handleSpaceAttribute = (value, node) => {
5
- if (node.name === 'xhs-vue-text' && validSpaces.includes(value)) {
6
- node.children.forEach((it) => {
7
- if (it.type === 'text')
8
- it.data = it.data.replace(/ /g, `&${value};`);
9
- });
10
- }
11
- };
12
- exports.default = handleSpaceAttribute;
@@ -1,2 +0,0 @@
1
- declare const handleStyleAttribute: (value: string, node: any) => void;
2
- export default handleStyleAttribute;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
4
- const postcssRpx2Vw_1 = require("../../../../lib/postcssRpx2Vw");
5
- const utils_1 = require("./utils");
6
- const handleStyleAttribute = (value, node) => {
7
- var _a;
8
- if ((_a = (0, utils_1.matchMustache)(value)) === null || _a === void 0 ? void 0 : _a.length) {
9
- node.attribs[':style'] = `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${xhs_mp_compiler_utils_1.CompileCallRuntimeMethodsNames.Rpx2vw}', ${(0, utils_1.injectContext2Exp)(value, node, 1)})`;
10
- delete node.attribs.style;
11
- }
12
- else {
13
- node.attribs.style = value.replace(/([\d.]+)rpx/g, (m, $1) => (0, postcssRpx2Vw_1.calcRpx2Vw)($1));
14
- }
15
- };
16
- exports.default = handleStyleAttribute;
@@ -1,10 +0,0 @@
1
- declare const matchMustache: (value: string) => never[] | RegExpMatchArray | null;
2
- export declare function injectModelHandler(isComponent: boolean, property: string, changeEvent?: any): string;
3
- export declare function addContextToNode({ nodes, loopContext, underTemplate }: {
4
- nodes: any;
5
- loopContext?: string[];
6
- underTemplate?: boolean;
7
- useSjs?: boolean;
8
- }): void;
9
- declare const injectContext2Exp: (exp: string, node: any, type: number) => string | undefined;
10
- export { matchMustache, injectContext2Exp };