baseguard 1.0.2 → 1.0.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.
Files changed (169) hide show
  1. package/.baseguardrc.example.json +63 -63
  2. package/.eslintrc.json +24 -24
  3. package/.prettierrc +7 -7
  4. package/CHANGELOG.md +195 -195
  5. package/DEPLOYMENT.md +624 -624
  6. package/DEPLOYMENT_CHECKLIST.md +239 -239
  7. package/DEPLOYMENT_SUMMARY_v1.0.2.md +202 -202
  8. package/QUICK_START.md +134 -134
  9. package/README.md +488 -488
  10. package/RELEASE_NOTES_v1.0.2.md +434 -434
  11. package/bin/base.js +628 -613
  12. package/dist/ai/fix-manager.d.ts.map +1 -1
  13. package/dist/ai/fix-manager.js +1 -1
  14. package/dist/ai/fix-manager.js.map +1 -1
  15. package/dist/ai/gemini-analyzer.d.ts.map +1 -1
  16. package/dist/ai/gemini-analyzer.js +29 -35
  17. package/dist/ai/gemini-analyzer.js.map +1 -1
  18. package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
  19. package/dist/ai/gemini-code-fixer.js +58 -58
  20. package/dist/ai/gemini-code-fixer.js.map +1 -1
  21. package/dist/ai/jules-implementer.d.ts +3 -0
  22. package/dist/ai/jules-implementer.d.ts.map +1 -1
  23. package/dist/ai/jules-implementer.js +63 -32
  24. package/dist/ai/jules-implementer.js.map +1 -1
  25. package/dist/ai/unified-code-fixer.js.map +1 -1
  26. package/dist/commands/check.d.ts.map +1 -1
  27. package/dist/commands/check.js +1 -1
  28. package/dist/commands/check.js.map +1 -1
  29. package/dist/commands/config.js +2 -1
  30. package/dist/commands/config.js.map +1 -1
  31. package/dist/commands/fix.d.ts.map +1 -1
  32. package/dist/commands/fix.js +44 -15
  33. package/dist/commands/fix.js.map +1 -1
  34. package/dist/core/api-key-manager.js +2 -2
  35. package/dist/core/api-key-manager.js.map +1 -1
  36. package/dist/core/baseguard.d.ts +1 -0
  37. package/dist/core/baseguard.d.ts.map +1 -1
  38. package/dist/core/baseguard.js +13 -10
  39. package/dist/core/baseguard.js.map +1 -1
  40. package/dist/core/baseline-checker.d.ts.map +1 -1
  41. package/dist/core/baseline-checker.js +2 -1
  42. package/dist/core/baseline-checker.js.map +1 -1
  43. package/dist/core/configuration-recovery.d.ts.map +1 -1
  44. package/dist/core/configuration-recovery.js +1 -1
  45. package/dist/core/configuration-recovery.js.map +1 -1
  46. package/dist/core/debug-logger.d.ts.map +1 -1
  47. package/dist/core/debug-logger.js +1 -1
  48. package/dist/core/debug-logger.js.map +1 -1
  49. package/dist/core/error-handler.d.ts.map +1 -1
  50. package/dist/core/error-handler.js +2 -1
  51. package/dist/core/error-handler.js.map +1 -1
  52. package/dist/core/gitignore-manager.js +5 -5
  53. package/dist/core/graceful-degradation-manager.d.ts.map +1 -1
  54. package/dist/core/graceful-degradation-manager.js +16 -16
  55. package/dist/core/graceful-degradation-manager.js.map +1 -1
  56. package/dist/core/lazy-loader.d.ts.map +1 -1
  57. package/dist/core/lazy-loader.js +9 -2
  58. package/dist/core/lazy-loader.js.map +1 -1
  59. package/dist/core/memory-manager.d.ts +0 -3
  60. package/dist/core/memory-manager.d.ts.map +1 -1
  61. package/dist/core/memory-manager.js.map +1 -1
  62. package/dist/core/parser-worker.d.ts +2 -0
  63. package/dist/core/parser-worker.d.ts.map +1 -0
  64. package/dist/core/parser-worker.js +19 -0
  65. package/dist/core/parser-worker.js.map +1 -0
  66. package/dist/core/startup-optimizer.d.ts +2 -0
  67. package/dist/core/startup-optimizer.d.ts.map +1 -1
  68. package/dist/core/startup-optimizer.js +19 -12
  69. package/dist/core/startup-optimizer.js.map +1 -1
  70. package/dist/core/system-error-handler.d.ts.map +1 -1
  71. package/dist/core/system-error-handler.js +18 -11
  72. package/dist/core/system-error-handler.js.map +1 -1
  73. package/dist/git/automation-engine.d.ts.map +1 -1
  74. package/dist/git/automation-engine.js +5 -4
  75. package/dist/git/automation-engine.js.map +1 -1
  76. package/dist/git/github-manager.d.ts.map +1 -1
  77. package/dist/git/github-manager.js.map +1 -1
  78. package/dist/git/hook-manager.js +5 -5
  79. package/dist/git/hook-manager.js.map +1 -1
  80. package/dist/parsers/parser-manager.d.ts.map +1 -1
  81. package/dist/parsers/parser-manager.js +1 -1
  82. package/dist/parsers/parser-manager.js.map +1 -1
  83. package/dist/parsers/svelte-parser.js +1 -1
  84. package/dist/parsers/svelte-parser.js.map +1 -1
  85. package/dist/parsers/vanilla-parser.d.ts.map +1 -1
  86. package/dist/parsers/vanilla-parser.js.map +1 -1
  87. package/dist/parsers/vue-parser.d.ts.map +1 -1
  88. package/dist/parsers/vue-parser.js.map +1 -1
  89. package/dist/ui/components.d.ts +1 -1
  90. package/dist/ui/components.d.ts.map +1 -1
  91. package/dist/ui/components.js +11 -11
  92. package/dist/ui/components.js.map +1 -1
  93. package/dist/ui/terminal-header.js +14 -14
  94. package/package.json +105 -105
  95. package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
  96. package/src/ai/agentkit-orchestrator.ts +533 -533
  97. package/src/ai/fix-manager.ts +362 -362
  98. package/src/ai/gemini-analyzer.ts +665 -671
  99. package/src/ai/gemini-code-fixer.ts +539 -540
  100. package/src/ai/index.ts +3 -3
  101. package/src/ai/jules-implementer.ts +504 -460
  102. package/src/ai/unified-code-fixer.ts +347 -347
  103. package/src/commands/automation.ts +343 -343
  104. package/src/commands/check.ts +298 -299
  105. package/src/commands/config.ts +584 -583
  106. package/src/commands/fix.ts +264 -238
  107. package/src/commands/index.ts +6 -6
  108. package/src/commands/init.ts +155 -155
  109. package/src/commands/status.ts +306 -306
  110. package/src/core/api-key-manager.ts +298 -298
  111. package/src/core/baseguard.ts +757 -756
  112. package/src/core/baseline-checker.ts +564 -563
  113. package/src/core/cache-manager.ts +271 -271
  114. package/src/core/configuration-recovery.ts +672 -673
  115. package/src/core/configuration.ts +595 -595
  116. package/src/core/debug-logger.ts +590 -590
  117. package/src/core/directory-filter.ts +420 -420
  118. package/src/core/error-handler.ts +518 -517
  119. package/src/core/file-processor.ts +337 -337
  120. package/src/core/gitignore-manager.ts +168 -168
  121. package/src/core/graceful-degradation-manager.ts +596 -596
  122. package/src/core/index.ts +16 -16
  123. package/src/core/lazy-loader.ts +317 -307
  124. package/src/core/memory-manager.ts +290 -295
  125. package/src/core/parser-worker.ts +33 -0
  126. package/src/core/startup-optimizer.ts +246 -243
  127. package/src/core/system-error-handler.ts +755 -750
  128. package/src/git/automation-engine.ts +361 -361
  129. package/src/git/github-manager.ts +190 -192
  130. package/src/git/hook-manager.ts +210 -210
  131. package/src/git/index.ts +3 -3
  132. package/src/index.ts +7 -7
  133. package/src/parsers/feature-validator.ts +558 -558
  134. package/src/parsers/index.ts +7 -7
  135. package/src/parsers/parser-manager.ts +418 -419
  136. package/src/parsers/parser.ts +25 -25
  137. package/src/parsers/react-parser-optimized.ts +160 -160
  138. package/src/parsers/react-parser.ts +358 -358
  139. package/src/parsers/svelte-parser.ts +510 -510
  140. package/src/parsers/vanilla-parser.ts +685 -686
  141. package/src/parsers/vue-parser.ts +476 -478
  142. package/src/types/index.ts +95 -95
  143. package/src/ui/components.ts +567 -567
  144. package/src/ui/help.ts +192 -192
  145. package/src/ui/index.ts +3 -3
  146. package/src/ui/prompts.ts +680 -680
  147. package/src/ui/terminal-header.ts +58 -58
  148. package/test-build.js +40 -40
  149. package/test-config-commands.js +55 -55
  150. package/test-header-simple.js +32 -32
  151. package/test-terminal-header.js +11 -11
  152. package/test-ui.js +28 -28
  153. package/tests/e2e/baseguard.e2e.test.ts +515 -515
  154. package/tests/e2e/cross-platform.e2e.test.ts +419 -419
  155. package/tests/e2e/git-integration.e2e.test.ts +486 -486
  156. package/tests/fixtures/react-project/package.json +13 -13
  157. package/tests/fixtures/react-project/src/App.css +75 -75
  158. package/tests/fixtures/react-project/src/App.tsx +76 -76
  159. package/tests/fixtures/svelte-project/package.json +10 -10
  160. package/tests/fixtures/svelte-project/src/App.svelte +368 -368
  161. package/tests/fixtures/vanilla-project/index.html +75 -75
  162. package/tests/fixtures/vanilla-project/script.js +330 -330
  163. package/tests/fixtures/vanilla-project/styles.css +358 -358
  164. package/tests/fixtures/vue-project/package.json +11 -11
  165. package/tests/fixtures/vue-project/src/App.vue +215 -215
  166. package/tsconfig.json +34 -34
  167. package/vitest.config.ts +11 -11
  168. package/dist/terminal-header.d.ts +0 -12
  169. package/dist/terminal-header.js +0 -45
@@ -1,478 +1,476 @@
1
- import { Parser } from './parser.js';
2
- import type { DetectedFeature } from '../types/index.js';
3
- import { LazyLoader } from '../core/lazy-loader.js';
4
- import traverse from '@babel/traverse';
5
- import * as t from '@babel/types';
6
- import postcss from 'postcss';
7
-
8
- /**
9
- * Vue single-file component parser - extracts ALL web platform features
10
- * while ignoring Vue-specific APIs
11
- */
12
- export class VueParser extends Parser {
13
- private readonly VUE_SPECIFIC_APIS = new Set([
14
- // Vue 3 Composition API
15
- 'ref', 'reactive', 'computed', 'watch', 'watchEffect', 'onMounted', 'onUnmounted',
16
- 'onBeforeMount', 'onBeforeUnmount', 'onUpdated', 'onBeforeUpdate',
17
- 'onActivated', 'onDeactivated', 'onErrorCaptured', 'provide', 'inject',
18
- 'getCurrentInstance', 'nextTick', 'defineComponent', 'defineProps', 'defineEmits',
19
- 'defineExpose', 'withDefaults', 'toRef', 'toRefs', 'unref', 'isRef',
20
-
21
- // Vue 2 Options API
22
- 'Vue', 'data', 'props', 'methods', 'computed', 'watch', 'created', 'mounted',
23
- 'updated', 'destroyed', 'beforeCreate', 'beforeMount', 'beforeUpdate', 'beforeDestroy',
24
- 'activated', 'deactivated', 'errorCaptured', 'mixins', 'extends', 'components',
25
-
26
- // Vue Router
27
- 'useRouter', 'useRoute', '$router', '$route', 'router-link', 'router-view',
28
-
29
- // Vuex/Pinia
30
- 'useStore', '$store', 'mapState', 'mapGetters', 'mapMutations', 'mapActions'
31
- ]);
32
-
33
- private readonly VUE_DIRECTIVES = new Set([
34
- 'v-if', 'v-else', 'v-else-if', 'v-for', 'v-show', 'v-bind', 'v-on', 'v-model',
35
- 'v-slot', 'v-pre', 'v-cloak', 'v-once', 'v-memo', 'v-html', 'v-text'
36
- ]);
37
-
38
- private readonly WEB_PLATFORM_APIS = new Set([
39
- // Canvas APIs
40
- 'getContext', 'CanvasRenderingContext2D', 'WebGLRenderingContext', 'WebGL2RenderingContext',
41
- 'OffscreenCanvas', 'ImageBitmap', 'createImageBitmap', 'Path2D',
42
-
43
- // WebRTC APIs
44
- 'RTCPeerConnection', 'RTCDataChannel', 'RTCSessionDescription', 'RTCIceCandidate',
45
- 'getUserMedia', 'getDisplayMedia', 'MediaStream', 'MediaStreamTrack',
46
-
47
- // WebAssembly
48
- 'WebAssembly', 'instantiate', 'compile', 'validate',
49
-
50
- // Service Workers & PWA
51
- 'ServiceWorker', 'serviceWorker', 'register', 'Cache', 'caches',
52
- 'PushManager', 'Notification', 'showNotification',
53
-
54
- // DOM APIs
55
- 'querySelector', 'querySelectorAll', 'getElementById', 'getElementsByClassName',
56
- 'addEventListener', 'removeEventListener', 'dispatchEvent', 'CustomEvent',
57
- 'MutationObserver', 'ResizeObserver', 'IntersectionObserver', 'PerformanceObserver',
58
- 'AbortController', 'AbortSignal', 'FormData', 'URLSearchParams', 'URL',
59
- 'fetch', 'Request', 'Response', 'Headers', 'Blob', 'File', 'FileReader',
60
-
61
- // Web APIs
62
- 'navigator', 'geolocation', 'permissions', 'clipboard', 'share',
63
- 'requestAnimationFrame', 'cancelAnimationFrame', 'requestIdleCallback',
64
- 'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
65
- 'localStorage', 'sessionStorage', 'indexedDB', 'crypto', 'performance',
66
-
67
- // Audio/Video APIs
68
- 'AudioContext', 'MediaRecorder', 'MediaSource', 'SourceBuffer',
69
- 'HTMLMediaElement', 'HTMLAudioElement', 'HTMLVideoElement',
70
-
71
- // Modern JavaScript APIs
72
- 'structuredClone', 'queueMicrotask', 'reportError',
73
- 'WeakRef', 'FinalizationRegistry', 'AggregateError',
74
-
75
- // Intl APIs
76
- 'Intl', 'DateTimeFormat', 'NumberFormat', 'Collator', 'PluralRules',
77
- 'RelativeTimeFormat', 'ListFormat', 'Locale'
78
- ]);
79
-
80
- canParse(filePath: string): boolean {
81
- return /\.vue$/.test(filePath);
82
- }
83
-
84
- async parseFeatures(content: string, filePath: string): Promise<DetectedFeature[]> {
85
- const features: DetectedFeature[] = [];
86
-
87
- try {
88
- // Lazy load Vue compiler
89
- const vueCompiler = await LazyLoader.getVueCompiler();
90
- const { descriptor } = vueCompiler.parse(content, { filename: filePath });
91
-
92
- // Parse script blocks for JavaScript features
93
- if (descriptor.script) {
94
- const scriptFeatures = await this.parseScriptBlock(
95
- descriptor.script.content,
96
- descriptor.script.lang || 'js',
97
- filePath
98
- );
99
- features.push(...scriptFeatures);
100
- }
101
-
102
- if (descriptor.scriptSetup) {
103
- const setupFeatures = await this.parseScriptBlock(
104
- descriptor.scriptSetup.content,
105
- descriptor.scriptSetup.lang || 'js',
106
- filePath
107
- );
108
- features.push(...setupFeatures);
109
- }
110
-
111
- // Parse style blocks for CSS features
112
- if (descriptor.styles) {
113
- for (const style of descriptor.styles) {
114
- const styleFeatures = await this.parseStyleBlock(
115
- style.content,
116
- style.lang || 'css',
117
- filePath
118
- );
119
- features.push(...styleFeatures);
120
- }
121
- }
122
-
123
- // Parse template for HTML features (standard elements only)
124
- if (descriptor.template) {
125
- const templateFeatures = this.parseTemplateBlock(
126
- descriptor.template.content,
127
- filePath
128
- );
129
- features.push(...templateFeatures);
130
- }
131
-
132
- } catch (error) {
133
- console.warn(`Warning: Could not parse Vue file ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
134
- }
135
-
136
- return features;
137
- }
138
-
139
- private async parseScriptBlock(content: string, lang: string, filePath: string): Promise<DetectedFeature[]> {
140
- const features: DetectedFeature[] = [];
141
-
142
- try {
143
- const isTypeScript = lang === 'ts' || lang === 'typescript';
144
-
145
- // Lazy load Babel dependencies
146
- const [parser, traverse] = await Promise.all([
147
- LazyLoader.getBabelParser(),
148
- LazyLoader.getBabelTraverse()
149
- ]);
150
-
151
- const ast = parser.parse(content, {
152
- sourceType: 'module',
153
- plugins: [
154
- 'typescript',
155
- 'decorators-legacy',
156
- 'classProperties',
157
- 'objectRestSpread',
158
- 'asyncGenerators',
159
- 'functionBind',
160
- 'exportDefaultFrom',
161
- 'exportNamespaceFrom',
162
- 'dynamicImport',
163
- 'nullishCoalescingOperator',
164
- 'optionalChaining',
165
- 'topLevelAwait'
166
- ].filter(plugin => isTypeScript || plugin !== 'typescript')
167
- });
168
-
169
- traverse(ast, {
170
- // Extract JavaScript Web APIs
171
- MemberExpression: (path: any) => {
172
- const feature = this.extractWebAPIFeature(path.node, path, content);
173
- if (feature) {
174
- features.push({ ...feature, file: filePath });
175
- }
176
- },
177
-
178
- // Extract function calls to Web APIs
179
- CallExpression: (path: any) => {
180
- const feature = this.extractWebAPICall(path.node, path, content);
181
- if (feature) {
182
- features.push({ ...feature, file: filePath });
183
- }
184
- },
185
-
186
- // Extract modern JavaScript syntax features
187
- OptionalMemberExpression: (path: any) => {
188
- features.push({
189
- feature: 'optional-chaining',
190
- type: 'js',
191
- context: this.getContext(content, path.node.loc?.start.line || 0),
192
- line: path.node.loc?.start.line || 0,
193
- column: path.node.loc?.start.column || 0,
194
- file: filePath
195
- });
196
- },
197
-
198
- // Nullish coalescing
199
- LogicalExpression: (path: any) => {
200
- if (path.node.operator === '??') {
201
- features.push({
202
- feature: 'nullish-coalescing',
203
- type: 'js',
204
- context: this.getContext(content, path.node.loc?.start.line || 0),
205
- line: path.node.loc?.start.line || 0,
206
- column: path.node.loc?.start.column || 0,
207
- file: filePath
208
- });
209
- }
210
- },
211
-
212
- // Private class fields
213
- ClassPrivateProperty: (path: any) => {
214
- features.push({
215
- feature: 'private-fields',
216
- type: 'js',
217
- context: this.getContext(content, path.node.loc?.start.line || 0),
218
- line: path.node.loc?.start.line || 0,
219
- column: path.node.loc?.start.column || 0,
220
- file: filePath
221
- });
222
- },
223
-
224
- // Top-level await
225
- AwaitExpression: (path: any) => {
226
- if (this.isTopLevelAwait(path)) {
227
- features.push({
228
- feature: 'top-level-await',
229
- type: 'js',
230
- context: this.getContext(content, path.node.loc?.start.line || 0),
231
- line: path.node.loc?.start.line || 0,
232
- column: path.node.loc?.start.column || 0,
233
- file: filePath
234
- });
235
- }
236
- }
237
- });
238
-
239
- } catch (error) {
240
- console.warn(`Warning: Could not parse script block in ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
241
- }
242
-
243
- return features;
244
- }
245
-
246
- private async parseStyleBlock(content: string, lang: string, filePath: string): Promise<DetectedFeature[]> {
247
- const features: DetectedFeature[] = [];
248
-
249
- try {
250
- // For now, only handle CSS (not SCSS, Less, etc.)
251
- if (lang === 'css' || !lang) {
252
- // Lazy load PostCSS
253
- const postcss = await LazyLoader.getPostCSS();
254
- const root = postcss.parse(content);
255
-
256
- root.walkDecls((decl: any) => {
257
- features.push({
258
- feature: decl.prop,
259
- type: 'css',
260
- context: `${decl.prop}: ${decl.value}`,
261
- line: decl.source?.start?.line || 0,
262
- column: decl.source?.start?.column || 0,
263
- file: filePath
264
- });
265
- });
266
-
267
- root.walkRules((rule: any) => {
268
- // Extract CSS selectors that might be modern features
269
- if (rule.selector.includes(':has(') ||
270
- rule.selector.includes(':is(') ||
271
- rule.selector.includes(':where(') ||
272
- rule.selector.includes(':focus-visible')) {
273
- features.push({
274
- feature: this.extractSelectorFeature(rule.selector),
275
- type: 'css',
276
- context: rule.selector,
277
- line: rule.source?.start?.line || 0,
278
- column: rule.source?.start?.column || 0,
279
- file: filePath
280
- });
281
- }
282
- });
283
-
284
- root.walkAtRules((atRule: any) => {
285
- // Extract at-rules like @supports, @container, etc.
286
- features.push({
287
- feature: `@${atRule.name}`,
288
- type: 'css',
289
- context: `@${atRule.name} ${atRule.params}`,
290
- line: atRule.source?.start?.line || 0,
291
- column: atRule.source?.start?.column || 0,
292
- file: filePath
293
- });
294
- });
295
- }
296
- } catch (error) {
297
- console.warn(`Warning: Could not parse style block in ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
298
- }
299
-
300
- return features;
301
- }
302
-
303
- private parseTemplateBlock(content: string, filePath: string): DetectedFeature[] {
304
- const features: DetectedFeature[] = [];
305
-
306
- // Extract standard HTML elements and attributes (ignore Vue directives)
307
- const htmlElementRegex = /<(\w+)([^>]*)>/g;
308
- const lines = content.split('\n');
309
-
310
- lines.forEach((line, index) => {
311
- let match: RegExpExecArray | null;
312
- while ((match = htmlElementRegex.exec(line)) !== null) {
313
- const tagName = match[1];
314
- const attributes = match[2];
315
-
316
- // Check for modern HTML elements
317
- if (tagName && this.isModernHTMLElement(tagName)) {
318
- features.push({
319
- feature: tagName,
320
- type: 'html',
321
- context: line.trim(),
322
- line: index + 1,
323
- column: match.index,
324
- file: filePath
325
- });
326
- }
327
-
328
- // Check for modern HTML attributes (ignore Vue directives)
329
- if (attributes) {
330
- const modernAttrs = this.extractModernAttributes(attributes);
331
- modernAttrs.forEach(attr => {
332
- features.push({
333
- feature: attr,
334
- type: 'html',
335
- context: line.trim(),
336
- line: index + 1,
337
- column: match!.index,
338
- file: filePath
339
- });
340
- });
341
- }
342
- }
343
- });
344
-
345
- return features;
346
- }
347
-
348
- private extractWebAPIFeature(node: t.MemberExpression, path: any, content: string): DetectedFeature | null {
349
- const apiName = this.getMemberExpressionName(node);
350
-
351
- if (!apiName || this.VUE_SPECIFIC_APIS.has(apiName)) {
352
- return null;
353
- }
354
-
355
- if (this.WEB_PLATFORM_APIS.has(apiName)) {
356
- return {
357
- feature: apiName,
358
- type: 'js',
359
- context: this.getContext(content, node.loc?.start.line || 0),
360
- line: node.loc?.start.line || 0,
361
- column: node.loc?.start.column || 0
362
- };
363
- }
364
-
365
- return null;
366
- }
367
-
368
- private extractWebAPICall(node: t.CallExpression, path: any, content: string): DetectedFeature | null {
369
- let apiName = '';
370
-
371
- if (t.isIdentifier(node.callee)) {
372
- apiName = node.callee.name;
373
- } else if (t.isMemberExpression(node.callee)) {
374
- apiName = this.getMemberExpressionName(node.callee);
375
- }
376
-
377
- if (!apiName || this.VUE_SPECIFIC_APIS.has(apiName)) {
378
- return null;
379
- }
380
-
381
- if (this.WEB_PLATFORM_APIS.has(apiName)) {
382
- return {
383
- feature: apiName,
384
- type: 'js',
385
- context: this.getContext(content, node.loc?.start.line || 0),
386
- line: node.loc?.start.line || 0,
387
- column: node.loc?.start.column || 0
388
- };
389
- }
390
-
391
- return null;
392
- }
393
-
394
- private getMemberExpressionName(node: t.MemberExpression): string {
395
- const parts: string[] = [];
396
-
397
- const traverse = (n: t.Expression): void => {
398
- if (t.isIdentifier(n)) {
399
- parts.unshift(n.name);
400
- } else if (t.isMemberExpression(n)) {
401
- if (t.isIdentifier(n.property)) {
402
- parts.unshift(n.property.name);
403
- }
404
- traverse(n.object);
405
- }
406
- };
407
-
408
- traverse(node);
409
- return parts.join('.');
410
- }
411
-
412
- private isTopLevelAwait(path: any): boolean {
413
- let parent = path.parent;
414
- while (parent) {
415
- if (t.isFunction(parent) || t.isArrowFunctionExpression(parent)) {
416
- return false;
417
- }
418
- parent = path.parentPath?.parent;
419
- }
420
- return true;
421
- }
422
-
423
- private extractSelectorFeature(selector: string): string {
424
- if (selector.includes(':has(')) return ':has()';
425
- if (selector.includes(':is(')) return ':is()';
426
- if (selector.includes(':where(')) return ':where()';
427
- if (selector.includes(':focus-visible')) return ':focus-visible';
428
- return selector;
429
- }
430
-
431
- private isModernHTMLElement(tagName: string): boolean {
432
- const modernElements = new Set([
433
- 'dialog', 'details', 'summary', 'main', 'article', 'section', 'nav', 'aside',
434
- 'header', 'footer', 'figure', 'figcaption', 'time', 'mark', 'progress', 'meter',
435
- 'canvas', 'video', 'audio', 'source', 'track', 'embed', 'object'
436
- ]);
437
- return modernElements.has(tagName);
438
- }
439
-
440
- private extractModernAttributes(attributes: string): string[] {
441
- const modernAttrs: string[] = [];
442
- const modernAttrPatterns = [
443
- /loading=["']lazy["']/,
444
- /decoding=["']async["']/,
445
- /fetchpriority=["'](high|low)["']/,
446
- /enterkeyhint=["']\w+["']/,
447
- /inputmode=["']\w+["']/
448
- ];
449
-
450
- modernAttrPatterns.forEach(pattern => {
451
- if (pattern.test(attributes)) {
452
- const match = attributes.match(pattern);
453
- if (match && match[0]) {
454
- const attrName = match[0].split('=')[0];
455
- if (attrName) {
456
- modernAttrs.push(attrName);
457
- }
458
- }
459
- }
460
- });
461
-
462
- return modernAttrs;
463
- }
464
-
465
- private getContext(content: string, line: number): string {
466
- const lines = content.split('\n');
467
- const targetLine = lines[line - 1] || '';
468
- return targetLine.trim();
469
- }
470
-
471
- getSupportedExtensions(): string[] {
472
- return ['.vue'];
473
- }
474
-
475
- getName(): string {
476
- return 'VueParser';
477
- }
478
- }
1
+ import { Parser } from './parser.js';
2
+ import type { DetectedFeature } from '../types/index.js';
3
+ import { LazyLoader } from '../core/lazy-loader.js';
4
+ import * as t from '@babel/types';
5
+
6
+ /**
7
+ * Vue single-file component parser - extracts ALL web platform features
8
+ * while ignoring Vue-specific APIs
9
+ */
10
+ export class VueParser extends Parser {
11
+ private readonly VUE_SPECIFIC_APIS = new Set([
12
+ // Vue 3 Composition API
13
+ 'ref', 'reactive', 'computed', 'watch', 'watchEffect', 'onMounted', 'onUnmounted',
14
+ 'onBeforeMount', 'onBeforeUnmount', 'onUpdated', 'onBeforeUpdate',
15
+ 'onActivated', 'onDeactivated', 'onErrorCaptured', 'provide', 'inject',
16
+ 'getCurrentInstance', 'nextTick', 'defineComponent', 'defineProps', 'defineEmits',
17
+ 'defineExpose', 'withDefaults', 'toRef', 'toRefs', 'unref', 'isRef',
18
+
19
+ // Vue 2 Options API
20
+ 'Vue', 'data', 'props', 'methods', 'computed', 'watch', 'created', 'mounted',
21
+ 'updated', 'destroyed', 'beforeCreate', 'beforeMount', 'beforeUpdate', 'beforeDestroy',
22
+ 'activated', 'deactivated', 'errorCaptured', 'mixins', 'extends', 'components',
23
+
24
+ // Vue Router
25
+ 'useRouter', 'useRoute', '$router', '$route', 'router-link', 'router-view',
26
+
27
+ // Vuex/Pinia
28
+ 'useStore', '$store', 'mapState', 'mapGetters', 'mapMutations', 'mapActions'
29
+ ]);
30
+
31
+ private readonly VUE_DIRECTIVES = new Set([
32
+ 'v-if', 'v-else', 'v-else-if', 'v-for', 'v-show', 'v-bind', 'v-on', 'v-model',
33
+ 'v-slot', 'v-pre', 'v-cloak', 'v-once', 'v-memo', 'v-html', 'v-text'
34
+ ]);
35
+
36
+ private readonly WEB_PLATFORM_APIS = new Set([
37
+ // Canvas APIs
38
+ 'getContext', 'CanvasRenderingContext2D', 'WebGLRenderingContext', 'WebGL2RenderingContext',
39
+ 'OffscreenCanvas', 'ImageBitmap', 'createImageBitmap', 'Path2D',
40
+
41
+ // WebRTC APIs
42
+ 'RTCPeerConnection', 'RTCDataChannel', 'RTCSessionDescription', 'RTCIceCandidate',
43
+ 'getUserMedia', 'getDisplayMedia', 'MediaStream', 'MediaStreamTrack',
44
+
45
+ // WebAssembly
46
+ 'WebAssembly', 'instantiate', 'compile', 'validate',
47
+
48
+ // Service Workers & PWA
49
+ 'ServiceWorker', 'serviceWorker', 'register', 'Cache', 'caches',
50
+ 'PushManager', 'Notification', 'showNotification',
51
+
52
+ // DOM APIs
53
+ 'querySelector', 'querySelectorAll', 'getElementById', 'getElementsByClassName',
54
+ 'addEventListener', 'removeEventListener', 'dispatchEvent', 'CustomEvent',
55
+ 'MutationObserver', 'ResizeObserver', 'IntersectionObserver', 'PerformanceObserver',
56
+ 'AbortController', 'AbortSignal', 'FormData', 'URLSearchParams', 'URL',
57
+ 'fetch', 'Request', 'Response', 'Headers', 'Blob', 'File', 'FileReader',
58
+
59
+ // Web APIs
60
+ 'navigator', 'geolocation', 'permissions', 'clipboard', 'share',
61
+ 'requestAnimationFrame', 'cancelAnimationFrame', 'requestIdleCallback',
62
+ 'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
63
+ 'localStorage', 'sessionStorage', 'indexedDB', 'crypto', 'performance',
64
+
65
+ // Audio/Video APIs
66
+ 'AudioContext', 'MediaRecorder', 'MediaSource', 'SourceBuffer',
67
+ 'HTMLMediaElement', 'HTMLAudioElement', 'HTMLVideoElement',
68
+
69
+ // Modern JavaScript APIs
70
+ 'structuredClone', 'queueMicrotask', 'reportError',
71
+ 'WeakRef', 'FinalizationRegistry', 'AggregateError',
72
+
73
+ // Intl APIs
74
+ 'Intl', 'DateTimeFormat', 'NumberFormat', 'Collator', 'PluralRules',
75
+ 'RelativeTimeFormat', 'ListFormat', 'Locale'
76
+ ]);
77
+
78
+ canParse(filePath: string): boolean {
79
+ return /\.vue$/.test(filePath);
80
+ }
81
+
82
+ async parseFeatures(content: string, filePath: string): Promise<DetectedFeature[]> {
83
+ const features: DetectedFeature[] = [];
84
+
85
+ try {
86
+ // Lazy load Vue compiler
87
+ const vueCompiler = await LazyLoader.getVueCompiler();
88
+ const { descriptor } = vueCompiler.parse(content, { filename: filePath });
89
+
90
+ // Parse script blocks for JavaScript features
91
+ if (descriptor.script) {
92
+ const scriptFeatures = await this.parseScriptBlock(
93
+ descriptor.script.content,
94
+ descriptor.script.lang || 'js',
95
+ filePath
96
+ );
97
+ features.push(...scriptFeatures);
98
+ }
99
+
100
+ if (descriptor.scriptSetup) {
101
+ const setupFeatures = await this.parseScriptBlock(
102
+ descriptor.scriptSetup.content,
103
+ descriptor.scriptSetup.lang || 'js',
104
+ filePath
105
+ );
106
+ features.push(...setupFeatures);
107
+ }
108
+
109
+ // Parse style blocks for CSS features
110
+ if (descriptor.styles) {
111
+ for (const style of descriptor.styles) {
112
+ const styleFeatures = await this.parseStyleBlock(
113
+ style.content,
114
+ style.lang || 'css',
115
+ filePath
116
+ );
117
+ features.push(...styleFeatures);
118
+ }
119
+ }
120
+
121
+ // Parse template for HTML features (standard elements only)
122
+ if (descriptor.template) {
123
+ const templateFeatures = this.parseTemplateBlock(
124
+ descriptor.template.content,
125
+ filePath
126
+ );
127
+ features.push(...templateFeatures);
128
+ }
129
+
130
+ } catch (error) {
131
+ console.warn(`Warning: Could not parse Vue file ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
132
+ }
133
+
134
+ return features;
135
+ }
136
+
137
+ private async parseScriptBlock(content: string, lang: string, filePath: string): Promise<DetectedFeature[]> {
138
+ const features: DetectedFeature[] = [];
139
+
140
+ try {
141
+ const isTypeScript = lang === 'ts' || lang === 'typescript';
142
+
143
+ // Lazy load Babel dependencies
144
+ const [parser, traverse] = await Promise.all([
145
+ LazyLoader.getBabelParser(),
146
+ LazyLoader.getBabelTraverse()
147
+ ]);
148
+
149
+ const ast = parser.parse(content, {
150
+ sourceType: 'module',
151
+ plugins: [
152
+ 'typescript',
153
+ 'decorators-legacy',
154
+ 'classProperties',
155
+ 'objectRestSpread',
156
+ 'asyncGenerators',
157
+ 'functionBind',
158
+ 'exportDefaultFrom',
159
+ 'exportNamespaceFrom',
160
+ 'dynamicImport',
161
+ 'nullishCoalescingOperator',
162
+ 'optionalChaining',
163
+ 'topLevelAwait'
164
+ ].filter(plugin => isTypeScript || plugin !== 'typescript')
165
+ });
166
+
167
+ traverse(ast, {
168
+ // Extract JavaScript Web APIs
169
+ MemberExpression: (path: any) => {
170
+ const feature = this.extractWebAPIFeature(path.node, path, content);
171
+ if (feature) {
172
+ features.push({ ...feature, file: filePath });
173
+ }
174
+ },
175
+
176
+ // Extract function calls to Web APIs
177
+ CallExpression: (path: any) => {
178
+ const feature = this.extractWebAPICall(path.node, path, content);
179
+ if (feature) {
180
+ features.push({ ...feature, file: filePath });
181
+ }
182
+ },
183
+
184
+ // Extract modern JavaScript syntax features
185
+ OptionalMemberExpression: (path: any) => {
186
+ features.push({
187
+ feature: 'optional-chaining',
188
+ type: 'js',
189
+ context: this.getContext(content, path.node.loc?.start.line || 0),
190
+ line: path.node.loc?.start.line || 0,
191
+ column: path.node.loc?.start.column || 0,
192
+ file: filePath
193
+ });
194
+ },
195
+
196
+ // Nullish coalescing
197
+ LogicalExpression: (path: any) => {
198
+ if (path.node.operator === '??') {
199
+ features.push({
200
+ feature: 'nullish-coalescing',
201
+ type: 'js',
202
+ context: this.getContext(content, path.node.loc?.start.line || 0),
203
+ line: path.node.loc?.start.line || 0,
204
+ column: path.node.loc?.start.column || 0,
205
+ file: filePath
206
+ });
207
+ }
208
+ },
209
+
210
+ // Private class fields
211
+ ClassPrivateProperty: (path: any) => {
212
+ features.push({
213
+ feature: 'private-fields',
214
+ type: 'js',
215
+ context: this.getContext(content, path.node.loc?.start.line || 0),
216
+ line: path.node.loc?.start.line || 0,
217
+ column: path.node.loc?.start.column || 0,
218
+ file: filePath
219
+ });
220
+ },
221
+
222
+ // Top-level await
223
+ AwaitExpression: (path: any) => {
224
+ if (this.isTopLevelAwait(path)) {
225
+ features.push({
226
+ feature: 'top-level-await',
227
+ type: 'js',
228
+ context: this.getContext(content, path.node.loc?.start.line || 0),
229
+ line: path.node.loc?.start.line || 0,
230
+ column: path.node.loc?.start.column || 0,
231
+ file: filePath
232
+ });
233
+ }
234
+ }
235
+ });
236
+
237
+ } catch (error) {
238
+ console.warn(`Warning: Could not parse script block in ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
239
+ }
240
+
241
+ return features;
242
+ }
243
+
244
+ private async parseStyleBlock(content: string, lang: string, filePath: string): Promise<DetectedFeature[]> {
245
+ const features: DetectedFeature[] = [];
246
+
247
+ try {
248
+ // For now, only handle CSS (not SCSS, Less, etc.)
249
+ if (lang === 'css' || !lang) {
250
+ // Lazy load PostCSS
251
+ const postcss = await LazyLoader.getPostCSS();
252
+ const root = postcss.parse(content);
253
+
254
+ root.walkDecls((decl: any) => {
255
+ features.push({
256
+ feature: decl.prop,
257
+ type: 'css',
258
+ context: `${decl.prop}: ${decl.value}`,
259
+ line: decl.source?.start?.line || 0,
260
+ column: decl.source?.start?.column || 0,
261
+ file: filePath
262
+ });
263
+ });
264
+
265
+ root.walkRules((rule: any) => {
266
+ // Extract CSS selectors that might be modern features
267
+ if (rule.selector.includes(':has(') ||
268
+ rule.selector.includes(':is(') ||
269
+ rule.selector.includes(':where(') ||
270
+ rule.selector.includes(':focus-visible')) {
271
+ features.push({
272
+ feature: this.extractSelectorFeature(rule.selector),
273
+ type: 'css',
274
+ context: rule.selector,
275
+ line: rule.source?.start?.line || 0,
276
+ column: rule.source?.start?.column || 0,
277
+ file: filePath
278
+ });
279
+ }
280
+ });
281
+
282
+ root.walkAtRules((atRule: any) => {
283
+ // Extract at-rules like @supports, @container, etc.
284
+ features.push({
285
+ feature: `@${atRule.name}`,
286
+ type: 'css',
287
+ context: `@${atRule.name} ${atRule.params}`,
288
+ line: atRule.source?.start?.line || 0,
289
+ column: atRule.source?.start?.column || 0,
290
+ file: filePath
291
+ });
292
+ });
293
+ }
294
+ } catch (error) {
295
+ console.warn(`Warning: Could not parse style block in ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
296
+ }
297
+
298
+ return features;
299
+ }
300
+
301
+ private parseTemplateBlock(content: string, filePath: string): DetectedFeature[] {
302
+ const features: DetectedFeature[] = [];
303
+
304
+ // Extract standard HTML elements and attributes (ignore Vue directives)
305
+ const htmlElementRegex = /<(\w+)([^>]*)>/g;
306
+ const lines = content.split('\n');
307
+
308
+ lines.forEach((line, index) => {
309
+ let match: RegExpExecArray | null;
310
+ while ((match = htmlElementRegex.exec(line)) !== null) {
311
+ const tagName = match[1];
312
+ const attributes = match[2];
313
+
314
+ // Check for modern HTML elements
315
+ if (tagName && this.isModernHTMLElement(tagName)) {
316
+ features.push({
317
+ feature: tagName,
318
+ type: 'html',
319
+ context: line.trim(),
320
+ line: index + 1,
321
+ column: match.index,
322
+ file: filePath
323
+ });
324
+ }
325
+
326
+ // Check for modern HTML attributes (ignore Vue directives)
327
+ if (attributes) {
328
+ const modernAttrs = this.extractModernAttributes(attributes);
329
+ modernAttrs.forEach(attr => {
330
+ features.push({
331
+ feature: attr,
332
+ type: 'html',
333
+ context: line.trim(),
334
+ line: index + 1,
335
+ column: match!.index,
336
+ file: filePath
337
+ });
338
+ });
339
+ }
340
+ }
341
+ });
342
+
343
+ return features;
344
+ }
345
+
346
+ private extractWebAPIFeature(node: t.MemberExpression, path: any, content: string): DetectedFeature | null {
347
+ const apiName = this.getMemberExpressionName(node);
348
+
349
+ if (!apiName || this.VUE_SPECIFIC_APIS.has(apiName)) {
350
+ return null;
351
+ }
352
+
353
+ if (this.WEB_PLATFORM_APIS.has(apiName)) {
354
+ return {
355
+ feature: apiName,
356
+ type: 'js',
357
+ context: this.getContext(content, node.loc?.start.line || 0),
358
+ line: node.loc?.start.line || 0,
359
+ column: node.loc?.start.column || 0
360
+ };
361
+ }
362
+
363
+ return null;
364
+ }
365
+
366
+ private extractWebAPICall(node: t.CallExpression, path: any, content: string): DetectedFeature | null {
367
+ let apiName = '';
368
+
369
+ if (t.isIdentifier(node.callee)) {
370
+ apiName = node.callee.name;
371
+ } else if (t.isMemberExpression(node.callee)) {
372
+ apiName = this.getMemberExpressionName(node.callee);
373
+ }
374
+
375
+ if (!apiName || this.VUE_SPECIFIC_APIS.has(apiName)) {
376
+ return null;
377
+ }
378
+
379
+ if (this.WEB_PLATFORM_APIS.has(apiName)) {
380
+ return {
381
+ feature: apiName,
382
+ type: 'js',
383
+ context: this.getContext(content, node.loc?.start.line || 0),
384
+ line: node.loc?.start.line || 0,
385
+ column: node.loc?.start.column || 0
386
+ };
387
+ }
388
+
389
+ return null;
390
+ }
391
+
392
+ private getMemberExpressionName(node: t.MemberExpression): string {
393
+ const parts: string[] = [];
394
+
395
+ const traverse = (n: t.Expression): void => {
396
+ if (t.isIdentifier(n)) {
397
+ parts.unshift(n.name);
398
+ } else if (t.isMemberExpression(n)) {
399
+ if (t.isIdentifier(n.property)) {
400
+ parts.unshift(n.property.name);
401
+ }
402
+ traverse(n.object);
403
+ }
404
+ };
405
+
406
+ traverse(node);
407
+ return parts.join('.');
408
+ }
409
+
410
+ private isTopLevelAwait(path: any): boolean {
411
+ let parent = path.parent;
412
+ while (parent) {
413
+ if (t.isFunction(parent) || t.isArrowFunctionExpression(parent)) {
414
+ return false;
415
+ }
416
+ parent = path.parentPath?.parent;
417
+ }
418
+ return true;
419
+ }
420
+
421
+ private extractSelectorFeature(selector: string): string {
422
+ if (selector.includes(':has(')) return ':has()';
423
+ if (selector.includes(':is(')) return ':is()';
424
+ if (selector.includes(':where(')) return ':where()';
425
+ if (selector.includes(':focus-visible')) return ':focus-visible';
426
+ return selector;
427
+ }
428
+
429
+ private isModernHTMLElement(tagName: string): boolean {
430
+ const modernElements = new Set([
431
+ 'dialog', 'details', 'summary', 'main', 'article', 'section', 'nav', 'aside',
432
+ 'header', 'footer', 'figure', 'figcaption', 'time', 'mark', 'progress', 'meter',
433
+ 'canvas', 'video', 'audio', 'source', 'track', 'embed', 'object'
434
+ ]);
435
+ return modernElements.has(tagName);
436
+ }
437
+
438
+ private extractModernAttributes(attributes: string): string[] {
439
+ const modernAttrs: string[] = [];
440
+ const modernAttrPatterns = [
441
+ /loading=["']lazy["']/,
442
+ /decoding=["']async["']/,
443
+ /fetchpriority=["'](high|low)["']/,
444
+ /enterkeyhint=["']\w+["']/,
445
+ /inputmode=["']\w+["']/
446
+ ];
447
+
448
+ modernAttrPatterns.forEach(pattern => {
449
+ if (pattern.test(attributes)) {
450
+ const match = attributes.match(pattern);
451
+ if (match && match[0]) {
452
+ const attrName = match[0].split('=')[0];
453
+ if (attrName) {
454
+ modernAttrs.push(attrName);
455
+ }
456
+ }
457
+ }
458
+ });
459
+
460
+ return modernAttrs;
461
+ }
462
+
463
+ private getContext(content: string, line: number): string {
464
+ const lines = content.split('\n');
465
+ const targetLine = lines[line - 1] || '';
466
+ return targetLine.trim();
467
+ }
468
+
469
+ getSupportedExtensions(): string[] {
470
+ return ['.vue'];
471
+ }
472
+
473
+ getName(): string {
474
+ return 'VueParser';
475
+ }
476
+ }