@tilua/compiler 9.1.2 → 9.1.3

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/README.md CHANGED
@@ -546,12 +546,12 @@ a script that requires any of them knows what it got.
546
546
  <!-- compatibility:start -->
547
547
  ## Compatibility
548
548
 
549
- `@tilua/compiler@9.1.2` works with these tilua packages. *Released with* is the
549
+ `@tilua/compiler@9.1.3` works with these tilua packages. *Released with* is the
550
550
  version it was built and tested against.
551
551
 
552
552
  | Package | Range | Released with | |
553
553
  | --- | --- | --- | --- |
554
- | `@tilua/parser` | `^9.1.2` | 9.1.2 | dependency |
554
+ | `@tilua/parser` | `^9.1.3` | 9.1.3 | dependency |
555
555
  <!-- compatibility:end -->
556
556
 
557
557
  ## Development
@@ -2817,6 +2817,8 @@ import {
2817
2817
  analyzeScopes,
2818
2818
  analyzeTypes,
2819
2819
  moduleExports,
2820
+ classesOf,
2821
+ exportsFingerprint,
2820
2822
  resolveModulePath,
2821
2823
  resolveTypeLibraries,
2822
2824
  importExpressions,
@@ -4183,6 +4185,7 @@ function parsedLibrary(file) {
4183
4185
  return program2;
4184
4186
  }
4185
4187
  var moduleAnalyses = /* @__PURE__ */ new Map();
4188
+ var MAX_CYCLE_PASSES = 6;
4186
4189
  function analyzeModules(modules, config) {
4187
4190
  const out = [];
4188
4191
  const analyses = /* @__PURE__ */ new Map();
@@ -4201,12 +4204,14 @@ function analyzeModules(modules, config) {
4201
4204
  const inProgress = /* @__PURE__ */ new Set();
4202
4205
  const analyzed = /* @__PURE__ */ new Map();
4203
4206
  let partials = 0;
4207
+ const cycles = /* @__PURE__ */ new Set();
4208
+ const provisional = /* @__PURE__ */ new Map();
4204
4209
  const readWhile = /* @__PURE__ */ new Map();
4205
4210
  const settingFor = `${libraries.files.join("|")}#${config?.directory ?? ""}#${JSON.stringify(config?.paths ?? {})}`;
4206
4211
  const analyzeModule = (file, program2) => {
4207
4212
  const done = analyzed.get(file);
4208
4213
  if (done) return done;
4209
- const remembered = moduleAnalyses.get(file);
4214
+ const remembered = cycles.size ? void 0 : moduleAnalyses.get(file);
4210
4215
  const script = scriptOf(file);
4211
4216
  const ownLibs = script ? [...libs, script] : libs;
4212
4217
  if (remembered && remembered.setting === settingFor && ownLibs.length === remembered.libs.length && remembered.libs.every((lib, i) => lib === ownLibs[i]) && remembered.program === program2 && [...remembered.read].every(([read3, stamp]) => stampOf(read3) === stamp)) {
@@ -4234,6 +4239,8 @@ function analyzeModules(modules, config) {
4234
4239
  const result2 = { types, diagnostics: said, scopes };
4235
4240
  if (partials === before) {
4236
4241
  analyzed.set(file, result2);
4242
+ }
4243
+ if (partials === before && !cycles.size) {
4237
4244
  const read3 = readWhile.get(file) ?? /* @__PURE__ */ new Map();
4238
4245
  const own = stampOf(file);
4239
4246
  if (own !== void 0) read3.set(file, own);
@@ -4256,7 +4263,8 @@ function analyzeModules(modules, config) {
4256
4263
  };
4257
4264
  if (inProgress.has(target)) {
4258
4265
  partials++;
4259
- return { values: /* @__PURE__ */ new Map(), types: /* @__PURE__ */ new Map(), partial: true };
4266
+ cycles.add(target);
4267
+ return provisional.get(target) ?? { values: /* @__PURE__ */ new Map(), types: /* @__PURE__ */ new Map(), partial: true };
4260
4268
  }
4261
4269
  const cached = exportsCache.get(target);
4262
4270
  if (cached) {
@@ -4283,11 +4291,6 @@ function analyzeModules(modules, config) {
4283
4291
  inProgress.delete(target);
4284
4292
  }
4285
4293
  };
4286
- for (const module of modules) {
4287
- const { types, diagnostics } = analyzeModule(module.file, module.program);
4288
- analyses.set(module.file, types);
4289
- out.push(...diagnostics);
4290
- }
4291
4294
  const exportsOf = (file) => {
4292
4295
  const cached = exportsCache.get(file);
4293
4296
  if (cached) return cached;
@@ -4297,6 +4300,30 @@ function analyzeModules(modules, config) {
4297
4300
  exportsCache.set(file, exports);
4298
4301
  return exports;
4299
4302
  };
4303
+ const reported = out.length;
4304
+ const libraryClasses = classesOf(libs);
4305
+ const fingerprints = /* @__PURE__ */ new Map();
4306
+ for (let pass = 1; ; pass++) {
4307
+ out.length = reported;
4308
+ for (const module of modules) {
4309
+ const { types, diagnostics } = analyzeModule(module.file, module.program);
4310
+ analyses.set(module.file, types);
4311
+ out.push(...diagnostics);
4312
+ }
4313
+ if (!cycles.size || pass === MAX_CYCLE_PASSES) break;
4314
+ let settled = pass > 1;
4315
+ for (const file of cycles) {
4316
+ const exports = byFile.has(file) ? exportsOf(file) : exportsCache.get(file);
4317
+ if (exports && !exports.partial) provisional.set(file, exports);
4318
+ const fingerprint = exports && !exports.partial ? exportsFingerprint(exports, libraryClasses) : void 0;
4319
+ if (fingerprint === void 0 || fingerprint !== fingerprints.get(file)) settled = false;
4320
+ fingerprints.set(file, fingerprint);
4321
+ }
4322
+ if (settled) break;
4323
+ analyzed.clear();
4324
+ exportsCache.clear();
4325
+ readWhile.clear();
4326
+ }
4300
4327
  return { types: analyses, diagnostics: out, lowerings: [...libraries.lowerings], exportsOf };
4301
4328
  }
4302
4329
  function allStatements(statements) {
package/dist/cli.cjs CHANGED
@@ -4176,6 +4176,7 @@ function parsedLibrary(file) {
4176
4176
  return program2;
4177
4177
  }
4178
4178
  var moduleAnalyses = /* @__PURE__ */ new Map();
4179
+ var MAX_CYCLE_PASSES = 6;
4179
4180
  function analyzeModules(modules, config2) {
4180
4181
  const out2 = [];
4181
4182
  const analyses = /* @__PURE__ */ new Map();
@@ -4194,12 +4195,14 @@ function analyzeModules(modules, config2) {
4194
4195
  const inProgress = /* @__PURE__ */ new Set();
4195
4196
  const analyzed = /* @__PURE__ */ new Map();
4196
4197
  let partials = 0;
4198
+ const cycles = /* @__PURE__ */ new Set();
4199
+ const provisional = /* @__PURE__ */ new Map();
4197
4200
  const readWhile = /* @__PURE__ */ new Map();
4198
4201
  const settingFor = `${libraries.files.join("|")}#${config2?.directory ?? ""}#${JSON.stringify(config2?.paths ?? {})}`;
4199
4202
  const analyzeModule = (file, program2) => {
4200
4203
  const done = analyzed.get(file);
4201
4204
  if (done) return done;
4202
- const remembered = moduleAnalyses.get(file);
4205
+ const remembered = cycles.size ? void 0 : moduleAnalyses.get(file);
4203
4206
  const script = scriptOf(file);
4204
4207
  const ownLibs = script ? [...libs, script] : libs;
4205
4208
  if (remembered && remembered.setting === settingFor && ownLibs.length === remembered.libs.length && remembered.libs.every((lib, i) => lib === ownLibs[i]) && remembered.program === program2 && [...remembered.read].every(([read3, stamp]) => stampOf(read3) === stamp)) {
@@ -4227,6 +4230,8 @@ function analyzeModules(modules, config2) {
4227
4230
  const result2 = { types, diagnostics: said, scopes };
4228
4231
  if (partials === before) {
4229
4232
  analyzed.set(file, result2);
4233
+ }
4234
+ if (partials === before && !cycles.size) {
4230
4235
  const read3 = readWhile.get(file) ?? /* @__PURE__ */ new Map();
4231
4236
  const own = stampOf(file);
4232
4237
  if (own !== void 0) read3.set(file, own);
@@ -4249,7 +4254,8 @@ function analyzeModules(modules, config2) {
4249
4254
  };
4250
4255
  if (inProgress.has(target)) {
4251
4256
  partials++;
4252
- return { values: /* @__PURE__ */ new Map(), types: /* @__PURE__ */ new Map(), partial: true };
4257
+ cycles.add(target);
4258
+ return provisional.get(target) ?? { values: /* @__PURE__ */ new Map(), types: /* @__PURE__ */ new Map(), partial: true };
4253
4259
  }
4254
4260
  const cached = exportsCache.get(target);
4255
4261
  if (cached) {
@@ -4276,11 +4282,6 @@ function analyzeModules(modules, config2) {
4276
4282
  inProgress.delete(target);
4277
4283
  }
4278
4284
  };
4279
- for (const module2 of modules) {
4280
- const { types, diagnostics } = analyzeModule(module2.file, module2.program);
4281
- analyses.set(module2.file, types);
4282
- out2.push(...diagnostics);
4283
- }
4284
4285
  const exportsOf = (file) => {
4285
4286
  const cached = exportsCache.get(file);
4286
4287
  if (cached) return cached;
@@ -4290,6 +4291,30 @@ function analyzeModules(modules, config2) {
4290
4291
  exportsCache.set(file, exports2);
4291
4292
  return exports2;
4292
4293
  };
4294
+ const reported = out2.length;
4295
+ const libraryClasses = (0, import_parser7.classesOf)(libs);
4296
+ const fingerprints = /* @__PURE__ */ new Map();
4297
+ for (let pass = 1; ; pass++) {
4298
+ out2.length = reported;
4299
+ for (const module2 of modules) {
4300
+ const { types, diagnostics } = analyzeModule(module2.file, module2.program);
4301
+ analyses.set(module2.file, types);
4302
+ out2.push(...diagnostics);
4303
+ }
4304
+ if (!cycles.size || pass === MAX_CYCLE_PASSES) break;
4305
+ let settled = pass > 1;
4306
+ for (const file of cycles) {
4307
+ const exports2 = byFile.has(file) ? exportsOf(file) : exportsCache.get(file);
4308
+ if (exports2 && !exports2.partial) provisional.set(file, exports2);
4309
+ const fingerprint = exports2 && !exports2.partial ? (0, import_parser7.exportsFingerprint)(exports2, libraryClasses) : void 0;
4310
+ if (fingerprint === void 0 || fingerprint !== fingerprints.get(file)) settled = false;
4311
+ fingerprints.set(file, fingerprint);
4312
+ }
4313
+ if (settled) break;
4314
+ analyzed.clear();
4315
+ exportsCache.clear();
4316
+ readWhile.clear();
4317
+ }
4293
4318
  return { types: analyses, diagnostics: out2, lowerings: [...libraries.lowerings], exportsOf };
4294
4319
  }
4295
4320
  function allStatements(statements) {
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  WRITTEN_BY_TILUA,
4
4
  bundle,
5
5
  resolveConfig
6
- } from "./chunk-NS6CK5FX.js";
6
+ } from "./chunk-YWRP7SXR.js";
7
7
 
8
8
  // src/cli.ts
9
9
  import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, watch, writeFileSync } from "fs";
package/dist/index.cjs CHANGED
@@ -4200,6 +4200,7 @@ function parsedLibrary(file) {
4200
4200
  return program2;
4201
4201
  }
4202
4202
  var moduleAnalyses = /* @__PURE__ */ new Map();
4203
+ var MAX_CYCLE_PASSES = 6;
4203
4204
  function analyzeModules(modules, config) {
4204
4205
  const out = [];
4205
4206
  const analyses = /* @__PURE__ */ new Map();
@@ -4218,12 +4219,14 @@ function analyzeModules(modules, config) {
4218
4219
  const inProgress = /* @__PURE__ */ new Set();
4219
4220
  const analyzed = /* @__PURE__ */ new Map();
4220
4221
  let partials = 0;
4222
+ const cycles = /* @__PURE__ */ new Set();
4223
+ const provisional = /* @__PURE__ */ new Map();
4221
4224
  const readWhile = /* @__PURE__ */ new Map();
4222
4225
  const settingFor = `${libraries.files.join("|")}#${config?.directory ?? ""}#${JSON.stringify(config?.paths ?? {})}`;
4223
4226
  const analyzeModule = (file, program2) => {
4224
4227
  const done = analyzed.get(file);
4225
4228
  if (done) return done;
4226
- const remembered = moduleAnalyses.get(file);
4229
+ const remembered = cycles.size ? void 0 : moduleAnalyses.get(file);
4227
4230
  const script = scriptOf(file);
4228
4231
  const ownLibs = script ? [...libs, script] : libs;
4229
4232
  if (remembered && remembered.setting === settingFor && ownLibs.length === remembered.libs.length && remembered.libs.every((lib, i) => lib === ownLibs[i]) && remembered.program === program2 && [...remembered.read].every(([read3, stamp]) => stampOf(read3) === stamp)) {
@@ -4251,6 +4254,8 @@ function analyzeModules(modules, config) {
4251
4254
  const result2 = { types, diagnostics: said, scopes };
4252
4255
  if (partials === before) {
4253
4256
  analyzed.set(file, result2);
4257
+ }
4258
+ if (partials === before && !cycles.size) {
4254
4259
  const read3 = readWhile.get(file) ?? /* @__PURE__ */ new Map();
4255
4260
  const own = stampOf(file);
4256
4261
  if (own !== void 0) read3.set(file, own);
@@ -4273,7 +4278,8 @@ function analyzeModules(modules, config) {
4273
4278
  };
4274
4279
  if (inProgress.has(target)) {
4275
4280
  partials++;
4276
- return { values: /* @__PURE__ */ new Map(), types: /* @__PURE__ */ new Map(), partial: true };
4281
+ cycles.add(target);
4282
+ return provisional.get(target) ?? { values: /* @__PURE__ */ new Map(), types: /* @__PURE__ */ new Map(), partial: true };
4277
4283
  }
4278
4284
  const cached = exportsCache.get(target);
4279
4285
  if (cached) {
@@ -4300,11 +4306,6 @@ function analyzeModules(modules, config) {
4300
4306
  inProgress.delete(target);
4301
4307
  }
4302
4308
  };
4303
- for (const module2 of modules) {
4304
- const { types, diagnostics } = analyzeModule(module2.file, module2.program);
4305
- analyses.set(module2.file, types);
4306
- out.push(...diagnostics);
4307
- }
4308
4309
  const exportsOf = (file) => {
4309
4310
  const cached = exportsCache.get(file);
4310
4311
  if (cached) return cached;
@@ -4314,6 +4315,30 @@ function analyzeModules(modules, config) {
4314
4315
  exportsCache.set(file, exports2);
4315
4316
  return exports2;
4316
4317
  };
4318
+ const reported = out.length;
4319
+ const libraryClasses = (0, import_parser7.classesOf)(libs);
4320
+ const fingerprints = /* @__PURE__ */ new Map();
4321
+ for (let pass = 1; ; pass++) {
4322
+ out.length = reported;
4323
+ for (const module2 of modules) {
4324
+ const { types, diagnostics } = analyzeModule(module2.file, module2.program);
4325
+ analyses.set(module2.file, types);
4326
+ out.push(...diagnostics);
4327
+ }
4328
+ if (!cycles.size || pass === MAX_CYCLE_PASSES) break;
4329
+ let settled = pass > 1;
4330
+ for (const file of cycles) {
4331
+ const exports2 = byFile.has(file) ? exportsOf(file) : exportsCache.get(file);
4332
+ if (exports2 && !exports2.partial) provisional.set(file, exports2);
4333
+ const fingerprint = exports2 && !exports2.partial ? (0, import_parser7.exportsFingerprint)(exports2, libraryClasses) : void 0;
4334
+ if (fingerprint === void 0 || fingerprint !== fingerprints.get(file)) settled = false;
4335
+ fingerprints.set(file, fingerprint);
4336
+ }
4337
+ if (settled) break;
4338
+ analyzed.clear();
4339
+ exportsCache.clear();
4340
+ readWhile.clear();
4341
+ }
4317
4342
  return { types: analyses, diagnostics: out, lowerings: [...libraries.lowerings], exportsOf };
4318
4343
  }
4319
4344
  function allStatements(statements) {
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  program,
9
9
  resolveConfig,
10
10
  syntaxOf
11
- } from "./chunk-NS6CK5FX.js";
11
+ } from "./chunk-YWRP7SXR.js";
12
12
 
13
13
  // src/compile.ts
14
14
  import { readFileSync } from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilua/compiler",
3
- "version": "9.1.2",
3
+ "version": "9.1.3",
4
4
  "description": "Compiles tilua to Luau: lowers the @tilua/parser AST to a luau-parser AST and prints it",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "license": "ISC",
38
38
  "type": "module",
39
39
  "dependencies": {
40
- "@tilua/parser": "^9.1.2",
40
+ "@tilua/parser": "^9.1.3",
41
41
  "luau-parser": "^1.1.0"
42
42
  },
43
43
  "devDependencies": {