@stillflow/engine 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +156 -3
- package/dist/index.cjs.js +1051 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.es.js +1023 -0
- package/dist/jsx-runtime.d.ts +43 -0
- package/dist/lib-DUuDpiwh.js +11975 -0
- package/dist/lib-lWz8P7iq.cjs +11979 -0
- package/dist/stillflow/abstracts/IR.d.ts +7 -0
- package/dist/stillflow/abstracts/meta.d.ts +8 -0
- package/dist/stillflow/abstracts/operators.d.ts +22 -0
- package/dist/stillflow/abstracts/state.d.ts +13 -0
- package/dist/stillflow/abstracts/view.d.ts +8 -0
- package/dist/stillflow/compiler/compile.d.ts +11 -0
- package/dist/stillflow/compiler/instantiate.d.ts +3 -0
- package/dist/stillflow/factories/factories.d.ts +10 -0
- package/dist/stillflow/index.d.ts +5 -0
- package/dist/stillflow/kernel/buffer.d.ts +10 -0
- package/dist/stillflow/kernel/kernel.d.ts +26 -0
- package/dist/stillflow/kernel/signal.d.ts +5 -0
- package/dist/stillflow/operators.d.ts +15 -0
- package/dist/stillflow/state.d.ts +15 -0
- package/dist/stillflow/stillflow.d.ts +28 -0
- package/dist/stillflow/tools/batcher.d.ts +9 -0
- package/dist/stillflow/variable.d.ts +12 -0
- package/dist/stillflow-collection/abstract/collection.delta.d.ts +10 -0
- package/dist/stillflow-collection/abstract/collection.flusher.d.ts +17 -0
- package/dist/stillflow-collection/abstract/collection.glee.d.ts +28 -0
- package/dist/stillflow-collection/abstract/collection.index.d.ts +9 -0
- package/dist/stillflow-collection/abstract/collection.logical.d.ts +13 -0
- package/dist/stillflow-collection/abstract/collection.physical.d.ts +13 -0
- package/dist/stillflow-collection/abstract/collection.serializable.d.ts +4 -0
- package/dist/stillflow-collection/array.d.ts +21 -0
- package/dist/stillflow-collection/fenwick.d.ts +28 -0
- package/dist/stillflow-collection/flushable.d.ts +38 -0
- package/dist/stillflow-collection/index.d.ts +6 -0
- package/dist/stillflow-collection/utilities/disjointed-set.d.ts +10 -0
- package/dist/stillflow-collection/utilities/fenwick-tree.d.ts +9 -0
- package/dist/stillflow-collection/utilities/index.d.ts +1 -0
- package/dist/stillflow-collection/utilities/interval-merger.d.ts +7 -0
- package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +11 -0
- package/dist/stillflow-runtime/dom.d.ts +5 -0
- package/dist/stillflow-runtime/utilities/delegate-event.d.ts +1 -0
- package/dist/stillflow-runtime/utilities/index.d.ts +3 -0
- package/dist/stillflow-runtime/utilities/reconcile-if.d.ts +10 -0
- package/dist/stillflow-runtime/utilities/reconcile-list.d.ts +8 -0
- package/dist/stillflow-serialize/deserialize.d.ts +2 -0
- package/dist/stillflow-serialize/index.d.ts +2 -0
- package/dist/stillflow-serialize/serialize.d.ts +2 -0
- package/dist/stillflow-serialize/serialized.d.ts +4 -0
- package/dist/stillflow-vite/dom.pass.codegen.d.ts +8 -0
- package/dist/stillflow-vite/dom.pass.transform.d.ts +16 -0
- package/dist/stillflow-vite/dom.target.d.ts +2 -0
- package/dist/stillflow-vite/targets.plugin.d.ts +9 -0
- package/dist/stillflow-vite/vm-abstract/index.d.ts +3 -0
- package/dist/stillflow-vite/vm-abstract/vm.instruction.d.ts +7 -0
- package/dist/stillflow-vite/vm-abstract/vm.options.d.ts +4 -0
- package/dist/stillflow-vite/vm-abstract/vm.target.d.ts +23 -0
- package/dist/stillflow-vite/vm-compiler/bytecode-builder.d.ts +33 -0
- package/dist/stillflow-vite/vm-compiler/codes.d.ts +20 -0
- package/dist/stillflow-vite/vm-compiler/dirty.d.ts +7 -0
- package/dist/stillflow-vite/vm-compiler/fabric.d.ts +9 -0
- package/dist/stillflow-vite/vm-compiler/index.d.ts +8 -0
- package/dist/stillflow-vite/vm-compiler/nodes.d.ts +72 -0
- package/dist/stillflow-vite/vm-compiler/pass.analyze-dirty.d.ts +3 -0
- package/dist/stillflow-vite/vm-compiler/pass.analyze-dynamic.d.ts +2 -0
- package/dist/stillflow-vite/vm-compiler/pass.lowering.d.ts +4 -0
- package/dist/stillflow-vite/vm-compiler/pass.scopes.d.ts +14 -0
- package/dist/stillflow-vite/vm-targets/collect-components.d.ts +8 -0
- package/dist/stillflow-vite/vm-targets/collect-imports.d.ts +3 -0
- package/dist/stillflow-vite/vm-targets/find-component.d.ts +3 -0
- package/dist/targets.index.d.ts +1 -0
- package/dist/vite.cjs.js +261 -0
- package/dist/vite.es.js +260 -0
- package/dist/vite.plugin.d.ts +3 -0
- package/dist/vm.instruction-DPuxu4sV.cjs +9 -0
- package/dist/vm.instruction-oyM-GI-p.js +4 -0
- package/dist/vms.cjs.js +1096 -0
- package/dist/vms.es.js +1095 -0
- package/package.json +99 -5
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Opcode } from './codes';
|
|
2
|
+
import { ChunkId, InternId, SlotId } from './nodes';
|
|
3
|
+
export interface BytecodeChunk {
|
|
4
|
+
readonly id: ChunkId;
|
|
5
|
+
readonly mount: number[];
|
|
6
|
+
readonly patch: number[];
|
|
7
|
+
readonly captures: readonly string[];
|
|
8
|
+
root_slots: SlotId[];
|
|
9
|
+
}
|
|
10
|
+
export declare class Interner<T> {
|
|
11
|
+
private _pool;
|
|
12
|
+
private readonly _table;
|
|
13
|
+
intern(value: T): InternId;
|
|
14
|
+
get(id: InternId): T;
|
|
15
|
+
}
|
|
16
|
+
export declare class BytecodeBuilder {
|
|
17
|
+
readonly chunks: BytecodeChunk[];
|
|
18
|
+
readonly interner: Interner<string>;
|
|
19
|
+
readonly component_chunks: Map<string, ChunkId>;
|
|
20
|
+
readonly is_controller_slot: boolean[];
|
|
21
|
+
root_chunk_id: ChunkId;
|
|
22
|
+
private _active;
|
|
23
|
+
private _slots;
|
|
24
|
+
allocate_slot(): SlotId;
|
|
25
|
+
allocate_chunk(): ChunkId;
|
|
26
|
+
allocate_controller_slot(): SlotId;
|
|
27
|
+
intern(value: string): InternId;
|
|
28
|
+
emit_mount(opcode: Opcode, ...ops: number[]): void;
|
|
29
|
+
emit_patch(opcode: Opcode, ...ops: number[]): void;
|
|
30
|
+
with_chunk(captures: readonly string[], site: () => void): BytecodeChunk;
|
|
31
|
+
fill_chunk(id: ChunkId, captures: readonly string[], site: () => SlotId[]): BytecodeChunk;
|
|
32
|
+
compile_subtree(captures: readonly string[], emit_root: () => SlotId[]): BytecodeChunk;
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const enum Opcode {
|
|
2
|
+
CREATE_ELEMENT = 0,
|
|
3
|
+
SET_STATIC_PROP = 1,
|
|
4
|
+
SET_DYNAMIC_PROP = 2,
|
|
5
|
+
UPDATE_DYNAMIC_PROP = 3,
|
|
6
|
+
CREATE_STATIC_TEXT = 4,
|
|
7
|
+
CREATE_DYNAMIC_TEXT = 5,
|
|
8
|
+
UPDATE_DYNAMIC_TEXT = 6,
|
|
9
|
+
APPEND = 7,
|
|
10
|
+
READ_EXPRESSION = 8,
|
|
11
|
+
FOR = 9,
|
|
12
|
+
MOUNT_CALL = 10,
|
|
13
|
+
PATCH_CALL = 11,
|
|
14
|
+
CREATE_ANCHOR = 12,
|
|
15
|
+
MOUNT_IF = 13,
|
|
16
|
+
PATCH_IF = 14,
|
|
17
|
+
READ_PROP = 15,
|
|
18
|
+
SET_EVENT = 16,
|
|
19
|
+
UPDATE_EVENT_DATA = 17
|
|
20
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExpressionNode } from './nodes';
|
|
2
|
+
export interface DirtyContext {
|
|
3
|
+
readonly variable_masks: Map<string, number>;
|
|
4
|
+
readonly tracked_variables: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function create_dirty_context(variables: Iterable<string>): DirtyContext;
|
|
7
|
+
export declare function compute_expression_mask(expression: ExpressionNode, context: DirtyContext): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CallNode, DelegatedEvent, ElementNode, ExpressionNode, ForNode, IfBranch, IfNode, StillflowNode, TextNode } from './nodes';
|
|
2
|
+
export declare class Fabric {
|
|
3
|
+
static expression(code: string, refs: string[]): ExpressionNode;
|
|
4
|
+
static element(tag: string, static_properties: Record<string, string>, dynamic_properties: Record<string, ExpressionNode>, children: StillflowNode[], delegated_events: Record<string, DelegatedEvent>): ElementNode;
|
|
5
|
+
static text(value: string | ExpressionNode): TextNode;
|
|
6
|
+
static for(select: ExpressionNode, item_name: string, index_name: string, body: StillflowNode[]): ForNode;
|
|
7
|
+
static call(component_name: string, properties: Record<string, ExpressionNode>): CallNode;
|
|
8
|
+
static if(branches: IfBranch[]): IfNode;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { StillflowNode } from './nodes';
|
|
2
|
+
export { Fabric } from './fabric';
|
|
3
|
+
export { SymbolScope } from './pass.scopes';
|
|
4
|
+
export { create_dirty_context } from './dirty';
|
|
5
|
+
export { analyze_dirty } from './pass.analyze-dirty';
|
|
6
|
+
export { analyze_tree } from './pass.analyze-dynamic';
|
|
7
|
+
export { resolve_scopes } from './pass.scopes';
|
|
8
|
+
export { lower_to_bytecode } from './pass.lowering';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DirtyContext } from './dirty';
|
|
2
|
+
type Brand<T, K extends string> = T & {
|
|
3
|
+
readonly __brand: K;
|
|
4
|
+
};
|
|
5
|
+
export type SlotId = Brand<number, 'SlotId'>;
|
|
6
|
+
export type ChunkId = Brand<number, 'ChunkId'>;
|
|
7
|
+
export type InternId = Brand<number, 'InternId'>;
|
|
8
|
+
export declare const as_slot: (n: number) => SlotId;
|
|
9
|
+
export declare const as_chunk: (n: number) => ChunkId;
|
|
10
|
+
export declare const as_intern: (n: number) => InternId;
|
|
11
|
+
export interface DelegatedEvent {
|
|
12
|
+
readonly handler: ExpressionNode;
|
|
13
|
+
readonly data: ExpressionNode;
|
|
14
|
+
}
|
|
15
|
+
export interface ScopeMeta {
|
|
16
|
+
captures: Set<string>;
|
|
17
|
+
}
|
|
18
|
+
export interface AnalysisMeta {
|
|
19
|
+
has_child_chunks: boolean;
|
|
20
|
+
dirty_mask: number;
|
|
21
|
+
is_dynamic: boolean;
|
|
22
|
+
slot?: SlotId;
|
|
23
|
+
}
|
|
24
|
+
export interface BaseNodeMeta {
|
|
25
|
+
scope: ScopeMeta;
|
|
26
|
+
analysis: AnalysisMeta;
|
|
27
|
+
}
|
|
28
|
+
export interface BaseStillflowNode<K extends string> {
|
|
29
|
+
readonly kind: K;
|
|
30
|
+
readonly meta: BaseNodeMeta;
|
|
31
|
+
}
|
|
32
|
+
export declare const create_empty_meta: () => BaseNodeMeta;
|
|
33
|
+
export interface ExpressionNode extends BaseStillflowNode<'Expression'> {
|
|
34
|
+
readonly code: string;
|
|
35
|
+
readonly refs: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
export interface ElementNode extends BaseStillflowNode<'Element'> {
|
|
38
|
+
readonly tag: string;
|
|
39
|
+
readonly static_properties: Record<string, string>;
|
|
40
|
+
readonly dynamic_properties: Record<string, ExpressionNode>;
|
|
41
|
+
readonly children: StillflowNode[];
|
|
42
|
+
delegated_events: Record<string, DelegatedEvent>;
|
|
43
|
+
delegated_events_mask: Record<string, {
|
|
44
|
+
handler: number;
|
|
45
|
+
data: number;
|
|
46
|
+
}>;
|
|
47
|
+
dynamic_properties_mask: Record<string, number>;
|
|
48
|
+
}
|
|
49
|
+
export interface TextNode extends BaseStillflowNode<'Text'> {
|
|
50
|
+
readonly value: string | ExpressionNode;
|
|
51
|
+
readonly is_dynamic: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface ForNode extends BaseStillflowNode<'For'> {
|
|
54
|
+
readonly select: ExpressionNode;
|
|
55
|
+
readonly item_name: string;
|
|
56
|
+
readonly index_name: string;
|
|
57
|
+
readonly body: StillflowNode[];
|
|
58
|
+
dirty_context: DirtyContext;
|
|
59
|
+
}
|
|
60
|
+
export interface CallNode extends BaseStillflowNode<'Call'> {
|
|
61
|
+
readonly component_name: string;
|
|
62
|
+
readonly properties: Record<string, ExpressionNode>;
|
|
63
|
+
}
|
|
64
|
+
export interface IfBranch {
|
|
65
|
+
readonly condition?: ExpressionNode;
|
|
66
|
+
readonly children: StillflowNode[];
|
|
67
|
+
}
|
|
68
|
+
export interface IfNode extends BaseStillflowNode<'If'> {
|
|
69
|
+
readonly branches: IfBranch[];
|
|
70
|
+
}
|
|
71
|
+
export type StillflowNode = ExpressionNode | ElementNode | TextNode | ForNode | CallNode | IfNode;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StillflowNode } from './nodes';
|
|
2
|
+
export declare class SymbolScope {
|
|
3
|
+
readonly parent: SymbolScope | null;
|
|
4
|
+
private _locals;
|
|
5
|
+
private _uses;
|
|
6
|
+
constructor(parent?: SymbolScope | null);
|
|
7
|
+
declare(name: string): void;
|
|
8
|
+
has_own(name: string): boolean;
|
|
9
|
+
is_captured(name: string): boolean;
|
|
10
|
+
mark_used(name: string): boolean;
|
|
11
|
+
is_used(name: string): boolean;
|
|
12
|
+
has(name: string): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function resolve_scopes(node: StillflowNode, scope: SymbolScope): Set<string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NodePath, PluginPass, types } from '@babel/core';
|
|
2
|
+
import { Component } from '../vm-abstract/vm.target';
|
|
3
|
+
export declare function filter_parameters(nodes: types.FunctionParameter[]): {
|
|
4
|
+
ids: string[];
|
|
5
|
+
defaults: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
export declare function get_return_argument(node: types.FunctionExpression | types.ArrowFunctionExpression | types.FunctionDeclaration): types.Node;
|
|
8
|
+
export declare function collect_components(program_path: NodePath<types.Program>, state: PluginPass): Map<string, Component>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { target_dom as dom } from './stillflow-vite/dom.target';
|
package/dist/vite.cjs.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _babel_core = require("@babel/core");
|
|
3
|
+
// src/stillflow-vite/vm-targets/collect-components.ts
|
|
4
|
+
function get_function_body(node) {
|
|
5
|
+
const body = node.body;
|
|
6
|
+
if (_babel_core.types.isBlockStatement(body)) return body.body;
|
|
7
|
+
return [_babel_core.types.toBlock(body)];
|
|
8
|
+
}
|
|
9
|
+
function filter_parameters(nodes) {
|
|
10
|
+
const params = [];
|
|
11
|
+
const defaults = {};
|
|
12
|
+
for (const param of nodes) if (_babel_core.types.isIdentifier(param)) params.push(param.name);
|
|
13
|
+
else if (_babel_core.types.isAssignmentPattern(param)) {
|
|
14
|
+
if (_babel_core.types.isIdentifier(param.left)) defaults[param.left.name] = (0, _babel_core.generate)(param.right).code;
|
|
15
|
+
else throw new Error(`Identifier expected at ${param.loc.filename} ${param.loc.start.line}:${param.loc.start.column}`);
|
|
16
|
+
} else throw new Error(`Identifier or assignment pattern expected at ${param.loc.filename} ${param.loc.start.line}:${param.loc.start.column}`);
|
|
17
|
+
return {
|
|
18
|
+
ids: params,
|
|
19
|
+
defaults
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function get_return_argument(node) {
|
|
23
|
+
const statement = get_function_body(node).find((statement) => _babel_core.types.isReturnStatement(statement));
|
|
24
|
+
if (!statement || !statement.argument) {
|
|
25
|
+
if (_babel_core.types.isArrowFunctionExpression(node)) return node.body;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return statement.argument;
|
|
29
|
+
}
|
|
30
|
+
function collect_components(program_path, state) {
|
|
31
|
+
const components = /* @__PURE__ */ new Map();
|
|
32
|
+
const filename = state.filename || "unknown";
|
|
33
|
+
program_path.traverse({
|
|
34
|
+
FunctionDeclaration(path) {
|
|
35
|
+
if (!path.node.id) return;
|
|
36
|
+
const argument = get_return_argument(path.node);
|
|
37
|
+
if (!_babel_core.types.isJSXElement(argument)) return;
|
|
38
|
+
components.set(path.node.id.name, {
|
|
39
|
+
node: path.node,
|
|
40
|
+
parameters: filter_parameters(path.node.params),
|
|
41
|
+
body: argument,
|
|
42
|
+
filename,
|
|
43
|
+
scope: path.scope
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
VariableDeclarator(path) {
|
|
47
|
+
if (!_babel_core.types.isIdentifier(path.node.id)) return;
|
|
48
|
+
if (!(_babel_core.types.isFunctionExpression(path.node.init) || _babel_core.types.isArrowFunctionExpression(path.node.init))) return;
|
|
49
|
+
const initializer = path.node.init;
|
|
50
|
+
const argument = get_return_argument(initializer);
|
|
51
|
+
if (!_babel_core.types.isJSXElement(argument)) return;
|
|
52
|
+
components.set(path.node.id.name, {
|
|
53
|
+
node: initializer,
|
|
54
|
+
parameters: filter_parameters(initializer.params),
|
|
55
|
+
body: argument,
|
|
56
|
+
filename,
|
|
57
|
+
scope: path.scope
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return components;
|
|
62
|
+
}
|
|
63
|
+
// src/stillflow-vite/vm-targets/collect-imports.ts
|
|
64
|
+
function collect_imports(program_path) {
|
|
65
|
+
const imports = /* @__PURE__ */ new Map();
|
|
66
|
+
program_path.traverse({ ImportDeclaration(path) {
|
|
67
|
+
const source = path.node.source.value;
|
|
68
|
+
for (const specifier of path.node.specifiers) if (_babel_core.types.isImportDefaultSpecifier(specifier)) imports.set(specifier.local.name, {
|
|
69
|
+
source,
|
|
70
|
+
imported_name: "default",
|
|
71
|
+
is_default: true
|
|
72
|
+
});
|
|
73
|
+
else if (_babel_core.types.isImportSpecifier(specifier)) imports.set(specifier.local.name, {
|
|
74
|
+
source,
|
|
75
|
+
imported_name: _babel_core.types.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value,
|
|
76
|
+
is_default: false
|
|
77
|
+
});
|
|
78
|
+
else if (_babel_core.types.isImportNamespaceSpecifier(specifier)) throw new Error(`Does not support import namespaces`);
|
|
79
|
+
} });
|
|
80
|
+
return imports;
|
|
81
|
+
}
|
|
82
|
+
// src/stillflow-vite/vm-targets/find-component.ts
|
|
83
|
+
function find_component(ast, name, filename) {
|
|
84
|
+
let result = null;
|
|
85
|
+
_babel_core.types.traverseFast(ast, (node) => {
|
|
86
|
+
if (result) return;
|
|
87
|
+
if (_babel_core.types.isExportDefaultDeclaration(node)) {
|
|
88
|
+
const declaration = node.declaration;
|
|
89
|
+
if (_babel_core.types.isFunctionDeclaration(declaration)) {
|
|
90
|
+
if (declaration.id) {
|
|
91
|
+
const argument = get_return_argument(declaration);
|
|
92
|
+
if (_babel_core.types.isJSXElement(argument)) result = {
|
|
93
|
+
node: declaration,
|
|
94
|
+
parameters: filter_parameters(declaration.params),
|
|
95
|
+
body: argument,
|
|
96
|
+
filename,
|
|
97
|
+
scope: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
} else if (_babel_core.types.isArrowFunctionExpression(declaration)) {
|
|
101
|
+
const argument = get_return_argument(declaration);
|
|
102
|
+
if (_babel_core.types.isJSXElement(argument)) result = {
|
|
103
|
+
node: declaration,
|
|
104
|
+
parameters: filter_parameters(declaration.params),
|
|
105
|
+
body: argument,
|
|
106
|
+
filename,
|
|
107
|
+
scope: null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (_babel_core.types.isExportNamedDeclaration(node)) {
|
|
112
|
+
const declaration = node.declaration;
|
|
113
|
+
if (_babel_core.types.isFunctionDeclaration(declaration)) {
|
|
114
|
+
if (declaration.id?.name === name) {
|
|
115
|
+
const argument = get_return_argument(declaration);
|
|
116
|
+
if (_babel_core.types.isJSXElement(argument)) result = {
|
|
117
|
+
node: declaration,
|
|
118
|
+
parameters: filter_parameters(declaration.params),
|
|
119
|
+
body: argument,
|
|
120
|
+
filename,
|
|
121
|
+
scope: null
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (_babel_core.types.isVariableDeclaration(declaration)) declaration.declarations.forEach((declaration) => {
|
|
126
|
+
if (result) return;
|
|
127
|
+
const id = declaration.id;
|
|
128
|
+
if (_babel_core.types.isIdentifier(id)) {
|
|
129
|
+
if (name === id.name) {
|
|
130
|
+
const init = declaration.init;
|
|
131
|
+
if (_babel_core.types.isArrowFunctionExpression(init) || _babel_core.types.isFunctionExpression(init)) {
|
|
132
|
+
const argument = get_return_argument(init);
|
|
133
|
+
if (_babel_core.types.isJSXElement(argument)) result = {
|
|
134
|
+
node: init,
|
|
135
|
+
parameters: filter_parameters(init.params),
|
|
136
|
+
body: argument,
|
|
137
|
+
filename,
|
|
138
|
+
scope: null
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
// src/stillflow-vite/targets.plugin.ts
|
|
149
|
+
function StillflowTargets({ node_module, path, babel, fs, parser }, options) {
|
|
150
|
+
const { existsSync, readFileSync, statSync } = fs;
|
|
151
|
+
const { types } = babel;
|
|
152
|
+
const { parse } = parser;
|
|
153
|
+
const { createRequire } = node_module;
|
|
154
|
+
const require$1 = createRequire({}.url);
|
|
155
|
+
function resolve_import(source, filename) {
|
|
156
|
+
try {
|
|
157
|
+
return require$1.resolve(source, { paths: [path.dirname(filename)] });
|
|
158
|
+
} catch (error) {
|
|
159
|
+
const base = path.resolve(path.dirname(filename), source);
|
|
160
|
+
const extensions = [
|
|
161
|
+
".ts",
|
|
162
|
+
".tsx",
|
|
163
|
+
".jsx",
|
|
164
|
+
".js"
|
|
165
|
+
];
|
|
166
|
+
for (const extension of extensions) {
|
|
167
|
+
const fullname = base + extension;
|
|
168
|
+
if (existsSync(fullname)) return fullname;
|
|
169
|
+
}
|
|
170
|
+
if (existsSync(base) && statSync(base).isDirectory()) for (const extension of extensions) {
|
|
171
|
+
const fullname = path.join(base, `index${extension}`);
|
|
172
|
+
if (existsSync(fullname)) return fullname;
|
|
173
|
+
}
|
|
174
|
+
return error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return function StillflowTarget() {
|
|
178
|
+
return {
|
|
179
|
+
name: "stillflow-aot",
|
|
180
|
+
visitor: { Program: { enter(program_path, state) {
|
|
181
|
+
const components = collect_components(program_path, state);
|
|
182
|
+
const imports = collect_imports(program_path);
|
|
183
|
+
const filename = state.filename || "unknown";
|
|
184
|
+
for (const [local_name, import_info] of imports) {
|
|
185
|
+
if (components.has(local_name)) continue;
|
|
186
|
+
const resolved_import = resolve_import(import_info.source, filename);
|
|
187
|
+
if (resolved_import instanceof Error) {
|
|
188
|
+
console.error(`[stillflow] Could not import file "${import_info.source}: "`, resolved_import);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const source = readFileSync(resolved_import, "utf-8");
|
|
192
|
+
const ast = parse(source, {
|
|
193
|
+
sourceType: "module",
|
|
194
|
+
plugins: ["jsx", "typescript"]
|
|
195
|
+
});
|
|
196
|
+
if (ast == null) {
|
|
197
|
+
console.warn(`[stillflow] File is not found: ${resolved_import}`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const component = find_component(ast, import_info.imported_name, resolved_import);
|
|
201
|
+
if (component) components.set(local_name, component);
|
|
202
|
+
}
|
|
203
|
+
const jsx_elements = [];
|
|
204
|
+
program_path.traverse({ CallExpression(path) {
|
|
205
|
+
if (!types.isIdentifier(path.node.callee, { name: "$" })) return;
|
|
206
|
+
const argument = path.node.arguments;
|
|
207
|
+
if (argument.length !== 1) return;
|
|
208
|
+
if (!types.isJSXElement(argument[0])) return;
|
|
209
|
+
const jsx_path = path.get("arguments.0");
|
|
210
|
+
jsx_elements.push(jsx_path);
|
|
211
|
+
} });
|
|
212
|
+
for (const jsx_path of jsx_elements.reverse()) try {
|
|
213
|
+
const call_path = jsx_path.parentPath;
|
|
214
|
+
const program = options.targets[0].main(jsx_path.node, components);
|
|
215
|
+
if (!types.isCallExpression(call_path.node)) continue;
|
|
216
|
+
const functional_module = types.functionExpression(null, [types.identifier("$parent")], types.blockStatement(program.body));
|
|
217
|
+
if (program.module.length > 0) program_path.unshiftContainer("body", program.module);
|
|
218
|
+
call_path.replaceWith(functional_module);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.error(`[stillflow] Failed to compile JSX in ${state.filename}: `, error);
|
|
221
|
+
}
|
|
222
|
+
program_path.traverse({ JSXElement(path) {
|
|
223
|
+
path.replaceWith(types.nullLiteral());
|
|
224
|
+
} });
|
|
225
|
+
} } }
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// src/vite.plugin.ts
|
|
230
|
+
function stillflow_plugin(options) {
|
|
231
|
+
return {
|
|
232
|
+
name: "vite-plugin-stillflow",
|
|
233
|
+
enforce: "pre",
|
|
234
|
+
async transform(code, id) {
|
|
235
|
+
if (!(id.endsWith(".tsx") || id.endsWith(".jsx"))) return;
|
|
236
|
+
const node_module = await new Function("return import('node:module')")();
|
|
237
|
+
const parser = await Promise.resolve().then(() => require("./lib-lWz8P7iq.cjs"));
|
|
238
|
+
const babel = await import("@babel/core");
|
|
239
|
+
const path = await new Function("return import('node:path')")();
|
|
240
|
+
const fs = await new Function("return import('node:fs')")();
|
|
241
|
+
const result = await (0, _babel_core.transformAsync)(code, {
|
|
242
|
+
filename: id,
|
|
243
|
+
plugins: [StillflowTargets({
|
|
244
|
+
node_module,
|
|
245
|
+
babel,
|
|
246
|
+
parser,
|
|
247
|
+
path,
|
|
248
|
+
fs
|
|
249
|
+
}, options)],
|
|
250
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
251
|
+
babelrc: false,
|
|
252
|
+
configFile: false
|
|
253
|
+
});
|
|
254
|
+
return {
|
|
255
|
+
code: result?.code ?? code,
|
|
256
|
+
map: result?.map
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
exports.stillflow_plugin = stillflow_plugin;
|