@aiot-toolkit/parser 2.0.5-beta.2 → 2.0.5-beta.4

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.
@@ -67,7 +67,7 @@ class UxToTypescript {
67
67
  } = sourceTree;
68
68
  const importTarget = await this.importToTypescript(importList);
69
69
  const templateTarget = await new _TemplateToTypescript.default(this.options, this.compilerOption, importList).translate(template, offsetList);
70
- const scriptTarget = new _ScriptToTypescript.default(this.options, this.compilerOption, this.contxt).translate(script, []);
70
+ const scriptTarget = await new _ScriptToTypescript.default(this.options, this.compilerOption, this.contxt).translate(script, []);
71
71
  // 切割script中的转换结果和source map
72
72
  const spliteResult = _SourceMapUtil.default.splitSourceMap(scriptTarget.targetTree);
73
73
  const styleTarget = new _StyleToTypescript.default(this.options, this.compilerOption).translate(style, []);
@@ -1,4 +1,3 @@
1
- import { MapData } from '@aiot-toolkit/shared-utils';
2
1
  import { SourceFile } from 'ts-morph';
3
2
  import IOffset from '../../../interface/IOffset';
4
3
  import ITranslate from '../../../interface/ITranslate';
@@ -15,10 +14,10 @@ declare class ScriptToTypescript implements ITranslate<IScriptAst, SourceFile> {
15
14
  readonly context: IFileLaneContext;
16
15
  private _systemFeatures;
17
16
  constructor(options: IOptions, compilerOption: ITranslateOption, context: IFileLaneContext);
18
- translate(sourceTree: IScriptAst, offsetList: IOffset[]): {
17
+ translate(sourceTree: IScriptAst, offsetList: IOffset[]): Promise<{
19
18
  targetTree: SourceFile;
20
- mapList: MapData[];
21
- };
19
+ mapList: never[];
20
+ }>;
22
21
  /**
23
22
  * babel自定义插件实现替换
24
23
  * @param sourceCode
@@ -29,5 +28,9 @@ declare class ScriptToTypescript implements ITranslate<IScriptAst, SourceFile> {
29
28
  * 缓存并检查 feature
30
29
  */
31
30
  private cacheAndCheckFeature;
31
+ /**
32
+ * 检查代码
33
+ */
34
+ private checkCode;
32
35
  }
33
36
  export default ScriptToTypescript;
@@ -9,6 +9,7 @@ var babel = _interopRequireWildcard(require("@babel/core"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _ParserUtil = _interopRequireDefault(require("../../../utils/ParserUtil"));
11
11
  var _FeatureConfig = _interopRequireDefault(require("../../config/FeatureConfig"));
12
+ var _eslint = require("eslint");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  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); }
14
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -24,9 +25,16 @@ class ScriptToTypescript {
24
25
  this.compilerOption = compilerOption;
25
26
  this.context = context;
26
27
  }
27
- translate(sourceTree,
28
+ async translate(sourceTree,
28
29
  // eslint-disable-next-line
29
30
  offsetList) {
31
+ // 检查代码错误
32
+ const logs = await this.checkCode(sourceTree);
33
+ if (logs) {
34
+ logs.forEach(log => {
35
+ this.options.onLog(log);
36
+ });
37
+ }
30
38
  // 使用babel实现替换,由此实现自动更新source map
31
39
  const content = this.babelScript(sourceTree);
32
40
  const fileName = this.options.filePath + '.js';
@@ -151,5 +159,52 @@ class ScriptToTypescript {
151
159
  });
152
160
  }
153
161
  }
162
+
163
+ /**
164
+ * 检查代码
165
+ */
166
+ async checkCode(sourceTree) {
167
+ const code = sourceTree.content;
168
+ if (!code) {
169
+ return;
170
+ }
171
+ const lintResult = await new _eslint.ESLint({
172
+ useEslintrc: false,
173
+ baseConfig: {
174
+ env: {
175
+ browser: true,
176
+ node: true,
177
+ es2022: true
178
+ },
179
+ parserOptions: {
180
+ sourceType: 'module',
181
+ ecmaVersion: 'latest'
182
+ },
183
+ rules: {
184
+ '*': 'off',
185
+ // 检查未定义的变量
186
+ 'no-undef': 'error'
187
+ }
188
+ }
189
+ }).lintText(code);
190
+ if (lintResult?.length) {
191
+ const result = [];
192
+ const offsetLine = (sourceTree.sourceCodeLocation?.startLine || 0) - 1;
193
+ lintResult.forEach(item => {
194
+ item.messages.forEach(message => {
195
+ result.push({
196
+ filePath: this.options.filePath,
197
+ level: _sharedUtils.Loglevel.WARN,
198
+ message: message.message,
199
+ position: {
200
+ startLine: message.line + offsetLine,
201
+ startColumn: message.column
202
+ }
203
+ });
204
+ });
205
+ });
206
+ return result;
207
+ }
208
+ }
154
209
  }
155
210
  var _default = exports.default = ScriptToTypescript;
@@ -27,7 +27,7 @@ class UxToTypescript {
27
27
  const appImport = this.importToTypescript(sourceTree.import);
28
28
  const appStyle = new _StyleToTypescript.default(this.options, this.compilerOption).translate(sourceTree.style, []);
29
29
  const appTemplate = await new _TemplateToTypescript.default(this.options, this.compilerOption, sourceTree.import.map(item => item.name.toLowerCase())).translate(sourceTree.template, []);
30
- const appScript = new _ScriptToTypescript.default(this.options, this.compilerOption, this.context).translate(sourceTree.script, []);
30
+ const appScript = await new _ScriptToTypescript.default(this.options, this.compilerOption, this.context).translate(sourceTree.script, []);
31
31
  // 切割出源码和map信息
32
32
  const spliteResult = _SourceMapUtil.default.splitSourceMap(appScript.targetTree);
33
33
  const integratedList = this.integratedFunction.bind(this, appImport, appStyle.targetTree, appTemplate.targetTree, spliteResult.newScriptTree, this.options)();
@@ -63,18 +63,13 @@ const ATTRIBUTE_CONFIG = {
63
63
  if (nameLocation) {
64
64
  const {
65
65
  startLine,
66
- startColumn,
67
- pos
66
+ startColumn
68
67
  } = nameLocation;
69
68
  logs.forEach(log => {
70
69
  const position = log.position;
71
70
  if (position) {
72
71
  position.startLine += startLine - 1;
73
72
  position.startColumn += startColumn;
74
- position.pos += pos;
75
- position.endLine += startLine - 1;
76
- position.endColumn += startColumn;
77
- position.end += pos;
78
73
  }
79
74
  option.onLog(log);
80
75
  });
@@ -755,7 +755,7 @@ class StyleUtil {
755
755
  return value[0];
756
756
  } else {
757
757
  // 例如animation-name属性值
758
- return value.join(' ');
758
+ return value.map(item => item === ',' ? `${item} ` : item).join('').trim();
759
759
  }
760
760
  } else {
761
761
  // 例如transform属性值,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/parser",
3
- "version": "2.0.5-beta.2",
3
+ "version": "2.0.5-beta.4",
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,19 +20,20 @@
20
20
  "test": "node ./__tests__/parser.test.js"
21
21
  },
22
22
  "dependencies": {
23
- "@aiot-toolkit/generator": "2.0.5-beta.2",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.2",
23
+ "@aiot-toolkit/generator": "2.0.5-beta.4",
24
+ "@aiot-toolkit/shared-utils": "2.0.5-beta.4",
25
25
  "@babel/core": "^7.23.6",
26
26
  "@babel/generator": "^7.24.10",
27
27
  "@babel/parser": "^7.24.8",
28
28
  "@babel/preset-env": "^7.25.4",
29
29
  "@babel/traverse": "^7.23.7",
30
30
  "@babel/types": "^7.23.6",
31
- "aiot-parse5": "^1.0.0",
31
+ "aiot-parse5": "^1.0.2",
32
32
  "colord": "^2.9.3",
33
33
  "css-tree": "npm:aiot-css-tree@^2.3.1",
34
34
  "csstree-validator": "^3.0.0",
35
- "file-lane": "2.0.5-beta.2",
35
+ "eslint": "^8.46.0",
36
+ "file-lane": "2.0.5-beta.4",
36
37
  "fs-extra": "^11.2.0",
37
38
  "google-protobuf": "^3.21.2",
38
39
  "less": "^4.2.0",
@@ -51,6 +52,7 @@
51
52
  },
52
53
  "devDependencies": {
53
54
  "@types/css-tree": "^2.3.3",
55
+ "@types/eslint": "^8.56.12",
54
56
  "@types/fs-extra": "^11.0.4",
55
57
  "@types/less": "^3.0.5",
56
58
  "@types/postcss-import": "^14.0.3",
@@ -58,5 +60,5 @@
58
60
  "@types/reserved-words": "^0.1.4",
59
61
  "babel-plugin-tester": "^11.0.4"
60
62
  },
61
- "gitHead": "90f28324bb8bded7f04e1074dbf5ddc9a31f86f6"
63
+ "gitHead": "cfa77c8f2d3916b703ac23a93a9dcc0df1bc261a"
62
64
  }