luau2ts 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/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/cli/args.d.ts +19 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +130 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +65 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/modes.d.ts +17 -0
- package/dist/cli/modes.d.ts.map +1 -0
- package/dist/cli/modes.js +134 -0
- package/dist/cli/modes.js.map +1 -0
- package/dist/compile/class-shape.d.ts +31 -0
- package/dist/compile/class-shape.d.ts.map +1 -0
- package/dist/compile/class-shape.js +291 -0
- package/dist/compile/class-shape.js.map +1 -0
- package/dist/compile/context.d.ts +86 -0
- package/dist/compile/context.d.ts.map +1 -0
- package/dist/compile/context.js +144 -0
- package/dist/compile/context.js.map +1 -0
- package/dist/compile/index.d.ts +43 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +2028 -0
- package/dist/compile/index.js.map +1 -0
- package/dist/compile/macros/datatypes.d.ts +2 -0
- package/dist/compile/macros/datatypes.d.ts.map +1 -0
- package/dist/compile/macros/datatypes.js +76 -0
- package/dist/compile/macros/datatypes.js.map +1 -0
- package/dist/compile/macros/index.d.ts +33 -0
- package/dist/compile/macros/index.d.ts.map +1 -0
- package/dist/compile/macros/index.js +71 -0
- package/dist/compile/macros/index.js.map +1 -0
- package/dist/compile/macros/instance.d.ts +2 -0
- package/dist/compile/macros/instance.d.ts.map +1 -0
- package/dist/compile/macros/instance.js +58 -0
- package/dist/compile/macros/instance.js.map +1 -0
- package/dist/compile/macros/stdlib.d.ts +2 -0
- package/dist/compile/macros/stdlib.d.ts.map +1 -0
- package/dist/compile/macros/stdlib.js +140 -0
- package/dist/compile/macros/stdlib.js.map +1 -0
- package/dist/compile/rbxts-runtime.d.ts +2 -0
- package/dist/compile/rbxts-runtime.d.ts.map +1 -0
- package/dist/compile/rbxts-runtime.js +163 -0
- package/dist/compile/rbxts-runtime.js.map +1 -0
- package/dist/compile/sourcemap.d.ts +25 -0
- package/dist/compile/sourcemap.d.ts.map +1 -0
- package/dist/compile/sourcemap.js +71 -0
- package/dist/compile/sourcemap.js.map +1 -0
- package/dist/compile/type.d.ts +6 -0
- package/dist/compile/type.d.ts.map +1 -0
- package/dist/compile/type.js +122 -0
- package/dist/compile/type.js.map +1 -0
- package/dist/compile/util.d.ts +38 -0
- package/dist/compile/util.d.ts.map +1 -0
- package/dist/compile/util.js +153 -0
- package/dist/compile/util.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +227 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/types.d.ts +430 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +14 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/parser/wasm/luau-parser.d.mts +21 -0
- package/dist/parser/wasm/luau-parser.mjs +2 -0
- package/dist/parser/wasm/luau-parser.wasm +0 -0
- package/dist/rojo/index.d.ts +4 -0
- package/dist/rojo/index.d.ts.map +1 -0
- package/dist/rojo/index.js +3 -0
- package/dist/rojo/index.js.map +1 -0
- package/dist/rojo/load-project.d.ts +12 -0
- package/dist/rojo/load-project.d.ts.map +1 -0
- package/dist/rojo/load-project.js +35 -0
- package/dist/rojo/load-project.js.map +1 -0
- package/dist/rojo/types.d.ts +39 -0
- package/dist/rojo/types.d.ts.map +1 -0
- package/dist/rojo/types.js +2 -0
- package/dist/rojo/types.js.map +1 -0
- package/dist/rojo/walk-tree.d.ts +40 -0
- package/dist/rojo/walk-tree.d.ts.map +1 -0
- package/dist/rojo/walk-tree.js +164 -0
- package/dist/rojo/walk-tree.js.map +1 -0
- package/dist/runtime/arith.d.ts +13 -0
- package/dist/runtime/arith.d.ts.map +1 -0
- package/dist/runtime/arith.js +151 -0
- package/dist/runtime/arith.js.map +1 -0
- package/dist/runtime/index-helper.d.ts +3 -0
- package/dist/runtime/index-helper.d.ts.map +1 -0
- package/dist/runtime/index-helper.js +40 -0
- package/dist/runtime/index-helper.js.map +1 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +13 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/iterator.d.ts +58 -0
- package/dist/runtime/iterator.d.ts.map +1 -0
- package/dist/runtime/iterator.js +181 -0
- package/dist/runtime/iterator.js.map +1 -0
- package/dist/runtime/length.d.ts +2 -0
- package/dist/runtime/length.d.ts.map +1 -0
- package/dist/runtime/length.js +15 -0
- package/dist/runtime/length.js.map +1 -0
- package/dist/runtime/lua-stdlib.d.ts +186 -0
- package/dist/runtime/lua-stdlib.d.ts.map +1 -0
- package/dist/runtime/lua-stdlib.js +502 -0
- package/dist/runtime/lua-stdlib.js.map +1 -0
- package/dist/runtime/metatable.d.ts +16 -0
- package/dist/runtime/metatable.d.ts.map +1 -0
- package/dist/runtime/metatable.js +129 -0
- package/dist/runtime/metatable.js.map +1 -0
- package/dist/runtime/pattern.d.ts +21 -0
- package/dist/runtime/pattern.d.ts.map +1 -0
- package/dist/runtime/pattern.js +375 -0
- package/dist/runtime/pattern.js.map +1 -0
- package/dist/runtime/pcall.d.ts +12 -0
- package/dist/runtime/pcall.d.ts.map +1 -0
- package/dist/runtime/pcall.js +54 -0
- package/dist/runtime/pcall.js.map +1 -0
- package/dist/runtime/string-lib.d.ts +31 -0
- package/dist/runtime/string-lib.d.ts.map +1 -0
- package/dist/runtime/string-lib.js +296 -0
- package/dist/runtime/string-lib.js.map +1 -0
- package/dist/runtime/table-lib.d.ts +18 -0
- package/dist/runtime/table-lib.d.ts.map +1 -0
- package/dist/runtime/table-lib.js +133 -0
- package/dist/runtime/table-lib.js.map +1 -0
- package/dist/runtime/tostring.d.ts +3 -0
- package/dist/runtime/tostring.d.ts.map +1 -0
- package/dist/runtime/tostring.js +82 -0
- package/dist/runtime/tostring.js.map +1 -0
- package/dist/runtime/truthy.d.ts +13 -0
- package/dist/runtime/truthy.d.ts.map +1 -0
- package/dist/runtime/truthy.js +26 -0
- package/dist/runtime/truthy.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
const { factory } = ts;
|
|
3
|
+
/** Walk a flat list of statements and detect class patterns. Returns the
|
|
4
|
+
* detected classes plus the union of consumed indexes (so callers can
|
|
5
|
+
* skip them in the regular pipeline). */
|
|
6
|
+
export function detectClasses(stmts) {
|
|
7
|
+
const out = [];
|
|
8
|
+
for (let i = 0; i < stmts.length; i++) {
|
|
9
|
+
const candidate = matchClassDeclaration(stmts, i);
|
|
10
|
+
if (!candidate)
|
|
11
|
+
continue;
|
|
12
|
+
// Walk forward, collecting __index, .new, :constructor, :method
|
|
13
|
+
// statements that belong to this class.
|
|
14
|
+
const pattern = {
|
|
15
|
+
name: candidate.name,
|
|
16
|
+
superclass: candidate.superclass,
|
|
17
|
+
consumed: new Set([i]),
|
|
18
|
+
ctorFactory: null,
|
|
19
|
+
constructor: null,
|
|
20
|
+
methods: [],
|
|
21
|
+
};
|
|
22
|
+
for (let j = i + 1; j < stmts.length; j++) {
|
|
23
|
+
const s = stmts[j];
|
|
24
|
+
if (matchIndexAssignment(s, pattern.name)) {
|
|
25
|
+
pattern.consumed.add(j);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const fnMatch = matchClassFunction(s, pattern.name);
|
|
29
|
+
if (fnMatch) {
|
|
30
|
+
pattern.consumed.add(j);
|
|
31
|
+
if (fnMatch.kind === 'static' && fnMatch.methodName === 'new') {
|
|
32
|
+
pattern.ctorFactory = s;
|
|
33
|
+
}
|
|
34
|
+
else if (fnMatch.kind === 'method' && fnMatch.methodName === 'constructor') {
|
|
35
|
+
pattern.constructor = s;
|
|
36
|
+
}
|
|
37
|
+
else if (fnMatch.kind === 'method') {
|
|
38
|
+
pattern.methods.push(s);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Static non-`new` method — drop into instance methods for now.
|
|
42
|
+
pattern.methods.push(s);
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// Any non-matching statement breaks the class block.
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
// Require at least a `.new` factory or a `:constructor` to be confident
|
|
50
|
+
// we matched a real class — bare `setmetatable({}, …)` blocks aren't
|
|
51
|
+
// necessarily classes.
|
|
52
|
+
if (!pattern.ctorFactory && !pattern.constructor && pattern.methods.length === 0)
|
|
53
|
+
continue;
|
|
54
|
+
out.push(pattern);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** Check whether a statement is `local <Name> = setmetatable({}, <table>)`.
|
|
59
|
+
* Returns the class name + (optional) superclass identifier read from the
|
|
60
|
+
* metatable's `__index` field. */
|
|
61
|
+
function matchClassDeclaration(stmts, i) {
|
|
62
|
+
const stat = stmts[i];
|
|
63
|
+
if (!stat || stat.type !== 'Local')
|
|
64
|
+
return null;
|
|
65
|
+
const ls = stat;
|
|
66
|
+
if (ls.vars.length !== 1 || ls.values.length !== 1)
|
|
67
|
+
return null;
|
|
68
|
+
const name = ls.vars[0].name;
|
|
69
|
+
const value = ls.values[0];
|
|
70
|
+
if (value.type !== 'Call')
|
|
71
|
+
return null;
|
|
72
|
+
const call = value;
|
|
73
|
+
if (call.func.type !== 'Global' || call.func.name !== 'setmetatable')
|
|
74
|
+
return null;
|
|
75
|
+
if (call.args.length < 1 || call.args[0].type !== 'Table')
|
|
76
|
+
return null;
|
|
77
|
+
// Optional second argument: a table literal whose `__index` field gives
|
|
78
|
+
// the superclass.
|
|
79
|
+
let superclass = null;
|
|
80
|
+
if (call.args.length >= 2 && call.args[1].type === 'Table') {
|
|
81
|
+
const meta = call.args[1];
|
|
82
|
+
for (const item of meta.items) {
|
|
83
|
+
if (item.kind !== 'Record')
|
|
84
|
+
continue;
|
|
85
|
+
const key = item.key;
|
|
86
|
+
if (!key || key.type !== 'ConstantString')
|
|
87
|
+
continue;
|
|
88
|
+
if (key.value !== '__index')
|
|
89
|
+
continue;
|
|
90
|
+
if (item.value.type === 'Global')
|
|
91
|
+
superclass = item.value.name;
|
|
92
|
+
else if (item.value.type === 'Local')
|
|
93
|
+
superclass = item.value.name;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { name, superclass };
|
|
97
|
+
}
|
|
98
|
+
/** Match `<Class>.__index = <Class>` (or `= <Superclass>`). */
|
|
99
|
+
function matchIndexAssignment(stat, className) {
|
|
100
|
+
if (stat.type !== 'Assign')
|
|
101
|
+
return false;
|
|
102
|
+
const a = stat;
|
|
103
|
+
if (a.vars.length !== 1)
|
|
104
|
+
return false;
|
|
105
|
+
const v = a.vars[0];
|
|
106
|
+
if (v.type !== 'IndexName')
|
|
107
|
+
return false;
|
|
108
|
+
if (v.index !== '__index')
|
|
109
|
+
return false;
|
|
110
|
+
if (v.expr.type !== 'Global' && v.expr.type !== 'Local')
|
|
111
|
+
return false;
|
|
112
|
+
return v.expr.name === className;
|
|
113
|
+
}
|
|
114
|
+
/** Match `function <Class>.method(...)` or `function <Class>:method(...)`. */
|
|
115
|
+
function matchClassFunction(stat, className) {
|
|
116
|
+
if (stat.type !== 'Function')
|
|
117
|
+
return null;
|
|
118
|
+
const fs = stat;
|
|
119
|
+
// The name expr is an IndexName with `op` = '.' or ':'. We want the
|
|
120
|
+
// root to be `<className>` and the index to be the method name.
|
|
121
|
+
const nameExpr = fs.name;
|
|
122
|
+
if (nameExpr.type !== 'IndexName')
|
|
123
|
+
return null;
|
|
124
|
+
if (nameExpr.expr.type !== 'Global' && nameExpr.expr.type !== 'Local')
|
|
125
|
+
return null;
|
|
126
|
+
if (nameExpr.expr.name !== className)
|
|
127
|
+
return null;
|
|
128
|
+
const op = nameExpr.op;
|
|
129
|
+
return {
|
|
130
|
+
kind: op === ':' ? 'method' : 'static',
|
|
131
|
+
methodName: nameExpr.index,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** Compile a detected class pattern into a TS `class` declaration. The
|
|
135
|
+
* returned node replaces the consumed statements in the output. */
|
|
136
|
+
export function compileClassPattern(pattern, ctx, compileBlockBody, compileExpr) {
|
|
137
|
+
const members = [];
|
|
138
|
+
// Constructor — prefer :constructor; fall back to the .new factory body.
|
|
139
|
+
const ctorFn = pattern.constructor ?? pattern.ctorFactory;
|
|
140
|
+
if (ctorFn) {
|
|
141
|
+
const fnExpr = ctorFn.func;
|
|
142
|
+
const params = (fnExpr.args ?? []).map((a) => factory.createParameterDeclaration(undefined, undefined, a.name));
|
|
143
|
+
const body = ctorBody(fnExpr.body, pattern, ctx, compileBlockBody, compileExpr);
|
|
144
|
+
members.push(factory.createConstructorDeclaration(undefined, params, factory.createBlock(body, true)));
|
|
145
|
+
}
|
|
146
|
+
// Methods.
|
|
147
|
+
for (const method of pattern.methods) {
|
|
148
|
+
const nameExpr = method.name;
|
|
149
|
+
if (nameExpr.type !== 'IndexName')
|
|
150
|
+
continue;
|
|
151
|
+
const methodName = nameExpr.index;
|
|
152
|
+
const fnExpr = method.func;
|
|
153
|
+
const params = (fnExpr.args ?? []).map((a) => factory.createParameterDeclaration(undefined, undefined, a.name));
|
|
154
|
+
const isStatic = nameExpr.op === '.';
|
|
155
|
+
const modifiers = isStatic
|
|
156
|
+
? [factory.createModifier(ts.SyntaxKind.StaticKeyword)]
|
|
157
|
+
: undefined;
|
|
158
|
+
// Method bodies have the same `self` → `this` requirement as the
|
|
159
|
+
// constructor. Rewrite once after compileBlockBody so the emitted
|
|
160
|
+
// method reads `return this.x + arg` rather than `return self.x + arg`.
|
|
161
|
+
const rawBody = compileBlockBody(fnExpr.body, ctx);
|
|
162
|
+
const bodyStmts = rawBody.map((s) => rewriteSelfToThis(s));
|
|
163
|
+
members.push(factory.createMethodDeclaration(modifiers, undefined, methodName, undefined, undefined, params, undefined, factory.createBlock(bodyStmts, true)));
|
|
164
|
+
}
|
|
165
|
+
// Inheritance.
|
|
166
|
+
const heritage = pattern.superclass
|
|
167
|
+
? [
|
|
168
|
+
factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
|
169
|
+
factory.createExpressionWithTypeArguments(factory.createIdentifier(pattern.superclass), undefined),
|
|
170
|
+
]),
|
|
171
|
+
]
|
|
172
|
+
: undefined;
|
|
173
|
+
return factory.createClassDeclaration(undefined, pattern.name, undefined, heritage, members);
|
|
174
|
+
}
|
|
175
|
+
/** Compile the body of a `:constructor` or `.new` factory. The factory
|
|
176
|
+
* body typically contains `local self = setmetatable({}, Class)` and
|
|
177
|
+
* `self:constructor(...)`; we skip those bookkeeping lines and emit the
|
|
178
|
+
* rest verbatim. The constructor body itself becomes the TS constructor. */
|
|
179
|
+
function ctorBody(body, pattern, ctx, compileBlockBody, compileExpr) {
|
|
180
|
+
// If `:constructor` exists, use its body. Otherwise, the factory body
|
|
181
|
+
// typically wraps a `self:constructor(...)` call — we inline the
|
|
182
|
+
// factory body instead, keeping the user's actual init statements.
|
|
183
|
+
const stmts = body.type === 'Block' ? body.body : [body];
|
|
184
|
+
const filtered = stmts.filter((s) => !isClassPlumbing(s, pattern));
|
|
185
|
+
let compiled = filtered.flatMap((s) => compileBlockBody(s, ctx));
|
|
186
|
+
// Rewrite `self` → `this` and `Superclass.constructor(this, ...)` →
|
|
187
|
+
// `super(...)` so the synthesized class body uses TS-idiomatic names.
|
|
188
|
+
compiled = compiled.map((s) => rewriteSelfToThis(s));
|
|
189
|
+
if (pattern.superclass) {
|
|
190
|
+
compiled = compiled.map((s) => rewriteSuperCall(s, pattern.superclass));
|
|
191
|
+
}
|
|
192
|
+
return compiled;
|
|
193
|
+
// `compileExpr` is unused here today but kept in the signature for the
|
|
194
|
+
// future where we'll inline literal field assignments as TS class fields
|
|
195
|
+
// (`x: number = 0` syntax) instead of `this.x = …` constructor stmts.
|
|
196
|
+
void compileExpr;
|
|
197
|
+
}
|
|
198
|
+
/** Rewrite every `Identifier('self')` reference in a TS statement to
|
|
199
|
+
* `this`. The class-shape detector copies Luau bodies that bind `self`
|
|
200
|
+
* via `self = setmetatable({}, Class)`; once we elevate the body into a
|
|
201
|
+
* TS class, every `self.X` is the synthesized `this.X`. */
|
|
202
|
+
function rewriteSelfToThis(stat) {
|
|
203
|
+
function visit(node) {
|
|
204
|
+
if (ts.isIdentifier(node) && node.text === 'self') {
|
|
205
|
+
// Don't rewrite when `self` is the property name of a member
|
|
206
|
+
// access — `obj.self` should stay as `obj.self`.
|
|
207
|
+
// ts.isIdentifier covers both Identifier and the property-name
|
|
208
|
+
// position; we use the parent check at the call site below.
|
|
209
|
+
return factory.createThis();
|
|
210
|
+
}
|
|
211
|
+
return ts.visitEachChild(node, visit, undefined);
|
|
212
|
+
}
|
|
213
|
+
// Wrap so we don't rewrite property *names* (e.g. `obj.self` stays).
|
|
214
|
+
function topLevel(node) {
|
|
215
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
216
|
+
// Recurse only into the `expression` part; leave `name` alone.
|
|
217
|
+
const expr = topLevel(node.expression);
|
|
218
|
+
return factory.createPropertyAccessExpression(expr, node.name);
|
|
219
|
+
}
|
|
220
|
+
if (ts.isIdentifier(node) && node.text === 'self') {
|
|
221
|
+
return factory.createThis();
|
|
222
|
+
}
|
|
223
|
+
return ts.visitEachChild(node, topLevel, undefined);
|
|
224
|
+
}
|
|
225
|
+
void visit;
|
|
226
|
+
return topLevel(stat);
|
|
227
|
+
}
|
|
228
|
+
/** Statements that are pure metatable plumbing — `local self = setmetatable(...)`,
|
|
229
|
+
* `self:constructor(...)`, `return self`. Kept out of the TS constructor body. */
|
|
230
|
+
function isClassPlumbing(stat, pattern) {
|
|
231
|
+
// `local self = setmetatable({}, Class)` — first line of .new factory.
|
|
232
|
+
if (stat.type === 'Local') {
|
|
233
|
+
const ls = stat;
|
|
234
|
+
if (ls.vars.length === 1 && ls.vars[0].name === 'self' && ls.values.length === 1) {
|
|
235
|
+
const v = ls.values[0];
|
|
236
|
+
if (v.type === 'Call' && v.func.type === 'Global' && v.func.name === 'setmetatable') {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// `self:constructor(...)` call — second line of .new factory.
|
|
242
|
+
if (stat.type === 'Expr') {
|
|
243
|
+
const e = stat.expr;
|
|
244
|
+
if (e.type === 'Call' && e.func.type === 'IndexName') {
|
|
245
|
+
const f = e.func;
|
|
246
|
+
if (f.index === 'constructor'
|
|
247
|
+
&& f.expr.type === 'Local'
|
|
248
|
+
&& f.expr.name === 'self')
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// `return self` — last line of .new factory.
|
|
253
|
+
if (stat.type === 'Return') {
|
|
254
|
+
const r = stat;
|
|
255
|
+
if (r.values.length === 1) {
|
|
256
|
+
const v = r.values[0];
|
|
257
|
+
if (v.type === 'Local' && v.name === 'self')
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
void pattern;
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
/** Best-effort: rewrite any `Superclass.constructor(this, ...)` call in a
|
|
265
|
+
* TS statement to `super(...)`. */
|
|
266
|
+
function rewriteSuperCall(stat, superclass) {
|
|
267
|
+
function visit(node) {
|
|
268
|
+
if (ts.isCallExpression(node)
|
|
269
|
+
&& ts.isPropertyAccessExpression(node.expression)
|
|
270
|
+
&& ts.isIdentifier(node.expression.expression)
|
|
271
|
+
&& node.expression.expression.text === superclass
|
|
272
|
+
&& ts.isIdentifier(node.expression.name)
|
|
273
|
+
&& node.expression.name.text === 'constructor') {
|
|
274
|
+
// Drop the first arg if it's `this` / `self` — both forms appear
|
|
275
|
+
// depending on whether the self→this rewrite ran first (which
|
|
276
|
+
// produces a ts.ThisExpression node, not an identifier).
|
|
277
|
+
const args = node.arguments.slice();
|
|
278
|
+
if (args.length > 0) {
|
|
279
|
+
const first = args[0];
|
|
280
|
+
const isThisLike = first.kind === ts.SyntaxKind.ThisKeyword
|
|
281
|
+
|| (ts.isIdentifier(first) && (first.text === 'this' || first.text === 'self'));
|
|
282
|
+
if (isThisLike)
|
|
283
|
+
args.shift();
|
|
284
|
+
}
|
|
285
|
+
return factory.createCallExpression(factory.createSuper(), undefined, args);
|
|
286
|
+
}
|
|
287
|
+
return ts.visitEachChild(node, visit, undefined);
|
|
288
|
+
}
|
|
289
|
+
return visit(stat);
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=class-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-shape.js","sourceRoot":"","sources":["../../src/compile/class-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAU5B,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAuBvB;;0CAE0C;AAC1C,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,GAAG,GAAmB,EAAE,CAAC;IAE/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,SAAS;YAAE,SAAS;QAEzB,gEAAgE;QAChE,wCAAwC;QACxC,MAAM,OAAO,GAAiB;YAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,UAAU,EAAE,SAAS,CAAC,UAAU;YAChC,QAAQ,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACtB,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,IAAI;YACjB,O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AU,CAAC,WAAW;uBACrC,CAAC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC;gBAClF,IAAI,UAAU;oBAAE,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,CAAC;YACD,OAAO,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAiB,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare const RUNTIME_MODULE = "luau2ts/runtime";
|
|
2
|
+
/** What we know about a value at compile time.
|
|
3
|
+
*
|
|
4
|
+
* Primitives use plain string tags. Roblox datatypes (Vector3, CFrame,
|
|
5
|
+
* Color3, …) use the `'datatype:<Name>'` form so the compiler can fast-
|
|
6
|
+
* path arithmetic operators to the underlying instance methods. Anything
|
|
7
|
+
* we can't narrow falls back to `'unknown'`. */
|
|
8
|
+
export type StaticValueType = 'number' | 'boolean' | 'string' | 'nil' | 'unknown' | `datatype:${string}`;
|
|
9
|
+
/** Roblox datatypes that expose `__add`/`__sub`/`__mul`/`__div`/`__unm`
|
|
10
|
+
* metamethods we can fast-path. The compiler narrows constructor calls
|
|
11
|
+
* and annotated locals to `'datatype:<Name>'`; arithmetic between two
|
|
12
|
+
* values of the same datatype emits `a.add(b)` instead of `luaAdd(a, b)`. */
|
|
13
|
+
export declare const ARITH_DATATYPES: Set<string>;
|
|
14
|
+
/** Compatibility mode for emitted TypeScript.
|
|
15
|
+
*
|
|
16
|
+
* - `native`: emit TS that imports stdlib helpers from `luau2ts/runtime`.
|
|
17
|
+
* `Vector3.new(...)`, `game:GetService(...)`, 1-indexed array semantics.
|
|
18
|
+
* - `rbxts`: emit TS that mirrors what roblox-ts would accept as input.
|
|
19
|
+
* `new Vector3(...)`, `import { Workspace } from "@rbxts/services"`,
|
|
20
|
+
* `new ClassName()` for `Instance.new("ClassName")`, optional 0-indexed
|
|
21
|
+
* arrays for statically-array-typed expressions.
|
|
22
|
+
*/
|
|
23
|
+
export type CompatMode = 'native' | 'rbxts';
|
|
24
|
+
export declare class CompileContext {
|
|
25
|
+
readonly compatMode: CompatMode;
|
|
26
|
+
private readonly imports;
|
|
27
|
+
private readonly scopes;
|
|
28
|
+
/** Per-scope Luau-name → JS-name override map. Used when a `local X = expr`
|
|
29
|
+
* whose `expr` captures the outer `X` forces us to rename the new local
|
|
30
|
+
* to a fresh name (so the inner reference still binds to the outer). */
|
|
31
|
+
private readonly jsNameOverrides;
|
|
32
|
+
/** Names of user-defined functions in this file whose bodies transitively
|
|
33
|
+
* contain a yielding call. Calls to these names are themselves yielding
|
|
34
|
+
* and the compiler must wrap each call site in `await`. Populated by a
|
|
35
|
+
* pre-pass over the AST before code emission. */
|
|
36
|
+
readonly yieldingFunctions: Set<string>;
|
|
37
|
+
private tempCounter;
|
|
38
|
+
/** Reserved-import bookkeeping for module paths other than RUNTIME_MODULE.
|
|
39
|
+
* Used by the macro registry to collect e.g. `@rbxts/services` symbols so
|
|
40
|
+
* the emitter can prepend the right imports alongside the runtime helpers. */
|
|
41
|
+
private readonly extraImports;
|
|
42
|
+
/** Names of classes the class-shape detector inferred from
|
|
43
|
+
* metatable-OOP patterns. Recorded so subsequent `<Class>.new(...)`
|
|
44
|
+
* calls in the same file are lowered to `new <Class>(...)` rather than
|
|
45
|
+
* staying as static-method references. */
|
|
46
|
+
private readonly detectedClasses;
|
|
47
|
+
/** Names locally bound to imported module identifiers — used to suppress
|
|
48
|
+
* redundant `let X = X` declarations when a macro rewrote the RHS to
|
|
49
|
+
* the same name as the LHS variable (e.g. `local Workspace =
|
|
50
|
+
* game:GetService('Workspace')` after the macro fires). The key is the
|
|
51
|
+
* Luau-level local name; the value is the imported module name (used
|
|
52
|
+
* for diagnostics). */
|
|
53
|
+
private readonly suppressedLocals;
|
|
54
|
+
constructor(compatMode?: CompatMode);
|
|
55
|
+
/** Record a named import from `module`. The emitter will write
|
|
56
|
+
* `import { ...names } from "<module>"` once per module. */
|
|
57
|
+
useImport(module: string, name: string): string;
|
|
58
|
+
/** Returns the recorded extra imports as `{ module, names[] }` tuples,
|
|
59
|
+
* sorted by module path then by name for deterministic output. */
|
|
60
|
+
extraImportEntries(): {
|
|
61
|
+
module: string;
|
|
62
|
+
names: string[];
|
|
63
|
+
}[];
|
|
64
|
+
/** Record a name as a TS class detected by the class-shape pass. Lookup
|
|
65
|
+
* happens at every `<Name>.new(...)` call site so we can lower it to
|
|
66
|
+
* `new <Name>(...)` instead of leaving it as a static-method call. */
|
|
67
|
+
recordDetectedClass(name: string): void;
|
|
68
|
+
isDetectedClass(name: string): boolean;
|
|
69
|
+
/** Mark a local identifier as already bound to an import of the same
|
|
70
|
+
* name. Subsequent `local <name> = <name>` declarations are dropped to
|
|
71
|
+
* avoid the redundant shadowing. */
|
|
72
|
+
suppressLocal(name: string): void;
|
|
73
|
+
isSuppressedLocal(name: string): boolean;
|
|
74
|
+
use(helper: string): string;
|
|
75
|
+
importedHelpers(): string[];
|
|
76
|
+
freshIdentifier(prefix: string): string;
|
|
77
|
+
withScope<T>(fn: () => T): T;
|
|
78
|
+
setLocalJsName(name: string, jsName: string): void;
|
|
79
|
+
getLocalJsName(name: string): string | undefined;
|
|
80
|
+
defineLocal(name: string, type: StaticValueType): void;
|
|
81
|
+
hasLocalInCurrentScope(name: string): boolean;
|
|
82
|
+
hasLocalInOuterScope(name: string): boolean;
|
|
83
|
+
assignLocal(name: string, type: StaticValueType): void;
|
|
84
|
+
lookupLocal(name: string): StaticValueType;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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AE,MAAM,GAAG,IAAI;IAIjC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIxC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAK3B,eAAe,IAAI,MAAM,EAAE;IAI3B,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAMvC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAW5B,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAIlD,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAQhD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAItD,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI7C,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAO3C,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAWtD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe;CAO3C"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export const RUNTIME_MODULE = 'luau2ts/runtime';
|
|
2
|
+
/** Roblox datatypes that expose `__add`/`__sub`/`__mul`/`__div`/`__unm`
|
|
3
|
+
* metamethods we can fast-path. The compiler narrows constructor calls
|
|
4
|
+
* and annotated locals to `'datatype:<Name>'`; arithmetic between two
|
|
5
|
+
* values of the same datatype emits `a.add(b)` instead of `luaAdd(a, b)`. */
|
|
6
|
+
export const ARITH_DATATYPES = new Set([
|
|
7
|
+
'Vector3', 'Vector2', 'Vector3int16', 'Vector2int16', 'CFrame',
|
|
8
|
+
]);
|
|
9
|
+
export class CompileContext {
|
|
10
|
+
compatMode;
|
|
11
|
+
imports = new Set();
|
|
12
|
+
scopes = [new Map()];
|
|
13
|
+
/** Per-scope Luau-name → JS-name override map. Used when a `local X = expr`
|
|
14
|
+
* whose `expr` captures the outer `X` forces us to rename the new local
|
|
15
|
+
* to a fresh name (so the inner reference still binds to the outer). */
|
|
16
|
+
jsNameOverrides = [new Map()];
|
|
17
|
+
/** Names of user-defined functions in this file whose bodies transitively
|
|
18
|
+
* contain a yielding call. Calls to these names are themselves yielding
|
|
19
|
+
* and the compiler must wrap each call site in `await`. Populated by a
|
|
20
|
+
* pre-pass over the AST before code emission. */
|
|
21
|
+
yieldingFunctions = new Set();
|
|
22
|
+
tempCounter = 0;
|
|
23
|
+
/** Reserved-import bookkeeping for module paths other than RUNTIME_MODULE.
|
|
24
|
+
* Used by the macro registry to collect e.g. `@rbxts/services` symbols so
|
|
25
|
+
* the emitter can prepend the right imports alongside the runtime helpers. */
|
|
26
|
+
extraImports = new Map();
|
|
27
|
+
/** Names of classes the class-shape detector inferred from
|
|
28
|
+
* metatable-OOP patterns. Recorded so subsequent `<Class>.new(...)`
|
|
29
|
+
* calls in the same file are lowered to `new <Class>(...)` rather than
|
|
30
|
+
* staying as static-method references. */
|
|
31
|
+
detectedClasses = new Set();
|
|
32
|
+
/** Names locally bound to imported module identifiers — used to suppress
|
|
33
|
+
* redundant `let X = X` declarations when a macro rewrote the RHS to
|
|
34
|
+
* the same name as the LHS variable (e.g. `local Workspace =
|
|
35
|
+
* game:GetService('Workspace')` after the macro fires). The key is the
|
|
36
|
+
* Luau-level local name; the value is the imported module name (used
|
|
37
|
+
* for diagnostics). */
|
|
38
|
+
suppressedLocals = new Set();
|
|
39
|
+
constructor(compatMode = 'native') {
|
|
40
|
+
this.compatMode = compatMode;
|
|
41
|
+
}
|
|
42
|
+
/** Record a named import from `module`. The emitter will write
|
|
43
|
+
* `import { ...names } from "<module>"` once per module. */
|
|
44
|
+
useImport(module, name) {
|
|
45
|
+
let names = this.extraImports.get(module);
|
|
46
|
+
if (!names) {
|
|
47
|
+
names = new Set();
|
|
48
|
+
this.extraImports.set(module, names);
|
|
49
|
+
}
|
|
50
|
+
names.add(name);
|
|
51
|
+
return name;
|
|
52
|
+
}
|
|
53
|
+
/** Returns the recorded extra imports as `{ module, names[] }` tuples,
|
|
54
|
+
* sorted by module path then by name for deterministic output. */
|
|
55
|
+
extraImportEntries() {
|
|
56
|
+
return [...this.extraImports.entries()]
|
|
57
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
58
|
+
.map(([module, names]) => ({ module, names: [...names].sort() }));
|
|
59
|
+
}
|
|
60
|
+
/** Record a name as a TS class detected by the class-shape pass. Lookup
|
|
61
|
+
* happens at every `<Name>.new(...)` call site so we can lower it to
|
|
62
|
+
* `new <Name>(...)` instead of leaving it as a static-method call. */
|
|
63
|
+
recordDetectedClass(name) {
|
|
64
|
+
this.detectedClasses.add(name);
|
|
65
|
+
}
|
|
66
|
+
isDetectedClass(name) {
|
|
67
|
+
return this.detectedClasses.has(name);
|
|
68
|
+
}
|
|
69
|
+
/** Mark a local identifier as already bound to an import of the same
|
|
70
|
+
* name. Subsequent `local <name> = <name>` declarations are dropped to
|
|
71
|
+
* avoid the redundant shadowing. */
|
|
72
|
+
suppressLocal(name) {
|
|
73
|
+
this.suppressedLocals.add(name);
|
|
74
|
+
}
|
|
75
|
+
isSuppressedLocal(name) {
|
|
76
|
+
return this.suppressedLocals.has(name);
|
|
77
|
+
}
|
|
78
|
+
use(helper) {
|
|
79
|
+
this.imports.add(helper);
|
|
80
|
+
return helper;
|
|
81
|
+
}
|
|
82
|
+
importedHelpers() {
|
|
83
|
+
return [...this.imports].sort();
|
|
84
|
+
}
|
|
85
|
+
freshIdentifier(prefix) {
|
|
86
|
+
const id = this.tempCounter;
|
|
87
|
+
this.tempCounter += 1;
|
|
88
|
+
return `${prefix}_${id}`;
|
|
89
|
+
}
|
|
90
|
+
withScope(fn) {
|
|
91
|
+
this.scopes.push(new Map());
|
|
92
|
+
this.jsNameOverrides.push(new Map());
|
|
93
|
+
try {
|
|
94
|
+
return fn();
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
this.scopes.pop();
|
|
98
|
+
this.jsNameOverrides.pop();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
setLocalJsName(name, jsName) {
|
|
102
|
+
this.jsNameOverrides[this.jsNameOverrides.length - 1].set(name, jsName);
|
|
103
|
+
}
|
|
104
|
+
getLocalJsName(name) {
|
|
105
|
+
for (let i = this.jsNameOverrides.length - 1; i >= 0; i -= 1) {
|
|
106
|
+
const v = this.jsNameOverrides[i].get(name);
|
|
107
|
+
if (v !== undefined)
|
|
108
|
+
return v;
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
defineLocal(name, type) {
|
|
113
|
+
this.scopes[this.scopes.length - 1].set(name, type);
|
|
114
|
+
}
|
|
115
|
+
hasLocalInCurrentScope(name) {
|
|
116
|
+
return this.scopes[this.scopes.length - 1].has(name);
|
|
117
|
+
}
|
|
118
|
+
hasLocalInOuterScope(name) {
|
|
119
|
+
for (let i = this.scopes.length - 2; i >= 0; i -= 1) {
|
|
120
|
+
if (this.scopes[i].has(name))
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
assignLocal(name, type) {
|
|
126
|
+
for (let i = this.scopes.length - 1; i >= 0; i -= 1) {
|
|
127
|
+
const scope = this.scopes[i];
|
|
128
|
+
if (scope.has(name)) {
|
|
129
|
+
scope.set(name, type);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.defineLocal(name, type);
|
|
134
|
+
}
|
|
135
|
+
lookupLocal(name) {
|
|
136
|
+
for (let i = this.scopes.length - 1; i >= 0; i -= 1) {
|
|
137
|
+
const type = this.scopes[i].get(name);
|
|
138
|
+
if (type)
|
|
139
|
+
return type;
|
|
140
|
+
}
|
|
141
|
+
return 'unknown';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,IAAqB;QAC7C,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC;YAC9B,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACtB,OAAO;YACT,CAAC;QACH,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;QACxB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ParseResult } from '../parser/index.js';
|
|
2
|
+
import { type CompatMode } from './context.js';
|
|
3
|
+
import './macros/datatypes.js';
|
|
4
|
+
import './macros/instance.js';
|
|
5
|
+
import './macros/stdlib.js';
|
|
6
|
+
import './rbxts-runtime.js';
|
|
7
|
+
import { type SourceMap } from './sourcemap.js';
|
|
8
|
+
export interface CompileOptions {
|
|
9
|
+
/** Path of the source file. Used in the source map's `sources` field. */
|
|
10
|
+
sourceFile?: string;
|
|
11
|
+
/** Generate a source map mapping each TS statement back to its .luau line. */
|
|
12
|
+
sourceMap?: boolean;
|
|
13
|
+
/** Inline the source map as a base64 data URL appended to the output. */
|
|
14
|
+
inlineSourceMap?: boolean;
|
|
15
|
+
/** Preserve `--` line comments and `--[[ ]]` block comments from the source. */
|
|
16
|
+
preserveComments?: boolean;
|
|
17
|
+
/** Emit-shape compatibility mode.
|
|
18
|
+
*
|
|
19
|
+
* - `'native'` (default): emit TS that imports stdlib helpers from
|
|
20
|
+
* `luau2ts/runtime` and pairs with any Roblox runtime that mirrors
|
|
21
|
+
* Roblox's Luau API surface: `Vector3.new(...)`, `game:GetService(...)`, etc.
|
|
22
|
+
* - `'rbxts'`: emit TS that mirrors what roblox-ts accepts as input:
|
|
23
|
+
* `new Vector3(...)`, `import { Workspace } from "@rbxts/services"`,
|
|
24
|
+
* `new ClassName()` for `Instance.new("ClassName")`, etc.
|
|
25
|
+
*/
|
|
26
|
+
compatMode?: CompatMode;
|
|
27
|
+
/** Run Prettier on the emitted TypeScript. Defaults to `true`. Disable
|
|
28
|
+
* if you want raw TypeScript-printer output (faster, but the output is
|
|
29
|
+
* 4-space indented without canonical spacing around blocks). */
|
|
30
|
+
pretty?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface CompileResult {
|
|
33
|
+
/** Full TypeScript source of the compiled output. */
|
|
34
|
+
source: string;
|
|
35
|
+
/** Helper names the output imports from luau2ts/runtime. */
|
|
36
|
+
helpers: string[];
|
|
37
|
+
/** Parser errors, if any (compiler returns parser-error output even so). */
|
|
38
|
+
errors: ParseResult['errors'];
|
|
39
|
+
/** Source map JSON when sourceMap was requested. */
|
|
40
|
+
sourceMap?: SourceMap;
|
|
41
|
+
}
|
|
42
|
+
export declare function compile(source: string, options?: CompileOptions): Promise<CompileResult>;
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAgBL,KAAK,WAAW,EAKjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAmD,KAAK,UAAU,EAAwB,MAAM,cAAc,CAAC;AAItH,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,oBAAoB,CAAC;AAG5B,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,gBAAgB,CAAC;AAisExB,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yEAAyE;IACzE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;qEAEiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4EAA4E;IAC5E,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,oDAAoD;IACpD,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,wBAAsB,OAAO,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAgLxB"}
|