@tarojs/taroize 4.0.0-beta.8 → 4.0.0-beta.9
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/lib/src/global.js +4 -0
- package/lib/src/global.js.map +1 -1
- package/lib/src/index.js +29 -19
- package/lib/src/index.js.map +1 -1
- package/lib/src/script.js +8 -2
- package/lib/src/script.js.map +1 -1
- package/lib/src/template.js +53 -11
- package/lib/src/template.js.map +1 -1
- package/lib/src/utils.js +147 -46
- package/lib/src/utils.js.map +1 -1
- package/lib/src/vue.js +1 -1
- package/lib/src/vue.js.map +1 -1
- package/lib/src/wxml.js +163 -51
- package/lib/src/wxml.js.map +1 -1
- package/package.json +2 -2
package/lib/src/wxml.js
CHANGED
|
@@ -47,7 +47,7 @@ function buildElement(name, children = [], attributes = []) {
|
|
|
47
47
|
}
|
|
48
48
|
// 将 style 属性中属性名转小驼峰格式 并且将 {{}} 转为 ${}格式生成对应ast节点
|
|
49
49
|
function convertStyleAttrs(styleAttrsMap) {
|
|
50
|
-
(0, utils_1.
|
|
50
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] convertStyleAttrs - 进入函数 ${(0, utils_1.getLineBreak)()}`);
|
|
51
51
|
styleAttrsMap.forEach((attr) => {
|
|
52
52
|
attr.attrName = (0, shared_1.toCamelCase)(attr.attrName.trim());
|
|
53
53
|
// 匹配 {{}} 内部以及左右两边值
|
|
@@ -73,7 +73,7 @@ function convertStyleAttrs(styleAttrsMap) {
|
|
|
73
73
|
* @param { any[] } attrKeyValueMap 属性解析为 {attrName: attrValue} 形式的数组
|
|
74
74
|
*/
|
|
75
75
|
function parseStyleAttrs(styleAttrsMap, attrKeyValueMap) {
|
|
76
|
-
(0, utils_1.
|
|
76
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseStyleAttrs - 进入函数 ${(0, utils_1.getLineBreak)()}`);
|
|
77
77
|
styleAttrsMap.forEach((attr) => {
|
|
78
78
|
if (attr) {
|
|
79
79
|
// 对含三元运算符的写法 style="width:{{ xx ? xx : xx }}" 匹配第一个 : 避免匹配三元表达式中的 : 运算符
|
|
@@ -98,20 +98,13 @@ function convertStyleUnit(value) {
|
|
|
98
98
|
if (Number(size) === 0) {
|
|
99
99
|
return match.replace(size, '0').replace(unit, 'rem');
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
if (parseInt(size, 10) === 0) {
|
|
103
|
-
return match.replace(size, '1').replace(unit, 'rem');
|
|
104
|
-
}
|
|
105
|
-
return match.replace(size, parseInt(size, 10) / 20 + '').replace(unit, 'rem');
|
|
101
|
+
return match.replace(size, parseFloat(size) / 20 + '').replace(unit, 'rem');
|
|
106
102
|
})
|
|
107
103
|
.replace(/\s*-?([0-9.]+)(rpx)\b/gi, function (match, size, unit) {
|
|
108
104
|
if (Number(size) === 0) {
|
|
109
105
|
return match.replace(size, '0').replace(unit, 'rem');
|
|
110
106
|
}
|
|
111
|
-
|
|
112
|
-
return match.replace(size, '1').replace(unit, 'rem');
|
|
113
|
-
}
|
|
114
|
-
return match.replace(size, parseInt(size, 10) / 40 + '').replace(unit, 'rem');
|
|
107
|
+
return match.replace(size, parseFloat(size) / 40 + '').replace(unit, 'rem');
|
|
115
108
|
});
|
|
116
109
|
// 把 xx="...{{参数}}rpx/px"的尺寸单位都转为rem,比如"{{参数}}rpx" -> "{{参数/40}}rem"
|
|
117
110
|
tempValue = tempValue
|
|
@@ -130,8 +123,9 @@ function convertStyleUnit(value) {
|
|
|
130
123
|
});
|
|
131
124
|
}
|
|
132
125
|
catch (error) {
|
|
126
|
+
(0, utils_1.createErrorCodeMsg)('WxmlUnitConversionError', `wxml内px/rpx单位转换失败: ${error}`, tempValue, global_1.globals.currentParseFile);
|
|
133
127
|
(0, helper_1.printLog)("error" /* processTypeEnum.ERROR */, `wxml内px/rpx单位转换失败: ${error}`);
|
|
134
|
-
(0, utils_1.
|
|
128
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] convertStyleUnit - wxml内px/rpx单位转换异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
135
129
|
}
|
|
136
130
|
}
|
|
137
131
|
return tempValue;
|
|
@@ -144,6 +138,7 @@ exports.convertStyleUnit = convertStyleUnit;
|
|
|
144
138
|
* @returns Visitor
|
|
145
139
|
*/
|
|
146
140
|
const createPreWxmlVistor = (templates) => {
|
|
141
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createPreWxmlVistor - 入参 ${(0, utils_1.getLineBreak)()}templates: ${templates} ${(0, utils_1.getLineBreak)()}`);
|
|
147
142
|
// const Applys = new Map<string, string[]>()
|
|
148
143
|
return {
|
|
149
144
|
JSXElement: {
|
|
@@ -190,8 +185,9 @@ function getWxsImports(templateFileName, usedWxses, dirPath) {
|
|
|
190
185
|
}
|
|
191
186
|
exports.getWxsImports = getWxsImports;
|
|
192
187
|
const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], templates) => {
|
|
193
|
-
(0, utils_1.
|
|
188
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 入参 ${(0, utils_1.getLineBreak)()}dirPath: ${dirPath} ${(0, utils_1.getLineBreak)()}`);
|
|
194
189
|
const jsxAttrVisitor = (path) => {
|
|
190
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析JSXAttribute ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
195
191
|
const name = path.node.name;
|
|
196
192
|
const jsx = path.findParent((p) => p.isJSXElement());
|
|
197
193
|
// 把 hidden 转换为 wxif
|
|
@@ -228,16 +224,31 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
228
224
|
}
|
|
229
225
|
};
|
|
230
226
|
const renameJSXKey = (path) => {
|
|
227
|
+
var _a, _b, _c, _d;
|
|
228
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析JSXIdentifier ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
231
229
|
const nodeName = path.node.name;
|
|
232
230
|
if (path.parentPath.isJSXAttribute()) {
|
|
231
|
+
const cacheNode = (0, lodash_1.cloneDeep)(path.parentPath.parentPath.parent);
|
|
233
232
|
if (nodeName === exports.WX_SHOW) {
|
|
234
233
|
path.replaceWith(t.jSXIdentifier(exports.WX_IF)); // wx:show转换后不支持,不频繁切换的话wx:if可替代
|
|
234
|
+
const position = {
|
|
235
|
+
col: ((_a = cacheNode.position) === null || _a === void 0 ? void 0 : _a.start.column) || 0,
|
|
236
|
+
row: ((_b = cacheNode.position) === null || _b === void 0 ? void 0 : _b.start.line) || 0
|
|
237
|
+
};
|
|
238
|
+
(0, utils_1.createErrorCodeMsg)('uncompilableAttribute', `属性 ${nodeName}不能编译,会被替换为wx:if`, (0, utils_1.astToCode)(cacheNode) || '', global_1.globals.currentParseFile, position);
|
|
235
239
|
// eslint-disable-next-line no-console
|
|
236
240
|
console.log(`属性 ${nodeName}不能编译,会被替换为wx:if`);
|
|
241
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] createWxmlVistor - ${nodeName} 属性不能编译,会被替换为 wx:if ${(0, utils_1.getLineBreak)()}`);
|
|
237
242
|
}
|
|
238
243
|
else if (nodeName.startsWith('wx:') && !exports.wxTemplateCommand.includes(nodeName)) {
|
|
244
|
+
const position = {
|
|
245
|
+
col: ((_c = cacheNode.position) === null || _c === void 0 ? void 0 : _c.start.column) || 0,
|
|
246
|
+
row: ((_d = cacheNode.position) === null || _d === void 0 ? void 0 : _d.start.line) || 0
|
|
247
|
+
};
|
|
248
|
+
(0, utils_1.createErrorCodeMsg)('unknownScopeAttribute', `未知 wx 作用域属性: ${nodeName},该属性会被移除掉。`, (0, utils_1.astToCode)(cacheNode) || '', global_1.globals.currentParseFile, position);
|
|
239
249
|
// eslint-disable-next-line no-console
|
|
240
250
|
console.log(`未知 wx 作用域属性: ${nodeName},该属性会被移除掉。`);
|
|
251
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] createWxmlVistor - 未知 wx 作用域属性: ${nodeName},该属性会被移除掉 ${(0, utils_1.getLineBreak)()}`);
|
|
241
252
|
path.parentPath.remove();
|
|
242
253
|
}
|
|
243
254
|
}
|
|
@@ -247,6 +258,7 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
247
258
|
JSXIdentifier: renameJSXKey,
|
|
248
259
|
Identifier: {
|
|
249
260
|
enter(path) {
|
|
261
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析Identifier ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
250
262
|
if (!path.isReferencedIdentifier()) {
|
|
251
263
|
return;
|
|
252
264
|
}
|
|
@@ -261,7 +273,8 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
261
273
|
},
|
|
262
274
|
JSXElement: {
|
|
263
275
|
enter(path) {
|
|
264
|
-
var _a;
|
|
276
|
+
var _a, _b, _c;
|
|
277
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析JSXElement ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
265
278
|
const openingElement = path.get('openingElement');
|
|
266
279
|
const jsxName = openingElement.get('name');
|
|
267
280
|
const attrs = openingElement.get('attributes');
|
|
@@ -299,6 +312,7 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
299
312
|
}
|
|
300
313
|
const tagName = jsxName.node.name;
|
|
301
314
|
if (tagName === 'Slot') {
|
|
315
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - tagName: Slot ${(0, utils_1.getLineBreak)()}`);
|
|
302
316
|
const nameAttr = attrs.find((a) => t.isJSXAttribute(a.node) && a.node.name.name === 'name');
|
|
303
317
|
let slotName = '';
|
|
304
318
|
if (nameAttr && t.isJSXAttribute(nameAttr.node)) {
|
|
@@ -306,7 +320,12 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
306
320
|
slotName = nameAttr.node.value.value;
|
|
307
321
|
}
|
|
308
322
|
else {
|
|
309
|
-
|
|
323
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] createWxmlVistor - slot 的值不是一个字符串 ${(0, utils_1.getLineBreak)()}`);
|
|
324
|
+
// const error = codeFrameError(jsxName.node, 'slot 的值必须是一个字符串')
|
|
325
|
+
// @ts-ignore
|
|
326
|
+
const { line, column } = ((_b = (_a = path.node) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.start) || { line: 0, column: 0 };
|
|
327
|
+
const position = { col: column, row: line };
|
|
328
|
+
throw new utils_1.IReportError('slot 的值必须是一个字符串', 'SlotValueTypeError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
310
329
|
}
|
|
311
330
|
}
|
|
312
331
|
const children = t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('props')), t.identifier(slotName ? buildSlotName(slotName) : 'children'));
|
|
@@ -314,13 +333,16 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
314
333
|
path.replaceWith(path.parentPath.isJSXElement() ? t.jSXExpressionContainer(children) : children);
|
|
315
334
|
}
|
|
316
335
|
catch (error) {
|
|
336
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] createWxmlVistor - Slot 节点替换异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
317
337
|
//
|
|
318
338
|
}
|
|
319
339
|
}
|
|
320
340
|
if (tagName === 'Wxs') {
|
|
341
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - tagName: Wxs ${(0, utils_1.getLineBreak)()}`);
|
|
321
342
|
wxses.push(getWXS(attrs.map((a) => a.node), path, imports));
|
|
322
343
|
}
|
|
323
344
|
if (tagName === 'Template') {
|
|
345
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - tagName: Template ${(0, utils_1.getLineBreak)()}`);
|
|
324
346
|
const template = (0, template_1.parseTemplate)(path, dirPath, wxses);
|
|
325
347
|
if (template) {
|
|
326
348
|
let funcs = new Set();
|
|
@@ -336,13 +358,14 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
336
358
|
const usedTemplate = new Set();
|
|
337
359
|
// funcs的值首先来源于预解析结果
|
|
338
360
|
if (templates) {
|
|
339
|
-
const applyFuncs = (
|
|
361
|
+
const applyFuncs = (_c = templates.get(name)) === null || _c === void 0 ? void 0 : _c.funcs;
|
|
340
362
|
if (applyFuncs) {
|
|
341
363
|
funcs = applyFuncs;
|
|
342
364
|
}
|
|
343
365
|
}
|
|
344
366
|
(0, traverse_1.default)(ast, {
|
|
345
367
|
JSXIdentifier(path) {
|
|
368
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析JSXIdentifier ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
346
369
|
const node = path.node;
|
|
347
370
|
if (node.name.endsWith('Tmpl') && node.name.length > 4 && path.parentPath.isJSXOpeningElement()) {
|
|
348
371
|
usedTemplate.add(node.name);
|
|
@@ -374,6 +397,7 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
374
397
|
}
|
|
375
398
|
},
|
|
376
399
|
JSXAttribute(path) {
|
|
400
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析JSXAttribute ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
377
401
|
// 识别template使用到的处理事件的func
|
|
378
402
|
const node = path.node;
|
|
379
403
|
if (t.isJSXExpressionContainer(node.value) &&
|
|
@@ -389,6 +413,7 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
389
413
|
(0, traverse_1.default)(ast, {
|
|
390
414
|
// 将使用到的处理事件的func写入到props
|
|
391
415
|
BlockStatement(path) {
|
|
416
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - 解析BlockStatement ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
392
417
|
if (funcs.size > 0) {
|
|
393
418
|
const body = path.node.body;
|
|
394
419
|
if (t.isVariableDeclaration(body[0])) {
|
|
@@ -431,12 +456,14 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
431
456
|
}
|
|
432
457
|
}
|
|
433
458
|
if (tagName === 'Import') {
|
|
459
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - tagName: Import ${(0, utils_1.getLineBreak)()}`);
|
|
434
460
|
const mods = (0, template_1.parseModule)(path, dirPath, 'import');
|
|
435
461
|
if (mods) {
|
|
436
462
|
imports.push(...mods);
|
|
437
463
|
}
|
|
438
464
|
}
|
|
439
465
|
if (tagName === 'Include') {
|
|
466
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] createWxmlVistor - tagName: Include ${(0, utils_1.getLineBreak)()}`);
|
|
440
467
|
(0, template_1.parseModule)(path, dirPath, 'include');
|
|
441
468
|
}
|
|
442
469
|
},
|
|
@@ -456,6 +483,7 @@ const createWxmlVistor = (loopIds, refIds, dirPath, wxses = [], imports = [], te
|
|
|
456
483
|
path.replaceWith(caller);
|
|
457
484
|
}
|
|
458
485
|
catch (error) {
|
|
486
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] createWxmlVistor - block 节点替换异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
459
487
|
//
|
|
460
488
|
}
|
|
461
489
|
}
|
|
@@ -471,7 +499,7 @@ exports.createWxmlVistor = createWxmlVistor;
|
|
|
471
499
|
*/
|
|
472
500
|
function templateBfs(templates) {
|
|
473
501
|
var _a;
|
|
474
|
-
(0, utils_1.
|
|
502
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] templateBfs - 进入函数 ${(0, utils_1.getLineBreak)()}`);
|
|
475
503
|
const names = [];
|
|
476
504
|
const applys = new Map();
|
|
477
505
|
for (const key of templates.keys()) {
|
|
@@ -517,7 +545,7 @@ function templateBfs(templates) {
|
|
|
517
545
|
}
|
|
518
546
|
}
|
|
519
547
|
function parseWXML(dirPath, wxml, parseImport) {
|
|
520
|
-
(0, utils_1.
|
|
548
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseWXML - 入参 ${(0, utils_1.getLineBreak)()}dirPath: ${dirPath} ${(0, utils_1.getLineBreak)()}parseImport: ${parseImport} ${(0, utils_1.getLineBreak)()}`);
|
|
521
549
|
try {
|
|
522
550
|
wxml = prettyPrint(wxml, {
|
|
523
551
|
max_char: 0,
|
|
@@ -526,6 +554,7 @@ function parseWXML(dirPath, wxml, parseImport) {
|
|
|
526
554
|
});
|
|
527
555
|
}
|
|
528
556
|
catch (error) {
|
|
557
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] parseWXML - wxml代码格式化异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
529
558
|
//
|
|
530
559
|
}
|
|
531
560
|
if (!parseImport) {
|
|
@@ -547,7 +576,7 @@ function parseWXML(dirPath, wxml, parseImport) {
|
|
|
547
576
|
wxml: t.nullLiteral(),
|
|
548
577
|
};
|
|
549
578
|
}
|
|
550
|
-
const nodes = removeEmptyTextAndComment((0, himalaya_wxml_1.parse)(wxml.trim()));
|
|
579
|
+
const nodes = removeEmptyTextAndComment((0, himalaya_wxml_1.parse)(wxml.trim(), Object.assign(Object.assign({}, himalaya_wxml_1.parseDefaults), { includePositions: true })));
|
|
551
580
|
const ast = t.file(t.program([t.expressionStatement(parseNode(buildElement('block', nodes)))], []));
|
|
552
581
|
// 确认当前解析页面是否已经解析过,如果解析过则直接获取缓存解析
|
|
553
582
|
let parseResult = (0, cache_1.getCacheWxml)(dirPath, hydrate(ast));
|
|
@@ -580,6 +609,7 @@ function parseWXML(dirPath, wxml, parseImport) {
|
|
|
580
609
|
}
|
|
581
610
|
exports.parseWXML = parseWXML;
|
|
582
611
|
function getWXS(attrs, path, imports) {
|
|
612
|
+
var _a, _b, _c, _d, _e, _f;
|
|
583
613
|
let moduleName = null;
|
|
584
614
|
let src = null;
|
|
585
615
|
for (const attr of attrs) {
|
|
@@ -588,7 +618,11 @@ function getWXS(attrs, path, imports) {
|
|
|
588
618
|
const attrValue = attr.value;
|
|
589
619
|
let value = null;
|
|
590
620
|
if (attrValue === null) {
|
|
591
|
-
|
|
621
|
+
// @ts-ignore
|
|
622
|
+
const { line, column } = ((_b = (_a = path.node) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.start) || { line: 0, column: 0 };
|
|
623
|
+
const position = { col: column, row: line };
|
|
624
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - wxs 标签的属性值为空 ${(0, utils_1.getLineBreak)()}`);
|
|
625
|
+
throw new utils_1.IReportError('wxs 标签的属性值不得为空', 'WxsTagAttributeEmptyError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
592
626
|
}
|
|
593
627
|
if (t.isStringLiteral(attrValue)) {
|
|
594
628
|
value = attrValue.value;
|
|
@@ -607,13 +641,18 @@ function getWXS(attrs, path, imports) {
|
|
|
607
641
|
if (!src) {
|
|
608
642
|
const { children: [script], } = path.node;
|
|
609
643
|
if (!t.isJSXText(script)) {
|
|
610
|
-
|
|
644
|
+
// @ts-ignore
|
|
645
|
+
const { line, column } = ((_d = (_c = path.node) === null || _c === void 0 ? void 0 : _c.position) === null || _d === void 0 ? void 0 : _d.start) || { line: 0, column: 0 };
|
|
646
|
+
const position = { col: column, row: line };
|
|
647
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - wxs 没有 src 属性且标签内部没有 wxs 代码 ${(0, utils_1.getLineBreak)()}`);
|
|
648
|
+
throw new utils_1.IReportError('wxs 如果没有 src 属性,标签内部必须有 wxs 代码。', 'WxsTagCodeMissingError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
611
649
|
}
|
|
612
650
|
src = './wxs__' + moduleName;
|
|
613
651
|
const ast = (0, utils_1.parseCode)(script.value);
|
|
614
652
|
(0, traverse_1.default)(ast, {
|
|
615
653
|
CallExpression(path) {
|
|
616
|
-
var _a, _b, _c;
|
|
654
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
655
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] getWXS - 解析CallExpression ${(0, utils_1.getLineBreak)()}${path} ${(0, utils_1.getLineBreak)()}`);
|
|
617
656
|
// wxs标签中getRegExp转换为new RegExp
|
|
618
657
|
if (t.isIdentifier(path.node.callee, { name: 'getRegExp' })) {
|
|
619
658
|
// 根据正则表达式是否定义了正则匹配修饰符,有则不变,没有就用默认
|
|
@@ -631,25 +670,41 @@ function getWXS(attrs, path, imports) {
|
|
|
631
670
|
path.replaceWith(newExpr);
|
|
632
671
|
}
|
|
633
672
|
else if (t.isIdentifier(regex) || t.isIdentifier(modifier)) {
|
|
634
|
-
|
|
673
|
+
// @ts-ignore
|
|
674
|
+
const { line, column } = ((_d = (_c = path.node) === null || _c === void 0 ? void 0 : _c.position) === null || _d === void 0 ? void 0 : _d.start) || { line: 0, column: 0 };
|
|
675
|
+
const position = { col: column, row: line };
|
|
676
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - getRegExp 函数暂不支持传入变量类型的参数 ${(0, utils_1.getLineBreak)()}`);
|
|
677
|
+
throw new utils_1.IReportError('getRegExp 函数暂不支持传入变量类型的参数', 'GetRegExpVariableTypeError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
635
678
|
}
|
|
636
679
|
else {
|
|
637
|
-
|
|
680
|
+
// @ts-ignore
|
|
681
|
+
const { line, column } = ((_f = (_e = path.node) === null || _e === void 0 ? void 0 : _e.position) === null || _f === void 0 ? void 0 : _f.start) || { line: 0, column: 0 };
|
|
682
|
+
const position = { col: column, row: line };
|
|
683
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - getRegExp 函数暂不支持传入非字符串类型的参数 ${(0, utils_1.getLineBreak)()}`);
|
|
684
|
+
throw new utils_1.IReportError('getRegExp 函数暂不支持传入非字符串类型的参数', 'GetRegExpParameterTypeError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
638
685
|
}
|
|
639
686
|
}
|
|
640
687
|
else if (path.node.arguments.length === 1) {
|
|
641
688
|
const regex = path.node.arguments[0];
|
|
642
689
|
if (t.isStringLiteral(regex)) {
|
|
643
|
-
const regexStr = (
|
|
690
|
+
const regexStr = (_g = regex.extra) === null || _g === void 0 ? void 0 : _g.raw;
|
|
644
691
|
const regexWithoutQuotes = regexStr.replace(/^['"](.*)['"]$/, '$1');
|
|
645
692
|
const newExpr = t.newExpression(t.identifier('RegExp'), [t.stringLiteral(regexWithoutQuotes)]);
|
|
646
693
|
path.replaceWith(newExpr);
|
|
647
694
|
}
|
|
648
695
|
else if (t.isIdentifier(regex)) {
|
|
649
|
-
|
|
696
|
+
// @ts-ignore
|
|
697
|
+
const { line, column } = ((_j = (_h = path.node) === null || _h === void 0 ? void 0 : _h.position) === null || _j === void 0 ? void 0 : _j.start) || { line: 0, column: 0 };
|
|
698
|
+
const position = { col: column, row: line };
|
|
699
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - getRegExp 函数暂不支持传入变量类型的参数 ${(0, utils_1.getLineBreak)()}`);
|
|
700
|
+
throw new utils_1.IReportError('getRegExp 函数暂不支持传入变量类型的参数', 'GetRegExpVariableTypeError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
650
701
|
}
|
|
651
702
|
else {
|
|
652
|
-
|
|
703
|
+
// @ts-ignore
|
|
704
|
+
const { line, column } = ((_l = (_k = path.node) === null || _k === void 0 ? void 0 : _k.position) === null || _l === void 0 ? void 0 : _l.start) || { line: 0, column: 0 };
|
|
705
|
+
const position = { col: column, row: line };
|
|
706
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - getRegExp 函数暂不支持传入非字符串类型的参数 ${(0, utils_1.getLineBreak)()}`);
|
|
707
|
+
throw new utils_1.IReportError('getRegExp 函数暂不支持传入非字符串类型的参数', 'GetRegExpParameterTypeError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
653
708
|
}
|
|
654
709
|
}
|
|
655
710
|
else {
|
|
@@ -684,7 +739,11 @@ function getWXS(attrs, path, imports) {
|
|
|
684
739
|
});
|
|
685
740
|
}
|
|
686
741
|
if (!moduleName || !src) {
|
|
687
|
-
|
|
742
|
+
// @ts-ignore
|
|
743
|
+
const { line, column } = ((_f = (_e = path.node) === null || _e === void 0 ? void 0 : _e.position) === null || _f === void 0 ? void 0 : _f.start) || { line: 0, column: 0 };
|
|
744
|
+
const position = { col: column, row: line };
|
|
745
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] getWXS - wxs 未同时存在 wxs、src 两个属性 ${(0, utils_1.getLineBreak)()}`);
|
|
746
|
+
throw new utils_1.IReportError('一个 wxs 需要同时存在两个属性:`module`, `src`', 'WxsTagAttributesMissingError', 'WXML_FILE', (0, utils_1.astToCode)(path.node) || '', position);
|
|
688
747
|
}
|
|
689
748
|
path.remove();
|
|
690
749
|
return {
|
|
@@ -706,6 +765,7 @@ function hydrate(file) {
|
|
|
706
765
|
}
|
|
707
766
|
}
|
|
708
767
|
function transformLoop(name, attr, jsx, value) {
|
|
768
|
+
var _a, _b;
|
|
709
769
|
const jsxElement = jsx.get('openingElement');
|
|
710
770
|
if (!jsxElement.node) {
|
|
711
771
|
return;
|
|
@@ -715,7 +775,11 @@ function transformLoop(name, attr, jsx, value) {
|
|
|
715
775
|
const hasSinglewxForItem = wxForItem && t.isJSXAttribute(wxForItem) && wxForItem.value && t.isJSXExpressionContainer(wxForItem.value);
|
|
716
776
|
if (hasSinglewxForItem || name === exports.WX_FOR || name === 'wx:for-items') {
|
|
717
777
|
if (!value || !t.isJSXExpressionContainer(value)) {
|
|
718
|
-
|
|
778
|
+
// @ts-ignore
|
|
779
|
+
const { line, column } = ((_b = (_a = jsx.node) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.start) || { line: 0, column: 0 };
|
|
780
|
+
const position = { col: column, row: line };
|
|
781
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] transformLoop - wx:for 的值未用 "{{}}" 包裹 ${(0, utils_1.getLineBreak)()}`);
|
|
782
|
+
throw new utils_1.IReportError('wx:for 的值必须使用 "{{}}" 包裹', 'WxForValueFormatError', 'WXML_FILE', (0, utils_1.astToCode)(jsx.node) || '', position);
|
|
719
783
|
}
|
|
720
784
|
attr.remove();
|
|
721
785
|
let item = t.stringLiteral('item');
|
|
@@ -724,17 +788,26 @@ function transformLoop(name, attr, jsx, value) {
|
|
|
724
788
|
.get('openingElement')
|
|
725
789
|
.get('attributes')
|
|
726
790
|
.forEach((p) => {
|
|
791
|
+
var _a, _b, _c, _d;
|
|
727
792
|
const node = p.node;
|
|
728
793
|
if (node.name.name === exports.WX_FOR_ITEM) {
|
|
729
794
|
if (!node.value || !t.isStringLiteral(node.value)) {
|
|
730
|
-
|
|
795
|
+
// @ts-ignore
|
|
796
|
+
const { line, column } = ((_b = (_a = jsx.node) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.start) || { line: 0, column: 0 };
|
|
797
|
+
const position = { col: column, row: line };
|
|
798
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] transformLoop - ${exports.WX_FOR_ITEM} 的值不是一个字符串 ${(0, utils_1.getLineBreak)()}`);
|
|
799
|
+
throw new utils_1.IReportError(exports.WX_FOR_ITEM + ' 的值必须是一个字符串', 'WxForItemValueError', 'WXML_FILE', (0, utils_1.astToCode)(jsx.node) || '', position);
|
|
731
800
|
}
|
|
732
801
|
item = node.value;
|
|
733
802
|
p.remove();
|
|
734
803
|
}
|
|
735
804
|
if (node.name.name === exports.WX_FOR_INDEX) {
|
|
736
805
|
if (!node.value || !t.isStringLiteral(node.value)) {
|
|
737
|
-
|
|
806
|
+
// @ts-ignore
|
|
807
|
+
const { line, column } = ((_d = (_c = jsx.node) === null || _c === void 0 ? void 0 : _c.position) === null || _d === void 0 ? void 0 : _d.start) || { line: 0, column: 0 };
|
|
808
|
+
const position = { col: column, row: line };
|
|
809
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] transformLoop - ${exports.WX_FOR_INDEX} 的值不是一个字符串 ${(0, utils_1.getLineBreak)()}`);
|
|
810
|
+
throw new utils_1.IReportError(exports.WX_FOR_INDEX + ' 的值必须是一个字符串', 'WxForIndexValueError', 'WXML_FILE', (0, utils_1.astToCode)(jsx.node) || '', position);
|
|
738
811
|
}
|
|
739
812
|
index = node.value;
|
|
740
813
|
p.remove();
|
|
@@ -774,6 +847,7 @@ function transformLoop(name, attr, jsx, value) {
|
|
|
774
847
|
jsx.replaceWith(ifBlock);
|
|
775
848
|
}
|
|
776
849
|
catch (error) {
|
|
850
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] transformLoop - wx:if和wx:for合用时父组件使用wx:if导致使用replaceWith异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
777
851
|
// jsx外层是wx:if的转换,替换(replaceWith)时会抛出异常
|
|
778
852
|
// catch异常后,正常替换
|
|
779
853
|
}
|
|
@@ -793,6 +867,7 @@ function transformLoop(name, attr, jsx, value) {
|
|
|
793
867
|
jsx.replaceWith(block);
|
|
794
868
|
}
|
|
795
869
|
catch (error) {
|
|
870
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] transformLoop - 节点替换异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
796
871
|
//
|
|
797
872
|
}
|
|
798
873
|
return {
|
|
@@ -802,6 +877,7 @@ function transformLoop(name, attr, jsx, value) {
|
|
|
802
877
|
}
|
|
803
878
|
}
|
|
804
879
|
function transformIf(name, attr, jsx, value) {
|
|
880
|
+
var _a, _b;
|
|
805
881
|
if (name !== exports.WX_IF) {
|
|
806
882
|
return;
|
|
807
883
|
}
|
|
@@ -820,10 +896,18 @@ function transformIf(name, attr, jsx, value) {
|
|
|
820
896
|
.filter((s) => !(s.isJSXExpressionContainer() && t.isJSXEmptyExpression(s.get('expression'))));
|
|
821
897
|
}
|
|
822
898
|
catch (error) {
|
|
899
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] transformIf - 节点过滤异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
823
900
|
return;
|
|
824
901
|
}
|
|
825
902
|
if (value === null || !t.isJSXExpressionContainer(value)) {
|
|
903
|
+
const cacheNode = (0, lodash_1.cloneDeep)(attr.parentPath.parent);
|
|
904
|
+
const position = {
|
|
905
|
+
col: ((_a = cacheNode.position) === null || _a === void 0 ? void 0 : _a.start.column) || 0,
|
|
906
|
+
row: ((_b = cacheNode.position) === null || _b === void 0 ? void 0 : _b.start.line) || 0,
|
|
907
|
+
};
|
|
908
|
+
(0, utils_1.createErrorCodeMsg)('wxIfValueFormatError', 'wx:if 的值需要用双括号 `{{}}` 包裹它的值', (0, utils_1.astToCode)(cacheNode) || '', global_1.globals.currentParseFile, position);
|
|
826
909
|
console.error('wx:if 的值需要用双括号 `{{}}` 包裹它的值');
|
|
910
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] transformIf - wx:if 的值需要用双括号 {{}} 包裹它的值 ${(0, utils_1.getLineBreak)()}`);
|
|
827
911
|
if (value && t.isStringLiteral(value)) {
|
|
828
912
|
value = t.jSXExpressionContainer((0, utils_1.buildTemplate)(value.value));
|
|
829
913
|
}
|
|
@@ -832,10 +916,12 @@ function transformIf(name, attr, jsx, value) {
|
|
|
832
916
|
condition: exports.WX_IF,
|
|
833
917
|
path: jsx,
|
|
834
918
|
tester: value,
|
|
919
|
+
cachePath: (0, lodash_1.cloneDeep)(jsx)
|
|
835
920
|
});
|
|
836
921
|
attr.remove();
|
|
837
922
|
for (let index = 0; index < siblings.length; index++) {
|
|
838
923
|
const sibling = siblings[index];
|
|
924
|
+
const cacheSibling = (0, lodash_1.cloneDeep)(sibling);
|
|
839
925
|
const next = (0, lodash_1.cloneDeep)(siblings[index + 1]);
|
|
840
926
|
const currMatches = findWXIfProps(sibling);
|
|
841
927
|
const nextMatches = findWXIfProps(next);
|
|
@@ -846,6 +932,7 @@ function transformIf(name, attr, jsx, value) {
|
|
|
846
932
|
condition: currMatches.reg.input,
|
|
847
933
|
path: sibling,
|
|
848
934
|
tester: currMatches.tester,
|
|
935
|
+
cachePath: cacheSibling
|
|
849
936
|
});
|
|
850
937
|
if (nextMatches === null) {
|
|
851
938
|
break;
|
|
@@ -854,6 +941,7 @@ function transformIf(name, attr, jsx, value) {
|
|
|
854
941
|
handleConditions(conditions);
|
|
855
942
|
}
|
|
856
943
|
function handleConditions(conditions) {
|
|
944
|
+
var _a, _b;
|
|
857
945
|
if (conditions.length === 1) {
|
|
858
946
|
const ct = conditions[0];
|
|
859
947
|
if (!t.isJSXEmptyExpression(ct.tester.expression)) {
|
|
@@ -861,6 +949,7 @@ function handleConditions(conditions) {
|
|
|
861
949
|
ct.path.replaceWith(t.jSXExpressionContainer(t.logicalExpression('&&', ct.tester.expression, (0, lodash_1.cloneDeep)(ct.path.node))));
|
|
862
950
|
}
|
|
863
951
|
catch (error) {
|
|
952
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] handleConditions - 替换节点异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
864
953
|
//
|
|
865
954
|
}
|
|
866
955
|
}
|
|
@@ -868,14 +957,18 @@ function handleConditions(conditions) {
|
|
|
868
957
|
if (conditions.length > 1) {
|
|
869
958
|
const lastLength = conditions.length - 1;
|
|
870
959
|
const lastCon = conditions[lastLength];
|
|
960
|
+
// 记录当前操作的 condition
|
|
961
|
+
let currentCondition = null;
|
|
871
962
|
let lastAlternate = (0, lodash_1.cloneDeep)(lastCon.path.node);
|
|
872
963
|
try {
|
|
873
964
|
if (lastCon.condition === exports.WX_ELSE_IF && !t.isJSXEmptyExpression(lastCon.tester.expression)) {
|
|
874
965
|
lastAlternate = t.logicalExpression('&&', lastCon.tester.expression, lastAlternate);
|
|
875
966
|
}
|
|
876
967
|
const node = conditions.slice(0, lastLength).reduceRight((acc, condition) => {
|
|
968
|
+
currentCondition = condition;
|
|
877
969
|
if (t.isJSXEmptyExpression(condition.tester.expression)) {
|
|
878
970
|
(0, helper_1.printLog)("warning" /* processTypeEnum.WARNING */, 'condition.tester.expression', 't.isJSXEmptyExpression(condition.tester.expression)');
|
|
971
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] handleConditions - t.isJSXEmptyExpression(condition.tester.expression) ${(0, utils_1.getLineBreak)()}`);
|
|
879
972
|
return null;
|
|
880
973
|
}
|
|
881
974
|
return t.conditionalExpression(condition.tester.expression, (0, lodash_1.cloneDeep)(condition.path.node), acc);
|
|
@@ -886,8 +979,10 @@ function handleConditions(conditions) {
|
|
|
886
979
|
}
|
|
887
980
|
}
|
|
888
981
|
catch (error) {
|
|
889
|
-
|
|
890
|
-
|
|
982
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] handleConditions - wx:elif 转换异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
983
|
+
const { line, column } = ((_b = (_a = currentCondition.cachePath.node) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.start) || { line: 0, column: 0 };
|
|
984
|
+
const position = { col: column, row: line };
|
|
985
|
+
throw new utils_1.IReportError('属性转换错误 wx:elif 的值需要用双括号 `{{}}` 包裹它的值', 'wxElifValueFormatError', 'WXML_FILE', (0, utils_1.astToCode)(currentCondition.cachePath.node) || '', position);
|
|
891
986
|
}
|
|
892
987
|
}
|
|
893
988
|
}
|
|
@@ -920,7 +1015,7 @@ function findWXIfProps(jsx) {
|
|
|
920
1015
|
return matches;
|
|
921
1016
|
}
|
|
922
1017
|
function parseNode(node, tagName) {
|
|
923
|
-
(0, utils_1.
|
|
1018
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseNode - 入参 ${(0, utils_1.getLineBreak)()}tagName: ${tagName} ${(0, utils_1.getLineBreak)()}`);
|
|
924
1019
|
if (node.type === NodeType.Text) {
|
|
925
1020
|
return parseText(node, tagName);
|
|
926
1021
|
}
|
|
@@ -932,12 +1027,13 @@ function parseNode(node, tagName) {
|
|
|
932
1027
|
value: ' ' + node.content + ' ',
|
|
933
1028
|
},
|
|
934
1029
|
];
|
|
935
|
-
|
|
1030
|
+
const jsxExpressionContainer = t.jSXExpressionContainer(emptyStatement);
|
|
1031
|
+
return (0, utils_1.addLocInfo)(jsxExpressionContainer, node);
|
|
936
1032
|
}
|
|
937
1033
|
return parseElement(node);
|
|
938
1034
|
}
|
|
939
1035
|
function parseElement(element) {
|
|
940
|
-
(0, utils_1.
|
|
1036
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseElement - 进入函数 ${(0, utils_1.getLineBreak)()}`);
|
|
941
1037
|
const tagName = t.jSXIdentifier(global_1.THIRD_PARTY_COMPONENTS.has(element.tagName) ? element.tagName : allCamelCase(element.tagName));
|
|
942
1038
|
if (utils_1.DEFAULT_Component_SET.has(tagName.name)) {
|
|
943
1039
|
global_1.usedComponents.add(tagName.name);
|
|
@@ -984,7 +1080,14 @@ function parseElement(element) {
|
|
|
984
1080
|
});
|
|
985
1081
|
}
|
|
986
1082
|
}
|
|
987
|
-
return t.jSXElement(
|
|
1083
|
+
// return t.jSXElement(
|
|
1084
|
+
// t.jSXOpeningElement(tagName, attributes.map(parseAttribute)),
|
|
1085
|
+
// t.jSXClosingElement(tagName),
|
|
1086
|
+
// removeEmptyTextAndComment(element.children).map((el) => parseNode(el, element.tagName)),
|
|
1087
|
+
// false
|
|
1088
|
+
// )
|
|
1089
|
+
const jSXElement = t.jSXElement(t.jSXOpeningElement(tagName, attributes.map(parseAttribute)), t.jSXClosingElement(tagName), removeEmptyTextAndComment(element.children).map((el) => parseNode(el, element.tagName)), false);
|
|
1090
|
+
return (0, utils_1.addLocInfo)(jSXElement, element);
|
|
988
1091
|
}
|
|
989
1092
|
function removeEmptyTextAndComment(nodes) {
|
|
990
1093
|
return nodes
|
|
@@ -997,16 +1100,19 @@ function removeEmptyTextAndComment(nodes) {
|
|
|
997
1100
|
}
|
|
998
1101
|
exports.removeEmptyTextAndComment = removeEmptyTextAndComment;
|
|
999
1102
|
function parseText(node, tagName) {
|
|
1000
|
-
(0, utils_1.
|
|
1103
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseText - 进入函数 ${(0, utils_1.getLineBreak)()}`);
|
|
1001
1104
|
if (tagName === 'wxs') {
|
|
1002
|
-
return t.jSXText(node.content)
|
|
1105
|
+
// return t.jSXText(node.content)
|
|
1106
|
+
return (0, utils_1.addLocInfo)(t.jSXText(node.content), node);
|
|
1003
1107
|
}
|
|
1004
1108
|
const { type, content } = parseContent(node.content);
|
|
1005
1109
|
if (type === 'raw') {
|
|
1006
1110
|
const text = content.replace(/([{}]+)/g, "{'$1'}");
|
|
1007
|
-
return t.jSXText(text)
|
|
1111
|
+
// return t.jSXText(text)
|
|
1112
|
+
return (0, utils_1.addLocInfo)(t.jSXText(text), node);
|
|
1008
1113
|
}
|
|
1009
|
-
return t.jSXExpressionContainer(
|
|
1114
|
+
// return t.jSXExpressionContainer(buildTemplate(content))
|
|
1115
|
+
return (0, utils_1.addLocInfo)(t.jSXExpressionContainer((0, utils_1.buildTemplate)(content)), node);
|
|
1010
1116
|
}
|
|
1011
1117
|
// 匹配{{content}}
|
|
1012
1118
|
const handlebarsRE = /\{\{((?:.|\n)+?)\}\}/g;
|
|
@@ -1014,7 +1120,7 @@ function singleQuote(s) {
|
|
|
1014
1120
|
return `'${s}'`;
|
|
1015
1121
|
}
|
|
1016
1122
|
function parseContent(content, single = false) {
|
|
1017
|
-
(0, utils_1.
|
|
1123
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseContent - 进入函数 ${(0, utils_1.getLineBreak)()}`);
|
|
1018
1124
|
content = content.trim();
|
|
1019
1125
|
if (!handlebarsRE.test(content)) {
|
|
1020
1126
|
return {
|
|
@@ -1069,7 +1175,7 @@ function isAllKeyValueFormat(styleAttrsMap) {
|
|
|
1069
1175
|
* @returns
|
|
1070
1176
|
*/
|
|
1071
1177
|
function parseStyle(key, value) {
|
|
1072
|
-
(0, utils_1.
|
|
1178
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseStyle - 入参 ${(0, utils_1.getLineBreak)()}key: ${key} ${(0, utils_1.getLineBreak)()}value: ${value} ${(0, utils_1.getLineBreak)()}`);
|
|
1073
1179
|
const styleAttrs = value.trim().split(';');
|
|
1074
1180
|
// 针对attrName: attrValue 格式做转换处理, 其他类型采用'+'连接符
|
|
1075
1181
|
if (isAllKeyValueFormat(styleAttrs)) {
|
|
@@ -1085,14 +1191,17 @@ function parseStyle(key, value) {
|
|
|
1085
1191
|
}
|
|
1086
1192
|
exports.parseStyle = parseStyle;
|
|
1087
1193
|
function parseAttribute(attr) {
|
|
1088
|
-
(0, utils_1.
|
|
1194
|
+
(0, utils_1.updateLogFileContent)(`INFO [taroize] parseAttribute - 入参 ${(0, utils_1.getLineBreak)()}attr: ${JSON.stringify(attr)} ${(0, utils_1.getLineBreak)()}`);
|
|
1089
1195
|
let { key, value } = attr;
|
|
1090
1196
|
let jsxValue = null;
|
|
1091
1197
|
let type = '';
|
|
1092
1198
|
let content = '';
|
|
1093
1199
|
if (value) {
|
|
1200
|
+
const cacheValue = value;
|
|
1094
1201
|
if (key === 'class' && value.startsWith('[') && value.endsWith(']')) {
|
|
1095
1202
|
value = value.slice(1, value.length - 1).replace(',', '');
|
|
1203
|
+
(0, utils_1.createErrorCodeMsg)('unsupportedClassArray', 'Taro/React 不支持 class 传入数组,此写法可能无法得到正确的 class', `class=${JSON.stringify(cacheValue).replace(/"/g, "'")}`, global_1.globals.currentParseFile);
|
|
1204
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] parseAttribute - Taro/React 不支持 class 传入数组,此写法可能无法得到正确的 class ${(0, utils_1.getLineBreak)()}`);
|
|
1096
1205
|
// eslint-disable-next-line no-console
|
|
1097
1206
|
console.log((0, utils_1.codeFrameError)(attr, 'Taro/React 不支持 class 传入数组,此写法可能无法得到正确的 class'));
|
|
1098
1207
|
}
|
|
@@ -1110,10 +1219,8 @@ function parseAttribute(attr) {
|
|
|
1110
1219
|
}
|
|
1111
1220
|
}
|
|
1112
1221
|
catch (error) {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
(0, utils_1.printToLogFile)(`package: taroize, style="${value}" 解析异常 ${(0, utils_1.getLineBreak)()}`);
|
|
1116
|
-
throw new Error(errorMsg);
|
|
1222
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] parseAttribute - 属性 style="${value}" 解析异常 ${(0, utils_1.getLineBreak)()}${error} ${(0, utils_1.getLineBreak)()}`);
|
|
1223
|
+
throw new utils_1.IReportError(`属性解析失败 style="${value}"解析失败,${error}`, 'StyleAttributeParsingError', 'WXML_FILE', `style="${value}"`);
|
|
1117
1224
|
}
|
|
1118
1225
|
}
|
|
1119
1226
|
else {
|
|
@@ -1137,7 +1244,8 @@ function parseAttribute(attr) {
|
|
|
1137
1244
|
expr = t.stringLiteral('');
|
|
1138
1245
|
}
|
|
1139
1246
|
else {
|
|
1140
|
-
|
|
1247
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] parseAttribute - 模板参数转换异常 ${(0, utils_1.getLineBreak)()}${err} ${(0, utils_1.getLineBreak)()}`);
|
|
1248
|
+
throw new utils_1.IReportError(err, 'TemplateParameterConversionError', 'WXML_FILE', `${key}: ${value}`);
|
|
1141
1249
|
}
|
|
1142
1250
|
}
|
|
1143
1251
|
else if (content.includes(':') || content.includes('...')) {
|
|
@@ -1148,10 +1256,13 @@ function parseAttribute(attr) {
|
|
|
1148
1256
|
}
|
|
1149
1257
|
else {
|
|
1150
1258
|
const err = `转换模板参数: \`${key}: ${value}\` 报错`;
|
|
1151
|
-
|
|
1259
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] parseAttribute - 模板参数转换异常 ${(0, utils_1.getLineBreak)()}${err} ${(0, utils_1.getLineBreak)()}`);
|
|
1260
|
+
throw new utils_1.IReportError(err, 'TemplateParameterConversionError', 'WXML_FILE', `${key}: ${value}`);
|
|
1152
1261
|
}
|
|
1153
1262
|
}
|
|
1154
1263
|
if (t.isThisExpression(expr)) {
|
|
1264
|
+
(0, utils_1.createErrorCodeMsg)('ThisKeywordUsageWarning', '在参数中使用 `this` 可能会造成意想不到的结果,已将此参数修改为 `__placeholder__`,你可以在转换后的代码查找这个关键字修改。', value, global_1.globals.currentParseFile);
|
|
1265
|
+
(0, utils_1.updateLogFileContent)(`WARN [taroize] parseAttribute - 在参数中使用 this 可能会造成意想不到的结果 ${(0, utils_1.getLineBreak)()}`);
|
|
1155
1266
|
console.error('在参数中使用 `this` 可能会造成意想不到的结果,已将此参数修改为 `__placeholder__`,你可以在转换后的代码查找这个关键字修改。');
|
|
1156
1267
|
expr = t.stringLiteral('__placeholder__');
|
|
1157
1268
|
}
|
|
@@ -1195,7 +1306,8 @@ function handleAttrKey(key) {
|
|
|
1195
1306
|
key = key.replace(/^(bind:|catch:|bind|catch)/, 'on');
|
|
1196
1307
|
key = (0, lodash_1.camelCase)(key);
|
|
1197
1308
|
if (!(0, utils_1.isValidVarName)(key)) {
|
|
1198
|
-
|
|
1309
|
+
(0, utils_1.updateLogFileContent)(`ERROR [taroize] handleAttrKey - ${key} 不是一个有效 JavaScript 变量名 ${(0, utils_1.getLineBreak)()}`);
|
|
1310
|
+
throw new utils_1.IReportError(`属性名"${key}" 不是一个有效 JavaScript 变量名`, 'InvalidVariableNameError', 'WXML_FILE', `${key}`);
|
|
1199
1311
|
}
|
|
1200
1312
|
return key.substr(0, 2) + key[2].toUpperCase() + key.substr(3);
|
|
1201
1313
|
}
|