typescript-to-lua 1.1.1 → 1.2.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 (113) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/LuaAST.d.ts +1 -0
  3. package/dist/LuaAST.js +10 -2
  4. package/dist/LuaLib.d.ts +3 -3
  5. package/dist/LuaLib.js +4 -4
  6. package/dist/LuaPrinter.d.ts +11 -4
  7. package/dist/LuaPrinter.js +54 -11
  8. package/dist/lualib/ArrayFlat.lua +1 -1
  9. package/dist/lualib/ArrayFlatMap.lua +1 -1
  10. package/dist/lualib/ArrayIsArray.lua +1 -1
  11. package/dist/lualib/ArrayReduce.lua +7 -1
  12. package/dist/lualib/ArrayReduceRight.lua +7 -1
  13. package/dist/lualib/ArraySetLength.lua +1 -1
  14. package/dist/lualib/ArraySplice.lua +5 -5
  15. package/dist/lualib/Await.lua +14 -10
  16. package/dist/lualib/CloneDescriptor.lua +8 -8
  17. package/dist/lualib/Decorate.lua +1 -1
  18. package/dist/lualib/DelegatedYield.lua +1 -3
  19. package/dist/lualib/Delete.lua +6 -6
  20. package/dist/lualib/Error.lua +47 -44
  21. package/dist/lualib/Generator.lua +1 -5
  22. package/dist/lualib/InstanceOf.lua +1 -1
  23. package/dist/lualib/InstanceOfObject.lua +1 -1
  24. package/dist/lualib/Map.lua +130 -134
  25. package/dist/lualib/Number.lua +1 -1
  26. package/dist/lualib/NumberIsFinite.lua +1 -1
  27. package/dist/lualib/NumberToString.lua +3 -5
  28. package/dist/lualib/ObjectDefineProperty.lua +40 -8
  29. package/dist/lualib/ParseFloat.lua +9 -5
  30. package/dist/lualib/ParseInt.lua +15 -3
  31. package/dist/lualib/Promise.lua +18 -22
  32. package/dist/lualib/Set.lua +119 -123
  33. package/dist/lualib/SetDescriptor.lua +7 -1
  34. package/dist/lualib/SourceMapTraceBack.lua +1 -1
  35. package/dist/lualib/SparseArrayNew.lua +5 -0
  36. package/dist/lualib/SparseArrayPush.lua +9 -0
  37. package/dist/lualib/SparseArraySpread.lua +4 -0
  38. package/dist/lualib/StringAccess.lua +1 -1
  39. package/dist/lualib/StringCharCodeAt.lua +1 -1
  40. package/dist/lualib/StringEndsWith.lua +2 -2
  41. package/dist/lualib/StringPadEnd.lua +2 -2
  42. package/dist/lualib/StringPadStart.lua +2 -2
  43. package/dist/lualib/StringReplace.lua +7 -1
  44. package/dist/lualib/StringSlice.lua +2 -2
  45. package/dist/lualib/StringSplit.lua +3 -3
  46. package/dist/lualib/StringStartsWith.lua +1 -1
  47. package/dist/lualib/StringSubstr.lua +1 -1
  48. package/dist/lualib/StringSubstring.lua +2 -2
  49. package/dist/lualib/Symbol.lua +3 -5
  50. package/dist/lualib/WeakMap.lua +40 -42
  51. package/dist/lualib/WeakSet.lua +36 -38
  52. package/dist/lualib/lualib_bundle.lua +603 -555
  53. package/dist/transformation/builtins/array.js +1 -2
  54. package/dist/transformation/builtins/function.js +1 -2
  55. package/dist/transformation/builtins/index.d.ts +1 -1
  56. package/dist/transformation/builtins/index.js +37 -4
  57. package/dist/transformation/builtins/object.d.ts +2 -1
  58. package/dist/transformation/builtins/object.js +1 -2
  59. package/dist/transformation/builtins/string.js +1 -2
  60. package/dist/transformation/context/context.d.ts +12 -0
  61. package/dist/transformation/context/context.js +102 -3
  62. package/dist/transformation/utils/diagnostics.d.ts +6 -0
  63. package/dist/transformation/utils/diagnostics.js +3 -1
  64. package/dist/transformation/utils/lua-ast.d.ts +0 -1
  65. package/dist/transformation/utils/lua-ast.js +13 -22
  66. package/dist/transformation/utils/preceding-statements.d.ts +3 -0
  67. package/dist/transformation/utils/preceding-statements.js +11 -0
  68. package/dist/transformation/utils/scope.d.ts +1 -0
  69. package/dist/transformation/utils/scope.js +8 -1
  70. package/dist/transformation/utils/typescript/index.d.ts +1 -0
  71. package/dist/transformation/utils/typescript/index.js +16 -1
  72. package/dist/transformation/visitors/access.d.ts +3 -0
  73. package/dist/transformation/visitors/access.js +63 -36
  74. package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
  75. package/dist/transformation/visitors/binary-expression/assignments.js +66 -57
  76. package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
  77. package/dist/transformation/visitors/binary-expression/compound.js +66 -68
  78. package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
  79. package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +54 -25
  80. package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
  81. package/dist/transformation/visitors/binary-expression/index.js +64 -20
  82. package/dist/transformation/visitors/call.d.ts +3 -2
  83. package/dist/transformation/visitors/call.js +109 -122
  84. package/dist/transformation/visitors/class/index.js +4 -7
  85. package/dist/transformation/visitors/class/new.js +4 -6
  86. package/dist/transformation/visitors/conditional.js +28 -14
  87. package/dist/transformation/visitors/delete.js +4 -0
  88. package/dist/transformation/visitors/expression-list.d.ts +7 -0
  89. package/dist/transformation/visitors/expression-list.js +120 -0
  90. package/dist/transformation/visitors/function.js +6 -8
  91. package/dist/transformation/visitors/identifier.js +4 -0
  92. package/dist/transformation/visitors/literal.js +69 -16
  93. package/dist/transformation/visitors/loops/do-while.js +34 -8
  94. package/dist/transformation/visitors/loops/for.js +25 -5
  95. package/dist/transformation/visitors/loops/utils.d.ts +1 -0
  96. package/dist/transformation/visitors/loops/utils.js +13 -2
  97. package/dist/transformation/visitors/modules/export.js +1 -1
  98. package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
  99. package/dist/transformation/visitors/optional-chaining.js +172 -0
  100. package/dist/transformation/visitors/sourceFile.js +4 -1
  101. package/dist/transformation/visitors/switch.js +29 -9
  102. package/dist/transformation/visitors/template.js +5 -2
  103. package/dist/transformation/visitors/typeof.js +3 -1
  104. package/dist/transformation/visitors/variable-declaration.js +21 -7
  105. package/dist/transformation/visitors/void.js +4 -7
  106. package/dist/transpilation/transformers.js +4 -1
  107. package/dist/transpilation/utils.js +2 -1
  108. package/package.json +5 -5
  109. package/dist/lualib/OptionalChainAccess.lua +0 -6
  110. package/dist/lualib/OptionalFunctionCall.lua +0 -6
  111. package/dist/lualib/OptionalMethodCall.lua +0 -11
  112. package/dist/transformation/utils/transform.d.ts +0 -8
  113. package/dist/transformation/utils/transform.js +0 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ - Upgraded to TypeScript 4.5.x.
6
+ - Improved general output formatting.
7
+ - Added support for more complicated (nested) destructuring patterns, also fixing an exception they caused before.
8
+ - Fixed incorrect interactions between standard library functionality and optional chaining, e.g. `myArray?.forEach()`.
9
+ - Fixed rejected promises sometimes not getting the correct rejection reason.
10
+ - Fixed some `delete` behavior that was different in Lua compared to JS.
11
+ - Fixed a bug causing exported classes to lose their decorators.
12
+ - Fixed plugins checking for ts-node from the wrong location (tsconfig directory), plugins will now check for ts-node relative to the tstl directory.
13
+
14
+ Under the hood:
15
+
16
+ - We can now transform using preceding statements, allowing all kinds of optimizations and improvements to output Lua.
17
+ - Updated various language constructs to use preceding statements instead of inline immediately-invoked functions.
18
+
3
19
  ## 1.1.0
4
20
 
5
21
  - **[Breaking]** We now use TypeScript's JSX transformer instead of maintaining our own. As a result, `React.createElement` now requires a self parameter, so remove `@noSelf`, `this: void` if necessary.
package/dist/LuaAST.d.ts CHANGED
@@ -216,6 +216,7 @@ export interface StringLiteral extends Expression {
216
216
  }
217
217
  export declare function isStringLiteral(node: Node): node is StringLiteral;
218
218
  export declare function createStringLiteral(value: string, tsOriginal?: ts.Node): StringLiteral;
219
+ export declare function isLiteral(node: Node): node is NilLiteral | DotsLiteral | BooleanLiteral | NumericLiteral | StringLiteral;
219
220
  export declare enum FunctionExpressionFlags {
220
221
  None = 1,
221
222
  Inline = 2,
package/dist/LuaAST.js CHANGED
@@ -2,8 +2,8 @@
2
2
  // Simplified Lua AST based roughly on http://lua-users.org/wiki/MetaLuaAbstractSyntaxTree,
3
3
  // https://www.lua.org/manual/5.3/manual.html#9 and the TS AST implementation
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createFunctionExpression = exports.isFunctionExpression = exports.FunctionExpressionFlags = exports.createStringLiteral = exports.isStringLiteral = exports.createNumericLiteral = exports.isNumericLiteral = exports.createDotsLiteral = exports.isDotsLiteral = exports.createBooleanLiteral = exports.isBooleanLiteral = exports.createNilLiteral = exports.isNilLiteral = exports.createExpressionStatement = exports.isExpressionStatement = exports.createBreakStatement = exports.isBreakStatement = exports.createReturnStatement = exports.isReturnStatement = exports.createLabelStatement = exports.isLabelStatement = exports.createGotoStatement = exports.isGotoStatement = exports.createForInStatement = exports.isForInStatement = exports.createForStatement = exports.isForStatement = exports.createRepeatStatement = exports.isRepeatStatement = exports.createWhileStatement = exports.isWhileStatement = exports.isIterationStatement = exports.createIfStatement = exports.isIfStatement = exports.createAssignmentStatement = exports.isAssignmentStatement = exports.createVariableDeclarationStatement = exports.isVariableDeclarationStatement = exports.createDoStatement = exports.isDoStatement = exports.createBlock = exports.isBlock = exports.createFile = exports.isFile = exports.getOriginalPos = exports.setNodeOriginal = exports.setNodePosition = exports.cloneNode = exports.createNode = exports.SyntaxKind = void 0;
6
- exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = void 0;
5
+ exports.isFunctionExpression = exports.FunctionExpressionFlags = exports.isLiteral = exports.createStringLiteral = exports.isStringLiteral = exports.createNumericLiteral = exports.isNumericLiteral = exports.createDotsLiteral = exports.isDotsLiteral = exports.createBooleanLiteral = exports.isBooleanLiteral = exports.createNilLiteral = exports.isNilLiteral = exports.createExpressionStatement = exports.isExpressionStatement = exports.createBreakStatement = exports.isBreakStatement = exports.createReturnStatement = exports.isReturnStatement = exports.createLabelStatement = exports.isLabelStatement = exports.createGotoStatement = exports.isGotoStatement = exports.createForInStatement = exports.isForInStatement = exports.createForStatement = exports.isForStatement = exports.createRepeatStatement = exports.isRepeatStatement = exports.createWhileStatement = exports.isWhileStatement = exports.isIterationStatement = exports.createIfStatement = exports.isIfStatement = exports.createAssignmentStatement = exports.isAssignmentStatement = exports.createVariableDeclarationStatement = exports.isVariableDeclarationStatement = exports.createDoStatement = exports.isDoStatement = exports.createBlock = exports.isBlock = exports.createFile = exports.isFile = exports.getOriginalPos = exports.setNodeOriginal = exports.setNodePosition = exports.cloneNode = exports.createNode = exports.SyntaxKind = void 0;
6
+ exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = exports.createFunctionExpression = void 0;
7
7
  // We can elide a lot of nodes especially tokens and keywords
8
8
  // because we don't create the AST from text
9
9
  const ts = require("typescript");
@@ -338,6 +338,14 @@ function createStringLiteral(value, tsOriginal) {
338
338
  return expression;
339
339
  }
340
340
  exports.createStringLiteral = createStringLiteral;
341
+ function isLiteral(node) {
342
+ return (isNilLiteral(node) ||
343
+ isDotsLiteral(node) ||
344
+ isBooleanLiteral(node) ||
345
+ isNumericLiteral(node) ||
346
+ isStringLiteral(node));
347
+ }
348
+ exports.isLiteral = isLiteral;
341
349
  var FunctionExpressionFlags;
342
350
  (function (FunctionExpressionFlags) {
343
351
  FunctionExpressionFlags[FunctionExpressionFlags["None"] = 1] = "None";
package/dist/LuaLib.d.ts CHANGED
@@ -56,9 +56,6 @@ export declare enum LuaLibFeature {
56
56
  ObjectKeys = "ObjectKeys",
57
57
  ObjectRest = "ObjectRest",
58
58
  ObjectValues = "ObjectValues",
59
- OptionalChainAccess = "OptionalChainAccess",
60
- OptionalFunctionCall = "OptionalFunctionCall",
61
- OptionalMethodCall = "OptionalMethodCall",
62
59
  ParseFloat = "ParseFloat",
63
60
  ParseInt = "ParseInt",
64
61
  Promise = "Promise",
@@ -68,6 +65,9 @@ export declare enum LuaLibFeature {
68
65
  PromiseRace = "PromiseRace",
69
66
  Set = "Set",
70
67
  SetDescriptor = "SetDescriptor",
68
+ SparseArrayNew = "SparseArrayNew",
69
+ SparseArrayPush = "SparseArrayPush",
70
+ SparseArraySpread = "SparseArraySpread",
71
71
  WeakMap = "WeakMap",
72
72
  WeakSet = "WeakSet",
73
73
  SourceMapTraceBack = "SourceMapTraceBack",
package/dist/LuaLib.js CHANGED
@@ -60,9 +60,6 @@ var LuaLibFeature;
60
60
  LuaLibFeature["ObjectKeys"] = "ObjectKeys";
61
61
  LuaLibFeature["ObjectRest"] = "ObjectRest";
62
62
  LuaLibFeature["ObjectValues"] = "ObjectValues";
63
- LuaLibFeature["OptionalChainAccess"] = "OptionalChainAccess";
64
- LuaLibFeature["OptionalFunctionCall"] = "OptionalFunctionCall";
65
- LuaLibFeature["OptionalMethodCall"] = "OptionalMethodCall";
66
63
  LuaLibFeature["ParseFloat"] = "ParseFloat";
67
64
  LuaLibFeature["ParseInt"] = "ParseInt";
68
65
  LuaLibFeature["Promise"] = "Promise";
@@ -72,6 +69,9 @@ var LuaLibFeature;
72
69
  LuaLibFeature["PromiseRace"] = "PromiseRace";
73
70
  LuaLibFeature["Set"] = "Set";
74
71
  LuaLibFeature["SetDescriptor"] = "SetDescriptor";
72
+ LuaLibFeature["SparseArrayNew"] = "SparseArrayNew";
73
+ LuaLibFeature["SparseArrayPush"] = "SparseArrayPush";
74
+ LuaLibFeature["SparseArraySpread"] = "SparseArraySpread";
75
75
  LuaLibFeature["WeakMap"] = "WeakMap";
76
76
  LuaLibFeature["WeakSet"] = "WeakSet";
77
77
  LuaLibFeature["SourceMapTraceBack"] = "SourceMapTraceBack";
@@ -107,7 +107,7 @@ const luaLibDependencies = {
107
107
  Await: [LuaLibFeature.InstanceOf, LuaLibFeature.New],
108
108
  Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
109
109
  DelegatedYield: [LuaLibFeature.StringAccess],
110
- Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors],
110
+ Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors, LuaLibFeature.Error, LuaLibFeature.New],
111
111
  Error: [LuaLibFeature.Class, LuaLibFeature.ClassExtends, LuaLibFeature.New],
112
112
  FunctionBind: [LuaLibFeature.Unpack],
113
113
  Generator: [LuaLibFeature.Symbol],
@@ -1,5 +1,6 @@
1
1
  import { SourceNode } from "source-map";
2
2
  import * as ts from "typescript";
3
+ import { CompilerOptions } from "./CompilerOptions";
3
4
  import * as lua from "./LuaAST";
4
5
  import { EmitHost } from "./transpilation";
5
6
  export declare const escapeString: (value: string) => string;
@@ -17,16 +18,18 @@ export declare class LuaPrinter {
17
18
  private program;
18
19
  private sourceFile;
19
20
  private static operatorMap;
21
+ private static operatorPrecedence;
22
+ private static rightAssociativeOperators;
20
23
  private currentIndent;
21
- private luaFile;
22
- private relativeSourcePath;
23
- private options;
24
+ protected luaFile: string;
25
+ protected relativeSourcePath: string;
26
+ protected options: CompilerOptions;
24
27
  static readonly sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
25
28
  constructor(emitHost: EmitHost, program: ts.Program, sourceFile: string);
26
29
  print(file: lua.File): PrintResult;
27
30
  private printInlineSourceMap;
28
31
  private printStackTraceOverride;
29
- private printFile;
32
+ protected printFile(file: lua.File): SourceNode;
30
33
  protected pushIndent(): void;
31
34
  protected popIndent(): void;
32
35
  protected indent(input?: SourceChunk): SourceChunk;
@@ -73,6 +76,10 @@ export declare class LuaPrinter {
73
76
  printTableIndexExpression(expression: lua.TableIndexExpression): SourceNode;
74
77
  printOperator(kind: lua.Operator): SourceNode;
75
78
  protected joinChunksWithComma(chunks: SourceChunk[]): SourceChunk[];
79
+ /**
80
+ * Returns true if the expression list (table field or parameters) should be printed on one line.
81
+ */
82
+ protected isSimpleExpressionList(expressions: lua.Expression[]): boolean;
76
83
  protected printExpressionList(expressions: lua.Expression[]): SourceChunk[];
77
84
  private buildSourceMap;
78
85
  }
@@ -512,26 +512,31 @@ class LuaPrinter {
512
512
  printUnaryExpression(expression) {
513
513
  const chunks = [];
514
514
  chunks.push(this.printOperator(expression.operator));
515
- chunks.push(this.printExpressionInParenthesesIfNeeded(expression.operand));
515
+ chunks.push(this.printExpressionInParenthesesIfNeeded(expression.operand, LuaPrinter.operatorPrecedence[expression.operator]));
516
516
  return this.createSourceNode(expression, chunks);
517
517
  }
518
518
  printBinaryExpression(expression) {
519
519
  const chunks = [];
520
- chunks.push(this.printExpressionInParenthesesIfNeeded(expression.left));
520
+ const isRightAssociative = LuaPrinter.rightAssociativeOperators.has(expression.operator);
521
+ const precedence = LuaPrinter.operatorPrecedence[expression.operator];
522
+ chunks.push(this.printExpressionInParenthesesIfNeeded(expression.left, isRightAssociative ? precedence + 1 : precedence));
521
523
  chunks.push(" ", this.printOperator(expression.operator), " ");
522
- chunks.push(this.printExpressionInParenthesesIfNeeded(expression.right));
524
+ chunks.push(this.printExpressionInParenthesesIfNeeded(expression.right, isRightAssociative ? precedence : precedence + 1));
523
525
  return this.createSourceNode(expression, chunks);
524
526
  }
525
- printExpressionInParenthesesIfNeeded(expression) {
526
- return this.needsParenthesis(expression)
527
+ printExpressionInParenthesesIfNeeded(expression, minPrecedenceToOmit) {
528
+ return this.needsParenthesis(expression, minPrecedenceToOmit)
527
529
  ? this.createSourceNode(expression, ["(", this.printExpression(expression), ")"])
528
530
  : this.printExpression(expression);
529
531
  }
530
- needsParenthesis(expression) {
531
- return (lua.isBinaryExpression(expression) ||
532
- lua.isFunctionExpression(expression) ||
533
- lua.isTableExpression(expression) ||
534
- (lua.isUnaryExpression(expression) && expression.operator === lua.SyntaxKind.NotOperator));
532
+ needsParenthesis(expression, minPrecedenceToOmit) {
533
+ if (lua.isBinaryExpression(expression) || lua.isUnaryExpression(expression)) {
534
+ return (minPrecedenceToOmit === undefined ||
535
+ LuaPrinter.operatorPrecedence[expression.operator] < minPrecedenceToOmit);
536
+ }
537
+ else {
538
+ return lua.isFunctionExpression(expression) || lua.isTableExpression(expression);
539
+ }
535
540
  }
536
541
  printCallExpression(expression) {
537
542
  const chunks = [];
@@ -575,9 +580,19 @@ class LuaPrinter {
575
580
  joinChunksWithComma(chunks) {
576
581
  return (0, utils_1.intersperse)(chunks, ", ");
577
582
  }
583
+ /**
584
+ * Returns true if the expression list (table field or parameters) should be printed on one line.
585
+ */
586
+ isSimpleExpressionList(expressions) {
587
+ if (expressions.length <= 1)
588
+ return true;
589
+ if (expressions.length > 4)
590
+ return false;
591
+ return expressions.every(isSimpleExpression);
592
+ }
578
593
  printExpressionList(expressions) {
579
594
  const chunks = [];
580
- if (expressions.every(isSimpleExpression)) {
595
+ if (this.isSimpleExpressionList(expressions)) {
581
596
  chunks.push(...this.joinChunksWithComma(expressions.map(e => this.printExpression(e))));
582
597
  }
583
598
  else {
@@ -675,5 +690,33 @@ LuaPrinter.operatorMap = {
675
690
  [lua.SyntaxKind.BitwiseLeftShiftOperator]: "<<",
676
691
  [lua.SyntaxKind.BitwiseNotOperator]: "~",
677
692
  };
693
+ LuaPrinter.operatorPrecedence = {
694
+ [lua.SyntaxKind.OrOperator]: 1,
695
+ [lua.SyntaxKind.AndOperator]: 2,
696
+ [lua.SyntaxKind.EqualityOperator]: 3,
697
+ [lua.SyntaxKind.InequalityOperator]: 3,
698
+ [lua.SyntaxKind.LessThanOperator]: 3,
699
+ [lua.SyntaxKind.LessEqualOperator]: 3,
700
+ [lua.SyntaxKind.GreaterThanOperator]: 3,
701
+ [lua.SyntaxKind.GreaterEqualOperator]: 3,
702
+ [lua.SyntaxKind.BitwiseOrOperator]: 4,
703
+ [lua.SyntaxKind.BitwiseExclusiveOrOperator]: 5,
704
+ [lua.SyntaxKind.BitwiseAndOperator]: 6,
705
+ [lua.SyntaxKind.BitwiseLeftShiftOperator]: 7,
706
+ [lua.SyntaxKind.BitwiseRightShiftOperator]: 7,
707
+ [lua.SyntaxKind.ConcatOperator]: 8,
708
+ [lua.SyntaxKind.AdditionOperator]: 9,
709
+ [lua.SyntaxKind.SubtractionOperator]: 9,
710
+ [lua.SyntaxKind.MultiplicationOperator]: 10,
711
+ [lua.SyntaxKind.DivisionOperator]: 10,
712
+ [lua.SyntaxKind.FloorDivisionOperator]: 10,
713
+ [lua.SyntaxKind.ModuloOperator]: 10,
714
+ [lua.SyntaxKind.NotOperator]: 11,
715
+ [lua.SyntaxKind.LengthOperator]: 11,
716
+ [lua.SyntaxKind.NegationOperator]: 11,
717
+ [lua.SyntaxKind.BitwiseNotOperator]: 11,
718
+ [lua.SyntaxKind.PowerOperator]: 12,
719
+ };
720
+ LuaPrinter.rightAssociativeOperators = new Set([lua.SyntaxKind.ConcatOperator, lua.SyntaxKind.PowerOperator]);
678
721
  LuaPrinter.sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
679
722
  //# sourceMappingURL=LuaPrinter.js.map
@@ -4,7 +4,7 @@ function __TS__ArrayFlat(array, depth)
4
4
  end
5
5
  local result = {}
6
6
  for ____, value in ipairs(array) do
7
- if (depth > 0) and __TS__ArrayIsArray(value) then
7
+ if depth > 0 and __TS__ArrayIsArray(value) then
8
8
  result = __TS__ArrayConcat(
9
9
  result,
10
10
  __TS__ArrayFlat(value, depth - 1)
@@ -4,7 +4,7 @@ function __TS__ArrayFlatMap(array, callback)
4
4
  local i = 0
5
5
  while i < #array do
6
6
  local value = callback(_G, array[i + 1], i, array)
7
- if (type(value) == "table") and __TS__ArrayIsArray(value) then
7
+ if type(value) == "table" and __TS__ArrayIsArray(value) then
8
8
  result = __TS__ArrayConcat(result, value)
9
9
  else
10
10
  result[#result + 1] = value
@@ -1,3 +1,3 @@
1
1
  function __TS__ArrayIsArray(value)
2
- return (type(value) == "table") and ((value[1] ~= nil) or (next(value, nil) == nil))
2
+ return type(value) == "table" and (value[1] ~= nil or next(value, nil) == nil)
3
3
  end
@@ -11,7 +11,13 @@ function __TS__ArrayReduce(arr, callbackFn, ...)
11
11
  error("Reduce of empty array with no initial value", 0)
12
12
  end
13
13
  for i = k, len - 1 do
14
- accumulator = callbackFn(_G, accumulator, arr[i + 1], i, arr)
14
+ accumulator = callbackFn(
15
+ _G,
16
+ accumulator,
17
+ arr[i + 1],
18
+ i,
19
+ arr
20
+ )
15
21
  end
16
22
  return accumulator
17
23
  end
@@ -11,7 +11,13 @@ function __TS__ArrayReduceRight(arr, callbackFn, ...)
11
11
  error("Reduce of empty array with no initial value", 0)
12
12
  end
13
13
  for i = k, 0, -1 do
14
- accumulator = callbackFn(_G, accumulator, arr[i + 1], i, arr)
14
+ accumulator = callbackFn(
15
+ _G,
16
+ accumulator,
17
+ arr[i + 1],
18
+ i,
19
+ arr
20
+ )
15
21
  end
16
22
  return accumulator
17
23
  end
@@ -1,5 +1,5 @@
1
1
  function __TS__ArraySetLength(arr, length)
2
- if (((length < 0) or (length ~= length)) or (length == math.huge)) or (math.floor(length) ~= length) then
2
+ if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
3
3
  error(
4
4
  "invalid array length: " .. tostring(length),
5
5
  0
@@ -35,7 +35,7 @@ function __TS__ArraySplice(list, ...)
35
35
  if itemCount < actualDeleteCount then
36
36
  do
37
37
  local k = actualStart
38
- while k < (len - actualDeleteCount) do
38
+ while k < len - actualDeleteCount do
39
39
  local from = k + actualDeleteCount
40
40
  local to = k + itemCount
41
41
  if list[from + 1] then
@@ -48,7 +48,7 @@ function __TS__ArraySplice(list, ...)
48
48
  end
49
49
  do
50
50
  local k = len
51
- while k > ((len - actualDeleteCount) + itemCount) do
51
+ while k > len - actualDeleteCount + itemCount do
52
52
  list[k] = nil
53
53
  k = k - 1
54
54
  end
@@ -57,8 +57,8 @@ function __TS__ArraySplice(list, ...)
57
57
  do
58
58
  local k = len - actualDeleteCount
59
59
  while k > actualStart do
60
- local from = (k + actualDeleteCount) - 1
61
- local to = (k + itemCount) - 1
60
+ local from = k + actualDeleteCount - 1
61
+ local to = k + itemCount - 1
62
62
  if list[from + 1] then
63
63
  list[to + 1] = list[from + 1]
64
64
  else
@@ -75,7 +75,7 @@ function __TS__ArraySplice(list, ...)
75
75
  end
76
76
  do
77
77
  local k = #list - 1
78
- while k >= ((len - actualDeleteCount) + itemCount) do
78
+ while k >= len - actualDeleteCount + itemCount do
79
79
  list[k + 1] = nil
80
80
  k = k - 1
81
81
  end
@@ -4,14 +4,20 @@ function __TS__AsyncAwaiter(generator)
4
4
  function(____, resolve, reject)
5
5
  local adopt, fulfilled, rejected, step, asyncCoroutine
6
6
  function adopt(self, value)
7
- return ((__TS__InstanceOf(value, __TS__Promise) and (function() return value end)) or (function() return __TS__Promise.resolve(value) end))()
7
+ local ____temp_0
8
+ if __TS__InstanceOf(value, __TS__Promise) then
9
+ ____temp_0 = value
10
+ else
11
+ ____temp_0 = __TS__Promise.resolve(value)
12
+ end
13
+ return ____temp_0
8
14
  end
9
15
  function fulfilled(self, value)
10
16
  local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
11
17
  if success then
12
18
  step(_G, resultOrError, errorOrErrorHandler)
13
19
  else
14
- reject(_G, resultOrError)
20
+ reject(_G, errorOrErrorHandler)
15
21
  end
16
22
  end
17
23
  function rejected(self, handler)
@@ -34,14 +40,12 @@ function __TS__AsyncAwaiter(generator)
34
40
  if coroutine.status(asyncCoroutine) == "dead" then
35
41
  resolve(_G, result)
36
42
  else
37
- (function()
38
- local ____self = adopt(_G, result)
39
- return ____self["then"](
40
- ____self,
41
- fulfilled,
42
- rejected(_G, errorHandler)
43
- )
44
- end)()
43
+ local ____self_1 = adopt(_G, result)
44
+ ____self_1["then"](
45
+ ____self_1,
46
+ fulfilled,
47
+ rejected(_G, errorHandler)
48
+ )
45
49
  end
46
50
  end
47
51
  asyncCoroutine = coroutine.create(generator)
@@ -1,19 +1,19 @@
1
+ local value
2
+ local writable
3
+ local set
4
+ local get
5
+ local configurable
6
+ local enumerable
1
7
  function __TS__CloneDescriptor(____bindingPattern0)
2
- local enumerable
3
8
  enumerable = ____bindingPattern0.enumerable
4
- local configurable
5
9
  configurable = ____bindingPattern0.configurable
6
- local get
7
10
  get = ____bindingPattern0.get
8
- local set
9
11
  set = ____bindingPattern0.set
10
- local writable
11
12
  writable = ____bindingPattern0.writable
12
- local value
13
13
  value = ____bindingPattern0.value
14
14
  local descriptor = {enumerable = enumerable == true, configurable = configurable == true}
15
- local hasGetterOrSetter = (get ~= nil) or (set ~= nil)
16
- local hasValueOrWritableAttribute = (writable ~= nil) or (value ~= nil)
15
+ local hasGetterOrSetter = get ~= nil or set ~= nil
16
+ local hasValueOrWritableAttribute = writable ~= nil or value ~= nil
17
17
  if hasGetterOrSetter and hasValueOrWritableAttribute then
18
18
  error("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.", 0)
19
19
  end
@@ -12,7 +12,7 @@ function __TS__Decorate(decorators, target, key, desc)
12
12
  local value = rawget(target, key)
13
13
  local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
14
14
  local desc = decorator(_G, target, key, descriptor) or descriptor
15
- local isSimpleValue = (((desc.configurable == true) and (desc.writable == true)) and (not desc.get)) and (not desc.set)
15
+ local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
16
16
  if isSimpleValue then
17
17
  rawset(target, key, desc.value)
18
18
  else
@@ -1,9 +1,7 @@
1
1
  function __TS__DelegatedYield(iterable)
2
2
  if type(iterable) == "string" then
3
3
  for index = 0, #iterable - 1 do
4
- coroutine.yield(
5
- __TS__StringAccess(iterable, index)
6
- )
4
+ coroutine.yield(__TS__StringAccess(iterable, index))
7
5
  end
8
6
  elseif iterable.____coroutine ~= nil then
9
7
  local co = iterable.____coroutine
@@ -4,16 +4,16 @@ function __TS__Delete(target, key)
4
4
  if descriptor then
5
5
  if not descriptor.configurable then
6
6
  error(
7
- ((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. ".",
7
+ __TS__New(
8
+ TypeError,
9
+ ((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. "."
10
+ ),
8
11
  0
9
12
  )
10
13
  end
11
14
  descriptors[key] = nil
12
15
  return true
13
16
  end
14
- if target[key] ~= nil then
15
- target[key] = nil
16
- return true
17
- end
18
- return false
17
+ target[key] = nil
18
+ return true
19
19
  end
@@ -16,7 +16,7 @@ function __TS__WrapErrorToString(self, getDescription)
16
16
  return function(self)
17
17
  local description = getDescription(self)
18
18
  local caller = debug.getinfo(3, "f")
19
- if (_VERSION == "Lua 5.1") or (caller and (caller.func ~= error)) then
19
+ if _VERSION == "Lua 5.1" or caller and caller.func ~= error then
20
20
  return description
21
21
  else
22
22
  return (tostring(description) .. "\n") .. self.stack
@@ -27,49 +27,52 @@ function __TS__InitErrorClass(self, Type, name)
27
27
  Type.name = name
28
28
  return setmetatable(
29
29
  Type,
30
- {
31
- __call = function(____, _self, message) return __TS__New(Type, message) end
32
- }
30
+ {__call = function(____, _self, message) return __TS__New(Type, message) end}
33
31
  )
34
32
  end
35
- Error = __TS__InitErrorClass(
36
- _G,
37
- (function()
38
- local ____ = __TS__Class()
39
- ____.name = ""
40
- function ____.prototype.____constructor(self, message)
41
- if message == nil then
42
- message = ""
43
- end
44
- self.message = message
45
- self.name = "Error"
46
- self.stack = __TS__GetErrorStack(_G, self.constructor.new)
47
- local metatable = getmetatable(self)
48
- if not metatable.__errorToStringPatched then
49
- metatable.__errorToStringPatched = true
50
- metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
51
- end
52
- end
53
- function ____.prototype.__tostring(self)
54
- return (((self.message ~= "") and (function() return (self.name .. ": ") .. self.message end)) or (function() return self.name end))()
55
- end
56
- return ____
57
- end)(),
58
- "Error"
59
- )
60
- for ____, errorName in ipairs({"RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"}) do
61
- _G[errorName] = __TS__InitErrorClass(
62
- _G,
63
- (function()
64
- local ____ = __TS__Class()
65
- ____.name = ____.name
66
- __TS__ClassExtends(____, Error)
67
- function ____.prototype.____constructor(self, ...)
68
- Error.prototype.____constructor(self, ...)
69
- self.name = errorName
70
- end
71
- return ____
72
- end)(),
73
- errorName
74
- )
33
+ local ____TS__InitErrorClass_3 = __TS__InitErrorClass
34
+ local ____G_2 = _G
35
+ ____class_0 = __TS__Class()
36
+ ____class_0.name = ""
37
+ function ____class_0.prototype.____constructor(self, message)
38
+ if message == nil then
39
+ message = ""
40
+ end
41
+ self.message = message
42
+ self.name = "Error"
43
+ self.stack = __TS__GetErrorStack(_G, self.constructor.new)
44
+ local metatable = getmetatable(self)
45
+ if not metatable.__errorToStringPatched then
46
+ metatable.__errorToStringPatched = true
47
+ metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
48
+ end
49
+ end
50
+ function ____class_0.prototype.__tostring(self)
51
+ local ____temp_1
52
+ if self.message ~= "" then
53
+ ____temp_1 = (self.name .. ": ") .. self.message
54
+ else
55
+ ____temp_1 = self.name
56
+ end
57
+ return ____temp_1
58
+ end
59
+ Error = ____TS__InitErrorClass_3(____G_2, ____class_0, "Error")
60
+ for ____, errorName in ipairs({
61
+ "RangeError",
62
+ "ReferenceError",
63
+ "SyntaxError",
64
+ "TypeError",
65
+ "URIError"
66
+ }) do
67
+ local ____G_7 = _G
68
+ local ____TS__InitErrorClass_6 = __TS__InitErrorClass
69
+ local ____G_5 = _G
70
+ local ____class_4 = __TS__Class()
71
+ ____class_4.name = ____class_4.name
72
+ __TS__ClassExtends(____class_4, Error)
73
+ function ____class_4.prototype.____constructor(self, ...)
74
+ Error.prototype.____constructor(self, ...)
75
+ self.name = errorName
76
+ end
77
+ ____G_7[errorName] = ____TS__InitErrorClass_6(____G_5, ____class_4, errorName)
75
78
  end
@@ -20,11 +20,7 @@ function __TS__Generator(fn)
20
20
  local args = {...}
21
21
  local argsLength = select("#", ...)
22
22
  return {
23
- ____coroutine = coroutine.create(
24
- function() return fn(
25
- (unpack or table.unpack)(args, 1, argsLength)
26
- ) end
27
- ),
23
+ ____coroutine = coroutine.create(function() return fn((unpack or table.unpack)(args, 1, argsLength)) end),
28
24
  [Symbol.iterator] = __TS__GeneratorIterator,
29
25
  next = __TS__GeneratorNext
30
26
  }
@@ -3,7 +3,7 @@ function __TS__InstanceOf(obj, classTbl)
3
3
  error("Right-hand side of 'instanceof' is not an object", 0)
4
4
  end
5
5
  if classTbl[Symbol.hasInstance] ~= nil then
6
- return not (not classTbl[Symbol.hasInstance](classTbl, obj))
6
+ return not not classTbl[Symbol.hasInstance](classTbl, obj)
7
7
  end
8
8
  if type(obj) == "table" then
9
9
  local luaClass = obj.constructor
@@ -1,4 +1,4 @@
1
1
  function __TS__InstanceOfObject(value)
2
2
  local valueType = type(value)
3
- return (valueType == "table") or (valueType == "function")
3
+ return valueType == "table" or valueType == "function"
4
4
  end