UNPKG

3.32 kBTypeScriptView Raw
1import type { ScopeValueSets, NameValue, ValueScope, ValueScopeName } from "./scope";
2import { _Code, Code, Name } from "./code";
3import { Scope } from "./scope";
4export { _, str, strConcat, nil, getProperty, stringify, regexpCode, Name, Code } from "./code";
5export { Scope, ScopeStore, ValueScope, ValueScopeName, ScopeValueSets, varKinds } from "./scope";
6export type SafeExpr = Code | number | boolean | null;
7export type Block = Code | (() => void);
8export declare const operators: {
9 GT: _Code;
10 GTE: _Code;
11 LT: _Code;
12 LTE: _Code;
13 EQ: _Code;
14 NEQ: _Code;
15 NOT: _Code;
16 OR: _Code;
17 AND: _Code;
18 ADD: _Code;
19};
20export interface CodeGenOptions {
21 es5?: boolean;
22 lines?: boolean;
23 ownProperties?: boolean;
24}
25export declare class CodeGen {
26 readonly _scope: Scope;
27 readonly _extScope: ValueScope;
28 readonly _values: ScopeValueSets;
29 private readonly _nodes;
30 private readonly _blockStarts;
31 private readonly _constants;
32 private readonly opts;
33 constructor(extScope: ValueScope, opts?: CodeGenOptions);
34 toString(): string;
35 name(prefix: string): Name;
36 scopeName(prefix: string): ValueScopeName;
37 scopeValue(prefixOrName: ValueScopeName | string, value: NameValue): Name;
38 getScopeValue(prefix: string, keyOrRef: unknown): ValueScopeName | undefined;
39 scopeRefs(scopeName: Name): Code;
40 scopeCode(): Code;
41 private _def;
42 const(nameOrPrefix: Name | string, rhs: SafeExpr, _constant?: boolean): Name;
43 let(nameOrPrefix: Name | string, rhs?: SafeExpr, _constant?: boolean): Name;
44 var(nameOrPrefix: Name | string, rhs?: SafeExpr, _constant?: boolean): Name;
45 assign(lhs: Code, rhs: SafeExpr, sideEffects?: boolean): CodeGen;
46 add(lhs: Code, rhs: SafeExpr): CodeGen;
47 code(c: Block | SafeExpr): CodeGen;
48 object(...keyValues: [Name | string, SafeExpr | string][]): _Code;
49 if(condition: Code | boolean, thenBody?: Block, elseBody?: Block): CodeGen;
50 elseIf(condition: Code | boolean): CodeGen;
51 else(): CodeGen;
52 endIf(): CodeGen;
53 private _for;
54 for(iteration: Code, forBody?: Block): CodeGen;
55 forRange(nameOrPrefix: Name | string, from: SafeExpr, to: SafeExpr, forBody: (index: Name) => void, varKind?: Code): CodeGen;
56 forOf(nameOrPrefix: Name | string, iterable: Code, forBody: (item: Name) => void, varKind?: Code): CodeGen;
57 forIn(nameOrPrefix: Name | string, obj: Code, forBody: (item: Name) => void, varKind?: Code): CodeGen;
58 endFor(): CodeGen;
59 label(label: Name): CodeGen;
60 break(label?: Code): CodeGen;
61 return(value: Block | SafeExpr): CodeGen;
62 try(tryBody: Block, catchCode?: (e: Name) => void, finallyCode?: Block): CodeGen;
63 throw(error: Code): CodeGen;
64 block(body?: Block, nodeCount?: number): CodeGen;
65 endBlock(nodeCount?: number): CodeGen;
66 func(name: Name, args?: Code, async?: boolean, funcBody?: Block): CodeGen;
67 endFunc(): CodeGen;
68 optimize(n?: number): void;
69 private _leafNode;
70 private _blockNode;
71 private _endBlockNode;
72 private _elseNode;
73 private get _root();
74 private get _currNode();
75 private set _currNode(value);
76}
77export declare function not<T extends Code | SafeExpr>(x: T): T;
78export declare function and(...args: Code[]): Code;
79export declare function or(...args: Code[]): Code;
80
\No newline at end of file