xray16 1.6.2 → 1.6.4

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.
@@ -0,0 +1,109 @@
1
+ import * as ts from "typescript";
2
+ import { type TFoldedValue, type TInlineValue } from "./constants";
3
+ /**
4
+ * Resolve the member symbol for a property or element access expression.
5
+ * When direct symbol resolution fails, element access is resolved through the object type. This supports
6
+ * literal keys and keys that fold to constants at build time, such as 'table[misc.device_pda]'.
7
+ *
8
+ * @param checker - Program type checker.
9
+ * @param node - Access expression to resolve symbol for.
10
+ * @returns Resolved member symbol or null.
11
+ */
12
+ export declare function resolveMemberSymbol(checker: ts.TypeChecker, node: ts.PropertyAccessExpression | ts.ElementAccessExpression): ts.Symbol | null;
13
+ /**
14
+ * Get literal value of symbol declared type, if it is a unit type.
15
+ * Uses declared type instead of flow-narrowed type so mutable narrowed values are never inlined.
16
+ *
17
+ * @param checker - Program type checker.
18
+ * @param symbol - Symbol to get declared literal value for.
19
+ * @returns Literal value, or null when the declared type is not a unit type.
20
+ */
21
+ export declare function getDeclaredLiteralValue(checker: ts.TypeChecker, symbol: ts.Symbol): TInlineValue | null;
22
+ /**
23
+ * Convert a folded value to a string for concatenation contexts.
24
+ * Non-integer numbers are rejected because JS 'String()' and LuaJIT 'tostring' format them differently
25
+ * (17 significant digits vs '%.14g'), so folding would change runtime-visible output.
26
+ * Expression trees are rejected because Lua '..' coercion differs from JS string conversion.
27
+ *
28
+ * @param value - Folded value to convert.
29
+ * @returns String representation or null.
30
+ */
31
+ export declare function toFoldedString(value: TFoldedValue | null): string | null;
32
+ /**
33
+ * Guard folded numeric results against NaN and Infinity, which cannot be emitted as Lua literals.
34
+ *
35
+ * @param value - Folded numeric value.
36
+ * @returns Finite number, or null when the value cannot be emitted as a Lua literal.
37
+ */
38
+ export declare function toFiniteNumber(value: number): number | null;
39
+ /**
40
+ * Fold a binary expression with constant operands using JavaScript semantics.
41
+ * JavaScript semantics are the correct target because TSTL preserves them at runtime,
42
+ * including '%' behavior for negative operands.
43
+ *
44
+ * When an operand is an expression tree with engine references, the result is a tree as well.
45
+ * Trees only allow numeric operands and operators where emitted Lua matches TSTL lowering exactly:
46
+ * '%', bitwise operators and string concatenation with trees are rejected.
47
+ *
48
+ * @param operator - Binary operator kind.
49
+ * @param left - Folded left operand.
50
+ * @param right - Folded right operand.
51
+ * @returns Folded value, or null when the operation is not safe to fold.
52
+ */
53
+ export declare function foldBinaryExpression(operator: ts.SyntaxKind, left: TFoldedValue, right: TFoldedValue): TFoldedValue | null;
54
+ /**
55
+ * Evaluate an expression to a compile-time constant value when possible.
56
+ * Supports literals, unary/binary arithmetic, string concatenation, template literals,
57
+ * references to enum members / module-level const scalars / `as const` object properties,
58
+ * whitelisted namespace constants like 'math.pi' and runtime-constant engine references
59
+ * like 'stalker_ids.action_dying' (emitted as expressions instead of baked literals).
60
+ *
61
+ * @param checker - Program type checker.
62
+ * @param expression - Expression to evaluate.
63
+ * @param seen - Set of declarations on current resolution path, guards from circular references.
64
+ * @returns Folded constant value, or null when the expression is not safe to fold.
65
+ */
66
+ export declare function evaluateConstantExpression(checker: ts.TypeChecker, expression: ts.Expression, seen: Set<ts.Declaration>): TFoldedValue | null;
67
+ /**
68
+ * Check whether an enum member is computable at build time - either constant for TypeScript
69
+ * or initialized with an expression that folds to a literal or an engine reference tree.
70
+ *
71
+ * @param checker - Program type checker.
72
+ * @param member - Enum member to check.
73
+ * @returns Whether the member is computable at build time.
74
+ */
75
+ export declare function isComputableEnumMember(checker: ts.TypeChecker, member: ts.EnumMember): boolean;
76
+ /**
77
+ * Resolve a referenced symbol to a compile-time constant value when the reference is safe to fold.
78
+ * Safe references are enum members, module-level const scalars, readonly `as const` object properties
79
+ * and `static readonly` engine members from ambient 'xray16' typings - values that cannot legally
80
+ * change at runtime. Tags are not required on referenced declarations.
81
+ *
82
+ * @param checker - Program type checker.
83
+ * @param symbol - Referenced symbol to resolve.
84
+ * @param seen - Set of declarations on current resolution path.
85
+ * @returns Folded constant value, or null when the symbol is not safe to fold.
86
+ */
87
+ export declare function resolveConstantSymbol(checker: ts.TypeChecker, symbol: ts.Symbol, seen: Set<ts.Declaration>): TFoldedValue | null;
88
+ /**
89
+ * Get the constant value of a declaration.
90
+ * Initializers are folded first so engine references are substituted as expressions - the declared
91
+ * literal type fast path would silently bake possibly stale values claimed by typings.
92
+ * Declared unit types are only used for initializer-less declarations like ambient constants.
93
+ * Safety and tagging requirements are checked by callers.
94
+ *
95
+ * @param checker - Program type checker.
96
+ * @param symbol - Symbol to get value for.
97
+ * @param seen - Set of declarations on current resolution path.
98
+ * @returns Constant value, or null when the declaration cannot be folded.
99
+ */
100
+ export declare function getComputedDeclarationValue(checker: ts.TypeChecker, symbol: ts.Symbol, seen: Set<ts.Declaration>): TFoldedValue | null;
101
+ /**
102
+ * Get the inlineable value for a symbol resolved from an access expression or identifier.
103
+ * Only symbols declared inside tagged enums or variable statements produce values.
104
+ *
105
+ * @param checker - Program type checker.
106
+ * @param symbol - Symbol to resolve inline value for.
107
+ * @returns Folded value, or null when the symbol is not tagged for inlining.
108
+ */
109
+ export declare function tryGetInlineValue(checker: ts.TypeChecker, symbol: ts.Symbol): TFoldedValue | null;
@@ -0,0 +1,393 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveMemberSymbol = resolveMemberSymbol;
4
+ exports.getDeclaredLiteralValue = getDeclaredLiteralValue;
5
+ exports.toFoldedString = toFoldedString;
6
+ exports.toFiniteNumber = toFiniteNumber;
7
+ exports.foldBinaryExpression = foldBinaryExpression;
8
+ exports.evaluateConstantExpression = evaluateConstantExpression;
9
+ exports.isComputableEnumMember = isComputableEnumMember;
10
+ exports.resolveConstantSymbol = resolveConstantSymbol;
11
+ exports.getComputedDeclarationValue = getComputedDeclarationValue;
12
+ exports.tryGetInlineValue = tryGetInlineValue;
13
+ const ts = require("typescript");
14
+ const ast_1 = require("./ast");
15
+ const constants_1 = require("./constants");
16
+ const TREE_BINARY_OPERATORS = {
17
+ [ts.SyntaxKind.PlusToken]: "+",
18
+ [ts.SyntaxKind.MinusToken]: "-",
19
+ [ts.SyntaxKind.AsteriskToken]: "*",
20
+ [ts.SyntaxKind.SlashToken]: "/",
21
+ [ts.SyntaxKind.AsteriskAsteriskToken]: "**",
22
+ };
23
+ /**
24
+ * Resolve the member symbol for a property or element access expression.
25
+ * When direct symbol resolution fails, element access is resolved through the object type. This supports
26
+ * literal keys and keys that fold to constants at build time, such as 'table[misc.device_pda]'.
27
+ *
28
+ * @param checker - Program type checker.
29
+ * @param node - Access expression to resolve symbol for.
30
+ * @returns Resolved member symbol or null.
31
+ */
32
+ function resolveMemberSymbol(checker, node) {
33
+ const symbol = checker.getSymbolAtLocation(node);
34
+ if (symbol !== undefined) {
35
+ return symbol;
36
+ }
37
+ if (ts.isElementAccessExpression(node)) {
38
+ const key = evaluateConstantExpression(checker, node.argumentExpression, new Set());
39
+ if (typeof key === "string" || typeof key === "number") {
40
+ return checker.getTypeAtLocation(node.expression).getProperty(String(key)) ?? null;
41
+ }
42
+ }
43
+ return null;
44
+ }
45
+ /**
46
+ * Get literal value of symbol declared type, if it is a unit type.
47
+ * Uses declared type instead of flow-narrowed type so mutable narrowed values are never inlined.
48
+ *
49
+ * @param checker - Program type checker.
50
+ * @param symbol - Symbol to get declared literal value for.
51
+ * @returns Literal value, or null when the declared type is not a unit type.
52
+ */
53
+ function getDeclaredLiteralValue(checker, symbol) {
54
+ const declaration = symbol.valueDeclaration;
55
+ if (declaration === undefined) {
56
+ return null;
57
+ }
58
+ const type = checker.getTypeOfSymbolAtLocation(symbol, declaration);
59
+ if (type.isStringLiteral()) {
60
+ return type.value;
61
+ }
62
+ if (type.isNumberLiteral()) {
63
+ return type.value;
64
+ }
65
+ if ((type.flags & ts.TypeFlags.BooleanLiteral) !== 0) {
66
+ return checker.typeToString(type) === "true";
67
+ }
68
+ return null;
69
+ }
70
+ /**
71
+ * Convert a folded value to a string for concatenation contexts.
72
+ * Non-integer numbers are rejected because JS 'String()' and LuaJIT 'tostring' format them differently
73
+ * (17 significant digits vs '%.14g'), so folding would change runtime-visible output.
74
+ * Expression trees are rejected because Lua '..' coercion differs from JS string conversion.
75
+ *
76
+ * @param value - Folded value to convert.
77
+ * @returns String representation or null.
78
+ */
79
+ function toFoldedString(value) {
80
+ if (typeof value === "string") {
81
+ return value;
82
+ }
83
+ if (typeof value === "number" && Number.isInteger(value) && Math.abs(value) < 1e14) {
84
+ return String(value);
85
+ }
86
+ return null;
87
+ }
88
+ /**
89
+ * Guard folded numeric results against NaN and Infinity, which cannot be emitted as Lua literals.
90
+ *
91
+ * @param value - Folded numeric value.
92
+ * @returns Finite number, or null when the value cannot be emitted as a Lua literal.
93
+ */
94
+ function toFiniteNumber(value) {
95
+ return Number.isFinite(value) ? value : null;
96
+ }
97
+ /**
98
+ * Fold a binary expression with constant operands using JavaScript semantics.
99
+ * JavaScript semantics are the correct target because TSTL preserves them at runtime,
100
+ * including '%' behavior for negative operands.
101
+ *
102
+ * When an operand is an expression tree with engine references, the result is a tree as well.
103
+ * Trees only allow numeric operands and operators where emitted Lua matches TSTL lowering exactly:
104
+ * '%', bitwise operators and string concatenation with trees are rejected.
105
+ *
106
+ * @param operator - Binary operator kind.
107
+ * @param left - Folded left operand.
108
+ * @param right - Folded right operand.
109
+ * @returns Folded value, or null when the operation is not safe to fold.
110
+ */
111
+ function foldBinaryExpression(operator, left, right) {
112
+ if (typeof left === "object" || typeof right === "object") {
113
+ const treeOperator = TREE_BINARY_OPERATORS[operator];
114
+ if (treeOperator === undefined || !(0, constants_1.isNumericFoldedValue)(left) || !(0, constants_1.isNumericFoldedValue)(right)) {
115
+ return null;
116
+ }
117
+ return { kind: "binary", operator: treeOperator, left, right };
118
+ }
119
+ if (operator === ts.SyntaxKind.PlusToken) {
120
+ if (typeof left === "number" && typeof right === "number") {
121
+ return toFiniteNumber(left + right);
122
+ }
123
+ const leftString = toFoldedString(left);
124
+ const rightString = toFoldedString(right);
125
+ return leftString !== null && rightString !== null ? leftString + rightString : null;
126
+ }
127
+ if (typeof left !== "number" || typeof right !== "number") {
128
+ return null;
129
+ }
130
+ switch (operator) {
131
+ case ts.SyntaxKind.MinusToken:
132
+ return toFiniteNumber(left - right);
133
+ case ts.SyntaxKind.AsteriskToken:
134
+ return toFiniteNumber(left * right);
135
+ case ts.SyntaxKind.SlashToken:
136
+ return toFiniteNumber(left / right);
137
+ case ts.SyntaxKind.PercentToken:
138
+ return toFiniteNumber(left % right);
139
+ case ts.SyntaxKind.AsteriskAsteriskToken:
140
+ return toFiniteNumber(left ** right);
141
+ case ts.SyntaxKind.AmpersandToken:
142
+ return left & right;
143
+ case ts.SyntaxKind.BarToken:
144
+ return left | right;
145
+ case ts.SyntaxKind.CaretToken:
146
+ return left ^ right;
147
+ case ts.SyntaxKind.LessThanLessThanToken:
148
+ return left << right;
149
+ case ts.SyntaxKind.GreaterThanGreaterThanToken:
150
+ return left >> right;
151
+ case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
152
+ return left >>> right;
153
+ default:
154
+ return null;
155
+ }
156
+ }
157
+ /**
158
+ * Evaluate an expression to a compile-time constant value when possible.
159
+ * Supports literals, unary/binary arithmetic, string concatenation, template literals,
160
+ * references to enum members / module-level const scalars / `as const` object properties,
161
+ * whitelisted namespace constants like 'math.pi' and runtime-constant engine references
162
+ * like 'stalker_ids.action_dying' (emitted as expressions instead of baked literals).
163
+ *
164
+ * @param checker - Program type checker.
165
+ * @param expression - Expression to evaluate.
166
+ * @param seen - Set of declarations on current resolution path, guards from circular references.
167
+ * @returns Folded constant value, or null when the expression is not safe to fold.
168
+ */
169
+ function evaluateConstantExpression(checker, expression, seen) {
170
+ const node = (0, ast_1.unwrapInitializer)(expression);
171
+ if (node === null) {
172
+ return null;
173
+ }
174
+ if (ts.isStringLiteralLike(node)) {
175
+ return node.text;
176
+ }
177
+ if (ts.isNumericLiteral(node)) {
178
+ return Number(node.text);
179
+ }
180
+ if (node.kind === ts.SyntaxKind.TrueKeyword) {
181
+ return true;
182
+ }
183
+ if (node.kind === ts.SyntaxKind.FalseKeyword) {
184
+ return false;
185
+ }
186
+ if (ts.isPrefixUnaryExpression(node)) {
187
+ const operand = evaluateConstantExpression(checker, node.operand, seen);
188
+ if (operand === null) {
189
+ return null;
190
+ }
191
+ switch (node.operator) {
192
+ case ts.SyntaxKind.MinusToken:
193
+ if (typeof operand === "number") {
194
+ return toFiniteNumber(-operand);
195
+ }
196
+ return typeof operand === "object" && (0, constants_1.isNumericFoldedValue)(operand) ? { kind: "negate", operand } : null;
197
+ case ts.SyntaxKind.PlusToken:
198
+ return typeof operand === "number" || (typeof operand === "object" && (0, constants_1.isNumericFoldedValue)(operand))
199
+ ? operand
200
+ : null;
201
+ case ts.SyntaxKind.TildeToken:
202
+ return typeof operand === "number" ? ~operand : null;
203
+ case ts.SyntaxKind.ExclamationToken:
204
+ return typeof operand === "boolean" ? !operand : null;
205
+ default:
206
+ return null;
207
+ }
208
+ }
209
+ if (ts.isBinaryExpression(node)) {
210
+ const left = evaluateConstantExpression(checker, node.left, seen);
211
+ if (left === null) {
212
+ return null;
213
+ }
214
+ const right = evaluateConstantExpression(checker, node.right, seen);
215
+ if (right === null) {
216
+ return null;
217
+ }
218
+ return foldBinaryExpression(node.operatorToken.kind, left, right);
219
+ }
220
+ if (ts.isTemplateExpression(node)) {
221
+ let result = node.head.text;
222
+ for (const span of node.templateSpans) {
223
+ const substitution = toFoldedString(evaluateConstantExpression(checker, span.expression, seen));
224
+ if (substitution === null) {
225
+ return null;
226
+ }
227
+ result += substitution + span.literal.text;
228
+ }
229
+ return result;
230
+ }
231
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
232
+ const namespaceConstant = constants_1.FOLDABLE_NAMESPACE_CONSTANTS[node.expression.text]?.[node.name.text];
233
+ if (namespaceConstant !== undefined) {
234
+ return namespaceConstant;
235
+ }
236
+ }
237
+ if (ts.isIdentifier(node)) {
238
+ const symbol = checker.getSymbolAtLocation(node);
239
+ return symbol === undefined ? null : resolveConstantSymbol(checker, symbol, seen);
240
+ }
241
+ if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
242
+ const symbol = resolveMemberSymbol(checker, node);
243
+ return symbol === null ? null : resolveConstantSymbol(checker, symbol, seen);
244
+ }
245
+ return null;
246
+ }
247
+ /**
248
+ * Fold an enum member to a constant value.
249
+ * TypeScript computes literal values of constant members; members initialized with engine references
250
+ * fold to expression trees instead.
251
+ *
252
+ * @param checker - Program type checker.
253
+ * @param declaration - Enum member declaration to fold.
254
+ * @param seen - Set of declarations on current resolution path.
255
+ * @returns Folded constant value, or null when the member is not computable at build time.
256
+ */
257
+ function getEnumMemberValue(checker, declaration, seen) {
258
+ const value = checker.getConstantValue(declaration);
259
+ if (typeof value === "string" || typeof value === "number") {
260
+ return value;
261
+ }
262
+ if (declaration.initializer === undefined || seen.has(declaration)) {
263
+ return null;
264
+ }
265
+ seen.add(declaration);
266
+ try {
267
+ return evaluateConstantExpression(checker, declaration.initializer, seen);
268
+ }
269
+ finally {
270
+ seen.delete(declaration);
271
+ }
272
+ }
273
+ /**
274
+ * Check whether an enum member is computable at build time - either constant for TypeScript
275
+ * or initialized with an expression that folds to a literal or an engine reference tree.
276
+ *
277
+ * @param checker - Program type checker.
278
+ * @param member - Enum member to check.
279
+ * @returns Whether the member is computable at build time.
280
+ */
281
+ function isComputableEnumMember(checker, member) {
282
+ return getEnumMemberValue(checker, member, new Set()) !== null;
283
+ }
284
+ /**
285
+ * Resolve a referenced symbol to a compile-time constant value when the reference is safe to fold.
286
+ * Safe references are enum members, module-level const scalars, readonly `as const` object properties
287
+ * and `static readonly` engine members from ambient 'xray16' typings - values that cannot legally
288
+ * change at runtime. Tags are not required on referenced declarations.
289
+ *
290
+ * @param checker - Program type checker.
291
+ * @param symbol - Referenced symbol to resolve.
292
+ * @param seen - Set of declarations on current resolution path.
293
+ * @returns Folded constant value, or null when the symbol is not safe to fold.
294
+ */
295
+ function resolveConstantSymbol(checker, symbol, seen) {
296
+ const resolved = (symbol.flags & ts.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(symbol) : symbol;
297
+ const declaration = resolved.valueDeclaration;
298
+ if (declaration === undefined) {
299
+ return null;
300
+ }
301
+ if (ts.isEnumMember(declaration)) {
302
+ return getEnumMemberValue(checker, declaration, seen);
303
+ }
304
+ if (ts.isPropertyDeclaration(declaration)) {
305
+ const path = (0, ast_1.getEngineConstantPath)(declaration);
306
+ if (path === null) {
307
+ return null;
308
+ }
309
+ const type = checker.getTypeOfSymbolAtLocation(resolved, declaration);
310
+ return {
311
+ kind: "engine-ref",
312
+ path,
313
+ isNumeric: type.isNumberLiteral() || (type.flags & ts.TypeFlags.NumberLike) !== 0,
314
+ };
315
+ }
316
+ if (ts.isVariableDeclaration(declaration)) {
317
+ const statement = (0, ast_1.getContainingVariableStatement)(declaration);
318
+ if (statement === null || !(0, ast_1.isModuleLevelConst)(statement)) {
319
+ return null;
320
+ }
321
+ return getComputedDeclarationValue(checker, resolved, seen);
322
+ }
323
+ if (ts.isPropertyAssignment(declaration) || ts.isShorthandPropertyAssignment(declaration)) {
324
+ return (0, ast_1.isReadonlyModuleConstProperty)(declaration) ? getComputedDeclarationValue(checker, resolved, seen) : null;
325
+ }
326
+ return null;
327
+ }
328
+ /**
329
+ * Get the constant value of a declaration.
330
+ * Initializers are folded first so engine references are substituted as expressions - the declared
331
+ * literal type fast path would silently bake possibly stale values claimed by typings.
332
+ * Declared unit types are only used for initializer-less declarations like ambient constants.
333
+ * Safety and tagging requirements are checked by callers.
334
+ *
335
+ * @param checker - Program type checker.
336
+ * @param symbol - Symbol to get value for.
337
+ * @param seen - Set of declarations on current resolution path.
338
+ * @returns Constant value, or null when the declaration cannot be folded.
339
+ */
340
+ function getComputedDeclarationValue(checker, symbol, seen) {
341
+ const declaration = symbol.valueDeclaration;
342
+ if (declaration === undefined) {
343
+ return null;
344
+ }
345
+ if (seen.has(declaration)) {
346
+ return null;
347
+ }
348
+ seen.add(declaration);
349
+ try {
350
+ if ((ts.isVariableDeclaration(declaration) || ts.isPropertyAssignment(declaration)) &&
351
+ declaration.initializer !== undefined) {
352
+ return evaluateConstantExpression(checker, declaration.initializer, seen);
353
+ }
354
+ if (ts.isShorthandPropertyAssignment(declaration)) {
355
+ const valueSymbol = checker.getShorthandAssignmentValueSymbol(declaration);
356
+ return valueSymbol === undefined ? null : resolveConstantSymbol(checker, valueSymbol, seen);
357
+ }
358
+ return getDeclaredLiteralValue(checker, symbol);
359
+ }
360
+ finally {
361
+ seen.delete(declaration);
362
+ }
363
+ }
364
+ /**
365
+ * Get the inlineable value for a symbol resolved from an access expression or identifier.
366
+ * Only symbols declared inside tagged enums or variable statements produce values.
367
+ *
368
+ * @param checker - Program type checker.
369
+ * @param symbol - Symbol to resolve inline value for.
370
+ * @returns Folded value, or null when the symbol is not tagged for inlining.
371
+ */
372
+ function tryGetInlineValue(checker, symbol) {
373
+ const declaration = symbol.valueDeclaration;
374
+ if (declaration === undefined) {
375
+ return null;
376
+ }
377
+ if (ts.isEnumMember(declaration)) {
378
+ if (!(0, ast_1.hasInlineTag)(declaration.parent)) {
379
+ return null;
380
+ }
381
+ return getEnumMemberValue(checker, declaration, new Set());
382
+ }
383
+ if (ts.isPropertyAssignment(declaration) ||
384
+ ts.isShorthandPropertyAssignment(declaration) ||
385
+ ts.isVariableDeclaration(declaration)) {
386
+ const statement = (0, ast_1.getContainingVariableStatement)(declaration);
387
+ if (statement === null || !(0, ast_1.hasInlineTag)(statement)) {
388
+ return null;
389
+ }
390
+ return getComputedDeclarationValue(checker, symbol, new Set());
391
+ }
392
+ return null;
393
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./ast";
2
+ export * from "./constants";
3
+ export * from "./errors";
4
+ export * from "./evaluation";
5
+ export * from "./transformers";
6
+ export * from "./validation";
7
+ export * from "./virtual";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ast"), exports);
18
+ __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./errors"), exports);
20
+ __exportStar(require("./evaluation"), exports);
21
+ __exportStar(require("./transformers"), exports);
22
+ __exportStar(require("./validation"), exports);
23
+ __exportStar(require("./virtual"), exports);
@@ -0,0 +1,41 @@
1
+ import * as ts from "typescript";
2
+ import * as lua from "typescript-to-lua";
3
+ import { type TFoldedValue } from "./constants";
4
+ /**
5
+ * Create a Lua expression for the provided folded value.
6
+ * Literals become Lua literals; expression trees with engine references become global access
7
+ * expressions and arithmetic over them.
8
+ *
9
+ * @param value - Folded value to create expression for.
10
+ * @param node - Original TypeScript node.
11
+ * @returns Lua expression.
12
+ */
13
+ export declare function createFoldedExpression(value: TFoldedValue, node: ts.Node): lua.Expression;
14
+ /**
15
+ * Transform property and element access expressions by inlining literal values from tagged declarations.
16
+ * Object spreads of `@virtual` objects accessed through namespaces are expanded to table literals.
17
+ *
18
+ * @param node - Access expression node to transform.
19
+ * @param context - Transformation context.
20
+ * @returns Lua literal when the access resolves to a tagged constant, default transformation otherwise.
21
+ */
22
+ export declare function transformAccessExpression(node: ts.PropertyAccessExpression | ts.ElementAccessExpression, context: lua.TransformationContext): lua.Expression;
23
+ /**
24
+ * Transform identifier expressions by inlining literal values from tagged scalar constants
25
+ * and expand object spreads of `@virtual` objects into table literals.
26
+ *
27
+ * @param node - Identifier node to transform.
28
+ * @param context - Transformation context.
29
+ * @returns Lua literal when the identifier resolves to a tagged constant, default transformation otherwise.
30
+ */
31
+ export declare function transformIdentifierExpression(node: ts.Identifier, context: lua.TransformationContext): lua.Expression;
32
+ /**
33
+ * Transform import declarations by stripping bindings for tagged declarations with no remaining runtime usages.
34
+ * When no runtime bindings remain, the require is dropped for provably pure modules
35
+ * or kept as a side-effect import otherwise.
36
+ *
37
+ * @param statement - Import declaration to transform.
38
+ * @param context - Transformation context.
39
+ * @returns Transformed statements.
40
+ */
41
+ export declare function transformImportDeclaration(statement: ts.ImportDeclaration, context: lua.TransformationContext): Array<lua.Statement>;