@aiot-toolkit/parser 2.0.6-beta.15 → 2.0.6-beta.17

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.
@@ -36,7 +36,7 @@ class ParserUtil {
36
36
  * @param offsetList
37
37
  */
38
38
  static getOffsetColumn(position, offsetList) {
39
- if (!(offsetList !== null && offsetList !== void 0 && offsetList.length)) {
39
+ if (!offsetList?.length) {
40
40
  return 0;
41
41
  }
42
42
  const {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.STYLE_ATTRIBUTE_LIST = exports.STYLE_ATTRIBUTE_CONFIG = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _ExtendedBoxStyle = _interopRequireDefault(require("../translate/vela/utils/ExtendedBoxStyle"));
10
9
  var _UxUtil = _interopRequireDefault(require("../utils/UxUtil"));
@@ -4,10 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
- require("core-js/modules/web.url-search-params.delete.js");
9
- require("core-js/modules/web.url-search-params.has.js");
10
- require("core-js/modules/web.url-search-params.size.js");
11
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
12
8
  var _cssTree = _interopRequireWildcard(require("css-tree"));
13
9
  var _lodash = _interopRequireDefault(require("lodash"));
@@ -128,8 +124,7 @@ class StyleParser {
128
124
  * @returns
129
125
  */
130
126
  getAlias() {
131
- var _CommonUtil$requireMo;
132
- return ((_CommonUtil$requireMo = _sharedUtils.CommonUtil.requireModule(_path.default.join(this.options.projectPath, this.QUICKAPP_CONFIG))) === null || _CommonUtil$requireMo === void 0 || (_CommonUtil$requireMo = _CommonUtil$requireMo.webpack) === null || _CommonUtil$requireMo === void 0 || (_CommonUtil$requireMo = _CommonUtil$requireMo.resolve) === null || _CommonUtil$requireMo === void 0 ? void 0 : _CommonUtil$requireMo.alias) || {};
127
+ return _sharedUtils.CommonUtil.requireModule(_path.default.join(this.options.projectPath, this.QUICKAPP_CONFIG))?.webpack?.resolve?.alias || {};
133
128
  }
134
129
  /**
135
130
  * 将Less样式转为CSS
@@ -166,8 +161,8 @@ class StyleParser {
166
161
  });
167
162
  reject(`### lessToCss ### ${error}`);
168
163
  } else {
169
- CSSCode = output !== null && output !== void 0 && output.css ? output.css : '';
170
- if (output !== null && output !== void 0 && output.map) {
164
+ CSSCode = output?.css ? output.css : '';
165
+ if (output?.map) {
171
166
  this.nodeMap = output.map;
172
167
  this.isCss && (this.isCss = false);
173
168
  }
@@ -274,7 +269,7 @@ class StyleParser {
274
269
  onLog({
275
270
  level: _sharedUtils.Loglevel.THROW,
276
271
  filePath,
277
- message: `### Css ### ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`
272
+ message: `### Css ### ${error?.toString() || 'unknown error'}`
278
273
  });
279
274
  }
280
275
  }
@@ -418,9 +413,8 @@ class StyleParser {
418
413
  if (_StyleUtil.default.isSelectorList(sourceNode)) {
419
414
  sourceNode.children.toArray().forEach(node => {
420
415
  if ('children' in node) {
421
- var _node$children;
422
416
  let childResult = [];
423
- (_node$children = node.children) === null || _node$children === void 0 || _node$children.toArray().forEach(childNode => {
417
+ node.children?.toArray().forEach(childNode => {
424
418
  childResult.push({
425
419
  type: childNode.type,
426
420
  name: _StyleUtil.default.generateNodename(childNode)
@@ -532,7 +526,7 @@ class StyleParser {
532
526
  // 警告:不能为空
533
527
  onLog({
534
528
  level: _sharedUtils.Loglevel.WARN,
535
- filePath: (tempPosition === null || tempPosition === void 0 ? void 0 : tempPosition.source) || filePath,
529
+ filePath: tempPosition?.source || filePath,
536
530
  position: tempPosition,
537
531
  message: ['The value in', {
538
532
  word: 'url'
@@ -600,7 +594,8 @@ class StyleParser {
600
594
  }
601
595
  return targetList;
602
596
  }
603
- printError(errorType, errors = []) {
597
+ printError(errorType) {
598
+ let errors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
604
599
  let isParserError = errorType === 'parserError';
605
600
  let sourceCodeStyle = _sharedUtils.Loglevel.WARN;
606
601
  if (isParserError) {
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.TemplateValueType = void 0;
7
- require("core-js/modules/es.error.cause.js");
8
- require("core-js/modules/es.array.push.js");
9
7
  let TemplateValueType = exports.TemplateValueType = /*#__PURE__*/function (TemplateValueType) {
10
8
  TemplateValueType[TemplateValueType["CHAR"] = 1] = "CHAR";
11
9
  TemplateValueType[TemplateValueType["CODE"] = 2] = "CODE";
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var parse5 = _interopRequireWildcard(require("aiot-parse5"));
10
9
  var _path = _interopRequireDefault(require("path"));
@@ -26,7 +25,6 @@ class UxParser {
26
25
  this.collectImageResource = collectImageResource;
27
26
  }
28
27
  async parser() {
29
- var _childNode$childNodes, _childNode$sourceCode;
30
28
  const content = this.options.content;
31
29
  const fileName = _path.default.basename(this.options.filePath);
32
30
  const ast = {
@@ -63,7 +61,7 @@ class UxParser {
63
61
  case 'script':
64
62
  // 存储script正文的偏移行数
65
63
  this.options.scriptOffsetLine = 0;
66
- if (childNode !== null && childNode !== void 0 && (_childNode$childNodes = childNode.childNodes) !== null && _childNode$childNodes !== void 0 && (_childNode$childNodes = _childNode$childNodes[0]) !== null && _childNode$childNodes !== void 0 && _childNode$childNodes.sourceCodeLocation) {
64
+ if (childNode?.childNodes?.[0]?.sourceCodeLocation) {
67
65
  this.options.scriptOffsetLine = childNode.childNodes[0].sourceCodeLocation.startLine || 0;
68
66
  }
69
67
  const scriptContent = parse5.serialize(childNode);
@@ -81,7 +79,7 @@ class UxParser {
81
79
  // 转换全局变量为符合lang类型的字符串
82
80
  const globalStyle = _UxUtil.default.convertGlobalJson(this.globalVar, langType);
83
81
  // 解析CSS 转为 js格式的内容
84
- const cssParserResult = await new _StyleParser.default(this.options, this.compilerOption, this.collectImageResource, ((_childNode$sourceCode = childNode.sourceCodeLocation) === null || _childNode$sourceCode === void 0 ? void 0 : _childNode$sourceCode.startLine) || 0).parser(`${cssContent}\n${globalStyle}`, cssFileName);
82
+ const cssParserResult = await new _StyleParser.default(this.options, this.compilerOption, this.collectImageResource, childNode.sourceCodeLocation?.startLine || 0).parser(`${cssContent}\n${globalStyle}`, cssFileName);
85
83
  // 多Style标签(TODO: 应该不支持多style标签)
86
84
  ast.style.styleContent.push(...cssParserResult.ast.styleContent);
87
85
  ast.style.content = parse5.serialize(childNode);
@@ -100,7 +98,6 @@ class UxParser {
100
98
  };
101
99
  }
102
100
  parserSyncWithoutStyle() {
103
- var _childNode$childNodes2;
104
101
  const content = this.options.content;
105
102
  const fileName = _path.default.basename(this.options.filePath);
106
103
  const ast = {
@@ -140,7 +137,7 @@ class UxParser {
140
137
  case 'script':
141
138
  // 存储script正文的偏移行数
142
139
  this.options.scriptOffsetLine = 0;
143
- if (childNode !== null && childNode !== void 0 && (_childNode$childNodes2 = childNode.childNodes) !== null && _childNode$childNodes2 !== void 0 && (_childNode$childNodes2 = _childNode$childNodes2[0]) !== null && _childNode$childNodes2 !== void 0 && _childNode$childNodes2.sourceCodeLocation) {
140
+ if (childNode?.childNodes?.[0]?.sourceCodeLocation) {
144
141
  this.options.scriptOffsetLine = childNode.childNodes[0].sourceCodeLocation.startLine || 0;
145
142
  }
146
143
  const scriptContent = parse5.serialize(childNode);
@@ -236,11 +233,10 @@ class UxParser {
236
233
  const templateChildNodes = templateNode.content.childNodes;
237
234
  const elements = templateChildNodes.filter(node => _TemplateUtil.default.isElement(node));
238
235
  if (elements.length !== 1) {
239
- var _templateNode$sourceC;
240
236
  onLog({
241
237
  level: _sharedUtils.Loglevel.THROW,
242
238
  filePath,
243
- position: _TemplateUtil.default.parse5LocationToPosition((_templateNode$sourceC = templateNode.sourceCodeLocation) === null || _templateNode$sourceC === void 0 ? void 0 : _templateNode$sourceC.startTag),
239
+ position: _TemplateUtil.default.parse5LocationToPosition(templateNode.sourceCodeLocation?.startTag),
244
240
  message: [{
245
241
  word: '<template>'
246
242
  }, `There are`, {
@@ -300,10 +296,9 @@ class UxParser {
300
296
  ...sourceNode
301
297
  });
302
298
  } else {
303
- var _sourceNode$sourceCod;
304
299
  onLog({
305
300
  filePath: this.options.filePath,
306
- position: _TemplateUtil.default.parse5LocationToPosition((_sourceNode$sourceCod = sourceNode.sourceCodeLocation) === null || _sourceNode$sourceCod === void 0 ? void 0 : _sourceNode$sourceCod.startTag),
301
+ position: _TemplateUtil.default.parse5LocationToPosition(sourceNode.sourceCodeLocation?.startTag),
307
302
  level: _sharedUtils.Loglevel.ERROR,
308
303
  message: ['### uxParser ### import missing', {
309
304
  word: `name or src`
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _lodash = _interopRequireDefault(require("lodash"));
10
9
  var _ParserUtil = _interopRequireDefault(require("../../../utils/ParserUtil"));
@@ -21,7 +20,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
21
20
  */
22
21
  class TemplateToTypescript {
23
22
  _mapList = [];
24
- elementUtil = new _ElementConfigUtil.default(_ElementConfig.default);
23
+ elementUtil = (() => new _ElementConfigUtil.default(_ElementConfig.default))();
25
24
  constructor(options, compilerOption, importList) {
26
25
  this.options = options;
27
26
  this.compilerOption = compilerOption;
@@ -101,7 +100,7 @@ class TemplateToTypescript {
101
100
  } = node;
102
101
  const translateList = [new _ForTranslate.default(this.options, this.compilerOption), new _IfTranslate.default(this.options, this.compilerOption)];
103
102
  const elementConfig = this.elementUtil.getElementConfig(tagName);
104
- const effectType = (elementConfig === null || elementConfig === void 0 ? void 0 : elementConfig.aliasName) || tagName;
103
+ const effectType = elementConfig?.aliasName || tagName;
105
104
  // 1.a
106
105
  const result = {
107
106
  type: `'${effectType}'`,
@@ -175,8 +174,7 @@ class TemplateToTypescript {
175
174
  if (effectChildNodes.length) {
176
175
  result.children = [];
177
176
  for (const item of effectChildNodes) {
178
- var _result$children;
179
- (_result$children = result.children) === null || _result$children === void 0 || _result$children.push(await this.createTargetNode(item, existingIdentifiers));
177
+ result.children?.push(await this.createTargetNode(item, existingIdentifiers));
180
178
  }
181
179
  }
182
180
  return result;
@@ -241,10 +239,9 @@ class TemplateToTypescript {
241
239
  childNodes
242
240
  } = node;
243
241
  let result = attrs.map(item => {
244
- var _node$sourceCodeLocat;
245
242
  return {
246
243
  ...item,
247
- nameLocation: _TemplateUtil.default.parse5LocationToPosition((_node$sourceCodeLocat = node.sourceCodeLocation) === null || _node$sourceCodeLocat === void 0 || (_node$sourceCodeLocat = _node$sourceCodeLocat.attrs) === null || _node$sourceCodeLocat === void 0 ? void 0 : _node$sourceCodeLocat[item.name])
244
+ nameLocation: _TemplateUtil.default.parse5LocationToPosition(node.sourceCodeLocation?.attrs?.[item.name])
248
245
  };
249
246
  });
250
247
 
@@ -139,7 +139,7 @@ class UxToTypescript {
139
139
  style
140
140
  } = data;
141
141
  const scriptValue = this.wrapScript(script);
142
- return [imports.join('\n'), [`const $style$ = ${JSON.stringify(style)}`, `const $template$ = ${(template === null || template === void 0 ? void 0 : template.getFullText()) || `''`}`].join('\n'), `const $script$=${scriptValue || 'null'}`, `module.exports = function ($app_require$, $app_exports$, $app_module$) {
142
+ return [imports.join('\n'), [`const $style$ = ${JSON.stringify(style)}`, `const $template$ = ${template?.getFullText() || `''`}`].join('\n'), `const $script$=${scriptValue || 'null'}`, `module.exports = function ($app_require$, $app_exports$, $app_module$) {
143
143
  ${this.ruleScript(Boolean(scriptValue))}
144
144
  $app_module$.exports.template = $template$
145
145
  $app_module$.exports.style = $style$;
@@ -170,7 +170,7 @@ class UxToTypescript {
170
170
  return '';
171
171
  }
172
172
  wrapScript(script) {
173
- const code = script === null || script === void 0 ? void 0 : script.getFullText();
173
+ const code = script?.getFullText();
174
174
  const {
175
175
  fileType
176
176
  } = this.options;
@@ -54,10 +54,9 @@ class ForTranslate {
54
54
  indexNode
55
55
  } = _CfTranslate.default.extractForNodes(forAttribute, this.options);
56
56
  if (!listNode) {
57
- var _node$sourceCodeLocat;
58
57
  onLog({
59
58
  filePath,
60
- position: _TemplateUtil.default.parse5LocationToPosition((_node$sourceCodeLocat = node.sourceCodeLocation) === null || _node$sourceCodeLocat === void 0 || (_node$sourceCodeLocat = _node$sourceCodeLocat.attrs) === null || _node$sourceCodeLocat === void 0 ? void 0 : _node$sourceCodeLocat[this.KEY]),
59
+ position: _TemplateUtil.default.parse5LocationToPosition(node.sourceCodeLocation?.attrs?.[this.KEY]),
61
60
  level: _sharedUtils.Loglevel.THROW,
62
61
  message: [{
63
62
  word: 'list'
@@ -4,14 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
- require("core-js/modules/es.set.difference.v2.js");
9
- require("core-js/modules/es.set.intersection.v2.js");
10
- require("core-js/modules/es.set.is-disjoint-from.v2.js");
11
- require("core-js/modules/es.set.is-subset-of.v2.js");
12
- require("core-js/modules/es.set.is-superset-of.v2.js");
13
- require("core-js/modules/es.set.symmetric-difference.v2.js");
14
- require("core-js/modules/es.set.union.v2.js");
15
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
16
8
  var babel = _interopRequireWildcard(require("@babel/core"));
17
9
  var _path = _interopRequireDefault(require("path"));
@@ -27,8 +19,9 @@ const BabelPreset = require('@babel/preset-env');
27
19
  * ScriptToTypescript
28
20
  */
29
21
  class ScriptToTypescript {
30
- _systemFeatures = new Set();
31
- constructor(options, compilerOption, context, disableCheckCode = false) {
22
+ _systemFeatures = (() => new Set())();
23
+ constructor(options, compilerOption, context) {
24
+ let disableCheckCode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
32
25
  this.options = options;
33
26
  this.compilerOption = compilerOption;
34
27
  this.context = context;
@@ -103,15 +96,14 @@ class ScriptToTypescript {
103
96
  }]],
104
97
  plugins
105
98
  });
106
- return (babelResult === null || babelResult === void 0 ? void 0 : babelResult.code) || '';
99
+ return babelResult?.code || '';
107
100
  } catch (error) {
108
101
  const loc = error.loc;
109
102
  const babelError = error;
110
103
  let position = undefined;
111
104
  let message = babelError.message;
112
105
  if (loc) {
113
- var _sourceTree$sourceCod;
114
- const offsetLine = (((_sourceTree$sourceCod = sourceTree.sourceCodeLocation) === null || _sourceTree$sourceCod === void 0 ? void 0 : _sourceTree$sourceCod.startLine) || 0) - 1;
106
+ const offsetLine = (sourceTree.sourceCodeLocation?.startLine || 0) - 1;
115
107
  const startLine = loc.line + offsetLine;
116
108
  const startColumn = loc.column;
117
109
  // babel 错误信息中包含行列信息,需要替换
@@ -203,10 +195,9 @@ class ScriptToTypescript {
203
195
  }
204
196
  }
205
197
  }).lintText(code);
206
- if (lintResult !== null && lintResult !== void 0 && lintResult.length) {
207
- var _sourceTree$sourceCod2;
198
+ if (lintResult?.length) {
208
199
  const result = [];
209
- const offsetLine = (((_sourceTree$sourceCod2 = sourceTree.sourceCodeLocation) === null || _sourceTree$sourceCod2 === void 0 ? void 0 : _sourceTree$sourceCod2.startLine) || 0) - 1;
200
+ const offsetLine = (sourceTree.sourceCodeLocation?.startLine || 0) - 1;
210
201
  lintResult.forEach(item => {
211
202
  item.messages.forEach(message => {
212
203
  result.push({
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _StyleSelectorType = require("../../enum/StyleSelectorType");
10
9
  var _StyleUtil = _interopRequireDefault(require("../../utils/StyleUtil"));
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _tsMorph = require("ts-morph");
10
9
  var _ElementConfig = _interopRequireDefault(require("../../config/vela/ElementConfig"));
@@ -22,14 +21,14 @@ const STATIC_NAME = 'static';
22
21
  * TemplateToTypescript
23
22
  */
24
23
  class TemplateToTypescript {
25
- project = new _tsMorph.Project({
24
+ project = (() => new _tsMorph.Project({
26
25
  useInMemoryFileSystem: true,
27
26
  manipulationSettings: {
28
27
  indentationText: _tsMorph.IndentationText.TwoSpaces
29
28
  }
30
- });
29
+ }))();
31
30
  _mapList = [];
32
- elementConfigUtil = new _ElementConfigUtil.default(_ElementConfig.default);
31
+ elementConfigUtil = (() => new _ElementConfigUtil.default(_ElementConfig.default))();
33
32
  /**
34
33
  *
35
34
  * @param importList 组件列表
@@ -116,10 +115,9 @@ class TemplateToTypescript {
116
115
  nodeName
117
116
  } = node;
118
117
  let result = attrs.map(item => {
119
- var _node$sourceCodeLocat;
120
118
  return {
121
119
  ...item,
122
- nameLocation: _TemplateUtil.default.parse5LocationToPosition((_node$sourceCodeLocat = node.sourceCodeLocation) === null || _node$sourceCodeLocat === void 0 || (_node$sourceCodeLocat = _node$sourceCodeLocat.attrs) === null || _node$sourceCodeLocat === void 0 ? void 0 : _node$sourceCodeLocat[item.name])
120
+ nameLocation: _TemplateUtil.default.parse5LocationToPosition(node.sourceCodeLocation?.attrs?.[item.name])
123
121
  };
124
122
  });
125
123
  // 1.a
@@ -177,10 +175,10 @@ class TemplateToTypescript {
177
175
  item.name = attributeName;
178
176
 
179
177
  // 4.a
180
- const effectDecorator = hasStaticAttribute ? decorator === null || decorator === void 0 ? void 0 : decorator.filter(item => item !== STATIC_NAME) : decorator;
178
+ const effectDecorator = hasStaticAttribute ? decorator?.filter(item => item !== STATIC_NAME) : decorator;
181
179
 
182
180
  // 4.b
183
- if (effectDecorator !== null && effectDecorator !== void 0 && effectDecorator.length && !excludesAttributes.includes(attributeName)) {
181
+ if (effectDecorator?.length && !excludesAttributes.includes(attributeName)) {
184
182
  const modiferName = attributeName;
185
183
  modifiers[modiferName] = Object.fromEntries(effectDecorator.map(item => [item, true]));
186
184
  }
@@ -231,7 +229,7 @@ class TemplateToTypescript {
231
229
  callerName: '__ce__',
232
230
  tag: {
233
231
  name: 'span',
234
- location: _TemplateUtil.default.parse5LocationToPosition(sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag)
232
+ location: _TemplateUtil.default.parse5LocationToPosition(sourceCodeLocation?.startTag)
235
233
  },
236
234
  attributes: [{
237
235
  name: 'value',
@@ -254,7 +252,7 @@ class TemplateToTypescript {
254
252
  word: nodeName
255
253
  }, `unsupport text as child, replace as`, {
256
254
  word: `<text>${this.templateUtil.getTextContent(textChildren[0], this.elementConfigUtil)}</text>`
257
- }, docHelp === null || docHelp === void 0 ? void 0 : docHelp.createWidgetReferenceMessage({
255
+ }, docHelp?.createWidgetReferenceMessage({
258
256
  componentName: 'text'
259
257
  })],
260
258
  filePath: this.options.filePath,
@@ -266,7 +264,7 @@ class TemplateToTypescript {
266
264
  // 提取标识符,用于创建节点函数
267
265
  const currentIdentifiers = this.getIdentifiersFromNode(node);
268
266
  const allIdentifiers = [...(identifiers || []), ...currentIdentifiers];
269
- const hasElementChildren = childNodes === null || childNodes === void 0 ? void 0 : childNodes.some(item => _TemplateUtil.default.isElement(item));
267
+ const hasElementChildren = childNodes?.some(item => _TemplateUtil.default.isElement(item));
270
268
  let effectChildNodes = childNodes ? childNodes.filter(item => {
271
269
  // 当前元素
272
270
  // 1. “允许文本子节点,且有普通元素”,则分别处理普通子元素和文本子元素,例如: `<text>aaa<span>abc</span></text>`,需要分别处理 aaa和 <span>abc</span>
@@ -288,13 +286,12 @@ class TemplateToTypescript {
288
286
  callerName: name,
289
287
  tag: {
290
288
  name: nodeName,
291
- location: _TemplateUtil.default.parse5LocationToPosition(sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag)
289
+ location: _TemplateUtil.default.parse5LocationToPosition(sourceCodeLocation?.startTag)
292
290
  },
293
291
  attributes: attributes.map(item => {
294
- var _sourceCodeLocation$a;
295
292
  return {
296
293
  ...item,
297
- nameLocation: item.nameLocation || _TemplateUtil.default.parse5LocationToPosition(sourceCodeLocation === null || sourceCodeLocation === void 0 || (_sourceCodeLocation$a = sourceCodeLocation.attrs) === null || _sourceCodeLocation$a === void 0 ? void 0 : _sourceCodeLocation$a[item.name])
294
+ nameLocation: item.nameLocation || _TemplateUtil.default.parse5LocationToPosition(sourceCodeLocation?.attrs?.[item.name])
298
295
  };
299
296
  }),
300
297
  children,
@@ -372,7 +369,7 @@ class TemplateToTypescript {
372
369
  const {
373
370
  importList
374
371
  } = this;
375
- return importList === null || importList === void 0 ? void 0 : importList.map(item => item.toLowerCase()).includes(componentName.toLowerCase());
372
+ return importList?.map(item => item.toLowerCase()).includes(componentName.toLowerCase());
376
373
  }
377
374
 
378
375
  /**
@@ -384,13 +381,12 @@ class TemplateToTypescript {
384
381
  * @returns
385
382
  */
386
383
  async createElementWrap(node, elementExpression, infomation, identifiers) {
387
- var _this$compilerOption;
388
384
  // 1
389
385
  if (_TemplateUtil.default.isText(node)) {
390
386
  return elementExpression;
391
387
  }
392
388
  const translateList = [new _CbTranslate.default(this.options, this.compilerOption, infomation), new _CfTranslate.default(this.options, this.compilerOption), new _CiTranslate.default(this.options, this.compilerOption)];
393
- const params = (_this$compilerOption = this.compilerOption) !== null && _this$compilerOption !== void 0 && _this$compilerOption.enableProtobuf ? ['aiot'].join(',') : '';
389
+ const params = this.compilerOption?.enableProtobuf ? ['aiot'].join(',') : '';
394
390
  let result = elementExpression;
395
391
  for (let item of translateList) {
396
392
  if (item.match(node)) {
@@ -440,7 +436,7 @@ class TemplateToTypescript {
440
436
  result.hasStaticAttribute = attributeName.toLowerCase() === STATIC_NAME;
441
437
  }
442
438
  if (!result.hasStaticDecorator) {
443
- result.hasStaticDecorator = attributeName !== STATIC_NAME && Boolean(decorator === null || decorator === void 0 ? void 0 : decorator.includes(STATIC_NAME));
439
+ result.hasStaticDecorator = attributeName !== STATIC_NAME && Boolean(decorator?.includes(STATIC_NAME));
444
440
  }
445
441
  if (!result.hasEvent) {
446
442
  result.hasEvent = _TemplateUtil.default.isEventAttribute(attributeName);
@@ -4,17 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.set.difference.v2.js");
8
- require("core-js/modules/es.set.intersection.v2.js");
9
- require("core-js/modules/es.set.is-disjoint-from.v2.js");
10
- require("core-js/modules/es.set.is-subset-of.v2.js");
11
- require("core-js/modules/es.set.is-superset-of.v2.js");
12
- require("core-js/modules/es.set.symmetric-difference.v2.js");
13
- require("core-js/modules/es.set.union.v2.js");
14
7
  /**
15
8
  * TranslateCache
16
9
  */
17
10
  class TranslateCache {
18
- featureCache = new Set();
11
+ featureCache = (() => new Set())();
19
12
  }
20
13
  var _default = exports.default = TranslateCache;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = e2e;
7
- require("core-js/modules/es.array.push.js");
8
7
  var t = _interopRequireWildcard(require("@babel/types"));
9
8
  var parser = _interopRequireWildcard(require("@babel/parser"));
10
9
  var _path = _interopRequireDefault(require("path"));
@@ -22,9 +21,10 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
22
21
  function e2e() {
23
22
  return {
24
23
  visitor: {
25
- ExportDefaultDeclaration(path, {
26
- opts
27
- }) {
24
+ ExportDefaultDeclaration(path, _ref) {
25
+ let {
26
+ opts
27
+ } = _ref;
28
28
  const opts2 = opts;
29
29
  const options = opts2.options;
30
30
  switch (options.fileType) {
@@ -114,7 +114,6 @@ function addPageTestCode(path, opts) {
114
114
  }
115
115
  }
116
116
  function getTestcaseConfig(filePath, opts, e2eConfig) {
117
- var _e2eConfig$testcases;
118
117
  const {
119
118
  projectPath
120
119
  } = opts.options;
@@ -123,7 +122,7 @@ function getTestcaseConfig(filePath, opts, e2eConfig) {
123
122
  } = opts.compilerOption;
124
123
  const relativeSrc = _path.default.relative(_path.default.join(projectPath, sourceRoot || ''), filePath);
125
124
  const pageName = _path.default.dirname(relativeSrc).replace(/\\/g, _path.default.posix.sep);
126
- return (_e2eConfig$testcases = e2eConfig.testcases) === null || _e2eConfig$testcases === void 0 ? void 0 : _e2eConfig$testcases.find(item => item.name === pageName);
125
+ return e2eConfig.testcases?.find(item => item.name === pageName);
127
126
  }
128
127
 
129
128
  /**
@@ -15,9 +15,10 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
15
15
  function translateRequire() {
16
16
  return {
17
17
  visitor: {
18
- CallExpression(path, {
19
- opts
20
- }) {
18
+ CallExpression(path, _ref) {
19
+ let {
20
+ opts
21
+ } = _ref;
21
22
  const {
22
23
  node
23
24
  } = path;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = startPage;
7
- require("core-js/modules/web.url.parse.js");
8
7
  var _url = _interopRequireDefault(require("url"));
9
8
  var _BabelUtil = _interopRequireDefault(require("../../../utils/BabelUtil"));
10
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.eventAttributeTranslate = exports.defaultAttributeTranslate = exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _tsMorph = require("ts-morph");
10
9
  var _ParserUtil = _interopRequireDefault(require("../../../../utils/ParserUtil"));
@@ -46,7 +45,6 @@ const ATTRIBUTE_CONFIG = {
46
45
  return global.$translateStyle$(${result})
47
46
  }`;
48
47
  } else {
49
- var _styleResult$targetTr;
50
48
  const logs = [];
51
49
  const onLog = log => {
52
50
  logs.push(log);
@@ -76,7 +74,7 @@ const ATTRIBUTE_CONFIG = {
76
74
  option.onLog(log);
77
75
  });
78
76
  }
79
- const value = (_styleResult$targetTr = styleResult.targetTree) === null || _styleResult$targetTr === void 0 || (_styleResult$targetTr = _styleResult$targetTr[0]) === null || _styleResult$targetTr === void 0 ? void 0 : _styleResult$targetTr[1];
77
+ const value = styleResult.targetTree?.[0]?.[1];
80
78
  return JSON.stringify(value);
81
79
  }
82
80
  }
@@ -108,7 +106,8 @@ const ATTRIBUTE_CONFIG = {
108
106
  * @param disabledWrap 是否禁用函数包裹。因为普通属性不用函数无法动态响应,而 for 的 list 属性设置函数又报错;所以这里临时加一个参数,在生成__list__的地方手动设置为 true
109
107
  * @returns
110
108
  */
111
- const defaultAttributeTranslate = (value, disabledWrap = false) => {
109
+ const defaultAttributeTranslate = function (value) {
110
+ let disabledWrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
112
111
  if (disabledWrap) {
113
112
  return value;
114
113
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _generator = _interopRequireDefault(require("@babel/generator"));
10
9
  var traverse = _interopRequireWildcard(require("@babel/traverse"));
@@ -61,8 +60,8 @@ class TemplateUtil {
61
60
  return m.toUpperCase();
62
61
  });
63
62
  };
64
- const separateModelValue = params === null || params === void 0 ? void 0 : params.separateModelValue;
65
- const nameToCamel = params === null || params === void 0 ? void 0 : params.nameToCamel;
63
+ const separateModelValue = params?.separateModelValue;
64
+ const nameToCamel = params?.nameToCamel;
66
65
  const result = {};
67
66
  for (const item of attributes) {
68
67
  const {
@@ -110,7 +109,7 @@ class TemplateUtil {
110
109
  */
111
110
  translateAttributeName(name) {
112
111
  const config = _AttributeConfig.default[name];
113
- if (config !== null && config !== void 0 && config.aliasName) {
112
+ if (config?.aliasName) {
114
113
  return config.aliasName;
115
114
  }
116
115
  if (TemplateUtil.isEventAttribute(name)) {
@@ -130,7 +129,8 @@ class TemplateUtil {
130
129
  * @param attribute
131
130
  * @returns
132
131
  */
133
- async translateAttributeValue(attribute, identifiers, disabledWrap = false) {
132
+ async translateAttributeValue(attribute, identifiers) {
133
+ let disabledWrap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
134
134
  let {
135
135
  name,
136
136
  value,
@@ -196,7 +196,7 @@ class TemplateUtil {
196
196
  onLog,
197
197
  filePath
198
198
  } = this.option;
199
- const nameLocation = ownerNode === null || ownerNode === void 0 ? void 0 : ownerNode.nameLocation;
199
+ const nameLocation = ownerNode?.nameLocation;
200
200
 
201
201
  /**
202
202
  * 遍历标识符,如果满足以下条件,不加前缀
@@ -217,7 +217,7 @@ class TemplateUtil {
217
217
  return code;
218
218
  }
219
219
  const ast = types.file(types.program([types.expressionStatement(expression)]));
220
- const bodyNode = ast === null || ast === void 0 ? void 0 : ast.program.body[0];
220
+ const bodyNode = ast?.program.body[0];
221
221
  if (ast) {
222
222
  traverse.default(ast, {
223
223
  Identifier(path) {
@@ -366,7 +366,7 @@ class TemplateUtil {
366
366
  return `validateElement ${tag} error`;
367
367
  }
368
368
  const elementConfig = getElementConfig(tag.name);
369
- const effectTag = (elementConfig === null || elementConfig === void 0 ? void 0 : elementConfig.aliasName) || tag.name;
369
+ const effectTag = elementConfig?.aliasName || tag.name;
370
370
  const {
371
371
  globalInstance,
372
372
  dataInstance,
@@ -396,10 +396,9 @@ class TemplateUtil {
396
396
  } = node;
397
397
  const target = attrs.find(item => TemplateUtil.parseAttributeName(item.name).attributeName.toLowerCase() === name);
398
398
  if (target) {
399
- var _node$sourceCodeLocat;
400
399
  return {
401
400
  ...target,
402
- nameLocation: TemplateUtil.parse5LocationToPosition((_node$sourceCodeLocat = node.sourceCodeLocation) === null || _node$sourceCodeLocat === void 0 || (_node$sourceCodeLocat = _node$sourceCodeLocat.attrs) === null || _node$sourceCodeLocat === void 0 ? void 0 : _node$sourceCodeLocat[target.name])
401
+ nameLocation: TemplateUtil.parse5LocationToPosition(node.sourceCodeLocation?.attrs?.[target.name])
403
402
  };
404
403
  }
405
404
  }
@@ -442,8 +441,7 @@ class TemplateUtil {
442
441
  const forceDynamicList = ['if', 'for'];
443
442
  let result = TemplateUtil.isEventAttribute(attributeName) || forceDynamicList.includes(attributeName.toLowerCase());
444
443
  if (!result) {
445
- var _getElementConfig;
446
- const config = (_getElementConfig = getElementConfig(nodeName)) === null || _getElementConfig === void 0 || (_getElementConfig = _getElementConfig.attributes) === null || _getElementConfig === void 0 ? void 0 : _getElementConfig[attributeName];
444
+ const config = getElementConfig(nodeName)?.attributes?.[attributeName];
447
445
  if (config && config.forceDynamic) {
448
446
  result = true;
449
447
  }
@@ -571,7 +569,7 @@ class TemplateUtil {
571
569
  if (attribute) {
572
570
  const {
573
571
  decorator
574
- } = TemplateUtil.parseAttributeName(attribute === null || attribute === void 0 ? void 0 : attribute.name);
572
+ } = TemplateUtil.parseAttributeName(attribute?.name);
575
573
  if (decorator) {
576
574
  return {
577
575
  [decoratorName]: Object.fromEntries(decorator.map(item => [item, true]))
@@ -594,9 +592,9 @@ class TemplateUtil {
594
592
  preConditions,
595
593
  selfCondition
596
594
  } = condition;
597
- const result = ((preConditions === null || preConditions === void 0 ? void 0 : preConditions.map(item => this.translateTemplateValue(TemplateUtil.toDynamicValue(item.value), identifiers, item).result).map(item => {
595
+ const result = (preConditions?.map(item => this.translateTemplateValue(TemplateUtil.toDynamicValue(item.value), identifiers, item).result).map(item => {
598
596
  return `!(${item})`;
599
- })) || []).concat(selfCondition ? [this.translateTemplateValue(TemplateUtil.toDynamicValue(selfCondition.value), identifiers, selfCondition).result] : []).map(item => `(${item})`).join(' && ');
597
+ }) || []).concat(selfCondition ? [this.translateTemplateValue(TemplateUtil.toDynamicValue(selfCondition.value), identifiers, selfCondition).result] : []).map(item => `(${item})`).join(' && ');
600
598
  return result;
601
599
  }
602
600
 
@@ -666,10 +664,9 @@ class TemplateUtil {
666
664
  const itemElse = TemplateUtil.getAttribute(element, 'else');
667
665
  // 2
668
666
  if (!itemIf && !itemElIf) {
669
- var _element$sourceCodeLo;
670
667
  onLog({
671
668
  filePath,
672
- position: TemplateUtil.parse5LocationToPosition((_element$sourceCodeLo = element.sourceCodeLocation) === null || _element$sourceCodeLo === void 0 ? void 0 : _element$sourceCodeLo.startTag),
669
+ position: TemplateUtil.parse5LocationToPosition(element.sourceCodeLocation?.startTag),
673
670
  level: _sharedUtils.Loglevel.THROW,
674
671
  message: [{
675
672
  word: element.nodeName
@@ -679,11 +676,10 @@ class TemplateUtil {
679
676
 
680
677
  // 3
681
678
  if (i === 0 && !itemIf) {
682
- var _element$sourceCodeLo2;
683
679
  onLog({
684
680
  level: _sharedUtils.Loglevel.THROW,
685
681
  filePath,
686
- position: TemplateUtil.parse5LocationToPosition((_element$sourceCodeLo2 = element.sourceCodeLocation) === null || _element$sourceCodeLo2 === void 0 ? void 0 : _element$sourceCodeLo2.startTag),
682
+ position: TemplateUtil.parse5LocationToPosition(element.sourceCodeLocation?.startTag),
687
683
  message: [`the first element requires`, {
688
684
  word: 'if'
689
685
  }, `attribute`]
@@ -808,7 +804,7 @@ class TemplateUtil {
808
804
  const parsedValues = new _TemplateValueParser.default().parse(value);
809
805
  const firstParsedValue = parsedValues[0];
810
806
  // 2.1
811
- if ((firstParsedValue === null || firstParsedValue === void 0 ? void 0 : firstParsedValue.type) === _TemplateValueParser.TemplateValueType.CHAR) {
807
+ if (firstParsedValue?.type === _TemplateValueParser.TemplateValueType.CHAR) {
812
808
  const srcPath = _path.default.join(projectPath, sourceRoot);
813
809
  const resourcePath = _path.default.join(_path.default.dirname(filePath), firstParsedValue.value);
814
810
  if (!resourcePath.startsWith(srcPath)) {
@@ -33,20 +33,18 @@ class CfTranslate {
33
33
  const attribute = _TemplateUtil.default.getAttribute(node, this.KEY);
34
34
  const tid = _TemplateUtil.default.getAttribute(node, 'tid');
35
35
  if (attribute) {
36
- var _node$sourceCodeLocat;
37
36
  const {
38
37
  itemNode,
39
38
  indexNode,
40
39
  listNode
41
40
  } = CfTranslate.extractForNodes({
42
41
  ...attribute,
43
- nameLocation: _TemplateUtil.default.parse5LocationToPosition((_node$sourceCodeLocat = node.sourceCodeLocation) === null || _node$sourceCodeLocat === void 0 || (_node$sourceCodeLocat = _node$sourceCodeLocat.attrs) === null || _node$sourceCodeLocat === void 0 ? void 0 : _node$sourceCodeLocat[this.KEY])
42
+ nameLocation: _TemplateUtil.default.parse5LocationToPosition(node.sourceCodeLocation?.attrs?.[this.KEY])
44
43
  }, this.options);
45
44
  if (!listNode) {
46
- var _node$sourceCodeLocat2;
47
45
  onLog({
48
46
  filePath,
49
- position: _TemplateUtil.default.parse5LocationToPosition((_node$sourceCodeLocat2 = node.sourceCodeLocation) === null || _node$sourceCodeLocat2 === void 0 || (_node$sourceCodeLocat2 = _node$sourceCodeLocat2.attrs) === null || _node$sourceCodeLocat2 === void 0 ? void 0 : _node$sourceCodeLocat2[this.KEY]),
47
+ position: _TemplateUtil.default.parse5LocationToPosition(node.sourceCodeLocation?.attrs?.[this.KEY]),
50
48
  level: _sharedUtils.Loglevel.THROW,
51
49
  message: [{
52
50
  word: 'list'
@@ -59,7 +57,7 @@ class CfTranslate {
59
57
  const listName = listNode.getText();
60
58
  const modifiers = this.getModifiers(node);
61
59
  const opts = {
62
- exp: await this.genExp(listName, [...identifiers, itemName, indexName], tid === null || tid === void 0 ? void 0 : tid.value, attribute),
60
+ exp: await this.genExp(listName, [...identifiers, itemName, indexName], tid?.value, attribute),
63
61
  modifiers
64
62
  };
65
63
  if (indexNode) {
@@ -87,8 +85,8 @@ class CfTranslate {
87
85
  filePath
88
86
  } = this.options;
89
87
  const listCode = await this.templateUtil.translateAttributeValue({
90
- name: (attribute === null || attribute === void 0 ? void 0 : attribute.name) || '',
91
- nameLocation: attribute === null || attribute === void 0 ? void 0 : attribute.nameLocation,
88
+ name: attribute?.name || '',
89
+ nameLocation: attribute?.nameLocation,
92
90
  value: _TemplateUtil.default.toDynamicValue(listName)
93
91
  }, identifiers, Boolean(tid));
94
92
  if (!tid) {
@@ -101,15 +99,15 @@ class CfTranslate {
101
99
  message: [{
102
100
  word: tid
103
101
  }, `tid expecting a static string,actually a dynamic value`],
104
- position: attribute === null || attribute === void 0 ? void 0 : attribute.nameLocation
102
+ position: attribute?.nameLocation
105
103
  });
106
104
  }
107
105
  return `function() {
108
106
  return {
109
107
  __list__: ${listCode},
110
108
  __tid__: ${await this.templateUtil.translateAttributeValue({
111
- name: (attribute === null || attribute === void 0 ? void 0 : attribute.name) || '',
112
- nameLocation: attribute === null || attribute === void 0 ? void 0 : attribute.nameLocation,
109
+ name: attribute?.name || '',
110
+ nameLocation: attribute?.nameLocation,
113
111
  value: tid
114
112
  }, identifiers)}
115
113
  }
@@ -42,10 +42,9 @@ class CiTranslate {
42
42
  const name = '__ci__';
43
43
  const condition = this.templateUtil.getIfCoditionList(node);
44
44
  if (!condition) {
45
- var _node$sourceCodeLocat;
46
45
  onLog({
47
46
  filePath,
48
- position: _TemplateUtil.default.parse5LocationToPosition((_node$sourceCodeLocat = node.sourceCodeLocation) === null || _node$sourceCodeLocat === void 0 ? void 0 : _node$sourceCodeLocat.startTag),
47
+ position: _TemplateUtil.default.parse5LocationToPosition(node.sourceCodeLocation?.startTag),
49
48
  level: _sharedUtils.Loglevel.THROW,
50
49
  message: [{
51
50
  word: 'if'
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var parser = _interopRequireWildcard(require("@babel/parser"));
9
8
  var t = _interopRequireWildcard(require("@babel/types"));
10
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -46,7 +46,7 @@ class ElementConfigUtil {
46
46
  docHelp
47
47
  } = options;
48
48
  // 1
49
- if (!(importList !== null && importList !== void 0 && importList.includes(tagName))) {
49
+ if (!importList?.includes(tagName)) {
50
50
  const config = this.getElementConfig(tagName);
51
51
  if (!config) {
52
52
  onLog({
@@ -69,8 +69,7 @@ class ElementConfigUtil {
69
69
  // 3
70
70
  if (config && config.attributes) {
71
71
  const requireList = Object.keys(config.attributes).filter(attributeName => {
72
- var _config$attributes$at;
73
- return config.attributes && ((_config$attributes$at = config.attributes[attributeName]) === null || _config$attributes$at === void 0 ? void 0 : _config$attributes$at.required);
72
+ return config.attributes && config.attributes[attributeName]?.required;
74
73
  });
75
74
  const missingAttribute = requireList.filter(attributeName => attributes.findIndex(item => item.name === attributeName) < 0);
76
75
  if (missingAttribute.length) {
@@ -82,7 +81,7 @@ class ElementConfigUtil {
82
81
  word: `[${tagName}]`
83
82
  }, `missing attributes`, {
84
83
  word: missingAttribute.join('、')
85
- }, docHelp === null || docHelp === void 0 ? void 0 : docHelp.createWidgetReferenceMessage({
84
+ }, docHelp?.createWidgetReferenceMessage({
86
85
  componentName: tagName,
87
86
  chapter: _QuickAppDocHelp.QuickAppDocWidgetType.ATTRIBUTE
88
87
  })]
@@ -127,7 +126,7 @@ class ElementConfigUtil {
127
126
  const isEvent = _TemplateUtil.default.isEventAttribute(name);
128
127
  if (isEvent) {
129
128
  const eventName = _TemplateUtil.default.translateEventName(name);
130
- const eventList = [...((elementConfig === null || elementConfig === void 0 ? void 0 : elementConfig.events) || []), ...this.config.commonEvents];
129
+ const eventList = [...(elementConfig?.events || []), ...this.config.commonEvents];
131
130
  if (!eventList.includes(eventName)) {
132
131
  onLog({
133
132
  filePath,
@@ -135,7 +134,7 @@ class ElementConfigUtil {
135
134
  level: _sharedUtils.Loglevel.WARN,
136
135
  message: [{
137
136
  word: `[${name}]`
138
- }, `unsupport event`, docHelp === null || docHelp === void 0 ? void 0 : docHelp.createWidgetReferenceMessage({
137
+ }, `unsupport event`, docHelp?.createWidgetReferenceMessage({
139
138
  componentName: tagName,
140
139
  chapter: _QuickAppDocHelp.QuickAppDocWidgetType.EVENT
141
140
  })]
@@ -174,7 +173,7 @@ class ElementConfigUtil {
174
173
  level: _sharedUtils.Loglevel.WARN,
175
174
  message: [`unsupport attribute`, {
176
175
  word: `[${tagName}.${name}]`
177
- }, docHelp === null || docHelp === void 0 ? void 0 : docHelp.createWidgetReferenceMessage({
176
+ }, docHelp?.createWidgetReferenceMessage({
178
177
  componentName: tagName
179
178
  })]
180
179
  });
@@ -197,7 +196,7 @@ class ElementConfigUtil {
197
196
  word: value
198
197
  }, `, but the valid value is`, {
199
198
  word: enums.join('/')
200
- }, docHelp === null || docHelp === void 0 ? void 0 : docHelp.createWidgetReferenceMessage({
199
+ }, docHelp?.createWidgetReferenceMessage({
201
200
  componentName: tagName,
202
201
  chapter: _QuickAppDocHelp.QuickAppDocWidgetType.ATTRIBUTE
203
202
  })]
@@ -28,8 +28,8 @@ class StyleMapUtil {
28
28
  * @param useAbsolutePath 是否生成绝对路径
29
29
  * @returns
30
30
  */
31
- transfromLocToPosition(location, useAbsolutePath = true) {
32
- var _nodeStartPosition$so, _nodeEndPosition$sour;
31
+ transfromLocToPosition(location) {
32
+ let useAbsolutePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
33
33
  const {
34
34
  projectPath
35
35
  } = this.options;
@@ -42,10 +42,10 @@ class StyleMapUtil {
42
42
  column: location.end.column
43
43
  });
44
44
  let nodePath = '';
45
- if ((_nodeStartPosition$so = nodeStartPosition.source) !== null && _nodeStartPosition$so !== void 0 && _nodeStartPosition$so.endsWith('.ux') && nodeStartPosition.line) {
45
+ if (nodeStartPosition.source?.endsWith('.ux') && nodeStartPosition.line) {
46
46
  nodeStartPosition.line = nodeStartPosition.line - 1 + this.lineOffset;
47
47
  }
48
- if ((_nodeEndPosition$sour = nodeEndPosition.source) !== null && _nodeEndPosition$sour !== void 0 && _nodeEndPosition$sour.endsWith('.ux') && nodeEndPosition.line) {
48
+ if (nodeEndPosition.source?.endsWith('.ux') && nodeEndPosition.line) {
49
49
  nodeEndPosition.line = nodeEndPosition.line - 1 + this.lineOffset;
50
50
  }
51
51
  // nodeStartPosition.source在scss转css时会添加file://前缀,在这里需要去掉,以免影响路径的计算
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.array.push.js");
8
7
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
8
  var _cssTree = require("css-tree");
10
9
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
@@ -129,11 +128,10 @@ class StyleUtil {
129
128
  if ('children' in nodeC) {
130
129
  const nodeCChildrens = Array.isArray(nodeC.children) ? nodeC.children : nodeC.children.toArray();
131
130
  nodeCChildrens.forEach(childNode => {
132
- var _childNode$value;
133
131
  // 处理 除法
134
132
  // example: {type: "MediaFeature", name: "min-width", value: {type: "Ratio", left: "30", right: "1"}}
135
133
  // generate结果:(min-width: 30/1)
136
- if (StyleUtil.isMediaFeature(childNode) && ((_childNode$value = childNode.value) === null || _childNode$value === void 0 ? void 0 : _childNode$value.type) === 'Ratio') {
134
+ if (StyleUtil.isMediaFeature(childNode) && childNode.value?.type === 'Ratio') {
137
135
  const value = eval((0, _cssTree.generate)(childNode.value));
138
136
  childNode.value = {
139
137
  type: 'Number',
@@ -255,8 +253,7 @@ class StyleUtil {
255
253
  const mediaLevel4OperatorList = ['>', '>=', '<', '<='];
256
254
  const mediaLevel4OperatorRegex = /[><]=?/;
257
255
  if (error.offset) {
258
- var _source;
259
- const errorWord = ((_source = error.source) === null || _source === void 0 ? void 0 : _source[error.offset]) || '';
256
+ const errorWord = error.source?.[error.offset] || '';
260
257
  // 排除media中写level4运算符的报错问题
261
258
  if (mediaLevel4OperatorList.includes(errorWord) || mediaLevel4OperatorRegex.test(fallbackNode.value)) {
262
259
  return false;
@@ -274,7 +271,6 @@ class StyleUtil {
274
271
  static collectParserError(error, fallbackNode) {
275
272
  // 检查错误解析是否为需要输出
276
273
  if (StyleUtil.checkParserError(error, fallbackNode)) {
277
- var _loc$start, _loc$start2, _loc$start3, _loc$start4, _loc$start5, _loc$end, _loc$start6, _loc$end2, _loc$start7, _loc$end3;
278
274
  let parserError;
279
275
  let {
280
276
  message,
@@ -288,12 +284,12 @@ class StyleUtil {
288
284
  word: name
289
285
  }],
290
286
  details: message,
291
- startLine: (loc === null || loc === void 0 || (_loc$start = loc.start) === null || _loc$start === void 0 ? void 0 : _loc$start.line) || (loc === null || loc === void 0 || (_loc$start2 = loc.start) === null || _loc$start2 === void 0 ? void 0 : _loc$start2.startLine) || 0,
292
- startCol: (loc === null || loc === void 0 || (_loc$start3 = loc.start) === null || _loc$start3 === void 0 ? void 0 : _loc$start3.column) || (loc === null || loc === void 0 || (_loc$start4 = loc.start) === null || _loc$start4 === void 0 ? void 0 : _loc$start4.startCol) || 0,
293
- startOffset: (loc === null || loc === void 0 || (_loc$start5 = loc.start) === null || _loc$start5 === void 0 ? void 0 : _loc$start5.offset) || 0,
294
- endLine: (loc === null || loc === void 0 || (_loc$end = loc.end) === null || _loc$end === void 0 ? void 0 : _loc$end.line) || (loc === null || loc === void 0 || (_loc$start6 = loc.start) === null || _loc$start6 === void 0 ? void 0 : _loc$start6.startLine) || 0,
295
- endCol: (loc === null || loc === void 0 || (_loc$end2 = loc.end) === null || _loc$end2 === void 0 ? void 0 : _loc$end2.column) || (loc === null || loc === void 0 || (_loc$start7 = loc.start) === null || _loc$start7 === void 0 ? void 0 : _loc$start7.startCol) || 0,
296
- endOffset: (loc === null || loc === void 0 || (_loc$end3 = loc.end) === null || _loc$end3 === void 0 ? void 0 : _loc$end3.offset) || 0,
287
+ startLine: loc?.start?.line || loc?.start?.startLine || 0,
288
+ startCol: loc?.start?.column || loc?.start?.startCol || 0,
289
+ startOffset: loc?.start?.offset || 0,
290
+ endLine: loc?.end?.line || loc?.start?.startLine || 0,
291
+ endCol: loc?.end?.column || loc?.start?.startCol || 0,
292
+ endOffset: loc?.end?.offset || 0,
297
293
  source: 'value' in fallbackNode ? fallbackNode.value : ''
298
294
  };
299
295
  return parserError;
@@ -337,21 +333,19 @@ class StyleUtil {
337
333
  }];
338
334
  }
339
335
  if (loc) {
340
- var _loc$start8, _loc$start9, _loc$start10, _loc$start11, _loc$start12, _loc$end4;
341
336
  syntaxErrors.push({
342
337
  messages,
343
338
  details,
344
- startLine: (loc === null || loc === void 0 || (_loc$start8 = loc.start) === null || _loc$start8 === void 0 ? void 0 : _loc$start8.line) || 0,
345
- startCol: (loc === null || loc === void 0 || (_loc$start9 = loc.start) === null || _loc$start9 === void 0 ? void 0 : _loc$start9.column) || 1,
346
- startOffset: (loc === null || loc === void 0 || (_loc$start10 = loc.start) === null || _loc$start10 === void 0 ? void 0 : _loc$start10.offset) || 0,
347
- endLine: (loc === null || loc === void 0 || (_loc$start11 = loc.start) === null || _loc$start11 === void 0 ? void 0 : _loc$start11.line) || 0,
348
- endCol: (loc === null || loc === void 0 || (_loc$start12 = loc.start) === null || _loc$start12 === void 0 ? void 0 : _loc$start12.column) || 1,
349
- endOffset: (loc === null || loc === void 0 || (_loc$end4 = loc.end) === null || _loc$end4 === void 0 ? void 0 : _loc$end4.offset) || 0,
339
+ startLine: loc?.start?.line || 0,
340
+ startCol: loc?.start?.column || 1,
341
+ startOffset: loc?.start?.offset || 0,
342
+ endLine: loc?.start?.line || 0,
343
+ endCol: loc?.start?.column || 1,
344
+ endOffset: loc?.end?.offset || 0,
350
345
  source: css
351
346
  });
352
347
  } else {
353
- var _error$property;
354
- const propertyLength = (error === null || error === void 0 || (_error$property = error.property) === null || _error$property === void 0 ? void 0 : _error$property.length) || 0;
348
+ const propertyLength = error?.property?.length || 0;
355
349
  syntaxErrors.push({
356
350
  messages,
357
351
  details,
@@ -637,7 +631,7 @@ class StyleUtil {
637
631
  } = sourceNode;
638
632
  // 属性校验
639
633
  const config = _StyleBaseConfig.STYLE_ATTRIBUTE_CONFIG[name];
640
- if (config !== null && config !== void 0 && config.validate) {
634
+ if (config?.validate) {
641
635
  const {
642
636
  message: validMessages,
643
637
  level: validInfoLevel
@@ -646,7 +640,7 @@ class StyleUtil {
646
640
  StyleUtil.handleStyleError(validInfoLevel, validMessages, options, sourceNode.position);
647
641
  }
648
642
  }
649
- if (config !== null && config !== void 0 && config.translate) {
643
+ if (config?.translate) {
650
644
  targetList = {
651
645
  ...targetList,
652
646
  ...config.translate(sourceNode)
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- require("core-js/modules/es.error.cause.js");
8
- require("core-js/modules/es.array.push.js");
9
7
  var _path = _interopRequireDefault(require("path"));
10
8
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -32,7 +30,7 @@ class UxUtil {
32
30
  */
33
31
  static getLangType(node) {
34
32
  let langType = 'css';
35
- for (let attr of (node === null || node === void 0 ? void 0 : node.attrs) || []) {
33
+ for (let attr of node?.attrs || []) {
36
34
  if (attr.name === 'lang') {
37
35
  langType = attr.value;
38
36
  break;
@@ -62,7 +60,8 @@ class UxUtil {
62
60
  * @param langType
63
61
  * @returns
64
62
  */
65
- static convertGlobalJson(globalVar, langType = 'css') {
63
+ static convertGlobalJson(globalVar) {
64
+ let langType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'css';
66
65
  if (langType === 'css' && globalVar) {
67
66
  return '';
68
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/parser",
3
- "version": "2.0.6-beta.15",
3
+ "version": "2.0.6-beta.17",
4
4
  "description": "Parse the source code of aiot and convert it to the AST (Abstract Syntax Tree) of the target code.",
5
5
  "keywords": [
6
6
  "aiot",
@@ -20,7 +20,7 @@
20
20
  "test": "node ./__tests__/parser.test.js"
21
21
  },
22
22
  "dependencies": {
23
- "@aiot-toolkit/shared-utils": "2.0.6-beta.15",
23
+ "@aiot-toolkit/shared-utils": "2.0.6-beta.17",
24
24
  "@babel/core": "^7.23.6",
25
25
  "@babel/generator": "^7.24.10",
26
26
  "@babel/parser": "^7.24.8",
@@ -31,7 +31,7 @@
31
31
  "css-tree": "npm:aiot-css-tree@^2.3.1",
32
32
  "csstree-validator": "^3.0.0",
33
33
  "eslint": "^8.46.0",
34
- "file-lane": "2.0.6-beta.15",
34
+ "file-lane": "2.0.6-beta.17",
35
35
  "fs-extra": "^11.2.0",
36
36
  "google-protobuf": "^3.21.2",
37
37
  "less": "^4.2.0",
@@ -60,5 +60,5 @@
60
60
  "@types/tinycolor2": "^1.4.6",
61
61
  "babel-plugin-tester": "^11.0.4"
62
62
  },
63
- "gitHead": "8a927aec513af6d004f88e21d85bba0ef2dcac90"
63
+ "gitHead": "d9d60157e951ebbc58f6a6f6fac63efd9d9d4fd5"
64
64
  }