@defold-typescript/transpiler 0.42.0 → 0.44.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,13 @@ 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
+ import { LuaLibFeature } from "typescript-to-lua";
1392
+
1386
1393
  // src/lua-require-scan.ts
1387
1394
  var PLACEHOLDER = "\x00";
1388
1395
  function longBracketLevel(src, open) {
@@ -1476,6 +1483,149 @@ function scanEmittedRequires(lua) {
1476
1483
  return sites;
1477
1484
  }
1478
1485
 
1486
+ // src/hsm-builtin.ts
1487
+ var HSM_MODULE_SPECIFIER = "@defold-typescript/types/hsm";
1488
+ var HSM_REQUIRE_ROOT = "defold_typescript_hsm";
1489
+ var HSM_LUALIB_MODULES = new Set(["async"]);
1490
+ function hsmRequireName(name) {
1491
+ return `${HSM_REQUIRE_ROOT}.${name}`;
1492
+ }
1493
+ function hsmSpecifier(name) {
1494
+ return name === "index" ? HSM_MODULE_SPECIFIER : `${HSM_MODULE_SPECIFIER}/${name}`;
1495
+ }
1496
+ function defaultPackageRoot() {
1497
+ return path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
1498
+ }
1499
+ function hsmSourceFiles(dir) {
1500
+ 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();
1501
+ }
1502
+ function resolveHsmSourceDir(packageRoot = defaultPackageRoot()) {
1503
+ const workspace = path.join(packageRoot, "..", "hsm", "src");
1504
+ if (existsSync(workspace)) {
1505
+ return workspace;
1506
+ }
1507
+ const shipped = path.join(packageRoot, "dist", "hsm");
1508
+ if (existsSync(shipped)) {
1509
+ return shipped;
1510
+ }
1511
+ return null;
1512
+ }
1513
+ function requireHsmSourceDir() {
1514
+ const dir = resolveHsmSourceDir();
1515
+ if (dir === null) {
1516
+ throw new Error("@defold-typescript/transpiler: the hsm source is missing from this install; reinstall @defold-typescript/transpiler.");
1517
+ }
1518
+ return dir;
1519
+ }
1520
+ var modules;
1521
+ function hsmModules() {
1522
+ modules ??= hsmSourceFiles(requireHsmSourceDir()).map((file) => {
1523
+ const name = file.slice(0, -".ts".length);
1524
+ return { name, specifier: hsmSpecifier(name), requireName: hsmRequireName(name) };
1525
+ });
1526
+ return modules;
1527
+ }
1528
+ function hsmModuleOfRequire(requirePath) {
1529
+ if (!requirePath.startsWith(`${HSM_REQUIRE_ROOT}.`)) {
1530
+ return;
1531
+ }
1532
+ return hsmModules().find((module) => module.requireName === requirePath);
1533
+ }
1534
+ function isHsmRequireName(requirePath) {
1535
+ return hsmModuleOfRequire(requirePath) !== undefined;
1536
+ }
1537
+ function hsmModuleOfSpecifier(node) {
1538
+ if (node === undefined || !ts4.isStringLiteral(node)) {
1539
+ return;
1540
+ }
1541
+ const { text } = node;
1542
+ if (text !== HSM_MODULE_SPECIFIER && !text.startsWith(`${HSM_MODULE_SPECIFIER}/`)) {
1543
+ return;
1544
+ }
1545
+ return hsmModules().find((module) => module.specifier === text);
1546
+ }
1547
+ function requiredHsmNames(lua) {
1548
+ const names = [];
1549
+ for (const { path: requirePath } of scanEmittedRequires(lua)) {
1550
+ const module = hsmModuleOfRequire(requirePath);
1551
+ if (module !== undefined) {
1552
+ names.push(module.name);
1553
+ }
1554
+ }
1555
+ return names;
1556
+ }
1557
+ function hsmClosure(chunks, compile) {
1558
+ const pending = [];
1559
+ for (const lua of chunks) {
1560
+ pending.push(...requiredHsmNames(lua));
1561
+ }
1562
+ if (pending.length === 0) {
1563
+ return;
1564
+ }
1565
+ const compiled = compile();
1566
+ const selected = {};
1567
+ for (let name = pending.pop();name !== undefined; name = pending.pop()) {
1568
+ const lua = compiled[name];
1569
+ if (name in selected || lua === undefined) {
1570
+ continue;
1571
+ }
1572
+ selected[name] = lua;
1573
+ pending.push(...requiredHsmNames(lua));
1574
+ }
1575
+ return Object.fromEntries(Object.entries(selected).sort(([a], [b]) => a.localeCompare(b)));
1576
+ }
1577
+ function lowerSpecifier(module) {
1578
+ return ts4.factory.createStringLiteral(`@NoResolution:${module.requireName}`);
1579
+ }
1580
+ function loweredAnything(lowered) {
1581
+ return Array.isArray(lowered) ? lowered.length > 0 : lowered !== undefined;
1582
+ }
1583
+ function importSurvivesElision(node, context) {
1584
+ const clause = node.importClause;
1585
+ if (clause === undefined) {
1586
+ return true;
1587
+ }
1588
+ const { resolver } = context;
1589
+ if (clause.name !== undefined && resolver.isReferencedAliasDeclaration(clause)) {
1590
+ return true;
1591
+ }
1592
+ const bindings = clause.namedBindings;
1593
+ if (bindings === undefined) {
1594
+ return false;
1595
+ }
1596
+ if (ts4.isNamespaceImport(bindings)) {
1597
+ return resolver.isReferencedAliasDeclaration(bindings);
1598
+ }
1599
+ return bindings.elements.some((element) => resolver.isReferencedAliasDeclaration(element));
1600
+ }
1601
+ function registerLualib(module, emitted, context) {
1602
+ if (emitted && HSM_LUALIB_MODULES.has(module.name)) {
1603
+ context.usedLuaLibFeatures.add(LuaLibFeature.Promise);
1604
+ context.usedLuaLibFeatures.add(LuaLibFeature.New);
1605
+ }
1606
+ }
1607
+ var hsmLoweringPlugin = {
1608
+ visitors: {
1609
+ [ts4.SyntaxKind.ImportDeclaration]: (node, context) => {
1610
+ const module = hsmModuleOfSpecifier(node.moduleSpecifier);
1611
+ if (module === undefined) {
1612
+ return context.superTransformStatements(node);
1613
+ }
1614
+ registerLualib(module, importSurvivesElision(node, context), context);
1615
+ return context.superTransformStatements(ts4.factory.updateImportDeclaration(node, node.modifiers, node.importClause, lowerSpecifier(module), node.attributes));
1616
+ },
1617
+ [ts4.SyntaxKind.ExportDeclaration]: (node, context) => {
1618
+ const module = hsmModuleOfSpecifier(node.moduleSpecifier);
1619
+ if (module === undefined) {
1620
+ return context.superTransformStatements(node);
1621
+ }
1622
+ const lowered = context.superTransformStatements(ts4.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, lowerSpecifier(module), node.attributes));
1623
+ registerLualib(module, loweredAnything(lowered), context);
1624
+ return lowered;
1625
+ }
1626
+ }
1627
+ };
1628
+
1479
1629
  // src/timers-runtime.ts
1480
1630
  var TIMERS_MODULE_SPECIFIER = "@defold-typescript/types/timers";
1481
1631
  var TIMERS_REQUIRE_NAME = "defold_typescript_timers";
@@ -1530,7 +1680,7 @@ function findEmittedRequires(lua) {
1530
1680
  const found = [];
1531
1681
  const seen = new Set;
1532
1682
  for (const { path } of scanEmittedRequires(lua)) {
1533
- if (GENERATED_RUNTIME_REQUIRES.has(path) || seen.has(path)) {
1683
+ if (GENERATED_RUNTIME_REQUIRES.has(path) || isHsmRequireName(path) || seen.has(path)) {
1534
1684
  continue;
1535
1685
  }
1536
1686
  seen.add(path);
@@ -1989,20 +2139,20 @@ function readLibrarySceneDocuments(host, projectRoot, extensions = LIBRARY_SCENE
1989
2139
  return { documents, unreadable };
1990
2140
  }
1991
2141
  // src/main-entry-factory-imports.ts
1992
- import * as ts4 from "typescript";
2142
+ import * as ts5 from "typescript";
1993
2143
  function findMainEntryFactoryImports(fileName, source) {
1994
- const sourceFile = ts4.createSourceFile(fileName, source, ts4.ScriptTarget.Latest, true);
2144
+ const sourceFile = ts5.createSourceFile(fileName, source, ts5.ScriptTarget.Latest, true);
1995
2145
  const factories = [];
1996
2146
  for (const statement of sourceFile.statements) {
1997
- if (!ts4.isImportDeclaration(statement)) {
2147
+ if (!ts5.isImportDeclaration(statement)) {
1998
2148
  continue;
1999
2149
  }
2000
2150
  const specifier = statement.moduleSpecifier;
2001
- if (!ts4.isStringLiteral(specifier) || specifier.text !== FACTORY_MODULE) {
2151
+ if (!ts5.isStringLiteral(specifier) || specifier.text !== FACTORY_MODULE) {
2002
2152
  continue;
2003
2153
  }
2004
2154
  const bindings = statement.importClause?.namedBindings;
2005
- if (bindings === undefined || !ts4.isNamedImports(bindings)) {
2155
+ if (bindings === undefined || !ts5.isNamedImports(bindings)) {
2006
2156
  continue;
2007
2157
  }
2008
2158
  for (const element of bindings.elements) {
@@ -2015,7 +2165,7 @@ function findMainEntryFactoryImports(fileName, source) {
2015
2165
  return factories;
2016
2166
  }
2017
2167
  // src/output-paths.ts
2018
- import * as path from "node:path";
2168
+ import * as path2 from "node:path";
2019
2169
  var DEFAULT_INCLUDE = ["src/**/*.ts"];
2020
2170
  var SCRIPT_SUFFIX_BY_KIND = {
2021
2171
  script: ".ts.script",
@@ -2032,7 +2182,7 @@ function parseBuildConfig(raw) {
2032
2182
  function stripIncludeBase(pattern) {
2033
2183
  const firstWildcard = pattern.search(/[*?[]/);
2034
2184
  if (firstWildcard === -1) {
2035
- return pattern.endsWith("/") ? pattern : `${path.posix.dirname(pattern)}/`;
2185
+ return pattern.endsWith("/") ? pattern : `${path2.posix.dirname(pattern)}/`;
2036
2186
  }
2037
2187
  const upToWildcard = pattern.slice(0, firstWildcard);
2038
2188
  const lastSlash = upToWildcard.lastIndexOf("/");
@@ -2043,7 +2193,7 @@ function projectRelativeBase(pattern) {
2043
2193
  if (ABSOLUTE_SPELLING_RE.test(pattern)) {
2044
2194
  return;
2045
2195
  }
2046
- const base = path.posix.normalize(stripIncludeBase(pattern.split("\\").join("/")));
2196
+ const base = path2.posix.normalize(stripIncludeBase(pattern.split("\\").join("/")));
2047
2197
  if (base === ".." || base.startsWith("../")) {
2048
2198
  return;
2049
2199
  }
@@ -2056,7 +2206,7 @@ function relUnderOutDir(rel, config) {
2056
2206
  }
2057
2207
  const includeBase = include.map(stripIncludeBase).filter((base) => rel.startsWith(base)).sort((a, b) => b.length - a.length)[0] ?? "";
2058
2208
  const relUnderBase = rel.slice(includeBase.length);
2059
- return path.posix.join(outDir, relUnderBase);
2209
+ return path2.posix.join(outDir, relUnderBase);
2060
2210
  }
2061
2211
  function requirePathForRel(rel) {
2062
2212
  const segments = rel.split("/").filter((segment) => segment !== "" && segment !== "." && segment !== "..");
@@ -2075,16 +2225,16 @@ function computeOutputRel(rel, config, kind) {
2075
2225
  return baseRel.replace(/\.ts$/, SCRIPT_SUFFIX_BY_KIND[kind]);
2076
2226
  }
2077
2227
  // src/program-diagnostics.ts
2078
- import * as ts9 from "typescript";
2228
+ import * as ts10 from "typescript";
2079
2229
  import * as tstl from "typescript-to-lua";
2080
2230
 
2081
2231
  // src/message-guard-lowering.ts
2082
- import * as ts5 from "typescript";
2232
+ import * as ts6 from "typescript";
2083
2233
  import {
2084
2234
  createBinaryExpression as createBinaryExpression3,
2085
2235
  createCallExpression as createCallExpression3,
2086
2236
  createIdentifier as createIdentifier3,
2087
- SyntaxKind as SyntaxKind7
2237
+ SyntaxKind as SyntaxKind8
2088
2238
  } from "typescript-to-lua";
2089
2239
  var GUARD_MODULE = "@defold-typescript/types";
2090
2240
  var GUARD_NAME = "isMessage";
@@ -2093,7 +2243,7 @@ function resolvesToGuardExport(callee, checker) {
2093
2243
  if (symbol === undefined) {
2094
2244
  return false;
2095
2245
  }
2096
- if (symbol.flags & ts5.SymbolFlags.Alias) {
2246
+ if (symbol.flags & ts6.SymbolFlags.Alias) {
2097
2247
  symbol = checker.getAliasedSymbol(symbol);
2098
2248
  }
2099
2249
  if (symbol.getName() !== GUARD_NAME) {
@@ -2107,12 +2257,12 @@ function resolvesToGuardExport(callee, checker) {
2107
2257
  }
2108
2258
  var messageGuardLoweringPlugin = {
2109
2259
  visitors: {
2110
- [ts5.SyntaxKind.CallExpression]: (node, context) => {
2260
+ [ts6.SyntaxKind.CallExpression]: (node, context) => {
2111
2261
  const [messageIdArg, , expectedArg] = node.arguments;
2112
2262
  if (node.arguments.length === 3 && messageIdArg !== undefined && expectedArg !== undefined && resolvesToGuardExport(node.expression, context.checker)) {
2113
2263
  const messageId = context.transformExpression(messageIdArg);
2114
2264
  const expected = context.transformExpression(expectedArg);
2115
- return createBinaryExpression3(messageId, createCallExpression3(createIdentifier3("hash"), [expected]), SyntaxKind7.EqualityOperator, node);
2265
+ return createBinaryExpression3(messageId, createCallExpression3(createIdentifier3("hash"), [expected]), SyntaxKind8.EqualityOperator, node);
2116
2266
  }
2117
2267
  return context.superTransformExpression(node);
2118
2268
  }
@@ -2120,37 +2270,37 @@ var messageGuardLoweringPlugin = {
2120
2270
  };
2121
2271
 
2122
2272
  // src/timers-lowering.ts
2123
- import * as ts6 from "typescript";
2124
- import { LuaLibFeature } from "typescript-to-lua";
2273
+ import * as ts7 from "typescript";
2274
+ import { LuaLibFeature as LuaLibFeature2 } from "typescript-to-lua";
2125
2275
  function isTimersSpecifier(node) {
2126
- return ts6.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
2276
+ return ts7.isStringLiteral(node) && node.text === TIMERS_MODULE_SPECIFIER;
2127
2277
  }
2128
2278
  function importsTimersModule(sourceFile) {
2129
- return sourceFile.statements.some((statement) => ts6.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
2279
+ return sourceFile.statements.some((statement) => ts7.isImportDeclaration(statement) && isTimersSpecifier(statement.moduleSpecifier));
2130
2280
  }
2131
2281
  var TIMERS_REQUIRE_PATH = `@NoResolution:${TIMERS_REQUIRE_NAME}`;
2132
2282
  var timersLoweringPlugin = {
2133
2283
  visitors: {
2134
- [ts6.SyntaxKind.ImportDeclaration]: (node, context) => {
2284
+ [ts7.SyntaxKind.ImportDeclaration]: (node, context) => {
2135
2285
  if (!isTimersSpecifier(node.moduleSpecifier)) {
2136
2286
  return context.superTransformStatements(node);
2137
2287
  }
2138
- context.usedLuaLibFeatures.add(LuaLibFeature.Promise);
2139
- context.usedLuaLibFeatures.add(LuaLibFeature.New);
2140
- const rewritten = ts6.factory.updateImportDeclaration(node, node.modifiers, node.importClause, ts6.factory.createStringLiteral(TIMERS_REQUIRE_PATH), node.attributes);
2288
+ context.usedLuaLibFeatures.add(LuaLibFeature2.Promise);
2289
+ context.usedLuaLibFeatures.add(LuaLibFeature2.New);
2290
+ const rewritten = ts7.factory.updateImportDeclaration(node, node.modifiers, node.importClause, ts7.factory.createStringLiteral(TIMERS_REQUIRE_PATH), node.attributes);
2141
2291
  return context.superTransformStatements(rewritten);
2142
2292
  }
2143
2293
  }
2144
2294
  };
2145
2295
 
2146
2296
  // src/type-application-erasure.ts
2147
- import * as ts7 from "typescript";
2297
+ import * as ts8 from "typescript";
2148
2298
  var TYPE_APPLICATION_APIS = new Set(["go.get", "go.set"]);
2149
2299
  function isTypeApplication(call, checker) {
2150
2300
  if (call.arguments.length !== 0)
2151
2301
  return false;
2152
2302
  const declaration = checker.getResolvedSignature(call)?.declaration;
2153
- if (declaration === undefined || !ts7.isFunctionDeclaration(declaration))
2303
+ if (declaration === undefined || !ts8.isFunctionDeclaration(declaration))
2154
2304
  return false;
2155
2305
  if (declaration.parameters.length !== 0 || declaration.typeParameters === undefined)
2156
2306
  return false;
@@ -2164,7 +2314,7 @@ function isTypeApplication(call, checker) {
2164
2314
  }
2165
2315
  var typeApplicationErasurePlugin = {
2166
2316
  visitors: {
2167
- [ts7.SyntaxKind.CallExpression]: (node, context) => {
2317
+ [ts8.SyntaxKind.CallExpression]: (node, context) => {
2168
2318
  if (isTypeApplication(node, context.checker)) {
2169
2319
  return context.transformExpression(node.expression);
2170
2320
  }
@@ -2174,10 +2324,10 @@ var typeApplicationErasurePlugin = {
2174
2324
  };
2175
2325
 
2176
2326
  // src/window-event-guard-lowering.ts
2177
- import * as ts8 from "typescript";
2327
+ import * as ts9 from "typescript";
2178
2328
  import {
2179
2329
  createBinaryExpression as createBinaryExpression4,
2180
- SyntaxKind as SyntaxKind11
2330
+ SyntaxKind as SyntaxKind12
2181
2331
  } from "typescript-to-lua";
2182
2332
  var GUARD_MODULE2 = "@defold-typescript/types";
2183
2333
  var GUARD_NAME2 = "isWindowEvent";
@@ -2186,7 +2336,7 @@ function resolvesToGuardExport2(callee, checker) {
2186
2336
  if (symbol === undefined) {
2187
2337
  return false;
2188
2338
  }
2189
- if (symbol.flags & ts8.SymbolFlags.Alias) {
2339
+ if (symbol.flags & ts9.SymbolFlags.Alias) {
2190
2340
  symbol = checker.getAliasedSymbol(symbol);
2191
2341
  }
2192
2342
  if (symbol.getName() !== GUARD_NAME2) {
@@ -2200,12 +2350,12 @@ function resolvesToGuardExport2(callee, checker) {
2200
2350
  }
2201
2351
  var windowEventGuardLoweringPlugin = {
2202
2352
  visitors: {
2203
- [ts8.SyntaxKind.CallExpression]: (node, context) => {
2353
+ [ts9.SyntaxKind.CallExpression]: (node, context) => {
2204
2354
  const [eventArg, , expectedArg] = node.arguments;
2205
2355
  if (node.arguments.length === 3 && eventArg !== undefined && expectedArg !== undefined && resolvesToGuardExport2(node.expression, context.checker)) {
2206
2356
  const event = context.transformExpression(eventArg);
2207
2357
  const expected = context.transformExpression(expectedArg);
2208
- return createBinaryExpression4(event, expected, SyntaxKind11.EqualityOperator, node);
2358
+ return createBinaryExpression4(event, expected, SyntaxKind12.EqualityOperator, node);
2209
2359
  }
2210
2360
  return context.superTransformExpression(node);
2211
2361
  }
@@ -2226,7 +2376,7 @@ function isAmbient(fileName) {
2226
2376
  return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
2227
2377
  }
2228
2378
  function getProgramDiagnostics(program, sourceFile) {
2229
- const { diagnostics } = tstl.getProgramTranspileResult(ts9.sys, noopWriteFile, {
2379
+ const { diagnostics } = tstl.getProgramTranspileResult(ts10.sys, noopWriteFile, {
2230
2380
  program,
2231
2381
  plugins: LUA_PLUGINS,
2232
2382
  ...sourceFile ? { sourceFiles: [sourceFile] } : {}
@@ -2796,12 +2946,12 @@ function relativeAddressesFrom(index, context) {
2796
2946
  // src/session.ts
2797
2947
  import { readFileSync as readFileSync2 } from "node:fs";
2798
2948
  import { createRequire as createRequire2 } from "node:module";
2799
- import * as path3 from "node:path";
2800
- import * as ts13 from "typescript";
2949
+ import * as path4 from "node:path";
2950
+ import * as ts14 from "typescript";
2801
2951
  import * as tstl3 from "typescript-to-lua";
2802
2952
 
2803
2953
  // src/companion-emit.ts
2804
- import * as ts10 from "typescript";
2954
+ import * as ts11 from "typescript";
2805
2955
  import {
2806
2956
  createAssignmentStatement as createAssignmentStatement2,
2807
2957
  createCallExpression as createCallExpression4,
@@ -2824,7 +2974,7 @@ import {
2824
2974
  isMethodCallExpression,
2825
2975
  isRepeatStatement,
2826
2976
  isReturnStatement as isReturnStatement2,
2827
- isStringLiteral as isStringLiteral6,
2977
+ isStringLiteral as isStringLiteral7,
2828
2978
  isTableExpression,
2829
2979
  isVariableDeclarationStatement,
2830
2980
  LuaPrinter
@@ -2835,8 +2985,8 @@ function exportsIdentifier() {
2835
2985
  }
2836
2986
  function isRuntimeScriptSource(sourceFile, checker) {
2837
2987
  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);
2988
+ const expression = ts11.isExpressionStatement(statement) ? statement.expression : ts11.isExportAssignment(statement) && !statement.isExportEquals ? statement.expression : undefined;
2989
+ return expression !== undefined && ts11.isCallExpression(expression) && resolvesToFactoryExport(expression.expression, checker);
2840
2990
  });
2841
2991
  }
2842
2992
  function planFor(sourceFile, checker) {
@@ -2988,11 +3138,11 @@ function freeNames(statements) {
2988
3138
  function resolvedRequirePaths(sourceFile, checker) {
2989
3139
  const paths = new Map;
2990
3140
  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)) {
3141
+ const specifier = ts11.isImportDeclaration(statement) || ts11.isExportDeclaration(statement) ? statement.moduleSpecifier : undefined;
3142
+ if (specifier === undefined || !ts11.isStringLiteral(specifier)) {
2993
3143
  continue;
2994
3144
  }
2995
- const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts10.isSourceFile(declaration));
3145
+ const target = checker.getSymbolAtLocation(specifier)?.declarations?.find((declaration) => ts11.isSourceFile(declaration));
2996
3146
  if (target === undefined || target.isDeclarationFile) {
2997
3147
  continue;
2998
3148
  }
@@ -3010,7 +3160,7 @@ function resolveMovedRequires(statements, paths) {
3010
3160
  return;
3011
3161
  }
3012
3162
  const [argument] = node.params;
3013
- if (argument === undefined || !isStringLiteral6(argument)) {
3163
+ if (argument === undefined || !isStringLiteral7(argument)) {
3014
3164
  return;
3015
3165
  }
3016
3166
  const resolved = paths.get(argument.value);
@@ -3033,7 +3183,7 @@ function withResolvedRequire(statement, paths) {
3033
3183
  return statement;
3034
3184
  }
3035
3185
  const [argument] = value.params;
3036
- if (argument === undefined || !isStringLiteral6(argument)) {
3186
+ if (argument === undefined || !isStringLiteral7(argument)) {
3037
3187
  return statement;
3038
3188
  }
3039
3189
  const resolved = paths.get(argument.value);
@@ -3156,11 +3306,11 @@ function createCompanionEmitPlugin() {
3156
3306
  return statements;
3157
3307
  }
3158
3308
  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
3309
+ [ts11.SyntaxKind.VariableStatement]: capture,
3310
+ [ts11.SyntaxKind.FunctionDeclaration]: capture,
3311
+ [ts11.SyntaxKind.ClassDeclaration]: capture,
3312
+ [ts11.SyntaxKind.EnumDeclaration]: capture,
3313
+ [ts11.SyntaxKind.ExportDeclaration]: capture
3164
3314
  };
3165
3315
  let configuredNoResolvePaths = [];
3166
3316
  const plugin = {
@@ -3229,7 +3379,7 @@ function emitCompanion(program, emitHost, file, sourceFile, plan, owned, compani
3229
3379
  }
3230
3380
 
3231
3381
  // src/editor-script-erasure.ts
3232
- import * as ts11 from "typescript";
3382
+ import * as ts12 from "typescript";
3233
3383
  import {
3234
3384
  createReturnStatement as createReturnStatement3
3235
3385
  } from "typescript-to-lua";
@@ -3249,7 +3399,7 @@ function resolveEditorFactoryExport(callee, checker) {
3249
3399
  if (symbol === undefined) {
3250
3400
  return;
3251
3401
  }
3252
- if (symbol.flags & ts11.SymbolFlags.Alias) {
3402
+ if (symbol.flags & ts12.SymbolFlags.Alias) {
3253
3403
  symbol = checker.getAliasedSymbol(symbol);
3254
3404
  }
3255
3405
  const name = symbol.getName();
@@ -3263,7 +3413,7 @@ function resolveEditorFactoryExport(callee, checker) {
3263
3413
  return declaration.getSourceFile().fileName.includes(EDITOR_FACTORY_MODULE) ? name : undefined;
3264
3414
  }
3265
3415
  function lowerEditorFactoryCall(expression, context) {
3266
- if (!ts11.isCallExpression(expression)) {
3416
+ if (!ts12.isCallExpression(expression)) {
3267
3417
  return;
3268
3418
  }
3269
3419
  if (resolveEditorFactoryExport(expression.expression, context.checker) !== EDITOR_SCRIPT_FACTORY_NAME) {
@@ -3276,7 +3426,7 @@ function lowerEditorFactoryCall(expression, context) {
3276
3426
  return [createReturnStatement3([context.transformExpression(module)])];
3277
3427
  }
3278
3428
  function isEditorFactoryOnlyImport(node) {
3279
- if (!ts11.isStringLiteral(node.moduleSpecifier) || !EDITOR_FACTORY_SPECIFIERS.has(node.moduleSpecifier.text)) {
3429
+ if (!ts12.isStringLiteral(node.moduleSpecifier) || !EDITOR_FACTORY_SPECIFIERS.has(node.moduleSpecifier.text)) {
3280
3430
  return false;
3281
3431
  }
3282
3432
  const clause = node.importClause;
@@ -3287,7 +3437,7 @@ function isEditorFactoryOnlyImport(node) {
3287
3437
  return false;
3288
3438
  }
3289
3439
  const bindings = clause.namedBindings;
3290
- if (bindings === undefined || !ts11.isNamedImports(bindings)) {
3440
+ if (bindings === undefined || !ts12.isNamedImports(bindings)) {
3291
3441
  return false;
3292
3442
  }
3293
3443
  const runtime = bindings.elements.filter((element) => !element.isTypeOnly);
@@ -3298,7 +3448,7 @@ function isEditorFactoryOnlyImport(node) {
3298
3448
  }
3299
3449
  var editorScriptErasurePlugin = {
3300
3450
  visitors: {
3301
- [ts11.SyntaxKind.ExportAssignment]: (node, context) => {
3451
+ [ts12.SyntaxKind.ExportAssignment]: (node, context) => {
3302
3452
  if (!node.isExportEquals) {
3303
3453
  const lowered = lowerEditorFactoryCall(node.expression, context);
3304
3454
  if (lowered !== undefined) {
@@ -3307,35 +3457,35 @@ var editorScriptErasurePlugin = {
3307
3457
  }
3308
3458
  return context.superTransformStatements(node);
3309
3459
  },
3310
- [ts11.SyntaxKind.CallExpression]: (node, context) => {
3460
+ [ts12.SyntaxKind.CallExpression]: (node, context) => {
3311
3461
  const command = node.arguments[0];
3312
3462
  if (command !== undefined && resolveEditorFactoryExport(node.expression, context.checker) === EDITOR_COMMAND_FACTORY_NAME) {
3313
3463
  return context.transformExpression(command);
3314
3464
  }
3315
3465
  return context.superTransformExpression(node);
3316
3466
  },
3317
- [ts11.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
3467
+ [ts12.SyntaxKind.ImportDeclaration]: (node, context) => isEditorFactoryOnlyImport(node) ? [] : context.superTransformStatements(node)
3318
3468
  }
3319
3469
  };
3320
3470
 
3321
3471
  // src/transpile.ts
3322
- import { readdirSync, readFileSync } from "node:fs";
3472
+ import { readdirSync as readdirSync2, readFileSync } from "node:fs";
3323
3473
  import { createRequire } from "node:module";
3324
- import * as path2 from "node:path";
3474
+ import * as path3 from "node:path";
3325
3475
  import * as tstl2 from "typescript-to-lua";
3326
3476
 
3327
3477
  // src/go-property-direct-call.ts
3328
- import * as ts12 from "typescript";
3478
+ import * as ts13 from "typescript";
3329
3479
  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
3480
  function findDirectGoPropertyCalls(sourceFile) {
3331
3481
  const calls = [];
3332
3482
  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") {
3483
+ if (ts13.isCallExpression(node) && ts13.isPropertyAccessExpression(node.expression) && node.expression.name.text === "property" && ts13.isIdentifier(node.expression.expression) && node.expression.expression.text === "go") {
3334
3484
  calls.push(node);
3335
3485
  }
3336
- ts12.forEachChild(node, visit);
3486
+ ts13.forEachChild(node, visit);
3337
3487
  };
3338
- ts12.forEachChild(sourceFile, visit);
3488
+ ts13.forEachChild(sourceFile, visit);
3339
3489
  return calls;
3340
3490
  }
3341
3491
 
@@ -3347,12 +3497,12 @@ function flattenDiagnosticMessage(text) {
3347
3497
  return flattenDiagnosticMessage(text.messageText);
3348
3498
  }
3349
3499
  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"));
3500
+ var TYPES_PKG_ROOT = path3.dirname(requireFromHere.resolve("@defold-typescript/types/package.json"));
3501
+ var TSTL_LANG_EXT_ROOT = path3.dirname(requireFromHere.resolve("@typescript-to-lua/language-extensions/package.json"));
3352
3502
  function readAmbient(rel) {
3353
- return readFileSync(path2.join(TYPES_PKG_ROOT, rel), "utf8");
3503
+ return readFileSync(path3.join(TYPES_PKG_ROOT, rel), "utf8");
3354
3504
  }
3355
- var LUA_TYPES_ROOT = path2.dirname(createRequire(path2.join(TYPES_PKG_ROOT, "package.json")).resolve("lua-types/package.json"));
3505
+ var LUA_TYPES_ROOT = path3.dirname(createRequire(path3.join(TYPES_PKG_ROOT, "package.json")).resolve("lua-types/package.json"));
3356
3506
  var LUA_TYPES_ENTRY_FILES = ["5.1.d.ts", "special/jit-only.d.ts"];
3357
3507
  var REFERENCE_PATH_RE = /\/\/\/\s*<reference\s+path="([^"]+)"\s*\/>/g;
3358
3508
  function collectLuaTypesClosure() {
@@ -3361,14 +3511,14 @@ function collectLuaTypesClosure() {
3361
3511
  const key = `node_modules/lua-types/${rel}`;
3362
3512
  if (key in files)
3363
3513
  return;
3364
- const source = readFileSync(path2.join(LUA_TYPES_ROOT, rel), "utf8");
3514
+ const source = readFileSync(path3.join(LUA_TYPES_ROOT, rel), "utf8");
3365
3515
  files[key] = source;
3366
- const dir = path2.posix.dirname(rel);
3516
+ const dir = path3.posix.dirname(rel);
3367
3517
  for (const match of source.matchAll(REFERENCE_PATH_RE)) {
3368
3518
  const ref = match[1];
3369
3519
  if (!ref)
3370
3520
  continue;
3371
- visit(path2.posix.normalize(path2.posix.join(dir, ref)));
3521
+ visit(path3.posix.normalize(path3.posix.join(dir, ref)));
3372
3522
  }
3373
3523
  };
3374
3524
  for (const entry of LUA_TYPES_ENTRY_FILES)
@@ -3377,7 +3527,7 @@ function collectLuaTypesClosure() {
3377
3527
  }
3378
3528
  function buildAmbientFiles() {
3379
3529
  const files = {
3380
- "node_modules/@typescript-to-lua/language-extensions/index.d.ts": readFileSync(path2.join(TSTL_LANG_EXT_ROOT, "index.d.ts"), "utf8"),
3530
+ "node_modules/@typescript-to-lua/language-extensions/index.d.ts": readFileSync(path3.join(TSTL_LANG_EXT_ROOT, "index.d.ts"), "utf8"),
3381
3531
  "node_modules/@defold-typescript/types/src/core-types.ts": readAmbient("src/core-types.ts"),
3382
3532
  "node_modules/@defold-typescript/types/src/engine-globals.d.ts": readAmbient("src/engine-globals.d.ts"),
3383
3533
  "node_modules/@defold-typescript/types/src/go-overloads.d.ts": readAmbient("src/go-overloads.d.ts"),
@@ -3416,13 +3566,18 @@ export type { ScriptProperties, ScriptProperty } from "./src/lifecycle.js";
3416
3566
  ].join(`
3417
3567
  `)
3418
3568
  };
3569
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "hsm"))) {
3570
+ if (entry.endsWith(".d.ts")) {
3571
+ files[`node_modules/@defold-typescript/types/hsm/${entry}`] = readAmbient(`hsm/${entry}`);
3572
+ }
3573
+ }
3419
3574
  Object.assign(files, collectLuaTypesClosure());
3420
- for (const entry of readdirSync(path2.join(TYPES_PKG_ROOT, "generated"))) {
3575
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "generated"))) {
3421
3576
  if (entry.endsWith(".d.ts")) {
3422
3577
  files[`node_modules/@defold-typescript/types/generated/${entry}`] = readAmbient(`generated/${entry}`);
3423
3578
  }
3424
3579
  }
3425
- for (const entry of readdirSync(path2.join(TYPES_PKG_ROOT, "src"))) {
3580
+ for (const entry of readdirSync2(path3.join(TYPES_PKG_ROOT, "src"))) {
3426
3581
  if (entry.endsWith(".d.ts")) {
3427
3582
  files[`node_modules/@defold-typescript/types/src/${entry}`] = readAmbient(`src/${entry}`);
3428
3583
  }
@@ -3489,20 +3644,19 @@ function collectOutputs(transpiledFiles, diagnostics, userKeys, emittedCompanion
3489
3644
  }
3490
3645
  }
3491
3646
  }
3647
+ const hsm = hsmClosure([...Object.values(lua), ...Object.values(companions)], compileHsmModules);
3492
3648
  return {
3493
3649
  lua,
3494
3650
  sourceMaps,
3495
3651
  diagnostics: collectedDiagnostics,
3496
3652
  ...Object.keys(companions).length > 0 ? { companions } : {},
3497
3653
  ...lualib !== undefined ? { lualib } : {},
3498
- ...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {}
3654
+ ...timersImported ? { timersRuntime: TIMERS_RUNTIME } : {},
3655
+ ...hsm !== undefined ? { hsmModules: hsm } : {}
3499
3656
  };
3500
3657
  }
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, {
3658
+ function transpileVirtual(files, companionEmit) {
3659
+ return tstl2.transpileVirtualProject({ ...AMBIENT_FILES, ...files }, {
3506
3660
  luaTarget: tstl2.LuaTarget.Lua51,
3507
3661
  sourceMap: true,
3508
3662
  lib: ["lib.es2022.d.ts"],
@@ -3515,12 +3669,59 @@ function transpileProject(input) {
3515
3669
  { plugin: windowEventGuardLoweringPlugin },
3516
3670
  { plugin: messageDispatchLoweringPlugin },
3517
3671
  { plugin: timersLoweringPlugin },
3672
+ { plugin: hsmLoweringPlugin },
3518
3673
  { plugin: typeApplicationErasurePlugin },
3519
3674
  { plugin: companionEmit.plugin }
3520
3675
  ]
3521
3676
  });
3677
+ }
3678
+ function transpileProject(input) {
3679
+ const userKeys = new Set(Object.keys(input.files));
3680
+ const companionEmit = createCompanionEmitPlugin();
3681
+ const result = transpileVirtual(input.files, companionEmit);
3522
3682
  return collectOutputs(result.transpiledFiles, result.diagnostics, userKeys, companionEmit.companions);
3523
3683
  }
3684
+ var compiledHsm;
3685
+ function requiresLualib(lua) {
3686
+ return scanEmittedRequires(lua).some(({ path: requirePath }) => requirePath === "lualib_bundle");
3687
+ }
3688
+ function compileHsmModules() {
3689
+ if (compiledHsm !== undefined) {
3690
+ return compiledHsm;
3691
+ }
3692
+ const sourceDir = requireHsmSourceDir();
3693
+ const nameByKey = new Map;
3694
+ const files = {};
3695
+ for (const { name } of hsmModules()) {
3696
+ const key = `${HSM_REQUIRE_ROOT}/${name}.ts`;
3697
+ nameByKey.set(key, name);
3698
+ files[key] = readFileSync(path3.join(sourceDir, `${name}.ts`), "utf8");
3699
+ }
3700
+ const result = transpileVirtual(files, createCompanionEmitPlugin());
3701
+ const problems = result.diagnostics.map((d) => `${d.file?.fileName ?? "(project)"}: ${flattenDiagnosticMessage(d.messageText)}`);
3702
+ const lua = {};
3703
+ for (const file of result.transpiledFiles) {
3704
+ if (isLualibBundle(file)) {
3705
+ continue;
3706
+ }
3707
+ const source = file.sourceFiles.find((s) => nameByKey.has(s.fileName));
3708
+ const name = source === undefined ? undefined : nameByKey.get(source.fileName);
3709
+ if (name === undefined || typeof file.lua !== "string") {
3710
+ continue;
3711
+ }
3712
+ if (!HSM_LUALIB_MODULES.has(name) && requiresLualib(file.lua)) {
3713
+ problems.push(`the compiled ${name} module requires lualib_bundle`);
3714
+ }
3715
+ lua[name] = file.lua;
3716
+ }
3717
+ if (problems.length > 0) {
3718
+ throw new Error(`@defold-typescript/transpiler: the hsm library does not compile:
3719
+ ${problems.join(`
3720
+ `)}`);
3721
+ }
3722
+ compiledHsm = lua;
3723
+ return lua;
3724
+ }
3524
3725
  function transpile(source) {
3525
3726
  const project = transpileProject({ files: { "main.ts": source } });
3526
3727
  return {
@@ -3546,6 +3747,7 @@ function compilerOptions(companionEmit) {
3546
3747
  { plugin: windowEventGuardLoweringPlugin },
3547
3748
  { plugin: messageDispatchLoweringPlugin },
3548
3749
  { plugin: timersLoweringPlugin },
3750
+ { plugin: hsmLoweringPlugin },
3549
3751
  { plugin: typeApplicationErasurePlugin },
3550
3752
  { plugin: companionEmit.plugin }
3551
3753
  ]
@@ -3589,18 +3791,18 @@ function createTranspileSession() {
3589
3791
  if (cached) {
3590
3792
  return cached;
3591
3793
  }
3592
- const created = ts13.createSourceFile(fileName, content, ts13.ScriptTarget.Latest, false);
3794
+ const created = ts14.createSourceFile(fileName, content, ts14.ScriptTarget.Latest, false);
3593
3795
  sourceFileCache.set(normalized, created);
3594
3796
  return created;
3595
3797
  }
3596
3798
  let filePath;
3597
3799
  if (fileName.startsWith("lib.")) {
3598
- const typeScriptDir = path3.dirname(requireFromHere2.resolve("typescript"));
3599
- filePath = path3.join(typeScriptDir, fileName);
3800
+ const typeScriptDir = path4.dirname(requireFromHere2.resolve("typescript"));
3801
+ filePath = path4.join(typeScriptDir, fileName);
3600
3802
  }
3601
3803
  if (fileName.includes("language-extensions")) {
3602
3804
  const dtsName = fileName.replace(/(\.d)?(\.ts)$/, ".d.ts");
3603
- filePath = path3.resolve(dtsName);
3805
+ filePath = path4.resolve(dtsName);
3604
3806
  }
3605
3807
  if (filePath !== undefined) {
3606
3808
  const cached = libCache.get(fileName);
@@ -3608,7 +3810,7 @@ function createTranspileSession() {
3608
3810
  return cached;
3609
3811
  }
3610
3812
  const fileContent = readFileSync2(filePath, "utf8");
3611
- const created = ts13.createSourceFile(filePath, fileContent, ts13.ScriptTarget.Latest, false);
3813
+ const created = ts14.createSourceFile(filePath, fileContent, ts14.ScriptTarget.Latest, false);
3612
3814
  libCache.set(fileName, created);
3613
3815
  return created;
3614
3816
  }
@@ -3621,10 +3823,10 @@ function createTranspileSession() {
3621
3823
  return AMBIENT_FILES[normalized];
3622
3824
  }
3623
3825
  const host = {
3624
- fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts13.sys.fileExists(fileName),
3826
+ fileExists: (fileName) => mergedContent(normalizeSlashes(fileName)) !== undefined || ts14.sys.fileExists(fileName),
3625
3827
  getCanonicalFileName: (fileName) => fileName,
3626
3828
  getCurrentDirectory: () => "",
3627
- getDefaultLibFileName: ts13.getDefaultLibFileName,
3829
+ getDefaultLibFileName: ts14.getDefaultLibFileName,
3628
3830
  readFile: () => "",
3629
3831
  getNewLine: () => `
3630
3832
  `,
@@ -3646,15 +3848,15 @@ function createTranspileSession() {
3646
3848
  const userKeys = new Set(userFiles.keys());
3647
3849
  const rootNames = [...Object.keys(AMBIENT_FILES).map(normalizeSlashes), ...userKeys];
3648
3850
  const companionEmit = createCompanionEmitPlugin();
3649
- program = ts13.createProgram(rootNames, compilerOptions(companionEmit), host, program);
3650
- const preEmitDiagnostics = ts13.getPreEmitDiagnostics(program);
3851
+ program = ts14.createProgram(rootNames, compilerOptions(companionEmit), host, program);
3852
+ const preEmitDiagnostics = ts14.getPreEmitDiagnostics(program);
3651
3853
  const collector = createOutputCollector();
3652
3854
  const { diagnostics: transpileDiagnostics } = new tstl3.Transpiler().emit({
3653
3855
  program,
3654
3856
  writeFile: collector.writeFile
3655
3857
  });
3656
3858
  const diagnostics = [
3657
- ...ts13.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
3859
+ ...ts14.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics])
3658
3860
  ];
3659
3861
  return collectOutputs(collector.files, diagnostics, userKeys, companionEmit.companions);
3660
3862
  }
@@ -3664,7 +3866,7 @@ function createTranspileSession() {
3664
3866
  };
3665
3867
  }
3666
3868
  // src/text-script-property.ts
3667
- import * as ts14 from "typescript";
3869
+ import * as ts15 from "typescript";
3668
3870
  function findTextScriptProperties(program, fileNames) {
3669
3871
  const checker = program.getTypeChecker();
3670
3872
  const findings = [];
@@ -3675,7 +3877,7 @@ function findTextScriptProperties(program, fileNames) {
3675
3877
  }
3676
3878
  const located = [];
3677
3879
  const visit = (node) => {
3678
- if (ts14.isCallExpression(node)) {
3880
+ if (ts15.isCallExpression(node)) {
3679
3881
  const hooks = factoryHooks(node, checker);
3680
3882
  for (const property of hooks?.properties ?? []) {
3681
3883
  if (!isPropertiesHook(property)) {
@@ -3688,7 +3890,7 @@ function findTextScriptProperties(program, fileNames) {
3688
3890
  }
3689
3891
  }
3690
3892
  }
3691
- ts14.forEachChild(node, visit);
3893
+ ts15.forEachChild(node, visit);
3692
3894
  };
3693
3895
  visit(sourceFile);
3694
3896
  for (const call of findDirectGoPropertyCalls(sourceFile)) {
@@ -3697,7 +3899,7 @@ function findTextScriptProperties(program, fileNames) {
3697
3899
  continue;
3698
3900
  }
3699
3901
  if (mayHoldString(checker.getTypeAtLocation(value), checker)) {
3700
- const name = ts14.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
3902
+ const name = ts15.isStringLiteralLike(nameArgument) ? nameArgument.text : nameArgument.getText(sourceFile);
3701
3903
  located.push({ name, value });
3702
3904
  }
3703
3905
  }
@@ -3714,20 +3916,20 @@ function mayHoldString(type, checker, visited = new Set) {
3714
3916
  return false;
3715
3917
  }
3716
3918
  visited.add(type);
3717
- if (type.flags & ts14.TypeFlags.StringLike) {
3919
+ if (type.flags & ts15.TypeFlags.StringLike) {
3718
3920
  return true;
3719
3921
  }
3720
3922
  if (type.isUnionOrIntersection()) {
3721
3923
  return type.types.some((member) => mayHoldString(member, checker, visited));
3722
3924
  }
3723
- if (type.flags & ts14.TypeFlags.Instantiable) {
3925
+ if (type.flags & ts15.TypeFlags.Instantiable) {
3724
3926
  const constraint = checker.getBaseConstraintOfType(type);
3725
3927
  return constraint !== undefined && constraint !== type ? mayHoldString(constraint, checker, visited) : false;
3726
3928
  }
3727
3929
  return false;
3728
3930
  }
3729
3931
  // src/url-address-slots.ts
3730
- import * as ts15 from "typescript";
3932
+ import * as ts16 from "typescript";
3731
3933
  var ADDRESS_CLASSES = {
3732
3934
  "game-object": true,
3733
3935
  component: true,
@@ -3746,7 +3948,7 @@ function isFragmentCaret(slot, position) {
3746
3948
  return slot.fragmentStart !== -1 && position >= slot.fragmentStart;
3747
3949
  }
3748
3950
  function tableKey(checker, callee) {
3749
- const symbol = checker.getSymbolAtLocation(ts15.isIdentifier(callee) ? callee : callee.name);
3951
+ const symbol = checker.getSymbolAtLocation(ts16.isIdentifier(callee) ? callee : callee.name);
3750
3952
  if (!symbol)
3751
3953
  return;
3752
3954
  const fqn = checker.getFullyQualifiedName(symbol);
@@ -3754,43 +3956,43 @@ function tableKey(checker, callee) {
3754
3956
  }
3755
3957
  function parameterName(checker, call, index) {
3756
3958
  const declaration = checker.getResolvedSignature(call)?.declaration;
3757
- if (!declaration || !ts15.isFunctionLike(declaration))
3959
+ if (!declaration || !ts16.isFunctionLike(declaration))
3758
3960
  return;
3759
3961
  const parameter = declaration.parameters[index];
3760
- if (!parameter || parameter.dotDotDotToken || !ts15.isIdentifier(parameter.name))
3962
+ if (!parameter || parameter.dotDotDotToken || !ts16.isIdentifier(parameter.name))
3761
3963
  return;
3762
3964
  return parameter.name.text;
3763
3965
  }
3764
3966
  var EQUALITY_OPERATORS = new Set([
3765
- ts15.SyntaxKind.EqualsEqualsEqualsToken,
3766
- ts15.SyntaxKind.ExclamationEqualsEqualsToken,
3767
- ts15.SyntaxKind.EqualsEqualsToken,
3768
- ts15.SyntaxKind.ExclamationEqualsToken
3967
+ ts16.SyntaxKind.EqualsEqualsEqualsToken,
3968
+ ts16.SyntaxKind.ExclamationEqualsEqualsToken,
3969
+ ts16.SyntaxKind.EqualsEqualsToken,
3970
+ ts16.SyntaxKind.ExclamationEqualsToken
3769
3971
  ]);
3770
3972
  function comparisonSatisfied(checker, entry, call) {
3771
3973
  if (entry.comparedParameter === undefined)
3772
3974
  return true;
3773
3975
  let node = call;
3774
- while (ts15.isParenthesizedExpression(node.parent))
3976
+ while (ts16.isParenthesizedExpression(node.parent))
3775
3977
  node = node.parent;
3776
3978
  const comparison = node.parent;
3777
- if (!ts15.isBinaryExpression(comparison))
3979
+ if (!ts16.isBinaryExpression(comparison))
3778
3980
  return false;
3779
3981
  if (!EQUALITY_OPERATORS.has(comparison.operatorToken.kind))
3780
3982
  return false;
3781
3983
  const other = comparison.left === node ? comparison.right : comparison.left;
3782
3984
  const symbol = checker.getSymbolAtLocation(other);
3783
- return (symbol?.declarations ?? []).some((declaration) => ts15.isParameter(declaration) && ts15.isIdentifier(declaration.name) && declaration.name.text === entry.comparedParameter);
3985
+ return (symbol?.declarations ?? []).some((declaration) => ts16.isParameter(declaration) && ts16.isIdentifier(declaration.name) && declaration.name.text === entry.comparedParameter);
3784
3986
  }
3785
3987
  function classifiedEntryOfArgument(checker, table, argument) {
3786
3988
  const call = argument.parent;
3787
- if (!ts15.isCallExpression(call))
3989
+ if (!ts16.isCallExpression(call))
3788
3990
  return;
3789
3991
  const argumentIndex = call.arguments.indexOf(argument);
3790
3992
  if (argumentIndex === -1)
3791
3993
  return;
3792
3994
  const callee = call.expression;
3793
- if (!ts15.isPropertyAccessExpression(callee) && !ts15.isIdentifier(callee))
3995
+ if (!ts16.isPropertyAccessExpression(callee) && !ts16.isIdentifier(callee))
3794
3996
  return;
3795
3997
  const fqn = tableKey(checker, callee);
3796
3998
  if (fqn === undefined)
@@ -3807,10 +4009,10 @@ function classifiedEntryOfArgument(checker, table, argument) {
3807
4009
  }
3808
4010
  function slotThroughHashedCall(checker, table, literal) {
3809
4011
  const call = literal.parent;
3810
- if (!ts15.isCallExpression(call))
4012
+ if (!ts16.isCallExpression(call))
3811
4013
  return;
3812
4014
  const callee = call.expression;
3813
- if (!ts15.isPropertyAccessExpression(callee) && !ts15.isIdentifier(callee))
4015
+ if (!ts16.isPropertyAccessExpression(callee) && !ts16.isIdentifier(callee))
3814
4016
  return;
3815
4017
  if (tableKey(checker, callee) !== "hash")
3816
4018
  return;
@@ -3828,24 +4030,24 @@ function addressTextOf(checker, entry, call) {
3828
4030
  if (entry.addressParameter === undefined)
3829
4031
  return;
3830
4032
  const declaration = checker.getResolvedSignature(call)?.declaration;
3831
- if (!declaration || !ts15.isFunctionLike(declaration))
4033
+ if (!declaration || !ts16.isFunctionLike(declaration))
3832
4034
  return;
3833
- const index = declaration.parameters.findIndex((parameter) => !parameter.dotDotDotToken && ts15.isIdentifier(parameter.name) && parameter.name.text === entry.addressParameter);
4035
+ const index = declaration.parameters.findIndex((parameter) => !parameter.dotDotDotToken && ts16.isIdentifier(parameter.name) && parameter.name.text === entry.addressParameter);
3834
4036
  if (index === -1)
3835
4037
  return;
3836
4038
  const argument = call.arguments[index];
3837
- return argument && ts15.isStringLiteralLike(argument) ? argument.text : undefined;
4039
+ return argument && ts16.isStringLiteralLike(argument) ? argument.text : undefined;
3838
4040
  }
3839
4041
  function innermostLiteralAt(sourceFile, position) {
3840
4042
  let found;
3841
4043
  const visit = (node) => {
3842
4044
  if (position < node.getStart(sourceFile) || position > node.getEnd())
3843
4045
  return;
3844
- if (ts15.isStringLiteralLike(node))
4046
+ if (ts16.isStringLiteralLike(node))
3845
4047
  found = node;
3846
- ts15.forEachChild(node, visit);
4048
+ ts16.forEachChild(node, visit);
3847
4049
  };
3848
- ts15.forEachChild(sourceFile, visit);
4050
+ ts16.forEachChild(sourceFile, visit);
3849
4051
  return found;
3850
4052
  }
3851
4053
  function resolveClassifiedSlotAtPosition(input) {
@@ -3879,23 +4081,23 @@ function resolveClassifiedSlotAtPosition(input) {
3879
4081
  };
3880
4082
  }
3881
4083
  // src/url-cross-world-address.ts
3882
- import * as ts17 from "typescript";
4084
+ import * as ts18 from "typescript";
3883
4085
 
3884
4086
  // src/url-address-literals.ts
3885
- import * as ts16 from "typescript";
4087
+ import * as ts17 from "typescript";
3886
4088
  function isAmbient2(fileName) {
3887
4089
  return /[\\/]node_modules[\\/]/.test(fileName) || /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(fileName);
3888
4090
  }
3889
4091
  function referenceTargetSymbol(type) {
3890
- if ((type.flags & ts16.TypeFlags.Object) === 0)
4092
+ if ((type.flags & ts17.TypeFlags.Object) === 0)
3891
4093
  return;
3892
- if ((type.objectFlags & ts16.ObjectFlags.Reference) === 0)
4094
+ if ((type.objectFlags & ts17.ObjectFlags.Reference) === 0)
3893
4095
  return;
3894
4096
  return type.target.symbol;
3895
4097
  }
3896
4098
  function ambientHashAliasTargets(checker, anchor) {
3897
4099
  const targets = new Set;
3898
- for (const symbol of checker.getSymbolsInScope(anchor, ts16.SymbolFlags.Type)) {
4100
+ for (const symbol of checker.getSymbolsInScope(anchor, ts17.SymbolFlags.Type)) {
3899
4101
  if (symbol.name !== "Hash")
3900
4102
  continue;
3901
4103
  const target = referenceTargetSymbol(checker.getDeclaredTypeOfSymbol(symbol));
@@ -3911,7 +4113,7 @@ function canonicalHashSymbols(checker, program) {
3911
4113
  if (!anchor)
3912
4114
  return canonical;
3913
4115
  const aliased = ambientHashAliasTargets(checker, anchor);
3914
- for (const symbol of checker.getSymbolsInScope(anchor, ts16.SymbolFlags.Function)) {
4116
+ for (const symbol of checker.getSymbolsInScope(anchor, ts17.SymbolFlags.Function)) {
3915
4117
  if (symbol.name !== "hash")
3916
4118
  continue;
3917
4119
  const declaration = symbol.declarations?.[0];
@@ -3933,7 +4135,7 @@ function hashedSourceOfType(checker, type, canonical) {
3933
4135
  return source?.isStringLiteral() ? source.value : undefined;
3934
4136
  }
3935
4137
  function staticAddressTextOf(checker, node, canonical) {
3936
- return ts16.isStringLiteralLike(node) ? node.text : hashedSourceOfType(checker, checker.getTypeAtLocation(node), canonical);
4138
+ return ts17.isStringLiteralLike(node) ? node.text : hashedSourceOfType(checker, checker.getTypeAtLocation(node), canonical);
3937
4139
  }
3938
4140
 
3939
4141
  // src/url-cross-world-address.ts
@@ -3957,7 +4159,7 @@ function checkCrossWorldAddresses(input) {
3957
4159
  if (worlds.length === 0)
3958
4160
  continue;
3959
4161
  const visit = (node) => {
3960
- if (ts17.isExpression(node)) {
4162
+ if (ts18.isExpression(node)) {
3961
4163
  const entry = addressEntryOfArgument(checker, table, node);
3962
4164
  if (entry !== undefined && slotRejectsForeignSocket(entry)) {
3963
4165
  const address = staticAddressTextOf(checker, node, canonical);
@@ -3974,14 +4176,14 @@ function checkCrossWorldAddresses(input) {
3974
4176
  }
3975
4177
  }
3976
4178
  }
3977
- ts17.forEachChild(node, visit);
4179
+ ts18.forEachChild(node, visit);
3978
4180
  };
3979
- ts17.forEachChild(sourceFile, visit);
4181
+ ts18.forEachChild(sourceFile, visit);
3980
4182
  }
3981
4183
  return findings;
3982
4184
  }
3983
4185
  // src/url-fragment-reachability.ts
3984
- import * as ts18 from "typescript";
4186
+ import * as ts19 from "typescript";
3985
4187
  function pathOfKey(key) {
3986
4188
  const socket = socketOfAddress(key);
3987
4189
  return socket === undefined ? key : key.slice(socket.length + 1);
@@ -4026,7 +4228,7 @@ function checkUrlFragmentReachability(input) {
4026
4228
  if (isAmbient2(sourceFile.fileName))
4027
4229
  continue;
4028
4230
  const visit = (node) => {
4029
- if (ts18.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
4231
+ if (ts19.isExpression(node) && isAddressClass(addressClassOfArgument(checker, table, node))) {
4030
4232
  const text = staticAddressTextOf(checker, node, canonical);
4031
4233
  if (text !== undefined) {
4032
4234
  const hash = text.indexOf("#");
@@ -4045,9 +4247,9 @@ function checkUrlFragmentReachability(input) {
4045
4247
  }
4046
4248
  }
4047
4249
  }
4048
- ts18.forEachChild(node, visit);
4250
+ ts19.forEachChild(node, visit);
4049
4251
  };
4050
- ts18.forEachChild(sourceFile, visit);
4252
+ ts19.forEachChild(sourceFile, visit);
4051
4253
  }
4052
4254
  return { kind: "checked", findings };
4053
4255
  }
@@ -4058,6 +4260,8 @@ export {
4058
4260
  DEFAULT_INCLUDE,
4059
4261
  GAME_PROJECT_DOCUMENT,
4060
4262
  GUI_EXTENSIONS,
4263
+ HSM_MODULE_SPECIFIER,
4264
+ HSM_REQUIRE_ROOT,
4061
4265
  INPUT_BINDING_EXTENSIONS,
4062
4266
  LIBRARY_DEPENDENCY_ROOT,
4063
4267
  LIBRARY_SCENE_EXTENSIONS,
@@ -4085,6 +4289,7 @@ export {
4085
4289
  checkUrlFragmentReachability,
4086
4290
  collectComponentDeclarations,
4087
4291
  collectComponentIds,
4292
+ compileHsmModules,
4088
4293
  componentIdOfSameObjectAddress,
4089
4294
  computeCompanionClosure,
4090
4295
  computeOutputRel,
@@ -4096,6 +4301,9 @@ export {
4096
4301
  getProgramDiagnostics,
4097
4302
  guiScriptResourceOf,
4098
4303
  guiScriptResourcesOf,
4304
+ hsmModules,
4305
+ hsmRequireName,
4306
+ hsmSourceFiles,
4099
4307
  isAddressClass,
4100
4308
  isContainedResourcePath,
4101
4309
  isDefignoredPath,
@@ -4112,8 +4320,10 @@ export {
4112
4320
  readLibrarySceneDocuments,
4113
4321
  readSceneDocuments,
4114
4322
  relativeAddressesFrom,
4323
+ requireHsmSourceDir,
4115
4324
  requirePathForRel,
4116
4325
  resolveClassifiedSlotAtPosition,
4326
+ resolveHsmSourceDir,
4117
4327
  rewriteEmittedRequires,
4118
4328
  slotRejectsForeignSocket,
4119
4329
  socketOfAddress,