@defold-typescript/transpiler 0.42.0 → 0.43.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.js CHANGED
@@ -1383,6 +1383,12 @@ function readGameProjectSetting(gameProjectText, section, key) {
1383
1383
  }
1384
1384
  return;
1385
1385
  }
1386
+ // src/hsm-builtin.ts
1387
+ import { existsSync, readdirSync } from "node:fs";
1388
+ import * as path from "node:path";
1389
+ import { fileURLToPath } from "node:url";
1390
+ import * as ts4 from "typescript";
1391
+
1386
1392
  // src/lua-require-scan.ts
1387
1393
  var PLACEHOLDER = "\x00";
1388
1394
  function longBracketLevel(src, open) {
@@ -1476,6 +1482,118 @@ function scanEmittedRequires(lua) {
1476
1482
  return sites;
1477
1483
  }
1478
1484
 
1485
+ // src/hsm-builtin.ts
1486
+ var HSM_MODULE_SPECIFIER = "@defold-typescript/types/hsm";
1487
+ var HSM_REQUIRE_ROOT = "defold_typescript_hsm";
1488
+ function hsmRequireName(name) {
1489
+ return `${HSM_REQUIRE_ROOT}.${name}`;
1490
+ }
1491
+ function hsmSpecifier(name) {
1492
+ return name === "index" ? HSM_MODULE_SPECIFIER : `${HSM_MODULE_SPECIFIER}/${name}`;
1493
+ }
1494
+ function defaultPackageRoot() {
1495
+ return path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
1496
+ }
1497
+ function hsmSourceFiles(dir) {
1498
+ return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".ts") && !entry.name.endsWith(".test.ts") && !entry.name.endsWith(".d.ts")).map((entry) => entry.name).sort();
1499
+ }
1500
+ function resolveHsmSourceDir(packageRoot = defaultPackageRoot()) {
1501
+ const workspace = path.join(packageRoot, "..", "hsm", "src");
1502
+ if (existsSync(workspace)) {
1503
+ return workspace;
1504
+ }
1505
+ const shipped = path.join(packageRoot, "dist", "hsm");
1506
+ if (existsSync(shipped)) {
1507
+ return shipped;
1508
+ }
1509
+ return null;
1510
+ }
1511
+ function requireHsmSourceDir() {
1512
+ const dir = resolveHsmSourceDir();
1513
+ if (dir === null) {
1514
+ throw new Error("@defold-typescript/transpiler: the hsm source is missing from this install; reinstall @defold-typescript/transpiler.");
1515
+ }
1516
+ return dir;
1517
+ }
1518
+ var modules;
1519
+ function hsmModules() {
1520
+ modules ??= hsmSourceFiles(requireHsmSourceDir()).map((file) => {
1521
+ const name = file.slice(0, -".ts".length);
1522
+ return { name, specifier: hsmSpecifier(name), requireName: hsmRequireName(name) };
1523
+ });
1524
+ return modules;
1525
+ }
1526
+ function hsmModuleOfRequire(requirePath) {
1527
+ if (!requirePath.startsWith(`${HSM_REQUIRE_ROOT}.`)) {
1528
+ return;
1529
+ }
1530
+ return hsmModules().find((module) => module.requireName === requirePath);
1531
+ }
1532
+ function isHsmRequireName(requirePath) {
1533
+ return hsmModuleOfRequire(requirePath) !== undefined;
1534
+ }
1535
+ function hsmModuleOfSpecifier(node) {
1536
+ if (node === undefined || !ts4.isStringLiteral(node)) {
1537
+ return;
1538
+ }
1539
+ const { text } = node;
1540
+ if (text !== HSM_MODULE_SPECIFIER && !text.startsWith(`${HSM_MODULE_SPECIFIER}/`)) {
1541
+ return;
1542
+ }
1543
+ return hsmModules().find((module) => module.specifier === text);
1544
+ }
1545
+ function requiredHsmNames(lua) {
1546
+ const names = [];
1547
+ for (const { path: requirePath } of scanEmittedRequires(lua)) {
1548
+ const module = hsmModuleOfRequire(requirePath);
1549
+ if (module !== undefined) {
1550
+ names.push(module.name);
1551
+ }
1552
+ }
1553
+ return names;
1554
+ }
1555
+ function hsmClosure(chunks, compile) {
1556
+ const pending = [];
1557
+ for (const lua of chunks) {
1558
+ pending.push(...requiredHsmNames(lua));
1559
+ }
1560
+ if (pending.length === 0) {
1561
+ return;
1562
+ }
1563
+ const compiled = compile();
1564
+ const selected = {};
1565
+ for (let name = pending.pop();name !== undefined; name = pending.pop()) {
1566
+ const lua = compiled[name];
1567
+ if (name in selected || lua === undefined) {
1568
+ continue;
1569
+ }
1570
+ selected[name] = lua;
1571
+ pending.push(...requiredHsmNames(lua));
1572
+ }
1573
+ return Object.fromEntries(Object.entries(selected).sort(([a], [b]) => a.localeCompare(b)));
1574
+ }
1575
+ function lowerSpecifier(module) {
1576
+ return ts4.factory.createStringLiteral(`@NoResolution:${module.requireName}`);
1577
+ }
1578
+ var hsmLoweringPlugin = {
1579
+ visitors: {
1580
+ [ts4.SyntaxKind.ImportDeclaration]: (node, context) => {
1581
+ const module = hsmModuleOfSpecifier(node.moduleSpecifier);
1582
+ if (module === undefined) {
1583
+ return context.superTransformStatements(node);
1584
+ }
1585
+ return context.superTransformStatements(ts4.factory.updateImportDeclaration(node, node.modifiers, node.importClause, lowerSpecifier(module), node.attributes));
1586
+ },
1587
+ [ts4.SyntaxKind.ExportDeclaration]: (node, context) => {
1588
+ const module = hsmModuleOfSpecifier(node.moduleSpecifier);
1589
+ if (module === undefined) {
1590
+ return context.superTransformStatements(node);
1591
+ }
1592
+ return context.superTransformStatements(ts4.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, lowerSpecifier(module), node.attributes));
1593
+ }
1594
+ }
1595
+ };
1596
+
1479
1597
  // src/timers-runtime.ts
1480
1598
  var TIMERS_MODULE_SPECIFIER = "@defold-typescript/types/timers";
1481
1599
  var TIMERS_REQUIRE_NAME = "defold_typescript_timers";
@@ -1530,7 +1648,7 @@ function findEmittedRequires(lua) {
1530
1648
  const found = [];
1531
1649
  const seen = new Set;
1532
1650
  for (const { path } of scanEmittedRequires(lua)) {
1533
- if (GENERATED_RUNTIME_REQUIRES.has(path) || seen.has(path)) {
1651
+ if (GENERATED_RUNTIME_REQUIRES.has(path) || isHsmRequireName(path) || seen.has(path)) {
1534
1652
  continue;
1535
1653
  }
1536
1654
  seen.add(path);
@@ -1989,20 +2107,20 @@ function readLibrarySceneDocuments(host, projectRoot, extensions = LIBRARY_SCENE
1989
2107
  return { documents, unreadable };
1990
2108
  }
1991
2109
  // src/main-entry-factory-imports.ts
1992
- import * as ts4 from "typescript";
2110
+ import * as ts5 from "typescript";
1993
2111
  function findMainEntryFactoryImports(fileName, source) {
1994
- const sourceFile = ts4.createSourceFile(fileName, source, ts4.ScriptTarget.Latest, true);
2112
+ const sourceFile = ts5.createSourceFile(fileName, source, ts5.ScriptTarget.Latest, true);
1995
2113
  const factories = [];
1996
2114
  for (const statement of sourceFile.statements) {
1997
- if (!ts4.isImportDeclaration(statement)) {
2115
+ if (!ts5.isImportDeclaration(statement)) {
1998
2116
  continue;
1999
2117
  }
2000
2118
  const specifier = statement.moduleSpecifier;
2001
- if (!ts4.isStringLiteral(specifier) || specifier.text !== FACTORY_MODULE) {
2119
+ if (!ts5.isStringLiteral(specifier) || specifier.text !== FACTORY_MODULE) {
2002
2120
  continue;
2003
2121
  }
2004
2122
  const bindings = statement.importClause?.namedBindings;
2005
- if (bindings === undefined || !ts4.isNamedImports(bindings)) {
2123
+ if (bindings === undefined || !ts5.isNamedImports(bindings)) {
2006
2124
  continue;
2007
2125
  }
2008
2126
  for (const element of bindings.elements) {
@@ -2015,7 +2133,7 @@ function findMainEntryFactoryImports(fileName, source) {
2015
2133
  return factories;
2016
2134
  }
2017
2135
  // src/output-paths.ts
2018
- import * as path from "node:path";
2136
+ import * as path2 from "node:path";
2019
2137
  var DEFAULT_INCLUDE = ["src/**/*.ts"];
2020
2138
  var SCRIPT_SUFFIX_BY_KIND = {
2021
2139
  script: ".ts.script",
@@ -2032,7 +2150,7 @@ function parseBuildConfig(raw) {
2032
2150
  function stripIncludeBase(pattern) {
2033
2151
  const firstWildcard = pattern.search(/[*?[]/);
2034
2152
  if (firstWildcard === -1) {
2035
- return pattern.endsWith("/") ? pattern : `${path.posix.dirname(pattern)}/`;
2153
+ return pattern.endsWith("/") ? pattern : `${path2.posix.dirname(pattern)}/`;
2036
2154
  }
2037
2155
  const upToWildcard = pattern.slice(0, firstWildcard);
2038
2156
  const lastSlash = upToWildcard.lastIndexOf("/");
@@ -2043,7 +2161,7 @@ function projectRelativeBase(pattern) {
2043
2161
  if (ABSOLUTE_SPELLING_RE.test(pattern)) {
2044
2162
  return;
2045
2163
  }
2046
- const base = path.posix.normalize(stripIncludeBase(pattern.split("\\").join("/")));
2164
+ const base = path2.posix.normalize(stripIncludeBase(pattern.split("\\").join("/")));
2047
2165
  if (base === ".." || base.startsWith("../")) {
2048
2166
  return;
2049
2167
  }
@@ -2056,7 +2174,7 @@ function relUnderOutDir(rel, config) {
2056
2174
  }
2057
2175
  const includeBase = include.map(stripIncludeBase).filter((base) => rel.startsWith(base)).sort((a, b) => b.length - a.length)[0] ?? "";
2058
2176
  const relUnderBase = rel.slice(includeBase.length);
2059
- return path.posix.join(outDir, relUnderBase);
2177
+ return path2.posix.join(outDir, relUnderBase);
2060
2178
  }
2061
2179
  function requirePathForRel(rel) {
2062
2180
  const segments = rel.split("/").filter((segment) => segment !== "" && segment !== "." && segment !== "..");
@@ -2075,16 +2193,16 @@ function computeOutputRel(rel, config, kind) {
2075
2193
  return baseRel.replace(/\.ts$/, SCRIPT_SUFFIX_BY_KIND[kind]);
2076
2194
  }
2077
2195
  // src/program-diagnostics.ts
2078
- import * as ts9 from "typescript";
2196
+ import * as ts10 from "typescript";
2079
2197
  import * as tstl from "typescript-to-lua";
2080
2198
 
2081
2199
  // src/message-guard-lowering.ts
2082
- import * as ts5 from "typescript";
2200
+ import * as ts6 from "typescript";
2083
2201
  import {
2084
2202
  createBinaryExpression as createBinaryExpression3,
2085
2203
  createCallExpression as createCallExpression3,
2086
2204
  createIdentifier as createIdentifier3,
2087
- SyntaxKind as SyntaxKind7
2205
+ SyntaxKind as SyntaxKind8
2088
2206
  } from "typescript-to-lua";
2089
2207
  var GUARD_MODULE = "@defold-typescript/types";
2090
2208
  var GUARD_NAME = "isMessage";
@@ -2093,7 +2211,7 @@ function resolvesToGuardExport(callee, checker) {
2093
2211
  if (symbol === undefined) {
2094
2212
  return false;
2095
2213
  }
2096
- if (symbol.flags & ts5.SymbolFlags.Alias) {
2214
+ if (symbol.flags & ts6.SymbolFlags.Alias) {
2097
2215
  symbol = checker.getAliasedSymbol(symbol);
2098
2216
  }
2099
2217
  if (symbol.getName() !== GUARD_NAME) {
@@ -2107,12 +2225,12 @@ function resolvesToGuardExport(callee, checker) {
2107
2225
  }
2108
2226
  var messageGuardLoweringPlugin = {
2109
2227
  visitors: {
2110
- [ts5.SyntaxKind.CallExpression]: (node, context) => {
2228
+ [ts6.SyntaxKind.CallExpression]: (node, context) => {
2111
2229
  const [messageIdArg, , expectedArg] = node.arguments;
2112
2230
  if (node.arguments.length === 3 && messageIdArg !== undefined && expectedArg !== undefined && resolvesToGuardExport(node.expression, context.checker)) {
2113
2231
  const messageId = context.transformExpression(messageIdArg);
2114
2232
  const expected = context.transformExpression(expectedArg);
2115
- return createBinaryExpression3(messageId, createCallExpression3(createIdentifier3("hash"), [expected]), SyntaxKind7.EqualityOperator, node);
2233
+ return createBinaryExpression3(messageId, createCallExpression3(createIdentifier3("hash"), [expected]), SyntaxKind8.EqualityOperator, node);
2116
2234
  }
2117
2235
  return context.superTransformExpression(node);
2118
2236
  }
@@ -2120,37 +2238,37 @@ var messageGuardLoweringPlugin = {
2120
2238
  };
2121
2239
 
2122
2240
  // src/timers-lowering.ts
2123
- import * as ts6 from "typescript";
2241
+ import * as ts7 from "typescript";
2124
2242
  import { LuaLibFeature } from "typescript-to-lua";
2125
2243
  function isTimersSpecifier(node) {
2126
- return ts6.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
2244
+ return ts7.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
2127
2245
  }
2128
2246
  function importsTimersModule(sourceFile) {
2129
- return sourceFile.statements.some((statement) => ts6.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
2247
+ return sourceFile.statements.some((statement) => ts7.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
2130
2248
  }
2131
2249
  var TIMERS_REQUIRE_PATH = `@NoResolution:${TIMERS_REQUIRE_NAME}`;
2132
2250
  var timersLoweringPlugin = {
2133
2251
  visitors: {
2134
- [ts6.SyntaxKind.ImportDeclaration]: (node, context) => {
2252
+ [ts7.SyntaxKind.ImportDeclaration]: (node, context) => {
2135
2253
  if (!isTimersSpecifier(node.moduleSpecifier)) {
2136
2254
  return context.superTransformStatements(node);
2137
2255
  }
2138
2256
  context.usedLuaLibFeatures.add(LuaLibFeature.Promise);
2139
2257
  context.usedLuaLibFeatures.add(LuaLibFeature.New);
2140
- const rewritten = ts6.factory.updateImportDeclaration(node, node.modifiers, node.importClause, ts6.factory.createStringLiteral(TIMERS_REQUIRE_PATH), node.attributes);
2258
+ const rewritten = ts7.factory.updateImportDeclaration(node, node.modifiers, node.importClause, ts7.factory.createStringLiteral(TIMERS_REQUIRE_PATH), node.attributes);
2141
2259
  return context.superTransformStatements(rewritten);
2142
2260
  }
2143
2261
  }
2144
2262
  };
2145
2263
 
2146
2264
  // src/type-application-erasure.ts
2147
- import * as ts7 from "typescript";
2265
+ import * as ts8 from "typescript";
2148
2266
  var TYPE_APPLICATION_APIS = new Set(["go.get", "go.set"]);
2149
2267
  function isTypeApplication(call, checker) {
2150
2268
  if (call.arguments.length !== 0)
2151
2269
  return false;
2152
2270
  const declaration = checker.getResolvedSignature(call)?.declaration;
2153
- if (declaration === undefined || !ts7.isFunctionDeclaration(declaration))
2271
+ if (declaration === undefined || !ts8.isFunctionDeclaration(declaration))
2154
2272
  return false;
2155
2273
  if (declaration.parameters.length !== 0 || declaration.typeParameters === undefined)
2156
2274
  return false;
@@ -2164,7 +2282,7 @@ function isTypeApplication(call, checker) {
2164
2282
  }
2165
2283
  var typeApplicationErasurePlugin = {
2166
2284
  visitors: {
2167
- [ts7.SyntaxKind.CallExpression]: (node, context) => {
2285
+ [ts8.SyntaxKind.CallExpression]: (node, context) => {
2168
2286
  if (isTypeApplication(node, context.checker)) {
2169
2287
  return context.transformExpression(node.expression);
2170
2288
  }
@@ -2174,10 +2292,10 @@ var typeApplicationErasurePlugin = {
2174
2292
  };
2175
2293
 
2176
2294
  // src/window-event-guard-lowering.ts
2177
- import * as ts8 from "typescript";
2295
+ import * as ts9 from "typescript";
2178
2296
  import {
2179
2297
  createBinaryExpression as createBinaryExpression4,
2180
- SyntaxKind as SyntaxKind11
2298
+ SyntaxKind as SyntaxKind12
2181
2299
  } from "typescript-to-lua";
2182
2300
  var GUARD_MODULE2 = "@defold-typescript/types";
2183
2301
  var GUARD_NAME2 = "isWindowEvent";
@@ -2186,7 +2304,7 @@ function resolvesToGuardExport2(callee, checker) {
2186
2304
  if (symbol === undefined) {
2187
2305
  return false;
2188
2306
  }
2189
- if (symbol.flags & ts8.SymbolFlags.Alias) {
2307
+ if (symbol.flags & ts9.SymbolFlags.Alias) {
2190
2308
  symbol = checker.getAliasedSymbol(symbol);
2191
2309
  }
2192
2310
  if (symbol.getName() !== GUARD_NAME2) {
@@ -2200,12 +2318,12 @@ function resolvesToGuardExport2(callee, checker) {
2200
2318
  }
2201
2319
  var windowEventGuardLoweringPlugin = {
2202
2320
  visitors: {
2203
- [ts8.SyntaxKind.CallExpression]: (node, context) => {
2321
+ [ts9.SyntaxKind.CallExpression]: (node, context) => {
2204
2322
  const [eventArg, , expectedArg] = node.arguments;
2205
2323
  if (node.arguments.length === 3 && eventArg !== undefined && expectedArg !== undefined && resolvesToGuardExport2(node.expression, context.checker)) {
2206
2324
  const event = context.transformExpression(eventArg);
2207
2325
  const expected = context.transformExpression(expectedArg);
2208
- return createBinaryExpression4(event, expected, SyntaxKind11.EqualityOperator, node);
2326
+ return createBinaryExpression4(event, expected, SyntaxKind12.EqualityOperator, node);
2209
2327
  }
2210
2328
  return context.superTransformExpression(node);
2211
2329
  }
@@ -2226,7 +2344,7 @@ function isAmbient(fileName) {
2226
2344
  return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
2227
2345
  }
2228
2346
  function getProgramDiagnostics(program, sourceFile) {
2229
- const { diagnostics } = tstl.getProgramTranspileResult(ts9.sys, noopWriteFile, {
2347
+ const { diagnostics } = tstl.getProgramTranspileResult(ts10.sys, noopWriteFile, {
2230
2348
  program,
2231
2349
  plugins: LUA_PLUGINS,
2232
2350
  ...sourceFile ? { sourceFiles: [sourceFile] } : {}
@@ -2796,12 +2914,12 @@ function relativeAddressesFrom(index, context) {
2796
2914
  // src/session.ts
2797
2915
  import { readFileSync as readFileSync2 } from "node:fs";
2798
2916
  import { createRequire as createRequire2 } from "node:module";
2799
- import * as path3 from "node:path";
2800
- import * as ts13 from "typescript";
2917
+ import * as path4 from "node:path";
2918
+ import * as ts14 from "typescript";
2801
2919
  import * as tstl3 from "typescript-to-lua";
2802
2920
 
2803
2921
  // src/companion-emit.ts
2804
- import * as ts10 from "typescript";
2922
+ import * as ts11 from "typescript";
2805
2923
  import {
2806
2924
  createAssignmentStatement as createAssignmentStatement2,
2807
2925
  createCallExpression as createCallExpression4,
@@ -2824,7 +2942,7 @@ import {
2824
2942
  isMethodCallExpression,
2825
2943
  isRepeatStatement,
2826
2944
  isReturnStatement as isReturnStatement2,
2827
- isStringLiteral as isStringLiteral6,
2945
+ isStringLiteral as isStringLiteral7,
2828
2946
  isTableExpression,
2829
2947
  isVariableDeclarationStatement,
2830
2948
  LuaPrinter
@@ -2835,8 +2953,8 @@ function exportsIdentifier() {
2835
2953
  }
2836
2954
  function isRuntimeScriptSource(sourceFile, checker) {
2837
2955
  return sourceFile.statements.some((statement) => {
2838
- const expression = ts10.isExpressionStatement(statement) ? statement.expression : ts10.isExportAssignment(statement) && !statement.isExportEquals ? statement.expression : undefined;
2839
- return expression !== undefined && ts10.isCallExpression(expression) && resolvesToFactoryExport(expression.expression, checker);
2956
+ const expression = ts11.isExpressionStatement(statement) ? statement.expression : ts11.isExportAssignment(statement) && !statement.isExportEquals ? statement.expression : undefined;
2957
+ return expression !== undefined && ts11.isCallExpression(expression) && resolvesToFactoryExport(expression.expression, checker);
2840
2958
  });
2841
2959
  }
2842
2960
  function planFor(sourceFile, checker) {
@@ -2988,11 +3106,11 @@ function freeNames(statements) {
2988
3106
  function resolvedRequirePaths(sourceFile, checker) {
2989
3107
  const paths = new Map;
2990
3108
  for (const statement of sourceFile.statements) {
2991
- const specifier = ts10.isImportDeclaration(statement) || ts10.isExportDeclaration(statement) ? statement.moduleSpecifier : undefined;
2992
- if (specifier === undefined || !ts10.isStringLiteral(specifier)) {
3109
+ const specifier = ts11.isImportDeclaration(statement) || ts11.isExportDeclaration(statement) ? statement.moduleSpecifier : undefined;
3110
+ if (specifier === undefined || !ts11.isStringLiteral(specifier)) {
2993
3111
  continue;
2994
3112
  }
2995
- const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts10.isSourceFile(declaration));
3113
+ const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts11.isSourceFile(declaration));
2996
3114
  if (target === undefined || target.isDeclarationFile) {
2997
3115
  continue;
2998
3116
  }
@@ -3010,7 +3128,7 @@ function resolveMovedRequires(statements, paths) {
3010
3128
  return;
3011
3129
  }
3012
3130
  const [argument] = node.params;
3013
- if (argument === undefined || !isStringLiteral6(argument)) {
3131
+ if (argument === undefined || !isStringLiteral7(argument)) {
3014
3132
  return;
3015
3133
  }
3016
3134
  const resolved = paths.get(argument.value);
@@ -3033,7 +3151,7 @@ function withResolvedRequire(statement, paths) {
3033
3151
  return statement;
3034
3152
  }
3035
3153
  const [argument] = value.params;
3036
- if (argument === undefined || !isStringLiteral6(argument)) {
3154
+ if (argument === undefined || !isStringLiteral7(argument)) {
3037
3155
  return statement;
3038
3156
  }
3039
3157
  const resolved = paths.get(argument.value);
@@ -3156,11 +3274,11 @@ function createCompanionEmitPlugin() {
3156
3274
  return statements;
3157
3275
  }
3158
3276
  const visitors = {
3159
- [ts10.SyntaxKind.VariableStatement]: capture,
3160
- [ts10.SyntaxKind.FunctionDeclaration]: capture,
3161
- [ts10.SyntaxKind.ClassDeclaration]: capture,
3162
- [ts10.SyntaxKind.EnumDeclaration]: capture,
3163
- [ts10.SyntaxKind.ExportDeclaration]: capture
3277
+ [ts11.SyntaxKind.VariableStatement]: capture,
3278
+ [ts11.SyntaxKind.FunctionDeclaration]: capture,
3279
+ [ts11.SyntaxKind.ClassDeclaration]: capture,
3280
+ [ts11.SyntaxKind.EnumDeclaration]: capture,
3281
+ [ts11.SyntaxKind.ExportDeclaration]: capture
3164
3282
  };
3165
3283
  let configuredNoResolvePaths = [];
3166
3284
  const plugin = {
@@ -3229,7 +3347,7 @@ function emitCompanion(program, emitHost, file, sourceFile, plan, owned, compani
3229
3347
  }
3230
3348
 
3231
3349
  // src/editor-script-erasure.ts
3232
- import * as ts11 from "typescript";
3350
+ import * as ts12 from "typescript";
3233
3351
  import {
3234
3352
  createReturnStatement as createReturnStatement3
3235
3353
  } from "typescript-to-lua";
@@ -3249,7 +3367,7 @@ function resolveEditorFactoryExport(callee, checker) {
3249
3367
  if (symbol === undefined) {
3250
3368
  return;
3251
3369
  }
3252
- if (symbol.flags & ts11.SymbolFlags.Alias) {
3370
+ if (symbol.flags & ts12.SymbolFlags.Alias) {
3253
3371
  symbol = checker.getAliasedSymbol(symbol);
3254
3372
  }
3255
3373
  const name = symbol.getName();
@@ -3263,7 +3381,7 @@ function resolveEditorFactoryExport(callee, checker) {
3263
3381
  return declaration.getSourceFile().fileName.includes(EDITOR_FACTORY_MODULE) ? name : undefined;
3264
3382
  }
3265
3383
  function lowerEditorFactoryCall(expression, context) {
3266
- if (!ts11.isCallExpression(expression)) {
3384
+ if (!ts12.isCallExpression(expression)) {
3267
3385
  return;
3268
3386
  }
3269
3387
  if (resolveEditorFactoryExport(expression.expression, context.checker) !== EDITOR_SCRIPT_FACTORY_NAME) {
@@ -3276,7 +3394,7 @@ function lowerEditorFactoryCall(expression, context) {
3276
3394
  return [createReturnStatement3([context.transformExpression(module)])];
3277
3395
  }
3278
3396
  function isEditorFactoryOnlyImport(node) {
3279
- if (!ts11.isStringLiteral(node.moduleSpecifier) || !EDITOR_FACTORY_SPECIFIERS.has(node.moduleSpecifier.text)) {
3397
+ if (!ts12.isStringLiteral(node.moduleSpecifier) || !EDITOR_FACTORY_SPECIFIERS.has(node.moduleSpecifier.text)) {
3280
3398
  return false;
3281
3399
  }
3282
3400
  const clause = node.importClause;
@@ -3287,7 +3405,7 @@ function isEditorFactoryOnlyImport(node) {
3287
3405
  return false;
3288
3406
  }
3289
3407
  const bindings = clause.namedBindings;
3290
- if (bindings === undefined || !ts11.isNamedImports(bindings)) {
3408
+ if (bindings === undefined || !ts12.isNamedImports(bindings)) {
3291
3409
  return false;
3292
3410
  }
3293
3411
  const runtime = bindings.elements.filter((element) => !element.isTypeOnly);
@@ -3298,7 +3416,7 @@ function isEditorFactoryOnlyImport(node) {
3298
3416
  }
3299
3417
  var editorScriptErasurePlugin = {
3300
3418
  visitors: {
3301
- [ts11.SyntaxKind.ExportAssignment]: (node, context) => {
3419
+ [ts12.SyntaxKind.ExportAssignment]: (node, context) => {
3302
3420
  if (!node.isExportEquals) {
3303
3421
  const lowered = lowerEditorFactoryCall(node.expression, context);
3304
3422
  if (lowered !== undefined) {
@@ -3307,35 +3425,35 @@ var editorScriptErasurePlugin = {
3307
3425
  }
3308
3426
  return context.superTransformStatements(node);
3309
3427
  },
3310
- [ts11.SyntaxKind.CallExpression]: (node, context) => {
3428
+ [ts12.SyntaxKind.CallExpression]: (node, context) => {
3311
3429
  const command = node.arguments[0];
3312
3430
  if (command !== undefined && resolveEditorFactoryExport(node.expression, context.checker) === EDITOR_COMMAND_FACTORY_NAME) {
3313
3431
  return context.transformExpression(command);
3314
3432
  }
3315
3433
  return context.superTransformExpression(node);
3316
3434
  },
3317
- [ts11.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
3435
+ [ts12.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
3318
3436
  }
3319
3437
  };
3320
3438
 
3321
3439
  // src/transpile.ts
3322
- import { readdirSync, readFileSync } from "node:fs";
3440
+ import { readdirSync as readdirSync2, readFileSync } from "node:fs";
3323
3441
  import { createRequire } from "node:module";
3324
- import * as path2 from "node:path";
3442
+ import * as path3 from "node:path";
3325
3443
  import * as tstl2 from "typescript-to-lua";
3326
3444
 
3327
3445
  // src/go-property-direct-call.ts
3328
- import * as ts12 from "typescript";
3446
+ import * as ts13 from "typescript";
3329
3447
  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).";
3330
3448
  function findDirectGoPropertyCalls(sourceFile) {
3331
3449
  const calls = [];
3332
3450
  const visit = (node) => {
3333
- if (ts12.isCallExpression(node) && ts12.isPropertyAccessExpression(node.expression) && node.expression.name.text === "property" && ts12.isIdentifier(node.expression.expression) && node.expression.expression.text === "go") {
3451
+ if (ts13.isCallExpression(node) && ts13.isPropertyAccessExpression(node.expression) && node.expression.name.text === "property" && ts13.isIdentifier(node.expression.expression) && node.expression.expression.text === "go") {
3334
3452
  calls.push(node);
3335
3453
  }
3336
- ts12.forEachChild(node, visit);
3454
+ ts13.forEachChild(node, visit);
3337
3455
  };
3338
- ts12.forEachChild(sourceFile, visit);
3456
+ ts13.forEachChild(sourceFile, visit);
3339
3457
  return calls;
3340
3458
  }
3341
3459
 
@@ -3347,12 +3465,12 @@ function flattenDiagnosticMessage(text) {
3347
3465
  return flattenDiagnosticMessage(text.messageText);
3348
3466
  }
3349
3467
  var requireFromHere = createRequire(import.meta.url);
3350
- var TYPES_PKG_ROOT = path2.dirname(requireFromHere.resolve("@defold-typescript/types/package.json"));
3351
- var TSTL_LANG_EXT_ROOT = path2.dirname(requireFromHere.resolve("@typescript-to-lua/language-extensions/package.json"));
3468
+ var TYPES_PKG_ROOT = path3.dirname(requireFromHere.resolve("@defold-typescript/types/package.json"));
3469
+ var TSTL_LANG_EXT_ROOT = path3.dirname(requireFromHere.resolve("@typescript-to-lua/language-extensions/package.json"));
3352
3470
  function readAmbient(rel) {
3353
- return readFileSync(path2.join(TYPES_PKG_ROOT, rel), "utf8");
3471
+ return readFileSync(path3.join(TYPES_PKG_ROOT, rel), "utf8");
3354
3472
  }
3355
- var LUA_TYPES_ROOT = path2.dirname(createRequire(path2.join(TYPES_PKG_ROOT, "package.json")).resolve("lua-types/package.json"));
3473
+ var LUA_TYPES_ROOT = path3.dirname(createRequire(path3.join(TYPES_PKG_ROOT, "package.json")).resolve("lua-types/package.json"));
3356
3474
  var LUA_TYPES_ENTRY_FILES = ["5.1.d.ts", "special/jit-only.d.ts"];
3357
3475
  var REFERENCE_PATH_RE = /\/\/\/\s*<reference\s+path="([^"]+)"\s*\/>/g;
3358
3476
  function collectLuaTypesClosure() {
@@ -3361,14 +3479,14 @@ function collectLuaTypesClosure() {
3361
3479
  const key = `node_modules/lua-types/${rel}`;
3362
3480
  if (key in files)
3363
3481
  return;
3364
- const source = readFileSync(path2.join(LUA_TYPES_ROOT, rel), "utf8");
3482
+ const source = readFileSync(path3.join(LUA_TYPES_ROOT, rel), "utf8");
3365
3483
  files[key] = source;
3366
- const dir = path2.posix.dirname(rel);
3484
+ const dir = path3.posix.dirname(rel);
3367
3485
  for (const match of source.matchAll(REFERENCE_PATH_RE)) {
3368
3486
  const ref = match[1];
3369
3487
  if (!ref)
3370
3488
  continue;
3371
- visit(path2.posix.normalize(path2.posix.join(dir, ref)));
3489
+ visit(path3.posix.normalize(path3.posix.join(dir, ref)));
3372
3490
  }
3373
3491
  };
3374
3492
  for (const entry of LUA_TYPES_ENTRY_FILES)
@@ -3377,7 +3495,7 @@ function collectLuaTypesClosure() {
3377
3495
  }
3378
3496
  function buildAmbientFiles() {
3379
3497
  const files = {
3380
- "node_modules/@typescript-to-lua/language-extensions/index.d.ts": readFileSync(path2.join(TSTL_LANG_EXT_ROOT, "index.d.ts"), "utf8"),
3498
+ "node_modules/@typescript-to-lua/language-extensions/index.d.ts": readFileSync(path3.join(TSTL_LANG_EXT_ROOT, "index.d.ts"), "utf8"),
3381
3499
  "node_modules/@defold-typescript/types/src/core-types.ts": readAmbient("src/core-types.ts"),
3382
3500
  "node_modules/@defold-typescript/types/src/engine-globals.d.ts": readAmbient("src/engine-globals.d.ts"),
3383
3501
  "node_modules/@defold-typescript/types/src/go-overloads.d.ts": readAmbient("src/go-overloads.d.ts"),
@@ -3416,13 +3534,18 @@ export type { ScriptProperties, ScriptProperty } from "./src/lifecycle.js";
3416
3534
  ].join(`
3417
3535
  `)
3418
3536
  };
3537
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "hsm"))) {
3538
+ if (entry.endsWith(".d.ts")) {
3539
+ files[`node_modules/@defold-typescript/types/hsm/${entry}`] = readAmbient(`hsm/${entry}`);
3540
+ }
3541
+ }
3419
3542
  Object.assign(files, collectLuaTypesClosure());
3420
- for (const entry of readdirSync(path2.join(TYPES_PKG_ROOT, "generated"))) {
3543
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "generated"))) {
3421
3544
  if (entry.endsWith(".d.ts")) {
3422
3545
  files[`node_modules/@defold-typescript/types/generated/${entry}`] = readAmbient(`generated/${entry}`);
3423
3546
  }
3424
3547
  }
3425
- for (const entry of readdirSync(path2.join(TYPES_PKG_ROOT, "src"))) {
3548
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "src"))) {
3426
3549
  if (entry.endsWith(".d.ts")) {
3427
3550
  files[`node_modules/@defold-typescript/types/src/${entry}`] = readAmbient(`src/${entry}`);
3428
3551
  }
@@ -3489,20 +3612,19 @@ function collectOutputs(transpiledFiles, diagnostics, userKeys, emittedCompanion
3489
3612
  }
3490
3613
  }
3491
3614
  }
3615
+ const hsm = hsmClosure([...Object.values(lua), ...Object.values(companions)], compileHsmModules);
3492
3616
  return {
3493
3617
  lua,
3494
3618
  sourceMaps,
3495
3619
  diagnostics: collectedDiagnostics,
3496
3620
  ...Object.keys(companions).length > 0 ? { companions } : {},
3497
3621
  ...lualib !== undefined ? { lualib } : {},
3498
- ...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {}
3622
+ ...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {},
3623
+ ...hsm !== undefined ? { hsmModules: hsm } : {}
3499
3624
  };
3500
3625
  }
3501
- function transpileProject(input) {
3502
- const userKeys = new Set(Object.keys(input.files));
3503
- const merged = { ...AMBIENT_FILES, ...input.files };
3504
- const companionEmit = createCompanionEmitPlugin();
3505
- const result = tstl2.transpileVirtualProject(merged, {
3626
+ function transpileVirtual(files, companionEmit) {
3627
+ return tstl2.transpileVirtualProject({ ...AMBIENT_FILES, ...files }, {
3506
3628
  luaTarget: tstl2.LuaTarget.Lua51,
3507
3629
  sourceMap: true,
3508
3630
  lib: ["lib.es2022.d.ts"],
@@ -3515,12 +3637,53 @@ function transpileProject(input) {
3515
3637
  { plugin: windowEventGuardLoweringPlugin },
3516
3638
  { plugin: messageDispatchLoweringPlugin },
3517
3639
  { plugin: timersLoweringPlugin },
3640
+ { plugin: hsmLoweringPlugin },
3518
3641
  { plugin: typeApplicationErasurePlugin },
3519
3642
  { plugin: companionEmit.plugin }
3520
3643
  ]
3521
3644
  });
3645
+ }
3646
+ function transpileProject(input) {
3647
+ const userKeys = new Set(Object.keys(input.files));
3648
+ const companionEmit = createCompanionEmitPlugin();
3649
+ const result = transpileVirtual(input.files, companionEmit);
3522
3650
  return collectOutputs(result.transpiledFiles, result.diagnostics, userKeys, companionEmit.companions);
3523
3651
  }
3652
+ var compiledHsm;
3653
+ function compileHsmModules() {
3654
+ if (compiledHsm !== undefined) {
3655
+ return compiledHsm;
3656
+ }
3657
+ const sourceDir = requireHsmSourceDir();
3658
+ const nameByKey = new Map;
3659
+ const files = {};
3660
+ for (const { name } of hsmModules()) {
3661
+ const key = `${HSM_REQUIRE_ROOT}/${name}.ts`;
3662
+ nameByKey.set(key, name);
3663
+ files[key] = readFileSync(path3.join(sourceDir, `${name}.ts`), "utf8");
3664
+ }
3665
+ const result = transpileVirtual(files, createCompanionEmitPlugin());
3666
+ const problems = result.diagnostics.map((d) => `${d.file?.fileName ?? "(project)"}: ${flattenDiagnosticMessage(d.messageText)}`);
3667
+ const lua = {};
3668
+ for (const file of result.transpiledFiles) {
3669
+ if (isLualibBundle(file)) {
3670
+ problems.push("the compiled Lua requires lualib_bundle");
3671
+ continue;
3672
+ }
3673
+ const source = file.sourceFiles.find((s) => nameByKey.has(s.fileName));
3674
+ const name = source === undefined ? undefined : nameByKey.get(source.fileName);
3675
+ if (name !== undefined && typeof file.lua === "string") {
3676
+ lua[name] = file.lua;
3677
+ }
3678
+ }
3679
+ if (problems.length > 0) {
3680
+ throw new Error(`@defold-typescript/transpiler: the hsm library does not compile:
3681
+ ${problems.join(`
3682
+ `)}`);
3683
+ }
3684
+ compiledHsm = lua;
3685
+ return lua;
3686
+ }
3524
3687
  function transpile(source) {
3525
3688
  const project = transpileProject({ files: { "main.ts": source } });
3526
3689
  return {
@@ -3546,6 +3709,7 @@ function compilerOptions(companionEmit) {
3546
3709
  { plugin: windowEventGuardLoweringPlugin },
3547
3710
  { plugin: messageDispatchLoweringPlugin },
3548
3711
  { plugin: timersLoweringPlugin },
3712
+ { plugin: hsmLoweringPlugin },
3549
3713
  { plugin: typeApplicationErasurePlugin },
3550
3714
  { plugin: companionEmit.plugin }
3551
3715
  ]
@@ -3589,18 +3753,18 @@ function createTranspileSession() {
3589
3753
  if (cached) {
3590
3754
  return cached;
3591
3755
  }
3592
- const created = ts13.createSourceFile(fileName, content, ts13.ScriptTarget.Latest, false);
3756
+ const created = ts14.createSourceFile(fileName, content, ts14.ScriptTarget.Latest, false);
3593
3757
  sourceFileCache.set(normalized, created);
3594
3758
  return created;
3595
3759
  }
3596
3760
  let filePath;
3597
3761
  if (fileName.startsWith("lib.")) {
3598
- const typeScriptDir = path3.dirname(requireFromHere2.resolve("typescript"));
3599
- filePath = path3.join(typeScriptDir, fileName);
3762
+ const typeScriptDir = path4.dirname(requireFromHere2.resolve("typescript"));
3763
+ filePath = path4.join(typeScriptDir, fileName);
3600
3764
  }
3601
3765
  if (fileName.includes("language-extensions")) {
3602
3766
  const dtsName = fileName.replace(/(\.d)?(\.ts)$/, ".d.ts");
3603
- filePath = path3.resolve(dtsName);
3767
+ filePath = path4.resolve(dtsName);
3604
3768
  }
3605
3769
  if (filePath !== undefined) {
3606
3770
  const cached = libCache.get(fileName);
@@ -3608,7 +3772,7 @@ function createTranspileSession() {
3608
3772
  return cached;
3609
3773
  }
3610
3774
  const fileContent = readFileSync2(filePath, "utf8");
3611
- const created = ts13.createSourceFile(filePath, fileContent, ts13.ScriptTarget.Latest, false);
3775
+ const created = ts14.createSourceFile(filePath, fileContent, ts14.ScriptTarget.Latest, false);
3612
3776
  libCache.set(fileName, created);
3613
3777
  return created;
3614
3778
  }
@@ -3621,10 +3785,10 @@ function createTranspileSession() {
3621
3785
  return AMBIENT_FILES[normalized];
3622
3786
  }
3623
3787
  const host = {
3624
- fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts13.sys.fileExists(fileName),
3788
+ fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts14.sys.fileExists(fileName),
3625
3789
  getCanonicalFileName: (fileName) => fileName,
3626
3790
  getCurrentDirectory: () => "",
3627
- getDefaultLibFileName: ts13.getDefaultLibFileName,
3791
+ getDefaultLibFileName: ts14.getDefaultLibFileName,
3628
3792
  readFile: () => "",
3629
3793
  getNewLine: () => `
3630
3794
  `,
@@ -3646,15 +3810,15 @@ function createTranspileSession() {
3646
3810
  const userKeys = new Set(userFiles.keys());
3647
3811
  const rootNames = [...Object.keys(AMBIENT_FILES).map(normalizeSlashes), ...userKeys];
3648
3812
  const companionEmit = createCompanionEmitPlugin();
3649
- program = ts13.createProgram(rootNames, compilerOptions(companionEmit), host, program);
3650
- const preEmitDiagnostics = ts13.getPreEmitDiagnostics(program);
3813
+ program = ts14.createProgram(rootNames, compilerOptions(companionEmit), host, program);
3814
+ const preEmitDiagnostics = ts14.getPreEmitDiagnostics(program);
3651
3815
  const collector = createOutputCollector();
3652
3816
  const { diagnostics: transpileDiagnostics } = new tstl3.Transpiler().emit({
3653
3817
  program,
3654
3818
  writeFile: collector.writeFile
3655
3819
  });
3656
3820
  const diagnostics = [
3657
- ...ts13.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
3821
+ ...ts14.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
3658
3822
  ];
3659
3823
  return collectOutputs(collector.files, diagnostics, userKeys, companionEmit.companions);
3660
3824
  }
@@ -3664,7 +3828,7 @@ function createTranspileSession() {
3664
3828
  };
3665
3829
  }
3666
3830
  // src/text-script-property.ts
3667
- import * as ts14 from "typescript";
3831
+ import * as ts15 from "typescript";
3668
3832
  function findTextScriptProperties(program, fileNames) {
3669
3833
  const checker = program.getTypeChecker();
3670
3834
  const findings = [];
@@ -3675,7 +3839,7 @@ function findTextScriptProperties(program, fileNames) {
3675
3839
  }
3676
3840
  const located = [];
3677
3841
  const visit = (node) => {
3678
- if (ts14.isCallExpression(node)) {
3842
+ if (ts15.isCallExpression(node)) {
3679
3843
  const hooks = factoryHooks(node, checker);
3680
3844
  for (const property of hooks?.properties ?? []) {
3681
3845
  if (!isPropertiesHook(property)) {
@@ -3688,7 +3852,7 @@ function findTextScriptProperties(program, fileNames) {
3688
3852
  }
3689
3853
  }
3690
3854
  }
3691
- ts14.forEachChild(node, visit);
3855
+ ts15.forEachChild(node, visit);
3692
3856
  };
3693
3857
  visit(sourceFile);
3694
3858
  for (const call of findDirectGoPropertyCalls(sourceFile)) {
@@ -3697,7 +3861,7 @@ function findTextScriptProperties(program, fileNames) {
3697
3861
  continue;
3698
3862
  }
3699
3863
  if (mayHoldString(checker.getTypeAtLocation(value), checker)) {
3700
- const name = ts14.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
3864
+ const name = ts15.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
3701
3865
  located.push({ name, value });
3702
3866
  }
3703
3867
  }
@@ -3714,20 +3878,20 @@ function mayHoldString(type, checker, visited = new Set) {
3714
3878
  return false;
3715
3879
  }
3716
3880
  visited.add(type);
3717
- if (type.flags & ts14.TypeFlags.StringLike) {
3881
+ if (type.flags & ts15.TypeFlags.StringLike) {
3718
3882
  return true;
3719
3883
  }
3720
3884
  if (type.isUnionOrIntersection()) {
3721
3885
  return type.types.some((member) => mayHoldString(member, checker, visited));
3722
3886
  }
3723
- if (type.flags & ts14.TypeFlags.Instantiable) {
3887
+ if (type.flags & ts15.TypeFlags.Instantiable) {
3724
3888
  const constraint = checker.getBaseConstraintOfType(type);
3725
3889
  return constraint !== undefined && constraint !== type ? mayHoldString(constraint, checker, visited) : false;
3726
3890
  }
3727
3891
  return false;
3728
3892
  }
3729
3893
  // src/url-address-slots.ts
3730
- import * as ts15 from "typescript";
3894
+ import * as ts16 from "typescript";
3731
3895
  var ADDRESS_CLASSES = {
3732
3896
  "game-object": true,
3733
3897
  component: true,
@@ -3746,7 +3910,7 @@ function isFragmentCaret(slot, position) {
3746
3910
  return slot.fragmentStart !== -1 && position >= slot.fragmentStart;
3747
3911
  }
3748
3912
  function tableKey(checker, callee) {
3749
- const symbol = checker.getSymbolAtLocation(ts15.isIdentifier(callee) ? callee : callee.name);
3913
+ const symbol = checker.getSymbolAtLocation(ts16.isIdentifier(callee) ? callee : callee.name);
3750
3914
  if (!symbol)
3751
3915
  return;
3752
3916
  const fqn = checker.getFullyQualifiedName(symbol);
@@ -3754,43 +3918,43 @@ function tableKey(checker, callee) {
3754
3918
  }
3755
3919
  function parameterName(checker, call, index) {
3756
3920
  const declaration = checker.getResolvedSignature(call)?.declaration;
3757
- if (!declaration || !ts15.isFunctionLike(declaration))
3921
+ if (!declaration || !ts16.isFunctionLike(declaration))
3758
3922
  return;
3759
3923
  const parameter = declaration.parameters[index];
3760
- if (!parameter || parameter.dotDotDotToken || !ts15.isIdentifier(parameter.name))
3924
+ if (!parameter || parameter.dotDotDotToken || !ts16.isIdentifier(parameter.name))
3761
3925
  return;
3762
3926
  return parameter.name.text;
3763
3927
  }
3764
3928
  var EQUALITY_OPERATORS = new Set([
3765
- ts15.SyntaxKind.EqualsEqualsEqualsToken,
3766
- ts15.SyntaxKind.ExclamationEqualsEqualsToken,
3767
- ts15.SyntaxKind.EqualsEqualsToken,
3768
- ts15.SyntaxKind.ExclamationEqualsToken
3929
+ ts16.SyntaxKind.EqualsEqualsEqualsToken,
3930
+ ts16.SyntaxKind.ExclamationEqualsEqualsToken,
3931
+ ts16.SyntaxKind.EqualsEqualsToken,
3932
+ ts16.SyntaxKind.ExclamationEqualsToken
3769
3933
  ]);
3770
3934
  function comparisonSatisfied(checker, entry, call) {
3771
3935
  if (entry.comparedParameter === undefined)
3772
3936
  return true;
3773
3937
  let node = call;
3774
- while (ts15.isParenthesizedExpression(node.parent))
3938
+ while (ts16.isParenthesizedExpression(node.parent))
3775
3939
  node = node.parent;
3776
3940
  const comparison = node.parent;
3777
- if (!ts15.isBinaryExpression(comparison))
3941
+ if (!ts16.isBinaryExpression(comparison))
3778
3942
  return false;
3779
3943
  if (!EQUALITY_OPERATORS.has(comparison.operatorToken.kind))
3780
3944
  return false;
3781
3945
  const other = comparison.left === node ? comparison.right : comparison.left;
3782
3946
  const symbol = checker.getSymbolAtLocation(other);
3783
- return (symbol?.declarations ?? []).some((declaration) => ts15.isParameter(declaration) && ts15.isIdentifier(declaration.name) && declaration.name.text === entry.comparedParameter);
3947
+ return (symbol?.declarations ?? []).some((declaration) => ts16.isParameter(declaration) && ts16.isIdentifier(declaration.name) && declaration.name.text === entry.comparedParameter);
3784
3948
  }
3785
3949
  function classifiedEntryOfArgument(checker, table, argument) {
3786
3950
  const call = argument.parent;
3787
- if (!ts15.isCallExpression(call))
3951
+ if (!ts16.isCallExpression(call))
3788
3952
  return;
3789
3953
  const argumentIndex = call.arguments.indexOf(argument);
3790
3954
  if (argumentIndex === -1)
3791
3955
  return;
3792
3956
  const callee = call.expression;
3793
- if (!ts15.isPropertyAccessExpression(callee) && !ts15.isIdentifier(callee))
3957
+ if (!ts16.isPropertyAccessExpression(callee) && !ts16.isIdentifier(callee))
3794
3958
  return;
3795
3959
  const fqn = tableKey(checker, callee);
3796
3960
  if (fqn === undefined)
@@ -3807,10 +3971,10 @@ function classifiedEntryOfArgument(checker, table, argument) {
3807
3971
  }
3808
3972
  function slotThroughHashedCall(checker, table, literal) {
3809
3973
  const call = literal.parent;
3810
- if (!ts15.isCallExpression(call))
3974
+ if (!ts16.isCallExpression(call))
3811
3975
  return;
3812
3976
  const callee = call.expression;
3813
- if (!ts15.isPropertyAccessExpression(callee) && !ts15.isIdentifier(callee))
3977
+ if (!ts16.isPropertyAccessExpression(callee) && !ts16.isIdentifier(callee))
3814
3978
  return;
3815
3979
  if (tableKey(checker, callee) !== "hash")
3816
3980
  return;
@@ -3828,24 +3992,24 @@ function addressTextOf(checker, entry, call) {
3828
3992
  if (entry.addressParameter === undefined)
3829
3993
  return;
3830
3994
  const declaration = checker.getResolvedSignature(call)?.declaration;
3831
- if (!declaration || !ts15.isFunctionLike(declaration))
3995
+ if (!declaration || !ts16.isFunctionLike(declaration))
3832
3996
  return;
3833
- const index = declaration.parameters.findIndex((parameter) => !parameter.dotDotDotToken && ts15.isIdentifier(parameter.name) && parameter.name.text === entry.addressParameter);
3997
+ const index = declaration.parameters.findIndex((parameter) => !parameter.dotDotDotToken && ts16.isIdentifier(parameter.name) && parameter.name.text === entry.addressParameter);
3834
3998
  if (index === -1)
3835
3999
  return;
3836
4000
  const argument = call.arguments[index];
3837
- return argument && ts15.isStringLiteralLike(argument) ? argument.text : undefined;
4001
+ return argument && ts16.isStringLiteralLike(argument) ? argument.text : undefined;
3838
4002
  }
3839
4003
  function innermostLiteralAt(sourceFile, position) {
3840
4004
  let found;
3841
4005
  const visit = (node) => {
3842
4006
  if (position < node.getStart(sourceFile) || position > node.getEnd())
3843
4007
  return;
3844
- if (ts15.isStringLiteralLike(node))
4008
+ if (ts16.isStringLiteralLike(node))
3845
4009
  found = node;
3846
- ts15.forEachChild(node, visit);
4010
+ ts16.forEachChild(node, visit);
3847
4011
  };
3848
- ts15.forEachChild(sourceFile, visit);
4012
+ ts16.forEachChild(sourceFile, visit);
3849
4013
  return found;
3850
4014
  }
3851
4015
  function resolveClassifiedSlotAtPosition(input) {
@@ -3879,23 +4043,23 @@ function resolveClassifiedSlotAtPosition(input) {
3879
4043
  };
3880
4044
  }
3881
4045
  // src/url-cross-world-address.ts
3882
- import * as ts17 from "typescript";
4046
+ import * as ts18 from "typescript";
3883
4047
 
3884
4048
  // src/url-address-literals.ts
3885
- import * as ts16 from "typescript";
4049
+ import * as ts17 from "typescript";
3886
4050
  function isAmbient2(fileName) {
3887
4051
  return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
3888
4052
  }
3889
4053
  function referenceTargetSymbol(type) {
3890
- if ((type.flags & ts16.TypeFlags.Object) === 0)
4054
+ if ((type.flags & ts17.TypeFlags.Object) === 0)
3891
4055
  return;
3892
- if ((type.objectFlags & ts16.ObjectFlags.Reference) === 0)
4056
+ if ((type.objectFlags & ts17.ObjectFlags.Reference) === 0)
3893
4057
  return;
3894
4058
  return type.target.symbol;
3895
4059
  }
3896
4060
  function ambientHashAliasTargets(checker, anchor) {
3897
4061
  const targets = new Set;
3898
- for (const symbol of checker.getSymbolsInScope(anchor, ts16.SymbolFlags.Type)) {
4062
+ for (const symbol of checker.getSymbolsInScope(anchor, ts17.SymbolFlags.Type)) {
3899
4063
  if (symbol.name !== "Hash")
3900
4064
  continue;
3901
4065
  const target = referenceTargetSymbol(checker.getDeclaredTypeOfSymbol(symbol));
@@ -3911,7 +4075,7 @@ function canonicalHashSymbols(checker, program) {
3911
4075
  if (!anchor)
3912
4076
  return canonical;
3913
4077
  const aliased = ambientHashAliasTargets(checker, anchor);
3914
- for (const symbol of checker.getSymbolsInScope(anchor, ts16.SymbolFlags.Function)) {
4078
+ for (const symbol of checker.getSymbolsInScope(anchor, ts17.SymbolFlags.Function)) {
3915
4079
  if (symbol.name !== "hash")
3916
4080
  continue;
3917
4081
  const declaration = symbol.declarations?.[0];
@@ -3933,7 +4097,7 @@ function hashedSourceOfType(checker, type, canonical) {
3933
4097
  return source?.isStringLiteral() ? source.value : undefined;
3934
4098
  }
3935
4099
  function staticAddressTextOf(checker, node, canonical) {
3936
- return ts16.isStringLiteralLike(node) ? node.text : hashedSourceOfType(checker, checker.getTypeAtLocation(node), canonical);
4100
+ return ts17.isStringLiteralLike(node) ? node.text : hashedSourceOfType(checker, checker.getTypeAtLocation(node), canonical);
3937
4101
  }
3938
4102
 
3939
4103
  // src/url-cross-world-address.ts
@@ -3957,7 +4121,7 @@ function checkCrossWorldAddresses(input) {
3957
4121
  if (worlds.length === 0)
3958
4122
  continue;
3959
4123
  const visit = (node) => {
3960
- if (ts17.isExpression(node)) {
4124
+ if (ts18.isExpression(node)) {
3961
4125
  const entry = addressEntryOfArgument(checker, table, node);
3962
4126
  if (entry !== undefined && slotRejectsForeignSocket(entry)) {
3963
4127
  const address = staticAddressTextOf(checker, node, canonical);
@@ -3974,14 +4138,14 @@ function checkCrossWorldAddresses(input) {
3974
4138
  }
3975
4139
  }
3976
4140
  }
3977
- ts17.forEachChild(node, visit);
4141
+ ts18.forEachChild(node, visit);
3978
4142
  };
3979
- ts17.forEachChild(sourceFile, visit);
4143
+ ts18.forEachChild(sourceFile, visit);
3980
4144
  }
3981
4145
  return findings;
3982
4146
  }
3983
4147
  // src/url-fragment-reachability.ts
3984
- import * as ts18 from "typescript";
4148
+ import * as ts19 from "typescript";
3985
4149
  function pathOfKey(key) {
3986
4150
  const socket = socketOfAddress(key);
3987
4151
  return socket === undefined ? key : key.slice(socket.length + 1);
@@ -4026,7 +4190,7 @@ function checkUrlFragmentReachability(input) {
4026
4190
  if (isAmbient2(sourceFile.fileName))
4027
4191
  continue;
4028
4192
  const visit = (node) => {
4029
- if (ts18.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
4193
+ if (ts19.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
4030
4194
  const text = staticAddressTextOf(checker, node, canonical);
4031
4195
  if (text !== undefined) {
4032
4196
  const hash = text.indexOf("#");
@@ -4045,9 +4209,9 @@ function checkUrlFragmentReachability(input) {
4045
4209
  }
4046
4210
  }
4047
4211
  }
4048
- ts18.forEachChild(node, visit);
4212
+ ts19.forEachChild(node, visit);
4049
4213
  };
4050
- ts18.forEachChild(sourceFile, visit);
4214
+ ts19.forEachChild(sourceFile, visit);
4051
4215
  }
4052
4216
  return { kind: "checked", findings };
4053
4217
  }
@@ -4058,6 +4222,8 @@ export {
4058
4222
  DEFAULT_INCLUDE,
4059
4223
  GAME_PROJECT_DOCUMENT,
4060
4224
  GUI_EXTENSIONS,
4225
+ HSM_MODULE_SPECIFIER,
4226
+ HSM_REQUIRE_ROOT,
4061
4227
  INPUT_BINDING_EXTENSIONS,
4062
4228
  LIBRARY_DEPENDENCY_ROOT,
4063
4229
  LIBRARY_SCENE_EXTENSIONS,
@@ -4085,6 +4251,7 @@ export {
4085
4251
  checkUrlFragmentReachability,
4086
4252
  collectComponentDeclarations,
4087
4253
  collectComponentIds,
4254
+ compileHsmModules,
4088
4255
  componentIdOfSameObjectAddress,
4089
4256
  computeCompanionClosure,
4090
4257
  computeOutputRel,
@@ -4096,6 +4263,9 @@ export {
4096
4263
  getProgramDiagnostics,
4097
4264
  guiScriptResourceOf,
4098
4265
  guiScriptResourcesOf,
4266
+ hsmModules,
4267
+ hsmRequireName,
4268
+ hsmSourceFiles,
4099
4269
  isAddressClass,
4100
4270
  isContainedResourcePath,
4101
4271
  isDefignoredPath,
@@ -4114,6 +4284,7 @@ export {
4114
4284
  relativeAddressesFrom,
4115
4285
  requirePathForRel,
4116
4286
  resolveClassifiedSlotAtPosition,
4287
+ resolveHsmSourceDir,
4117
4288
  rewriteEmittedRequires,
4118
4289
  slotRejectsForeignSocket,
4119
4290
  socketOfAddress,