@tilua/compiler 9.1.0 → 9.1.2

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.0` works with these tilua packages. *Released with* is the
549
+ `@tilua/compiler@9.1.2` 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.0` | 9.1.0 | dependency |
554
+ | `@tilua/parser` | `^9.1.2` | 9.1.2 | dependency |
555
555
  <!-- compatibility:end -->
556
556
 
557
557
  ## Development
@@ -710,6 +710,8 @@ var Lowerer = class {
710
710
  receiverGlobal,
711
711
  argumentCount: args.length,
712
712
  at: this.callSite(name),
713
+ perFile: this.options.perFile ?? false,
714
+ report: (message) => this.diagnostics.push({ message, line: node.line.start, column: node.column.start }),
713
715
  get arguments() {
714
716
  return info();
715
717
  },
@@ -739,6 +741,8 @@ var Lowerer = class {
739
741
  options: lowerings[i].options ?? {},
740
742
  name,
741
743
  at: this.callSite(node.callee),
744
+ perFile: this.options.perFile ?? false,
745
+ report: (message) => this.diagnostics.push({ message, line: node.line.start, column: node.column.start }),
742
746
  get arguments() {
743
747
  return info();
744
748
  },
@@ -754,11 +758,16 @@ var Lowerer = class {
754
758
  if (!lowerings?.some((l) => l.plugin.globalValue)) return void 0;
755
759
  const name = this.globalName(node);
756
760
  if (name === void 0) return void 0;
761
+ const called = this.readingCallee;
757
762
  for (let i = lowerings.length - 1; i >= 0; i--) {
758
763
  const answer = lowerings[i].plugin.globalValue?.({
759
764
  options: lowerings[i].options ?? {},
760
765
  name,
761
766
  at: this.callSite(node),
767
+ perFile: this.options.perFile ?? false,
768
+ report: (message) => {
769
+ if (!called) this.diagnostics.push({ message, line: node.line.start, column: node.column.start });
770
+ },
762
771
  use: (runtime2) => this.loweringRuntime(i, runtime2)
763
772
  });
764
773
  if (answer !== void 0) return this.libraryExpression(answer, i, node);
@@ -2122,8 +2131,14 @@ end
2122
2131
  if (node.type === "CallExpression" && object2.type === "Identifier") {
2123
2132
  return this.link(node, this.reference(object2));
2124
2133
  }
2125
- return this.link(node, this.expression(object2));
2134
+ const callee = node.type === "CallExpression" && node.callee === object2;
2135
+ const reading = this.readingCallee;
2136
+ this.readingCallee = callee;
2137
+ const lowered = this.expression(object2);
2138
+ this.readingCallee = reading;
2139
+ return this.link(node, lowered);
2126
2140
  }
2141
+ readingCallee = false;
2127
2142
  /** A call is one value in tilua, and Luau would hand on every value one
2128
2143
  * returns in the last place of an argument list or a `return`: it is
2129
2144
  * kept to one there, `f((g()))`. Every value is taken only where the
@@ -3272,7 +3287,7 @@ async function bundle(options) {
3272
3287
  for (let n = 2; taken.has(pathKey(runtimeFile)); n++) runtimeFile = join(outDir, `_tilua${n}.luau`);
3273
3288
  for (let i = lowerings.length - 1; i >= 0 && !host; i--) {
3274
3289
  const { plugin: plugin3, options: own } = lowerings[i];
3275
- host = plugin3.files?.({ options: own ?? {}, directory: config?.directory ?? root, outDir, files: outputs, runtime: runtimeFile });
3290
+ host = plugin3.files?.({ options: own ?? {}, directory: config?.directory ?? root, rootDir, outDir, files: outputs, runtime: runtimeFile });
3276
3291
  }
3277
3292
  for (const problem of host?.problems ?? []) {
3278
3293
  diagnostics.push({
@@ -3315,6 +3330,7 @@ async function bundle(options) {
3315
3330
  const dynamicImports = /* @__PURE__ */ new Set();
3316
3331
  const lowered2 = lower(source.program, source.scopes, {
3317
3332
  names,
3333
+ perFile,
3318
3334
  types: analysis.types.get(file),
3319
3335
  lowerings,
3320
3336
  noLib: config?.noLib,
@@ -3493,6 +3509,27 @@ ${G}.arrays[${G}.scriptArgs] = true`).body.statements);
3493
3509
  files2.push({ path: runtimePath, code: `${runtimeCode}
3494
3510
  ${WRITTEN_BY_TILUA}: the runtime every file of the project requires.
3495
3511
  `, modules: [] });
3512
+ try {
3513
+ const more = await host?.output?.();
3514
+ for (const { file, code } of more?.files ?? []) {
3515
+ if (isOutside(outDir, resolve2(file))) return stop(`A library's file has to go inside outDir, not at ${file}`);
3516
+ files2.push({ path: relative(outDir, file).replace(/\\/g, "/"), code: `${code}
3517
+ ${WRITTEN_BY_TILUA}: a library's own file.
3518
+ `, modules: [] });
3519
+ }
3520
+ for (const problem of more?.problems ?? []) {
3521
+ diagnostics.push({
3522
+ file: problem.file ?? config?.path ?? anchor,
3523
+ message: problem.message,
3524
+ line: 1,
3525
+ column: 1,
3526
+ category: "config",
3527
+ ...problem.severity === "warning" && { severity: "warning" }
3528
+ });
3529
+ }
3530
+ } catch (error) {
3531
+ return stop(`A library could not write its files: ${error.message}`);
3532
+ }
3496
3533
  return { code: files2[0].code, files: files2, modules: moduleNames, diagnostics };
3497
3534
  }
3498
3535
  const several = mode !== "single";
@@ -4049,7 +4086,11 @@ ${several ? `
4049
4086
  })
4050
4087
  record = { loading = true, exports = exports }
4051
4088
  ${G}.records[name] = record
4052
- module.load(exports)
4089
+ -- A module runs once, so nothing keeps its body: anything can reach
4090
+ -- this table, and the body holds what the file kept to itself.
4091
+ local run = module.load
4092
+ module.load = nil
4093
+ run(exports)
4053
4094
  record.loading = false
4054
4095
  return exports
4055
4096
  end,
package/dist/cli.cjs CHANGED
@@ -727,6 +727,8 @@ var Lowerer = class {
727
727
  receiverGlobal,
728
728
  argumentCount: args2.length,
729
729
  at: this.callSite(name),
730
+ perFile: this.options.perFile ?? false,
731
+ report: (message) => this.diagnostics.push({ message, line: node.line.start, column: node.column.start }),
730
732
  get arguments() {
731
733
  return info();
732
734
  },
@@ -756,6 +758,8 @@ var Lowerer = class {
756
758
  options: lowerings[i].options ?? {},
757
759
  name,
758
760
  at: this.callSite(node.callee),
761
+ perFile: this.options.perFile ?? false,
762
+ report: (message) => this.diagnostics.push({ message, line: node.line.start, column: node.column.start }),
759
763
  get arguments() {
760
764
  return info();
761
765
  },
@@ -771,11 +775,16 @@ var Lowerer = class {
771
775
  if (!lowerings?.some((l) => l.plugin.globalValue)) return void 0;
772
776
  const name = this.globalName(node);
773
777
  if (name === void 0) return void 0;
778
+ const called = this.readingCallee;
774
779
  for (let i = lowerings.length - 1; i >= 0; i--) {
775
780
  const answer = lowerings[i].plugin.globalValue?.({
776
781
  options: lowerings[i].options ?? {},
777
782
  name,
778
783
  at: this.callSite(node),
784
+ perFile: this.options.perFile ?? false,
785
+ report: (message) => {
786
+ if (!called) this.diagnostics.push({ message, line: node.line.start, column: node.column.start });
787
+ },
779
788
  use: (runtime2) => this.loweringRuntime(i, runtime2)
780
789
  });
781
790
  if (answer !== void 0) return this.libraryExpression(answer, i, node);
@@ -2139,8 +2148,14 @@ end
2139
2148
  if (node.type === "CallExpression" && object2.type === "Identifier") {
2140
2149
  return this.link(node, this.reference(object2));
2141
2150
  }
2142
- return this.link(node, this.expression(object2));
2151
+ const callee = node.type === "CallExpression" && node.callee === object2;
2152
+ const reading = this.readingCallee;
2153
+ this.readingCallee = callee;
2154
+ const lowered = this.expression(object2);
2155
+ this.readingCallee = reading;
2156
+ return this.link(node, lowered);
2143
2157
  }
2158
+ readingCallee = false;
2144
2159
  /** A call is one value in tilua, and Luau would hand on every value one
2145
2160
  * returns in the last place of an argument list or a `return`: it is
2146
2161
  * kept to one there, `f((g()))`. Every value is taken only where the
@@ -3265,7 +3280,7 @@ async function bundle(options) {
3265
3280
  for (let n = 2; taken.has(pathKey(runtimeFile)); n++) runtimeFile = (0, import_node_path2.join)(outDir, `_tilua${n}.luau`);
3266
3281
  for (let i = lowerings.length - 1; i >= 0 && !host; i--) {
3267
3282
  const { plugin: plugin3, options: own } = lowerings[i];
3268
- host = plugin3.files?.({ options: own ?? {}, directory: config2?.directory ?? root, outDir, files: outputs, runtime: runtimeFile });
3283
+ host = plugin3.files?.({ options: own ?? {}, directory: config2?.directory ?? root, rootDir, outDir, files: outputs, runtime: runtimeFile });
3269
3284
  }
3270
3285
  for (const problem of host?.problems ?? []) {
3271
3286
  diagnostics.push({
@@ -3308,6 +3323,7 @@ async function bundle(options) {
3308
3323
  const dynamicImports = /* @__PURE__ */ new Set();
3309
3324
  const lowered2 = lower(source.program, source.scopes, {
3310
3325
  names,
3326
+ perFile,
3311
3327
  types: analysis.types.get(file),
3312
3328
  lowerings,
3313
3329
  noLib: config2?.noLib,
@@ -3486,6 +3502,27 @@ ${G}.arrays[${G}.scriptArgs] = true`).body.statements);
3486
3502
  files2.push({ path: runtimePath, code: `${runtimeCode}
3487
3503
  ${WRITTEN_BY_TILUA}: the runtime every file of the project requires.
3488
3504
  `, modules: [] });
3505
+ try {
3506
+ const more = await host?.output?.();
3507
+ for (const { file, code } of more?.files ?? []) {
3508
+ if (isOutside(outDir, (0, import_node_path2.resolve)(file))) return stop(`A library's file has to go inside outDir, not at ${file}`);
3509
+ files2.push({ path: (0, import_node_path2.relative)(outDir, file).replace(/\\/g, "/"), code: `${code}
3510
+ ${WRITTEN_BY_TILUA}: a library's own file.
3511
+ `, modules: [] });
3512
+ }
3513
+ for (const problem of more?.problems ?? []) {
3514
+ diagnostics.push({
3515
+ file: problem.file ?? config2?.path ?? anchor,
3516
+ message: problem.message,
3517
+ line: 1,
3518
+ column: 1,
3519
+ category: "config",
3520
+ ...problem.severity === "warning" && { severity: "warning" }
3521
+ });
3522
+ }
3523
+ } catch (error) {
3524
+ return stop(`A library could not write its files: ${error.message}`);
3525
+ }
3489
3526
  return { code: files2[0].code, files: files2, modules: moduleNames, diagnostics };
3490
3527
  }
3491
3528
  const several = mode !== "single";
@@ -4042,7 +4079,11 @@ ${several ? `
4042
4079
  })
4043
4080
  record = { loading = true, exports = exports }
4044
4081
  ${G}.records[name] = record
4045
- module.load(exports)
4082
+ -- A module runs once, so nothing keeps its body: anything can reach
4083
+ -- this table, and the body holds what the file kept to itself.
4084
+ local run = module.load
4085
+ module.load = nil
4086
+ run(exports)
4046
4087
  record.loading = false
4047
4088
  return exports
4048
4089
  end,
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  WRITTEN_BY_TILUA,
4
4
  bundle,
5
5
  resolveConfig
6
- } from "./chunk-3RJVN4KC.js";
6
+ } from "./chunk-NS6CK5FX.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
@@ -751,6 +751,8 @@ var Lowerer = class {
751
751
  receiverGlobal,
752
752
  argumentCount: args.length,
753
753
  at: this.callSite(name),
754
+ perFile: this.options.perFile ?? false,
755
+ report: (message) => this.diagnostics.push({ message, line: node.line.start, column: node.column.start }),
754
756
  get arguments() {
755
757
  return info();
756
758
  },
@@ -780,6 +782,8 @@ var Lowerer = class {
780
782
  options: lowerings[i].options ?? {},
781
783
  name,
782
784
  at: this.callSite(node.callee),
785
+ perFile: this.options.perFile ?? false,
786
+ report: (message) => this.diagnostics.push({ message, line: node.line.start, column: node.column.start }),
783
787
  get arguments() {
784
788
  return info();
785
789
  },
@@ -795,11 +799,16 @@ var Lowerer = class {
795
799
  if (!lowerings?.some((l) => l.plugin.globalValue)) return void 0;
796
800
  const name = this.globalName(node);
797
801
  if (name === void 0) return void 0;
802
+ const called = this.readingCallee;
798
803
  for (let i = lowerings.length - 1; i >= 0; i--) {
799
804
  const answer = lowerings[i].plugin.globalValue?.({
800
805
  options: lowerings[i].options ?? {},
801
806
  name,
802
807
  at: this.callSite(node),
808
+ perFile: this.options.perFile ?? false,
809
+ report: (message) => {
810
+ if (!called) this.diagnostics.push({ message, line: node.line.start, column: node.column.start });
811
+ },
803
812
  use: (runtime2) => this.loweringRuntime(i, runtime2)
804
813
  });
805
814
  if (answer !== void 0) return this.libraryExpression(answer, i, node);
@@ -2163,8 +2172,14 @@ end
2163
2172
  if (node.type === "CallExpression" && object2.type === "Identifier") {
2164
2173
  return this.link(node, this.reference(object2));
2165
2174
  }
2166
- return this.link(node, this.expression(object2));
2175
+ const callee = node.type === "CallExpression" && node.callee === object2;
2176
+ const reading = this.readingCallee;
2177
+ this.readingCallee = callee;
2178
+ const lowered = this.expression(object2);
2179
+ this.readingCallee = reading;
2180
+ return this.link(node, lowered);
2167
2181
  }
2182
+ readingCallee = false;
2168
2183
  /** A call is one value in tilua, and Luau would hand on every value one
2169
2184
  * returns in the last place of an argument list or a `return`: it is
2170
2185
  * kept to one there, `f((g()))`. Every value is taken only where the
@@ -3289,7 +3304,7 @@ async function bundle(options) {
3289
3304
  for (let n = 2; taken.has(pathKey(runtimeFile)); n++) runtimeFile = (0, import_node_path2.join)(outDir, `_tilua${n}.luau`);
3290
3305
  for (let i = lowerings.length - 1; i >= 0 && !host; i--) {
3291
3306
  const { plugin: plugin3, options: own } = lowerings[i];
3292
- host = plugin3.files?.({ options: own ?? {}, directory: config?.directory ?? root, outDir, files: outputs, runtime: runtimeFile });
3307
+ host = plugin3.files?.({ options: own ?? {}, directory: config?.directory ?? root, rootDir, outDir, files: outputs, runtime: runtimeFile });
3293
3308
  }
3294
3309
  for (const problem of host?.problems ?? []) {
3295
3310
  diagnostics.push({
@@ -3332,6 +3347,7 @@ async function bundle(options) {
3332
3347
  const dynamicImports = /* @__PURE__ */ new Set();
3333
3348
  const lowered2 = lower(source.program, source.scopes, {
3334
3349
  names,
3350
+ perFile,
3335
3351
  types: analysis.types.get(file),
3336
3352
  lowerings,
3337
3353
  noLib: config?.noLib,
@@ -3510,6 +3526,27 @@ ${G}.arrays[${G}.scriptArgs] = true`).body.statements);
3510
3526
  files2.push({ path: runtimePath, code: `${runtimeCode}
3511
3527
  ${WRITTEN_BY_TILUA}: the runtime every file of the project requires.
3512
3528
  `, modules: [] });
3529
+ try {
3530
+ const more = await host?.output?.();
3531
+ for (const { file, code } of more?.files ?? []) {
3532
+ if (isOutside(outDir, (0, import_node_path2.resolve)(file))) return stop(`A library's file has to go inside outDir, not at ${file}`);
3533
+ files2.push({ path: (0, import_node_path2.relative)(outDir, file).replace(/\\/g, "/"), code: `${code}
3534
+ ${WRITTEN_BY_TILUA}: a library's own file.
3535
+ `, modules: [] });
3536
+ }
3537
+ for (const problem of more?.problems ?? []) {
3538
+ diagnostics.push({
3539
+ file: problem.file ?? config?.path ?? anchor,
3540
+ message: problem.message,
3541
+ line: 1,
3542
+ column: 1,
3543
+ category: "config",
3544
+ ...problem.severity === "warning" && { severity: "warning" }
3545
+ });
3546
+ }
3547
+ } catch (error) {
3548
+ return stop(`A library could not write its files: ${error.message}`);
3549
+ }
3513
3550
  return { code: files2[0].code, files: files2, modules: moduleNames, diagnostics };
3514
3551
  }
3515
3552
  const several = mode !== "single";
@@ -4066,7 +4103,11 @@ ${several ? `
4066
4103
  })
4067
4104
  record = { loading = true, exports = exports }
4068
4105
  ${G}.records[name] = record
4069
- module.load(exports)
4106
+ -- A module runs once, so nothing keeps its body: anything can reach
4107
+ -- this table, and the body holds what the file kept to itself.
4108
+ local run = module.load
4109
+ module.load = nil
4110
+ run(exports)
4070
4111
  record.loading = false
4071
4112
  return exports
4072
4113
  end,
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as T from '@tilua/parser';
2
2
  import { OutputMode, TiluaConfig, ConfigProblem, LoweringPlugin, TypeAnalysis, ScopeAnalysis } from '@tilua/parser';
3
- export { EntryExports, EntryExportsLowering, FilesAnswer, FilesLayout, LoweringPlugin, LuaSyntax, MethodCall, MethodLowering, PluginContext } from '@tilua/parser';
3
+ export { EntryExports, EntryExportsLowering, FilesAnswer, FilesLayout, FilesOutput, FilesProblem, LoweringPlugin, LuaSyntax, MethodCall, MethodLowering, PluginContext } from '@tilua/parser';
4
4
  import * as L from 'luau-parser';
5
5
 
6
6
  /** What `tilua.config.json` holds. */
@@ -264,6 +264,8 @@ interface ModuleContext {
264
264
  readonly arrays?: string;
265
265
  }
266
266
  interface LowerOptions {
267
+ /** The build is `"output": "files"`, as a library is told. */
268
+ readonly perFile?: boolean;
267
269
  /** Lower the file as a module of a bundle. Without it, `import` and
268
270
  * `export` are errors. */
269
271
  readonly module?: ModuleContext;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as T from '@tilua/parser';
2
2
  import { OutputMode, TiluaConfig, ConfigProblem, LoweringPlugin, TypeAnalysis, ScopeAnalysis } from '@tilua/parser';
3
- export { EntryExports, EntryExportsLowering, FilesAnswer, FilesLayout, LoweringPlugin, LuaSyntax, MethodCall, MethodLowering, PluginContext } from '@tilua/parser';
3
+ export { EntryExports, EntryExportsLowering, FilesAnswer, FilesLayout, FilesOutput, FilesProblem, LoweringPlugin, LuaSyntax, MethodCall, MethodLowering, PluginContext } from '@tilua/parser';
4
4
  import * as L from 'luau-parser';
5
5
 
6
6
  /** What `tilua.config.json` holds. */
@@ -264,6 +264,8 @@ interface ModuleContext {
264
264
  readonly arrays?: string;
265
265
  }
266
266
  interface LowerOptions {
267
+ /** The build is `"output": "files"`, as a library is told. */
268
+ readonly perFile?: boolean;
267
269
  /** Lower the file as a module of a bundle. Without it, `import` and
268
270
  * `export` are errors. */
269
271
  readonly module?: ModuleContext;
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  program,
9
9
  resolveConfig,
10
10
  syntaxOf
11
- } from "./chunk-3RJVN4KC.js";
11
+ } from "./chunk-NS6CK5FX.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.0",
3
+ "version": "9.1.2",
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.0",
40
+ "@tilua/parser": "^9.1.2",
41
41
  "luau-parser": "^1.1.0"
42
42
  },
43
43
  "devDependencies": {