@defold-typescript/transpiler 0.50.1 → 0.52.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.d.ts +1 -0
- package/dist/index.js +331 -117
- package/dist/lifecycle-erasure.d.ts +1 -0
- package/dist/physics-event-guard-lowering.d.ts +2 -0
- package/dist/transpile.d.ts +3 -0
- package/package.json +2 -2
- package/src/hsm-builtin.ts +2 -2
- package/src/index.ts +1 -0
- package/src/lifecycle-erasure.ts +233 -8
- package/src/physics-event-guard-lowering.ts +56 -0
- package/src/program-diagnostics.ts +2 -0
- package/src/session.ts +2 -0
- package/src/timers-runtime.ts +2 -2
- package/src/transpile.ts +50 -12
package/dist/index.js
CHANGED
|
@@ -172,22 +172,26 @@ var FACTORY_SPECIFIERS = new Set([
|
|
|
172
172
|
`${FACTORY_MODULE}/gui-script`,
|
|
173
173
|
`${FACTORY_MODULE}/render-script`
|
|
174
174
|
]);
|
|
175
|
-
function
|
|
175
|
+
function factoryExportName(callee, checker) {
|
|
176
176
|
let symbol = checker.getSymbolAtLocation(callee);
|
|
177
177
|
if (symbol === undefined) {
|
|
178
|
-
return
|
|
178
|
+
return;
|
|
179
179
|
}
|
|
180
180
|
if (symbol.flags & ts2.SymbolFlags.Alias) {
|
|
181
181
|
symbol = checker.getAliasedSymbol(symbol);
|
|
182
182
|
}
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
const name = symbol.getName();
|
|
184
|
+
if (!FACTORY_NAMES.has(name)) {
|
|
185
|
+
return;
|
|
185
186
|
}
|
|
186
187
|
const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
187
188
|
if (declaration === undefined) {
|
|
188
|
-
return
|
|
189
|
+
return;
|
|
189
190
|
}
|
|
190
|
-
return declaration.getSourceFile().fileName.includes(FACTORY_MODULE);
|
|
191
|
+
return declaration.getSourceFile().fileName.includes(FACTORY_MODULE) ? name : undefined;
|
|
192
|
+
}
|
|
193
|
+
function resolvesToFactoryExport(callee, checker) {
|
|
194
|
+
return factoryExportName(callee, checker) !== undefined;
|
|
191
195
|
}
|
|
192
196
|
function isThisParameter2(param) {
|
|
193
197
|
return ts2.isIdentifier(param.name) && ts2.identifierToKeywordKind(param.name) === ts2.SyntaxKind.ThisKeyword;
|
|
@@ -270,6 +274,15 @@ function emitInitMerge(fn, context, property) {
|
|
|
270
274
|
const initFn = createFunctionExpression2(createBlock2([stateDecl, guard]), [createIdentifier2("self")], undefined, NodeFlags2.Declaration, fn);
|
|
271
275
|
return [builderDecl, createAssignmentStatement(createIdentifier2("init"), initFn, property)];
|
|
272
276
|
}
|
|
277
|
+
var RESOURCE_PROPERTY_MARKERS = new Set([
|
|
278
|
+
"resource.atlas",
|
|
279
|
+
"resource.buffer",
|
|
280
|
+
"resource.font",
|
|
281
|
+
"resource.material",
|
|
282
|
+
"resource.render_target",
|
|
283
|
+
"resource.texture",
|
|
284
|
+
"resource.tile_source"
|
|
285
|
+
]);
|
|
273
286
|
function propertyMembers(property) {
|
|
274
287
|
if (!ts2.isPropertyAssignment(property) || !ts2.isObjectLiteralExpression(property.initializer)) {
|
|
275
288
|
return [];
|
|
@@ -306,11 +319,108 @@ function isPropertiesHook(property) {
|
|
|
306
319
|
function emitPropertyRegistrations(property, context) {
|
|
307
320
|
return propertyMembers(property).map(({ name, initializer }) => createExpressionStatement(createCallExpression2(createTableIndexExpression(createIdentifier2("go"), createStringLiteral2("property")), [createStringLiteral2(name), context.transformExpression(initializer)])));
|
|
308
321
|
}
|
|
322
|
+
function scriptOnlyProperties(property, factory) {
|
|
323
|
+
const file = property.getSourceFile();
|
|
324
|
+
const start = property.getStart(file);
|
|
325
|
+
return {
|
|
326
|
+
file,
|
|
327
|
+
start,
|
|
328
|
+
length: property.getEnd() - start,
|
|
329
|
+
category: ts2.DiagnosticCategory.Error,
|
|
330
|
+
code: 0,
|
|
331
|
+
messageText: `\`${factory}\` cannot declare \`properties\`: Defold builds \`go.property\` only in \`.script\` files. Declare the property in a \`defineScript\` and send its value with \`msg.post\`.`
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function outermostWrapper(node) {
|
|
335
|
+
let current = node;
|
|
336
|
+
while (ts2.isParenthesizedExpression(current.parent) || ts2.isAsExpression(current.parent) || ts2.isSatisfiesExpression(current.parent) || ts2.isNonNullExpression(current.parent) || ts2.isTypeAssertionExpression(current.parent)) {
|
|
337
|
+
current = current.parent;
|
|
338
|
+
}
|
|
339
|
+
return current;
|
|
340
|
+
}
|
|
341
|
+
function innermostExpression(node) {
|
|
342
|
+
let current = node;
|
|
343
|
+
while (ts2.isParenthesizedExpression(current) || ts2.isAsExpression(current) || ts2.isSatisfiesExpression(current) || ts2.isNonNullExpression(current) || ts2.isTypeAssertionExpression(current)) {
|
|
344
|
+
current = current.expression;
|
|
345
|
+
}
|
|
346
|
+
return current;
|
|
347
|
+
}
|
|
348
|
+
function globalName(symbol, checker) {
|
|
349
|
+
if (symbol === undefined) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const fqn = checker.getFullyQualifiedName(symbol);
|
|
353
|
+
return fqn.startsWith("global.") ? fqn.slice("global.".length) : undefined;
|
|
354
|
+
}
|
|
355
|
+
function calledGlobal(call, checker) {
|
|
356
|
+
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
357
|
+
if (declaration === undefined || !ts2.isFunctionDeclaration(declaration) || declaration.name === undefined) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
return globalName(checker.getSymbolAtLocation(declaration.name), checker);
|
|
361
|
+
}
|
|
362
|
+
function isPropertyDefault(call, checker) {
|
|
363
|
+
const value = outermostWrapper(call);
|
|
364
|
+
const parent = value.parent;
|
|
365
|
+
if (ts2.isCallExpression(parent)) {
|
|
366
|
+
return parent.arguments[1] === value && calledGlobal(parent, checker) === "go.property";
|
|
367
|
+
}
|
|
368
|
+
const properties = parent?.parent?.parent;
|
|
369
|
+
if (properties === undefined || !ts2.isPropertyAssignment(properties) || !isPropertiesHook(properties)) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
const hooks = properties.parent;
|
|
373
|
+
return ts2.isObjectLiteralExpression(hooks) && factoryHooks(hooks.parent, checker) === hooks && propertyMembers(properties).some((member) => member.initializer === value);
|
|
374
|
+
}
|
|
375
|
+
function misplacedMarker(node, marker) {
|
|
376
|
+
const file = node.getSourceFile();
|
|
377
|
+
const start = node.getStart(file);
|
|
378
|
+
return {
|
|
379
|
+
file,
|
|
380
|
+
start,
|
|
381
|
+
length: node.getEnd() - start,
|
|
382
|
+
category: ts2.DiagnosticCategory.Error,
|
|
383
|
+
code: 0,
|
|
384
|
+
messageText: `\`${marker}\` is a build-time marker: Defold's build reads it only in a \`go.property\` default, and the engine binds no such function. Use it as a \`defineScript\` \`properties\` default.`
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function readsAsMarker(call) {
|
|
388
|
+
const callee = innermostExpression(call.expression);
|
|
389
|
+
if (ts2.isOptionalChain(call) || ts2.isOptionalChain(callee)) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
if (!ts2.isPropertyAccessExpression(callee) && !(ts2.isElementAccessExpression(callee) && ts2.isStringLiteralLike(innermostExpression(callee.argumentExpression)))) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
const receiver = innermostExpression(callee.expression);
|
|
396
|
+
if (!ts2.isIdentifier(receiver) || receiver.text !== "resource") {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
const [path] = call.arguments;
|
|
400
|
+
return path === undefined || ts2.isStringLiteralLike(innermostExpression(path));
|
|
401
|
+
}
|
|
402
|
+
function unreadableMarker(node, marker) {
|
|
403
|
+
const file = node.getSourceFile();
|
|
404
|
+
const start = node.getStart(file);
|
|
405
|
+
return {
|
|
406
|
+
file,
|
|
407
|
+
start,
|
|
408
|
+
length: node.getEnd() - start,
|
|
409
|
+
category: ts2.DiagnosticCategory.Error,
|
|
410
|
+
code: 0,
|
|
411
|
+
messageText: `\`${marker}\` in a property default must be written \`${marker}("<path>")\`, with a string literal path: Defold's build reads no other form.`
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function isCallee(node) {
|
|
415
|
+
const callee = outermostWrapper(node);
|
|
416
|
+
return ts2.isCallExpression(callee.parent) && callee.parent.expression === callee;
|
|
417
|
+
}
|
|
309
418
|
function eraseFactoryCall(expression, context) {
|
|
310
419
|
const hooks = factoryHooks(expression, context.checker);
|
|
311
|
-
if (hooks === undefined) {
|
|
420
|
+
if (hooks === undefined || !ts2.isCallExpression(expression)) {
|
|
312
421
|
return;
|
|
313
422
|
}
|
|
423
|
+
const factory = factoryExportName(expression.expression, context.checker);
|
|
314
424
|
const registrations = [];
|
|
315
425
|
const statements = [];
|
|
316
426
|
for (const property of hooks.properties) {
|
|
@@ -319,7 +429,11 @@ function eraseFactoryCall(expression, context) {
|
|
|
319
429
|
continue;
|
|
320
430
|
}
|
|
321
431
|
if (name === "properties") {
|
|
322
|
-
|
|
432
|
+
if (factory === "defineScript") {
|
|
433
|
+
registrations.push(...emitPropertyRegistrations(property, context));
|
|
434
|
+
} else if (factory !== undefined && propertyMembers(property).length > 0) {
|
|
435
|
+
context.diagnostics.push(scriptOnlyProperties(property, factory));
|
|
436
|
+
}
|
|
323
437
|
continue;
|
|
324
438
|
}
|
|
325
439
|
const fn = hookFunction(property);
|
|
@@ -373,7 +487,37 @@ var lifecycleErasurePlugin = {
|
|
|
373
487
|
}
|
|
374
488
|
return context.superTransformStatements(node);
|
|
375
489
|
},
|
|
376
|
-
[ts2.SyntaxKind.ImportDeclaration]: (node, context) => isFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
|
|
490
|
+
[ts2.SyntaxKind.ImportDeclaration]: (node, context) => isFactoryOnlyImport(node) ? [] : context.superTransformStatements(node),
|
|
491
|
+
[ts2.SyntaxKind.CallExpression]: (node, context) => {
|
|
492
|
+
const marker = node.parent === undefined ? undefined : calledGlobal(node, context.checker);
|
|
493
|
+
if (marker !== undefined && RESOURCE_PROPERTY_MARKERS.has(marker)) {
|
|
494
|
+
if (!isPropertyDefault(node, context.checker)) {
|
|
495
|
+
context.diagnostics.push(misplacedMarker(node, marker));
|
|
496
|
+
} else if (!readsAsMarker(node)) {
|
|
497
|
+
context.diagnostics.push(unreadableMarker(node, marker));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return context.superTransformExpression(node);
|
|
501
|
+
},
|
|
502
|
+
[ts2.SyntaxKind.PropertyAccessExpression]: (node, context) => {
|
|
503
|
+
if (node.parent !== undefined && !isCallee(node)) {
|
|
504
|
+
const marker = globalName(context.checker.getSymbolAtLocation(node.name), context.checker);
|
|
505
|
+
if (marker !== undefined && RESOURCE_PROPERTY_MARKERS.has(marker)) {
|
|
506
|
+
context.diagnostics.push(misplacedMarker(node, marker));
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return context.superTransformExpression(node);
|
|
510
|
+
},
|
|
511
|
+
[ts2.SyntaxKind.ElementAccessExpression]: (node, context) => {
|
|
512
|
+
if (node.parent !== undefined && !isCallee(node)) {
|
|
513
|
+
const key = innermostExpression(node.argumentExpression);
|
|
514
|
+
const marker = ts2.isStringLiteralLike(key) ? globalName(context.checker.getPropertyOfType(context.checker.getTypeAtLocation(node.expression), key.text), context.checker) : undefined;
|
|
515
|
+
if (marker !== undefined && RESOURCE_PROPERTY_MARKERS.has(marker)) {
|
|
516
|
+
context.diagnostics.push(misplacedMarker(node, marker));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return context.superTransformExpression(node);
|
|
520
|
+
}
|
|
377
521
|
}
|
|
378
522
|
};
|
|
379
523
|
|
|
@@ -2225,7 +2369,7 @@ function computeOutputRel(rel, config, kind) {
|
|
|
2225
2369
|
return baseRel.replace(/\.ts$/, SCRIPT_SUFFIX_BY_KIND[kind]);
|
|
2226
2370
|
}
|
|
2227
2371
|
// src/program-diagnostics.ts
|
|
2228
|
-
import * as
|
|
2372
|
+
import * as ts11 from "typescript";
|
|
2229
2373
|
import * as tstl from "typescript-to-lua";
|
|
2230
2374
|
|
|
2231
2375
|
// src/message-guard-lowering.ts
|
|
@@ -2269,38 +2413,81 @@ var messageGuardLoweringPlugin = {
|
|
|
2269
2413
|
}
|
|
2270
2414
|
};
|
|
2271
2415
|
|
|
2272
|
-
// src/
|
|
2416
|
+
// src/physics-event-guard-lowering.ts
|
|
2273
2417
|
import * as ts7 from "typescript";
|
|
2418
|
+
import {
|
|
2419
|
+
createBinaryExpression as createBinaryExpression4,
|
|
2420
|
+
createCallExpression as createCallExpression4,
|
|
2421
|
+
createIdentifier as createIdentifier4,
|
|
2422
|
+
createStringLiteral as createStringLiteral3,
|
|
2423
|
+
createTableIndexExpression as createTableIndexExpression2,
|
|
2424
|
+
SyntaxKind as SyntaxKind10
|
|
2425
|
+
} from "typescript-to-lua";
|
|
2426
|
+
var GUARD_MODULE2 = "@defold-typescript/types";
|
|
2427
|
+
var GUARD_NAME2 = "isPhysicsEvent";
|
|
2428
|
+
function resolvesToGuardExport2(callee, checker) {
|
|
2429
|
+
let symbol = checker.getSymbolAtLocation(callee);
|
|
2430
|
+
if (symbol === undefined) {
|
|
2431
|
+
return false;
|
|
2432
|
+
}
|
|
2433
|
+
if (symbol.flags & ts7.SymbolFlags.Alias) {
|
|
2434
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
2435
|
+
}
|
|
2436
|
+
if (symbol.getName() !== GUARD_NAME2) {
|
|
2437
|
+
return false;
|
|
2438
|
+
}
|
|
2439
|
+
const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
2440
|
+
if (declaration === undefined) {
|
|
2441
|
+
return false;
|
|
2442
|
+
}
|
|
2443
|
+
return declaration.getSourceFile().fileName.includes(GUARD_MODULE2);
|
|
2444
|
+
}
|
|
2445
|
+
var physicsEventGuardLoweringPlugin = {
|
|
2446
|
+
visitors: {
|
|
2447
|
+
[ts7.SyntaxKind.CallExpression]: (node, context) => {
|
|
2448
|
+
const [eventArg, nameArg] = node.arguments;
|
|
2449
|
+
if (node.arguments.length === 2 && eventArg !== undefined && nameArg !== undefined && resolvesToGuardExport2(node.expression, context.checker)) {
|
|
2450
|
+
const event = context.transformExpression(eventArg);
|
|
2451
|
+
const name = context.transformExpression(nameArg);
|
|
2452
|
+
return createBinaryExpression4(createTableIndexExpression2(event, createStringLiteral3("type")), createCallExpression4(createIdentifier4("hash"), [name]), SyntaxKind10.EqualityOperator, node);
|
|
2453
|
+
}
|
|
2454
|
+
return context.superTransformExpression(node);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2458
|
+
|
|
2459
|
+
// src/timers-lowering.ts
|
|
2460
|
+
import * as ts8 from "typescript";
|
|
2274
2461
|
import { LuaLibFeature as LuaLibFeature2 } from "typescript-to-lua";
|
|
2275
2462
|
function isTimersSpecifier(node) {
|
|
2276
|
-
return
|
|
2463
|
+
return ts8.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
|
|
2277
2464
|
}
|
|
2278
2465
|
function importsTimersModule(sourceFile) {
|
|
2279
|
-
return sourceFile.statements.some((statement) =>
|
|
2466
|
+
return sourceFile.statements.some((statement) => ts8.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
|
|
2280
2467
|
}
|
|
2281
2468
|
var TIMERS_REQUIRE_PATH = `@NoResolution:${TIMERS_REQUIRE_NAME}`;
|
|
2282
2469
|
var timersLoweringPlugin = {
|
|
2283
2470
|
visitors: {
|
|
2284
|
-
[
|
|
2471
|
+
[ts8.SyntaxKind.ImportDeclaration]: (node, context) => {
|
|
2285
2472
|
if (!isTimersSpecifier(node.moduleSpecifier)) {
|
|
2286
2473
|
return context.superTransformStatements(node);
|
|
2287
2474
|
}
|
|
2288
2475
|
context.usedLuaLibFeatures.add(LuaLibFeature2.Promise);
|
|
2289
2476
|
context.usedLuaLibFeatures.add(LuaLibFeature2.New);
|
|
2290
|
-
const rewritten =
|
|
2477
|
+
const rewritten = ts8.factory.updateImportDeclaration(node, node.modifiers, node.importClause, ts8.factory.createStringLiteral(TIMERS_REQUIRE_PATH), node.attributes);
|
|
2291
2478
|
return context.superTransformStatements(rewritten);
|
|
2292
2479
|
}
|
|
2293
2480
|
}
|
|
2294
2481
|
};
|
|
2295
2482
|
|
|
2296
2483
|
// src/type-application-erasure.ts
|
|
2297
|
-
import * as
|
|
2484
|
+
import * as ts9 from "typescript";
|
|
2298
2485
|
var TYPE_APPLICATION_APIS = new Set(["go.get", "go.set"]);
|
|
2299
2486
|
function isTypeApplication(call, checker) {
|
|
2300
2487
|
if (call.arguments.length !== 0)
|
|
2301
2488
|
return false;
|
|
2302
2489
|
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
2303
|
-
if (declaration === undefined || !
|
|
2490
|
+
if (declaration === undefined || !ts9.isFunctionDeclaration(declaration))
|
|
2304
2491
|
return false;
|
|
2305
2492
|
if (declaration.parameters.length !== 0 || declaration.typeParameters === undefined)
|
|
2306
2493
|
return false;
|
|
@@ -2314,7 +2501,7 @@ function isTypeApplication(call, checker) {
|
|
|
2314
2501
|
}
|
|
2315
2502
|
var typeApplicationErasurePlugin = {
|
|
2316
2503
|
visitors: {
|
|
2317
|
-
[
|
|
2504
|
+
[ts9.SyntaxKind.CallExpression]: (node, context) => {
|
|
2318
2505
|
if (isTypeApplication(node, context.checker)) {
|
|
2319
2506
|
return context.transformExpression(node.expression);
|
|
2320
2507
|
}
|
|
@@ -2324,38 +2511,38 @@ var typeApplicationErasurePlugin = {
|
|
|
2324
2511
|
};
|
|
2325
2512
|
|
|
2326
2513
|
// src/window-event-guard-lowering.ts
|
|
2327
|
-
import * as
|
|
2514
|
+
import * as ts10 from "typescript";
|
|
2328
2515
|
import {
|
|
2329
|
-
createBinaryExpression as
|
|
2330
|
-
SyntaxKind as
|
|
2516
|
+
createBinaryExpression as createBinaryExpression5,
|
|
2517
|
+
SyntaxKind as SyntaxKind14
|
|
2331
2518
|
} from "typescript-to-lua";
|
|
2332
|
-
var
|
|
2333
|
-
var
|
|
2334
|
-
function
|
|
2519
|
+
var GUARD_MODULE3 = "@defold-typescript/types";
|
|
2520
|
+
var GUARD_NAME3 = "isWindowEvent";
|
|
2521
|
+
function resolvesToGuardExport3(callee, checker) {
|
|
2335
2522
|
let symbol = checker.getSymbolAtLocation(callee);
|
|
2336
2523
|
if (symbol === undefined) {
|
|
2337
2524
|
return false;
|
|
2338
2525
|
}
|
|
2339
|
-
if (symbol.flags &
|
|
2526
|
+
if (symbol.flags & ts10.SymbolFlags.Alias) {
|
|
2340
2527
|
symbol = checker.getAliasedSymbol(symbol);
|
|
2341
2528
|
}
|
|
2342
|
-
if (symbol.getName() !==
|
|
2529
|
+
if (symbol.getName() !== GUARD_NAME3) {
|
|
2343
2530
|
return false;
|
|
2344
2531
|
}
|
|
2345
2532
|
const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
2346
2533
|
if (declaration === undefined) {
|
|
2347
2534
|
return false;
|
|
2348
2535
|
}
|
|
2349
|
-
return declaration.getSourceFile().fileName.includes(
|
|
2536
|
+
return declaration.getSourceFile().fileName.includes(GUARD_MODULE3);
|
|
2350
2537
|
}
|
|
2351
2538
|
var windowEventGuardLoweringPlugin = {
|
|
2352
2539
|
visitors: {
|
|
2353
|
-
[
|
|
2540
|
+
[ts10.SyntaxKind.CallExpression]: (node, context) => {
|
|
2354
2541
|
const [eventArg, , expectedArg] = node.arguments;
|
|
2355
|
-
if (node.arguments.length === 3 && eventArg !== undefined && expectedArg !== undefined &&
|
|
2542
|
+
if (node.arguments.length === 3 && eventArg !== undefined && expectedArg !== undefined && resolvesToGuardExport3(node.expression, context.checker)) {
|
|
2356
2543
|
const event = context.transformExpression(eventArg);
|
|
2357
2544
|
const expected = context.transformExpression(expectedArg);
|
|
2358
|
-
return
|
|
2545
|
+
return createBinaryExpression5(event, expected, SyntaxKind14.EqualityOperator, node);
|
|
2359
2546
|
}
|
|
2360
2547
|
return context.superTransformExpression(node);
|
|
2361
2548
|
}
|
|
@@ -2367,6 +2554,7 @@ var LUA_PLUGINS = [
|
|
|
2367
2554
|
lifecycleErasurePlugin,
|
|
2368
2555
|
messageGuardLoweringPlugin,
|
|
2369
2556
|
windowEventGuardLoweringPlugin,
|
|
2557
|
+
physicsEventGuardLoweringPlugin,
|
|
2370
2558
|
messageDispatchLoweringPlugin,
|
|
2371
2559
|
timersLoweringPlugin,
|
|
2372
2560
|
typeApplicationErasurePlugin
|
|
@@ -2376,7 +2564,7 @@ function isAmbient(fileName) {
|
|
|
2376
2564
|
return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
|
|
2377
2565
|
}
|
|
2378
2566
|
function getProgramDiagnostics(program, sourceFile) {
|
|
2379
|
-
const { diagnostics } = tstl.getProgramTranspileResult(
|
|
2567
|
+
const { diagnostics } = tstl.getProgramTranspileResult(ts11.sys, noopWriteFile, {
|
|
2380
2568
|
program,
|
|
2381
2569
|
plugins: LUA_PLUGINS,
|
|
2382
2570
|
...sourceFile ? { sourceFiles: [sourceFile] } : {}
|
|
@@ -2947,21 +3135,21 @@ function relativeAddressesFrom(index, context) {
|
|
|
2947
3135
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
2948
3136
|
import { createRequire as createRequire2 } from "node:module";
|
|
2949
3137
|
import * as path4 from "node:path";
|
|
2950
|
-
import * as
|
|
3138
|
+
import * as ts15 from "typescript";
|
|
2951
3139
|
import * as tstl3 from "typescript-to-lua";
|
|
2952
3140
|
|
|
2953
3141
|
// src/companion-emit.ts
|
|
2954
|
-
import * as
|
|
3142
|
+
import * as ts12 from "typescript";
|
|
2955
3143
|
import {
|
|
2956
3144
|
createAssignmentStatement as createAssignmentStatement2,
|
|
2957
|
-
createCallExpression as
|
|
3145
|
+
createCallExpression as createCallExpression5,
|
|
2958
3146
|
createFile,
|
|
2959
|
-
createIdentifier as
|
|
3147
|
+
createIdentifier as createIdentifier5,
|
|
2960
3148
|
createReturnStatement as createReturnStatement2,
|
|
2961
|
-
createStringLiteral as
|
|
3149
|
+
createStringLiteral as createStringLiteral4,
|
|
2962
3150
|
createTableExpression,
|
|
2963
3151
|
createTableFieldExpression,
|
|
2964
|
-
createTableIndexExpression as
|
|
3152
|
+
createTableIndexExpression as createTableIndexExpression3,
|
|
2965
3153
|
createVariableDeclarationStatement as createVariableDeclarationStatement3,
|
|
2966
3154
|
isBlock as isBlock3,
|
|
2967
3155
|
isCallExpression as isCallExpression4,
|
|
@@ -2981,12 +3169,12 @@ import {
|
|
|
2981
3169
|
} from "typescript-to-lua";
|
|
2982
3170
|
var EXPORTS_NAME = "____exports";
|
|
2983
3171
|
function exportsIdentifier() {
|
|
2984
|
-
return
|
|
3172
|
+
return createIdentifier5(EXPORTS_NAME);
|
|
2985
3173
|
}
|
|
2986
3174
|
function isRuntimeScriptSource(sourceFile, checker) {
|
|
2987
3175
|
return sourceFile.statements.some((statement) => {
|
|
2988
|
-
const expression =
|
|
2989
|
-
return expression !== undefined &&
|
|
3176
|
+
const expression = ts12.isExpressionStatement(statement) ? statement.expression : ts12.isExportAssignment(statement) && !statement.isExportEquals ? statement.expression : undefined;
|
|
3177
|
+
return expression !== undefined && ts12.isCallExpression(expression) && resolvesToFactoryExport(expression.expression, checker);
|
|
2990
3178
|
});
|
|
2991
3179
|
}
|
|
2992
3180
|
function planFor(sourceFile, checker) {
|
|
@@ -3138,11 +3326,11 @@ function freeNames(statements) {
|
|
|
3138
3326
|
function resolvedRequirePaths(sourceFile, checker) {
|
|
3139
3327
|
const paths = new Map;
|
|
3140
3328
|
for (const statement of sourceFile.statements) {
|
|
3141
|
-
const specifier =
|
|
3142
|
-
if (specifier === undefined || !
|
|
3329
|
+
const specifier = ts12.isImportDeclaration(statement) || ts12.isExportDeclaration(statement) ? statement.moduleSpecifier : undefined;
|
|
3330
|
+
if (specifier === undefined || !ts12.isStringLiteral(specifier)) {
|
|
3143
3331
|
continue;
|
|
3144
3332
|
}
|
|
3145
|
-
const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) =>
|
|
3333
|
+
const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts12.isSourceFile(declaration));
|
|
3146
3334
|
if (target === undefined || target.isDeclarationFile) {
|
|
3147
3335
|
continue;
|
|
3148
3336
|
}
|
|
@@ -3195,7 +3383,7 @@ function withResolvedRequire(statement, paths) {
|
|
|
3195
3383
|
if (resolved === argument.value) {
|
|
3196
3384
|
return statement;
|
|
3197
3385
|
}
|
|
3198
|
-
return createVariableDeclarationStatement3(
|
|
3386
|
+
return createVariableDeclarationStatement3(createIdentifier5(name.text), createCallExpression5(createIdentifier5("require"), [createStringLiteral4(resolved)]));
|
|
3199
3387
|
}
|
|
3200
3388
|
function copiedPrelude(halves, importBindings) {
|
|
3201
3389
|
const needed = new Set(importBindings);
|
|
@@ -3248,7 +3436,7 @@ function isHoistedNameDeclaration(statement) {
|
|
|
3248
3436
|
return isVariableDeclarationStatement(statement) && statement.right === undefined;
|
|
3249
3437
|
}
|
|
3250
3438
|
function internalsField(name) {
|
|
3251
|
-
return
|
|
3439
|
+
return createTableIndexExpression3(createTableIndexExpression3(exportsIdentifier(), createStringLiteral4(COMPANION_INTERNAL_FIELD)), createStringLiteral4(name));
|
|
3252
3440
|
}
|
|
3253
3441
|
function requireInsertionPoint(script, reads) {
|
|
3254
3442
|
let index = 0;
|
|
@@ -3311,11 +3499,11 @@ function createCompanionEmitPlugin() {
|
|
|
3311
3499
|
return statements;
|
|
3312
3500
|
}
|
|
3313
3501
|
const visitors = {
|
|
3314
|
-
[
|
|
3315
|
-
[
|
|
3316
|
-
[
|
|
3317
|
-
[
|
|
3318
|
-
[
|
|
3502
|
+
[ts12.SyntaxKind.VariableStatement]: capture,
|
|
3503
|
+
[ts12.SyntaxKind.FunctionDeclaration]: capture,
|
|
3504
|
+
[ts12.SyntaxKind.ClassDeclaration]: capture,
|
|
3505
|
+
[ts12.SyntaxKind.EnumDeclaration]: capture,
|
|
3506
|
+
[ts12.SyntaxKind.ExportDeclaration]: capture
|
|
3319
3507
|
};
|
|
3320
3508
|
let configuredNoResolvePaths = [];
|
|
3321
3509
|
const plugin = {
|
|
@@ -3353,13 +3541,13 @@ function emitCompanion(program, emitHost, file, sourceFile, plan, owned, compani
|
|
|
3353
3541
|
const halves = split(luaAst.statements, owned);
|
|
3354
3542
|
const requirePaths = resolvedRequirePaths(sourceFile, program.getTypeChecker());
|
|
3355
3543
|
resolveMovedRequires(halves.companion, requirePaths);
|
|
3356
|
-
const closureTable = createTableExpression(plan.internals.map((name) => createTableFieldExpression(
|
|
3544
|
+
const closureTable = createTableExpression(plan.internals.map((name) => createTableFieldExpression(createIdentifier5(name), createStringLiteral4(name))));
|
|
3357
3545
|
const companionStatements = [
|
|
3358
3546
|
createVariableDeclarationStatement3(exportsIdentifier(), createTableExpression()),
|
|
3359
3547
|
...copiedPrelude(halves, plan.importBindings).map((statement) => withResolvedRequire(statement, requirePaths)),
|
|
3360
3548
|
...halves.companion,
|
|
3361
3549
|
...plan.internals.length > 0 ? [
|
|
3362
|
-
createAssignmentStatement2(
|
|
3550
|
+
createAssignmentStatement2(createTableIndexExpression3(exportsIdentifier(), createStringLiteral4(COMPANION_INTERNAL_FIELD)), closureTable)
|
|
3363
3551
|
] : [],
|
|
3364
3552
|
createReturnStatement2([exportsIdentifier()])
|
|
3365
3553
|
];
|
|
@@ -3367,8 +3555,8 @@ function emitCompanion(program, emitHost, file, sourceFile, plan, owned, compani
|
|
|
3367
3555
|
const insertAt = requireInsertionPoint(halves.script, reads);
|
|
3368
3556
|
const scriptStatements = [
|
|
3369
3557
|
...halves.script.slice(0, insertAt),
|
|
3370
|
-
createVariableDeclarationStatement3(exportsIdentifier(),
|
|
3371
|
-
...plan.internals.map((name) => createVariableDeclarationStatement3(
|
|
3558
|
+
createVariableDeclarationStatement3(exportsIdentifier(), createCallExpression5(createIdentifier5("require"), [createStringLiteral4(plan.requirePath)])),
|
|
3559
|
+
...plan.internals.map((name) => createVariableDeclarationStatement3(createIdentifier5(name), internalsField(name))),
|
|
3372
3560
|
...halves.script.slice(insertAt),
|
|
3373
3561
|
createReturnStatement2([exportsIdentifier()])
|
|
3374
3562
|
];
|
|
@@ -3384,7 +3572,7 @@ function emitCompanion(program, emitHost, file, sourceFile, plan, owned, compani
|
|
|
3384
3572
|
}
|
|
3385
3573
|
|
|
3386
3574
|
// src/editor-script-erasure.ts
|
|
3387
|
-
import * as
|
|
3575
|
+
import * as ts13 from "typescript";
|
|
3388
3576
|
import {
|
|
3389
3577
|
createReturnStatement as createReturnStatement3
|
|
3390
3578
|
} from "typescript-to-lua";
|
|
@@ -3404,7 +3592,7 @@ function resolveEditorFactoryExport(callee, checker) {
|
|
|
3404
3592
|
if (symbol === undefined) {
|
|
3405
3593
|
return;
|
|
3406
3594
|
}
|
|
3407
|
-
if (symbol.flags &
|
|
3595
|
+
if (symbol.flags & ts13.SymbolFlags.Alias) {
|
|
3408
3596
|
symbol = checker.getAliasedSymbol(symbol);
|
|
3409
3597
|
}
|
|
3410
3598
|
const name = symbol.getName();
|
|
@@ -3418,7 +3606,7 @@ function resolveEditorFactoryExport(callee, checker) {
|
|
|
3418
3606
|
return declaration.getSourceFile().fileName.includes(EDITOR_FACTORY_MODULE) ? name : undefined;
|
|
3419
3607
|
}
|
|
3420
3608
|
function lowerEditorFactoryCall(expression, context) {
|
|
3421
|
-
if (!
|
|
3609
|
+
if (!ts13.isCallExpression(expression)) {
|
|
3422
3610
|
return;
|
|
3423
3611
|
}
|
|
3424
3612
|
if (resolveEditorFactoryExport(expression.expression, context.checker) !== EDITOR_SCRIPT_FACTORY_NAME) {
|
|
@@ -3431,7 +3619,7 @@ function lowerEditorFactoryCall(expression, context) {
|
|
|
3431
3619
|
return [createReturnStatement3([context.transformExpression(module)])];
|
|
3432
3620
|
}
|
|
3433
3621
|
function isEditorFactoryOnlyImport(node) {
|
|
3434
|
-
if (!
|
|
3622
|
+
if (!ts13.isStringLiteral(node.moduleSpecifier) || !EDITOR_FACTORY_SPECIFIERS.has(node.moduleSpecifier.text)) {
|
|
3435
3623
|
return false;
|
|
3436
3624
|
}
|
|
3437
3625
|
const clause = node.importClause;
|
|
@@ -3442,7 +3630,7 @@ function isEditorFactoryOnlyImport(node) {
|
|
|
3442
3630
|
return false;
|
|
3443
3631
|
}
|
|
3444
3632
|
const bindings = clause.namedBindings;
|
|
3445
|
-
if (bindings === undefined || !
|
|
3633
|
+
if (bindings === undefined || !ts13.isNamedImports(bindings)) {
|
|
3446
3634
|
return false;
|
|
3447
3635
|
}
|
|
3448
3636
|
const runtime = bindings.elements.filter((element) => !element.isTypeOnly);
|
|
@@ -3453,7 +3641,7 @@ function isEditorFactoryOnlyImport(node) {
|
|
|
3453
3641
|
}
|
|
3454
3642
|
var editorScriptErasurePlugin = {
|
|
3455
3643
|
visitors: {
|
|
3456
|
-
[
|
|
3644
|
+
[ts13.SyntaxKind.ExportAssignment]: (node, context) => {
|
|
3457
3645
|
if (!node.isExportEquals) {
|
|
3458
3646
|
const lowered = lowerEditorFactoryCall(node.expression, context);
|
|
3459
3647
|
if (lowered !== undefined) {
|
|
@@ -3462,14 +3650,14 @@ var editorScriptErasurePlugin = {
|
|
|
3462
3650
|
}
|
|
3463
3651
|
return context.superTransformStatements(node);
|
|
3464
3652
|
},
|
|
3465
|
-
[
|
|
3653
|
+
[ts13.SyntaxKind.CallExpression]: (node, context) => {
|
|
3466
3654
|
const command = node.arguments[0];
|
|
3467
3655
|
if (command !== undefined && resolveEditorFactoryExport(node.expression, context.checker) === EDITOR_COMMAND_FACTORY_NAME) {
|
|
3468
3656
|
return context.transformExpression(command);
|
|
3469
3657
|
}
|
|
3470
3658
|
return context.superTransformExpression(node);
|
|
3471
3659
|
},
|
|
3472
|
-
[
|
|
3660
|
+
[ts13.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
|
|
3473
3661
|
}
|
|
3474
3662
|
};
|
|
3475
3663
|
|
|
@@ -3480,17 +3668,17 @@ import * as path3 from "node:path";
|
|
|
3480
3668
|
import * as tstl2 from "typescript-to-lua";
|
|
3481
3669
|
|
|
3482
3670
|
// src/go-property-direct-call.ts
|
|
3483
|
-
import * as
|
|
3671
|
+
import * as ts14 from "typescript";
|
|
3484
3672
|
var GO_PROPERTY_DIRECT_CALL_MESSAGE = "`go.property` called directly is deprecated; declare the property in `defineScript({ properties })` so it types onto `self` (the transpiler emits the registration for you).";
|
|
3485
3673
|
function findDirectGoPropertyCalls(sourceFile) {
|
|
3486
3674
|
const calls = [];
|
|
3487
3675
|
const visit = (node) => {
|
|
3488
|
-
if (
|
|
3676
|
+
if (ts14.isCallExpression(node) && ts14.isPropertyAccessExpression(node.expression) && node.expression.name.text === "property" && ts14.isIdentifier(node.expression.expression) && node.expression.expression.text === "go") {
|
|
3489
3677
|
calls.push(node);
|
|
3490
3678
|
}
|
|
3491
|
-
|
|
3679
|
+
ts14.forEachChild(node, visit);
|
|
3492
3680
|
};
|
|
3493
|
-
|
|
3681
|
+
ts14.forEachChild(sourceFile, visit);
|
|
3494
3682
|
return calls;
|
|
3495
3683
|
}
|
|
3496
3684
|
|
|
@@ -3650,6 +3838,7 @@ function collectOutputs(transpiledFiles, diagnostics, userKeys, emittedCompanion
|
|
|
3650
3838
|
}
|
|
3651
3839
|
}
|
|
3652
3840
|
const hsm = hsmClosure([...Object.values(lua), ...Object.values(companions)], compileHsmModules);
|
|
3841
|
+
const hsmSourceMaps = hsm === undefined ? undefined : selectHsmSourceMaps(Object.keys(hsm));
|
|
3653
3842
|
return {
|
|
3654
3843
|
lua,
|
|
3655
3844
|
sourceMaps,
|
|
@@ -3657,9 +3846,21 @@ function collectOutputs(transpiledFiles, diagnostics, userKeys, emittedCompanion
|
|
|
3657
3846
|
...Object.keys(companions).length > 0 ? { companions } : {},
|
|
3658
3847
|
...lualib !== undefined ? { lualib } : {},
|
|
3659
3848
|
...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {},
|
|
3660
|
-
...hsm !== undefined ? { hsmModules: hsm } : {}
|
|
3849
|
+
...hsm !== undefined ? { hsmModules: hsm } : {},
|
|
3850
|
+
...hsmSourceMaps !== undefined ? { hsmSourceMaps } : {}
|
|
3661
3851
|
};
|
|
3662
3852
|
}
|
|
3853
|
+
function selectHsmSourceMaps(names) {
|
|
3854
|
+
const maps = compileHsmSourceMaps();
|
|
3855
|
+
const selected = {};
|
|
3856
|
+
for (const name of names) {
|
|
3857
|
+
const map = maps[name];
|
|
3858
|
+
if (map !== undefined) {
|
|
3859
|
+
selected[name] = map;
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
return selected;
|
|
3863
|
+
}
|
|
3663
3864
|
function transpileVirtual(files, companionEmit, overrides = {}) {
|
|
3664
3865
|
return tstl2.transpileVirtualProject({ ...AMBIENT_FILES, ...files }, {
|
|
3665
3866
|
luaTarget: tstl2.LuaTarget.Lua51,
|
|
@@ -3673,6 +3874,7 @@ function transpileVirtual(files, companionEmit, overrides = {}) {
|
|
|
3673
3874
|
{ plugin: editorScriptErasurePlugin },
|
|
3674
3875
|
{ plugin: messageGuardLoweringPlugin },
|
|
3675
3876
|
{ plugin: windowEventGuardLoweringPlugin },
|
|
3877
|
+
{ plugin: physicsEventGuardLoweringPlugin },
|
|
3676
3878
|
{ plugin: messageDispatchLoweringPlugin },
|
|
3677
3879
|
{ plugin: timersLoweringPlugin },
|
|
3678
3880
|
{ plugin: hsmLoweringPlugin },
|
|
@@ -3693,6 +3895,12 @@ function requiresLualib(lua) {
|
|
|
3693
3895
|
return scanEmittedRequires(lua).some(({ path: requirePath }) => requirePath === "lualib_bundle");
|
|
3694
3896
|
}
|
|
3695
3897
|
function compileHsmModules() {
|
|
3898
|
+
return compileHsm().lua;
|
|
3899
|
+
}
|
|
3900
|
+
function compileHsmSourceMaps() {
|
|
3901
|
+
return compileHsm().sourceMaps;
|
|
3902
|
+
}
|
|
3903
|
+
function compileHsm() {
|
|
3696
3904
|
if (compiledHsm !== undefined) {
|
|
3697
3905
|
return compiledHsm;
|
|
3698
3906
|
}
|
|
@@ -3707,6 +3915,7 @@ function compileHsmModules() {
|
|
|
3707
3915
|
const result = transpileVirtual(files, createCompanionEmitPlugin(), { removeComments: true });
|
|
3708
3916
|
const problems = result.diagnostics.map((d) => `${d.file?.fileName ?? "(project)"}: ${flattenDiagnosticMessage(d.messageText)}`);
|
|
3709
3917
|
const lua = {};
|
|
3918
|
+
const sourceMaps = {};
|
|
3710
3919
|
for (const file of result.transpiledFiles) {
|
|
3711
3920
|
if (isLualibBundle(file)) {
|
|
3712
3921
|
continue;
|
|
@@ -3720,14 +3929,17 @@ function compileHsmModules() {
|
|
|
3720
3929
|
problems.push(`the compiled ${name} module requires lualib_bundle`);
|
|
3721
3930
|
}
|
|
3722
3931
|
lua[name] = file.lua;
|
|
3932
|
+
if (typeof file.luaSourceMap === "string") {
|
|
3933
|
+
sourceMaps[name] = file.luaSourceMap;
|
|
3934
|
+
}
|
|
3723
3935
|
}
|
|
3724
3936
|
if (problems.length > 0) {
|
|
3725
3937
|
throw new Error(`@defold-typescript/transpiler: the hsm library does not compile:
|
|
3726
3938
|
${problems.join(`
|
|
3727
3939
|
`)}`);
|
|
3728
3940
|
}
|
|
3729
|
-
compiledHsm = lua;
|
|
3730
|
-
return
|
|
3941
|
+
compiledHsm = { lua, sourceMaps };
|
|
3942
|
+
return compiledHsm;
|
|
3731
3943
|
}
|
|
3732
3944
|
function transpile(source) {
|
|
3733
3945
|
const project = transpileProject({ files: { "main.ts": source } });
|
|
@@ -3753,6 +3965,7 @@ function compilerOptions(companionEmit) {
|
|
|
3753
3965
|
{ plugin: editorScriptErasurePlugin },
|
|
3754
3966
|
{ plugin: messageGuardLoweringPlugin },
|
|
3755
3967
|
{ plugin: windowEventGuardLoweringPlugin },
|
|
3968
|
+
{ plugin: physicsEventGuardLoweringPlugin },
|
|
3756
3969
|
{ plugin: messageDispatchLoweringPlugin },
|
|
3757
3970
|
{ plugin: timersLoweringPlugin },
|
|
3758
3971
|
{ plugin: hsmLoweringPlugin },
|
|
@@ -3799,7 +4012,7 @@ function createTranspileSession() {
|
|
|
3799
4012
|
if (cached) {
|
|
3800
4013
|
return cached;
|
|
3801
4014
|
}
|
|
3802
|
-
const created =
|
|
4015
|
+
const created = ts15.createSourceFile(fileName, content, ts15.ScriptTarget.Latest, false);
|
|
3803
4016
|
sourceFileCache.set(normalized, created);
|
|
3804
4017
|
return created;
|
|
3805
4018
|
}
|
|
@@ -3818,7 +4031,7 @@ function createTranspileSession() {
|
|
|
3818
4031
|
return cached;
|
|
3819
4032
|
}
|
|
3820
4033
|
const fileContent = readFileSync2(filePath, "utf8");
|
|
3821
|
-
const created =
|
|
4034
|
+
const created = ts15.createSourceFile(filePath, fileContent, ts15.ScriptTarget.Latest, false);
|
|
3822
4035
|
libCache.set(fileName, created);
|
|
3823
4036
|
return created;
|
|
3824
4037
|
}
|
|
@@ -3831,10 +4044,10 @@ function createTranspileSession() {
|
|
|
3831
4044
|
return AMBIENT_FILES[normalized];
|
|
3832
4045
|
}
|
|
3833
4046
|
const host = {
|
|
3834
|
-
fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined ||
|
|
4047
|
+
fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts15.sys.fileExists(fileName),
|
|
3835
4048
|
getCanonicalFileName: (fileName) => fileName,
|
|
3836
4049
|
getCurrentDirectory: () => "",
|
|
3837
|
-
getDefaultLibFileName:
|
|
4050
|
+
getDefaultLibFileName: ts15.getDefaultLibFileName,
|
|
3838
4051
|
readFile: () => "",
|
|
3839
4052
|
getNewLine: () => `
|
|
3840
4053
|
`,
|
|
@@ -3856,15 +4069,15 @@ function createTranspileSession() {
|
|
|
3856
4069
|
const userKeys = new Set(userFiles.keys());
|
|
3857
4070
|
const rootNames = [...Object.keys(AMBIENT_FILES).map(normalizeSlashes), ...userKeys];
|
|
3858
4071
|
const companionEmit = createCompanionEmitPlugin();
|
|
3859
|
-
program =
|
|
3860
|
-
const preEmitDiagnostics =
|
|
4072
|
+
program = ts15.createProgram(rootNames, compilerOptions(companionEmit), host, program);
|
|
4073
|
+
const preEmitDiagnostics = ts15.getPreEmitDiagnostics(program);
|
|
3861
4074
|
const collector = createOutputCollector();
|
|
3862
4075
|
const { diagnostics: transpileDiagnostics } = new tstl3.Transpiler().emit({
|
|
3863
4076
|
program,
|
|
3864
4077
|
writeFile: collector.writeFile
|
|
3865
4078
|
});
|
|
3866
4079
|
const diagnostics = [
|
|
3867
|
-
...
|
|
4080
|
+
...ts15.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
|
|
3868
4081
|
];
|
|
3869
4082
|
return collectOutputs(collector.files, diagnostics, userKeys, companionEmit.companions);
|
|
3870
4083
|
}
|
|
@@ -3874,7 +4087,7 @@ function createTranspileSession() {
|
|
|
3874
4087
|
};
|
|
3875
4088
|
}
|
|
3876
4089
|
// src/text-script-property.ts
|
|
3877
|
-
import * as
|
|
4090
|
+
import * as ts16 from "typescript";
|
|
3878
4091
|
function findTextScriptProperties(program, fileNames) {
|
|
3879
4092
|
const checker = program.getTypeChecker();
|
|
3880
4093
|
const findings = [];
|
|
@@ -3885,7 +4098,7 @@ function findTextScriptProperties(program, fileNames) {
|
|
|
3885
4098
|
}
|
|
3886
4099
|
const located = [];
|
|
3887
4100
|
const visit = (node) => {
|
|
3888
|
-
if (
|
|
4101
|
+
if (ts16.isCallExpression(node)) {
|
|
3889
4102
|
const hooks = factoryHooks(node, checker);
|
|
3890
4103
|
for (const property of hooks?.properties ?? []) {
|
|
3891
4104
|
if (!isPropertiesHook(property)) {
|
|
@@ -3898,7 +4111,7 @@ function findTextScriptProperties(program, fileNames) {
|
|
|
3898
4111
|
}
|
|
3899
4112
|
}
|
|
3900
4113
|
}
|
|
3901
|
-
|
|
4114
|
+
ts16.forEachChild(node, visit);
|
|
3902
4115
|
};
|
|
3903
4116
|
visit(sourceFile);
|
|
3904
4117
|
for (const call of findDirectGoPropertyCalls(sourceFile)) {
|
|
@@ -3907,7 +4120,7 @@ function findTextScriptProperties(program, fileNames) {
|
|
|
3907
4120
|
continue;
|
|
3908
4121
|
}
|
|
3909
4122
|
if (mayHoldString(checker.getTypeAtLocation(value), checker)) {
|
|
3910
|
-
const name =
|
|
4123
|
+
const name = ts16.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
|
|
3911
4124
|
located.push({ name, value });
|
|
3912
4125
|
}
|
|
3913
4126
|
}
|
|
@@ -3924,20 +4137,20 @@ function mayHoldString(type, checker, visited = new Set) {
|
|
|
3924
4137
|
return false;
|
|
3925
4138
|
}
|
|
3926
4139
|
visited.add(type);
|
|
3927
|
-
if (type.flags &
|
|
4140
|
+
if (type.flags & ts16.TypeFlags.StringLike) {
|
|
3928
4141
|
return true;
|
|
3929
4142
|
}
|
|
3930
4143
|
if (type.isUnionOrIntersection()) {
|
|
3931
4144
|
return type.types.some((member) => mayHoldString(member, checker, visited));
|
|
3932
4145
|
}
|
|
3933
|
-
if (type.flags &
|
|
4146
|
+
if (type.flags & ts16.TypeFlags.Instantiable) {
|
|
3934
4147
|
const constraint = checker.getBaseConstraintOfType(type);
|
|
3935
4148
|
return constraint !== undefined && constraint !== type ? mayHoldString(constraint, checker, visited) : false;
|
|
3936
4149
|
}
|
|
3937
4150
|
return false;
|
|
3938
4151
|
}
|
|
3939
4152
|
// src/url-address-slots.ts
|
|
3940
|
-
import * as
|
|
4153
|
+
import * as ts17 from "typescript";
|
|
3941
4154
|
var ADDRESS_CLASSES = {
|
|
3942
4155
|
"game-object": true,
|
|
3943
4156
|
component: true,
|
|
@@ -3956,7 +4169,7 @@ function isFragmentCaret(slot, position) {
|
|
|
3956
4169
|
return slot.fragmentStart !== -1 && position >= slot.fragmentStart;
|
|
3957
4170
|
}
|
|
3958
4171
|
function tableKey(checker, callee) {
|
|
3959
|
-
const symbol = checker.getSymbolAtLocation(
|
|
4172
|
+
const symbol = checker.getSymbolAtLocation(ts17.isIdentifier(callee) ? callee : callee.name);
|
|
3960
4173
|
if (!symbol)
|
|
3961
4174
|
return;
|
|
3962
4175
|
const fqn = checker.getFullyQualifiedName(symbol);
|
|
@@ -3964,43 +4177,43 @@ function tableKey(checker, callee) {
|
|
|
3964
4177
|
}
|
|
3965
4178
|
function parameterName(checker, call, index) {
|
|
3966
4179
|
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
3967
|
-
if (!declaration || !
|
|
4180
|
+
if (!declaration || !ts17.isFunctionLike(declaration))
|
|
3968
4181
|
return;
|
|
3969
4182
|
const parameter = declaration.parameters[index];
|
|
3970
|
-
if (!parameter || parameter.dotDotDotToken || !
|
|
4183
|
+
if (!parameter || parameter.dotDotDotToken || !ts17.isIdentifier(parameter.name))
|
|
3971
4184
|
return;
|
|
3972
4185
|
return parameter.name.text;
|
|
3973
4186
|
}
|
|
3974
4187
|
var EQUALITY_OPERATORS = new Set([
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
4188
|
+
ts17.SyntaxKind.EqualsEqualsEqualsToken,
|
|
4189
|
+
ts17.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
4190
|
+
ts17.SyntaxKind.EqualsEqualsToken,
|
|
4191
|
+
ts17.SyntaxKind.ExclamationEqualsToken
|
|
3979
4192
|
]);
|
|
3980
4193
|
function comparisonSatisfied(checker, entry, call) {
|
|
3981
4194
|
if (entry.comparedParameter === undefined)
|
|
3982
4195
|
return true;
|
|
3983
4196
|
let node = call;
|
|
3984
|
-
while (
|
|
4197
|
+
while (ts17.isParenthesizedExpression(node.parent))
|
|
3985
4198
|
node = node.parent;
|
|
3986
4199
|
const comparison = node.parent;
|
|
3987
|
-
if (!
|
|
4200
|
+
if (!ts17.isBinaryExpression(comparison))
|
|
3988
4201
|
return false;
|
|
3989
4202
|
if (!EQUALITY_OPERATORS.has(comparison.operatorToken.kind))
|
|
3990
4203
|
return false;
|
|
3991
4204
|
const other = comparison.left === node ? comparison.right : comparison.left;
|
|
3992
4205
|
const symbol = checker.getSymbolAtLocation(other);
|
|
3993
|
-
return (symbol?.declarations ?? []).some((declaration) =>
|
|
4206
|
+
return (symbol?.declarations ?? []).some((declaration) => ts17.isParameter(declaration) && ts17.isIdentifier(declaration.name) && declaration.name.text === entry.comparedParameter);
|
|
3994
4207
|
}
|
|
3995
4208
|
function classifiedEntryOfArgument(checker, table, argument) {
|
|
3996
4209
|
const call = argument.parent;
|
|
3997
|
-
if (!
|
|
4210
|
+
if (!ts17.isCallExpression(call))
|
|
3998
4211
|
return;
|
|
3999
4212
|
const argumentIndex = call.arguments.indexOf(argument);
|
|
4000
4213
|
if (argumentIndex === -1)
|
|
4001
4214
|
return;
|
|
4002
4215
|
const callee = call.expression;
|
|
4003
|
-
if (!
|
|
4216
|
+
if (!ts17.isPropertyAccessExpression(callee) && !ts17.isIdentifier(callee))
|
|
4004
4217
|
return;
|
|
4005
4218
|
const fqn = tableKey(checker, callee);
|
|
4006
4219
|
if (fqn === undefined)
|
|
@@ -4017,10 +4230,10 @@ function classifiedEntryOfArgument(checker, table, argument) {
|
|
|
4017
4230
|
}
|
|
4018
4231
|
function slotThroughHashedCall(checker, table, literal) {
|
|
4019
4232
|
const call = literal.parent;
|
|
4020
|
-
if (!
|
|
4233
|
+
if (!ts17.isCallExpression(call))
|
|
4021
4234
|
return;
|
|
4022
4235
|
const callee = call.expression;
|
|
4023
|
-
if (!
|
|
4236
|
+
if (!ts17.isPropertyAccessExpression(callee) && !ts17.isIdentifier(callee))
|
|
4024
4237
|
return;
|
|
4025
4238
|
if (tableKey(checker, callee) !== "hash")
|
|
4026
4239
|
return;
|
|
@@ -4038,24 +4251,24 @@ function addressTextOf(checker, entry, call) {
|
|
|
4038
4251
|
if (entry.addressParameter === undefined)
|
|
4039
4252
|
return;
|
|
4040
4253
|
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
4041
|
-
if (!declaration || !
|
|
4254
|
+
if (!declaration || !ts17.isFunctionLike(declaration))
|
|
4042
4255
|
return;
|
|
4043
|
-
const index = declaration.parameters.findIndex((parameter) => !parameter.dotDotDotToken &&
|
|
4256
|
+
const index = declaration.parameters.findIndex((parameter) => !parameter.dotDotDotToken && ts17.isIdentifier(parameter.name) && parameter.name.text === entry.addressParameter);
|
|
4044
4257
|
if (index === -1)
|
|
4045
4258
|
return;
|
|
4046
4259
|
const argument = call.arguments[index];
|
|
4047
|
-
return argument &&
|
|
4260
|
+
return argument && ts17.isStringLiteralLike(argument) ? argument.text : undefined;
|
|
4048
4261
|
}
|
|
4049
4262
|
function innermostLiteralAt(sourceFile, position) {
|
|
4050
4263
|
let found;
|
|
4051
4264
|
const visit = (node) => {
|
|
4052
4265
|
if (position < node.getStart(sourceFile) || position > node.getEnd())
|
|
4053
4266
|
return;
|
|
4054
|
-
if (
|
|
4267
|
+
if (ts17.isStringLiteralLike(node))
|
|
4055
4268
|
found = node;
|
|
4056
|
-
|
|
4269
|
+
ts17.forEachChild(node, visit);
|
|
4057
4270
|
};
|
|
4058
|
-
|
|
4271
|
+
ts17.forEachChild(sourceFile, visit);
|
|
4059
4272
|
return found;
|
|
4060
4273
|
}
|
|
4061
4274
|
function resolveClassifiedSlotAtPosition(input) {
|
|
@@ -4089,23 +4302,23 @@ function resolveClassifiedSlotAtPosition(input) {
|
|
|
4089
4302
|
};
|
|
4090
4303
|
}
|
|
4091
4304
|
// src/url-cross-world-address.ts
|
|
4092
|
-
import * as
|
|
4305
|
+
import * as ts19 from "typescript";
|
|
4093
4306
|
|
|
4094
4307
|
// src/url-address-literals.ts
|
|
4095
|
-
import * as
|
|
4308
|
+
import * as ts18 from "typescript";
|
|
4096
4309
|
function isAmbient2(fileName) {
|
|
4097
4310
|
return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
|
|
4098
4311
|
}
|
|
4099
4312
|
function referenceTargetSymbol(type) {
|
|
4100
|
-
if ((type.flags &
|
|
4313
|
+
if ((type.flags & ts18.TypeFlags.Object) === 0)
|
|
4101
4314
|
return;
|
|
4102
|
-
if ((type.objectFlags &
|
|
4315
|
+
if ((type.objectFlags & ts18.ObjectFlags.Reference) === 0)
|
|
4103
4316
|
return;
|
|
4104
4317
|
return type.target.symbol;
|
|
4105
4318
|
}
|
|
4106
4319
|
function ambientHashAliasTargets(checker, anchor) {
|
|
4107
4320
|
const targets = new Set;
|
|
4108
|
-
for (const symbol of checker.getSymbolsInScope(anchor,
|
|
4321
|
+
for (const symbol of checker.getSymbolsInScope(anchor, ts18.SymbolFlags.Type)) {
|
|
4109
4322
|
if (symbol.name !== "Hash")
|
|
4110
4323
|
continue;
|
|
4111
4324
|
const target = referenceTargetSymbol(checker.getDeclaredTypeOfSymbol(symbol));
|
|
@@ -4121,7 +4334,7 @@ function canonicalHashSymbols(checker, program) {
|
|
|
4121
4334
|
if (!anchor)
|
|
4122
4335
|
return canonical;
|
|
4123
4336
|
const aliased = ambientHashAliasTargets(checker, anchor);
|
|
4124
|
-
for (const symbol of checker.getSymbolsInScope(anchor,
|
|
4337
|
+
for (const symbol of checker.getSymbolsInScope(anchor, ts18.SymbolFlags.Function)) {
|
|
4125
4338
|
if (symbol.name !== "hash")
|
|
4126
4339
|
continue;
|
|
4127
4340
|
const declaration = symbol.declarations?.[0];
|
|
@@ -4143,7 +4356,7 @@ function hashedSourceOfType(checker, type, canonical) {
|
|
|
4143
4356
|
return source?.isStringLiteral() ? source.value : undefined;
|
|
4144
4357
|
}
|
|
4145
4358
|
function staticAddressTextOf(checker, node, canonical) {
|
|
4146
|
-
return
|
|
4359
|
+
return ts18.isStringLiteralLike(node) ? node.text : hashedSourceOfType(checker, checker.getTypeAtLocation(node), canonical);
|
|
4147
4360
|
}
|
|
4148
4361
|
|
|
4149
4362
|
// src/url-cross-world-address.ts
|
|
@@ -4167,7 +4380,7 @@ function checkCrossWorldAddresses(input) {
|
|
|
4167
4380
|
if (worlds.length === 0)
|
|
4168
4381
|
continue;
|
|
4169
4382
|
const visit = (node) => {
|
|
4170
|
-
if (
|
|
4383
|
+
if (ts19.isExpression(node)) {
|
|
4171
4384
|
const entry = addressEntryOfArgument(checker, table, node);
|
|
4172
4385
|
if (entry !== undefined && slotRejectsForeignSocket(entry)) {
|
|
4173
4386
|
const address = staticAddressTextOf(checker, node, canonical);
|
|
@@ -4184,14 +4397,14 @@ function checkCrossWorldAddresses(input) {
|
|
|
4184
4397
|
}
|
|
4185
4398
|
}
|
|
4186
4399
|
}
|
|
4187
|
-
|
|
4400
|
+
ts19.forEachChild(node, visit);
|
|
4188
4401
|
};
|
|
4189
|
-
|
|
4402
|
+
ts19.forEachChild(sourceFile, visit);
|
|
4190
4403
|
}
|
|
4191
4404
|
return findings;
|
|
4192
4405
|
}
|
|
4193
4406
|
// src/url-fragment-reachability.ts
|
|
4194
|
-
import * as
|
|
4407
|
+
import * as ts20 from "typescript";
|
|
4195
4408
|
function pathOfKey(key) {
|
|
4196
4409
|
const socket = socketOfAddress(key);
|
|
4197
4410
|
return socket === undefined ? key : key.slice(socket.length + 1);
|
|
@@ -4236,7 +4449,7 @@ function checkUrlFragmentReachability(input) {
|
|
|
4236
4449
|
if (isAmbient2(sourceFile.fileName))
|
|
4237
4450
|
continue;
|
|
4238
4451
|
const visit = (node) => {
|
|
4239
|
-
if (
|
|
4452
|
+
if (ts20.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
|
|
4240
4453
|
const text = staticAddressTextOf(checker, node, canonical);
|
|
4241
4454
|
if (text !== undefined) {
|
|
4242
4455
|
const hash = text.indexOf("#");
|
|
@@ -4255,9 +4468,9 @@ function checkUrlFragmentReachability(input) {
|
|
|
4255
4468
|
}
|
|
4256
4469
|
}
|
|
4257
4470
|
}
|
|
4258
|
-
|
|
4471
|
+
ts20.forEachChild(node, visit);
|
|
4259
4472
|
};
|
|
4260
|
-
|
|
4473
|
+
ts20.forEachChild(sourceFile, visit);
|
|
4261
4474
|
}
|
|
4262
4475
|
return { kind: "checked", findings };
|
|
4263
4476
|
}
|
|
@@ -4333,6 +4546,7 @@ export {
|
|
|
4333
4546
|
resolveClassifiedSlotAtPosition,
|
|
4334
4547
|
resolveHsmSourceDir,
|
|
4335
4548
|
rewriteEmittedRequires,
|
|
4549
|
+
scanEmittedRequires,
|
|
4336
4550
|
slotRejectsForeignSocket,
|
|
4337
4551
|
socketOfAddress,
|
|
4338
4552
|
stripIncludeBase,
|