baseguard 1.0.3 → 1.0.5
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/.baseguardrc.example.json +63 -63
- package/.eslintrc.json +24 -24
- package/.prettierrc +7 -7
- package/CHANGELOG.md +195 -195
- package/DEPLOYMENT.md +624 -624
- package/DEPLOYMENT_CHECKLIST.md +239 -239
- package/DEPLOYMENT_SUMMARY_v1.0.2.md +202 -202
- package/QUICK_START.md +134 -134
- package/README.md +488 -488
- package/RELEASE_NOTES_v1.0.2.md +434 -434
- package/bin/base.js +627 -627
- package/dist/ai/fix-manager.d.ts.map +1 -1
- package/dist/ai/fix-manager.js +1 -1
- package/dist/ai/fix-manager.js.map +1 -1
- package/dist/ai/gemini-analyzer.d.ts.map +1 -1
- package/dist/ai/gemini-analyzer.js +29 -35
- package/dist/ai/gemini-analyzer.js.map +1 -1
- package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
- package/dist/ai/gemini-code-fixer.js +58 -58
- package/dist/ai/gemini-code-fixer.js.map +1 -1
- package/dist/ai/jules-implementer.d.ts +3 -0
- package/dist/ai/jules-implementer.d.ts.map +1 -1
- package/dist/ai/jules-implementer.js +63 -32
- package/dist/ai/jules-implementer.js.map +1 -1
- package/dist/ai/unified-code-fixer.js.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +1 -1
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/config.js +2 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/fix.d.ts.map +1 -1
- package/dist/commands/fix.js +48 -15
- package/dist/commands/fix.js.map +1 -1
- package/dist/core/api-key-manager.js +2 -2
- package/dist/core/api-key-manager.js.map +1 -1
- package/dist/core/baseguard.d.ts +1 -0
- package/dist/core/baseguard.d.ts.map +1 -1
- package/dist/core/baseguard.js +13 -10
- package/dist/core/baseguard.js.map +1 -1
- package/dist/core/baseline-checker.d.ts.map +1 -1
- package/dist/core/baseline-checker.js +8 -5
- package/dist/core/baseline-checker.js.map +1 -1
- package/dist/core/configuration-recovery.d.ts.map +1 -1
- package/dist/core/configuration-recovery.js +1 -1
- package/dist/core/configuration-recovery.js.map +1 -1
- package/dist/core/debug-logger.d.ts.map +1 -1
- package/dist/core/debug-logger.js +1 -1
- package/dist/core/debug-logger.js.map +1 -1
- package/dist/core/error-handler.d.ts.map +1 -1
- package/dist/core/error-handler.js +2 -1
- package/dist/core/error-handler.js.map +1 -1
- package/dist/core/gitignore-manager.js +5 -5
- package/dist/core/graceful-degradation-manager.d.ts.map +1 -1
- package/dist/core/graceful-degradation-manager.js +16 -16
- package/dist/core/graceful-degradation-manager.js.map +1 -1
- package/dist/core/lazy-loader.d.ts.map +1 -1
- package/dist/core/lazy-loader.js +9 -2
- package/dist/core/lazy-loader.js.map +1 -1
- package/dist/core/memory-manager.d.ts +0 -3
- package/dist/core/memory-manager.d.ts.map +1 -1
- package/dist/core/memory-manager.js.map +1 -1
- package/dist/core/parser-worker.d.ts +2 -0
- package/dist/core/parser-worker.d.ts.map +1 -0
- package/dist/core/parser-worker.js +19 -0
- package/dist/core/parser-worker.js.map +1 -0
- package/dist/core/startup-optimizer.d.ts.map +1 -1
- package/dist/core/startup-optimizer.js +4 -8
- package/dist/core/startup-optimizer.js.map +1 -1
- package/dist/core/system-error-handler.d.ts.map +1 -1
- package/dist/core/system-error-handler.js.map +1 -1
- package/dist/git/automation-engine.d.ts.map +1 -1
- package/dist/git/automation-engine.js +5 -4
- package/dist/git/automation-engine.js.map +1 -1
- package/dist/git/github-manager.d.ts.map +1 -1
- package/dist/git/github-manager.js.map +1 -1
- package/dist/git/hook-manager.js +5 -5
- package/dist/git/hook-manager.js.map +1 -1
- package/dist/parsers/parser-manager.d.ts.map +1 -1
- package/dist/parsers/parser-manager.js +1 -1
- package/dist/parsers/parser-manager.js.map +1 -1
- package/dist/parsers/svelte-parser.js +1 -1
- package/dist/parsers/svelte-parser.js.map +1 -1
- package/dist/parsers/vanilla-parser.d.ts.map +1 -1
- package/dist/parsers/vanilla-parser.js.map +1 -1
- package/dist/parsers/vue-parser.d.ts.map +1 -1
- package/dist/parsers/vue-parser.js.map +1 -1
- package/dist/ui/components.d.ts +1 -1
- package/dist/ui/components.d.ts.map +1 -1
- package/dist/ui/components.js +11 -11
- package/dist/ui/components.js.map +1 -1
- package/dist/ui/terminal-header.js +14 -14
- package/package.json +105 -105
- package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
- package/src/ai/agentkit-orchestrator.ts +533 -533
- package/src/ai/fix-manager.ts +362 -362
- package/src/ai/gemini-analyzer.ts +665 -671
- package/src/ai/gemini-code-fixer.ts +539 -540
- package/src/ai/index.ts +3 -3
- package/src/ai/jules-implementer.ts +504 -460
- package/src/ai/unified-code-fixer.ts +347 -347
- package/src/commands/automation.ts +343 -343
- package/src/commands/check.ts +298 -299
- package/src/commands/config.ts +584 -583
- package/src/commands/fix.ts +269 -238
- package/src/commands/index.ts +6 -6
- package/src/commands/init.ts +155 -155
- package/src/commands/status.ts +306 -306
- package/src/core/api-key-manager.ts +298 -298
- package/src/core/baseguard.ts +757 -756
- package/src/core/baseline-checker.ts +566 -563
- package/src/core/cache-manager.ts +271 -271
- package/src/core/configuration-recovery.ts +672 -673
- package/src/core/configuration.ts +595 -595
- package/src/core/debug-logger.ts +590 -590
- package/src/core/directory-filter.ts +420 -420
- package/src/core/error-handler.ts +518 -517
- package/src/core/file-processor.ts +337 -337
- package/src/core/gitignore-manager.ts +168 -168
- package/src/core/graceful-degradation-manager.ts +596 -596
- package/src/core/index.ts +16 -16
- package/src/core/lazy-loader.ts +317 -307
- package/src/core/memory-manager.ts +290 -295
- package/src/core/parser-worker.ts +33 -0
- package/src/core/startup-optimizer.ts +246 -255
- package/src/core/system-error-handler.ts +755 -756
- package/src/git/automation-engine.ts +361 -361
- package/src/git/github-manager.ts +190 -192
- package/src/git/hook-manager.ts +210 -210
- package/src/git/index.ts +3 -3
- package/src/index.ts +7 -7
- package/src/parsers/feature-validator.ts +558 -558
- package/src/parsers/index.ts +7 -7
- package/src/parsers/parser-manager.ts +418 -419
- package/src/parsers/parser.ts +25 -25
- package/src/parsers/react-parser-optimized.ts +160 -160
- package/src/parsers/react-parser.ts +358 -358
- package/src/parsers/svelte-parser.ts +510 -510
- package/src/parsers/vanilla-parser.ts +685 -686
- package/src/parsers/vue-parser.ts +476 -478
- package/src/types/index.ts +95 -95
- package/src/ui/components.ts +567 -567
- package/src/ui/help.ts +192 -192
- package/src/ui/index.ts +3 -3
- package/src/ui/prompts.ts +680 -680
- package/src/ui/terminal-header.ts +58 -58
- package/test-build.js +40 -40
- package/test-config-commands.js +55 -55
- package/test-header-simple.js +32 -32
- package/test-terminal-header.js +11 -11
- package/test-ui.js +28 -28
- package/tests/e2e/baseguard.e2e.test.ts +515 -515
- package/tests/e2e/cross-platform.e2e.test.ts +419 -419
- package/tests/e2e/git-integration.e2e.test.ts +486 -486
- package/tests/fixtures/react-project/package.json +13 -13
- package/tests/fixtures/react-project/src/App.css +75 -75
- package/tests/fixtures/react-project/src/App.tsx +76 -76
- package/tests/fixtures/svelte-project/package.json +10 -10
- package/tests/fixtures/svelte-project/src/App.svelte +368 -368
- package/tests/fixtures/vanilla-project/index.html +75 -75
- package/tests/fixtures/vanilla-project/script.js +330 -330
- package/tests/fixtures/vanilla-project/styles.css +358 -358
- package/tests/fixtures/vue-project/package.json +11 -11
- package/tests/fixtures/vue-project/src/App.vue +215 -215
- package/tmp-smoke/.baseguard/backups/config-2026-02-19T12-04-11-067Z-auto.json +30 -0
- package/tmp-smoke/src/bad.css +3 -0
- package/tsconfig.json +34 -34
- package/vitest.config.ts +11 -11
- package/dist/terminal-header.d.ts +0 -12
- package/dist/terminal-header.js +0 -45
|
@@ -1,359 +1,359 @@
|
|
|
1
|
-
import { Parser } from './parser.js';
|
|
2
|
-
import type { DetectedFeature } from '../types/index.js';
|
|
3
|
-
import { LazyLoader } from '../core/lazy-loader.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* React/JSX parser using Babel - extracts ALL web platform features
|
|
7
|
-
* while ignoring React-specific APIs
|
|
8
|
-
*/
|
|
9
|
-
export class ReactParser extends Parser {
|
|
10
|
-
private readonly REACT_SPECIFIC_APIS = new Set([
|
|
11
|
-
// React hooks
|
|
12
|
-
'useState', 'useEffect', 'useContext', 'useReducer', 'useCallback', 'useMemo',
|
|
13
|
-
'useRef', 'useImperativeHandle', 'useLayoutEffect', 'useDebugValue',
|
|
14
|
-
'useId', 'useDeferredValue', 'useTransition', 'useSyncExternalStore',
|
|
15
|
-
|
|
16
|
-
// React components and APIs
|
|
17
|
-
'React', 'Component', 'PureComponent', 'Fragment', 'StrictMode',
|
|
18
|
-
'Suspense', 'lazy', 'memo', 'forwardRef', 'createContext', 'createElement',
|
|
19
|
-
'cloneElement', 'isValidElement', 'Children', 'createRef',
|
|
20
|
-
|
|
21
|
-
// React DOM
|
|
22
|
-
'ReactDOM', 'render', 'hydrate', 'unmountComponentAtNode', 'findDOMNode',
|
|
23
|
-
'createPortal', 'flushSync',
|
|
24
|
-
|
|
25
|
-
// JSX elements (these are handled separately)
|
|
26
|
-
'jsx', 'jsxs', '_jsx', '_jsxs'
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
private readonly WEB_PLATFORM_APIS = new Set([
|
|
30
|
-
// Canvas APIs
|
|
31
|
-
'getContext', 'CanvasRenderingContext2D', 'WebGLRenderingContext', 'WebGL2RenderingContext',
|
|
32
|
-
'OffscreenCanvas', 'ImageBitmap', 'createImageBitmap', 'Path2D',
|
|
33
|
-
|
|
34
|
-
// WebRTC APIs
|
|
35
|
-
'RTCPeerConnection', 'RTCDataChannel', 'RTCSessionDescription', 'RTCIceCandidate',
|
|
36
|
-
'getUserMedia', 'getDisplayMedia', 'MediaStream', 'MediaStreamTrack',
|
|
37
|
-
|
|
38
|
-
// WebAssembly
|
|
39
|
-
'WebAssembly', 'instantiate', 'compile', 'validate',
|
|
40
|
-
|
|
41
|
-
// Service Workers & PWA
|
|
42
|
-
'ServiceWorker', 'serviceWorker', 'register', 'Cache', 'caches',
|
|
43
|
-
'PushManager', 'Notification', 'showNotification',
|
|
44
|
-
|
|
45
|
-
// DOM APIs
|
|
46
|
-
'querySelector', 'querySelectorAll', 'getElementById', 'getElementsByClassName',
|
|
47
|
-
'addEventListener', 'removeEventListener', 'dispatchEvent', 'CustomEvent',
|
|
48
|
-
'MutationObserver', 'ResizeObserver', 'IntersectionObserver', 'PerformanceObserver',
|
|
49
|
-
'AbortController', 'AbortSignal', 'FormData', 'URLSearchParams', 'URL',
|
|
50
|
-
'fetch', 'Request', 'Response', 'Headers', 'Blob', 'File', 'FileReader',
|
|
51
|
-
|
|
52
|
-
// Web APIs
|
|
53
|
-
'navigator', 'geolocation', 'permissions', 'clipboard', 'share',
|
|
54
|
-
'requestAnimationFrame', 'cancelAnimationFrame', 'requestIdleCallback',
|
|
55
|
-
'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
|
|
56
|
-
'localStorage', 'sessionStorage', 'indexedDB', 'crypto', 'performance',
|
|
57
|
-
|
|
58
|
-
// Audio/Video APIs
|
|
59
|
-
'AudioContext', 'MediaRecorder', 'MediaSource', 'SourceBuffer',
|
|
60
|
-
'HTMLMediaElement', 'HTMLAudioElement', 'HTMLVideoElement',
|
|
61
|
-
|
|
62
|
-
// Modern JavaScript APIs
|
|
63
|
-
'structuredClone', 'queueMicrotask', 'reportError',
|
|
64
|
-
'WeakRef', 'FinalizationRegistry', 'AggregateError',
|
|
65
|
-
|
|
66
|
-
// Intl APIs
|
|
67
|
-
'Intl', 'DateTimeFormat', 'NumberFormat', 'Collator', 'PluralRules',
|
|
68
|
-
'RelativeTimeFormat', 'ListFormat', 'Locale'
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
private readonly CSS_PROPERTIES = new Set([
|
|
72
|
-
// Container Queries
|
|
73
|
-
'container-type', 'container-name', 'container',
|
|
74
|
-
|
|
75
|
-
// Grid & Flexbox
|
|
76
|
-
'display', 'grid-template-columns', 'grid-template-rows', 'gap', 'grid-gap',
|
|
77
|
-
'flex', 'flex-direction', 'flex-wrap', 'justify-content', 'align-items',
|
|
78
|
-
|
|
79
|
-
// Modern CSS
|
|
80
|
-
'aspect-ratio', 'object-fit', 'object-position', 'backdrop-filter',
|
|
81
|
-
'color-scheme', 'accent-color', 'scroll-behavior', 'scroll-snap-type',
|
|
82
|
-
'overscroll-behavior', 'touch-action', 'user-select',
|
|
83
|
-
|
|
84
|
-
// CSS Custom Properties
|
|
85
|
-
'--', 'var(', 'calc(', 'clamp(', 'min(', 'max(',
|
|
86
|
-
|
|
87
|
-
// Transforms & Animations
|
|
88
|
-
'transform', 'transform-origin', 'perspective', 'backface-visibility',
|
|
89
|
-
'animation', 'transition', 'will-change',
|
|
90
|
-
|
|
91
|
-
// Layout
|
|
92
|
-
'position', 'top', 'right', 'bottom', 'left', 'z-index',
|
|
93
|
-
'width', 'height', 'margin', 'padding', 'border', 'outline'
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
canParse(filePath: string): boolean {
|
|
97
|
-
return /\.(jsx|tsx)$/.test(filePath);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async parseFeatures(content: string, filePath: string): Promise<DetectedFeature[]> {
|
|
101
|
-
const features: DetectedFeature[] = [];
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
// Lazy load Babel dependencies
|
|
105
|
-
const [parser, traverse, types] = await Promise.all([
|
|
106
|
-
LazyLoader.getBabelParser(),
|
|
107
|
-
LazyLoader.getBabelTraverse(),
|
|
108
|
-
import('@babel/types')
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
const t = types.default || types;
|
|
112
|
-
const ast = parser.parse(content, {
|
|
113
|
-
sourceType: 'module',
|
|
114
|
-
plugins: [
|
|
115
|
-
'jsx',
|
|
116
|
-
'typescript',
|
|
117
|
-
'decorators-legacy',
|
|
118
|
-
'classProperties',
|
|
119
|
-
'objectRestSpread',
|
|
120
|
-
'asyncGenerators',
|
|
121
|
-
'functionBind',
|
|
122
|
-
'exportDefaultFrom',
|
|
123
|
-
'exportNamespaceFrom',
|
|
124
|
-
'dynamicImport',
|
|
125
|
-
'nullishCoalescingOperator',
|
|
126
|
-
'optionalChaining',
|
|
127
|
-
'topLevelAwait'
|
|
128
|
-
]
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
traverse(ast, {
|
|
132
|
-
// Extract JavaScript Web APIs
|
|
133
|
-
MemberExpression: (path: any) => {
|
|
134
|
-
const feature = this.extractWebAPIFeature(path.node, content, t);
|
|
135
|
-
if (feature) {
|
|
136
|
-
features.push({
|
|
137
|
-
...feature,
|
|
138
|
-
file: filePath,
|
|
139
|
-
line: path.node.loc?.start.line || 0,
|
|
140
|
-
column: path.node.loc?.start.column || 0
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
// Extract function calls to Web APIs
|
|
146
|
-
CallExpression: (path: any) => {
|
|
147
|
-
const feature = this.extractWebAPICall(path.node, content, t);
|
|
148
|
-
if (feature) {
|
|
149
|
-
features.push({
|
|
150
|
-
...feature,
|
|
151
|
-
file: filePath,
|
|
152
|
-
line: path.node.loc?.start.line || 0,
|
|
153
|
-
column: path.node.loc?.start.column || 0
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
// Extract CSS from inline styles
|
|
159
|
-
ObjectExpression: (path: any) => {
|
|
160
|
-
const cssFeatures = this.extractInlineCSS(path.node, content, t);
|
|
161
|
-
cssFeatures.forEach(feature => {
|
|
162
|
-
features.push({
|
|
163
|
-
...feature,
|
|
164
|
-
file: filePath,
|
|
165
|
-
line: path.node.loc?.start.line || 0,
|
|
166
|
-
column: path.node.loc?.start.column || 0
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
// Extract modern JavaScript syntax features
|
|
172
|
-
OptionalMemberExpression: (path: any) => {
|
|
173
|
-
features.push({
|
|
174
|
-
feature: 'optional-chaining',
|
|
175
|
-
type: 'js',
|
|
176
|
-
context: this.getContext(content, path.node.loc?.start.line || 0),
|
|
177
|
-
line: path.node.loc?.start.line || 0,
|
|
178
|
-
column: path.node.loc?.start.column || 0,
|
|
179
|
-
file: filePath
|
|
180
|
-
});
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
// Nullish coalescing
|
|
184
|
-
LogicalExpression: (path: any) => {
|
|
185
|
-
if (path.node.operator === '??') {
|
|
186
|
-
features.push({
|
|
187
|
-
feature: 'nullish-coalescing',
|
|
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
|
-
|
|
197
|
-
// Private class fields
|
|
198
|
-
ClassPrivateProperty: (path: any) => {
|
|
199
|
-
features.push({
|
|
200
|
-
feature: 'private-fields',
|
|
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
|
-
// Top-level await
|
|
210
|
-
AwaitExpression: (path: any) => {
|
|
211
|
-
if (this.isTopLevelAwait(path, t)) {
|
|
212
|
-
features.push({
|
|
213
|
-
feature: 'top-level-await',
|
|
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
|
-
});
|
|
223
|
-
|
|
224
|
-
} catch (error) {
|
|
225
|
-
console.warn(`Warning: Could not parse ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return features;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private extractWebAPIFeature(node: any, content: string, t: any): DetectedFeature | null {
|
|
232
|
-
const apiName = this.getMemberExpressionName(node, t);
|
|
233
|
-
|
|
234
|
-
if (!apiName || this.REACT_SPECIFIC_APIS.has(apiName)) {
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (this.WEB_PLATFORM_APIS.has(apiName)) {
|
|
239
|
-
return {
|
|
240
|
-
feature: apiName,
|
|
241
|
-
type: 'js',
|
|
242
|
-
context: this.getContext(content, node.loc?.start.line || 0),
|
|
243
|
-
line: node.loc?.start.line || 0,
|
|
244
|
-
column: node.loc?.start.column || 0
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
private extractWebAPICall(node: any, content: string, t: any): DetectedFeature | null {
|
|
252
|
-
let apiName = '';
|
|
253
|
-
|
|
254
|
-
if (t.isIdentifier(node.callee)) {
|
|
255
|
-
apiName = node.callee.name;
|
|
256
|
-
} else if (t.isMemberExpression(node.callee)) {
|
|
257
|
-
apiName = this.getMemberExpressionName(node.callee, t);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (!apiName || this.REACT_SPECIFIC_APIS.has(apiName)) {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (this.WEB_PLATFORM_APIS.has(apiName)) {
|
|
265
|
-
return {
|
|
266
|
-
feature: apiName,
|
|
267
|
-
type: 'js',
|
|
268
|
-
context: this.getContext(content, node.loc?.start.line || 0),
|
|
269
|
-
line: node.loc?.start.line || 0,
|
|
270
|
-
column: node.loc?.start.column || 0
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
private extractInlineCSS(node: any, content: string, t: any): DetectedFeature[] {
|
|
278
|
-
const features: DetectedFeature[] = [];
|
|
279
|
-
|
|
280
|
-
// Check if this is likely a style object (has CSS-like properties)
|
|
281
|
-
const hasStyleProps = node.properties.some((prop: any) => {
|
|
282
|
-
if (t.isObjectProperty(prop) && (t.isIdentifier(prop.key) || t.isStringLiteral(prop.key))) {
|
|
283
|
-
const key = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
284
|
-
return this.CSS_PROPERTIES.has(key) || key.includes('-') || key.startsWith('--');
|
|
285
|
-
}
|
|
286
|
-
return false;
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
if (!hasStyleProps) {
|
|
290
|
-
return features;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
node.properties.forEach((prop: any) => {
|
|
294
|
-
if (t.isObjectProperty(prop)) {
|
|
295
|
-
let key = '';
|
|
296
|
-
if (t.isIdentifier(prop.key)) {
|
|
297
|
-
key = prop.key.name;
|
|
298
|
-
} else if (t.isStringLiteral(prop.key)) {
|
|
299
|
-
key = prop.key.value;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (key && (this.CSS_PROPERTIES.has(key) || key.startsWith('--') || key.includes('-'))) {
|
|
303
|
-
features.push({
|
|
304
|
-
feature: key,
|
|
305
|
-
type: 'css',
|
|
306
|
-
context: this.getContext(content, prop.loc?.start.line || 0),
|
|
307
|
-
line: prop.loc?.start.line || 0,
|
|
308
|
-
column: prop.loc?.start.column || 0
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
return features;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
private getMemberExpressionName(node: any, t: any): string {
|
|
318
|
-
const parts: string[] = [];
|
|
319
|
-
|
|
320
|
-
const traverse = (n: any): void => {
|
|
321
|
-
if (t.isIdentifier(n)) {
|
|
322
|
-
parts.unshift(n.name);
|
|
323
|
-
} else if (t.isMemberExpression(n)) {
|
|
324
|
-
if (t.isIdentifier(n.property)) {
|
|
325
|
-
parts.unshift(n.property.name);
|
|
326
|
-
}
|
|
327
|
-
traverse(n.object);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
traverse(node);
|
|
332
|
-
return parts.join('.');
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
private isTopLevelAwait(path: any, t: any): boolean {
|
|
336
|
-
let currentPath = path.parentPath;
|
|
337
|
-
while (currentPath) {
|
|
338
|
-
if (t.isFunction(currentPath.node) || t.isArrowFunctionExpression(currentPath.node)) {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
currentPath = currentPath.parentPath!;
|
|
342
|
-
}
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
private getContext(content: string, line: number): string {
|
|
347
|
-
const lines = content.split('\n');
|
|
348
|
-
const targetLine = lines[line - 1] || '';
|
|
349
|
-
return targetLine.trim();
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
getSupportedExtensions(): string[] {
|
|
353
|
-
return ['.jsx', '.tsx'];
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
getName(): string {
|
|
357
|
-
return 'ReactParser';
|
|
358
|
-
}
|
|
1
|
+
import { Parser } from './parser.js';
|
|
2
|
+
import type { DetectedFeature } from '../types/index.js';
|
|
3
|
+
import { LazyLoader } from '../core/lazy-loader.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React/JSX parser using Babel - extracts ALL web platform features
|
|
7
|
+
* while ignoring React-specific APIs
|
|
8
|
+
*/
|
|
9
|
+
export class ReactParser extends Parser {
|
|
10
|
+
private readonly REACT_SPECIFIC_APIS = new Set([
|
|
11
|
+
// React hooks
|
|
12
|
+
'useState', 'useEffect', 'useContext', 'useReducer', 'useCallback', 'useMemo',
|
|
13
|
+
'useRef', 'useImperativeHandle', 'useLayoutEffect', 'useDebugValue',
|
|
14
|
+
'useId', 'useDeferredValue', 'useTransition', 'useSyncExternalStore',
|
|
15
|
+
|
|
16
|
+
// React components and APIs
|
|
17
|
+
'React', 'Component', 'PureComponent', 'Fragment', 'StrictMode',
|
|
18
|
+
'Suspense', 'lazy', 'memo', 'forwardRef', 'createContext', 'createElement',
|
|
19
|
+
'cloneElement', 'isValidElement', 'Children', 'createRef',
|
|
20
|
+
|
|
21
|
+
// React DOM
|
|
22
|
+
'ReactDOM', 'render', 'hydrate', 'unmountComponentAtNode', 'findDOMNode',
|
|
23
|
+
'createPortal', 'flushSync',
|
|
24
|
+
|
|
25
|
+
// JSX elements (these are handled separately)
|
|
26
|
+
'jsx', 'jsxs', '_jsx', '_jsxs'
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
private readonly WEB_PLATFORM_APIS = new Set([
|
|
30
|
+
// Canvas APIs
|
|
31
|
+
'getContext', 'CanvasRenderingContext2D', 'WebGLRenderingContext', 'WebGL2RenderingContext',
|
|
32
|
+
'OffscreenCanvas', 'ImageBitmap', 'createImageBitmap', 'Path2D',
|
|
33
|
+
|
|
34
|
+
// WebRTC APIs
|
|
35
|
+
'RTCPeerConnection', 'RTCDataChannel', 'RTCSessionDescription', 'RTCIceCandidate',
|
|
36
|
+
'getUserMedia', 'getDisplayMedia', 'MediaStream', 'MediaStreamTrack',
|
|
37
|
+
|
|
38
|
+
// WebAssembly
|
|
39
|
+
'WebAssembly', 'instantiate', 'compile', 'validate',
|
|
40
|
+
|
|
41
|
+
// Service Workers & PWA
|
|
42
|
+
'ServiceWorker', 'serviceWorker', 'register', 'Cache', 'caches',
|
|
43
|
+
'PushManager', 'Notification', 'showNotification',
|
|
44
|
+
|
|
45
|
+
// DOM APIs
|
|
46
|
+
'querySelector', 'querySelectorAll', 'getElementById', 'getElementsByClassName',
|
|
47
|
+
'addEventListener', 'removeEventListener', 'dispatchEvent', 'CustomEvent',
|
|
48
|
+
'MutationObserver', 'ResizeObserver', 'IntersectionObserver', 'PerformanceObserver',
|
|
49
|
+
'AbortController', 'AbortSignal', 'FormData', 'URLSearchParams', 'URL',
|
|
50
|
+
'fetch', 'Request', 'Response', 'Headers', 'Blob', 'File', 'FileReader',
|
|
51
|
+
|
|
52
|
+
// Web APIs
|
|
53
|
+
'navigator', 'geolocation', 'permissions', 'clipboard', 'share',
|
|
54
|
+
'requestAnimationFrame', 'cancelAnimationFrame', 'requestIdleCallback',
|
|
55
|
+
'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
|
|
56
|
+
'localStorage', 'sessionStorage', 'indexedDB', 'crypto', 'performance',
|
|
57
|
+
|
|
58
|
+
// Audio/Video APIs
|
|
59
|
+
'AudioContext', 'MediaRecorder', 'MediaSource', 'SourceBuffer',
|
|
60
|
+
'HTMLMediaElement', 'HTMLAudioElement', 'HTMLVideoElement',
|
|
61
|
+
|
|
62
|
+
// Modern JavaScript APIs
|
|
63
|
+
'structuredClone', 'queueMicrotask', 'reportError',
|
|
64
|
+
'WeakRef', 'FinalizationRegistry', 'AggregateError',
|
|
65
|
+
|
|
66
|
+
// Intl APIs
|
|
67
|
+
'Intl', 'DateTimeFormat', 'NumberFormat', 'Collator', 'PluralRules',
|
|
68
|
+
'RelativeTimeFormat', 'ListFormat', 'Locale'
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
private readonly CSS_PROPERTIES = new Set([
|
|
72
|
+
// Container Queries
|
|
73
|
+
'container-type', 'container-name', 'container',
|
|
74
|
+
|
|
75
|
+
// Grid & Flexbox
|
|
76
|
+
'display', 'grid-template-columns', 'grid-template-rows', 'gap', 'grid-gap',
|
|
77
|
+
'flex', 'flex-direction', 'flex-wrap', 'justify-content', 'align-items',
|
|
78
|
+
|
|
79
|
+
// Modern CSS
|
|
80
|
+
'aspect-ratio', 'object-fit', 'object-position', 'backdrop-filter',
|
|
81
|
+
'color-scheme', 'accent-color', 'scroll-behavior', 'scroll-snap-type',
|
|
82
|
+
'overscroll-behavior', 'touch-action', 'user-select',
|
|
83
|
+
|
|
84
|
+
// CSS Custom Properties
|
|
85
|
+
'--', 'var(', 'calc(', 'clamp(', 'min(', 'max(',
|
|
86
|
+
|
|
87
|
+
// Transforms & Animations
|
|
88
|
+
'transform', 'transform-origin', 'perspective', 'backface-visibility',
|
|
89
|
+
'animation', 'transition', 'will-change',
|
|
90
|
+
|
|
91
|
+
// Layout
|
|
92
|
+
'position', 'top', 'right', 'bottom', 'left', 'z-index',
|
|
93
|
+
'width', 'height', 'margin', 'padding', 'border', 'outline'
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
canParse(filePath: string): boolean {
|
|
97
|
+
return /\.(jsx|tsx)$/.test(filePath);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async parseFeatures(content: string, filePath: string): Promise<DetectedFeature[]> {
|
|
101
|
+
const features: DetectedFeature[] = [];
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
// Lazy load Babel dependencies
|
|
105
|
+
const [parser, traverse, types] = await Promise.all([
|
|
106
|
+
LazyLoader.getBabelParser(),
|
|
107
|
+
LazyLoader.getBabelTraverse(),
|
|
108
|
+
import('@babel/types')
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
const t = types.default || types;
|
|
112
|
+
const ast = parser.parse(content, {
|
|
113
|
+
sourceType: 'module',
|
|
114
|
+
plugins: [
|
|
115
|
+
'jsx',
|
|
116
|
+
'typescript',
|
|
117
|
+
'decorators-legacy',
|
|
118
|
+
'classProperties',
|
|
119
|
+
'objectRestSpread',
|
|
120
|
+
'asyncGenerators',
|
|
121
|
+
'functionBind',
|
|
122
|
+
'exportDefaultFrom',
|
|
123
|
+
'exportNamespaceFrom',
|
|
124
|
+
'dynamicImport',
|
|
125
|
+
'nullishCoalescingOperator',
|
|
126
|
+
'optionalChaining',
|
|
127
|
+
'topLevelAwait'
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
traverse(ast, {
|
|
132
|
+
// Extract JavaScript Web APIs
|
|
133
|
+
MemberExpression: (path: any) => {
|
|
134
|
+
const feature = this.extractWebAPIFeature(path.node, content, t);
|
|
135
|
+
if (feature) {
|
|
136
|
+
features.push({
|
|
137
|
+
...feature,
|
|
138
|
+
file: filePath,
|
|
139
|
+
line: path.node.loc?.start.line || 0,
|
|
140
|
+
column: path.node.loc?.start.column || 0
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
// Extract function calls to Web APIs
|
|
146
|
+
CallExpression: (path: any) => {
|
|
147
|
+
const feature = this.extractWebAPICall(path.node, content, t);
|
|
148
|
+
if (feature) {
|
|
149
|
+
features.push({
|
|
150
|
+
...feature,
|
|
151
|
+
file: filePath,
|
|
152
|
+
line: path.node.loc?.start.line || 0,
|
|
153
|
+
column: path.node.loc?.start.column || 0
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// Extract CSS from inline styles
|
|
159
|
+
ObjectExpression: (path: any) => {
|
|
160
|
+
const cssFeatures = this.extractInlineCSS(path.node, content, t);
|
|
161
|
+
cssFeatures.forEach(feature => {
|
|
162
|
+
features.push({
|
|
163
|
+
...feature,
|
|
164
|
+
file: filePath,
|
|
165
|
+
line: path.node.loc?.start.line || 0,
|
|
166
|
+
column: path.node.loc?.start.column || 0
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
// Extract modern JavaScript syntax features
|
|
172
|
+
OptionalMemberExpression: (path: any) => {
|
|
173
|
+
features.push({
|
|
174
|
+
feature: 'optional-chaining',
|
|
175
|
+
type: 'js',
|
|
176
|
+
context: this.getContext(content, path.node.loc?.start.line || 0),
|
|
177
|
+
line: path.node.loc?.start.line || 0,
|
|
178
|
+
column: path.node.loc?.start.column || 0,
|
|
179
|
+
file: filePath
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
// Nullish coalescing
|
|
184
|
+
LogicalExpression: (path: any) => {
|
|
185
|
+
if (path.node.operator === '??') {
|
|
186
|
+
features.push({
|
|
187
|
+
feature: 'nullish-coalescing',
|
|
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
|
+
|
|
197
|
+
// Private class fields
|
|
198
|
+
ClassPrivateProperty: (path: any) => {
|
|
199
|
+
features.push({
|
|
200
|
+
feature: 'private-fields',
|
|
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
|
+
// Top-level await
|
|
210
|
+
AwaitExpression: (path: any) => {
|
|
211
|
+
if (this.isTopLevelAwait(path, t)) {
|
|
212
|
+
features.push({
|
|
213
|
+
feature: 'top-level-await',
|
|
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
|
+
});
|
|
223
|
+
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.warn(`Warning: Could not parse ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return features;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private extractWebAPIFeature(node: any, content: string, t: any): DetectedFeature | null {
|
|
232
|
+
const apiName = this.getMemberExpressionName(node, t);
|
|
233
|
+
|
|
234
|
+
if (!apiName || this.REACT_SPECIFIC_APIS.has(apiName)) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (this.WEB_PLATFORM_APIS.has(apiName)) {
|
|
239
|
+
return {
|
|
240
|
+
feature: apiName,
|
|
241
|
+
type: 'js',
|
|
242
|
+
context: this.getContext(content, node.loc?.start.line || 0),
|
|
243
|
+
line: node.loc?.start.line || 0,
|
|
244
|
+
column: node.loc?.start.column || 0
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private extractWebAPICall(node: any, content: string, t: any): DetectedFeature | null {
|
|
252
|
+
let apiName = '';
|
|
253
|
+
|
|
254
|
+
if (t.isIdentifier(node.callee)) {
|
|
255
|
+
apiName = node.callee.name;
|
|
256
|
+
} else if (t.isMemberExpression(node.callee)) {
|
|
257
|
+
apiName = this.getMemberExpressionName(node.callee, t);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (!apiName || this.REACT_SPECIFIC_APIS.has(apiName)) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (this.WEB_PLATFORM_APIS.has(apiName)) {
|
|
265
|
+
return {
|
|
266
|
+
feature: apiName,
|
|
267
|
+
type: 'js',
|
|
268
|
+
context: this.getContext(content, node.loc?.start.line || 0),
|
|
269
|
+
line: node.loc?.start.line || 0,
|
|
270
|
+
column: node.loc?.start.column || 0
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private extractInlineCSS(node: any, content: string, t: any): DetectedFeature[] {
|
|
278
|
+
const features: DetectedFeature[] = [];
|
|
279
|
+
|
|
280
|
+
// Check if this is likely a style object (has CSS-like properties)
|
|
281
|
+
const hasStyleProps = node.properties.some((prop: any) => {
|
|
282
|
+
if (t.isObjectProperty(prop) && (t.isIdentifier(prop.key) || t.isStringLiteral(prop.key))) {
|
|
283
|
+
const key = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
284
|
+
return this.CSS_PROPERTIES.has(key) || key.includes('-') || key.startsWith('--');
|
|
285
|
+
}
|
|
286
|
+
return false;
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
if (!hasStyleProps) {
|
|
290
|
+
return features;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
node.properties.forEach((prop: any) => {
|
|
294
|
+
if (t.isObjectProperty(prop)) {
|
|
295
|
+
let key = '';
|
|
296
|
+
if (t.isIdentifier(prop.key)) {
|
|
297
|
+
key = prop.key.name;
|
|
298
|
+
} else if (t.isStringLiteral(prop.key)) {
|
|
299
|
+
key = prop.key.value;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (key && (this.CSS_PROPERTIES.has(key) || key.startsWith('--') || key.includes('-'))) {
|
|
303
|
+
features.push({
|
|
304
|
+
feature: key,
|
|
305
|
+
type: 'css',
|
|
306
|
+
context: this.getContext(content, prop.loc?.start.line || 0),
|
|
307
|
+
line: prop.loc?.start.line || 0,
|
|
308
|
+
column: prop.loc?.start.column || 0
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
return features;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private getMemberExpressionName(node: any, t: any): string {
|
|
318
|
+
const parts: string[] = [];
|
|
319
|
+
|
|
320
|
+
const traverse = (n: any): void => {
|
|
321
|
+
if (t.isIdentifier(n)) {
|
|
322
|
+
parts.unshift(n.name);
|
|
323
|
+
} else if (t.isMemberExpression(n)) {
|
|
324
|
+
if (t.isIdentifier(n.property)) {
|
|
325
|
+
parts.unshift(n.property.name);
|
|
326
|
+
}
|
|
327
|
+
traverse(n.object);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
traverse(node);
|
|
332
|
+
return parts.join('.');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private isTopLevelAwait(path: any, t: any): boolean {
|
|
336
|
+
let currentPath = path.parentPath;
|
|
337
|
+
while (currentPath) {
|
|
338
|
+
if (t.isFunction(currentPath.node) || t.isArrowFunctionExpression(currentPath.node)) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
currentPath = currentPath.parentPath!;
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private getContext(content: string, line: number): string {
|
|
347
|
+
const lines = content.split('\n');
|
|
348
|
+
const targetLine = lines[line - 1] || '';
|
|
349
|
+
return targetLine.trim();
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
getSupportedExtensions(): string[] {
|
|
353
|
+
return ['.jsx', '.tsx'];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
getName(): string {
|
|
357
|
+
return 'ReactParser';
|
|
358
|
+
}
|
|
359
359
|
}
|