purity-seal 0.0.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.
Files changed (49) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +173 -0
  3. package/dist/Build.d.ts +1 -0
  4. package/dist/Checker/Checker.pure.d.ts +59 -0
  5. package/dist/Checker/Opinion/Opinion.pure.d.ts +25 -0
  6. package/dist/Checker/Opinion/pure.d.ts +3 -0
  7. package/dist/Checker/pure.d.ts +3 -0
  8. package/dist/Checker/test.d.ts +1 -0
  9. package/dist/Classify/Classify.pure.d.ts +42 -0
  10. package/dist/Classify/Classify.test.d.ts +1 -0
  11. package/dist/Classify/File.nodejs.d.ts +3 -0
  12. package/dist/Classify/File.test.d.ts +1 -0
  13. package/dist/Classify/barrel.nodejs.d.ts +2 -0
  14. package/dist/Classify/nodejs.d.ts +3 -0
  15. package/dist/Classify/pure.d.ts +3 -0
  16. package/dist/Classify/test.d.ts +2 -0
  17. package/dist/Examples/AlternativeCheckers.test.d.ts +1 -0
  18. package/dist/Examples/IsolateRuntimes.test.d.ts +1 -0
  19. package/dist/Examples/Lua.test.d.ts +1 -0
  20. package/dist/Examples/MultipleClassifiers.test.d.ts +1 -0
  21. package/dist/Examples/OnionDiamond.test.d.ts +1 -0
  22. package/dist/Examples/StrictOrdering.test.d.ts +1 -0
  23. package/dist/Examples/test.d.ts +6 -0
  24. package/dist/Lib/Array/Array.pure.d.ts +36 -0
  25. package/dist/Lib/Array/pure.d.ts +3 -0
  26. package/dist/Lib/Function/Curry.pure.d.ts +8 -0
  27. package/dist/Lib/Function/Flow.pure.d.ts +9 -0
  28. package/dist/Lib/Function/Pipe.pure.d.ts +20 -0
  29. package/dist/Lib/Function/pure.d.ts +3 -0
  30. package/dist/Lib/Option/Option.pure.d.ts +89 -0
  31. package/dist/Lib/Option/pure.d.ts +3 -0
  32. package/dist/Lib/Reader/Reader.pure.d.ts +14 -0
  33. package/dist/Lib/Reader/pure.d.ts +3 -0
  34. package/dist/Lib/Result/Result.pure.d.ts +24 -0
  35. package/dist/Lib/Result/pure.d.ts +3 -0
  36. package/dist/Lib/Set/Set.pure.d.ts +11 -0
  37. package/dist/Lib/Set/pure.d.ts +3 -0
  38. package/dist/Lib/pure.d.ts +6 -0
  39. package/dist/Partial_Order/PartialOrder.pure.d.ts +10 -0
  40. package/dist/Partial_Order/pure.d.ts +3 -0
  41. package/dist/Partial_Order/test.d.ts +1 -0
  42. package/dist/Plugin/Lua.nodejs.d.ts +7 -0
  43. package/dist/Plugin/barrel.nodejs.d.ts +2 -0
  44. package/dist/Plugin/esbuild.nodejs.d.ts +6 -0
  45. package/dist/Plugin/nodejs.d.ts +1 -0
  46. package/dist/nodejs.d.ts +5 -0
  47. package/dist/nodejs.js +2575 -0
  48. package/dist/test.d.ts +4 -0
  49. package/package.json +32 -0
package/dist/nodejs.js ADDED
@@ -0,0 +1,2575 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+
31
+ // node_modules/luaparse/luaparse.js
32
+ var require_luaparse = __commonJS({
33
+ "node_modules/luaparse/luaparse.js"(exports, module) {
34
+ "use strict";
35
+ (function(root, name, factory) {
36
+ "use strict";
37
+ var objectTypes = {
38
+ "function": true,
39
+ "object": true
40
+ }, freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports, freeModule = objectTypes[typeof module] && module && !module.nodeType && module, freeGlobal = freeExports && freeModule && typeof global === "object" && global, moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
41
+ if (freeGlobal && (freeGlobal.global === freeGlobal || /* istanbul ignore next */
42
+ freeGlobal.window === freeGlobal || /* istanbul ignore next */
43
+ freeGlobal.self === freeGlobal)) {
44
+ root = freeGlobal;
45
+ }
46
+ if (typeof define === "function" && /* istanbul ignore next */
47
+ typeof define.amd === "object" && /* istanbul ignore next */
48
+ define.amd) {
49
+ define(["exports"], factory);
50
+ if (freeExports && moduleExports) factory(freeModule.exports);
51
+ } else if (freeExports && freeModule) {
52
+ if (moduleExports) factory(freeModule.exports);
53
+ else factory(freeExports);
54
+ } else {
55
+ factory(root[name] = {});
56
+ }
57
+ })(exports, "luaparse", function(exports2) {
58
+ "use strict";
59
+ exports2.version = "0.3.1";
60
+ var input, options, length, features, encodingMode;
61
+ var defaultOptions = exports2.defaultOptions = {
62
+ // Explicitly tell the parser when the input ends.
63
+ wait: false,
64
+ comments: true,
65
+ scope: false,
66
+ locations: false,
67
+ ranges: false,
68
+ onCreateNode: null,
69
+ onCreateScope: null,
70
+ onDestroyScope: null,
71
+ onLocalDeclaration: null,
72
+ luaVersion: "5.1",
73
+ encodingMode: "none"
74
+ };
75
+ function encodeUTF8(codepoint, highMask) {
76
+ highMask = highMask || 0;
77
+ if (codepoint < 128) {
78
+ return String.fromCharCode(codepoint);
79
+ } else if (codepoint < 2048) {
80
+ return String.fromCharCode(
81
+ highMask | 192 | codepoint >> 6,
82
+ highMask | 128 | codepoint & 63
83
+ );
84
+ } else if (codepoint < 65536) {
85
+ return String.fromCharCode(
86
+ highMask | 224 | codepoint >> 12,
87
+ highMask | 128 | codepoint >> 6 & 63,
88
+ highMask | 128 | codepoint & 63
89
+ );
90
+ } else if (codepoint < 1114112) {
91
+ return String.fromCharCode(
92
+ highMask | 240 | codepoint >> 18,
93
+ highMask | 128 | codepoint >> 12 & 63,
94
+ highMask | 128 | codepoint >> 6 & 63,
95
+ highMask | 128 | codepoint & 63
96
+ );
97
+ } else {
98
+ return null;
99
+ }
100
+ }
101
+ function toHex(num, digits) {
102
+ var result = num.toString(16);
103
+ while (result.length < digits)
104
+ result = "0" + result;
105
+ return result;
106
+ }
107
+ function checkChars(rx) {
108
+ return function(s) {
109
+ var m = rx.exec(s);
110
+ if (!m)
111
+ return s;
112
+ raise(null, errors.invalidCodeUnit, toHex(m[0].charCodeAt(0), 4).toUpperCase());
113
+ };
114
+ }
115
+ var encodingModes = {
116
+ // `pseudo-latin1` encoding mode: assume the input was decoded with the latin1 encoding
117
+ // WARNING: latin1 does **NOT** mean cp1252 here like in the bone-headed WHATWG standard;
118
+ // it means true ISO/IEC 8859-1 identity-mapped to Basic Latin and Latin-1 Supplement blocks
119
+ "pseudo-latin1": {
120
+ fixup: checkChars(/[^\x00-\xff]/),
121
+ encodeByte: function(value) {
122
+ if (value === null)
123
+ return "";
124
+ return String.fromCharCode(value);
125
+ },
126
+ encodeUTF8: function(codepoint) {
127
+ return encodeUTF8(codepoint);
128
+ }
129
+ },
130
+ // `x-user-defined` encoding mode: assume the input was decoded with the WHATWG `x-user-defined` encoding
131
+ "x-user-defined": {
132
+ fixup: checkChars(/[^\x00-\x7f\uf780-\uf7ff]/),
133
+ encodeByte: function(value) {
134
+ if (value === null)
135
+ return "";
136
+ if (value >= 128)
137
+ return String.fromCharCode(value | 63232);
138
+ return String.fromCharCode(value);
139
+ },
140
+ encodeUTF8: function(codepoint) {
141
+ return encodeUTF8(codepoint, 63232);
142
+ }
143
+ },
144
+ // `none` encoding mode: disregard intrepretation of string literals, leave identifiers as-is
145
+ "none": {
146
+ discardStrings: true,
147
+ fixup: function(s) {
148
+ return s;
149
+ },
150
+ encodeByte: function(value) {
151
+ return "";
152
+ },
153
+ encodeUTF8: function(codepoint) {
154
+ return "";
155
+ }
156
+ }
157
+ };
158
+ var EOF = 1, StringLiteral = 2, Keyword = 4, Identifier = 8, NumericLiteral = 16, Punctuator = 32, BooleanLiteral = 64, NilLiteral = 128, VarargLiteral = 256;
159
+ exports2.tokenTypes = {
160
+ EOF,
161
+ StringLiteral,
162
+ Keyword,
163
+ Identifier,
164
+ NumericLiteral,
165
+ Punctuator,
166
+ BooleanLiteral,
167
+ NilLiteral,
168
+ VarargLiteral
169
+ };
170
+ var errors = exports2.errors = {
171
+ unexpected: "unexpected %1 '%2' near '%3'",
172
+ unexpectedEOF: "unexpected symbol near '<eof>'",
173
+ expected: "'%1' expected near '%2'",
174
+ expectedToken: "%1 expected near '%2'",
175
+ unfinishedString: "unfinished string near '%1'",
176
+ malformedNumber: "malformed number near '%1'",
177
+ decimalEscapeTooLarge: "decimal escape too large near '%1'",
178
+ invalidEscape: "invalid escape sequence near '%1'",
179
+ hexadecimalDigitExpected: "hexadecimal digit expected near '%1'",
180
+ braceExpected: "missing '%1' near '%2'",
181
+ tooLargeCodepoint: "UTF-8 value too large near '%1'",
182
+ unfinishedLongString: "unfinished long string (starting at line %1) near '%2'",
183
+ unfinishedLongComment: "unfinished long comment (starting at line %1) near '%2'",
184
+ ambiguousSyntax: "ambiguous syntax (function call x new statement) near '%1'",
185
+ noLoopToBreak: "no loop to break near '%1'",
186
+ labelAlreadyDefined: "label '%1' already defined on line %2",
187
+ labelNotVisible: "no visible label '%1' for <goto>",
188
+ gotoJumpInLocalScope: "<goto %1> jumps into the scope of local '%2'",
189
+ cannotUseVararg: "cannot use '...' outside a vararg function near '%1'",
190
+ invalidCodeUnit: "code unit U+%1 is not allowed in the current encoding mode"
191
+ };
192
+ var ast = exports2.ast = {
193
+ labelStatement: function(label) {
194
+ return {
195
+ type: "LabelStatement",
196
+ label
197
+ };
198
+ },
199
+ breakStatement: function() {
200
+ return {
201
+ type: "BreakStatement"
202
+ };
203
+ },
204
+ gotoStatement: function(label) {
205
+ return {
206
+ type: "GotoStatement",
207
+ label
208
+ };
209
+ },
210
+ returnStatement: function(args) {
211
+ return {
212
+ type: "ReturnStatement",
213
+ "arguments": args
214
+ };
215
+ },
216
+ ifStatement: function(clauses) {
217
+ return {
218
+ type: "IfStatement",
219
+ clauses
220
+ };
221
+ },
222
+ ifClause: function(condition, body) {
223
+ return {
224
+ type: "IfClause",
225
+ condition,
226
+ body
227
+ };
228
+ },
229
+ elseifClause: function(condition, body) {
230
+ return {
231
+ type: "ElseifClause",
232
+ condition,
233
+ body
234
+ };
235
+ },
236
+ elseClause: function(body) {
237
+ return {
238
+ type: "ElseClause",
239
+ body
240
+ };
241
+ },
242
+ whileStatement: function(condition, body) {
243
+ return {
244
+ type: "WhileStatement",
245
+ condition,
246
+ body
247
+ };
248
+ },
249
+ doStatement: function(body) {
250
+ return {
251
+ type: "DoStatement",
252
+ body
253
+ };
254
+ },
255
+ repeatStatement: function(condition, body) {
256
+ return {
257
+ type: "RepeatStatement",
258
+ condition,
259
+ body
260
+ };
261
+ },
262
+ localStatement: function(variables, init) {
263
+ return {
264
+ type: "LocalStatement",
265
+ variables,
266
+ init
267
+ };
268
+ },
269
+ assignmentStatement: function(variables, init) {
270
+ return {
271
+ type: "AssignmentStatement",
272
+ variables,
273
+ init
274
+ };
275
+ },
276
+ callStatement: function(expression) {
277
+ return {
278
+ type: "CallStatement",
279
+ expression
280
+ };
281
+ },
282
+ functionStatement: function(identifier, parameters, isLocal, body) {
283
+ return {
284
+ type: "FunctionDeclaration",
285
+ identifier,
286
+ isLocal,
287
+ parameters,
288
+ body
289
+ };
290
+ },
291
+ forNumericStatement: function(variable, start, end2, step, body) {
292
+ return {
293
+ type: "ForNumericStatement",
294
+ variable,
295
+ start,
296
+ end: end2,
297
+ step,
298
+ body
299
+ };
300
+ },
301
+ forGenericStatement: function(variables, iterators, body) {
302
+ return {
303
+ type: "ForGenericStatement",
304
+ variables,
305
+ iterators,
306
+ body
307
+ };
308
+ },
309
+ chunk: function(body) {
310
+ return {
311
+ type: "Chunk",
312
+ body
313
+ };
314
+ },
315
+ identifier: function(name) {
316
+ return {
317
+ type: "Identifier",
318
+ name
319
+ };
320
+ },
321
+ literal: function(type, value, raw) {
322
+ type = type === StringLiteral ? "StringLiteral" : type === NumericLiteral ? "NumericLiteral" : type === BooleanLiteral ? "BooleanLiteral" : type === NilLiteral ? "NilLiteral" : "VarargLiteral";
323
+ return {
324
+ type,
325
+ value,
326
+ raw
327
+ };
328
+ },
329
+ tableKey: function(key, value) {
330
+ return {
331
+ type: "TableKey",
332
+ key,
333
+ value
334
+ };
335
+ },
336
+ tableKeyString: function(key, value) {
337
+ return {
338
+ type: "TableKeyString",
339
+ key,
340
+ value
341
+ };
342
+ },
343
+ tableValue: function(value) {
344
+ return {
345
+ type: "TableValue",
346
+ value
347
+ };
348
+ },
349
+ tableConstructorExpression: function(fields) {
350
+ return {
351
+ type: "TableConstructorExpression",
352
+ fields
353
+ };
354
+ },
355
+ binaryExpression: function(operator, left, right) {
356
+ var type = "and" === operator || "or" === operator ? "LogicalExpression" : "BinaryExpression";
357
+ return {
358
+ type,
359
+ operator,
360
+ left,
361
+ right
362
+ };
363
+ },
364
+ unaryExpression: function(operator, argument) {
365
+ return {
366
+ type: "UnaryExpression",
367
+ operator,
368
+ argument
369
+ };
370
+ },
371
+ memberExpression: function(base, indexer, identifier) {
372
+ return {
373
+ type: "MemberExpression",
374
+ indexer,
375
+ identifier,
376
+ base
377
+ };
378
+ },
379
+ indexExpression: function(base, index2) {
380
+ return {
381
+ type: "IndexExpression",
382
+ base,
383
+ index: index2
384
+ };
385
+ },
386
+ callExpression: function(base, args) {
387
+ return {
388
+ type: "CallExpression",
389
+ base,
390
+ "arguments": args
391
+ };
392
+ },
393
+ tableCallExpression: function(base, args) {
394
+ return {
395
+ type: "TableCallExpression",
396
+ base,
397
+ "arguments": args
398
+ };
399
+ },
400
+ stringCallExpression: function(base, argument) {
401
+ return {
402
+ type: "StringCallExpression",
403
+ base,
404
+ argument
405
+ };
406
+ },
407
+ comment: function(value, raw) {
408
+ return {
409
+ type: "Comment",
410
+ value,
411
+ raw
412
+ };
413
+ }
414
+ };
415
+ function finishNode(node) {
416
+ if (trackLocations) {
417
+ var location = locations.pop();
418
+ location.complete();
419
+ location.bless(node);
420
+ }
421
+ if (options.onCreateNode) options.onCreateNode(node);
422
+ return node;
423
+ }
424
+ var slice = Array.prototype.slice, toString = Object.prototype.toString;
425
+ var indexOf = (
426
+ /* istanbul ignore next */
427
+ function(array, element) {
428
+ for (var i = 0, length2 = array.length; i < length2; ++i) {
429
+ if (array[i] === element) return i;
430
+ }
431
+ return -1;
432
+ }
433
+ );
434
+ if (Array.prototype.indexOf)
435
+ indexOf = function(array, element) {
436
+ return array.indexOf(element);
437
+ };
438
+ function indexOfObject(array, property, element) {
439
+ for (var i = 0, length2 = array.length; i < length2; ++i) {
440
+ if (array[i][property] === element) return i;
441
+ }
442
+ return -1;
443
+ }
444
+ function sprintf(format) {
445
+ var args = slice.call(arguments, 1);
446
+ format = format.replace(/%(\d)/g, function(match, index2) {
447
+ return "" + args[index2 - 1] || /* istanbul ignore next */
448
+ "";
449
+ });
450
+ return format;
451
+ }
452
+ var assign = (
453
+ /* istanbul ignore next */
454
+ function(dest) {
455
+ var args = slice.call(arguments, 1), src, prop;
456
+ for (var i = 0, length2 = args.length; i < length2; ++i) {
457
+ src = args[i];
458
+ for (prop in src)
459
+ if (Object.prototype.hasOwnProperty.call(src, prop)) {
460
+ dest[prop] = src[prop];
461
+ }
462
+ }
463
+ return dest;
464
+ }
465
+ );
466
+ if (Object.assign)
467
+ assign = Object.assign;
468
+ exports2.SyntaxError = SyntaxError;
469
+ function fixupError(e) {
470
+ if (!Object.create)
471
+ return e;
472
+ return Object.create(e, {
473
+ "line": { "writable": true, value: e.line },
474
+ "index": { "writable": true, value: e.index },
475
+ "column": { "writable": true, value: e.column }
476
+ });
477
+ }
478
+ function raise(token2) {
479
+ var message = sprintf.apply(null, slice.call(arguments, 1)), error, col;
480
+ if (token2 === null || typeof token2.line === "undefined") {
481
+ col = index - lineStart + 1;
482
+ error = fixupError(new SyntaxError(sprintf("[%1:%2] %3", line, col, message)));
483
+ error.index = index;
484
+ error.line = line;
485
+ error.column = col;
486
+ } else {
487
+ col = token2.range[0] - token2.lineStart;
488
+ error = fixupError(new SyntaxError(sprintf("[%1:%2] %3", token2.line, col, message)));
489
+ error.line = token2.line;
490
+ error.index = token2.range[0];
491
+ error.column = col;
492
+ }
493
+ throw error;
494
+ }
495
+ function tokenValue(token2) {
496
+ var raw = input.slice(token2.range[0], token2.range[1]);
497
+ if (raw)
498
+ return raw;
499
+ return token2.value;
500
+ }
501
+ function raiseUnexpectedToken(type, token2) {
502
+ raise(token2, errors.expectedToken, type, tokenValue(token2));
503
+ }
504
+ function unexpected(found) {
505
+ var near = tokenValue(lookahead);
506
+ if ("undefined" !== typeof found.type) {
507
+ var type;
508
+ switch (found.type) {
509
+ case StringLiteral:
510
+ type = "string";
511
+ break;
512
+ case Keyword:
513
+ type = "keyword";
514
+ break;
515
+ case Identifier:
516
+ type = "identifier";
517
+ break;
518
+ case NumericLiteral:
519
+ type = "number";
520
+ break;
521
+ case Punctuator:
522
+ type = "symbol";
523
+ break;
524
+ case BooleanLiteral:
525
+ type = "boolean";
526
+ break;
527
+ case NilLiteral:
528
+ return raise(found, errors.unexpected, "symbol", "nil", near);
529
+ case EOF:
530
+ return raise(found, errors.unexpectedEOF);
531
+ }
532
+ return raise(found, errors.unexpected, type, tokenValue(found), near);
533
+ }
534
+ return raise(found, errors.unexpected, "symbol", found, near);
535
+ }
536
+ var index, token, previousToken, lookahead, comments, tokenStart, line, lineStart;
537
+ exports2.lex = lex;
538
+ function lex() {
539
+ skipWhiteSpace();
540
+ while (45 === input.charCodeAt(index) && 45 === input.charCodeAt(index + 1)) {
541
+ scanComment();
542
+ skipWhiteSpace();
543
+ }
544
+ if (index >= length) return {
545
+ type: EOF,
546
+ value: "<eof>",
547
+ line,
548
+ lineStart,
549
+ range: [index, index]
550
+ };
551
+ var charCode = input.charCodeAt(index), next2 = input.charCodeAt(index + 1);
552
+ tokenStart = index;
553
+ if (isIdentifierStart(charCode)) return scanIdentifierOrKeyword();
554
+ switch (charCode) {
555
+ case 39:
556
+ case 34:
557
+ return scanStringLiteral();
558
+ case 48:
559
+ case 49:
560
+ case 50:
561
+ case 51:
562
+ case 52:
563
+ case 53:
564
+ case 54:
565
+ case 55:
566
+ case 56:
567
+ case 57:
568
+ return scanNumericLiteral();
569
+ case 46:
570
+ if (isDecDigit(next2)) return scanNumericLiteral();
571
+ if (46 === next2) {
572
+ if (46 === input.charCodeAt(index + 2)) return scanVarargLiteral();
573
+ return scanPunctuator("..");
574
+ }
575
+ return scanPunctuator(".");
576
+ case 61:
577
+ if (61 === next2) return scanPunctuator("==");
578
+ return scanPunctuator("=");
579
+ case 62:
580
+ if (features.bitwiseOperators) {
581
+ if (62 === next2) return scanPunctuator(">>");
582
+ }
583
+ if (61 === next2) return scanPunctuator(">=");
584
+ return scanPunctuator(">");
585
+ case 60:
586
+ if (features.bitwiseOperators) {
587
+ if (60 === next2) return scanPunctuator("<<");
588
+ }
589
+ if (61 === next2) return scanPunctuator("<=");
590
+ return scanPunctuator("<");
591
+ case 126:
592
+ if (61 === next2) return scanPunctuator("~=");
593
+ if (!features.bitwiseOperators)
594
+ break;
595
+ return scanPunctuator("~");
596
+ case 58:
597
+ if (features.labels) {
598
+ if (58 === next2) return scanPunctuator("::");
599
+ }
600
+ return scanPunctuator(":");
601
+ case 91:
602
+ if (91 === next2 || 61 === next2) return scanLongStringLiteral();
603
+ return scanPunctuator("[");
604
+ case 47:
605
+ if (features.integerDivision) {
606
+ if (47 === next2) return scanPunctuator("//");
607
+ }
608
+ return scanPunctuator("/");
609
+ case 38:
610
+ case 124:
611
+ if (!features.bitwiseOperators)
612
+ break;
613
+ /* fall through */
614
+ case 42:
615
+ case 94:
616
+ case 37:
617
+ case 44:
618
+ case 123:
619
+ case 125:
620
+ case 93:
621
+ case 40:
622
+ case 41:
623
+ case 59:
624
+ case 35:
625
+ case 45:
626
+ case 43:
627
+ return scanPunctuator(input.charAt(index));
628
+ }
629
+ return unexpected(input.charAt(index));
630
+ }
631
+ function consumeEOL() {
632
+ var charCode = input.charCodeAt(index), peekCharCode = input.charCodeAt(index + 1);
633
+ if (isLineTerminator(charCode)) {
634
+ if (10 === charCode && 13 === peekCharCode) ++index;
635
+ if (13 === charCode && 10 === peekCharCode) ++index;
636
+ ++line;
637
+ lineStart = ++index;
638
+ return true;
639
+ }
640
+ return false;
641
+ }
642
+ function skipWhiteSpace() {
643
+ while (index < length) {
644
+ var charCode = input.charCodeAt(index);
645
+ if (isWhiteSpace(charCode)) {
646
+ ++index;
647
+ } else if (!consumeEOL()) {
648
+ break;
649
+ }
650
+ }
651
+ }
652
+ function scanIdentifierOrKeyword() {
653
+ var value, type;
654
+ while (isIdentifierPart(input.charCodeAt(++index))) ;
655
+ value = encodingMode.fixup(input.slice(tokenStart, index));
656
+ if (isKeyword(value)) {
657
+ type = Keyword;
658
+ } else if ("true" === value || "false" === value) {
659
+ type = BooleanLiteral;
660
+ value = "true" === value;
661
+ } else if ("nil" === value) {
662
+ type = NilLiteral;
663
+ value = null;
664
+ } else {
665
+ type = Identifier;
666
+ }
667
+ return {
668
+ type,
669
+ value,
670
+ line,
671
+ lineStart,
672
+ range: [tokenStart, index]
673
+ };
674
+ }
675
+ function scanPunctuator(value) {
676
+ index += value.length;
677
+ return {
678
+ type: Punctuator,
679
+ value,
680
+ line,
681
+ lineStart,
682
+ range: [tokenStart, index]
683
+ };
684
+ }
685
+ function scanVarargLiteral() {
686
+ index += 3;
687
+ return {
688
+ type: VarargLiteral,
689
+ value: "...",
690
+ line,
691
+ lineStart,
692
+ range: [tokenStart, index]
693
+ };
694
+ }
695
+ function scanStringLiteral() {
696
+ var delimiter = input.charCodeAt(index++), beginLine = line, beginLineStart = lineStart, stringStart = index, string = encodingMode.discardStrings ? null : "", charCode;
697
+ for (; ; ) {
698
+ charCode = input.charCodeAt(index++);
699
+ if (delimiter === charCode) break;
700
+ if (index > length || isLineTerminator(charCode)) {
701
+ string += input.slice(stringStart, index - 1);
702
+ raise(null, errors.unfinishedString, input.slice(tokenStart, index - 1));
703
+ }
704
+ if (92 === charCode) {
705
+ if (!encodingMode.discardStrings) {
706
+ var beforeEscape = input.slice(stringStart, index - 1);
707
+ string += encodingMode.fixup(beforeEscape);
708
+ }
709
+ var escapeValue = readEscapeSequence();
710
+ if (!encodingMode.discardStrings)
711
+ string += escapeValue;
712
+ stringStart = index;
713
+ }
714
+ }
715
+ if (!encodingMode.discardStrings) {
716
+ string += encodingMode.encodeByte(null);
717
+ string += encodingMode.fixup(input.slice(stringStart, index - 1));
718
+ }
719
+ return {
720
+ type: StringLiteral,
721
+ value: string,
722
+ line: beginLine,
723
+ lineStart: beginLineStart,
724
+ lastLine: line,
725
+ lastLineStart: lineStart,
726
+ range: [tokenStart, index]
727
+ };
728
+ }
729
+ function scanLongStringLiteral() {
730
+ var beginLine = line, beginLineStart = lineStart, string = readLongString(false);
731
+ if (false === string) raise(token, errors.expected, "[", tokenValue(token));
732
+ return {
733
+ type: StringLiteral,
734
+ value: encodingMode.discardStrings ? null : encodingMode.fixup(string),
735
+ line: beginLine,
736
+ lineStart: beginLineStart,
737
+ lastLine: line,
738
+ lastLineStart: lineStart,
739
+ range: [tokenStart, index]
740
+ };
741
+ }
742
+ function scanNumericLiteral() {
743
+ var character = input.charAt(index), next2 = input.charAt(index + 1);
744
+ var literal = "0" === character && "xX".indexOf(next2 || null) >= 0 ? readHexLiteral() : readDecLiteral();
745
+ var foundImaginaryUnit = readImaginaryUnitSuffix(), foundInt64Suffix = readInt64Suffix();
746
+ if (foundInt64Suffix && (foundImaginaryUnit || literal.hasFractionPart)) {
747
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
748
+ }
749
+ return {
750
+ type: NumericLiteral,
751
+ value: literal.value,
752
+ line,
753
+ lineStart,
754
+ range: [tokenStart, index]
755
+ };
756
+ }
757
+ function readImaginaryUnitSuffix() {
758
+ if (!features.imaginaryNumbers) return;
759
+ if ("iI".indexOf(input.charAt(index) || null) >= 0) {
760
+ ++index;
761
+ return true;
762
+ } else {
763
+ return false;
764
+ }
765
+ }
766
+ function readInt64Suffix() {
767
+ if (!features.integerSuffixes) return;
768
+ if ("uU".indexOf(input.charAt(index) || null) >= 0) {
769
+ ++index;
770
+ if ("lL".indexOf(input.charAt(index) || null) >= 0) {
771
+ ++index;
772
+ if ("lL".indexOf(input.charAt(index) || null) >= 0) {
773
+ ++index;
774
+ return "ULL";
775
+ } else {
776
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
777
+ }
778
+ } else {
779
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
780
+ }
781
+ } else if ("lL".indexOf(input.charAt(index) || null) >= 0) {
782
+ ++index;
783
+ if ("lL".indexOf(input.charAt(index) || null) >= 0) {
784
+ ++index;
785
+ return "LL";
786
+ } else {
787
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
788
+ }
789
+ }
790
+ }
791
+ function readHexLiteral() {
792
+ var fraction = 0, binaryExponent = 1, binarySign = 1, digit, fractionStart, exponentStart, digitStart;
793
+ digitStart = index += 2;
794
+ if (!isHexDigit(input.charCodeAt(index)))
795
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
796
+ while (isHexDigit(input.charCodeAt(index))) ++index;
797
+ digit = parseInt(input.slice(digitStart, index), 16);
798
+ var foundFraction = false;
799
+ if ("." === input.charAt(index)) {
800
+ foundFraction = true;
801
+ fractionStart = ++index;
802
+ while (isHexDigit(input.charCodeAt(index))) ++index;
803
+ fraction = input.slice(fractionStart, index);
804
+ fraction = fractionStart === index ? 0 : parseInt(fraction, 16) / Math.pow(16, index - fractionStart);
805
+ }
806
+ var foundBinaryExponent = false;
807
+ if ("pP".indexOf(input.charAt(index) || null) >= 0) {
808
+ foundBinaryExponent = true;
809
+ ++index;
810
+ if ("+-".indexOf(input.charAt(index) || null) >= 0)
811
+ binarySign = "+" === input.charAt(index++) ? 1 : -1;
812
+ exponentStart = index;
813
+ if (!isDecDigit(input.charCodeAt(index)))
814
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
815
+ while (isDecDigit(input.charCodeAt(index))) ++index;
816
+ binaryExponent = input.slice(exponentStart, index);
817
+ binaryExponent = Math.pow(2, binaryExponent * binarySign);
818
+ }
819
+ return {
820
+ value: (digit + fraction) * binaryExponent,
821
+ hasFractionPart: foundFraction || foundBinaryExponent
822
+ };
823
+ }
824
+ function readDecLiteral() {
825
+ while (isDecDigit(input.charCodeAt(index))) ++index;
826
+ var foundFraction = false;
827
+ if ("." === input.charAt(index)) {
828
+ foundFraction = true;
829
+ ++index;
830
+ while (isDecDigit(input.charCodeAt(index))) ++index;
831
+ }
832
+ var foundExponent = false;
833
+ if ("eE".indexOf(input.charAt(index) || null) >= 0) {
834
+ foundExponent = true;
835
+ ++index;
836
+ if ("+-".indexOf(input.charAt(index) || null) >= 0) ++index;
837
+ if (!isDecDigit(input.charCodeAt(index)))
838
+ raise(null, errors.malformedNumber, input.slice(tokenStart, index));
839
+ while (isDecDigit(input.charCodeAt(index))) ++index;
840
+ }
841
+ return {
842
+ value: parseFloat(input.slice(tokenStart, index)),
843
+ hasFractionPart: foundFraction || foundExponent
844
+ };
845
+ }
846
+ function readUnicodeEscapeSequence() {
847
+ var sequenceStart = index++;
848
+ if (input.charAt(index++) !== "{")
849
+ raise(null, errors.braceExpected, "{", "\\" + input.slice(sequenceStart, index));
850
+ if (!isHexDigit(input.charCodeAt(index)))
851
+ raise(null, errors.hexadecimalDigitExpected, "\\" + input.slice(sequenceStart, index));
852
+ while (input.charCodeAt(index) === 48) ++index;
853
+ var escStart = index;
854
+ while (isHexDigit(input.charCodeAt(index))) {
855
+ ++index;
856
+ if (index - escStart > 6)
857
+ raise(null, errors.tooLargeCodepoint, "\\" + input.slice(sequenceStart, index));
858
+ }
859
+ var b = input.charAt(index++);
860
+ if (b !== "}") {
861
+ if (b === '"' || b === "'")
862
+ raise(null, errors.braceExpected, "}", "\\" + input.slice(sequenceStart, index--));
863
+ else
864
+ raise(null, errors.hexadecimalDigitExpected, "\\" + input.slice(sequenceStart, index));
865
+ }
866
+ var codepoint = parseInt(input.slice(escStart, index - 1) || "0", 16);
867
+ var frag = "\\" + input.slice(sequenceStart, index);
868
+ if (codepoint > 1114111) {
869
+ raise(null, errors.tooLargeCodepoint, frag);
870
+ }
871
+ return encodingMode.encodeUTF8(codepoint, frag);
872
+ }
873
+ function readEscapeSequence() {
874
+ var sequenceStart = index;
875
+ switch (input.charAt(index)) {
876
+ // Lua allow the following escape sequences.
877
+ case "a":
878
+ ++index;
879
+ return "\x07";
880
+ case "n":
881
+ ++index;
882
+ return "\n";
883
+ case "r":
884
+ ++index;
885
+ return "\r";
886
+ case "t":
887
+ ++index;
888
+ return " ";
889
+ case "v":
890
+ ++index;
891
+ return "\v";
892
+ case "b":
893
+ ++index;
894
+ return "\b";
895
+ case "f":
896
+ ++index;
897
+ return "\f";
898
+ // Backslash at the end of the line. We treat all line endings as equivalent,
899
+ // and as representing the [LF] character (code 10). Lua 5.1 through 5.3
900
+ // have been verified to behave the same way.
901
+ case "\r":
902
+ case "\n":
903
+ consumeEOL();
904
+ return "\n";
905
+ case "0":
906
+ case "1":
907
+ case "2":
908
+ case "3":
909
+ case "4":
910
+ case "5":
911
+ case "6":
912
+ case "7":
913
+ case "8":
914
+ case "9":
915
+ while (isDecDigit(input.charCodeAt(index)) && index - sequenceStart < 3) ++index;
916
+ var frag = input.slice(sequenceStart, index);
917
+ var ddd = parseInt(frag, 10);
918
+ if (ddd > 255) {
919
+ raise(null, errors.decimalEscapeTooLarge, "\\" + ddd);
920
+ }
921
+ return encodingMode.encodeByte(ddd, "\\" + frag);
922
+ case "z":
923
+ if (features.skipWhitespaceEscape) {
924
+ ++index;
925
+ skipWhiteSpace();
926
+ return "";
927
+ }
928
+ break;
929
+ case "x":
930
+ if (features.hexEscapes) {
931
+ if (isHexDigit(input.charCodeAt(index + 1)) && isHexDigit(input.charCodeAt(index + 2))) {
932
+ index += 3;
933
+ return encodingMode.encodeByte(parseInt(input.slice(sequenceStart + 1, index), 16), "\\" + input.slice(sequenceStart, index));
934
+ }
935
+ raise(null, errors.hexadecimalDigitExpected, "\\" + input.slice(sequenceStart, index + 2));
936
+ }
937
+ break;
938
+ case "u":
939
+ if (features.unicodeEscapes)
940
+ return readUnicodeEscapeSequence();
941
+ break;
942
+ case "\\":
943
+ case '"':
944
+ case "'":
945
+ return input.charAt(index++);
946
+ }
947
+ if (features.strictEscapes)
948
+ raise(null, errors.invalidEscape, "\\" + input.slice(sequenceStart, index + 1));
949
+ return input.charAt(index++);
950
+ }
951
+ function scanComment() {
952
+ tokenStart = index;
953
+ index += 2;
954
+ var character = input.charAt(index), content = "", isLong = false, commentStart = index, lineStartComment = lineStart, lineComment = line;
955
+ if ("[" === character) {
956
+ content = readLongString(true);
957
+ if (false === content) content = character;
958
+ else isLong = true;
959
+ }
960
+ if (!isLong) {
961
+ while (index < length) {
962
+ if (isLineTerminator(input.charCodeAt(index))) break;
963
+ ++index;
964
+ }
965
+ if (options.comments) content = input.slice(commentStart, index);
966
+ }
967
+ if (options.comments) {
968
+ var node = ast.comment(content, input.slice(tokenStart, index));
969
+ if (options.locations) {
970
+ node.loc = {
971
+ start: { line: lineComment, column: tokenStart - lineStartComment },
972
+ end: { line, column: index - lineStart }
973
+ };
974
+ }
975
+ if (options.ranges) {
976
+ node.range = [tokenStart, index];
977
+ }
978
+ if (options.onCreateNode) options.onCreateNode(node);
979
+ comments.push(node);
980
+ }
981
+ }
982
+ function readLongString(isComment) {
983
+ var level = 0, content = "", terminator = false, character, stringStart, firstLine = line;
984
+ ++index;
985
+ while ("=" === input.charAt(index + level)) ++level;
986
+ if ("[" !== input.charAt(index + level)) return false;
987
+ index += level + 1;
988
+ if (isLineTerminator(input.charCodeAt(index))) consumeEOL();
989
+ stringStart = index;
990
+ while (index < length) {
991
+ while (isLineTerminator(input.charCodeAt(index))) consumeEOL();
992
+ character = input.charAt(index++);
993
+ if ("]" === character) {
994
+ terminator = true;
995
+ for (var i = 0; i < level; ++i) {
996
+ if ("=" !== input.charAt(index + i)) terminator = false;
997
+ }
998
+ if ("]" !== input.charAt(index + level)) terminator = false;
999
+ }
1000
+ if (terminator) {
1001
+ content += input.slice(stringStart, index - 1);
1002
+ index += level + 1;
1003
+ return content;
1004
+ }
1005
+ }
1006
+ raise(
1007
+ null,
1008
+ isComment ? errors.unfinishedLongComment : errors.unfinishedLongString,
1009
+ firstLine,
1010
+ "<eof>"
1011
+ );
1012
+ }
1013
+ function next() {
1014
+ previousToken = token;
1015
+ token = lookahead;
1016
+ lookahead = lex();
1017
+ }
1018
+ function consume(value) {
1019
+ if (value === token.value) {
1020
+ next();
1021
+ return true;
1022
+ }
1023
+ return false;
1024
+ }
1025
+ function expect(value) {
1026
+ if (value === token.value) next();
1027
+ else raise(token, errors.expected, value, tokenValue(token));
1028
+ }
1029
+ function isWhiteSpace(charCode) {
1030
+ return 9 === charCode || 32 === charCode || 11 === charCode || 12 === charCode;
1031
+ }
1032
+ function isLineTerminator(charCode) {
1033
+ return 10 === charCode || 13 === charCode;
1034
+ }
1035
+ function isDecDigit(charCode) {
1036
+ return charCode >= 48 && charCode <= 57;
1037
+ }
1038
+ function isHexDigit(charCode) {
1039
+ return charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70;
1040
+ }
1041
+ function isIdentifierStart(charCode) {
1042
+ if (charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || 95 === charCode)
1043
+ return true;
1044
+ if (features.extendedIdentifiers && charCode >= 128)
1045
+ return true;
1046
+ return false;
1047
+ }
1048
+ function isIdentifierPart(charCode) {
1049
+ if (charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || 95 === charCode || charCode >= 48 && charCode <= 57)
1050
+ return true;
1051
+ if (features.extendedIdentifiers && charCode >= 128)
1052
+ return true;
1053
+ return false;
1054
+ }
1055
+ function isKeyword(id) {
1056
+ switch (id.length) {
1057
+ case 2:
1058
+ return "do" === id || "if" === id || "in" === id || "or" === id;
1059
+ case 3:
1060
+ return "and" === id || "end" === id || "for" === id || "not" === id;
1061
+ case 4:
1062
+ if ("else" === id || "then" === id)
1063
+ return true;
1064
+ if (features.labels && !features.contextualGoto)
1065
+ return "goto" === id;
1066
+ return false;
1067
+ case 5:
1068
+ return "break" === id || "local" === id || "until" === id || "while" === id;
1069
+ case 6:
1070
+ return "elseif" === id || "repeat" === id || "return" === id;
1071
+ case 8:
1072
+ return "function" === id;
1073
+ }
1074
+ return false;
1075
+ }
1076
+ function isUnary(token2) {
1077
+ if (Punctuator === token2.type) return "#-~".indexOf(token2.value) >= 0;
1078
+ if (Keyword === token2.type) return "not" === token2.value;
1079
+ return false;
1080
+ }
1081
+ function isBlockFollow(token2) {
1082
+ if (EOF === token2.type) return true;
1083
+ if (Keyword !== token2.type) return false;
1084
+ switch (token2.value) {
1085
+ case "else":
1086
+ case "elseif":
1087
+ case "end":
1088
+ case "until":
1089
+ return true;
1090
+ default:
1091
+ return false;
1092
+ }
1093
+ }
1094
+ var scopes, scopeDepth, globals;
1095
+ function createScope() {
1096
+ var scope = scopes[scopeDepth++].slice();
1097
+ scopes.push(scope);
1098
+ if (options.onCreateScope) options.onCreateScope();
1099
+ }
1100
+ function destroyScope() {
1101
+ var scope = scopes.pop();
1102
+ --scopeDepth;
1103
+ if (options.onDestroyScope) options.onDestroyScope();
1104
+ }
1105
+ function scopeIdentifierName(name) {
1106
+ if (options.onLocalDeclaration) options.onLocalDeclaration(name);
1107
+ if (-1 !== indexOf(scopes[scopeDepth], name)) return;
1108
+ scopes[scopeDepth].push(name);
1109
+ }
1110
+ function scopeIdentifier(node) {
1111
+ scopeIdentifierName(node.name);
1112
+ attachScope(node, true);
1113
+ }
1114
+ function attachScope(node, isLocal) {
1115
+ if (!isLocal && -1 === indexOfObject(globals, "name", node.name))
1116
+ globals.push(node);
1117
+ node.isLocal = isLocal;
1118
+ }
1119
+ function scopeHasName(name) {
1120
+ return -1 !== indexOf(scopes[scopeDepth], name);
1121
+ }
1122
+ var locations = [], trackLocations;
1123
+ function createLocationMarker() {
1124
+ return new Marker(token);
1125
+ }
1126
+ function Marker(token2) {
1127
+ if (options.locations) {
1128
+ this.loc = {
1129
+ start: {
1130
+ line: token2.line,
1131
+ column: token2.range[0] - token2.lineStart
1132
+ },
1133
+ end: {
1134
+ line: 0,
1135
+ column: 0
1136
+ }
1137
+ };
1138
+ }
1139
+ if (options.ranges) this.range = [token2.range[0], 0];
1140
+ }
1141
+ Marker.prototype.complete = function() {
1142
+ if (options.locations) {
1143
+ this.loc.end.line = previousToken.lastLine || previousToken.line;
1144
+ this.loc.end.column = previousToken.range[1] - (previousToken.lastLineStart || previousToken.lineStart);
1145
+ }
1146
+ if (options.ranges) {
1147
+ this.range[1] = previousToken.range[1];
1148
+ }
1149
+ };
1150
+ Marker.prototype.bless = function(node) {
1151
+ if (this.loc) {
1152
+ var loc = this.loc;
1153
+ node.loc = {
1154
+ start: {
1155
+ line: loc.start.line,
1156
+ column: loc.start.column
1157
+ },
1158
+ end: {
1159
+ line: loc.end.line,
1160
+ column: loc.end.column
1161
+ }
1162
+ };
1163
+ }
1164
+ if (this.range) {
1165
+ node.range = [
1166
+ this.range[0],
1167
+ this.range[1]
1168
+ ];
1169
+ }
1170
+ };
1171
+ function markLocation() {
1172
+ if (trackLocations) locations.push(createLocationMarker());
1173
+ }
1174
+ function pushLocation(marker) {
1175
+ if (trackLocations) locations.push(marker);
1176
+ }
1177
+ function FullFlowContext() {
1178
+ this.scopes = [];
1179
+ this.pendingGotos = [];
1180
+ }
1181
+ FullFlowContext.prototype.isInLoop = function() {
1182
+ var i = this.scopes.length;
1183
+ while (i-- > 0) {
1184
+ if (this.scopes[i].isLoop)
1185
+ return true;
1186
+ }
1187
+ return false;
1188
+ };
1189
+ FullFlowContext.prototype.pushScope = function(isLoop) {
1190
+ var scope = {
1191
+ labels: {},
1192
+ locals: [],
1193
+ deferredGotos: [],
1194
+ isLoop: !!isLoop
1195
+ };
1196
+ this.scopes.push(scope);
1197
+ };
1198
+ FullFlowContext.prototype.popScope = function() {
1199
+ for (var i = 0; i < this.pendingGotos.length; ++i) {
1200
+ var theGoto = this.pendingGotos[i];
1201
+ if (theGoto.maxDepth >= this.scopes.length) {
1202
+ if (--theGoto.maxDepth <= 0)
1203
+ raise(theGoto.token, errors.labelNotVisible, theGoto.target);
1204
+ }
1205
+ }
1206
+ this.scopes.pop();
1207
+ };
1208
+ FullFlowContext.prototype.addGoto = function(target, token2) {
1209
+ var localCounts = [];
1210
+ for (var i = 0; i < this.scopes.length; ++i) {
1211
+ var scope = this.scopes[i];
1212
+ localCounts.push(scope.locals.length);
1213
+ if (Object.prototype.hasOwnProperty.call(scope.labels, target))
1214
+ return;
1215
+ }
1216
+ this.pendingGotos.push({
1217
+ maxDepth: this.scopes.length,
1218
+ target,
1219
+ token: token2,
1220
+ localCounts
1221
+ });
1222
+ };
1223
+ FullFlowContext.prototype.addLabel = function(name, token2) {
1224
+ var scope = this.currentScope();
1225
+ if (Object.prototype.hasOwnProperty.call(scope.labels, name)) {
1226
+ raise(token2, errors.labelAlreadyDefined, name, scope.labels[name].line);
1227
+ } else {
1228
+ var newGotos = [];
1229
+ for (var i = 0; i < this.pendingGotos.length; ++i) {
1230
+ var theGoto = this.pendingGotos[i];
1231
+ if (theGoto.maxDepth >= this.scopes.length && theGoto.target === name) {
1232
+ if (theGoto.localCounts[this.scopes.length - 1] < scope.locals.length) {
1233
+ scope.deferredGotos.push(theGoto);
1234
+ }
1235
+ continue;
1236
+ }
1237
+ newGotos.push(theGoto);
1238
+ }
1239
+ this.pendingGotos = newGotos;
1240
+ }
1241
+ scope.labels[name] = {
1242
+ localCount: scope.locals.length,
1243
+ line: token2.line
1244
+ };
1245
+ };
1246
+ FullFlowContext.prototype.addLocal = function(name, token2) {
1247
+ this.currentScope().locals.push({
1248
+ name,
1249
+ token: token2
1250
+ });
1251
+ };
1252
+ FullFlowContext.prototype.currentScope = function() {
1253
+ return this.scopes[this.scopes.length - 1];
1254
+ };
1255
+ FullFlowContext.prototype.raiseDeferredErrors = function() {
1256
+ var scope = this.currentScope();
1257
+ var bads = scope.deferredGotos;
1258
+ for (var i = 0; i < bads.length; ++i) {
1259
+ var theGoto = bads[i];
1260
+ raise(theGoto.token, errors.gotoJumpInLocalScope, theGoto.target, scope.locals[theGoto.localCounts[this.scopes.length - 1]].name);
1261
+ }
1262
+ };
1263
+ function LoopFlowContext() {
1264
+ this.level = 0;
1265
+ this.loopLevels = [];
1266
+ }
1267
+ LoopFlowContext.prototype.isInLoop = function() {
1268
+ return !!this.loopLevels.length;
1269
+ };
1270
+ LoopFlowContext.prototype.pushScope = function(isLoop) {
1271
+ ++this.level;
1272
+ if (isLoop)
1273
+ this.loopLevels.push(this.level);
1274
+ };
1275
+ LoopFlowContext.prototype.popScope = function() {
1276
+ var levels = this.loopLevels;
1277
+ var levlen = levels.length;
1278
+ if (levlen) {
1279
+ if (levels[levlen - 1] === this.level)
1280
+ levels.pop();
1281
+ }
1282
+ --this.level;
1283
+ };
1284
+ LoopFlowContext.prototype.addGoto = LoopFlowContext.prototype.addLabel = /* istanbul ignore next */
1285
+ function() {
1286
+ throw new Error("This should never happen");
1287
+ };
1288
+ LoopFlowContext.prototype.addLocal = LoopFlowContext.prototype.raiseDeferredErrors = function() {
1289
+ };
1290
+ function makeFlowContext() {
1291
+ return features.labels ? new FullFlowContext() : new LoopFlowContext();
1292
+ }
1293
+ function parseChunk() {
1294
+ next();
1295
+ markLocation();
1296
+ if (options.scope) createScope();
1297
+ var flowContext = makeFlowContext();
1298
+ flowContext.allowVararg = true;
1299
+ flowContext.pushScope();
1300
+ var body = parseBlock(flowContext);
1301
+ flowContext.popScope();
1302
+ if (options.scope) destroyScope();
1303
+ if (EOF !== token.type) unexpected(token);
1304
+ if (trackLocations && !body.length) previousToken = token;
1305
+ return finishNode(ast.chunk(body));
1306
+ }
1307
+ function parseBlock(flowContext) {
1308
+ var block = [], statement;
1309
+ while (!isBlockFollow(token)) {
1310
+ if ("return" === token.value || !features.relaxedBreak && "break" === token.value) {
1311
+ block.push(parseStatement(flowContext));
1312
+ break;
1313
+ }
1314
+ statement = parseStatement(flowContext);
1315
+ consume(";");
1316
+ if (statement) block.push(statement);
1317
+ }
1318
+ return block;
1319
+ }
1320
+ function parseStatement(flowContext) {
1321
+ markLocation();
1322
+ if (Punctuator === token.type) {
1323
+ if (consume("::")) return parseLabelStatement(flowContext);
1324
+ }
1325
+ if (features.emptyStatement) {
1326
+ if (consume(";")) {
1327
+ if (trackLocations) locations.pop();
1328
+ return;
1329
+ }
1330
+ }
1331
+ flowContext.raiseDeferredErrors();
1332
+ if (Keyword === token.type) {
1333
+ switch (token.value) {
1334
+ case "local":
1335
+ next();
1336
+ return parseLocalStatement(flowContext);
1337
+ case "if":
1338
+ next();
1339
+ return parseIfStatement(flowContext);
1340
+ case "return":
1341
+ next();
1342
+ return parseReturnStatement(flowContext);
1343
+ case "function":
1344
+ next();
1345
+ var name = parseFunctionName();
1346
+ return parseFunctionDeclaration(name);
1347
+ case "while":
1348
+ next();
1349
+ return parseWhileStatement(flowContext);
1350
+ case "for":
1351
+ next();
1352
+ return parseForStatement(flowContext);
1353
+ case "repeat":
1354
+ next();
1355
+ return parseRepeatStatement(flowContext);
1356
+ case "break":
1357
+ next();
1358
+ if (!flowContext.isInLoop())
1359
+ raise(token, errors.noLoopToBreak, token.value);
1360
+ return parseBreakStatement();
1361
+ case "do":
1362
+ next();
1363
+ return parseDoStatement(flowContext);
1364
+ case "goto":
1365
+ next();
1366
+ return parseGotoStatement(flowContext);
1367
+ }
1368
+ }
1369
+ if (features.contextualGoto && token.type === Identifier && token.value === "goto" && lookahead.type === Identifier && lookahead.value !== "goto") {
1370
+ next();
1371
+ return parseGotoStatement(flowContext);
1372
+ }
1373
+ if (trackLocations) locations.pop();
1374
+ return parseAssignmentOrCallStatement(flowContext);
1375
+ }
1376
+ function parseLabelStatement(flowContext) {
1377
+ var nameToken = token, label = parseIdentifier();
1378
+ if (options.scope) {
1379
+ scopeIdentifierName("::" + nameToken.value + "::");
1380
+ attachScope(label, true);
1381
+ }
1382
+ expect("::");
1383
+ flowContext.addLabel(nameToken.value, nameToken);
1384
+ return finishNode(ast.labelStatement(label));
1385
+ }
1386
+ function parseBreakStatement() {
1387
+ return finishNode(ast.breakStatement());
1388
+ }
1389
+ function parseGotoStatement(flowContext) {
1390
+ var name = token.value, gotoToken = previousToken, label = parseIdentifier();
1391
+ flowContext.addGoto(name, gotoToken);
1392
+ return finishNode(ast.gotoStatement(label));
1393
+ }
1394
+ function parseDoStatement(flowContext) {
1395
+ if (options.scope) createScope();
1396
+ flowContext.pushScope();
1397
+ var body = parseBlock(flowContext);
1398
+ flowContext.popScope();
1399
+ if (options.scope) destroyScope();
1400
+ expect("end");
1401
+ return finishNode(ast.doStatement(body));
1402
+ }
1403
+ function parseWhileStatement(flowContext) {
1404
+ var condition = parseExpectedExpression(flowContext);
1405
+ expect("do");
1406
+ if (options.scope) createScope();
1407
+ flowContext.pushScope(true);
1408
+ var body = parseBlock(flowContext);
1409
+ flowContext.popScope();
1410
+ if (options.scope) destroyScope();
1411
+ expect("end");
1412
+ return finishNode(ast.whileStatement(condition, body));
1413
+ }
1414
+ function parseRepeatStatement(flowContext) {
1415
+ if (options.scope) createScope();
1416
+ flowContext.pushScope(true);
1417
+ var body = parseBlock(flowContext);
1418
+ expect("until");
1419
+ flowContext.raiseDeferredErrors();
1420
+ var condition = parseExpectedExpression(flowContext);
1421
+ flowContext.popScope();
1422
+ if (options.scope) destroyScope();
1423
+ return finishNode(ast.repeatStatement(condition, body));
1424
+ }
1425
+ function parseReturnStatement(flowContext) {
1426
+ var expressions = [];
1427
+ if ("end" !== token.value) {
1428
+ var expression = parseExpression(flowContext);
1429
+ if (null != expression) expressions.push(expression);
1430
+ while (consume(",")) {
1431
+ expression = parseExpectedExpression(flowContext);
1432
+ expressions.push(expression);
1433
+ }
1434
+ consume(";");
1435
+ }
1436
+ return finishNode(ast.returnStatement(expressions));
1437
+ }
1438
+ function parseIfStatement(flowContext) {
1439
+ var clauses = [], condition, body, marker;
1440
+ if (trackLocations) {
1441
+ marker = locations[locations.length - 1];
1442
+ locations.push(marker);
1443
+ }
1444
+ condition = parseExpectedExpression(flowContext);
1445
+ expect("then");
1446
+ if (options.scope) createScope();
1447
+ flowContext.pushScope();
1448
+ body = parseBlock(flowContext);
1449
+ flowContext.popScope();
1450
+ if (options.scope) destroyScope();
1451
+ clauses.push(finishNode(ast.ifClause(condition, body)));
1452
+ if (trackLocations) marker = createLocationMarker();
1453
+ while (consume("elseif")) {
1454
+ pushLocation(marker);
1455
+ condition = parseExpectedExpression(flowContext);
1456
+ expect("then");
1457
+ if (options.scope) createScope();
1458
+ flowContext.pushScope();
1459
+ body = parseBlock(flowContext);
1460
+ flowContext.popScope();
1461
+ if (options.scope) destroyScope();
1462
+ clauses.push(finishNode(ast.elseifClause(condition, body)));
1463
+ if (trackLocations) marker = createLocationMarker();
1464
+ }
1465
+ if (consume("else")) {
1466
+ if (trackLocations) {
1467
+ marker = new Marker(previousToken);
1468
+ locations.push(marker);
1469
+ }
1470
+ if (options.scope) createScope();
1471
+ flowContext.pushScope();
1472
+ body = parseBlock(flowContext);
1473
+ flowContext.popScope();
1474
+ if (options.scope) destroyScope();
1475
+ clauses.push(finishNode(ast.elseClause(body)));
1476
+ }
1477
+ expect("end");
1478
+ return finishNode(ast.ifStatement(clauses));
1479
+ }
1480
+ function parseForStatement(flowContext) {
1481
+ var variable = parseIdentifier(), body;
1482
+ if (options.scope) {
1483
+ createScope();
1484
+ scopeIdentifier(variable);
1485
+ }
1486
+ if (consume("=")) {
1487
+ var start = parseExpectedExpression(flowContext);
1488
+ expect(",");
1489
+ var end2 = parseExpectedExpression(flowContext);
1490
+ var step = consume(",") ? parseExpectedExpression(flowContext) : null;
1491
+ expect("do");
1492
+ flowContext.pushScope(true);
1493
+ body = parseBlock(flowContext);
1494
+ flowContext.popScope();
1495
+ expect("end");
1496
+ if (options.scope) destroyScope();
1497
+ return finishNode(ast.forNumericStatement(variable, start, end2, step, body));
1498
+ } else {
1499
+ var variables = [variable];
1500
+ while (consume(",")) {
1501
+ variable = parseIdentifier();
1502
+ if (options.scope) scopeIdentifier(variable);
1503
+ variables.push(variable);
1504
+ }
1505
+ expect("in");
1506
+ var iterators = [];
1507
+ do {
1508
+ var expression = parseExpectedExpression(flowContext);
1509
+ iterators.push(expression);
1510
+ } while (consume(","));
1511
+ expect("do");
1512
+ flowContext.pushScope(true);
1513
+ body = parseBlock(flowContext);
1514
+ flowContext.popScope();
1515
+ expect("end");
1516
+ if (options.scope) destroyScope();
1517
+ return finishNode(ast.forGenericStatement(variables, iterators, body));
1518
+ }
1519
+ }
1520
+ function parseLocalStatement(flowContext) {
1521
+ var name, declToken = previousToken;
1522
+ if (Identifier === token.type) {
1523
+ var variables = [], init = [];
1524
+ do {
1525
+ name = parseIdentifier();
1526
+ variables.push(name);
1527
+ flowContext.addLocal(name.name, declToken);
1528
+ } while (consume(","));
1529
+ if (consume("=")) {
1530
+ do {
1531
+ var expression = parseExpectedExpression(flowContext);
1532
+ init.push(expression);
1533
+ } while (consume(","));
1534
+ }
1535
+ if (options.scope) {
1536
+ for (var i = 0, l = variables.length; i < l; ++i) {
1537
+ scopeIdentifier(variables[i]);
1538
+ }
1539
+ }
1540
+ return finishNode(ast.localStatement(variables, init));
1541
+ }
1542
+ if (consume("function")) {
1543
+ name = parseIdentifier();
1544
+ flowContext.addLocal(name.name, declToken);
1545
+ if (options.scope) {
1546
+ scopeIdentifier(name);
1547
+ createScope();
1548
+ }
1549
+ return parseFunctionDeclaration(name, true);
1550
+ } else {
1551
+ raiseUnexpectedToken("<name>", token);
1552
+ }
1553
+ }
1554
+ function parseAssignmentOrCallStatement(flowContext) {
1555
+ var previous = token, marker, startMarker;
1556
+ var lvalue, base, name;
1557
+ var targets = [];
1558
+ if (trackLocations) startMarker = createLocationMarker();
1559
+ do {
1560
+ if (trackLocations) marker = createLocationMarker();
1561
+ if (Identifier === token.type) {
1562
+ name = token.value;
1563
+ base = parseIdentifier();
1564
+ if (options.scope) attachScope(base, scopeHasName(name));
1565
+ lvalue = true;
1566
+ } else if ("(" === token.value) {
1567
+ next();
1568
+ base = parseExpectedExpression(flowContext);
1569
+ expect(")");
1570
+ lvalue = false;
1571
+ } else {
1572
+ return unexpected(token);
1573
+ }
1574
+ both: for (; ; ) {
1575
+ var newBase;
1576
+ switch (StringLiteral === token.type ? '"' : token.value) {
1577
+ case ".":
1578
+ case "[":
1579
+ lvalue = true;
1580
+ break;
1581
+ case ":":
1582
+ case "(":
1583
+ case "{":
1584
+ case '"':
1585
+ lvalue = null;
1586
+ break;
1587
+ default:
1588
+ break both;
1589
+ }
1590
+ base = parsePrefixExpressionPart(base, marker, flowContext);
1591
+ }
1592
+ targets.push(base);
1593
+ if ("," !== token.value)
1594
+ break;
1595
+ if (!lvalue) {
1596
+ return unexpected(token);
1597
+ }
1598
+ next();
1599
+ } while (true);
1600
+ if (targets.length === 1 && lvalue === null) {
1601
+ pushLocation(marker);
1602
+ return finishNode(ast.callStatement(targets[0]));
1603
+ } else if (!lvalue) {
1604
+ return unexpected(token);
1605
+ }
1606
+ expect("=");
1607
+ var values = [];
1608
+ do {
1609
+ values.push(parseExpectedExpression(flowContext));
1610
+ } while (consume(","));
1611
+ pushLocation(startMarker);
1612
+ return finishNode(ast.assignmentStatement(targets, values));
1613
+ }
1614
+ function parseIdentifier() {
1615
+ markLocation();
1616
+ var identifier = token.value;
1617
+ if (Identifier !== token.type) raiseUnexpectedToken("<name>", token);
1618
+ next();
1619
+ return finishNode(ast.identifier(identifier));
1620
+ }
1621
+ function parseFunctionDeclaration(name, isLocal) {
1622
+ var flowContext = makeFlowContext();
1623
+ flowContext.pushScope();
1624
+ var parameters = [];
1625
+ expect("(");
1626
+ if (!consume(")")) {
1627
+ while (true) {
1628
+ if (Identifier === token.type) {
1629
+ var parameter = parseIdentifier();
1630
+ if (options.scope) scopeIdentifier(parameter);
1631
+ parameters.push(parameter);
1632
+ if (consume(",")) continue;
1633
+ } else if (VarargLiteral === token.type) {
1634
+ flowContext.allowVararg = true;
1635
+ parameters.push(parsePrimaryExpression(flowContext));
1636
+ } else {
1637
+ raiseUnexpectedToken("<name> or '...'", token);
1638
+ }
1639
+ expect(")");
1640
+ break;
1641
+ }
1642
+ }
1643
+ var body = parseBlock(flowContext);
1644
+ flowContext.popScope();
1645
+ expect("end");
1646
+ if (options.scope) destroyScope();
1647
+ isLocal = isLocal || false;
1648
+ return finishNode(ast.functionStatement(name, parameters, isLocal, body));
1649
+ }
1650
+ function parseFunctionName() {
1651
+ var base, name, marker;
1652
+ if (trackLocations) marker = createLocationMarker();
1653
+ base = parseIdentifier();
1654
+ if (options.scope) {
1655
+ attachScope(base, scopeHasName(base.name));
1656
+ createScope();
1657
+ }
1658
+ while (consume(".")) {
1659
+ pushLocation(marker);
1660
+ name = parseIdentifier();
1661
+ base = finishNode(ast.memberExpression(base, ".", name));
1662
+ }
1663
+ if (consume(":")) {
1664
+ pushLocation(marker);
1665
+ name = parseIdentifier();
1666
+ base = finishNode(ast.memberExpression(base, ":", name));
1667
+ if (options.scope) scopeIdentifierName("self");
1668
+ }
1669
+ return base;
1670
+ }
1671
+ function parseTableConstructor(flowContext) {
1672
+ var fields = [], key, value;
1673
+ while (true) {
1674
+ markLocation();
1675
+ if (Punctuator === token.type && consume("[")) {
1676
+ key = parseExpectedExpression(flowContext);
1677
+ expect("]");
1678
+ expect("=");
1679
+ value = parseExpectedExpression(flowContext);
1680
+ fields.push(finishNode(ast.tableKey(key, value)));
1681
+ } else if (Identifier === token.type) {
1682
+ if ("=" === lookahead.value) {
1683
+ key = parseIdentifier();
1684
+ next();
1685
+ value = parseExpectedExpression(flowContext);
1686
+ fields.push(finishNode(ast.tableKeyString(key, value)));
1687
+ } else {
1688
+ value = parseExpectedExpression(flowContext);
1689
+ fields.push(finishNode(ast.tableValue(value)));
1690
+ }
1691
+ } else {
1692
+ if (null == (value = parseExpression(flowContext))) {
1693
+ locations.pop();
1694
+ break;
1695
+ }
1696
+ fields.push(finishNode(ast.tableValue(value)));
1697
+ }
1698
+ if (",;".indexOf(token.value) >= 0) {
1699
+ next();
1700
+ continue;
1701
+ }
1702
+ break;
1703
+ }
1704
+ expect("}");
1705
+ return finishNode(ast.tableConstructorExpression(fields));
1706
+ }
1707
+ function parseExpression(flowContext) {
1708
+ var expression = parseSubExpression(0, flowContext);
1709
+ return expression;
1710
+ }
1711
+ function parseExpectedExpression(flowContext) {
1712
+ var expression = parseExpression(flowContext);
1713
+ if (null == expression) raiseUnexpectedToken("<expression>", token);
1714
+ else return expression;
1715
+ }
1716
+ function binaryPrecedence(operator) {
1717
+ var charCode = operator.charCodeAt(0), length2 = operator.length;
1718
+ if (1 === length2) {
1719
+ switch (charCode) {
1720
+ case 94:
1721
+ return 12;
1722
+ // ^
1723
+ case 42:
1724
+ case 47:
1725
+ case 37:
1726
+ return 10;
1727
+ // * / %
1728
+ case 43:
1729
+ case 45:
1730
+ return 9;
1731
+ // + -
1732
+ case 38:
1733
+ return 6;
1734
+ // &
1735
+ case 126:
1736
+ return 5;
1737
+ // ~
1738
+ case 124:
1739
+ return 4;
1740
+ // |
1741
+ case 60:
1742
+ case 62:
1743
+ return 3;
1744
+ }
1745
+ } else if (2 === length2) {
1746
+ switch (charCode) {
1747
+ case 47:
1748
+ return 10;
1749
+ // //
1750
+ case 46:
1751
+ return 8;
1752
+ // ..
1753
+ case 60:
1754
+ case 62:
1755
+ if ("<<" === operator || ">>" === operator) return 7;
1756
+ return 3;
1757
+ // <= >=
1758
+ case 61:
1759
+ case 126:
1760
+ return 3;
1761
+ // == ~=
1762
+ case 111:
1763
+ return 1;
1764
+ }
1765
+ } else if (97 === charCode && "and" === operator) return 2;
1766
+ return 0;
1767
+ }
1768
+ function parseSubExpression(minPrecedence, flowContext) {
1769
+ var operator = token.value, expression, marker;
1770
+ if (trackLocations) marker = createLocationMarker();
1771
+ if (isUnary(token)) {
1772
+ markLocation();
1773
+ next();
1774
+ var argument = parseSubExpression(10, flowContext);
1775
+ if (argument == null) raiseUnexpectedToken("<expression>", token);
1776
+ expression = finishNode(ast.unaryExpression(operator, argument));
1777
+ }
1778
+ if (null == expression) {
1779
+ expression = parsePrimaryExpression(flowContext);
1780
+ if (null == expression) {
1781
+ expression = parsePrefixExpression(flowContext);
1782
+ }
1783
+ }
1784
+ if (null == expression) return null;
1785
+ var precedence;
1786
+ while (true) {
1787
+ operator = token.value;
1788
+ precedence = Punctuator === token.type || Keyword === token.type ? binaryPrecedence(operator) : 0;
1789
+ if (precedence === 0 || precedence <= minPrecedence) break;
1790
+ if ("^" === operator || ".." === operator) --precedence;
1791
+ next();
1792
+ var right = parseSubExpression(precedence, flowContext);
1793
+ if (null == right) raiseUnexpectedToken("<expression>", token);
1794
+ if (trackLocations) locations.push(marker);
1795
+ expression = finishNode(ast.binaryExpression(operator, expression, right));
1796
+ }
1797
+ return expression;
1798
+ }
1799
+ function parsePrefixExpressionPart(base, marker, flowContext) {
1800
+ var expression, identifier;
1801
+ if (Punctuator === token.type) {
1802
+ switch (token.value) {
1803
+ case "[":
1804
+ pushLocation(marker);
1805
+ next();
1806
+ expression = parseExpectedExpression(flowContext);
1807
+ expect("]");
1808
+ return finishNode(ast.indexExpression(base, expression));
1809
+ case ".":
1810
+ pushLocation(marker);
1811
+ next();
1812
+ identifier = parseIdentifier();
1813
+ return finishNode(ast.memberExpression(base, ".", identifier));
1814
+ case ":":
1815
+ pushLocation(marker);
1816
+ next();
1817
+ identifier = parseIdentifier();
1818
+ base = finishNode(ast.memberExpression(base, ":", identifier));
1819
+ pushLocation(marker);
1820
+ return parseCallExpression(base, flowContext);
1821
+ case "(":
1822
+ case "{":
1823
+ pushLocation(marker);
1824
+ return parseCallExpression(base, flowContext);
1825
+ }
1826
+ } else if (StringLiteral === token.type) {
1827
+ pushLocation(marker);
1828
+ return parseCallExpression(base, flowContext);
1829
+ }
1830
+ return null;
1831
+ }
1832
+ function parsePrefixExpression(flowContext) {
1833
+ var base, name, marker;
1834
+ if (trackLocations) marker = createLocationMarker();
1835
+ if (Identifier === token.type) {
1836
+ name = token.value;
1837
+ base = parseIdentifier();
1838
+ if (options.scope) attachScope(base, scopeHasName(name));
1839
+ } else if (consume("(")) {
1840
+ base = parseExpectedExpression(flowContext);
1841
+ expect(")");
1842
+ } else {
1843
+ return null;
1844
+ }
1845
+ for (; ; ) {
1846
+ var newBase = parsePrefixExpressionPart(base, marker, flowContext);
1847
+ if (newBase === null)
1848
+ break;
1849
+ base = newBase;
1850
+ }
1851
+ return base;
1852
+ }
1853
+ function parseCallExpression(base, flowContext) {
1854
+ if (Punctuator === token.type) {
1855
+ switch (token.value) {
1856
+ case "(":
1857
+ if (!features.emptyStatement) {
1858
+ if (token.line !== previousToken.line)
1859
+ raise(null, errors.ambiguousSyntax, token.value);
1860
+ }
1861
+ next();
1862
+ var expressions = [];
1863
+ var expression = parseExpression(flowContext);
1864
+ if (null != expression) expressions.push(expression);
1865
+ while (consume(",")) {
1866
+ expression = parseExpectedExpression(flowContext);
1867
+ expressions.push(expression);
1868
+ }
1869
+ expect(")");
1870
+ return finishNode(ast.callExpression(base, expressions));
1871
+ case "{":
1872
+ markLocation();
1873
+ next();
1874
+ var table = parseTableConstructor(flowContext);
1875
+ return finishNode(ast.tableCallExpression(base, table));
1876
+ }
1877
+ } else if (StringLiteral === token.type) {
1878
+ return finishNode(ast.stringCallExpression(base, parsePrimaryExpression(flowContext)));
1879
+ }
1880
+ raiseUnexpectedToken("function arguments", token);
1881
+ }
1882
+ function parsePrimaryExpression(flowContext) {
1883
+ var literals = StringLiteral | NumericLiteral | BooleanLiteral | NilLiteral | VarargLiteral, value = token.value, type = token.type, marker;
1884
+ if (trackLocations) marker = createLocationMarker();
1885
+ if (type === VarargLiteral && !flowContext.allowVararg) {
1886
+ raise(token, errors.cannotUseVararg, token.value);
1887
+ }
1888
+ if (type & literals) {
1889
+ pushLocation(marker);
1890
+ var raw = input.slice(token.range[0], token.range[1]);
1891
+ next();
1892
+ return finishNode(ast.literal(type, value, raw));
1893
+ } else if (Keyword === type && "function" === value) {
1894
+ pushLocation(marker);
1895
+ next();
1896
+ if (options.scope) createScope();
1897
+ return parseFunctionDeclaration(null);
1898
+ } else if (consume("{")) {
1899
+ pushLocation(marker);
1900
+ return parseTableConstructor(flowContext);
1901
+ }
1902
+ }
1903
+ exports2.parse = parse2;
1904
+ var versionFeatures = {
1905
+ "5.1": {},
1906
+ "5.2": {
1907
+ labels: true,
1908
+ emptyStatement: true,
1909
+ hexEscapes: true,
1910
+ skipWhitespaceEscape: true,
1911
+ strictEscapes: true,
1912
+ relaxedBreak: true
1913
+ },
1914
+ "5.3": {
1915
+ labels: true,
1916
+ emptyStatement: true,
1917
+ hexEscapes: true,
1918
+ skipWhitespaceEscape: true,
1919
+ strictEscapes: true,
1920
+ unicodeEscapes: true,
1921
+ bitwiseOperators: true,
1922
+ integerDivision: true,
1923
+ relaxedBreak: true
1924
+ },
1925
+ "LuaJIT": {
1926
+ // XXX: LuaJIT language features may depend on compilation options; may need to
1927
+ // rethink how to handle this. Specifically, there is a LUAJIT_ENABLE_LUA52COMPAT
1928
+ // that removes contextual goto. Maybe add 'LuaJIT-5.2compat' as well?
1929
+ labels: true,
1930
+ contextualGoto: true,
1931
+ hexEscapes: true,
1932
+ skipWhitespaceEscape: true,
1933
+ strictEscapes: true,
1934
+ unicodeEscapes: true,
1935
+ imaginaryNumbers: true,
1936
+ integerSuffixes: true
1937
+ }
1938
+ };
1939
+ function parse2(_input, _options) {
1940
+ if ("undefined" === typeof _options && "object" === typeof _input) {
1941
+ _options = _input;
1942
+ _input = void 0;
1943
+ }
1944
+ if (!_options) _options = {};
1945
+ input = _input || "";
1946
+ options = assign({}, defaultOptions, _options);
1947
+ index = 0;
1948
+ line = 1;
1949
+ lineStart = 0;
1950
+ length = input.length;
1951
+ scopes = [[]];
1952
+ scopeDepth = 0;
1953
+ globals = [];
1954
+ locations = [];
1955
+ if (!Object.prototype.hasOwnProperty.call(versionFeatures, options.luaVersion)) {
1956
+ throw new Error(sprintf("Lua version '%1' not supported", options.luaVersion));
1957
+ }
1958
+ features = assign({}, versionFeatures[options.luaVersion]);
1959
+ if (options.extendedIdentifiers !== void 0)
1960
+ features.extendedIdentifiers = !!options.extendedIdentifiers;
1961
+ if (!Object.prototype.hasOwnProperty.call(encodingModes, options.encodingMode)) {
1962
+ throw new Error(sprintf("Encoding mode '%1' not supported", options.encodingMode));
1963
+ }
1964
+ encodingMode = encodingModes[options.encodingMode];
1965
+ if (options.comments) comments = [];
1966
+ if (!options.wait) return end();
1967
+ return exports2;
1968
+ }
1969
+ exports2.write = write;
1970
+ function write(_input) {
1971
+ input += String(_input);
1972
+ length = input.length;
1973
+ return exports2;
1974
+ }
1975
+ exports2.end = end;
1976
+ function end(_input) {
1977
+ if ("undefined" !== typeof _input) write(_input);
1978
+ if (input && input.substr(0, 2) === "#!") input = input.replace(/^.*/, function(line2) {
1979
+ return line2.replace(/./g, " ");
1980
+ });
1981
+ length = input.length;
1982
+ trackLocations = options.locations || options.ranges;
1983
+ lookahead = lex();
1984
+ var chunk = parseChunk();
1985
+ if (options.comments) chunk.comments = comments;
1986
+ if (options.scope) chunk.globals = globals;
1987
+ if (locations.length > 0)
1988
+ throw new Error("Location tracking failed. This is most likely a bug in luaparse");
1989
+ return chunk;
1990
+ }
1991
+ });
1992
+ }
1993
+ });
1994
+
1995
+ // Classify/barrel.nodejs.ts
1996
+ var barrel_nodejs_exports = {};
1997
+ __export(barrel_nodejs_exports, {
1998
+ Asks: () => Asks2,
1999
+ AsksWhen: () => AsksWhen,
2000
+ AsksWhen_: () => AsksWhen_,
2001
+ Bind: () => Bind4,
2002
+ BindOption: () => BindOption,
2003
+ BindOption_: () => BindOption_,
2004
+ Bind_: () => Bind_4,
2005
+ Catch: () => Catch2,
2006
+ Catch_: () => Catch_2,
2007
+ Extensions: () => Extensions,
2008
+ Map: () => Map6,
2009
+ Map_: () => Map_5,
2010
+ None: () => None2,
2011
+ Pure: () => Pure2,
2012
+ SetWhen: () => SetWhen,
2013
+ SetWhen_: () => SetWhen_
2014
+ });
2015
+
2016
+ // Lib/Array/Array.pure.ts
2017
+ var Array_pure_exports = {};
2018
+ __export(Array_pure_exports, {
2019
+ Bind: () => Bind2,
2020
+ Bind_: () => Bind_2,
2021
+ Choose: () => Choose,
2022
+ Choose_: () => Choose_,
2023
+ Filter: () => Filter,
2024
+ Filter_: () => Filter_,
2025
+ IsNonEmpty: () => IsNonEmpty,
2026
+ Map: () => Map3,
2027
+ Map_: () => Map_2
2028
+ });
2029
+
2030
+ // Lib/Function/Curry.pure.ts
2031
+ var CurryRev = (body) => (
2032
+ // @ts-expect-error
2033
+ (...args1) => {
2034
+ if (args1.length >= body.length)
2035
+ return body(...args1);
2036
+ else
2037
+ return (...args2) => body(...args2.slice(0, Math.max(0, body.length - args1.length)), ...args1);
2038
+ }
2039
+ );
2040
+
2041
+ // Lib/Function/Flow.pure.ts
2042
+ function Flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
2043
+ switch (arguments.length) {
2044
+ case 1:
2045
+ return ab;
2046
+ case 2:
2047
+ return function() {
2048
+ return bc(ab.apply(this, arguments));
2049
+ };
2050
+ case 3:
2051
+ return function() {
2052
+ return cd(bc(ab.apply(this, arguments)));
2053
+ };
2054
+ case 4:
2055
+ return function() {
2056
+ return de(cd(bc(ab.apply(this, arguments))));
2057
+ };
2058
+ case 5:
2059
+ return function() {
2060
+ return ef(de(cd(bc(ab.apply(this, arguments)))));
2061
+ };
2062
+ case 6:
2063
+ return function() {
2064
+ return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
2065
+ };
2066
+ case 7:
2067
+ return function() {
2068
+ return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
2069
+ };
2070
+ case 8:
2071
+ return function() {
2072
+ return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
2073
+ };
2074
+ case 9:
2075
+ return function() {
2076
+ return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
2077
+ };
2078
+ }
2079
+ return;
2080
+ }
2081
+
2082
+ // Lib/Function/Pipe.pure.ts
2083
+ function Pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
2084
+ switch (arguments.length) {
2085
+ case 1:
2086
+ return a;
2087
+ case 2:
2088
+ return ab(a);
2089
+ case 3:
2090
+ return bc(ab(a));
2091
+ case 4:
2092
+ return cd(bc(ab(a)));
2093
+ case 5:
2094
+ return de(cd(bc(ab(a))));
2095
+ case 6:
2096
+ return ef(de(cd(bc(ab(a)))));
2097
+ case 7:
2098
+ return fg(ef(de(cd(bc(ab(a))))));
2099
+ case 8:
2100
+ return gh(fg(ef(de(cd(bc(ab(a)))))));
2101
+ case 9:
2102
+ return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
2103
+ default: {
2104
+ let ret = arguments[0];
2105
+ for (let i = 1; i < arguments.length; i++) {
2106
+ ret = arguments[i](ret);
2107
+ }
2108
+ return ret;
2109
+ }
2110
+ }
2111
+ }
2112
+
2113
+ // Lib/Option/Option.pure.ts
2114
+ var Option_pure_exports = {};
2115
+ __export(Option_pure_exports, {
2116
+ All: () => All,
2117
+ Bind: () => Bind,
2118
+ Bind_: () => Bind_,
2119
+ Catch: () => Catch,
2120
+ Catch_: () => Catch_,
2121
+ Default: () => Default,
2122
+ DefaultLazy: () => DefaultLazy,
2123
+ DefaultLazy_: () => DefaultLazy_,
2124
+ Default_: () => Default_,
2125
+ Elim: () => Elim,
2126
+ ElimLazy: () => ElimLazy,
2127
+ ElimLazy_: () => ElimLazy_,
2128
+ Elim_: () => Elim_,
2129
+ IsNone: () => IsNone,
2130
+ IsSome: () => IsSome,
2131
+ Map: () => Map2,
2132
+ Map_: () => Map_,
2133
+ Match: () => Match,
2134
+ Match_: () => Match_,
2135
+ None: () => None,
2136
+ OfNullable: () => OfNullable,
2137
+ Some: () => Some,
2138
+ Some_Filter: () => Some_Filter,
2139
+ Some_Filter_: () => Some_Filter_
2140
+ });
2141
+ var Some = (value) => ({
2142
+ _tag: "Some",
2143
+ value
2144
+ });
2145
+ var none = { _tag: "None" };
2146
+ var None = () => none;
2147
+ var OfNullable = (value) => value === null || value === void 0 ? none : Some(value);
2148
+ var Some_Filter_ = (a, pred) => pred(a) ? Some(a) : None();
2149
+ var Some_Filter = CurryRev(Some_Filter_);
2150
+ var IsSome = (opt) => opt._tag === "Some";
2151
+ var IsNone = (opt) => opt._tag === "None";
2152
+ var All = (os) => {
2153
+ const out = [];
2154
+ for (const o of os) {
2155
+ if (IsNone(o)) return None();
2156
+ out.push(o.value);
2157
+ }
2158
+ return Some(out);
2159
+ };
2160
+ var Bind_ = (opt, f) => IsSome(opt) ? f(opt.value) : none;
2161
+ var Bind = CurryRev(Bind_);
2162
+ var Map_ = (opt, f) => IsSome(opt) ? Some(f(opt.value)) : none;
2163
+ var Map2 = CurryRev(Map_);
2164
+ var Catch_ = (opt, f) => IsSome(opt) ? opt : f();
2165
+ var Catch = CurryRev(Catch_);
2166
+ var Default_ = (opt, fallback) => IsSome(opt) ? opt.value : fallback;
2167
+ var Default = CurryRev(Default_);
2168
+ var DefaultLazy_ = (opt, fallback) => IsSome(opt) ? opt.value : fallback();
2169
+ var DefaultLazy = CurryRev(DefaultLazy_);
2170
+ var Elim_ = (opt, fallback, f) => Pipe(Map_(opt, f), (o) => Default_(o, fallback));
2171
+ var Elim = CurryRev(Elim_);
2172
+ var ElimLazy_ = (opt, fallback, f) => Pipe(Map2(opt, f), DefaultLazy(fallback));
2173
+ var ElimLazy = CurryRev(ElimLazy_);
2174
+ var Match_ = (opt, handlers) => IsSome(opt) ? handlers.onSome(opt.value) : handlers.onNone();
2175
+ var Match = CurryRev(Match_);
2176
+
2177
+ // Lib/Array/Array.pure.ts
2178
+ var IsNonEmpty = ((xs) => xs.length > 0);
2179
+ var Bind_2 = (f) => (xs) => xs.flatMap(f);
2180
+ var Bind2 = CurryRev(Bind_2);
2181
+ var Choose_ = (xs, chooser) => {
2182
+ const out = [];
2183
+ for (let i = 0; i < xs.length; i++) {
2184
+ const y = chooser(xs[i], i);
2185
+ if (Option_pure_exports.IsSome(y)) out.push(y.value);
2186
+ }
2187
+ return out;
2188
+ };
2189
+ var Choose = CurryRev(Choose_);
2190
+ var Filter_ = (xs, pred) => {
2191
+ const out = [];
2192
+ for (let i = 0; i < xs.length; i++) {
2193
+ const x = xs[i];
2194
+ if (pred(x, i)) out.push(x);
2195
+ }
2196
+ return out;
2197
+ };
2198
+ var Filter = CurryRev(Filter_);
2199
+ var Map_2 = (xs, f) => xs.map(f);
2200
+ var Map3 = CurryRev(Map_2);
2201
+
2202
+ // Lib/Reader/Reader.pure.ts
2203
+ var Reader_pure_exports = {};
2204
+ __export(Reader_pure_exports, {
2205
+ Asks: () => Asks,
2206
+ Bind: () => Bind3,
2207
+ Bind_: () => Bind_3,
2208
+ Map: () => Map4,
2209
+ Map_: () => Map_3,
2210
+ Pure: () => Pure
2211
+ });
2212
+ var Pure = (a) => (_env) => a;
2213
+ var Map_3 = (m, f) => (env) => f(m(env));
2214
+ var Map4 = CurryRev(Map_3);
2215
+ var Bind_3 = (m, f) => (env) => f(m(env))(env);
2216
+ var Bind3 = CurryRev(Bind_3);
2217
+ var Asks = (f) => (env) => f(env);
2218
+
2219
+ // Lib/Result/Result.pure.ts
2220
+ var Result_pure_exports = {};
2221
+ __export(Result_pure_exports, {
2222
+ Error: () => Error2,
2223
+ GetOrThrow: () => GetOrThrow,
2224
+ IsError: () => IsError,
2225
+ IsOk: () => IsOk,
2226
+ Map: () => Map5,
2227
+ Map_: () => Map_4,
2228
+ Ok: () => Ok
2229
+ });
2230
+ var Ok = (value) => ({
2231
+ _tag: "Ok",
2232
+ value
2233
+ });
2234
+ var Error2 = (reason) => ({
2235
+ _tag: "Error",
2236
+ error: reason
2237
+ });
2238
+ var IsOk = (res) => res._tag === "Ok";
2239
+ var IsError = (res) => res._tag === "Error";
2240
+ var Map_4 = (res, f) => IsOk(res) ? Ok(f(res.value)) : res;
2241
+ var Map5 = CurryRev(Map_4);
2242
+ var GetOrThrow = (res) => {
2243
+ if (IsOk(res))
2244
+ return res.value;
2245
+ else
2246
+ throw new globalThis.Error(JSON.stringify(res.error));
2247
+ };
2248
+
2249
+ // Lib/Set/Set.pure.ts
2250
+ var Set_pure_exports = {};
2251
+ __export(Set_pure_exports, {
2252
+ Empty: () => Empty,
2253
+ Empty_Mut: () => Empty_Mut,
2254
+ FromIterable: () => FromIterable,
2255
+ Has: () => Has,
2256
+ Singleton: () => Singleton,
2257
+ ToArray: () => ToArray,
2258
+ ToMutable: () => ToMutable
2259
+ });
2260
+ var _empty = new globalThis.Set();
2261
+ var Empty = () => _empty;
2262
+ var Empty_Mut = () => new globalThis.Set();
2263
+ var Singleton = (x) => new globalThis.Set([x]);
2264
+ var FromIterable = (xs) => new globalThis.Set(xs);
2265
+ var ToArray = (set) => [...set];
2266
+ var ToMutable = (set) => new globalThis.Set(set);
2267
+ var Has = (xs, y) => xs.has(y);
2268
+
2269
+ // Classify/Classify.pure.ts
2270
+ var Pure2 = (a) => (_) => Option_pure_exports.Some(a);
2271
+ var None2 = () => (_) => Option_pure_exports.None();
2272
+ var Map_5 = (m, f) => Reader_pure_exports.Map_(m, (m2) => Option_pure_exports.Map_(m2, f));
2273
+ var Map6 = CurryRev(Map_5);
2274
+ var Bind_4 = (m, f) => (ext) => Option_pure_exports.Bind(m(ext), (t) => f(t)(ext));
2275
+ var Bind4 = CurryRev(Bind_4);
2276
+ var BindOption_ = (m, f) => Reader_pure_exports.Map_(m, (m2) => Option_pure_exports.Bind_(m2, f));
2277
+ var BindOption = CurryRev(BindOption_);
2278
+ var Asks2 = (f) => (ext) => Option_pure_exports.Some(f(ext));
2279
+ var Catch_2 = (m1, m2) => (ext) => Option_pure_exports.Catch_(m1(ext), () => m2(ext));
2280
+ var Catch2 = CurryRev(Catch_2);
2281
+ var AsksWhen_ = (p, m) => Reader_pure_exports.Bind_(Reader_pure_exports.Asks(p), (b) => b ? m : None2());
2282
+ var AsksWhen = CurryRev(AsksWhen_);
2283
+ var SetWhen_ = (p, f) => AsksWhen_(p, Flow(f, Option_pure_exports.Some));
2284
+ var SetWhen = CurryRev(SetWhen_);
2285
+
2286
+ // Classify/File.nodejs.ts
2287
+ import path from "node:path";
2288
+ var Extensions = (extIter) => {
2289
+ const exts = Set_pure_exports.FromIterable(extIter);
2290
+ if (exts.values().some((x) => x.includes("."))) {
2291
+ throw new Error("File extensions may not contain a '.' character. Pass multiple extensions instead.");
2292
+ }
2293
+ return (filepath) => Pipe(
2294
+ path.basename(filepath).split("."),
2295
+ Array_pure_exports.Filter((x) => Set_pure_exports.Has(exts, x)),
2296
+ (x) => x.join("."),
2297
+ Option_pure_exports.Some_Filter((x) => x.length > 0)
2298
+ );
2299
+ };
2300
+
2301
+ // Checker/Checker.pure.ts
2302
+ var Checker_pure_exports = {};
2303
+ __export(Checker_pure_exports, {
2304
+ Allow: () => Allow2,
2305
+ Ask: () => Ask,
2306
+ Asks: () => Asks3,
2307
+ AsksWhen: () => AsksWhen2,
2308
+ AsksWhen_: () => AsksWhen_2,
2309
+ Bind: () => Bind6,
2310
+ Bind_: () => Bind_5,
2311
+ Build: () => Build,
2312
+ Deny: () => Deny2,
2313
+ IfM: () => IfM,
2314
+ IfM_: () => IfM_,
2315
+ Map: () => Map8,
2316
+ Map_: () => Map_6,
2317
+ Opinion: () => Opinion_pure_exports,
2318
+ Pure: () => Pure4,
2319
+ Then: () => Then,
2320
+ Then_: () => Then_,
2321
+ Validate: () => Validate,
2322
+ Warn: () => Warn2,
2323
+ When: () => When,
2324
+ When_: () => When_
2325
+ });
2326
+
2327
+ // Checker/Opinion/Opinion.pure.ts
2328
+ var Opinion_pure_exports = {};
2329
+ __export(Opinion_pure_exports, {
2330
+ Allow: () => Allow,
2331
+ Bind: () => Bind5,
2332
+ Deny: () => Deny,
2333
+ Map: () => Map7,
2334
+ Pure: () => Pure3,
2335
+ Warn: () => Warn
2336
+ });
2337
+ var Pure3 = (a) => ({ _tag: "Pure", Value: a });
2338
+ var Allow = () => ({ _tag: "Allow" });
2339
+ var Deny = (d) => ({ _tag: "Deny", Deps: d });
2340
+ var Warn = (x) => ({ _tag: "Warn", Message: x });
2341
+ var Map7 = (m, f) => m._tag === "Pure" ? Pure3(f(m.Value)) : m;
2342
+ var Bind5 = (m, f) => m._tag === "Pure" ? f(m.Value) : m;
2343
+
2344
+ // Partial_Order/PartialOrder.pure.ts
2345
+ var PartialOrder_pure_exports = {};
2346
+ __export(PartialOrder_pure_exports, {
2347
+ Make: () => Make,
2348
+ Query: () => Query
2349
+ });
2350
+ var invert = (rel) => rel === "<" ? ">" : "<";
2351
+ var Make = (chains) => {
2352
+ const po = /* @__PURE__ */ new Map();
2353
+ let cyclic = false;
2354
+ const getRels = (x) => {
2355
+ if (!po.has(x)) po.set(x, /* @__PURE__ */ new Map());
2356
+ return po.get(x);
2357
+ };
2358
+ const addRel = (x, rel, y) => {
2359
+ const xRels = getRels(x);
2360
+ if (xRels.get(y) === invert(rel)) {
2361
+ cyclic = true;
2362
+ } else {
2363
+ xRels.set(y, rel);
2364
+ }
2365
+ };
2366
+ const addRelSym = (x, _rel, y) => {
2367
+ addRel(x, "<", y);
2368
+ addRel(y, ">", x);
2369
+ };
2370
+ for (const chain of chains) {
2371
+ if (chain.length === 0) continue;
2372
+ const head = chain[0];
2373
+ const tail = chain.slice(1);
2374
+ let xs = Array.isArray(head) ? head : [head];
2375
+ for (const l of tail) {
2376
+ const ys = Array.isArray(l) ? l : [l];
2377
+ for (const x of xs) {
2378
+ for (const y of ys) {
2379
+ addRelSym(x, "<", y);
2380
+ getRels(x).forEach((rel, w) => {
2381
+ if (rel === ">") addRelSym(w, "<", y);
2382
+ });
2383
+ getRels(y).forEach((rel, z) => {
2384
+ if (rel === "<") addRelSym(x, "<", z);
2385
+ });
2386
+ }
2387
+ }
2388
+ xs = ys;
2389
+ }
2390
+ }
2391
+ return cyclic ? Result_pure_exports.Error("Partial order rules induce a cycle") : Result_pure_exports.Ok(po);
2392
+ };
2393
+ var Query = (po, x, y) => x === y ? "=" : po.get(x)?.get(y) ?? "?";
2394
+
2395
+ // Checker/Checker.pure.ts
2396
+ var Pure4 = (val) => Reader_pure_exports.Pure(Opinion_pure_exports.Pure(val));
2397
+ var Allow2 = () => Reader_pure_exports.Pure(Opinion_pure_exports.Allow());
2398
+ var Deny2 = () => Reader_pure_exports.Asks(Opinion_pure_exports.Deny);
2399
+ var Warn2 = (x) => Reader_pure_exports.Pure(Opinion_pure_exports.Warn(x));
2400
+ var Bind_5 = (m, f) => (d) => Opinion_pure_exports.Bind(m(d), (t) => f(t)(d));
2401
+ var Bind6 = CurryRev(Bind_5);
2402
+ var Map_6 = (m, f) => Bind_5(m, Flow(f, Pure4));
2403
+ var Map8 = CurryRev(Map_6);
2404
+ var Asks3 = (f) => Reader_pure_exports.Asks(Flow(f, Opinion_pure_exports.Pure));
2405
+ var Ask = Asks3((d) => d);
2406
+ var Then_ = (m1, m2) => Bind_5(m1, (_) => m2);
2407
+ var Then = CurryRev(Then_);
2408
+ var When_ = (b, m) => b ? m : Pure4(void 0);
2409
+ var When = CurryRev(When_);
2410
+ var AsksWhen_2 = (p, m) => Bind_5(Asks3(p), When(m));
2411
+ var AsksWhen2 = CurryRev(AsksWhen_2);
2412
+ var IfM_ = (mp, m1, m2) => Bind_5(mp, (b) => b ? m1 : m2);
2413
+ var IfM = CurryRev(IfM_);
2414
+ var Build = (classify) => (partialOrder) => build(classify, Result_pure_exports.GetOrThrow(partialOrder));
2415
+ var build = (classify, po) => ([xPath, yPath]) => Pipe(
2416
+ Option_pure_exports.All([classify(xPath), classify(yPath)]),
2417
+ Option_pure_exports.Elim(
2418
+ Opinion_pure_exports.Pure(void 0),
2419
+ ([xClass, yClass]) => {
2420
+ switch (PartialOrder_pure_exports.Query(po, xClass, yClass)) {
2421
+ case "<":
2422
+ case "=":
2423
+ return Opinion_pure_exports.Allow();
2424
+ case ">":
2425
+ case "?":
2426
+ return Opinion_pure_exports.Deny([xPath, yPath]);
2427
+ }
2428
+ }
2429
+ )
2430
+ );
2431
+ var Validate = (check, deps) => {
2432
+ const out = { deny: [], warn: [] };
2433
+ deps.forEach((x) => {
2434
+ const opinion = check(x);
2435
+ switch (opinion._tag) {
2436
+ case "Pure":
2437
+ return out.warn.push(`unhandled dependency: [${x[0]} -> ${x[1]}]`);
2438
+ case "Allow":
2439
+ return;
2440
+ case "Deny":
2441
+ return out.deny.push(x);
2442
+ case "Warn":
2443
+ return out.warn.push(opinion.Message);
2444
+ default:
2445
+ opinion;
2446
+ }
2447
+ });
2448
+ return out;
2449
+ };
2450
+
2451
+ // Plugin/barrel.nodejs.ts
2452
+ var barrel_nodejs_exports2 = {};
2453
+ __export(barrel_nodejs_exports2, {
2454
+ Esbuild: () => Esbuild,
2455
+ Lua: () => Lua_nodejs_exports
2456
+ });
2457
+
2458
+ // Plugin/esbuild.nodejs.ts
2459
+ var Esbuild = (check) => ({
2460
+ name: "purity-seal",
2461
+ setup: (build2) => {
2462
+ build2.initialOptions.metafile = true;
2463
+ build2.onEnd((buildResult) => {
2464
+ if (buildResult.metafile === void 0) return {};
2465
+ const inputs = buildResult.metafile.inputs;
2466
+ const warnings = [];
2467
+ const warn = (dependent, dependency, message) => warnings.push({
2468
+ text: message,
2469
+ notes: [
2470
+ { text: `Dependent: ${dependent}` },
2471
+ { text: `Dependency: ${dependency}` }
2472
+ ]
2473
+ });
2474
+ const errors = [];
2475
+ const error = (dependent, dependency, message) => errors.push({
2476
+ text: message,
2477
+ notes: [
2478
+ { text: `Dependent: ${dependent}` },
2479
+ { text: `Dependency: ${dependency}` }
2480
+ ]
2481
+ });
2482
+ for (const dependent in inputs) {
2483
+ for (const { path: dependency } of inputs[dependent].imports) {
2484
+ const result = check([dependent, dependency]);
2485
+ switch (result._tag) {
2486
+ case "Pure":
2487
+ warn(dependent, dependency, "unhandled dependency");
2488
+ break;
2489
+ case "Allow":
2490
+ break;
2491
+ case "Warn":
2492
+ warn(dependent, dependency, result.Message);
2493
+ break;
2494
+ case "Deny":
2495
+ const reason = `Deny: ${result.Deps[0]} depends on ${result.Deps[1]}`;
2496
+ error(dependent, dependency, reason);
2497
+ break;
2498
+ default:
2499
+ result;
2500
+ }
2501
+ }
2502
+ }
2503
+ return { warnings, errors };
2504
+ });
2505
+ }
2506
+ });
2507
+
2508
+ // Plugin/Lua.nodejs.ts
2509
+ var Lua_nodejs_exports = {};
2510
+ __export(Lua_nodejs_exports, {
2511
+ BuildDeps: () => BuildDeps
2512
+ });
2513
+ var Parser = __toESM(require_luaparse(), 1);
2514
+ import Fs from "node:fs/promises";
2515
+ var BuildDeps = async (filenames, bag) => {
2516
+ const opened = /* @__PURE__ */ new Set();
2517
+ const rec = async (filename) => {
2518
+ if (opened.has(filename)) return [];
2519
+ else {
2520
+ opened.add(filename);
2521
+ const filepath = bag.resolveModule(filename);
2522
+ const contents = await readFileContents(filepath);
2523
+ const imports = parseImports(contents, bag);
2524
+ const deps2 = imports.map((x) => [
2525
+ filepath,
2526
+ bag.resolveModule(x)
2527
+ ]);
2528
+ const depsRec = await Promise.all(imports.map(rec));
2529
+ return deps2.concat(depsRec.flat());
2530
+ }
2531
+ };
2532
+ const deps = [];
2533
+ for (const filename of filenames) {
2534
+ deps.push(...await rec(filename));
2535
+ }
2536
+ return deps;
2537
+ };
2538
+ var readFileContents = async (filename) => {
2539
+ const file = await Fs.open(filename);
2540
+ const lines = [];
2541
+ for await (const line of file.readLines()) {
2542
+ lines.push(line);
2543
+ }
2544
+ await file.close();
2545
+ return lines.join("\n");
2546
+ };
2547
+ var parseImports = (text, bag) => Pipe(
2548
+ Parser.parse(text, bag).body,
2549
+ Array_pure_exports.Filter((x) => x.type === "LocalStatement"),
2550
+ Array_pure_exports.Bind(traverse_imports_after_assignment),
2551
+ Array_pure_exports.Map((x) => x.slice(1, -1))
2552
+ // luaparse wraps strings in double quotes
2553
+ );
2554
+ var traverse_imports_after_assignment = (n) => Array_pure_exports.Choose(n.init, (x) => {
2555
+ if (x.type === "StringCallExpression")
2556
+ return Option_pure_exports.Some(x.argument.raw);
2557
+ else if (x.type === "CallExpression" && x.base.type === "Identifier" && x.base.name === "require" && Array_pure_exports.IsNonEmpty(x.arguments) && x.arguments[0].type === "StringLiteral")
2558
+ return Option_pure_exports.Some(x.arguments[0].raw);
2559
+ else
2560
+ return Option_pure_exports.None();
2561
+ });
2562
+ export {
2563
+ Array_pure_exports as Array,
2564
+ Checker_pure_exports as Checker,
2565
+ barrel_nodejs_exports as Classify,
2566
+ CurryRev,
2567
+ Flow,
2568
+ Option_pure_exports as Option,
2569
+ PartialOrder_pure_exports as PartialOrder,
2570
+ Pipe,
2571
+ barrel_nodejs_exports2 as Plugin,
2572
+ Reader_pure_exports as Reader,
2573
+ Result_pure_exports as Result,
2574
+ Set_pure_exports as Set
2575
+ };