@fictjs/compiler 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as BabelCore from '@babel/core';
2
+ import { SourceLocation, Node, ClassBody, LVal } from '@babel/types';
2
3
 
3
4
  interface CompilerWarning {
4
5
  code: string;
@@ -146,6 +147,397 @@ declare function resolveModuleMetadata(source: string, importer: string | undefi
146
147
  declare function setModuleMetadata(fileName: string | undefined, metadata: ModuleReactiveMetadata, options?: FictCompilerOptions): void;
147
148
  declare function clearModuleMetadata(options?: FictCompilerOptions): void;
148
149
 
150
+ type TraceMarkerKind = 'once' | 'reactive' | 'effect';
151
+ interface TraceMarker {
152
+ kind: TraceMarkerKind;
153
+ label: string;
154
+ deps?: string[];
155
+ regionId?: number;
156
+ runCount?: number;
157
+ lastDurationMs?: number;
158
+ }
159
+ interface LineTrace {
160
+ line: number;
161
+ markers: TraceMarker[];
162
+ }
163
+ interface RegionInfoSerializable {
164
+ id: number;
165
+ startLine?: number;
166
+ startColumn?: number;
167
+ endLine?: number;
168
+ endColumn?: number;
169
+ dependencies: string[];
170
+ declarations: string[];
171
+ hasControlFlow: boolean;
172
+ hasReactiveWrites: boolean;
173
+ children?: RegionInfoSerializable[];
174
+ }
175
+ interface AnalyzeDiagnostic {
176
+ code: string;
177
+ message: string;
178
+ severity: 'error' | 'warning' | 'info' | 'hint';
179
+ line: number;
180
+ column: number;
181
+ endLine?: number;
182
+ endColumn?: number;
183
+ }
184
+ interface ComponentAnalysis {
185
+ name: string;
186
+ startLine: number;
187
+ endLine: number;
188
+ trace: LineTrace[];
189
+ regions?: RegionInfoSerializable[];
190
+ }
191
+ interface AnalyzeOptions {
192
+ includeRegions?: boolean;
193
+ includeDiagnostics?: boolean;
194
+ verbosity?: 'minimal' | 'verbose';
195
+ compilerOptions?: Partial<FictCompilerOptions>;
196
+ }
197
+ interface AnalyzeResult {
198
+ fileName: string;
199
+ components: ComponentAnalysis[];
200
+ diagnostics: AnalyzeDiagnostic[];
201
+ }
202
+
203
+ declare function analyzeFictFile(code: string, fileName: string, options?: AnalyzeOptions): AnalyzeResult;
204
+
205
+ /**
206
+ * Type alias for class body members from Babel AST.
207
+ */
208
+ type BabelClassMember = ClassBody['body'][number];
209
+ /**
210
+ * Type alias for function parameter nodes from Babel AST.
211
+ * These are preserved for proper props pattern lowering.
212
+ * Includes Identifier, Pattern (ObjectPattern, ArrayPattern), and RestElement.
213
+ */
214
+ type BabelParamNode = Node;
215
+ type BlockId = number;
216
+ interface SourceInfo {
217
+ loc?: SourceLocation | null;
218
+ }
219
+ /** Terminator of a basic block */
220
+ type Terminator = ({
221
+ kind: 'Return';
222
+ argument?: Expression;
223
+ } & SourceInfo) | ({
224
+ kind: 'Throw';
225
+ argument: Expression;
226
+ } & SourceInfo) | ({
227
+ kind: 'Jump';
228
+ target: BlockId;
229
+ } & SourceInfo) | ({
230
+ kind: 'Branch';
231
+ test: Expression;
232
+ consequent: BlockId;
233
+ alternate: BlockId;
234
+ } & SourceInfo) | ({
235
+ kind: 'Switch';
236
+ discriminant: Expression;
237
+ cases: {
238
+ test?: Expression;
239
+ target: BlockId;
240
+ }[];
241
+ } & SourceInfo) | ({
242
+ kind: 'Unreachable';
243
+ } & SourceInfo) | ({
244
+ kind: 'Break';
245
+ target: BlockId;
246
+ label?: string;
247
+ } & SourceInfo) | ({
248
+ kind: 'Continue';
249
+ target: BlockId;
250
+ label?: string;
251
+ } & SourceInfo) | ({
252
+ kind: 'ForOf';
253
+ variable: string;
254
+ /** Variable declaration kind (const, let, var) */
255
+ variableKind: 'const' | 'let' | 'var';
256
+ /** Original pattern for destructuring (stored as Babel AST node) */
257
+ pattern?: LVal;
258
+ iterable: Expression;
259
+ body: BlockId;
260
+ exit: BlockId;
261
+ } & SourceInfo) | ({
262
+ kind: 'ForIn';
263
+ variable: string;
264
+ /** Variable declaration kind (const, let, var) */
265
+ variableKind: 'const' | 'let' | 'var';
266
+ /** Original pattern for destructuring (stored as Babel AST node) */
267
+ pattern?: LVal;
268
+ object: Expression;
269
+ body: BlockId;
270
+ exit: BlockId;
271
+ } & SourceInfo) | ({
272
+ kind: 'Try';
273
+ tryBlock: BlockId;
274
+ catchBlock?: BlockId;
275
+ catchParam?: string;
276
+ finallyBlock?: BlockId;
277
+ exit: BlockId;
278
+ } & SourceInfo);
279
+ /** Instruction interfaces for proper type narrowing */
280
+ interface AssignInstruction extends SourceInfo {
281
+ kind: 'Assign';
282
+ target: Identifier;
283
+ value: Expression;
284
+ declarationKind?: 'const' | 'let' | 'var' | 'function';
285
+ }
286
+ interface ExpressionInstruction extends SourceInfo {
287
+ kind: 'Expression';
288
+ value: Expression;
289
+ }
290
+ interface PhiInstruction extends SourceInfo {
291
+ kind: 'Phi';
292
+ variable: string;
293
+ target: Identifier;
294
+ sources: {
295
+ block: BlockId;
296
+ id: Identifier;
297
+ }[];
298
+ }
299
+ /** A single HIR instruction */
300
+ type Instruction = AssignInstruction | ExpressionInstruction | PhiInstruction;
301
+ /** Minimal expression placeholder; future work will refine variants */
302
+ type Expression = Identifier | Literal | ImportExpression | MetaProperty | CallExpression | MemberExpression | BinaryExpression | UnaryExpression | ConditionalExpression | LogicalExpression | ArrayExpression | ObjectExpression | JSXElementExpression | ArrowFunctionExpression | FunctionExpression | AssignmentExpression | UpdateExpression | TemplateLiteral | SpreadElement | AwaitExpression | NewExpression | SequenceExpression | YieldExpression | OptionalCallExpression | TaggedTemplateExpression | ClassExpression | ThisExpression | SuperExpression | OptionalMemberExpression;
303
+ interface Identifier extends SourceInfo {
304
+ kind: 'Identifier';
305
+ name: string;
306
+ }
307
+ interface Literal extends SourceInfo {
308
+ kind: 'Literal';
309
+ value: string | number | boolean | bigint | null | undefined | RegExp;
310
+ }
311
+ interface ImportExpression extends SourceInfo {
312
+ kind: 'ImportExpression';
313
+ source: Expression;
314
+ }
315
+ interface MetaProperty extends SourceInfo {
316
+ kind: 'MetaProperty';
317
+ meta: Identifier;
318
+ property: Identifier;
319
+ }
320
+ interface CallExpression extends SourceInfo {
321
+ kind: 'CallExpression';
322
+ callee: Expression;
323
+ arguments: Expression[];
324
+ /** Optional purity hint (e.g., from @__PURE__ annotations) */
325
+ pure?: boolean;
326
+ }
327
+ interface MemberExpression extends SourceInfo {
328
+ kind: 'MemberExpression';
329
+ object: Expression;
330
+ property: Expression;
331
+ computed: boolean;
332
+ optional?: boolean;
333
+ }
334
+ interface BinaryExpression extends SourceInfo {
335
+ kind: 'BinaryExpression';
336
+ operator: string;
337
+ left: Expression;
338
+ right: Expression;
339
+ }
340
+ interface UnaryExpression extends SourceInfo {
341
+ kind: 'UnaryExpression';
342
+ operator: string;
343
+ argument: Expression;
344
+ prefix: boolean;
345
+ }
346
+ interface ConditionalExpression extends SourceInfo {
347
+ kind: 'ConditionalExpression';
348
+ test: Expression;
349
+ consequent: Expression;
350
+ alternate: Expression;
351
+ }
352
+ interface LogicalExpression extends SourceInfo {
353
+ kind: 'LogicalExpression';
354
+ operator: '&&' | '||' | '??';
355
+ left: Expression;
356
+ right: Expression;
357
+ }
358
+ interface ArrayExpression extends SourceInfo {
359
+ kind: 'ArrayExpression';
360
+ elements: Expression[];
361
+ }
362
+ interface ObjectProperty extends SourceInfo {
363
+ kind: 'Property';
364
+ key: Expression;
365
+ computed?: boolean;
366
+ value: Expression;
367
+ shorthand?: boolean;
368
+ /**
369
+ * Property kind for object methods/getters/setters.
370
+ * Undefined or 'init' indicates a standard property initializer.
371
+ */
372
+ propertyKind?: 'init' | 'method' | 'get' | 'set';
373
+ }
374
+ interface ObjectExpression extends SourceInfo {
375
+ kind: 'ObjectExpression';
376
+ properties: (ObjectProperty | SpreadElement)[];
377
+ }
378
+ interface JSXElementExpression extends SourceInfo {
379
+ kind: 'JSXElement';
380
+ tagName: string | Expression;
381
+ isComponent: boolean;
382
+ attributes: JSXAttribute[];
383
+ children: JSXChild[];
384
+ }
385
+ interface JSXAttribute extends SourceInfo {
386
+ name: string;
387
+ value: Expression | null;
388
+ isSpread?: boolean;
389
+ spreadExpr?: Expression;
390
+ }
391
+ type JSXChild = {
392
+ kind: 'text';
393
+ value: string;
394
+ loc?: SourceLocation | null;
395
+ } | {
396
+ kind: 'expression';
397
+ value: Expression;
398
+ loc?: SourceLocation | null;
399
+ } | {
400
+ kind: 'element';
401
+ value: JSXElementExpression;
402
+ loc?: SourceLocation | null;
403
+ };
404
+ interface ArrowFunctionExpression extends SourceInfo {
405
+ kind: 'ArrowFunction';
406
+ params: Identifier[];
407
+ /** Original Babel param AST nodes for preserving patterns/rest params */
408
+ rawParams?: BabelParamNode[];
409
+ body: Expression | BasicBlock[];
410
+ isExpression: boolean;
411
+ isAsync?: boolean;
412
+ /** Marks this function as a reactive scope callback (e.g., renderHook(() => ...)). */
413
+ reactiveScope?: string;
414
+ }
415
+ interface FunctionExpression extends SourceInfo {
416
+ kind: 'FunctionExpression';
417
+ name?: string;
418
+ params: Identifier[];
419
+ /** Original Babel param AST nodes for preserving patterns/rest params */
420
+ rawParams?: BabelParamNode[];
421
+ body: BasicBlock[];
422
+ isAsync?: boolean;
423
+ /** Marks this function as a reactive scope callback (e.g., renderHook(() => ...)). */
424
+ reactiveScope?: string;
425
+ }
426
+ interface AssignmentExpression extends SourceInfo {
427
+ kind: 'AssignmentExpression';
428
+ operator: string;
429
+ left: Expression;
430
+ right: Expression;
431
+ }
432
+ interface UpdateExpression extends SourceInfo {
433
+ kind: 'UpdateExpression';
434
+ operator: '++' | '--';
435
+ argument: Expression;
436
+ prefix: boolean;
437
+ }
438
+ interface TemplateLiteral extends SourceInfo {
439
+ kind: 'TemplateLiteral';
440
+ quasis: string[];
441
+ expressions: Expression[];
442
+ }
443
+ interface SpreadElement extends SourceInfo {
444
+ kind: 'SpreadElement';
445
+ argument: Expression;
446
+ }
447
+ interface AwaitExpression extends SourceInfo {
448
+ kind: 'AwaitExpression';
449
+ argument: Expression;
450
+ }
451
+ interface NewExpression extends SourceInfo {
452
+ kind: 'NewExpression';
453
+ callee: Expression;
454
+ arguments: Expression[];
455
+ }
456
+ interface SequenceExpression extends SourceInfo {
457
+ kind: 'SequenceExpression';
458
+ expressions: Expression[];
459
+ }
460
+ interface YieldExpression extends SourceInfo {
461
+ kind: 'YieldExpression';
462
+ argument: Expression | null;
463
+ delegate: boolean;
464
+ }
465
+ interface OptionalCallExpression extends SourceInfo {
466
+ kind: 'OptionalCallExpression';
467
+ callee: Expression;
468
+ arguments: Expression[];
469
+ optional: boolean;
470
+ /** Optional purity hint (e.g., from @__PURE__ annotations) */
471
+ pure?: boolean;
472
+ }
473
+ interface TaggedTemplateExpression extends SourceInfo {
474
+ kind: 'TaggedTemplateExpression';
475
+ tag: Expression;
476
+ quasi: TemplateLiteral;
477
+ }
478
+ interface ClassExpression extends SourceInfo {
479
+ kind: 'ClassExpression';
480
+ name?: string;
481
+ superClass?: Expression;
482
+ /** Class body elements - stored as Babel AST nodes */
483
+ body: BabelClassMember[];
484
+ }
485
+ interface ThisExpression extends SourceInfo {
486
+ kind: 'ThisExpression';
487
+ }
488
+ interface SuperExpression extends SourceInfo {
489
+ kind: 'SuperExpression';
490
+ }
491
+ interface OptionalMemberExpression extends SourceInfo {
492
+ kind: 'OptionalMemberExpression';
493
+ object: Expression;
494
+ property: Expression;
495
+ computed: boolean;
496
+ optional: boolean;
497
+ }
498
+ interface BasicBlock {
499
+ id: BlockId;
500
+ instructions: Instruction[];
501
+ terminator: Terminator;
502
+ }
503
+ interface HIRFunction extends SourceInfo {
504
+ name?: string;
505
+ params: Identifier[];
506
+ blocks: BasicBlock[];
507
+ /** Original Babel param AST nodes for proper props pattern lowering */
508
+ rawParams?: BabelParamNode[];
509
+ /** Optional SSA version map for consumers */
510
+ ssaMap?: Map<string, number>;
511
+ /** Optional metadata about the origin of this function */
512
+ meta?: {
513
+ fromExpression?: boolean;
514
+ isArrow?: boolean;
515
+ hasExpressionBody?: boolean;
516
+ isAsync?: boolean;
517
+ noMemo?: boolean;
518
+ pure?: boolean;
519
+ /**
520
+ * Hook return info parsed from @fictReturn JSDoc annotation.
521
+ * Allows cross-module hook return type declarations.
522
+ */
523
+ hookReturnInfo?: {
524
+ objectProps?: Map<string, 'signal' | 'memo'>;
525
+ arrayProps?: Map<number, 'signal' | 'memo'>;
526
+ directAccessor?: 'signal' | 'memo';
527
+ };
528
+ };
529
+ }
530
+
531
+ interface InferTraceInput {
532
+ fn: HIRFunction;
533
+ sourceLines: string[];
534
+ startLine: number;
535
+ endLine: number;
536
+ verbosity: 'minimal' | 'verbose';
537
+ regions?: RegionInfoSerializable[];
538
+ }
539
+ declare function inferTraceMarkersForComponent(input: InferTraceInput): LineTrace[];
540
+
149
541
  declare const createFictPlugin: (api: object, options: FictCompilerOptions | null | undefined, dirname: string) => BabelCore.PluginObj<BabelCore.PluginPass>;
150
542
 
151
- export { type CompilerWarning, type FictCompilerOptions, type HookReturnInfoSerializable, type ModuleReactiveMetadata, type ReactiveExportKind, clearModuleMetadata, createFictPlugin, createFictPlugin as default, resolveModuleMetadata, setModuleMetadata };
543
+ export { type AnalyzeDiagnostic, type AnalyzeOptions, type AnalyzeResult, type CompilerWarning, type ComponentAnalysis, type FictCompilerOptions, type HookReturnInfoSerializable, type LineTrace, type ModuleReactiveMetadata, type ReactiveExportKind, type RegionInfoSerializable, type TraceMarker, type TraceMarkerKind, analyzeFictFile, clearModuleMetadata, createFictPlugin, createFictPlugin as default, inferTraceMarkersForComponent, resolveModuleMetadata, setModuleMetadata };