@defold-typescript/transpiler 0.41.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);
@@ -1688,9 +1806,13 @@ function buildInputActionIndex(documents) {
1688
1806
  }
1689
1807
  // src/project-resources.ts
1690
1808
  var SCAFFOLDED_DEFIGNORE_LINES = ["/node_modules", "/.defold-types", "/.vscode"];
1691
- function isDefignoredPath(displayPath) {
1809
+ function parseDefignore(text) {
1810
+ return text.split(`
1811
+ `).map((line) => line.trim()).filter((line) => line !== "").map((line) => line.startsWith("/") ? line : `/${line}`);
1812
+ }
1813
+ function isDefignoredPath(displayPath, lines = SCAFFOLDED_DEFIGNORE_LINES) {
1692
1814
  const rooted = `/${displayPath.replace(/^\/+/, "")}`;
1693
- return SCAFFOLDED_DEFIGNORE_LINES.some((line) => rooted === line || rooted.startsWith(`${line}/`));
1815
+ return lines.some((line) => rooted === line || rooted.startsWith(`${line}/`));
1694
1816
  }
1695
1817
 
1696
1818
  // src/scene-documents.ts
@@ -1985,20 +2107,20 @@ function readLibrarySceneDocuments(host, projectRoot, extensions = LIBRARY_SCENE
1985
2107
  return { documents, unreadable };
1986
2108
  }
1987
2109
  // src/main-entry-factory-imports.ts
1988
- import * as ts4 from "typescript";
2110
+ import * as ts5 from "typescript";
1989
2111
  function findMainEntryFactoryImports(fileName, source) {
1990
- const sourceFile = ts4.createSourceFile(fileName, source, ts4.ScriptTarget.Latest, true);
2112
+ const sourceFile = ts5.createSourceFile(fileName, source, ts5.ScriptTarget.Latest, true);
1991
2113
  const factories = [];
1992
2114
  for (const statement of sourceFile.statements) {
1993
- if (!ts4.isImportDeclaration(statement)) {
2115
+ if (!ts5.isImportDeclaration(statement)) {
1994
2116
  continue;
1995
2117
  }
1996
2118
  const specifier = statement.moduleSpecifier;
1997
- if (!ts4.isStringLiteral(specifier) || specifier.text !== FACTORY_MODULE) {
2119
+ if (!ts5.isStringLiteral(specifier) || specifier.text !== FACTORY_MODULE) {
1998
2120
  continue;
1999
2121
  }
2000
2122
  const bindings = statement.importClause?.namedBindings;
2001
- if (bindings === undefined || !ts4.isNamedImports(bindings)) {
2123
+ if (bindings === undefined || !ts5.isNamedImports(bindings)) {
2002
2124
  continue;
2003
2125
  }
2004
2126
  for (const element of bindings.elements) {
@@ -2011,7 +2133,7 @@ function findMainEntryFactoryImports(fileName, source) {
2011
2133
  return factories;
2012
2134
  }
2013
2135
  // src/output-paths.ts
2014
- import * as path from "node:path";
2136
+ import * as path2 from "node:path";
2015
2137
  var DEFAULT_INCLUDE = ["src/**/*.ts"];
2016
2138
  var SCRIPT_SUFFIX_BY_KIND = {
2017
2139
  script: ".ts.script",
@@ -2028,7 +2150,7 @@ function parseBuildConfig(raw) {
2028
2150
  function stripIncludeBase(pattern) {
2029
2151
  const firstWildcard = pattern.search(/[*?[]/);
2030
2152
  if (firstWildcard === -1) {
2031
- return pattern.endsWith("/") ? pattern : `${path.posix.dirname(pattern)}/`;
2153
+ return pattern.endsWith("/") ? pattern : `${path2.posix.dirname(pattern)}/`;
2032
2154
  }
2033
2155
  const upToWildcard = pattern.slice(0, firstWildcard);
2034
2156
  const lastSlash = upToWildcard.lastIndexOf("/");
@@ -2039,7 +2161,7 @@ function projectRelativeBase(pattern) {
2039
2161
  if (ABSOLUTE_SPELLING_RE.test(pattern)) {
2040
2162
  return;
2041
2163
  }
2042
- const base = path.posix.normalize(stripIncludeBase(pattern.split("\\").join("/")));
2164
+ const base = path2.posix.normalize(stripIncludeBase(pattern.split("\\").join("/")));
2043
2165
  if (base === ".." || base.startsWith("../")) {
2044
2166
  return;
2045
2167
  }
@@ -2052,7 +2174,7 @@ function relUnderOutDir(rel, config) {
2052
2174
  }
2053
2175
  const includeBase = include.map(stripIncludeBase).filter((base) => rel.startsWith(base)).sort((a, b) => b.length - a.length)[0] ?? "";
2054
2176
  const relUnderBase = rel.slice(includeBase.length);
2055
- return path.posix.join(outDir, relUnderBase);
2177
+ return path2.posix.join(outDir, relUnderBase);
2056
2178
  }
2057
2179
  function requirePathForRel(rel) {
2058
2180
  const segments = rel.split("/").filter((segment) => segment !== "" && segment !== "." && segment !== "..");
@@ -2071,16 +2193,16 @@ function computeOutputRel(rel, config, kind) {
2071
2193
  return baseRel.replace(/\.ts$/, SCRIPT_SUFFIX_BY_KIND[kind]);
2072
2194
  }
2073
2195
  // src/program-diagnostics.ts
2074
- import * as ts9 from "typescript";
2196
+ import * as ts10 from "typescript";
2075
2197
  import * as tstl from "typescript-to-lua";
2076
2198
 
2077
2199
  // src/message-guard-lowering.ts
2078
- import * as ts5 from "typescript";
2200
+ import * as ts6 from "typescript";
2079
2201
  import {
2080
2202
  createBinaryExpression as createBinaryExpression3,
2081
2203
  createCallExpression as createCallExpression3,
2082
2204
  createIdentifier as createIdentifier3,
2083
- SyntaxKind as SyntaxKind7
2205
+ SyntaxKind as SyntaxKind8
2084
2206
  } from "typescript-to-lua";
2085
2207
  var GUARD_MODULE = "@defold-typescript/types";
2086
2208
  var GUARD_NAME = "isMessage";
@@ -2089,7 +2211,7 @@ function resolvesToGuardExport(callee, checker) {
2089
2211
  if (symbol === undefined) {
2090
2212
  return false;
2091
2213
  }
2092
- if (symbol.flags & ts5.SymbolFlags.Alias) {
2214
+ if (symbol.flags & ts6.SymbolFlags.Alias) {
2093
2215
  symbol = checker.getAliasedSymbol(symbol);
2094
2216
  }
2095
2217
  if (symbol.getName() !== GUARD_NAME) {
@@ -2103,12 +2225,12 @@ function resolvesToGuardExport(callee, checker) {
2103
2225
  }
2104
2226
  var messageGuardLoweringPlugin = {
2105
2227
  visitors: {
2106
- [ts5.SyntaxKind.CallExpression]: (node, context) => {
2228
+ [ts6.SyntaxKind.CallExpression]: (node, context) => {
2107
2229
  const [messageIdArg, , expectedArg] = node.arguments;
2108
2230
  if (node.arguments.length === 3 && messageIdArg !== undefined && expectedArg !== undefined && resolvesToGuardExport(node.expression, context.checker)) {
2109
2231
  const messageId = context.transformExpression(messageIdArg);
2110
2232
  const expected = context.transformExpression(expectedArg);
2111
- return createBinaryExpression3(messageId, createCallExpression3(createIdentifier3("hash"), [expected]), SyntaxKind7.EqualityOperator, node);
2233
+ return createBinaryExpression3(messageId, createCallExpression3(createIdentifier3("hash"), [expected]), SyntaxKind8.EqualityOperator, node);
2112
2234
  }
2113
2235
  return context.superTransformExpression(node);
2114
2236
  }
@@ -2116,37 +2238,37 @@ var messageGuardLoweringPlugin = {
2116
2238
  };
2117
2239
 
2118
2240
  // src/timers-lowering.ts
2119
- import * as ts6 from "typescript";
2241
+ import * as ts7 from "typescript";
2120
2242
  import { LuaLibFeature } from "typescript-to-lua";
2121
2243
  function isTimersSpecifier(node) {
2122
- return ts6.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
2244
+ return ts7.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
2123
2245
  }
2124
2246
  function importsTimersModule(sourceFile) {
2125
- return sourceFile.statements.some((statement) => ts6.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
2247
+ return sourceFile.statements.some((statement) => ts7.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
2126
2248
  }
2127
2249
  var TIMERS_REQUIRE_PATH = `@NoResolution:${TIMERS_REQUIRE_NAME}`;
2128
2250
  var timersLoweringPlugin = {
2129
2251
  visitors: {
2130
- [ts6.SyntaxKind.ImportDeclaration]: (node, context) => {
2252
+ [ts7.SyntaxKind.ImportDeclaration]: (node, context) => {
2131
2253
  if (!isTimersSpecifier(node.moduleSpecifier)) {
2132
2254
  return context.superTransformStatements(node);
2133
2255
  }
2134
2256
  context.usedLuaLibFeatures.add(LuaLibFeature.Promise);
2135
2257
  context.usedLuaLibFeatures.add(LuaLibFeature.New);
2136
- 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);
2137
2259
  return context.superTransformStatements(rewritten);
2138
2260
  }
2139
2261
  }
2140
2262
  };
2141
2263
 
2142
2264
  // src/type-application-erasure.ts
2143
- import * as ts7 from "typescript";
2265
+ import * as ts8 from "typescript";
2144
2266
  var TYPE_APPLICATION_APIS = new Set(["go.get", "go.set"]);
2145
2267
  function isTypeApplication(call, checker) {
2146
2268
  if (call.arguments.length !== 0)
2147
2269
  return false;
2148
2270
  const declaration = checker.getResolvedSignature(call)?.declaration;
2149
- if (declaration === undefined || !ts7.isFunctionDeclaration(declaration))
2271
+ if (declaration === undefined || !ts8.isFunctionDeclaration(declaration))
2150
2272
  return false;
2151
2273
  if (declaration.parameters.length !== 0 || declaration.typeParameters === undefined)
2152
2274
  return false;
@@ -2160,7 +2282,7 @@ function isTypeApplication(call, checker) {
2160
2282
  }
2161
2283
  var typeApplicationErasurePlugin = {
2162
2284
  visitors: {
2163
- [ts7.SyntaxKind.CallExpression]: (node, context) => {
2285
+ [ts8.SyntaxKind.CallExpression]: (node, context) => {
2164
2286
  if (isTypeApplication(node, context.checker)) {
2165
2287
  return context.transformExpression(node.expression);
2166
2288
  }
@@ -2170,10 +2292,10 @@ var typeApplicationErasurePlugin = {
2170
2292
  };
2171
2293
 
2172
2294
  // src/window-event-guard-lowering.ts
2173
- import * as ts8 from "typescript";
2295
+ import * as ts9 from "typescript";
2174
2296
  import {
2175
2297
  createBinaryExpression as createBinaryExpression4,
2176
- SyntaxKind as SyntaxKind11
2298
+ SyntaxKind as SyntaxKind12
2177
2299
  } from "typescript-to-lua";
2178
2300
  var GUARD_MODULE2 = "@defold-typescript/types";
2179
2301
  var GUARD_NAME2 = "isWindowEvent";
@@ -2182,7 +2304,7 @@ function resolvesToGuardExport2(callee, checker) {
2182
2304
  if (symbol === undefined) {
2183
2305
  return false;
2184
2306
  }
2185
- if (symbol.flags & ts8.SymbolFlags.Alias) {
2307
+ if (symbol.flags & ts9.SymbolFlags.Alias) {
2186
2308
  symbol = checker.getAliasedSymbol(symbol);
2187
2309
  }
2188
2310
  if (symbol.getName() !== GUARD_NAME2) {
@@ -2196,12 +2318,12 @@ function resolvesToGuardExport2(callee, checker) {
2196
2318
  }
2197
2319
  var windowEventGuardLoweringPlugin = {
2198
2320
  visitors: {
2199
- [ts8.SyntaxKind.CallExpression]: (node, context) => {
2321
+ [ts9.SyntaxKind.CallExpression]: (node, context) => {
2200
2322
  const [eventArg, , expectedArg] = node.arguments;
2201
2323
  if (node.arguments.length === 3 && eventArg !== undefined && expectedArg !== undefined && resolvesToGuardExport2(node.expression, context.checker)) {
2202
2324
  const event = context.transformExpression(eventArg);
2203
2325
  const expected = context.transformExpression(expectedArg);
2204
- return createBinaryExpression4(event, expected, SyntaxKind11.EqualityOperator, node);
2326
+ return createBinaryExpression4(event, expected, SyntaxKind12.EqualityOperator, node);
2205
2327
  }
2206
2328
  return context.superTransformExpression(node);
2207
2329
  }
@@ -2222,7 +2344,7 @@ function isAmbient(fileName) {
2222
2344
  return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
2223
2345
  }
2224
2346
  function getProgramDiagnostics(program, sourceFile) {
2225
- const { diagnostics } = tstl.getProgramTranspileResult(ts9.sys, noopWriteFile, {
2347
+ const { diagnostics } = tstl.getProgramTranspileResult(ts10.sys, noopWriteFile, {
2226
2348
  program,
2227
2349
  plugins: LUA_PLUGINS,
2228
2350
  ...sourceFile ? { sourceFiles: [sourceFile] } : {}
@@ -2792,12 +2914,12 @@ function relativeAddressesFrom(index, context) {
2792
2914
  // src/session.ts
2793
2915
  import { readFileSync as readFileSync2 } from "node:fs";
2794
2916
  import { createRequire as createRequire2 } from "node:module";
2795
- import * as path3 from "node:path";
2796
- import * as ts13 from "typescript";
2917
+ import * as path4 from "node:path";
2918
+ import * as ts14 from "typescript";
2797
2919
  import * as tstl3 from "typescript-to-lua";
2798
2920
 
2799
2921
  // src/companion-emit.ts
2800
- import * as ts10 from "typescript";
2922
+ import * as ts11 from "typescript";
2801
2923
  import {
2802
2924
  createAssignmentStatement as createAssignmentStatement2,
2803
2925
  createCallExpression as createCallExpression4,
@@ -2820,7 +2942,7 @@ import {
2820
2942
  isMethodCallExpression,
2821
2943
  isRepeatStatement,
2822
2944
  isReturnStatement as isReturnStatement2,
2823
- isStringLiteral as isStringLiteral6,
2945
+ isStringLiteral as isStringLiteral7,
2824
2946
  isTableExpression,
2825
2947
  isVariableDeclarationStatement,
2826
2948
  LuaPrinter
@@ -2831,8 +2953,8 @@ function exportsIdentifier() {
2831
2953
  }
2832
2954
  function isRuntimeScriptSource(sourceFile, checker) {
2833
2955
  return sourceFile.statements.some((statement) => {
2834
- const expression = ts10.isExpressionStatement(statement) ? statement.expression : ts10.isExportAssignment(statement) && !statement.isExportEquals ? statement.expression : undefined;
2835
- 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);
2836
2958
  });
2837
2959
  }
2838
2960
  function planFor(sourceFile, checker) {
@@ -2984,11 +3106,11 @@ function freeNames(statements) {
2984
3106
  function resolvedRequirePaths(sourceFile, checker) {
2985
3107
  const paths = new Map;
2986
3108
  for (const statement of sourceFile.statements) {
2987
- const specifier = ts10.isImportDeclaration(statement) || ts10.isExportDeclaration(statement) ? statement.moduleSpecifier : undefined;
2988
- 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)) {
2989
3111
  continue;
2990
3112
  }
2991
- const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts10.isSourceFile(declaration));
3113
+ const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts11.isSourceFile(declaration));
2992
3114
  if (target === undefined || target.isDeclarationFile) {
2993
3115
  continue;
2994
3116
  }
@@ -3006,7 +3128,7 @@ function resolveMovedRequires(statements, paths) {
3006
3128
  return;
3007
3129
  }
3008
3130
  const [argument] = node.params;
3009
- if (argument === undefined || !isStringLiteral6(argument)) {
3131
+ if (argument === undefined || !isStringLiteral7(argument)) {
3010
3132
  return;
3011
3133
  }
3012
3134
  const resolved = paths.get(argument.value);
@@ -3029,7 +3151,7 @@ function withResolvedRequire(statement, paths) {
3029
3151
  return statement;
3030
3152
  }
3031
3153
  const [argument] = value.params;
3032
- if (argument === undefined || !isStringLiteral6(argument)) {
3154
+ if (argument === undefined || !isStringLiteral7(argument)) {
3033
3155
  return statement;
3034
3156
  }
3035
3157
  const resolved = paths.get(argument.value);
@@ -3152,11 +3274,11 @@ function createCompanionEmitPlugin() {
3152
3274
  return statements;
3153
3275
  }
3154
3276
  const visitors = {
3155
- [ts10.SyntaxKind.VariableStatement]: capture,
3156
- [ts10.SyntaxKind.FunctionDeclaration]: capture,
3157
- [ts10.SyntaxKind.ClassDeclaration]: capture,
3158
- [ts10.SyntaxKind.EnumDeclaration]: capture,
3159
- [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
3160
3282
  };
3161
3283
  let configuredNoResolvePaths = [];
3162
3284
  const plugin = {
@@ -3225,7 +3347,7 @@ function emitCompanion(program, emitHost, file, sourceFile, plan, owned, compani
3225
3347
  }
3226
3348
 
3227
3349
  // src/editor-script-erasure.ts
3228
- import * as ts11 from "typescript";
3350
+ import * as ts12 from "typescript";
3229
3351
  import {
3230
3352
  createReturnStatement as createReturnStatement3
3231
3353
  } from "typescript-to-lua";
@@ -3245,7 +3367,7 @@ function resolveEditorFactoryExport(callee, checker) {
3245
3367
  if (symbol === undefined) {
3246
3368
  return;
3247
3369
  }
3248
- if (symbol.flags & ts11.SymbolFlags.Alias) {
3370
+ if (symbol.flags & ts12.SymbolFlags.Alias) {
3249
3371
  symbol = checker.getAliasedSymbol(symbol);
3250
3372
  }
3251
3373
  const name = symbol.getName();
@@ -3259,7 +3381,7 @@ function resolveEditorFactoryExport(callee, checker) {
3259
3381
  return declaration.getSourceFile().fileName.includes(EDITOR_FACTORY_MODULE) ? name : undefined;
3260
3382
  }
3261
3383
  function lowerEditorFactoryCall(expression, context) {
3262
- if (!ts11.isCallExpression(expression)) {
3384
+ if (!ts12.isCallExpression(expression)) {
3263
3385
  return;
3264
3386
  }
3265
3387
  if (resolveEditorFactoryExport(expression.expression, context.checker) !== EDITOR_SCRIPT_FACTORY_NAME) {
@@ -3272,7 +3394,7 @@ function lowerEditorFactoryCall(expression, context) {
3272
3394
  return [createReturnStatement3([context.transformExpression(module)])];
3273
3395
  }
3274
3396
  function isEditorFactoryOnlyImport(node) {
3275
- 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)) {
3276
3398
  return false;
3277
3399
  }
3278
3400
  const clause = node.importClause;
@@ -3283,7 +3405,7 @@ function isEditorFactoryOnlyImport(node) {
3283
3405
  return false;
3284
3406
  }
3285
3407
  const bindings = clause.namedBindings;
3286
- if (bindings === undefined || !ts11.isNamedImports(bindings)) {
3408
+ if (bindings === undefined || !ts12.isNamedImports(bindings)) {
3287
3409
  return false;
3288
3410
  }
3289
3411
  const runtime = bindings.elements.filter((element) => !element.isTypeOnly);
@@ -3294,7 +3416,7 @@ function isEditorFactoryOnlyImport(node) {
3294
3416
  }
3295
3417
  var editorScriptErasurePlugin = {
3296
3418
  visitors: {
3297
- [ts11.SyntaxKind.ExportAssignment]: (node, context) => {
3419
+ [ts12.SyntaxKind.ExportAssignment]: (node, context) => {
3298
3420
  if (!node.isExportEquals) {
3299
3421
  const lowered = lowerEditorFactoryCall(node.expression, context);
3300
3422
  if (lowered !== undefined) {
@@ -3303,35 +3425,35 @@ var editorScriptErasurePlugin = {
3303
3425
  }
3304
3426
  return context.superTransformStatements(node);
3305
3427
  },
3306
- [ts11.SyntaxKind.CallExpression]: (node, context) => {
3428
+ [ts12.SyntaxKind.CallExpression]: (node, context) => {
3307
3429
  const command = node.arguments[0];
3308
3430
  if (command !== undefined && resolveEditorFactoryExport(node.expression, context.checker) === EDITOR_COMMAND_FACTORY_NAME) {
3309
3431
  return context.transformExpression(command);
3310
3432
  }
3311
3433
  return context.superTransformExpression(node);
3312
3434
  },
3313
- [ts11.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
3435
+ [ts12.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
3314
3436
  }
3315
3437
  };
3316
3438
 
3317
3439
  // src/transpile.ts
3318
- import { readdirSync, readFileSync } from "node:fs";
3440
+ import { readdirSync as readdirSync2, readFileSync } from "node:fs";
3319
3441
  import { createRequire } from "node:module";
3320
- import * as path2 from "node:path";
3442
+ import * as path3 from "node:path";
3321
3443
  import * as tstl2 from "typescript-to-lua";
3322
3444
 
3323
3445
  // src/go-property-direct-call.ts
3324
- import * as ts12 from "typescript";
3446
+ import * as ts13 from "typescript";
3325
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).";
3326
3448
  function findDirectGoPropertyCalls(sourceFile) {
3327
3449
  const calls = [];
3328
3450
  const visit = (node) => {
3329
- 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") {
3330
3452
  calls.push(node);
3331
3453
  }
3332
- ts12.forEachChild(node, visit);
3454
+ ts13.forEachChild(node, visit);
3333
3455
  };
3334
- ts12.forEachChild(sourceFile, visit);
3456
+ ts13.forEachChild(sourceFile, visit);
3335
3457
  return calls;
3336
3458
  }
3337
3459
 
@@ -3343,12 +3465,12 @@ function flattenDiagnosticMessage(text) {
3343
3465
  return flattenDiagnosticMessage(text.messageText);
3344
3466
  }
3345
3467
  var requireFromHere = createRequire(import.meta.url);
3346
- var TYPES_PKG_ROOT = path2.dirname(requireFromHere.resolve("@defold-typescript/types/package.json"));
3347
- 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"));
3348
3470
  function readAmbient(rel) {
3349
- return readFileSync(path2.join(TYPES_PKG_ROOT, rel), "utf8");
3471
+ return readFileSync(path3.join(TYPES_PKG_ROOT, rel), "utf8");
3350
3472
  }
3351
- 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"));
3352
3474
  var LUA_TYPES_ENTRY_FILES = ["5.1.d.ts", "special/jit-only.d.ts"];
3353
3475
  var REFERENCE_PATH_RE = /\/\/\/\s*<reference\s+path="([^"]+)"\s*\/>/g;
3354
3476
  function collectLuaTypesClosure() {
@@ -3357,14 +3479,14 @@ function collectLuaTypesClosure() {
3357
3479
  const key = `node_modules/lua-types/${rel}`;
3358
3480
  if (key in files)
3359
3481
  return;
3360
- const source = readFileSync(path2.join(LUA_TYPES_ROOT, rel), "utf8");
3482
+ const source = readFileSync(path3.join(LUA_TYPES_ROOT, rel), "utf8");
3361
3483
  files[key] = source;
3362
- const dir = path2.posix.dirname(rel);
3484
+ const dir = path3.posix.dirname(rel);
3363
3485
  for (const match of source.matchAll(REFERENCE_PATH_RE)) {
3364
3486
  const ref = match[1];
3365
3487
  if (!ref)
3366
3488
  continue;
3367
- visit(path2.posix.normalize(path2.posix.join(dir, ref)));
3489
+ visit(path3.posix.normalize(path3.posix.join(dir, ref)));
3368
3490
  }
3369
3491
  };
3370
3492
  for (const entry of LUA_TYPES_ENTRY_FILES)
@@ -3373,7 +3495,7 @@ function collectLuaTypesClosure() {
3373
3495
  }
3374
3496
  function buildAmbientFiles() {
3375
3497
  const files = {
3376
- "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"),
3377
3499
  "node_modules/@defold-typescript/types/src/core-types.ts": readAmbient("src/core-types.ts"),
3378
3500
  "node_modules/@defold-typescript/types/src/engine-globals.d.ts": readAmbient("src/engine-globals.d.ts"),
3379
3501
  "node_modules/@defold-typescript/types/src/go-overloads.d.ts": readAmbient("src/go-overloads.d.ts"),
@@ -3412,13 +3534,18 @@ export type { ScriptProperties, ScriptProperty } from "./src/lifecycle.js";
3412
3534
  ].join(`
3413
3535
  `)
3414
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
+ }
3415
3542
  Object.assign(files, collectLuaTypesClosure());
3416
- for (const entry of readdirSync(path2.join(TYPES_PKG_ROOT, "generated"))) {
3543
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "generated"))) {
3417
3544
  if (entry.endsWith(".d.ts")) {
3418
3545
  files[`node_modules/@defold-typescript/types/generated/${entry}`] = readAmbient(`generated/${entry}`);
3419
3546
  }
3420
3547
  }
3421
- for (const entry of readdirSync(path2.join(TYPES_PKG_ROOT, "src"))) {
3548
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "src"))) {
3422
3549
  if (entry.endsWith(".d.ts")) {
3423
3550
  files[`node_modules/@defold-typescript/types/src/${entry}`] = readAmbient(`src/${entry}`);
3424
3551
  }
@@ -3485,20 +3612,19 @@ function collectOutputs(transpiledFiles, diagnostics, userKeys, emittedCompanion
3485
3612
  }
3486
3613
  }
3487
3614
  }
3615
+ const hsm = hsmClosure([...Object.values(lua), ...Object.values(companions)], compileHsmModules);
3488
3616
  return {
3489
3617
  lua,
3490
3618
  sourceMaps,
3491
3619
  diagnostics: collectedDiagnostics,
3492
3620
  ...Object.keys(companions).length > 0 ? { companions } : {},
3493
3621
  ...lualib !== undefined ? { lualib } : {},
3494
- ...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {}
3622
+ ...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {},
3623
+ ...hsm !== undefined ? { hsmModules: hsm } : {}
3495
3624
  };
3496
3625
  }
3497
- function transpileProject(input) {
3498
- const userKeys = new Set(Object.keys(input.files));
3499
- const merged = { ...AMBIENT_FILES, ...input.files };
3500
- const companionEmit = createCompanionEmitPlugin();
3501
- const result = tstl2.transpileVirtualProject(merged, {
3626
+ function transpileVirtual(files, companionEmit) {
3627
+ return tstl2.transpileVirtualProject({ ...AMBIENT_FILES, ...files }, {
3502
3628
  luaTarget: tstl2.LuaTarget.Lua51,
3503
3629
  sourceMap: true,
3504
3630
  lib: ["lib.es2022.d.ts"],
@@ -3511,12 +3637,53 @@ function transpileProject(input) {
3511
3637
  { plugin: windowEventGuardLoweringPlugin },
3512
3638
  { plugin: messageDispatchLoweringPlugin },
3513
3639
  { plugin: timersLoweringPlugin },
3640
+ { plugin: hsmLoweringPlugin },
3514
3641
  { plugin: typeApplicationErasurePlugin },
3515
3642
  { plugin: companionEmit.plugin }
3516
3643
  ]
3517
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);
3518
3650
  return collectOutputs(result.transpiledFiles, result.diagnostics, userKeys, companionEmit.companions);
3519
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
+ }
3520
3687
  function transpile(source) {
3521
3688
  const project = transpileProject({ files: { "main.ts": source } });
3522
3689
  return {
@@ -3542,6 +3709,7 @@ function compilerOptions(companionEmit) {
3542
3709
  { plugin: windowEventGuardLoweringPlugin },
3543
3710
  { plugin: messageDispatchLoweringPlugin },
3544
3711
  { plugin: timersLoweringPlugin },
3712
+ { plugin: hsmLoweringPlugin },
3545
3713
  { plugin: typeApplicationErasurePlugin },
3546
3714
  { plugin: companionEmit.plugin }
3547
3715
  ]
@@ -3585,18 +3753,18 @@ function createTranspileSession() {
3585
3753
  if (cached) {
3586
3754
  return cached;
3587
3755
  }
3588
- const created = ts13.createSourceFile(fileName, content, ts13.ScriptTarget.Latest, false);
3756
+ const created = ts14.createSourceFile(fileName, content, ts14.ScriptTarget.Latest, false);
3589
3757
  sourceFileCache.set(normalized, created);
3590
3758
  return created;
3591
3759
  }
3592
3760
  let filePath;
3593
3761
  if (fileName.startsWith("lib.")) {
3594
- const typeScriptDir = path3.dirname(requireFromHere2.resolve("typescript"));
3595
- filePath = path3.join(typeScriptDir, fileName);
3762
+ const typeScriptDir = path4.dirname(requireFromHere2.resolve("typescript"));
3763
+ filePath = path4.join(typeScriptDir, fileName);
3596
3764
  }
3597
3765
  if (fileName.includes("language-extensions")) {
3598
3766
  const dtsName = fileName.replace(/(\.d)?(\.ts)$/, ".d.ts");
3599
- filePath = path3.resolve(dtsName);
3767
+ filePath = path4.resolve(dtsName);
3600
3768
  }
3601
3769
  if (filePath !== undefined) {
3602
3770
  const cached = libCache.get(fileName);
@@ -3604,7 +3772,7 @@ function createTranspileSession() {
3604
3772
  return cached;
3605
3773
  }
3606
3774
  const fileContent = readFileSync2(filePath, "utf8");
3607
- const created = ts13.createSourceFile(filePath, fileContent, ts13.ScriptTarget.Latest, false);
3775
+ const created = ts14.createSourceFile(filePath, fileContent, ts14.ScriptTarget.Latest, false);
3608
3776
  libCache.set(fileName, created);
3609
3777
  return created;
3610
3778
  }
@@ -3617,10 +3785,10 @@ function createTranspileSession() {
3617
3785
  return AMBIENT_FILES[normalized];
3618
3786
  }
3619
3787
  const host = {
3620
- fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts13.sys.fileExists(fileName),
3788
+ fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts14.sys.fileExists(fileName),
3621
3789
  getCanonicalFileName: (fileName) => fileName,
3622
3790
  getCurrentDirectory: () => "",
3623
- getDefaultLibFileName: ts13.getDefaultLibFileName,
3791
+ getDefaultLibFileName: ts14.getDefaultLibFileName,
3624
3792
  readFile: () => "",
3625
3793
  getNewLine: () => `
3626
3794
  `,
@@ -3642,15 +3810,15 @@ function createTranspileSession() {
3642
3810
  const userKeys = new Set(userFiles.keys());
3643
3811
  const rootNames = [...Object.keys(AMBIENT_FILES).map(normalizeSlashes), ...userKeys];
3644
3812
  const companionEmit = createCompanionEmitPlugin();
3645
- program = ts13.createProgram(rootNames, compilerOptions(companionEmit), host, program);
3646
- const preEmitDiagnostics = ts13.getPreEmitDiagnostics(program);
3813
+ program = ts14.createProgram(rootNames, compilerOptions(companionEmit), host, program);
3814
+ const preEmitDiagnostics = ts14.getPreEmitDiagnostics(program);
3647
3815
  const collector = createOutputCollector();
3648
3816
  const { diagnostics: transpileDiagnostics } = new tstl3.Transpiler().emit({
3649
3817
  program,
3650
3818
  writeFile: collector.writeFile
3651
3819
  });
3652
3820
  const diagnostics = [
3653
- ...ts13.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
3821
+ ...ts14.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
3654
3822
  ];
3655
3823
  return collectOutputs(collector.files, diagnostics, userKeys, companionEmit.companions);
3656
3824
  }
@@ -3660,7 +3828,7 @@ function createTranspileSession() {
3660
3828
  };
3661
3829
  }
3662
3830
  // src/text-script-property.ts
3663
- import * as ts14 from "typescript";
3831
+ import * as ts15 from "typescript";
3664
3832
  function findTextScriptProperties(program, fileNames) {
3665
3833
  const checker = program.getTypeChecker();
3666
3834
  const findings = [];
@@ -3671,7 +3839,7 @@ function findTextScriptProperties(program, fileNames) {
3671
3839
  }
3672
3840
  const located = [];
3673
3841
  const visit = (node) => {
3674
- if (ts14.isCallExpression(node)) {
3842
+ if (ts15.isCallExpression(node)) {
3675
3843
  const hooks = factoryHooks(node, checker);
3676
3844
  for (const property of hooks?.properties ?? []) {
3677
3845
  if (!isPropertiesHook(property)) {
@@ -3684,7 +3852,7 @@ function findTextScriptProperties(program, fileNames) {
3684
3852
  }
3685
3853
  }
3686
3854
  }
3687
- ts14.forEachChild(node, visit);
3855
+ ts15.forEachChild(node, visit);
3688
3856
  };
3689
3857
  visit(sourceFile);
3690
3858
  for (const call of findDirectGoPropertyCalls(sourceFile)) {
@@ -3693,7 +3861,7 @@ function findTextScriptProperties(program, fileNames) {
3693
3861
  continue;
3694
3862
  }
3695
3863
  if (mayHoldString(checker.getTypeAtLocation(value), checker)) {
3696
- const name = ts14.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
3864
+ const name = ts15.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
3697
3865
  located.push({ name, value });
3698
3866
  }
3699
3867
  }
@@ -3710,20 +3878,20 @@ function mayHoldString(type, checker, visited = new Set) {
3710
3878
  return false;
3711
3879
  }
3712
3880
  visited.add(type);
3713
- if (type.flags & ts14.TypeFlags.StringLike) {
3881
+ if (type.flags & ts15.TypeFlags.StringLike) {
3714
3882
  return true;
3715
3883
  }
3716
3884
  if (type.isUnionOrIntersection()) {
3717
3885
  return type.types.some((member) => mayHoldString(member, checker, visited));
3718
3886
  }
3719
- if (type.flags & ts14.TypeFlags.Instantiable) {
3887
+ if (type.flags & ts15.TypeFlags.Instantiable) {
3720
3888
  const constraint = checker.getBaseConstraintOfType(type);
3721
3889
  return constraint !== undefined && constraint !== type ? mayHoldString(constraint, checker, visited) : false;
3722
3890
  }
3723
3891
  return false;
3724
3892
  }
3725
3893
  // src/url-address-slots.ts
3726
- import * as ts15 from "typescript";
3894
+ import * as ts16 from "typescript";
3727
3895
  var ADDRESS_CLASSES = {
3728
3896
  "game-object": true,
3729
3897
  component: true,
@@ -3742,7 +3910,7 @@ function isFragmentCaret(slot, position) {
3742
3910
  return slot.fragmentStart !== -1 && position >= slot.fragmentStart;
3743
3911
  }
3744
3912
  function tableKey(checker, callee) {
3745
- const symbol = checker.getSymbolAtLocation(ts15.isIdentifier(callee) ? callee : callee.name);
3913
+ const symbol = checker.getSymbolAtLocation(ts16.isIdentifier(callee) ? callee : callee.name);
3746
3914
  if (!symbol)
3747
3915
  return;
3748
3916
  const fqn = checker.getFullyQualifiedName(symbol);
@@ -3750,43 +3918,43 @@ function tableKey(checker, callee) {
3750
3918
  }
3751
3919
  function parameterName(checker, call, index) {
3752
3920
  const declaration = checker.getResolvedSignature(call)?.declaration;
3753
- if (!declaration || !ts15.isFunctionLike(declaration))
3921
+ if (!declaration || !ts16.isFunctionLike(declaration))
3754
3922
  return;
3755
3923
  const parameter = declaration.parameters[index];
3756
- if (!parameter || parameter.dotDotDotToken || !ts15.isIdentifier(parameter.name))
3924
+ if (!parameter || parameter.dotDotDotToken || !ts16.isIdentifier(parameter.name))
3757
3925
  return;
3758
3926
  return parameter.name.text;
3759
3927
  }
3760
3928
  var EQUALITY_OPERATORS = new Set([
3761
- ts15.SyntaxKind.EqualsEqualsEqualsToken,
3762
- ts15.SyntaxKind.ExclamationEqualsEqualsToken,
3763
- ts15.SyntaxKind.EqualsEqualsToken,
3764
- ts15.SyntaxKind.ExclamationEqualsToken
3929
+ ts16.SyntaxKind.EqualsEqualsEqualsToken,
3930
+ ts16.SyntaxKind.ExclamationEqualsEqualsToken,
3931
+ ts16.SyntaxKind.EqualsEqualsToken,
3932
+ ts16.SyntaxKind.ExclamationEqualsToken
3765
3933
  ]);
3766
3934
  function comparisonSatisfied(checker, entry, call) {
3767
3935
  if (entry.comparedParameter === undefined)
3768
3936
  return true;
3769
3937
  let node = call;
3770
- while (ts15.isParenthesizedExpression(node.parent))
3938
+ while (ts16.isParenthesizedExpression(node.parent))
3771
3939
  node = node.parent;
3772
3940
  const comparison = node.parent;
3773
- if (!ts15.isBinaryExpression(comparison))
3941
+ if (!ts16.isBinaryExpression(comparison))
3774
3942
  return false;
3775
3943
  if (!EQUALITY_OPERATORS.has(comparison.operatorToken.kind))
3776
3944
  return false;
3777
3945
  const other = comparison.left === node ? comparison.right : comparison.left;
3778
3946
  const symbol = checker.getSymbolAtLocation(other);
3779
- 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);
3780
3948
  }
3781
3949
  function classifiedEntryOfArgument(checker, table, argument) {
3782
3950
  const call = argument.parent;
3783
- if (!ts15.isCallExpression(call))
3951
+ if (!ts16.isCallExpression(call))
3784
3952
  return;
3785
3953
  const argumentIndex = call.arguments.indexOf(argument);
3786
3954
  if (argumentIndex === -1)
3787
3955
  return;
3788
3956
  const callee = call.expression;
3789
- if (!ts15.isPropertyAccessExpression(callee) && !ts15.isIdentifier(callee))
3957
+ if (!ts16.isPropertyAccessExpression(callee) && !ts16.isIdentifier(callee))
3790
3958
  return;
3791
3959
  const fqn = tableKey(checker, callee);
3792
3960
  if (fqn === undefined)
@@ -3803,10 +3971,10 @@ function classifiedEntryOfArgument(checker, table, argument) {
3803
3971
  }
3804
3972
  function slotThroughHashedCall(checker, table, literal) {
3805
3973
  const call = literal.parent;
3806
- if (!ts15.isCallExpression(call))
3974
+ if (!ts16.isCallExpression(call))
3807
3975
  return;
3808
3976
  const callee = call.expression;
3809
- if (!ts15.isPropertyAccessExpression(callee) && !ts15.isIdentifier(callee))
3977
+ if (!ts16.isPropertyAccessExpression(callee) && !ts16.isIdentifier(callee))
3810
3978
  return;
3811
3979
  if (tableKey(checker, callee) !== "hash")
3812
3980
  return;
@@ -3824,24 +3992,24 @@ function addressTextOf(checker, entry, call) {
3824
3992
  if (entry.addressParameter === undefined)
3825
3993
  return;
3826
3994
  const declaration = checker.getResolvedSignature(call)?.declaration;
3827
- if (!declaration || !ts15.isFunctionLike(declaration))
3995
+ if (!declaration || !ts16.isFunctionLike(declaration))
3828
3996
  return;
3829
- 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);
3830
3998
  if (index === -1)
3831
3999
  return;
3832
4000
  const argument = call.arguments[index];
3833
- return argument && ts15.isStringLiteralLike(argument) ? argument.text : undefined;
4001
+ return argument && ts16.isStringLiteralLike(argument) ? argument.text : undefined;
3834
4002
  }
3835
4003
  function innermostLiteralAt(sourceFile, position) {
3836
4004
  let found;
3837
4005
  const visit = (node) => {
3838
4006
  if (position < node.getStart(sourceFile) || position > node.getEnd())
3839
4007
  return;
3840
- if (ts15.isStringLiteralLike(node))
4008
+ if (ts16.isStringLiteralLike(node))
3841
4009
  found = node;
3842
- ts15.forEachChild(node, visit);
4010
+ ts16.forEachChild(node, visit);
3843
4011
  };
3844
- ts15.forEachChild(sourceFile, visit);
4012
+ ts16.forEachChild(sourceFile, visit);
3845
4013
  return found;
3846
4014
  }
3847
4015
  function resolveClassifiedSlotAtPosition(input) {
@@ -3875,23 +4043,23 @@ function resolveClassifiedSlotAtPosition(input) {
3875
4043
  };
3876
4044
  }
3877
4045
  // src/url-cross-world-address.ts
3878
- import * as ts17 from "typescript";
4046
+ import * as ts18 from "typescript";
3879
4047
 
3880
4048
  // src/url-address-literals.ts
3881
- import * as ts16 from "typescript";
4049
+ import * as ts17 from "typescript";
3882
4050
  function isAmbient2(fileName) {
3883
4051
  return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
3884
4052
  }
3885
4053
  function referenceTargetSymbol(type) {
3886
- if ((type.flags & ts16.TypeFlags.Object) === 0)
4054
+ if ((type.flags & ts17.TypeFlags.Object) === 0)
3887
4055
  return;
3888
- if ((type.objectFlags & ts16.ObjectFlags.Reference) === 0)
4056
+ if ((type.objectFlags & ts17.ObjectFlags.Reference) === 0)
3889
4057
  return;
3890
4058
  return type.target.symbol;
3891
4059
  }
3892
4060
  function ambientHashAliasTargets(checker, anchor) {
3893
4061
  const targets = new Set;
3894
- for (const symbol of checker.getSymbolsInScope(anchor, ts16.SymbolFlags.Type)) {
4062
+ for (const symbol of checker.getSymbolsInScope(anchor, ts17.SymbolFlags.Type)) {
3895
4063
  if (symbol.name !== "Hash")
3896
4064
  continue;
3897
4065
  const target = referenceTargetSymbol(checker.getDeclaredTypeOfSymbol(symbol));
@@ -3907,7 +4075,7 @@ function canonicalHashSymbols(checker, program) {
3907
4075
  if (!anchor)
3908
4076
  return canonical;
3909
4077
  const aliased = ambientHashAliasTargets(checker, anchor);
3910
- for (const symbol of checker.getSymbolsInScope(anchor, ts16.SymbolFlags.Function)) {
4078
+ for (const symbol of checker.getSymbolsInScope(anchor, ts17.SymbolFlags.Function)) {
3911
4079
  if (symbol.name !== "hash")
3912
4080
  continue;
3913
4081
  const declaration = symbol.declarations?.[0];
@@ -3929,7 +4097,7 @@ function hashedSourceOfType(checker, type, canonical) {
3929
4097
  return source?.isStringLiteral() ? source.value : undefined;
3930
4098
  }
3931
4099
  function staticAddressTextOf(checker, node, canonical) {
3932
- 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);
3933
4101
  }
3934
4102
 
3935
4103
  // src/url-cross-world-address.ts
@@ -3953,7 +4121,7 @@ function checkCrossWorldAddresses(input) {
3953
4121
  if (worlds.length === 0)
3954
4122
  continue;
3955
4123
  const visit = (node) => {
3956
- if (ts17.isExpression(node)) {
4124
+ if (ts18.isExpression(node)) {
3957
4125
  const entry = addressEntryOfArgument(checker, table, node);
3958
4126
  if (entry !== undefined && slotRejectsForeignSocket(entry)) {
3959
4127
  const address = staticAddressTextOf(checker, node, canonical);
@@ -3970,14 +4138,14 @@ function checkCrossWorldAddresses(input) {
3970
4138
  }
3971
4139
  }
3972
4140
  }
3973
- ts17.forEachChild(node, visit);
4141
+ ts18.forEachChild(node, visit);
3974
4142
  };
3975
- ts17.forEachChild(sourceFile, visit);
4143
+ ts18.forEachChild(sourceFile, visit);
3976
4144
  }
3977
4145
  return findings;
3978
4146
  }
3979
4147
  // src/url-fragment-reachability.ts
3980
- import * as ts18 from "typescript";
4148
+ import * as ts19 from "typescript";
3981
4149
  function pathOfKey(key) {
3982
4150
  const socket = socketOfAddress(key);
3983
4151
  return socket === undefined ? key : key.slice(socket.length + 1);
@@ -4022,7 +4190,7 @@ function checkUrlFragmentReachability(input) {
4022
4190
  if (isAmbient2(sourceFile.fileName))
4023
4191
  continue;
4024
4192
  const visit = (node) => {
4025
- if (ts18.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
4193
+ if (ts19.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
4026
4194
  const text = staticAddressTextOf(checker, node, canonical);
4027
4195
  if (text !== undefined) {
4028
4196
  const hash = text.indexOf("#");
@@ -4041,9 +4209,9 @@ function checkUrlFragmentReachability(input) {
4041
4209
  }
4042
4210
  }
4043
4211
  }
4044
- ts18.forEachChild(node, visit);
4212
+ ts19.forEachChild(node, visit);
4045
4213
  };
4046
- ts18.forEachChild(sourceFile, visit);
4214
+ ts19.forEachChild(sourceFile, visit);
4047
4215
  }
4048
4216
  return { kind: "checked", findings };
4049
4217
  }
@@ -4054,6 +4222,8 @@ export {
4054
4222
  DEFAULT_INCLUDE,
4055
4223
  GAME_PROJECT_DOCUMENT,
4056
4224
  GUI_EXTENSIONS,
4225
+ HSM_MODULE_SPECIFIER,
4226
+ HSM_REQUIRE_ROOT,
4057
4227
  INPUT_BINDING_EXTENSIONS,
4058
4228
  LIBRARY_DEPENDENCY_ROOT,
4059
4229
  LIBRARY_SCENE_EXTENSIONS,
@@ -4081,6 +4251,7 @@ export {
4081
4251
  checkUrlFragmentReachability,
4082
4252
  collectComponentDeclarations,
4083
4253
  collectComponentIds,
4254
+ compileHsmModules,
4084
4255
  componentIdOfSameObjectAddress,
4085
4256
  computeCompanionClosure,
4086
4257
  computeOutputRel,
@@ -4092,6 +4263,9 @@ export {
4092
4263
  getProgramDiagnostics,
4093
4264
  guiScriptResourceOf,
4094
4265
  guiScriptResourcesOf,
4266
+ hsmModules,
4267
+ hsmRequireName,
4268
+ hsmSourceFiles,
4095
4269
  isAddressClass,
4096
4270
  isContainedResourcePath,
4097
4271
  isDefignoredPath,
@@ -4100,6 +4274,7 @@ export {
4100
4274
  libraryIncludedEntries,
4101
4275
  listProjectResourcePaths,
4102
4276
  parseBuildConfig,
4277
+ parseDefignore,
4103
4278
  parseSceneTextFormat,
4104
4279
  projectRelativeBase,
4105
4280
  readGameProjectDependencies,
@@ -4109,6 +4284,7 @@ export {
4109
4284
  relativeAddressesFrom,
4110
4285
  requirePathForRel,
4111
4286
  resolveClassifiedSlotAtPosition,
4287
+ resolveHsmSourceDir,
4112
4288
  rewriteEmittedRequires,
4113
4289
  slotRejectsForeignSocket,
4114
4290
  socketOfAddress,