king-design-analyzer 2.1.4 → 2.1.6

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.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkGW5YOUB7_js = require('./chunk-GW5YOUB7.js');
4
- var chunk32HIMGM4_js = require('./chunk-32HIMGM4.js');
5
- var chunk2FV6BC3K_js = require('./chunk-2FV6BC3K.js');
4
+ var chunkD3Y6FGWA_js = require('./chunk-D3Y6FGWA.js');
5
+ var chunkHPAUCD5I_js = require('./chunk-HPAUCD5I.js');
6
6
 
7
7
  // src/tools/unifiedValidator.ts
8
8
  function validateCompilation(code) {
@@ -41,7 +41,7 @@ function validateCompilation(code) {
41
41
  errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 <template> \u6216 <script> \u6807\u7B7E"]
42
42
  };
43
43
  }
44
- const result = chunk2FV6BC3K_js.compileSFC(code, scopeId);
44
+ const result = chunkHPAUCD5I_js.compileSFC(code, scopeId);
45
45
  if (result.error) {
46
46
  return {
47
47
  name: "\u7F16\u8BD1\u68C0\u67E5",
@@ -110,7 +110,7 @@ async function validateCode(code) {
110
110
  summary: `\u274C AST\u89C4\u5219\u8FDD\u89C4 (${astResult.errors.length}\u9879)`
111
111
  };
112
112
  }
113
- const runtimeResult = chunk32HIMGM4_js.validateRuntimePrecheck(code);
113
+ const runtimeResult = chunkD3Y6FGWA_js.validateRuntimePrecheck(code);
114
114
  if (!runtimeResult.passed) {
115
115
  return {
116
116
  passed: false,
@@ -144,7 +144,7 @@ function validateCodeSync(code) {
144
144
  summary: `\u274C \u7F16\u8BD1\u5931\u8D25: ${compilationResult.errors[0]}`
145
145
  };
146
146
  }
147
- const runtimeResult = chunk32HIMGM4_js.validateRuntimePrecheck(code);
147
+ const runtimeResult = chunkD3Y6FGWA_js.validateRuntimePrecheck(code);
148
148
  return {
149
149
  passed: runtimeResult.passed,
150
150
  layers: {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk2FV6BC3K_js = require('./chunk-2FV6BC3K.js');
3
+ var chunkHPAUCD5I_js = require('./chunk-HPAUCD5I.js');
4
4
 
5
5
  // src/runtime/index.ts
6
6
  var scopeIdCounter = 0;
@@ -82,11 +82,30 @@ var MOCK_VUE_CONTEXT = {
82
82
  // @ksyun-internal/versatile Hooks
83
83
  // =========================================================================
84
84
  useToState: (_props, _key, _emit, defaultValue) => ({ value: defaultValue ?? void 0 }),
85
- useIdEntity: () => ({ value: void 0 })
85
+ useIdEntity: () => ({ value: void 0 }),
86
+ // =========================================================================
87
+ // Module Mocking
88
+ // =========================================================================
89
+ __mockModule: (modulePath) => {
90
+ const createMockProxy = (path) => {
91
+ return new Proxy(() => {
92
+ }, {
93
+ get: (target, prop) => {
94
+ if (prop === Symbol.toPrimitive) return () => 0;
95
+ if (prop === "then") return void 0;
96
+ return createMockProxy();
97
+ },
98
+ apply: (target, thisArg, args) => {
99
+ return createMockProxy();
100
+ }
101
+ });
102
+ };
103
+ return createMockProxy();
104
+ }
86
105
  };
87
106
  function validateRuntimePrecheck(code) {
88
107
  const scopeId = `runtime-${Date.now()}-${++scopeIdCounter}`;
89
- const { script, bindings, strippedImports, error } = chunk2FV6BC3K_js.compileSFC(code, scopeId);
108
+ const { script, bindings, strippedImports, error } = chunkHPAUCD5I_js.compileSFC(code, scopeId);
90
109
  if (error) {
91
110
  return {
92
111
  name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
@@ -1,4 +1,4 @@
1
- import { compileSFC } from './chunk-JAICJP7Q.mjs';
1
+ import { compileSFC } from './chunk-L4DS3EXI.mjs';
2
2
 
3
3
  // src/static/index.ts
4
4
  var scopeIdCounter = 0;
@@ -41,6 +41,27 @@ function scopeStyles(css, scopeClass) {
41
41
  return `${scopedSelector}${suffix}`;
42
42
  });
43
43
  }
44
+ function transformLocalImportToMock(importClause, source) {
45
+ const namespaceMatch = importClause.match(/^\*\s+as\s+(\w+)$/);
46
+ if (namespaceMatch) {
47
+ return `const ${namespaceMatch[1]} = __mockModule('${source}');`;
48
+ }
49
+ const namedMatch = importClause.match(/^\{([^}]+)\}$/);
50
+ if (namedMatch) {
51
+ return `const { ${namedMatch[1]} } = __mockModule('${source}');`;
52
+ }
53
+ const defaultMatch = importClause.match(/^(\w+)/);
54
+ if (defaultMatch) {
55
+ const defaultName = defaultMatch[1];
56
+ const mixedMatch = importClause.match(/^(\w+)\s*,\s*\{([^}]+)\}$/);
57
+ if (mixedMatch) {
58
+ const namedImports = mixedMatch[2];
59
+ return `const _mock_${defaultName} = __mockModule('${source}'); const ${defaultName} = _mock_${defaultName}.default || _mock_${defaultName}; const { ${namedImports} } = _mock_${defaultName};`;
60
+ }
61
+ return `const ${defaultName} = __mockModule('${source}').default || __mockModule('${source}');`;
62
+ }
63
+ return "";
64
+ }
44
65
  function compileSFC(code, scopeId, options) {
45
66
  const whitelist = options?.allowedImports ?? ALLOWED_IMPORT_SOURCES;
46
67
  const strippedImports = [];
@@ -58,8 +79,8 @@ function compileSFC(code, scopeId, options) {
58
79
  let cleanScript = script;
59
80
  cleanScript = cleanScript.replace(/import\s+type\s+[\s\S]*?from\s+['"].*?['"];?/g, "");
60
81
  cleanScript = cleanScript.replace(
61
- /import\s+[\s\S]*?from\s+['"]([^'"]+)['"];?/g,
62
- (match, source) => {
82
+ /import\s+([^;]+?)\s+from\s+['"]([^'"]+)['"];?/g,
83
+ (match, importClause, source) => {
63
84
  const isWhitelisted = whitelist.some(
64
85
  (w) => source === w || source.startsWith(w + "/")
65
86
  );
@@ -69,7 +90,7 @@ function compileSFC(code, scopeId, options) {
69
90
  }
70
91
  if (source.startsWith(".")) {
71
92
  strippedImports.push({ source, reason: "relative" });
72
- return "";
93
+ return transformLocalImportToMock(importClause.trim(), source);
73
94
  }
74
95
  strippedImports.push({ source, reason: "unknown" });
75
96
  return "";
@@ -19,6 +19,27 @@ function scopeStyles(css, scopeClass) {
19
19
  return `${scopedSelector}${suffix}`;
20
20
  });
21
21
  }
22
+ function transformLocalImportToMock(importClause, source) {
23
+ const namespaceMatch = importClause.match(/^\*\s+as\s+(\w+)$/);
24
+ if (namespaceMatch) {
25
+ return `const ${namespaceMatch[1]} = __mockModule('${source}');`;
26
+ }
27
+ const namedMatch = importClause.match(/^\{([^}]+)\}$/);
28
+ if (namedMatch) {
29
+ return `const { ${namedMatch[1]} } = __mockModule('${source}');`;
30
+ }
31
+ const defaultMatch = importClause.match(/^(\w+)/);
32
+ if (defaultMatch) {
33
+ const defaultName = defaultMatch[1];
34
+ const mixedMatch = importClause.match(/^(\w+)\s*,\s*\{([^}]+)\}$/);
35
+ if (mixedMatch) {
36
+ const namedImports = mixedMatch[2];
37
+ return `const _mock_${defaultName} = __mockModule('${source}'); const ${defaultName} = _mock_${defaultName}.default || _mock_${defaultName}; const { ${namedImports} } = _mock_${defaultName};`;
38
+ }
39
+ return `const ${defaultName} = __mockModule('${source}').default || __mockModule('${source}');`;
40
+ }
41
+ return "";
42
+ }
22
43
  function compileSFC(code, scopeId, options) {
23
44
  const whitelist = options?.allowedImports ?? ALLOWED_IMPORT_SOURCES;
24
45
  const strippedImports = [];
@@ -36,8 +57,8 @@ function compileSFC(code, scopeId, options) {
36
57
  let cleanScript = script;
37
58
  cleanScript = cleanScript.replace(/import\s+type\s+[\s\S]*?from\s+['"].*?['"];?/g, "");
38
59
  cleanScript = cleanScript.replace(
39
- /import\s+[\s\S]*?from\s+['"]([^'"]+)['"];?/g,
40
- (match, source) => {
60
+ /import\s+([^;]+?)\s+from\s+['"]([^'"]+)['"];?/g,
61
+ (match, importClause, source) => {
41
62
  const isWhitelisted = whitelist.some(
42
63
  (w) => source === w || source.startsWith(w + "/")
43
64
  );
@@ -47,7 +68,7 @@ function compileSFC(code, scopeId, options) {
47
68
  }
48
69
  if (source.startsWith(".")) {
49
70
  strippedImports.push({ source, reason: "relative" });
50
- return "";
71
+ return transformLocalImportToMock(importClause.trim(), source);
51
72
  }
52
73
  strippedImports.push({ source, reason: "unknown" });
53
74
  return "";
@@ -1,4 +1,4 @@
1
- import { compileSFC } from './chunk-JAICJP7Q.mjs';
1
+ import { compileSFC } from './chunk-L4DS3EXI.mjs';
2
2
 
3
3
  // src/runtime/index.ts
4
4
  var scopeIdCounter = 0;
@@ -80,7 +80,26 @@ var MOCK_VUE_CONTEXT = {
80
80
  // @ksyun-internal/versatile Hooks
81
81
  // =========================================================================
82
82
  useToState: (_props, _key, _emit, defaultValue) => ({ value: defaultValue ?? void 0 }),
83
- useIdEntity: () => ({ value: void 0 })
83
+ useIdEntity: () => ({ value: void 0 }),
84
+ // =========================================================================
85
+ // Module Mocking
86
+ // =========================================================================
87
+ __mockModule: (modulePath) => {
88
+ const createMockProxy = (path) => {
89
+ return new Proxy(() => {
90
+ }, {
91
+ get: (target, prop) => {
92
+ if (prop === Symbol.toPrimitive) return () => 0;
93
+ if (prop === "then") return void 0;
94
+ return createMockProxy();
95
+ },
96
+ apply: (target, thisArg, args) => {
97
+ return createMockProxy();
98
+ }
99
+ });
100
+ };
101
+ return createMockProxy();
102
+ }
84
103
  };
85
104
  function validateRuntimePrecheck(code) {
86
105
  const scopeId = `runtime-${Date.now()}-${++scopeIdCounter}`;
@@ -1,6 +1,6 @@
1
1
  import { analyzeCodeWithAST } from './chunk-UYVGHUC5.mjs';
2
- import { validateRuntimePrecheck } from './chunk-KWZGUEDK.mjs';
3
- import { compileSFC } from './chunk-JAICJP7Q.mjs';
2
+ import { validateRuntimePrecheck } from './chunk-NZ6TLWMD.mjs';
3
+ import { compileSFC } from './chunk-L4DS3EXI.mjs';
4
4
 
5
5
  // src/tools/unifiedValidator.ts
6
6
  function validateCompilation(code) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk2FV6BC3K_js = require('./chunk-2FV6BC3K.js');
3
+ var chunkHPAUCD5I_js = require('./chunk-HPAUCD5I.js');
4
4
 
5
5
  // src/static/index.ts
6
6
  var scopeIdCounter = 0;
@@ -44,7 +44,7 @@ function validateCompilation(code) {
44
44
  errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 <template> \u6216 <script> \u6807\u7B7E"]
45
45
  };
46
46
  }
47
- const result = chunk2FV6BC3K_js.compileSFC(code, scopeId);
47
+ const result = chunkHPAUCD5I_js.compileSFC(code, scopeId);
48
48
  if (result.error) {
49
49
  return {
50
50
  name: "\u7F16\u8BD1\u68C0\u67E5",
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunkD6QDTSMN_js = require('../chunk-D6QDTSMN.js');
3
+ var chunkBVQTJJYS_js = require('../chunk-BVQTJJYS.js');
4
4
  require('../chunk-GW5YOUB7.js');
5
- require('../chunk-32HIMGM4.js');
6
- require('../chunk-2FV6BC3K.js');
5
+ require('../chunk-D3Y6FGWA.js');
6
+ require('../chunk-HPAUCD5I.js');
7
7
 
8
8
 
9
9
 
10
10
  Object.defineProperty(exports, "validateCode", {
11
11
  enumerable: true,
12
- get: function () { return chunkD6QDTSMN_js.validateCode; }
12
+ get: function () { return chunkBVQTJJYS_js.validateCode; }
13
13
  });
14
14
  Object.defineProperty(exports, "validateCodeSync", {
15
15
  enumerable: true,
16
- get: function () { return chunkD6QDTSMN_js.validateCodeSync; }
16
+ get: function () { return chunkBVQTJJYS_js.validateCodeSync; }
17
17
  });
@@ -1,4 +1,4 @@
1
- export { validateCode, validateCodeSync } from '../chunk-CVJFFX7X.mjs';
1
+ export { validateCode, validateCodeSync } from '../chunk-QSJKP7AO.mjs';
2
2
  import '../chunk-UYVGHUC5.mjs';
3
- import '../chunk-KWZGUEDK.mjs';
4
- import '../chunk-JAICJP7Q.mjs';
3
+ import '../chunk-NZ6TLWMD.mjs';
4
+ import '../chunk-L4DS3EXI.mjs';
package/dist/index.js CHANGED
@@ -1,25 +1,25 @@
1
1
  'use strict';
2
2
 
3
- var chunkXKMKIWYX_js = require('./chunk-XKMKIWYX.js');
3
+ var chunkWYSRJVX4_js = require('./chunk-WYSRJVX4.js');
4
4
  require('./chunk-YTEYDSDW.js');
5
- var chunkD6QDTSMN_js = require('./chunk-D6QDTSMN.js');
5
+ var chunkBVQTJJYS_js = require('./chunk-BVQTJJYS.js');
6
6
  var chunkGW5YOUB7_js = require('./chunk-GW5YOUB7.js');
7
- var chunk32HIMGM4_js = require('./chunk-32HIMGM4.js');
8
- var chunk2FV6BC3K_js = require('./chunk-2FV6BC3K.js');
7
+ var chunkD3Y6FGWA_js = require('./chunk-D3Y6FGWA.js');
8
+ var chunkHPAUCD5I_js = require('./chunk-HPAUCD5I.js');
9
9
 
10
10
 
11
11
 
12
12
  Object.defineProperty(exports, "validateCompilation", {
13
13
  enumerable: true,
14
- get: function () { return chunkXKMKIWYX_js.validateCompilation; }
14
+ get: function () { return chunkWYSRJVX4_js.validateCompilation; }
15
15
  });
16
16
  Object.defineProperty(exports, "validateCode", {
17
17
  enumerable: true,
18
- get: function () { return chunkD6QDTSMN_js.validateCode; }
18
+ get: function () { return chunkBVQTJJYS_js.validateCode; }
19
19
  });
20
20
  Object.defineProperty(exports, "validateCodeSync", {
21
21
  enumerable: true,
22
- get: function () { return chunkD6QDTSMN_js.validateCodeSync; }
22
+ get: function () { return chunkBVQTJJYS_js.validateCodeSync; }
23
23
  });
24
24
  Object.defineProperty(exports, "analyzeCodeWithAST", {
25
25
  enumerable: true,
@@ -31,13 +31,13 @@ Object.defineProperty(exports, "componentRegistry", {
31
31
  });
32
32
  Object.defineProperty(exports, "validateRuntimePrecheck", {
33
33
  enumerable: true,
34
- get: function () { return chunk32HIMGM4_js.validateRuntimePrecheck; }
34
+ get: function () { return chunkD3Y6FGWA_js.validateRuntimePrecheck; }
35
35
  });
36
36
  Object.defineProperty(exports, "compileSFC", {
37
37
  enumerable: true,
38
- get: function () { return chunk2FV6BC3K_js.compileSFC; }
38
+ get: function () { return chunkHPAUCD5I_js.compileSFC; }
39
39
  });
40
40
  Object.defineProperty(exports, "scopeStyles", {
41
41
  enumerable: true,
42
- get: function () { return chunk2FV6BC3K_js.scopeStyles; }
42
+ get: function () { return chunkHPAUCD5I_js.scopeStyles; }
43
43
  });
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- export { validateCompilation } from './chunk-UV564QXV.mjs';
1
+ export { validateCompilation } from './chunk-DSWKLUIX.mjs';
2
2
  import './chunk-5H7N2A5X.mjs';
3
- export { validateCode, validateCodeSync } from './chunk-CVJFFX7X.mjs';
3
+ export { validateCode, validateCodeSync } from './chunk-QSJKP7AO.mjs';
4
4
  export { analyzeCodeWithAST, componentRegistry } from './chunk-UYVGHUC5.mjs';
5
- export { validateRuntimePrecheck } from './chunk-KWZGUEDK.mjs';
6
- export { compileSFC, scopeStyles } from './chunk-JAICJP7Q.mjs';
5
+ export { validateRuntimePrecheck } from './chunk-NZ6TLWMD.mjs';
6
+ export { compileSFC, scopeStyles } from './chunk-L4DS3EXI.mjs';
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var chunk32HIMGM4_js = require('../chunk-32HIMGM4.js');
4
- var chunk2FV6BC3K_js = require('../chunk-2FV6BC3K.js');
3
+ var chunkD3Y6FGWA_js = require('../chunk-D3Y6FGWA.js');
4
+ var chunkHPAUCD5I_js = require('../chunk-HPAUCD5I.js');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "validateRuntimePrecheck", {
9
9
  enumerable: true,
10
- get: function () { return chunk32HIMGM4_js.validateRuntimePrecheck; }
10
+ get: function () { return chunkD3Y6FGWA_js.validateRuntimePrecheck; }
11
11
  });
12
12
  Object.defineProperty(exports, "compileSFC", {
13
13
  enumerable: true,
14
- get: function () { return chunk2FV6BC3K_js.compileSFC; }
14
+ get: function () { return chunkHPAUCD5I_js.compileSFC; }
15
15
  });
@@ -1,2 +1,2 @@
1
- export { validateRuntimePrecheck } from '../chunk-KWZGUEDK.mjs';
2
- export { compileSFC } from '../chunk-JAICJP7Q.mjs';
1
+ export { validateRuntimePrecheck } from '../chunk-NZ6TLWMD.mjs';
2
+ export { compileSFC } from '../chunk-L4DS3EXI.mjs';
@@ -1,19 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var chunkXKMKIWYX_js = require('../chunk-XKMKIWYX.js');
4
- var chunk2FV6BC3K_js = require('../chunk-2FV6BC3K.js');
3
+ var chunkWYSRJVX4_js = require('../chunk-WYSRJVX4.js');
4
+ var chunkHPAUCD5I_js = require('../chunk-HPAUCD5I.js');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "validateCompilation", {
9
9
  enumerable: true,
10
- get: function () { return chunkXKMKIWYX_js.validateCompilation; }
10
+ get: function () { return chunkWYSRJVX4_js.validateCompilation; }
11
11
  });
12
12
  Object.defineProperty(exports, "compileSFC", {
13
13
  enumerable: true,
14
- get: function () { return chunk2FV6BC3K_js.compileSFC; }
14
+ get: function () { return chunkHPAUCD5I_js.compileSFC; }
15
15
  });
16
16
  Object.defineProperty(exports, "scopeStyles", {
17
17
  enumerable: true,
18
- get: function () { return chunk2FV6BC3K_js.scopeStyles; }
18
+ get: function () { return chunkHPAUCD5I_js.scopeStyles; }
19
19
  });
@@ -1,2 +1,2 @@
1
- export { validateCompilation } from '../chunk-UV564QXV.mjs';
2
- export { compileSFC, scopeStyles } from '../chunk-JAICJP7Q.mjs';
1
+ export { validateCompilation } from '../chunk-DSWKLUIX.mjs';
2
+ export { compileSFC, scopeStyles } from '../chunk-L4DS3EXI.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "king-design-analyzer",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
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",
@@ -76,6 +76,7 @@
76
76
  "author": "",
77
77
  "license": "MIT",
78
78
  "dependencies": {
79
+ "king-design-analyzer": "^2.1.4",
79
80
  "sucrase": "^3.35.1"
80
81
  },
81
82
  "peerDependencies": {