@vue-jsx-vapor/compiler 0.0.2 → 0.1.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.cjs +85 -145
- package/dist/index.d.cts +368 -0
- package/dist/index.d.ts +368 -0
- package/dist/index.js +84 -144
- package/package.json +1 -1
package/dist/index.d.cts
ADDED
@@ -0,0 +1,368 @@
|
|
1
|
+
import { IRFor as IRFor$1, VaporCodegenResult as VaporCodegenResult$1 } from '@vue/compiler-vapor';
|
2
|
+
export { generate } from '@vue/compiler-vapor';
|
3
|
+
import { SimpleExpressionNode, BindingTypes, DirectiveNode, CompoundExpressionNode, TransformOptions as TransformOptions$1, CompilerCompatOptions, CommentNode, CompilerOptions as CompilerOptions$1, ElementNode } from '@vue/compiler-dom';
|
4
|
+
import * as _vue_runtime_vapor from '@vue/runtime-vapor';
|
5
|
+
import { JSXFragment, Node, JSXAttribute, JSXElement, Program } from '@babel/types';
|
6
|
+
import { Prettify } from '@vue/shared';
|
7
|
+
|
8
|
+
interface IRProp extends Omit<DirectiveTransformResult, 'value'> {
|
9
|
+
values: SimpleExpressionNode[];
|
10
|
+
}
|
11
|
+
declare enum IRDynamicPropsKind {
|
12
|
+
EXPRESSION = 0,// v-bind="value"
|
13
|
+
ATTRIBUTE = 1
|
14
|
+
}
|
15
|
+
type IRPropsStatic = IRProp[];
|
16
|
+
interface IRPropsDynamicExpression {
|
17
|
+
kind: IRDynamicPropsKind.EXPRESSION;
|
18
|
+
value: SimpleExpressionNode;
|
19
|
+
handler?: boolean;
|
20
|
+
}
|
21
|
+
interface IRPropsDynamicAttribute extends IRProp {
|
22
|
+
kind: IRDynamicPropsKind.ATTRIBUTE;
|
23
|
+
}
|
24
|
+
type IRProps = IRPropsStatic | IRPropsDynamicAttribute | IRPropsDynamicExpression;
|
25
|
+
interface SlotBlockIRNode extends BlockIRNode {
|
26
|
+
props?: SimpleExpressionNode;
|
27
|
+
}
|
28
|
+
declare enum IRSlotType {
|
29
|
+
STATIC = 0,
|
30
|
+
DYNAMIC = 1,
|
31
|
+
LOOP = 2,
|
32
|
+
CONDITIONAL = 3,
|
33
|
+
EXPRESSION = 4
|
34
|
+
}
|
35
|
+
interface IRSlotsStatic {
|
36
|
+
slotType: IRSlotType.STATIC;
|
37
|
+
slots: Record<string, SlotBlockIRNode>;
|
38
|
+
}
|
39
|
+
interface IRSlotDynamicBasic {
|
40
|
+
slotType: IRSlotType.DYNAMIC;
|
41
|
+
name: SimpleExpressionNode;
|
42
|
+
fn: SlotBlockIRNode;
|
43
|
+
}
|
44
|
+
interface IRSlotDynamicLoop {
|
45
|
+
slotType: IRSlotType.LOOP;
|
46
|
+
name: SimpleExpressionNode;
|
47
|
+
fn: SlotBlockIRNode;
|
48
|
+
loop: IRFor$1;
|
49
|
+
}
|
50
|
+
interface IRSlotDynamicConditional {
|
51
|
+
slotType: IRSlotType.CONDITIONAL;
|
52
|
+
condition: SimpleExpressionNode;
|
53
|
+
positive: IRSlotDynamicBasic;
|
54
|
+
negative?: IRSlotDynamicBasic | IRSlotDynamicConditional;
|
55
|
+
}
|
56
|
+
interface IRSlotsExpression {
|
57
|
+
slotType: IRSlotType.EXPRESSION;
|
58
|
+
slots: SimpleExpressionNode;
|
59
|
+
}
|
60
|
+
type IRSlotDynamic = IRSlotDynamicBasic | IRSlotDynamicLoop | IRSlotDynamicConditional;
|
61
|
+
type IRSlots = IRSlotsStatic | IRSlotDynamic | IRSlotsExpression;
|
62
|
+
|
63
|
+
declare enum IRNodeTypes {
|
64
|
+
ROOT = 0,
|
65
|
+
BLOCK = 1,
|
66
|
+
SET_PROP = 2,
|
67
|
+
SET_DYNAMIC_PROPS = 3,
|
68
|
+
SET_TEXT = 4,
|
69
|
+
SET_EVENT = 5,
|
70
|
+
SET_DYNAMIC_EVENTS = 6,
|
71
|
+
SET_HTML = 7,
|
72
|
+
SET_TEMPLATE_REF = 8,
|
73
|
+
SET_MODEL_VALUE = 9,
|
74
|
+
SET_INHERIT_ATTRS = 10,
|
75
|
+
INSERT_NODE = 11,
|
76
|
+
PREPEND_NODE = 12,
|
77
|
+
CREATE_TEXT_NODE = 13,
|
78
|
+
CREATE_COMPONENT_NODE = 14,
|
79
|
+
SLOT_OUTLET_NODE = 15,
|
80
|
+
WITH_DIRECTIVE = 16,
|
81
|
+
DECLARE_OLD_REF = 17,// consider make it more general
|
82
|
+
IF = 18,
|
83
|
+
FOR = 19
|
84
|
+
}
|
85
|
+
interface BaseIRNode {
|
86
|
+
type: IRNodeTypes;
|
87
|
+
}
|
88
|
+
type VaporHelper = keyof typeof _vue_runtime_vapor;
|
89
|
+
interface RootNode {
|
90
|
+
type: IRNodeTypes.ROOT;
|
91
|
+
source: string;
|
92
|
+
children: JSXFragment['children'];
|
93
|
+
helpers: Set<symbol>;
|
94
|
+
components: string[];
|
95
|
+
directives: string[];
|
96
|
+
temps: number;
|
97
|
+
ssrHelpers?: symbol[];
|
98
|
+
transformed?: boolean;
|
99
|
+
}
|
100
|
+
interface BlockIRNode extends BaseIRNode {
|
101
|
+
type: IRNodeTypes.BLOCK;
|
102
|
+
node: RootNode | Node;
|
103
|
+
dynamic: IRDynamicInfo;
|
104
|
+
effect: IREffect[];
|
105
|
+
operation: OperationNode[];
|
106
|
+
returns: number[];
|
107
|
+
}
|
108
|
+
interface RootIRNode {
|
109
|
+
type: IRNodeTypes.ROOT;
|
110
|
+
node: RootNode;
|
111
|
+
source: string;
|
112
|
+
template: string[];
|
113
|
+
component: Set<string>;
|
114
|
+
directive: Set<string>;
|
115
|
+
block: BlockIRNode;
|
116
|
+
}
|
117
|
+
interface IfIRNode extends BaseIRNode {
|
118
|
+
type: IRNodeTypes.IF;
|
119
|
+
id: number;
|
120
|
+
condition: SimpleExpressionNode;
|
121
|
+
positive: BlockIRNode;
|
122
|
+
negative?: BlockIRNode | IfIRNode;
|
123
|
+
once?: boolean;
|
124
|
+
}
|
125
|
+
interface IRFor {
|
126
|
+
source: SimpleExpressionNode;
|
127
|
+
value?: SimpleExpressionNode;
|
128
|
+
key?: SimpleExpressionNode;
|
129
|
+
index?: SimpleExpressionNode;
|
130
|
+
}
|
131
|
+
interface ForIRNode extends BaseIRNode, IRFor {
|
132
|
+
type: IRNodeTypes.FOR;
|
133
|
+
id: number;
|
134
|
+
keyProp?: SimpleExpressionNode;
|
135
|
+
render: BlockIRNode;
|
136
|
+
once: boolean;
|
137
|
+
container?: number;
|
138
|
+
}
|
139
|
+
interface SetPropIRNode extends BaseIRNode {
|
140
|
+
type: IRNodeTypes.SET_PROP;
|
141
|
+
element: number;
|
142
|
+
prop: IRProp;
|
143
|
+
root: boolean;
|
144
|
+
tag: string;
|
145
|
+
}
|
146
|
+
interface SetDynamicPropsIRNode extends BaseIRNode {
|
147
|
+
type: IRNodeTypes.SET_DYNAMIC_PROPS;
|
148
|
+
element: number;
|
149
|
+
props: IRProps[];
|
150
|
+
root: boolean;
|
151
|
+
}
|
152
|
+
interface SetDynamicEventsIRNode extends BaseIRNode {
|
153
|
+
type: IRNodeTypes.SET_DYNAMIC_EVENTS;
|
154
|
+
element: number;
|
155
|
+
event: SimpleExpressionNode;
|
156
|
+
}
|
157
|
+
interface SetTextIRNode extends BaseIRNode {
|
158
|
+
type: IRNodeTypes.SET_TEXT;
|
159
|
+
element: number;
|
160
|
+
values: SimpleExpressionNode[];
|
161
|
+
}
|
162
|
+
type KeyOverride = [find: string, replacement: string];
|
163
|
+
interface SetEventIRNode extends BaseIRNode {
|
164
|
+
type: IRNodeTypes.SET_EVENT;
|
165
|
+
element: number;
|
166
|
+
key: SimpleExpressionNode;
|
167
|
+
value?: SimpleExpressionNode;
|
168
|
+
modifiers: {
|
169
|
+
options: string[];
|
170
|
+
keys: string[];
|
171
|
+
nonKeys: string[];
|
172
|
+
};
|
173
|
+
keyOverride?: KeyOverride;
|
174
|
+
delegate: boolean;
|
175
|
+
/** Whether it's in effect */
|
176
|
+
effect: boolean;
|
177
|
+
}
|
178
|
+
interface SetHtmlIRNode extends BaseIRNode {
|
179
|
+
type: IRNodeTypes.SET_HTML;
|
180
|
+
element: number;
|
181
|
+
value: SimpleExpressionNode;
|
182
|
+
}
|
183
|
+
interface SetTemplateRefIRNode extends BaseIRNode {
|
184
|
+
type: IRNodeTypes.SET_TEMPLATE_REF;
|
185
|
+
element: number;
|
186
|
+
value: SimpleExpressionNode;
|
187
|
+
refFor: boolean;
|
188
|
+
effect: boolean;
|
189
|
+
}
|
190
|
+
interface SetModelValueIRNode extends BaseIRNode {
|
191
|
+
type: IRNodeTypes.SET_MODEL_VALUE;
|
192
|
+
element: number;
|
193
|
+
key: SimpleExpressionNode;
|
194
|
+
value: SimpleExpressionNode;
|
195
|
+
bindingType?: BindingTypes;
|
196
|
+
isComponent: boolean;
|
197
|
+
}
|
198
|
+
interface SetInheritAttrsIRNode extends BaseIRNode {
|
199
|
+
type: IRNodeTypes.SET_INHERIT_ATTRS;
|
200
|
+
staticProps: boolean;
|
201
|
+
dynamicProps: true | string[];
|
202
|
+
}
|
203
|
+
interface CreateTextNodeIRNode extends BaseIRNode {
|
204
|
+
type: IRNodeTypes.CREATE_TEXT_NODE;
|
205
|
+
id: number;
|
206
|
+
values: SimpleExpressionNode[];
|
207
|
+
effect: boolean;
|
208
|
+
}
|
209
|
+
interface InsertNodeIRNode extends BaseIRNode {
|
210
|
+
type: IRNodeTypes.INSERT_NODE;
|
211
|
+
elements: number[];
|
212
|
+
parent: number;
|
213
|
+
anchor?: number;
|
214
|
+
}
|
215
|
+
interface PrependNodeIRNode extends BaseIRNode {
|
216
|
+
type: IRNodeTypes.PREPEND_NODE;
|
217
|
+
elements: number[];
|
218
|
+
parent: number;
|
219
|
+
}
|
220
|
+
interface WithDirectiveIRNode extends BaseIRNode {
|
221
|
+
type: IRNodeTypes.WITH_DIRECTIVE;
|
222
|
+
element: number;
|
223
|
+
dir: VaporDirectiveNode;
|
224
|
+
name: string;
|
225
|
+
builtin?: boolean;
|
226
|
+
asset?: boolean;
|
227
|
+
}
|
228
|
+
interface CreateComponentIRNode extends BaseIRNode {
|
229
|
+
type: IRNodeTypes.CREATE_COMPONENT_NODE;
|
230
|
+
id: number;
|
231
|
+
tag: string;
|
232
|
+
props: IRProps[];
|
233
|
+
slots: IRSlots[];
|
234
|
+
asset: boolean;
|
235
|
+
root: boolean;
|
236
|
+
once: boolean;
|
237
|
+
}
|
238
|
+
interface DeclareOldRefIRNode extends BaseIRNode {
|
239
|
+
type: IRNodeTypes.DECLARE_OLD_REF;
|
240
|
+
id: number;
|
241
|
+
}
|
242
|
+
interface SlotOutletIRNode extends BaseIRNode {
|
243
|
+
type: IRNodeTypes.SLOT_OUTLET_NODE;
|
244
|
+
id: number;
|
245
|
+
name: SimpleExpressionNode;
|
246
|
+
props: IRProps[];
|
247
|
+
fallback?: BlockIRNode;
|
248
|
+
}
|
249
|
+
type IRNode = OperationNode | RootIRNode;
|
250
|
+
type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | SetInheritAttrsIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
|
251
|
+
declare enum DynamicFlag {
|
252
|
+
NONE = 0,
|
253
|
+
/**
|
254
|
+
* This node is referenced and needs to be saved as a variable.
|
255
|
+
*/
|
256
|
+
REFERENCED = 1,
|
257
|
+
/**
|
258
|
+
* This node is not generated from template, but is generated dynamically.
|
259
|
+
*/
|
260
|
+
NON_TEMPLATE = 2,
|
261
|
+
/**
|
262
|
+
* This node needs to be inserted back into the template.
|
263
|
+
*/
|
264
|
+
INSERT = 4
|
265
|
+
}
|
266
|
+
interface IRDynamicInfo {
|
267
|
+
id?: number;
|
268
|
+
flags: DynamicFlag;
|
269
|
+
anchor?: number;
|
270
|
+
children: IRDynamicInfo[];
|
271
|
+
template?: number;
|
272
|
+
}
|
273
|
+
interface IREffect {
|
274
|
+
expressions: SimpleExpressionNode[];
|
275
|
+
identifiers: string[];
|
276
|
+
operations: OperationNode[];
|
277
|
+
declareNames: Set<string>;
|
278
|
+
rewrittenNames: Set<string>;
|
279
|
+
earlyCheckExps: string[];
|
280
|
+
inVFor: boolean;
|
281
|
+
}
|
282
|
+
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
|
283
|
+
type HackOptions<T> = Prettify<Overwrite<T, {
|
284
|
+
nodeTransforms?: NodeTransform[];
|
285
|
+
directiveTransforms?: Record<string, DirectiveTransform | undefined>;
|
286
|
+
}>>;
|
287
|
+
type VaporDirectiveNode = Overwrite<DirectiveNode, {
|
288
|
+
exp: Exclude<DirectiveNode['exp'], CompoundExpressionNode>;
|
289
|
+
arg: Exclude<DirectiveNode['arg'], CompoundExpressionNode>;
|
290
|
+
}>;
|
291
|
+
|
292
|
+
type NodeTransform = (node: BlockIRNode['node'], context: TransformContext<BlockIRNode['node']>) => void | (() => void) | (() => void)[];
|
293
|
+
type DirectiveTransform = (dir: JSXAttribute, node: JSXElement, context: TransformContext<JSXElement>) => DirectiveTransformResult | void;
|
294
|
+
interface DirectiveTransformResult {
|
295
|
+
key: SimpleExpressionNode;
|
296
|
+
value: SimpleExpressionNode;
|
297
|
+
modifier?: '.' | '^';
|
298
|
+
runtimeCamelize?: boolean;
|
299
|
+
handler?: boolean;
|
300
|
+
model?: boolean;
|
301
|
+
modelModifiers?: string[];
|
302
|
+
}
|
303
|
+
type TransformOptions = HackOptions<TransformOptions$1>;
|
304
|
+
declare class TransformContext<T extends BlockIRNode['node'] = BlockIRNode['node']> {
|
305
|
+
ir: RootIRNode;
|
306
|
+
node: T;
|
307
|
+
parent: TransformContext<RootNode | JSXElement | JSXFragment> | null;
|
308
|
+
root: TransformContext<RootNode>;
|
309
|
+
index: number;
|
310
|
+
block: BlockIRNode;
|
311
|
+
options: Required<Omit<TransformOptions, 'filename' | keyof CompilerCompatOptions>>;
|
312
|
+
template: string;
|
313
|
+
childrenTemplate: (string | null)[];
|
314
|
+
dynamic: IRDynamicInfo;
|
315
|
+
inVOnce: boolean;
|
316
|
+
inVFor: number;
|
317
|
+
comment: CommentNode[];
|
318
|
+
component: Set<string>;
|
319
|
+
directive: Set<string>;
|
320
|
+
slots: IRSlots[];
|
321
|
+
private globalId;
|
322
|
+
constructor(ir: RootIRNode, node: T, options?: TransformOptions);
|
323
|
+
enterBlock(ir: BlockIRNode, isVFor?: boolean): () => void;
|
324
|
+
increaseId: () => number;
|
325
|
+
reference(): number;
|
326
|
+
pushTemplate(content: string): number;
|
327
|
+
registerTemplate(): number;
|
328
|
+
registerEffect(expressions: SimpleExpressionNode[], ...operations: OperationNode[]): void;
|
329
|
+
registerOperation(...node: OperationNode[]): void;
|
330
|
+
create<E extends T>(node: E, index: number): TransformContext<E>;
|
331
|
+
}
|
332
|
+
declare function transform(node: RootNode, options?: TransformOptions): RootIRNode;
|
333
|
+
declare function transformNode(context: TransformContext<BlockIRNode['node']>): void;
|
334
|
+
|
335
|
+
interface VaporCodegenResult extends Omit<VaporCodegenResult$1, 'ast'> {
|
336
|
+
ast: RootIRNode;
|
337
|
+
}
|
338
|
+
declare function compile(source: string | Program, options?: CompilerOptions): VaporCodegenResult;
|
339
|
+
type CompilerOptions = HackOptions<CompilerOptions$1>;
|
340
|
+
type TransformPreset = [
|
341
|
+
NodeTransform[],
|
342
|
+
Record<string, DirectiveTransform>
|
343
|
+
];
|
344
|
+
|
345
|
+
declare function resolveNode(node: JSXElement, context: TransformContext): ElementNode;
|
346
|
+
declare function resolveDirectiveNode(node: JSXAttribute, context: TransformContext): VaporDirectiveNode;
|
347
|
+
|
348
|
+
declare const transformText: NodeTransform;
|
349
|
+
|
350
|
+
declare const transformElement: NodeTransform;
|
351
|
+
|
352
|
+
declare const transformChildren: NodeTransform;
|
353
|
+
|
354
|
+
declare const transformTemplateRef: NodeTransform;
|
355
|
+
|
356
|
+
declare const transformVBind: DirectiveTransform;
|
357
|
+
|
358
|
+
declare const transformVOn: DirectiveTransform;
|
359
|
+
|
360
|
+
declare const transformVSlot: NodeTransform;
|
361
|
+
|
362
|
+
declare const transformVModel: DirectiveTransform;
|
363
|
+
|
364
|
+
declare const transformVShow: DirectiveTransform;
|
365
|
+
|
366
|
+
declare const transformVHtml: DirectiveTransform;
|
367
|
+
|
368
|
+
export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateTextNodeIRNode, type DeclareOldRefIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetInheritAttrsIRNode, type SetModelValueIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SetTextIRNode, type SlotBlockIRNode, type SlotOutletIRNode, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, type VaporHelper, type WithDirectiveIRNode, compile, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVHtml, transformVModel, transformVOn, transformVShow, transformVSlot };
|