king-design-analyzer 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ast/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  require('../chunk-YTEYDSDW.js');
4
- var chunkTKBNPZIO_js = require('../chunk-TKBNPZIO.js');
4
+ var chunkGW5YOUB7_js = require('../chunk-GW5YOUB7.js');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "analyzeCodeWithAST", {
9
9
  enumerable: true,
10
- get: function () { return chunkTKBNPZIO_js.analyzeCodeWithAST; }
10
+ get: function () { return chunkGW5YOUB7_js.analyzeCodeWithAST; }
11
11
  });
12
12
  Object.defineProperty(exports, "componentRegistry", {
13
13
  enumerable: true,
14
- get: function () { return chunkTKBNPZIO_js.componentRegistry; }
14
+ get: function () { return chunkGW5YOUB7_js.componentRegistry; }
15
15
  });
@@ -1,2 +1,2 @@
1
1
  import '../chunk-5H7N2A5X.mjs';
2
- export { analyzeCodeWithAST, componentRegistry } from '../chunk-27IE6LRY.mjs';
2
+ export { analyzeCodeWithAST, componentRegistry } from '../chunk-UYVGHUC5.mjs';
@@ -1,4 +1,5 @@
1
- import { analyzeCodeWithAST } from './chunk-27IE6LRY.mjs';
1
+ import { analyzeCodeWithAST } from './chunk-UYVGHUC5.mjs';
2
+ import { validateRuntimePrecheck } from './chunk-ZONZNAWA.mjs';
2
3
  import { compileSFC } from './chunk-WJAGRAWV.mjs';
3
4
 
4
5
  // src/tools/unifiedValidator.ts
@@ -82,67 +83,6 @@ async function validateAST(code) {
82
83
  };
83
84
  }
84
85
  }
85
- function validateRuntimePrecheck(code) {
86
- const scopeId = `runtime-${Date.now()}`;
87
- const { script, bindings, error } = compileSFC(code, scopeId);
88
- if (error) {
89
- return {
90
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
91
- passed: false,
92
- errors: [error]
93
- };
94
- }
95
- try {
96
- const funcBody = `
97
- "use strict";
98
- ${script}
99
- return { ${bindings.join(", ")} };
100
- `;
101
- const mockContext = {
102
- ref: (v) => ({ value: v }),
103
- reactive: (v) => v,
104
- computed: (fn) => ({ value: fn() }),
105
- onMounted: () => {
106
- },
107
- onUnmounted: () => {
108
- },
109
- watch: () => {
110
- },
111
- shallowRef: (v) => ({ value: v }),
112
- nextTick: () => Promise.resolve(),
113
- toRef: () => ({}),
114
- toRefs: () => ({}),
115
- watchEffect: () => {
116
- },
117
- readonly: (v) => v,
118
- h: () => ({})
119
- };
120
- const keys = Object.keys(mockContext);
121
- const values = Object.values(mockContext);
122
- const runner = new Function(...keys, funcBody);
123
- const result = runner(...values);
124
- for (const binding of bindings) {
125
- if (!(binding in result)) {
126
- return {
127
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
128
- passed: false,
129
- errors: [`\u53D8\u91CF ${binding} \u672A\u6B63\u786E\u5BFC\u51FA`]
130
- };
131
- }
132
- }
133
- return {
134
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
135
- passed: true,
136
- errors: []
137
- };
138
- } catch (e) {
139
- return {
140
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
141
- passed: false,
142
- errors: [`JavaScript \u6267\u884C\u9519\u8BEF: ${e.message}`]
143
- };
144
- }
145
- }
146
86
  async function validateCode(code) {
147
87
  const compilationResult = validateCompilation(code);
148
88
  if (!compilationResult.passed) {
@@ -32,7 +32,7 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
32
32
  var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
33
33
 
34
34
  // src/analysis/componentRegistry.ts
35
- var __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-TKBNPZIO.js', document.baseURI).href)));
35
+ var __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-GW5YOUB7.js', document.baseURI).href)));
36
36
  var __dirname$1 = path__namespace.dirname(__filename$1);
37
37
  function resolveComponentsPath() {
38
38
  const prodPath = path__namespace.join(__dirname$1, "../components");
@@ -122,7 +122,7 @@ var ComponentRegistry = class {
122
122
  }
123
123
  };
124
124
  var componentRegistry = new ComponentRegistry();
125
- var __filename2 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-TKBNPZIO.js', document.baseURI).href)));
125
+ var __filename2 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-GW5YOUB7.js', document.baseURI).href)));
126
126
  var __dirname2 = path__namespace.dirname(__filename2);
127
127
  function resolveHooksPath() {
128
128
  const prodPath = path__namespace.join(__dirname2, "../hooks");
@@ -596,6 +596,10 @@ async function analyzeCodeWithAST(code) {
596
596
  const scriptBindings = extractScriptBindings(scriptContent);
597
597
  checkTemplateVariables(descriptor.template, scriptBindings, violations);
598
598
  }
599
+ if (scriptContent) {
600
+ const scriptBindings = extractScriptBindings(scriptContent);
601
+ checkScriptFunctionCalls(scriptContent, scriptBindings, violations);
602
+ }
599
603
  return violations;
600
604
  }
601
605
  function extractScriptBindings(scriptContent) {
@@ -645,6 +649,38 @@ function extractScriptBindings(scriptContent) {
645
649
  }
646
650
  return bindings;
647
651
  }
652
+ function checkScriptFunctionCalls(scriptContent, bindings, violations) {
653
+ try {
654
+ let visit2 = function(node) {
655
+ if (ts__namespace.isCallExpression(node)) {
656
+ const callee = node.expression;
657
+ if (ts__namespace.isIdentifier(callee)) {
658
+ const funcName = callee.text;
659
+ const isHookCall = funcName.startsWith("use") && funcName.length > 3 && funcName[3] === funcName[3].toUpperCase();
660
+ if (isHookCall) {
661
+ if (!bindings.has(funcName)) {
662
+ violations.push({
663
+ rule: "\u4F7F\u7528\u4E86\u672A\u5BFC\u5165\u7684 Hook",
664
+ match: `${funcName}()`,
665
+ suggestion: `\u8BF7\u5148\u5BFC\u5165 ${funcName}: import { ${funcName} } from '@ksyun-internal/versatile'`
666
+ });
667
+ }
668
+ }
669
+ }
670
+ }
671
+ ts__namespace.forEachChild(node, visit2);
672
+ };
673
+ var visit = visit2;
674
+ const sourceFile = ts__namespace.createSourceFile(
675
+ "temp.ts",
676
+ scriptContent,
677
+ ts__namespace.ScriptTarget.Latest,
678
+ true
679
+ );
680
+ ts__namespace.forEachChild(sourceFile, visit2);
681
+ } catch (err) {
682
+ }
683
+ }
648
684
  function checkTemplateVariables(template, bindings, violations) {
649
685
  const templateContent = template.content;
650
686
  const templateAst = template.ast;
@@ -790,6 +826,11 @@ function checkImport(node, violations, sourceFile) {
790
826
  return;
791
827
  }
792
828
  if (!hooksRegistry.isKnownHook(originalName)) {
829
+ violations.push({
830
+ rule: "\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 Hook",
831
+ match: originalName,
832
+ suggestion: `Hook ${originalName} \u4E0D\u5B58\u5728\u4E8E @ksyun-internal/versatile\u3002\u53EF\u7528\u7684 Hooks: ${hooksRegistry.getAllHookNames().join(", ") || "\u6682\u65E0"}`
833
+ });
793
834
  return;
794
835
  }
795
836
  if (isAlias) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkTKBNPZIO_js = require('./chunk-TKBNPZIO.js');
3
+ var chunkGW5YOUB7_js = require('./chunk-GW5YOUB7.js');
4
+ var chunkY77A3DEY_js = require('./chunk-Y77A3DEY.js');
4
5
  var chunk2L37YJOJ_js = require('./chunk-2L37YJOJ.js');
5
6
 
6
7
  // src/tools/unifiedValidator.ts
@@ -63,7 +64,7 @@ function validateCompilation(code) {
63
64
  }
64
65
  async function validateAST(code) {
65
66
  try {
66
- const violations = await chunkTKBNPZIO_js.analyzeCodeWithAST(code);
67
+ const violations = await chunkGW5YOUB7_js.analyzeCodeWithAST(code);
67
68
  if (violations.length > 0) {
68
69
  return {
69
70
  name: "AST\u89C4\u5219\u68C0\u67E5",
@@ -84,67 +85,6 @@ async function validateAST(code) {
84
85
  };
85
86
  }
86
87
  }
87
- function validateRuntimePrecheck(code) {
88
- const scopeId = `runtime-${Date.now()}`;
89
- const { script, bindings, error } = chunk2L37YJOJ_js.compileSFC(code, scopeId);
90
- if (error) {
91
- return {
92
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
93
- passed: false,
94
- errors: [error]
95
- };
96
- }
97
- try {
98
- const funcBody = `
99
- "use strict";
100
- ${script}
101
- return { ${bindings.join(", ")} };
102
- `;
103
- const mockContext = {
104
- ref: (v) => ({ value: v }),
105
- reactive: (v) => v,
106
- computed: (fn) => ({ value: fn() }),
107
- onMounted: () => {
108
- },
109
- onUnmounted: () => {
110
- },
111
- watch: () => {
112
- },
113
- shallowRef: (v) => ({ value: v }),
114
- nextTick: () => Promise.resolve(),
115
- toRef: () => ({}),
116
- toRefs: () => ({}),
117
- watchEffect: () => {
118
- },
119
- readonly: (v) => v,
120
- h: () => ({})
121
- };
122
- const keys = Object.keys(mockContext);
123
- const values = Object.values(mockContext);
124
- const runner = new Function(...keys, funcBody);
125
- const result = runner(...values);
126
- for (const binding of bindings) {
127
- if (!(binding in result)) {
128
- return {
129
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
130
- passed: false,
131
- errors: [`\u53D8\u91CF ${binding} \u672A\u6B63\u786E\u5BFC\u51FA`]
132
- };
133
- }
134
- }
135
- return {
136
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
137
- passed: true,
138
- errors: []
139
- };
140
- } catch (e) {
141
- return {
142
- name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
143
- passed: false,
144
- errors: [`JavaScript \u6267\u884C\u9519\u8BEF: ${e.message}`]
145
- };
146
- }
147
- }
148
88
  async function validateCode(code) {
149
89
  const compilationResult = validateCompilation(code);
150
90
  if (!compilationResult.passed) {
@@ -170,7 +110,7 @@ async function validateCode(code) {
170
110
  summary: `\u274C AST\u89C4\u5219\u8FDD\u89C4 (${astResult.errors.length}\u9879)`
171
111
  };
172
112
  }
173
- const runtimeResult = validateRuntimePrecheck(code);
113
+ const runtimeResult = chunkY77A3DEY_js.validateRuntimePrecheck(code);
174
114
  if (!runtimeResult.passed) {
175
115
  return {
176
116
  passed: false,
@@ -204,7 +144,7 @@ function validateCodeSync(code) {
204
144
  summary: `\u274C \u7F16\u8BD1\u5931\u8D25: ${compilationResult.errors[0]}`
205
145
  };
206
146
  }
207
- const runtimeResult = validateRuntimePrecheck(code);
147
+ const runtimeResult = chunkY77A3DEY_js.validateRuntimePrecheck(code);
208
148
  return {
209
149
  passed: runtimeResult.passed,
210
150
  layers: {
@@ -570,6 +570,10 @@ async function analyzeCodeWithAST(code) {
570
570
  const scriptBindings = extractScriptBindings(scriptContent);
571
571
  checkTemplateVariables(descriptor.template, scriptBindings, violations);
572
572
  }
573
+ if (scriptContent) {
574
+ const scriptBindings = extractScriptBindings(scriptContent);
575
+ checkScriptFunctionCalls(scriptContent, scriptBindings, violations);
576
+ }
573
577
  return violations;
574
578
  }
575
579
  function extractScriptBindings(scriptContent) {
@@ -619,6 +623,38 @@ function extractScriptBindings(scriptContent) {
619
623
  }
620
624
  return bindings;
621
625
  }
626
+ function checkScriptFunctionCalls(scriptContent, bindings, violations) {
627
+ try {
628
+ let visit2 = function(node) {
629
+ if (ts.isCallExpression(node)) {
630
+ const callee = node.expression;
631
+ if (ts.isIdentifier(callee)) {
632
+ const funcName = callee.text;
633
+ const isHookCall = funcName.startsWith("use") && funcName.length > 3 && funcName[3] === funcName[3].toUpperCase();
634
+ if (isHookCall) {
635
+ if (!bindings.has(funcName)) {
636
+ violations.push({
637
+ rule: "\u4F7F\u7528\u4E86\u672A\u5BFC\u5165\u7684 Hook",
638
+ match: `${funcName}()`,
639
+ suggestion: `\u8BF7\u5148\u5BFC\u5165 ${funcName}: import { ${funcName} } from '@ksyun-internal/versatile'`
640
+ });
641
+ }
642
+ }
643
+ }
644
+ }
645
+ ts.forEachChild(node, visit2);
646
+ };
647
+ var visit = visit2;
648
+ const sourceFile = ts.createSourceFile(
649
+ "temp.ts",
650
+ scriptContent,
651
+ ts.ScriptTarget.Latest,
652
+ true
653
+ );
654
+ ts.forEachChild(sourceFile, visit2);
655
+ } catch (err) {
656
+ }
657
+ }
622
658
  function checkTemplateVariables(template, bindings, violations) {
623
659
  const templateContent = template.content;
624
660
  const templateAst = template.ast;
@@ -764,6 +800,11 @@ function checkImport(node, violations, sourceFile) {
764
800
  return;
765
801
  }
766
802
  if (!hooksRegistry.isKnownHook(originalName)) {
803
+ violations.push({
804
+ rule: "\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 Hook",
805
+ match: originalName,
806
+ suggestion: `Hook ${originalName} \u4E0D\u5B58\u5728\u4E8E @ksyun-internal/versatile\u3002\u53EF\u7528\u7684 Hooks: ${hooksRegistry.getAllHookNames().join(", ") || "\u6682\u65E0"}`
807
+ });
767
808
  return;
768
809
  }
769
810
  if (isAlias) {
@@ -77,7 +77,12 @@ var MOCK_VUE_CONTEXT = {
77
77
  getCurrentInstance: () => null,
78
78
  h: () => ({}),
79
79
  createVNode: () => ({}),
80
- resolveComponent: () => ({})
80
+ resolveComponent: () => ({}),
81
+ // =========================================================================
82
+ // @ksyun-internal/versatile Hooks
83
+ // =========================================================================
84
+ useToState: (_props, _key, _emit, defaultValue) => ({ value: defaultValue ?? void 0 }),
85
+ useIdEntity: () => ({ value: void 0 })
81
86
  };
82
87
  function validateRuntimePrecheck(code) {
83
88
  const scopeId = `runtime-${Date.now()}-${++scopeIdCounter}`;
@@ -75,7 +75,12 @@ var MOCK_VUE_CONTEXT = {
75
75
  getCurrentInstance: () => null,
76
76
  h: () => ({}),
77
77
  createVNode: () => ({}),
78
- resolveComponent: () => ({})
78
+ resolveComponent: () => ({}),
79
+ // =========================================================================
80
+ // @ksyun-internal/versatile Hooks
81
+ // =========================================================================
82
+ useToState: (_props, _key, _emit, defaultValue) => ({ value: defaultValue ?? void 0 }),
83
+ useIdEntity: () => ({ value: void 0 })
79
84
  };
80
85
  function validateRuntimePrecheck(code) {
81
86
  const scopeId = `runtime-${Date.now()}-${++scopeIdCounter}`;
@@ -1,16 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunkD2Y4IXVE_js = require('../chunk-D2Y4IXVE.js');
4
- require('../chunk-TKBNPZIO.js');
3
+ var chunkRHPVVTOE_js = require('../chunk-RHPVVTOE.js');
4
+ require('../chunk-GW5YOUB7.js');
5
+ require('../chunk-Y77A3DEY.js');
5
6
  require('../chunk-2L37YJOJ.js');
6
7
 
7
8
 
8
9
 
9
10
  Object.defineProperty(exports, "validateCode", {
10
11
  enumerable: true,
11
- get: function () { return chunkD2Y4IXVE_js.validateCode; }
12
+ get: function () { return chunkRHPVVTOE_js.validateCode; }
12
13
  });
13
14
  Object.defineProperty(exports, "validateCodeSync", {
14
15
  enumerable: true,
15
- get: function () { return chunkD2Y4IXVE_js.validateCodeSync; }
16
+ get: function () { return chunkRHPVVTOE_js.validateCodeSync; }
16
17
  });
@@ -1,3 +1,4 @@
1
- export { validateCode, validateCodeSync } from '../chunk-DXTRLMSI.mjs';
2
- import '../chunk-27IE6LRY.mjs';
1
+ export { validateCode, validateCodeSync } from '../chunk-4G533OEX.mjs';
2
+ import '../chunk-UYVGHUC5.mjs';
3
+ import '../chunk-ZONZNAWA.mjs';
3
4
  import '../chunk-WJAGRAWV.mjs';
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  var chunkREPE4KTQ_js = require('./chunk-REPE4KTQ.js');
4
4
  require('./chunk-YTEYDSDW.js');
5
- var chunkBJXTWCDK_js = require('./chunk-BJXTWCDK.js');
6
- var chunkD2Y4IXVE_js = require('./chunk-D2Y4IXVE.js');
7
- var chunkTKBNPZIO_js = require('./chunk-TKBNPZIO.js');
5
+ var chunkRHPVVTOE_js = require('./chunk-RHPVVTOE.js');
6
+ var chunkGW5YOUB7_js = require('./chunk-GW5YOUB7.js');
7
+ var chunkY77A3DEY_js = require('./chunk-Y77A3DEY.js');
8
8
  var chunk2L37YJOJ_js = require('./chunk-2L37YJOJ.js');
9
9
 
10
10
 
@@ -13,25 +13,25 @@ Object.defineProperty(exports, "validateCompilation", {
13
13
  enumerable: true,
14
14
  get: function () { return chunkREPE4KTQ_js.validateCompilation; }
15
15
  });
16
- Object.defineProperty(exports, "validateRuntimePrecheck", {
17
- enumerable: true,
18
- get: function () { return chunkBJXTWCDK_js.validateRuntimePrecheck; }
19
- });
20
16
  Object.defineProperty(exports, "validateCode", {
21
17
  enumerable: true,
22
- get: function () { return chunkD2Y4IXVE_js.validateCode; }
18
+ get: function () { return chunkRHPVVTOE_js.validateCode; }
23
19
  });
24
20
  Object.defineProperty(exports, "validateCodeSync", {
25
21
  enumerable: true,
26
- get: function () { return chunkD2Y4IXVE_js.validateCodeSync; }
22
+ get: function () { return chunkRHPVVTOE_js.validateCodeSync; }
27
23
  });
28
24
  Object.defineProperty(exports, "analyzeCodeWithAST", {
29
25
  enumerable: true,
30
- get: function () { return chunkTKBNPZIO_js.analyzeCodeWithAST; }
26
+ get: function () { return chunkGW5YOUB7_js.analyzeCodeWithAST; }
31
27
  });
32
28
  Object.defineProperty(exports, "componentRegistry", {
33
29
  enumerable: true,
34
- get: function () { return chunkTKBNPZIO_js.componentRegistry; }
30
+ get: function () { return chunkGW5YOUB7_js.componentRegistry; }
31
+ });
32
+ Object.defineProperty(exports, "validateRuntimePrecheck", {
33
+ enumerable: true,
34
+ get: function () { return chunkY77A3DEY_js.validateRuntimePrecheck; }
35
35
  });
36
36
  Object.defineProperty(exports, "compileSFC", {
37
37
  enumerable: true,
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { validateCompilation } from './chunk-YYKRQHUZ.mjs';
2
2
  import './chunk-5H7N2A5X.mjs';
3
- export { validateRuntimePrecheck } from './chunk-X7PYJSHF.mjs';
4
- export { validateCode, validateCodeSync } from './chunk-DXTRLMSI.mjs';
5
- export { analyzeCodeWithAST, componentRegistry } from './chunk-27IE6LRY.mjs';
3
+ export { validateCode, validateCodeSync } from './chunk-4G533OEX.mjs';
4
+ export { analyzeCodeWithAST, componentRegistry } from './chunk-UYVGHUC5.mjs';
5
+ export { validateRuntimePrecheck } from './chunk-ZONZNAWA.mjs';
6
6
  export { compileSFC, scopeStyles } from './chunk-WJAGRAWV.mjs';
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkBJXTWCDK_js = require('../chunk-BJXTWCDK.js');
3
+ var chunkY77A3DEY_js = require('../chunk-Y77A3DEY.js');
4
4
  var chunk2L37YJOJ_js = require('../chunk-2L37YJOJ.js');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "validateRuntimePrecheck", {
9
9
  enumerable: true,
10
- get: function () { return chunkBJXTWCDK_js.validateRuntimePrecheck; }
10
+ get: function () { return chunkY77A3DEY_js.validateRuntimePrecheck; }
11
11
  });
12
12
  Object.defineProperty(exports, "compileSFC", {
13
13
  enumerable: true,
@@ -1,2 +1,2 @@
1
- export { validateRuntimePrecheck } from '../chunk-X7PYJSHF.mjs';
1
+ export { validateRuntimePrecheck } from '../chunk-ZONZNAWA.mjs';
2
2
  export { compileSFC } from '../chunk-WJAGRAWV.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "king-design-analyzer",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "AST-based code analyzer for King Design Vue components with on-demand modular imports",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",