typescript-to-lua 1.0.1 → 1.1.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 (117) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/CompilerOptions.d.ts +4 -3
  3. package/dist/LuaAST.js +4 -4
  4. package/dist/LuaLib.d.ts +1 -0
  5. package/dist/LuaLib.js +1 -0
  6. package/dist/LuaPrinter.d.ts +6 -2
  7. package/dist/LuaPrinter.js +25 -16
  8. package/dist/cli/diagnostics.js +2 -2
  9. package/dist/cli/report.js +1 -1
  10. package/dist/cli/tsconfig.js +4 -4
  11. package/dist/lualib/Await.lua +26 -10
  12. package/dist/lualib/Promise.lua +20 -6
  13. package/dist/lualib/SourceMapTraceBack.lua +18 -8
  14. package/dist/lualib/StringReplace.lua +8 -13
  15. package/dist/lualib/StringReplaceAll.lua +35 -0
  16. package/dist/lualib/lualib_bundle.lua +106 -35
  17. package/dist/transformation/builtins/array.js +29 -29
  18. package/dist/transformation/builtins/console.js +2 -2
  19. package/dist/transformation/builtins/function.js +9 -9
  20. package/dist/transformation/builtins/global.js +8 -8
  21. package/dist/transformation/builtins/index.js +33 -33
  22. package/dist/transformation/builtins/math.js +4 -4
  23. package/dist/transformation/builtins/number.js +7 -7
  24. package/dist/transformation/builtins/object.js +11 -11
  25. package/dist/transformation/builtins/promise.js +9 -9
  26. package/dist/transformation/builtins/string.js +32 -30
  27. package/dist/transformation/builtins/symbol.js +3 -3
  28. package/dist/transformation/context/context.js +5 -5
  29. package/dist/transformation/index.js +1 -1
  30. package/dist/transformation/utils/annotations.d.ts +1 -3
  31. package/dist/transformation/utils/annotations.js +0 -2
  32. package/dist/transformation/utils/assignment-validation.js +8 -7
  33. package/dist/transformation/utils/diagnostics.js +4 -4
  34. package/dist/transformation/utils/export.js +4 -4
  35. package/dist/transformation/utils/function-context.js +8 -8
  36. package/dist/transformation/utils/lua-ast.js +18 -19
  37. package/dist/transformation/utils/lualib.js +1 -1
  38. package/dist/transformation/utils/safe-names.js +5 -5
  39. package/dist/transformation/utils/scope.d.ts +6 -0
  40. package/dist/transformation/utils/scope.js +70 -40
  41. package/dist/transformation/utils/symbols.js +6 -6
  42. package/dist/transformation/utils/transform.js +3 -3
  43. package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
  44. package/dist/transformation/utils/typescript/nodes.js +21 -1
  45. package/dist/transformation/visitors/access.js +16 -16
  46. package/dist/transformation/visitors/async-await.js +5 -4
  47. package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
  48. package/dist/transformation/visitors/binary-expression/bit.js +4 -4
  49. package/dist/transformation/visitors/binary-expression/compound.js +18 -18
  50. package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
  51. package/dist/transformation/visitors/binary-expression/index.js +21 -21
  52. package/dist/transformation/visitors/block.js +6 -6
  53. package/dist/transformation/visitors/break-continue.js +2 -2
  54. package/dist/transformation/visitors/call.js +35 -35
  55. package/dist/transformation/visitors/class/decorators.js +3 -3
  56. package/dist/transformation/visitors/class/index.js +34 -34
  57. package/dist/transformation/visitors/class/members/accessors.js +6 -6
  58. package/dist/transformation/visitors/class/members/constructor.js +7 -7
  59. package/dist/transformation/visitors/class/members/fields.js +6 -6
  60. package/dist/transformation/visitors/class/members/method.js +6 -6
  61. package/dist/transformation/visitors/class/new.js +12 -12
  62. package/dist/transformation/visitors/class/setup.js +11 -11
  63. package/dist/transformation/visitors/class/utils.js +2 -2
  64. package/dist/transformation/visitors/conditional.js +6 -6
  65. package/dist/transformation/visitors/delete.js +4 -4
  66. package/dist/transformation/visitors/enum.js +8 -8
  67. package/dist/transformation/visitors/errors.js +30 -30
  68. package/dist/transformation/visitors/expression-statement.js +10 -6
  69. package/dist/transformation/visitors/function.js +26 -26
  70. package/dist/transformation/visitors/identifier.js +22 -22
  71. package/dist/transformation/visitors/index.js +2 -2
  72. package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
  73. package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
  74. package/dist/transformation/visitors/language-extensions/multi.js +3 -3
  75. package/dist/transformation/visitors/language-extensions/operators.js +6 -6
  76. package/dist/transformation/visitors/language-extensions/range.js +6 -6
  77. package/dist/transformation/visitors/language-extensions/table.js +5 -5
  78. package/dist/transformation/visitors/literal.d.ts +1 -2
  79. package/dist/transformation/visitors/literal.js +19 -42
  80. package/dist/transformation/visitors/loops/do-while.js +2 -2
  81. package/dist/transformation/visitors/loops/for-in.js +4 -4
  82. package/dist/transformation/visitors/loops/for-of.js +13 -13
  83. package/dist/transformation/visitors/loops/for.js +3 -3
  84. package/dist/transformation/visitors/loops/utils.js +9 -9
  85. package/dist/transformation/visitors/modules/export.js +13 -13
  86. package/dist/transformation/visitors/modules/import.js +10 -10
  87. package/dist/transformation/visitors/namespace.js +13 -13
  88. package/dist/transformation/visitors/return.d.ts +1 -0
  89. package/dist/transformation/visitors/return.js +40 -26
  90. package/dist/transformation/visitors/sourceFile.js +8 -8
  91. package/dist/transformation/visitors/spread.js +11 -11
  92. package/dist/transformation/visitors/switch.js +34 -11
  93. package/dist/transformation/visitors/template.js +5 -5
  94. package/dist/transformation/visitors/typeof.js +2 -2
  95. package/dist/transformation/visitors/typescript.js +1 -1
  96. package/dist/transformation/visitors/unary-expression.js +9 -9
  97. package/dist/transformation/visitors/variable-declaration.js +28 -28
  98. package/dist/transformation/visitors/void.d.ts +6 -0
  99. package/dist/transformation/visitors/void.js +23 -0
  100. package/dist/transpilation/bundle.d.ts +3 -0
  101. package/dist/transpilation/bundle.js +52 -10
  102. package/dist/transpilation/diagnostics.js +3 -3
  103. package/dist/transpilation/index.js +2 -2
  104. package/dist/transpilation/output-collector.js +2 -2
  105. package/dist/transpilation/plugins.js +1 -1
  106. package/dist/transpilation/resolve.js +19 -12
  107. package/dist/transpilation/transformers.js +41 -24
  108. package/dist/transpilation/transpile.js +6 -6
  109. package/dist/transpilation/transpiler.js +8 -8
  110. package/dist/transpilation/utils.js +3 -2
  111. package/dist/tstl.js +8 -8
  112. package/dist/utils.js +2 -2
  113. package/package.json +15 -12
  114. package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
  115. package/dist/transformation/visitors/jsx/jsx.js +0 -237
  116. package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
  117. package/dist/transformation/visitors/jsx/xhtml.js +0 -260
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - **[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.
6
+ - **[Breaking(-ish)]** Due to limitations in 5.1, try/catch can no longer be used in async or generator functions when targetting Lua 5.1. This was already broken but now tstl will explicitly give an error if you try.
7
+ - Added support for the `switch` statement in all versions! (Before they were not supported in 5.1 and universal).
8
+ - Added support for `string.prototype.replaceAll` and improved `string.prototype.replace` implementation.
9
+ - Added `noResolvePaths` tsconfig option to disable module resolution for environment-provided modules.
10
+ - Implemented support for void expressions, i.e `void(0)` or `void(ignoreThisReturnValue())`.
11
+ - Upgraded TypeScript to 4.4.4 and made it a peer dependency to hopefully avoid plugin issues due to mismatching TypeScript versions.
12
+ - The `$vararg` language extension can be used to access CLI arguments, now also in bundles.
13
+ - Fixed a bug regarding `baseUrl` and relative imports.
14
+ - Fixed `sourceMapTraceback: true` not working correctly for bundles.
15
+ - Fixed an issue regarding hoisting in switch case clauses.
16
+ - Added missing function context validation cases for object literals.
17
+ - Fixed a problem where awaiting rejected promises in try/catch would give the wrong result.
18
+ - Fixed an issue where chained `.then` calls on already-resolved or already-rejected promises would cause some callbacks to not fire while they should.
19
+ - Fixed source file paths in source maps being absolute, they are now relative again.
20
+
3
21
  ## 1.0.0
4
22
 
5
23
  - **[Breaking]** `/* @tupleReturn */` has been removed and will no longer have any effect. You will get an error if you try ot use it or if you use declarations that use it.
@@ -17,15 +17,16 @@ export interface LuaPluginImport {
17
17
  }
18
18
  export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
19
19
  buildMode?: BuildMode;
20
- noImplicitSelf?: boolean;
21
- noHeader?: boolean;
22
20
  luaBundle?: string;
23
21
  luaBundleEntry?: string;
24
22
  luaTarget?: LuaTarget;
25
23
  luaLibImport?: LuaLibImportKind;
26
- sourceMapTraceback?: boolean;
27
24
  luaPlugins?: LuaPluginImport[];
25
+ noImplicitSelf?: boolean;
26
+ noHeader?: boolean;
27
+ noResolvePaths?: string[];
28
28
  plugins?: Array<ts.PluginImport | TransformerImport>;
29
+ sourceMapTraceback?: boolean;
29
30
  tstlVerbose?: boolean;
30
31
  [option: string]: any;
31
32
  };
package/dist/LuaAST.js CHANGED
@@ -162,9 +162,9 @@ function isVariableDeclarationStatement(node) {
162
162
  exports.isVariableDeclarationStatement = isVariableDeclarationStatement;
163
163
  function createVariableDeclarationStatement(left, right, tsOriginal) {
164
164
  const statement = createNode(SyntaxKind.VariableDeclarationStatement, tsOriginal);
165
- statement.left = utils_1.castArray(left);
165
+ statement.left = (0, utils_1.castArray)(left);
166
166
  if (right)
167
- statement.right = utils_1.castArray(right);
167
+ statement.right = (0, utils_1.castArray)(right);
168
168
  return statement;
169
169
  }
170
170
  exports.createVariableDeclarationStatement = createVariableDeclarationStatement;
@@ -174,8 +174,8 @@ function isAssignmentStatement(node) {
174
174
  exports.isAssignmentStatement = isAssignmentStatement;
175
175
  function createAssignmentStatement(left, right, tsOriginal) {
176
176
  const statement = createNode(SyntaxKind.AssignmentStatement, tsOriginal);
177
- statement.left = utils_1.castArray(left);
178
- statement.right = right ? utils_1.castArray(right) : [];
177
+ statement.left = (0, utils_1.castArray)(left);
178
+ statement.right = right ? (0, utils_1.castArray)(right) : [];
179
179
  return statement;
180
180
  }
181
181
  exports.createAssignmentStatement = createAssignmentStatement;
package/dist/LuaLib.d.ts CHANGED
@@ -81,6 +81,7 @@ export declare enum LuaLibFeature {
81
81
  StringPadEnd = "StringPadEnd",
82
82
  StringPadStart = "StringPadStart",
83
83
  StringReplace = "StringReplace",
84
+ StringReplaceAll = "StringReplaceAll",
84
85
  StringSlice = "StringSlice",
85
86
  StringSplit = "StringSplit",
86
87
  StringStartsWith = "StringStartsWith",
package/dist/LuaLib.js CHANGED
@@ -85,6 +85,7 @@ var LuaLibFeature;
85
85
  LuaLibFeature["StringPadEnd"] = "StringPadEnd";
86
86
  LuaLibFeature["StringPadStart"] = "StringPadStart";
87
87
  LuaLibFeature["StringReplace"] = "StringReplace";
88
+ LuaLibFeature["StringReplaceAll"] = "StringReplaceAll";
88
89
  LuaLibFeature["StringSlice"] = "StringSlice";
89
90
  LuaLibFeature["StringSplit"] = "StringSplit";
90
91
  LuaLibFeature["StringStartsWith"] = "StringStartsWith";
@@ -14,11 +14,15 @@ export interface PrintResult {
14
14
  export declare function createPrinter(printers: Printer[]): Printer;
15
15
  export declare class LuaPrinter {
16
16
  private emitHost;
17
+ private program;
18
+ private sourceFile;
17
19
  private static operatorMap;
18
20
  private currentIndent;
19
- private sourceFile;
21
+ private luaFile;
22
+ private relativeSourcePath;
20
23
  private options;
21
- constructor(emitHost: EmitHost, program: ts.Program, fileName: string);
24
+ static readonly sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
25
+ constructor(emitHost: EmitHost, program: ts.Program, sourceFile: string);
22
26
  print(file: lua.File): PrintResult;
23
27
  private printInlineSourceMap;
24
28
  private printStackTraceOverride;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LuaPrinter = exports.createPrinter = exports.tstlHeader = exports.escapeString = void 0;
4
+ const path = require("path");
4
5
  const source_map_1 = require("source-map");
6
+ const _1 = require(".");
5
7
  const CompilerOptions_1 = require("./CompilerOptions");
6
8
  const lua = require("./LuaAST");
7
9
  const LuaLib_1 = require("./LuaLib");
@@ -71,11 +73,15 @@ function createPrinter(printers) {
71
73
  }
72
74
  exports.createPrinter = createPrinter;
73
75
  class LuaPrinter {
74
- constructor(emitHost, program, fileName) {
76
+ constructor(emitHost, program, sourceFile) {
75
77
  this.emitHost = emitHost;
78
+ this.program = program;
79
+ this.sourceFile = sourceFile;
76
80
  this.currentIndent = "";
77
81
  this.options = program.getCompilerOptions();
78
- this.sourceFile = fileName;
82
+ this.luaFile = (0, utils_1.normalizeSlashes)((0, _1.getEmitPath)(this.sourceFile, this.program));
83
+ // Source nodes contain relative path from mapped lua file to original TS source file
84
+ this.relativeSourcePath = (0, utils_1.normalizeSlashes)(path.relative(path.dirname(this.luaFile), this.sourceFile));
79
85
  }
80
86
  print(file) {
81
87
  // Add traceback lualib if sourcemap traceback option is enabled
@@ -94,7 +100,7 @@ class LuaPrinter {
94
100
  }
95
101
  if (this.options.sourceMapTraceback) {
96
102
  const stackTraceOverride = this.printStackTraceOverride(rootSourceNode);
97
- code = code.replace("{#SourceMapTraceback}", stackTraceOverride);
103
+ code = code.replace(LuaPrinter.sourceMapTracebackPlaceholder, stackTraceOverride);
98
104
  }
99
105
  return { code, sourceMap: sourceMap.toString(), sourceMapNode: rootSourceNode };
100
106
  }
@@ -136,10 +142,12 @@ class LuaPrinter {
136
142
  else if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Inline && file.luaLibFeatures.size > 0) {
137
143
  // Inline lualib features
138
144
  header += "-- Lua Library inline imports\n";
139
- header += LuaLib_1.loadLuaLibFeatures(file.luaLibFeatures, this.emitHost);
145
+ header += (0, LuaLib_1.loadLuaLibFeatures)(file.luaLibFeatures, this.emitHost);
140
146
  }
141
- if (this.options.sourceMapTraceback) {
142
- header += "{#SourceMapTraceback}\n";
147
+ if (this.options.sourceMapTraceback && !(0, CompilerOptions_1.isBundleEnabled)(this.options)) {
148
+ // In bundle mode the traceback is being generated for the entire file in getBundleResult
149
+ // Otherwise, traceback is being generated locally
150
+ header += `${LuaPrinter.sourceMapTracebackPlaceholder}\n`;
143
151
  }
144
152
  return this.concatNodes(header, ...this.printStatementArray(file.statements));
145
153
  }
@@ -155,11 +163,11 @@ class LuaPrinter {
155
163
  createSourceNode(node, chunks, name) {
156
164
  const { line, column } = lua.getOriginalPos(node);
157
165
  return line !== undefined && column !== undefined
158
- ? new source_map_1.SourceNode(line + 1, column, this.sourceFile, chunks, name)
159
- : new source_map_1.SourceNode(null, null, this.sourceFile, chunks, name);
166
+ ? new source_map_1.SourceNode(line + 1, column, this.relativeSourcePath, chunks, name)
167
+ : new source_map_1.SourceNode(null, null, this.relativeSourcePath, chunks, name);
160
168
  }
161
169
  concatNodes(...chunks) {
162
- return new source_map_1.SourceNode(null, null, this.sourceFile, chunks);
170
+ return new source_map_1.SourceNode(null, null, this.relativeSourcePath, chunks);
163
171
  }
164
172
  printBlock(block) {
165
173
  return this.concatNodes(...this.printStatementArray(block.statements));
@@ -195,7 +203,7 @@ class LuaPrinter {
195
203
  if (lua.isReturnStatement(statement))
196
204
  break;
197
205
  }
198
- return statementNodes.length > 0 ? [...utils_1.intersperse(statementNodes, "\n"), "\n"] : [];
206
+ return statementNodes.length > 0 ? [...(0, utils_1.intersperse)(statementNodes, "\n"), "\n"] : [];
199
207
  }
200
208
  printStatement(statement) {
201
209
  let resultNode = this.printStatementExcludingComments(statement);
@@ -422,7 +430,7 @@ class LuaPrinter {
422
430
  }
423
431
  }
424
432
  printStringLiteral(expression) {
425
- return this.createSourceNode(expression, exports.escapeString(expression.value));
433
+ return this.createSourceNode(expression, (0, exports.escapeString)(expression.value));
426
434
  }
427
435
  printNumericLiteral(expression) {
428
436
  return this.createSourceNode(expression, String(expression.value));
@@ -486,7 +494,7 @@ class LuaPrinter {
486
494
  const chunks = [];
487
495
  const value = this.printExpression(expression.value);
488
496
  if (expression.key) {
489
- if (lua.isStringLiteral(expression.key) && safe_names_1.isValidLuaIdentifier(expression.key.value)) {
497
+ if (lua.isStringLiteral(expression.key) && (0, safe_names_1.isValidLuaIdentifier)(expression.key.value)) {
490
498
  chunks.push(expression.key.value, " = ", value);
491
499
  }
492
500
  else {
@@ -553,7 +561,7 @@ class LuaPrinter {
553
561
  printTableIndexExpression(expression) {
554
562
  const chunks = [];
555
563
  chunks.push(this.printExpressionInParenthesesIfNeeded(expression.table));
556
- if (lua.isStringLiteral(expression.index) && safe_names_1.isValidLuaIdentifier(expression.index.value)) {
564
+ if (lua.isStringLiteral(expression.index) && (0, safe_names_1.isValidLuaIdentifier)(expression.index.value)) {
557
565
  chunks.push(".", this.createSourceNode(expression.index, expression.index.value));
558
566
  }
559
567
  else {
@@ -562,10 +570,10 @@ class LuaPrinter {
562
570
  return this.createSourceNode(expression, chunks);
563
571
  }
564
572
  printOperator(kind) {
565
- return new source_map_1.SourceNode(null, null, this.sourceFile, LuaPrinter.operatorMap[kind]);
573
+ return new source_map_1.SourceNode(null, null, this.relativeSourcePath, LuaPrinter.operatorMap[kind]);
566
574
  }
567
575
  joinChunksWithComma(chunks) {
568
- return utils_1.intersperse(chunks, ", ");
576
+ return (0, utils_1.intersperse)(chunks, ", ");
569
577
  }
570
578
  printExpressionList(expressions) {
571
579
  const chunks = [];
@@ -588,7 +596,7 @@ class LuaPrinter {
588
596
  // will not generate 'empty' mappings in the source map that point to nothing in the original TS.
589
597
  buildSourceMap(sourceRoot, rootSourceNode) {
590
598
  const map = new source_map_1.SourceMapGenerator({
591
- file: utils_1.trimExtension(this.sourceFile) + ".lua",
599
+ file: path.basename(this.luaFile),
592
600
  sourceRoot,
593
601
  });
594
602
  let generatedLine = 1;
@@ -667,4 +675,5 @@ LuaPrinter.operatorMap = {
667
675
  [lua.SyntaxKind.BitwiseLeftShiftOperator]: "<<",
668
676
  [lua.SyntaxKind.BitwiseNotOperator]: "~",
669
677
  };
678
+ LuaPrinter.sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
670
679
  //# sourceMappingURL=LuaPrinter.js.map
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.optionBuildMustBeFirstCommandLineArgument = exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = exports.argumentForOptionMustBe = exports.compilerOptionExpectsAnArgument = exports.theSpecifiedPathDoesNotExist = exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = exports.compilerOptionRequiresAValueOfType = exports.unknownCompilerOption = exports.watchErrorSummary = exports.tstlOptionsAreMovingToTheTstlObject = void 0;
4
4
  const ts = require("typescript");
5
5
  const utils_1 = require("../utils");
6
- exports.tstlOptionsAreMovingToTheTstlObject = utils_1.createSerialDiagnosticFactory((tstl) => ({
6
+ exports.tstlOptionsAreMovingToTheTstlObject = (0, utils_1.createSerialDiagnosticFactory)((tstl) => ({
7
7
  category: ts.DiagnosticCategory.Warning,
8
8
  messageText: 'TSTL options are moving to the "tstl" object. Adjust your tsconfig to look like\n' +
9
9
  `"tstl": ${JSON.stringify(tstl, undefined, 4)}`,
@@ -19,7 +19,7 @@ const watchErrorSummary = (errorCount) => ({
19
19
  : `Found ${errorCount} errors. Watching for file changes.`,
20
20
  });
21
21
  exports.watchErrorSummary = watchErrorSummary;
22
- const createCommandLineError = (code, getMessage) => utils_1.createDiagnosticFactoryWithCode(code, (...args) => ({ messageText: getMessage(...args) }));
22
+ const createCommandLineError = (code, getMessage) => (0, utils_1.createDiagnosticFactoryWithCode)(code, (...args) => ({ messageText: getMessage(...args) }));
23
23
  exports.unknownCompilerOption = createCommandLineError(5023, (name) => `Unknown compiler option '${name}'.`);
24
24
  exports.compilerOptionRequiresAValueOfType = createCommandLineError(5024, (name, type) => `Compiler option '${name}' requires a value of type ${type}.`);
25
25
  exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = createCommandLineError(5042, () => "Option 'project' cannot be mixed with source files on a command line.");
@@ -6,7 +6,7 @@ const prepareDiagnosticForFormatting = (diagnostic) => diagnostic.source === "ty
6
6
  exports.prepareDiagnosticForFormatting = prepareDiagnosticForFormatting;
7
7
  function createDiagnosticReporter(pretty, system = ts.sys) {
8
8
  const reporter = ts.createDiagnosticReporter(system, pretty);
9
- return diagnostic => reporter(exports.prepareDiagnosticForFormatting(diagnostic));
9
+ return diagnostic => reporter((0, exports.prepareDiagnosticForFormatting)(diagnostic));
10
10
  }
11
11
  exports.createDiagnosticReporter = createDiagnosticReporter;
12
12
  //# sourceMappingURL=report.js.map
@@ -12,14 +12,14 @@ function locateConfigFile(commandLine) {
12
12
  if (commandLine.fileNames.length > 0) {
13
13
  return undefined;
14
14
  }
15
- const searchPath = utils_1.normalizeSlashes(process.cwd());
15
+ const searchPath = (0, utils_1.normalizeSlashes)(process.cwd());
16
16
  return ts.findConfigFile(searchPath, ts.sys.fileExists);
17
17
  }
18
18
  if (commandLine.fileNames.length !== 0) {
19
19
  return cliDiagnostics.optionProjectCannotBeMixedWithSourceFilesOnACommandLine();
20
20
  }
21
21
  // TODO: Unlike tsc, this resolves `.` to absolute path
22
- const fileOrDirectory = utils_1.normalizeSlashes(path.resolve(process.cwd(), project));
22
+ const fileOrDirectory = (0, utils_1.normalizeSlashes)(path.resolve(process.cwd(), project));
23
23
  if (ts.sys.directoryExists(fileOrDirectory)) {
24
24
  const configFileName = path.posix.join(fileOrDirectory, "tsconfig.json");
25
25
  if (ts.sys.fileExists(configFileName)) {
@@ -39,7 +39,7 @@ function locateConfigFile(commandLine) {
39
39
  exports.locateConfigFile = locateConfigFile;
40
40
  function parseConfigFileWithSystem(configFileName, commandLineOptions, system = ts.sys) {
41
41
  const parsedConfigFile = ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile(configFileName, system.readFile), system, path.dirname(configFileName), commandLineOptions, configFileName);
42
- return parse_1.updateParsedConfigFile(parsedConfigFile);
42
+ return (0, parse_1.updateParsedConfigFile)(parsedConfigFile);
43
43
  }
44
44
  exports.parseConfigFileWithSystem = parseConfigFileWithSystem;
45
45
  function createConfigFileUpdater(optionsToExtend) {
@@ -49,7 +49,7 @@ function createConfigFileUpdater(optionsToExtend) {
49
49
  if (!configFile || !configFilePath)
50
50
  return [];
51
51
  if (!configFileMap.has(configFile)) {
52
- const parsedConfigFile = parse_1.updateParsedConfigFile(ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configFilePath), optionsToExtend, configFilePath));
52
+ const parsedConfigFile = (0, parse_1.updateParsedConfigFile)(ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configFilePath), optionsToExtend, configFilePath));
53
53
  configFileMap.set(configFile, parsedConfigFile);
54
54
  }
55
55
  const parsedConfigFile = configFileMap.get(configFile);
@@ -2,19 +2,35 @@ function __TS__AsyncAwaiter(generator)
2
2
  return __TS__New(
3
3
  __TS__Promise,
4
4
  function(____, resolve, reject)
5
- local asyncCoroutine, adopt, fulfilled, step
5
+ local adopt, fulfilled, rejected, step, asyncCoroutine
6
6
  function adopt(self, value)
7
7
  return ((__TS__InstanceOf(value, __TS__Promise) and (function() return value end)) or (function() return __TS__Promise.resolve(value) end))()
8
8
  end
9
9
  function fulfilled(self, value)
10
- local success, resultOrError = coroutine.resume(asyncCoroutine, value)
10
+ local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
11
11
  if success then
12
- step(_G, resultOrError)
12
+ step(_G, resultOrError, errorOrErrorHandler)
13
13
  else
14
14
  reject(_G, resultOrError)
15
15
  end
16
16
  end
17
- function step(self, result)
17
+ function rejected(self, handler)
18
+ if handler then
19
+ return function(____, value)
20
+ local success, valueOrError = pcall(handler, value)
21
+ if success then
22
+ step(_G, valueOrError, handler)
23
+ else
24
+ reject(_G, valueOrError)
25
+ end
26
+ end
27
+ else
28
+ return function(____, value)
29
+ reject(_G, value)
30
+ end
31
+ end
32
+ end
33
+ function step(self, result, errorHandler)
18
34
  if coroutine.status(asyncCoroutine) == "dead" then
19
35
  resolve(_G, result)
20
36
  else
@@ -23,21 +39,21 @@ function __TS__AsyncAwaiter(generator)
23
39
  return ____self["then"](
24
40
  ____self,
25
41
  fulfilled,
26
- function(____, reason) return reject(_G, reason) end
42
+ rejected(_G, errorHandler)
27
43
  )
28
44
  end)()
29
45
  end
30
46
  end
31
47
  asyncCoroutine = coroutine.create(generator)
32
- local success, resultOrError = coroutine.resume(asyncCoroutine)
48
+ local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
33
49
  if success then
34
- step(_G, resultOrError)
50
+ step(_G, resultOrError, errorOrErrorHandler)
35
51
  else
36
- reject(_G, resultOrError)
52
+ reject(_G, errorOrErrorHandler)
37
53
  end
38
54
  end
39
55
  )
40
56
  end
41
- function __TS__Await(thing)
42
- return coroutine.yield(thing)
57
+ function __TS__Await(errorHandler, thing)
58
+ return coroutine.yield(errorHandler, thing)
43
59
  end
@@ -28,7 +28,10 @@ function __TS__Promise.prototype.____constructor(self, executor)
28
28
  self.rejectedCallbacks = {}
29
29
  self.finallyCallbacks = {}
30
30
  do
31
- local ____try, e = pcall(
31
+ local function ____catch(e)
32
+ self:reject(e)
33
+ end
34
+ local ____try, ____hasReturned = pcall(
32
35
  function()
33
36
  executor(
34
37
  _G,
@@ -38,7 +41,7 @@ function __TS__Promise.prototype.____constructor(self, executor)
38
41
  end
39
42
  )
40
43
  if not ____try then
41
- self:reject(e)
44
+ ____hasReturned, ____returnValue = ____catch(____hasReturned)
42
45
  end
43
46
  end
44
47
  end
@@ -67,10 +70,12 @@ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
67
70
  local promise = ____.promise
68
71
  local resolve = ____.resolve
69
72
  local reject = ____.reject
73
+ local isFulfilled = self.state == __TS__PromiseState.Fulfilled
74
+ local isRejected = self.state == __TS__PromiseState.Rejected
70
75
  if onFulfilled then
71
76
  local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
72
77
  __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
73
- if self.state == __TS__PromiseState.Fulfilled then
78
+ if isFulfilled then
74
79
  internalCallback(_G, self.value)
75
80
  end
76
81
  else
@@ -82,10 +87,16 @@ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
82
87
  if onRejected then
83
88
  local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
84
89
  __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
85
- if self.state == __TS__PromiseState.Rejected then
90
+ if isRejected then
86
91
  internalCallback(_G, self.rejectionReason)
87
92
  end
88
93
  end
94
+ if isFulfilled then
95
+ resolve(_G, self.value)
96
+ end
97
+ if isRejected then
98
+ reject(_G, self.rejectionReason)
99
+ end
89
100
  return promise
90
101
  end
91
102
  function __TS__Promise.prototype.catch(self, onRejected)
@@ -127,7 +138,10 @@ end
127
138
  function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
128
139
  return function(____, value)
129
140
  do
130
- local ____try, e = pcall(
141
+ local function ____catch(e)
142
+ reject(_G, e)
143
+ end
144
+ local ____try, ____hasReturned = pcall(
131
145
  function()
132
146
  self:handleCallbackData(
133
147
  f(_G, value),
@@ -137,7 +151,7 @@ function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve
137
151
  end
138
152
  )
139
153
  if not ____try then
140
- reject(_G, e)
154
+ ____hasReturned, ____returnValue = ____catch(____hasReturned)
141
155
  end
142
156
  end
143
157
  end
@@ -13,16 +13,26 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
13
13
  if type(trace) ~= "string" then
14
14
  return trace
15
15
  end
16
- local result = string.gsub(
17
- trace,
18
- "(%S+).lua:(%d+)",
19
- function(file, line)
20
- local fileSourceMap = _G.__TS__sourcemap[file .. ".lua"]
21
- if fileSourceMap and fileSourceMap[line] then
22
- return (file .. ".ts:") .. tostring(fileSourceMap[line])
16
+ local function replacer(____, file, srcFile, line)
17
+ local fileSourceMap = _G.__TS__sourcemap[file]
18
+ if fileSourceMap and fileSourceMap[line] then
19
+ local data = fileSourceMap[line]
20
+ if type(data) == "number" then
21
+ return (srcFile .. ":") .. tostring(data)
23
22
  end
24
- return (file .. ".lua:") .. line
23
+ return (tostring(data.file) .. ":") .. tostring(data.line)
25
24
  end
25
+ return (file .. ":") .. line
26
+ end
27
+ local result = string.gsub(
28
+ trace,
29
+ "(%S+)%.lua:(%d+)",
30
+ function(file, line) return replacer(_G, file .. ".lua", file .. ".ts", line) end
31
+ )
32
+ result = string.gsub(
33
+ result,
34
+ "(%[string \"[^\"]+\"%]):(%d+)",
35
+ function(file, line) return replacer(_G, file, "unknown", line) end
26
36
  )
27
37
  return result
28
38
  end
@@ -1,16 +1,11 @@
1
1
  function __TS__StringReplace(source, searchValue, replaceValue)
2
- searchValue = string.gsub(searchValue, "[%%%(%)%.%+%-%*%?%[%^%$]", "%%%1")
3
- if type(replaceValue) == "string" then
4
- replaceValue = string.gsub(replaceValue, "%%", "%%%%")
5
- local result = string.gsub(source, searchValue, replaceValue, 1)
6
- return result
7
- else
8
- local result = string.gsub(
9
- source,
10
- searchValue,
11
- function(match) return replaceValue(_G, match) end,
12
- 1
13
- )
14
- return result
2
+ local startPos, endPos = string.find(source, searchValue, nil, true)
3
+ if not startPos then
4
+ return source
15
5
  end
6
+ local sub = string.sub
7
+ local before = sub(source, 1, startPos - 1)
8
+ local replacement = (((type(replaceValue) == "string") and (function() return replaceValue end)) or (function() return replaceValue(_G, searchValue, startPos - 1, source) end))()
9
+ local after = sub(source, endPos + 1)
10
+ return (before .. replacement) .. after
16
11
  end
@@ -0,0 +1,35 @@
1
+ function __TS__StringReplaceAll(source, searchValue, replaceValue)
2
+ local replacer
3
+ if type(replaceValue) == "string" then
4
+ replacer = function() return replaceValue end
5
+ else
6
+ replacer = replaceValue
7
+ end
8
+ local parts = {}
9
+ local partsIndex = 1
10
+ local sub = string.sub
11
+ if #searchValue == 0 then
12
+ parts[1] = replacer(_G, "", 0, source)
13
+ partsIndex = 2
14
+ for i = 1, #source do
15
+ parts[partsIndex] = sub(source, i, i)
16
+ parts[partsIndex + 1] = replacer(_G, "", i, source)
17
+ partsIndex = partsIndex + 2
18
+ end
19
+ else
20
+ local find = string.find
21
+ local currentPos = 1
22
+ while true do
23
+ local startPos, endPos = find(source, searchValue, currentPos, true)
24
+ if not startPos then
25
+ break
26
+ end
27
+ parts[partsIndex] = sub(source, currentPos, startPos - 1)
28
+ parts[partsIndex + 1] = replacer(_G, searchValue, startPos - 1, source)
29
+ partsIndex = partsIndex + 2
30
+ currentPos = endPos + 1
31
+ end
32
+ parts[partsIndex] = sub(source, currentPos)
33
+ end
34
+ return table.concat(parts)
35
+ end