typescript-to-lua 1.6.1 → 1.7.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 (103) hide show
  1. package/dist/CompilerOptions.d.ts +1 -0
  2. package/dist/LuaPrinter.js +1 -0
  3. package/dist/cli/diagnostics.d.ts +3 -0
  4. package/dist/cli/diagnostics.js +2 -1
  5. package/dist/cli/parse.d.ts +1 -1
  6. package/dist/cli/parse.js +47 -11
  7. package/dist/lualib/ArraySlice.lua +10 -2
  8. package/dist/lualib/ArraySplice.lua +5 -1
  9. package/dist/lualib/Generator.lua +8 -1
  10. package/dist/lualib/ParseFloat.lua +5 -1
  11. package/dist/lualib/Promise.lua +6 -3
  12. package/dist/lualib/SparseArraySpread.lua +5 -1
  13. package/dist/lualib/StringCharCodeAt.lua +5 -1
  14. package/dist/lualib/lualib_bundle.lua +44 -10
  15. package/dist/lualib-build/plugin.js +1 -2
  16. package/dist/measure-performance.d.ts +15 -0
  17. package/dist/measure-performance.js +83 -0
  18. package/dist/transformation/builtins/array.js +2 -1
  19. package/dist/transformation/builtins/function.js +1 -1
  20. package/dist/transformation/builtins/global.d.ts +1 -1
  21. package/dist/transformation/builtins/global.js +13 -12
  22. package/dist/transformation/builtins/index.d.ts +2 -2
  23. package/dist/transformation/builtins/index.js +87 -89
  24. package/dist/transformation/builtins/object.d.ts +1 -1
  25. package/dist/transformation/builtins/object.js +4 -4
  26. package/dist/transformation/builtins/promise.js +4 -2
  27. package/dist/transformation/builtins/string.js +2 -0
  28. package/dist/transformation/context/context.d.ts +15 -0
  29. package/dist/transformation/context/context.js +66 -24
  30. package/dist/transformation/context/visitors.d.ts +1 -1
  31. package/dist/transformation/index.js +6 -5
  32. package/dist/transformation/utils/annotations.d.ts +1 -17
  33. package/dist/transformation/utils/annotations.js +48 -88
  34. package/dist/transformation/utils/assignment-validation.js +27 -23
  35. package/dist/transformation/utils/diagnostics.d.ts +1 -4
  36. package/dist/transformation/utils/diagnostics.js +2 -3
  37. package/dist/transformation/utils/function-context.d.ts +1 -1
  38. package/dist/transformation/utils/function-context.js +57 -51
  39. package/dist/transformation/utils/language-extensions.d.ts +57 -51
  40. package/dist/transformation/utils/language-extensions.js +99 -119
  41. package/dist/transformation/utils/lualib.d.ts +0 -1
  42. package/dist/transformation/utils/lualib.js +2 -8
  43. package/dist/transformation/utils/safe-names.d.ts +1 -1
  44. package/dist/transformation/utils/safe-names.js +3 -6
  45. package/dist/transformation/utils/scope.d.ts +0 -2
  46. package/dist/transformation/utils/scope.js +10 -27
  47. package/dist/transformation/utils/symbols.d.ts +1 -1
  48. package/dist/transformation/utils/symbols.js +7 -20
  49. package/dist/transformation/utils/typescript/index.d.ts +1 -0
  50. package/dist/transformation/utils/typescript/index.js +2 -1
  51. package/dist/transformation/utils/typescript/types.d.ts +2 -5
  52. package/dist/transformation/utils/typescript/types.js +27 -37
  53. package/dist/transformation/visitors/access.js +1 -4
  54. package/dist/transformation/visitors/block.js +4 -4
  55. package/dist/transformation/visitors/call.js +7 -18
  56. package/dist/transformation/visitors/class/index.js +8 -20
  57. package/dist/transformation/visitors/class/members/constructor.js +2 -2
  58. package/dist/transformation/visitors/class/new.js +2 -5
  59. package/dist/transformation/visitors/class/setup.d.ts +1 -1
  60. package/dist/transformation/visitors/class/setup.js +4 -4
  61. package/dist/transformation/visitors/class/utils.d.ts +1 -1
  62. package/dist/transformation/visitors/class/utils.js +2 -9
  63. package/dist/transformation/visitors/conditional.js +4 -4
  64. package/dist/transformation/visitors/function.d.ts +1 -1
  65. package/dist/transformation/visitors/function.js +8 -16
  66. package/dist/transformation/visitors/identifier.d.ts +1 -0
  67. package/dist/transformation/visitors/identifier.js +40 -44
  68. package/dist/transformation/visitors/language-extensions/call-extension.d.ts +10 -0
  69. package/dist/transformation/visitors/language-extensions/call-extension.js +23 -0
  70. package/dist/transformation/visitors/language-extensions/identifier.d.ts +5 -0
  71. package/dist/transformation/visitors/language-extensions/identifier.js +27 -0
  72. package/dist/transformation/visitors/language-extensions/iterable.d.ts +2 -3
  73. package/dist/transformation/visitors/language-extensions/iterable.js +21 -22
  74. package/dist/transformation/visitors/language-extensions/multi.d.ts +0 -1
  75. package/dist/transformation/visitors/language-extensions/multi.js +10 -24
  76. package/dist/transformation/visitors/language-extensions/operators.d.ts +2 -5
  77. package/dist/transformation/visitors/language-extensions/operators.js +89 -96
  78. package/dist/transformation/visitors/language-extensions/range.js +4 -2
  79. package/dist/transformation/visitors/language-extensions/table.d.ts +6 -3
  80. package/dist/transformation/visitors/language-extensions/table.js +46 -75
  81. package/dist/transformation/visitors/language-extensions/vararg.js +7 -3
  82. package/dist/transformation/visitors/literal.js +2 -23
  83. package/dist/transformation/visitors/loops/for-of.js +18 -18
  84. package/dist/transformation/visitors/loops/utils.js +5 -5
  85. package/dist/transformation/visitors/namespace.js +5 -14
  86. package/dist/transformation/visitors/return.js +2 -3
  87. package/dist/transformation/visitors/sourceFile.js +3 -4
  88. package/dist/transformation/visitors/spread.js +0 -5
  89. package/dist/transformation/visitors/switch.js +2 -2
  90. package/dist/transformation/visitors/variable-declaration.js +1 -1
  91. package/dist/transpilation/index.js +4 -8
  92. package/dist/transpilation/plugins.js +3 -0
  93. package/dist/transpilation/resolve.js +144 -161
  94. package/dist/transpilation/transpile.js +10 -0
  95. package/dist/transpilation/transpiler.d.ts +1 -0
  96. package/dist/transpilation/transpiler.js +18 -5
  97. package/dist/tstl.js +23 -4
  98. package/language-extensions/index.d.ts +156 -67
  99. package/package.json +2 -2
  100. package/dist/transformation/visitors/language-extensions/index.d.ts +0 -4
  101. package/dist/transformation/visitors/language-extensions/index.js +0 -17
  102. package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +0 -5
  103. package/dist/transformation/visitors/language-extensions/pairsIterable.js +0 -53
@@ -1,131 +1,111 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isExtensionValue = exports.getExtensionKinds = exports.isExtensionType = exports.ExtensionKind = void 0;
3
+ exports.getIterableExtensionKindForNode = exports.getIterableExtensionTypeForType = exports.IterableExtensionKind = exports.getExtensionKindForSymbol = exports.getExtensionKindForNode = exports.getExtensionKindForType = exports.ExtensionKind = void 0;
4
+ const ts = require("typescript");
4
5
  var ExtensionKind;
5
6
  (function (ExtensionKind) {
6
7
  ExtensionKind["MultiFunction"] = "MultiFunction";
7
- ExtensionKind["MultiType"] = "MultiType";
8
8
  ExtensionKind["RangeFunction"] = "RangeFunction";
9
9
  ExtensionKind["VarargConstant"] = "VarargConstant";
10
- ExtensionKind["IterableType"] = "IterableType";
11
- ExtensionKind["PairsIterableType"] = "PairsIterableType";
12
- ExtensionKind["AdditionOperatorType"] = "AdditionOperatorType";
13
- ExtensionKind["AdditionOperatorMethodType"] = "AdditionOperatorMethodType";
14
- ExtensionKind["SubtractionOperatorType"] = "SubtractionOperatorType";
15
- ExtensionKind["SubtractionOperatorMethodType"] = "SubtractionOperatorMethodType";
16
- ExtensionKind["MultiplicationOperatorType"] = "MultiplicationOperatorType";
17
- ExtensionKind["MultiplicationOperatorMethodType"] = "MultiplicationOperatorMethodType";
18
- ExtensionKind["DivisionOperatorType"] = "DivisionOperatorType";
19
- ExtensionKind["DivisionOperatorMethodType"] = "DivisionOperatorMethodType";
20
- ExtensionKind["ModuloOperatorType"] = "ModuloOperatorType";
21
- ExtensionKind["ModuloOperatorMethodType"] = "ModuloOperatorMethodType";
22
- ExtensionKind["PowerOperatorType"] = "PowerOperatorType";
23
- ExtensionKind["PowerOperatorMethodType"] = "PowerOperatorMethodType";
24
- ExtensionKind["FloorDivisionOperatorType"] = "FloorDivisionOperatorType";
25
- ExtensionKind["FloorDivisionOperatorMethodType"] = "FloorDivisionOperatorMethodType";
26
- ExtensionKind["BitwiseAndOperatorType"] = "BitwiseAndOperatorType";
27
- ExtensionKind["BitwiseAndOperatorMethodType"] = "BitwiseAndOperatorMethodType";
28
- ExtensionKind["BitwiseOrOperatorType"] = "BitwiseOrOperatorType";
29
- ExtensionKind["BitwiseOrOperatorMethodType"] = "BitwiseOrOperatorMethodType";
30
- ExtensionKind["BitwiseExclusiveOrOperatorType"] = "BitwiseExclusiveOrOperatorType";
31
- ExtensionKind["BitwiseExclusiveOrOperatorMethodType"] = "BitwiseExclusiveOrOperatorMethodType";
32
- ExtensionKind["BitwiseLeftShiftOperatorType"] = "BitwiseLeftShiftOperatorType";
33
- ExtensionKind["BitwiseLeftShiftOperatorMethodType"] = "BitwiseLeftShiftOperatorMethodType";
34
- ExtensionKind["BitwiseRightShiftOperatorType"] = "BitwiseRightShiftOperatorType";
35
- ExtensionKind["BitwiseRightShiftOperatorMethodType"] = "BitwiseRightShiftOperatorMethodType";
36
- ExtensionKind["ConcatOperatorType"] = "ConcatOperatorType";
37
- ExtensionKind["ConcatOperatorMethodType"] = "ConcatOperatorMethodType";
38
- ExtensionKind["LessThanOperatorType"] = "LessThanOperatorType";
39
- ExtensionKind["LessThanOperatorMethodType"] = "LessThanOperatorMethodType";
40
- ExtensionKind["GreaterThanOperatorType"] = "GreaterThanOperatorType";
41
- ExtensionKind["GreaterThanOperatorMethodType"] = "GreaterThanOperatorMethodType";
42
- ExtensionKind["NegationOperatorType"] = "NegationOperatorType";
43
- ExtensionKind["NegationOperatorMethodType"] = "NegationOperatorMethodType";
44
- ExtensionKind["BitwiseNotOperatorType"] = "BitwiseNotOperatorType";
45
- ExtensionKind["BitwiseNotOperatorMethodType"] = "BitwiseNotOperatorMethodType";
46
- ExtensionKind["LengthOperatorType"] = "LengthOperatorType";
47
- ExtensionKind["LengthOperatorMethodType"] = "LengthOperatorMethodType";
48
- ExtensionKind["TableNewType"] = "TableNewType";
49
- ExtensionKind["TableDeleteType"] = "TableDeleteType";
50
- ExtensionKind["TableDeleteMethodType"] = "TableDeleteMethodType";
51
- ExtensionKind["TableGetType"] = "TableGetType";
52
- ExtensionKind["TableGetMethodType"] = "TableGetMethodType";
53
- ExtensionKind["TableHasType"] = "TableHasType";
54
- ExtensionKind["TableHasMethodType"] = "TableHasMethodType";
55
- ExtensionKind["TableSetType"] = "TableSetType";
56
- ExtensionKind["TableSetMethodType"] = "TableSetMethodType";
10
+ ExtensionKind["AdditionOperatorType"] = "Addition";
11
+ ExtensionKind["AdditionOperatorMethodType"] = "AdditionMethod";
12
+ ExtensionKind["SubtractionOperatorType"] = "Subtraction";
13
+ ExtensionKind["SubtractionOperatorMethodType"] = "SubtractionMethod";
14
+ ExtensionKind["MultiplicationOperatorType"] = "Multiplication";
15
+ ExtensionKind["MultiplicationOperatorMethodType"] = "MultiplicationMethod";
16
+ ExtensionKind["DivisionOperatorType"] = "Division";
17
+ ExtensionKind["DivisionOperatorMethodType"] = "DivisionMethod";
18
+ ExtensionKind["ModuloOperatorType"] = "Modulo";
19
+ ExtensionKind["ModuloOperatorMethodType"] = "ModuloMethod";
20
+ ExtensionKind["PowerOperatorType"] = "Power";
21
+ ExtensionKind["PowerOperatorMethodType"] = "PowerMethod";
22
+ ExtensionKind["FloorDivisionOperatorType"] = "FloorDivision";
23
+ ExtensionKind["FloorDivisionOperatorMethodType"] = "FloorDivisionMethod";
24
+ ExtensionKind["BitwiseAndOperatorType"] = "BitwiseAnd";
25
+ ExtensionKind["BitwiseAndOperatorMethodType"] = "BitwiseAndMethod";
26
+ ExtensionKind["BitwiseOrOperatorType"] = "BitwiseOr";
27
+ ExtensionKind["BitwiseOrOperatorMethodType"] = "BitwiseOrMethod";
28
+ ExtensionKind["BitwiseExclusiveOrOperatorType"] = "BitwiseExclusiveOr";
29
+ ExtensionKind["BitwiseExclusiveOrOperatorMethodType"] = "BitwiseExclusiveOrMethod";
30
+ ExtensionKind["BitwiseLeftShiftOperatorType"] = "BitwiseLeftShift";
31
+ ExtensionKind["BitwiseLeftShiftOperatorMethodType"] = "BitwiseLeftShiftMethod";
32
+ ExtensionKind["BitwiseRightShiftOperatorType"] = "BitwiseRightShift";
33
+ ExtensionKind["BitwiseRightShiftOperatorMethodType"] = "BitwiseRightShiftMethod";
34
+ ExtensionKind["ConcatOperatorType"] = "Concat";
35
+ ExtensionKind["ConcatOperatorMethodType"] = "ConcatMethod";
36
+ ExtensionKind["LessThanOperatorType"] = "LessThan";
37
+ ExtensionKind["LessThanOperatorMethodType"] = "LessThanMethod";
38
+ ExtensionKind["GreaterThanOperatorType"] = "GreaterThan";
39
+ ExtensionKind["GreaterThanOperatorMethodType"] = "GreaterThanMethod";
40
+ ExtensionKind["NegationOperatorType"] = "Negation";
41
+ ExtensionKind["NegationOperatorMethodType"] = "NegationMethod";
42
+ ExtensionKind["BitwiseNotOperatorType"] = "BitwiseNot";
43
+ ExtensionKind["BitwiseNotOperatorMethodType"] = "BitwiseNotMethod";
44
+ ExtensionKind["LengthOperatorType"] = "Length";
45
+ ExtensionKind["LengthOperatorMethodType"] = "LengthMethod";
46
+ ExtensionKind["TableNewType"] = "TableNew";
47
+ ExtensionKind["TableDeleteType"] = "TableDelete";
48
+ ExtensionKind["TableDeleteMethodType"] = "TableDeleteMethod";
49
+ ExtensionKind["TableGetType"] = "TableGet";
50
+ ExtensionKind["TableGetMethodType"] = "TableGetMethod";
51
+ ExtensionKind["TableHasType"] = "TableHas";
52
+ ExtensionKind["TableHasMethodType"] = "TableHasMethod";
53
+ ExtensionKind["TableSetType"] = "TableSet";
54
+ ExtensionKind["TableSetMethodType"] = "TableSetMethod";
55
+ ExtensionKind["TableAddKeyType"] = "TableAddKey";
56
+ ExtensionKind["TableAddKeyMethodType"] = "TableAddKeyMethod";
57
57
  })(ExtensionKind = exports.ExtensionKind || (exports.ExtensionKind = {}));
58
- const extensionKindToValueName = {
59
- [ExtensionKind.MultiFunction]: "$multi",
60
- [ExtensionKind.RangeFunction]: "$range",
61
- [ExtensionKind.VarargConstant]: "$vararg",
62
- };
63
- const extensionKindToTypeBrand = {
64
- [ExtensionKind.MultiFunction]: "__luaMultiFunctionBrand",
65
- [ExtensionKind.MultiType]: "__luaMultiReturnBrand",
66
- [ExtensionKind.RangeFunction]: "__luaRangeFunctionBrand",
67
- [ExtensionKind.VarargConstant]: "__luaVarargConstantBrand",
68
- [ExtensionKind.IterableType]: "__luaIterableBrand",
69
- [ExtensionKind.PairsIterableType]: "__luaPairsIterableBrand",
70
- [ExtensionKind.AdditionOperatorType]: "__luaAdditionBrand",
71
- [ExtensionKind.AdditionOperatorMethodType]: "__luaAdditionMethodBrand",
72
- [ExtensionKind.SubtractionOperatorType]: "__luaSubtractionBrand",
73
- [ExtensionKind.SubtractionOperatorMethodType]: "__luaSubtractionMethodBrand",
74
- [ExtensionKind.MultiplicationOperatorType]: "__luaMultiplicationBrand",
75
- [ExtensionKind.MultiplicationOperatorMethodType]: "__luaMultiplicationMethodBrand",
76
- [ExtensionKind.DivisionOperatorType]: "__luaDivisionBrand",
77
- [ExtensionKind.DivisionOperatorMethodType]: "__luaDivisionMethodBrand",
78
- [ExtensionKind.ModuloOperatorType]: "__luaModuloBrand",
79
- [ExtensionKind.ModuloOperatorMethodType]: "__luaModuloMethodBrand",
80
- [ExtensionKind.PowerOperatorType]: "__luaPowerBrand",
81
- [ExtensionKind.PowerOperatorMethodType]: "__luaPowerMethodBrand",
82
- [ExtensionKind.FloorDivisionOperatorType]: "__luaFloorDivisionBrand",
83
- [ExtensionKind.FloorDivisionOperatorMethodType]: "__luaFloorDivisionMethodBrand",
84
- [ExtensionKind.BitwiseAndOperatorType]: "__luaBitwiseAndBrand",
85
- [ExtensionKind.BitwiseAndOperatorMethodType]: "__luaBitwiseAndMethodBrand",
86
- [ExtensionKind.BitwiseOrOperatorType]: "__luaBitwiseOrBrand",
87
- [ExtensionKind.BitwiseOrOperatorMethodType]: "__luaBitwiseOrMethodBrand",
88
- [ExtensionKind.BitwiseExclusiveOrOperatorType]: "__luaBitwiseExclusiveOrBrand",
89
- [ExtensionKind.BitwiseExclusiveOrOperatorMethodType]: "__luaBitwiseExclusiveOrMethodBrand",
90
- [ExtensionKind.BitwiseLeftShiftOperatorType]: "__luaBitwiseLeftShiftBrand",
91
- [ExtensionKind.BitwiseLeftShiftOperatorMethodType]: "__luaBitwiseLeftShiftMethodBrand",
92
- [ExtensionKind.BitwiseRightShiftOperatorType]: "__luaBitwiseRightShiftBrand",
93
- [ExtensionKind.BitwiseRightShiftOperatorMethodType]: "__luaBitwiseRightShiftMethodBrand",
94
- [ExtensionKind.ConcatOperatorType]: "__luaConcatBrand",
95
- [ExtensionKind.ConcatOperatorMethodType]: "__luaConcatMethodBrand",
96
- [ExtensionKind.LessThanOperatorType]: "__luaLessThanBrand",
97
- [ExtensionKind.LessThanOperatorMethodType]: "__luaLessThanMethodBrand",
98
- [ExtensionKind.GreaterThanOperatorType]: "__luaGreaterThanBrand",
99
- [ExtensionKind.GreaterThanOperatorMethodType]: "__luaGreaterThanMethodBrand",
100
- [ExtensionKind.NegationOperatorType]: "__luaNegationBrand",
101
- [ExtensionKind.NegationOperatorMethodType]: "__luaNegationMethodBrand",
102
- [ExtensionKind.BitwiseNotOperatorType]: "__luaBitwiseNotBrand",
103
- [ExtensionKind.BitwiseNotOperatorMethodType]: "__luaBitwiseNotMethodBrand",
104
- [ExtensionKind.LengthOperatorType]: "__luaLengthBrand",
105
- [ExtensionKind.LengthOperatorMethodType]: "__luaLengthMethodBrand",
106
- [ExtensionKind.TableNewType]: "__luaTableNewBrand",
107
- [ExtensionKind.TableDeleteType]: "__luaTableDeleteBrand",
108
- [ExtensionKind.TableDeleteMethodType]: "__luaTableDeleteMethodBrand",
109
- [ExtensionKind.TableGetType]: "__luaTableGetBrand",
110
- [ExtensionKind.TableGetMethodType]: "__luaTableGetMethodBrand",
111
- [ExtensionKind.TableHasType]: "__luaTableHasBrand",
112
- [ExtensionKind.TableHasMethodType]: "__luaTableHasMethodBrand",
113
- [ExtensionKind.TableSetType]: "__luaTableSetBrand",
114
- [ExtensionKind.TableSetMethodType]: "__luaTableSetMethodBrand",
115
- };
116
- function isExtensionType(type, extensionKind) {
117
- const typeBrand = extensionKindToTypeBrand[extensionKind];
118
- return typeBrand !== undefined && type.getProperty(typeBrand) !== undefined;
58
+ const extensionValues = new Set(Object.values(ExtensionKind));
59
+ function getExtensionKindForType(context, type) {
60
+ const value = getPropertyValue(context, type, "__tstlExtension");
61
+ if (value && extensionValues.has(value)) {
62
+ return value;
63
+ }
119
64
  }
120
- exports.isExtensionType = isExtensionType;
121
- function getExtensionKinds(type) {
122
- return Object.keys(extensionKindToTypeBrand).filter(e => type.getProperty(extensionKindToTypeBrand[e]) !== undefined);
65
+ exports.getExtensionKindForType = getExtensionKindForType;
66
+ const excludedTypeFlags = ((1 << 18) - 1) | // All flags from Any...Never
67
+ ts.TypeFlags.Index |
68
+ ts.TypeFlags.NonPrimitive;
69
+ function getPropertyValue(context, type, propertyName) {
70
+ if (type.flags & excludedTypeFlags)
71
+ return;
72
+ const property = type.getProperty(propertyName);
73
+ if (!property)
74
+ return undefined;
75
+ const propertyType = context.checker.getTypeOfSymbolAtLocation(property, context.sourceFile);
76
+ if (propertyType.isStringLiteral())
77
+ return propertyType.value;
123
78
  }
124
- exports.getExtensionKinds = getExtensionKinds;
125
- function isExtensionValue(context, symbol, extensionKind) {
126
- var _a;
127
- return (symbol.getName() === extensionKindToValueName[extensionKind] &&
128
- ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => isExtensionType(context.checker.getTypeAtLocation(d), extensionKind))) === true);
79
+ function getExtensionKindForNode(context, node) {
80
+ const originalNode = ts.getOriginalNode(node);
81
+ let type = context.checker.getTypeAtLocation(originalNode);
82
+ if (ts.isOptionalChain(originalNode)) {
83
+ type = context.checker.getNonNullableType(type);
84
+ }
85
+ return getExtensionKindForType(context, type);
129
86
  }
130
- exports.isExtensionValue = isExtensionValue;
87
+ exports.getExtensionKindForNode = getExtensionKindForNode;
88
+ function getExtensionKindForSymbol(context, symbol) {
89
+ const type = context.checker.getTypeOfSymbolAtLocation(symbol, context.sourceFile);
90
+ return getExtensionKindForType(context, type);
91
+ }
92
+ exports.getExtensionKindForSymbol = getExtensionKindForSymbol;
93
+ var IterableExtensionKind;
94
+ (function (IterableExtensionKind) {
95
+ IterableExtensionKind["Iterable"] = "Iterable";
96
+ IterableExtensionKind["Pairs"] = "Pairs";
97
+ IterableExtensionKind["PairsKey"] = "PairsKey";
98
+ })(IterableExtensionKind = exports.IterableExtensionKind || (exports.IterableExtensionKind = {}));
99
+ function getIterableExtensionTypeForType(context, type) {
100
+ const value = getPropertyValue(context, type, "__tstlIterable");
101
+ if (value && value in IterableExtensionKind) {
102
+ return value;
103
+ }
104
+ }
105
+ exports.getIterableExtensionTypeForType = getIterableExtensionTypeForType;
106
+ function getIterableExtensionKindForNode(context, node) {
107
+ const type = context.checker.getTypeAtLocation(node);
108
+ return getIterableExtensionTypeForType(context, type);
109
+ }
110
+ exports.getIterableExtensionKindForNode = getIterableExtensionKindForNode;
131
111
  //# sourceMappingURL=language-extensions.js.map
@@ -3,6 +3,5 @@ import * as lua from "../../LuaAST";
3
3
  import { LuaLibFeature } from "../../LuaLib";
4
4
  import { TransformationContext } from "../context";
5
5
  export { LuaLibFeature };
6
- export declare function getUsedLuaLibFeatures(context: TransformationContext): Set<LuaLibFeature>;
7
6
  export declare function importLuaLibFeature(context: TransformationContext, feature: LuaLibFeature): void;
8
7
  export declare function transformLuaLibFunction(context: TransformationContext, feature: LuaLibFeature, tsParent?: ts.Node, ...params: lua.Expression[]): lua.CallExpression;
@@ -1,17 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformLuaLibFunction = exports.importLuaLibFeature = exports.getUsedLuaLibFeatures = exports.LuaLibFeature = void 0;
3
+ exports.transformLuaLibFunction = exports.importLuaLibFeature = exports.LuaLibFeature = void 0;
4
4
  const lua = require("../../LuaAST");
5
5
  const LuaLib_1 = require("../../LuaLib");
6
6
  Object.defineProperty(exports, "LuaLibFeature", { enumerable: true, get: function () { return LuaLib_1.LuaLibFeature; } });
7
- const utils_1 = require("../../utils");
8
- const luaLibFeatures = new WeakMap();
9
- function getUsedLuaLibFeatures(context) {
10
- return (0, utils_1.getOrUpdate)(luaLibFeatures, context, () => new Set());
11
- }
12
- exports.getUsedLuaLibFeatures = getUsedLuaLibFeatures;
13
7
  function importLuaLibFeature(context, feature) {
14
- getUsedLuaLibFeatures(context).add(feature);
8
+ context.usedLuaLibFeatures.add(feature);
15
9
  }
16
10
  exports.importLuaLibFeature = importLuaLibFeature;
17
11
  function transformLuaLibFunction(context, feature, tsParent, ...params) {
@@ -6,5 +6,5 @@ export declare const isValidLuaIdentifier: (name: string, options: CompilerOptio
6
6
  export declare const luaKeywords: ReadonlySet<string>;
7
7
  export declare const isUnsafeName: (name: string, options: CompilerOptions) => boolean;
8
8
  export declare function hasUnsafeSymbolName(context: TransformationContext, symbol: ts.Symbol, tsOriginal: ts.Identifier): boolean;
9
- export declare function hasUnsafeIdentifierName(context: TransformationContext, identifier: ts.Identifier, checkSymbol?: boolean): boolean;
9
+ export declare function hasUnsafeIdentifierName(context: TransformationContext, identifier: ts.Identifier, symbol: ts.Symbol | undefined): boolean;
10
10
  export declare const createSafeName: (name: string) => string;
@@ -80,12 +80,9 @@ function hasUnsafeSymbolName(context, symbol, tsOriginal) {
80
80
  return (0, exports.isUnsafeName)(symbol.name, context.options) && !isAmbient && !(0, export_1.isSymbolExported)(context, symbol);
81
81
  }
82
82
  exports.hasUnsafeSymbolName = hasUnsafeSymbolName;
83
- function hasUnsafeIdentifierName(context, identifier, checkSymbol = true) {
84
- if (checkSymbol) {
85
- const symbol = context.checker.getSymbolAtLocation(identifier);
86
- if (symbol) {
87
- return hasUnsafeSymbolName(context, symbol, identifier);
88
- }
83
+ function hasUnsafeIdentifierName(context, identifier, symbol) {
84
+ if (symbol) {
85
+ return hasUnsafeSymbolName(context, symbol, identifier);
89
86
  }
90
87
  return checkName(context, identifier.text, identifier);
91
88
  }
@@ -36,8 +36,6 @@ export declare function walkScopesUp(context: TransformationContext): IterableIt
36
36
  export declare function markSymbolAsReferencedInCurrentScopes(context: TransformationContext, symbolId: lua.SymbolId, identifier: ts.Identifier): void;
37
37
  export declare function peekScope(context: TransformationContext): Scope;
38
38
  export declare function findScope(context: TransformationContext, scopeTypes: ScopeType): Scope | undefined;
39
- export declare function pushScope(context: TransformationContext, scopeType: ScopeType): Scope;
40
- export declare function popScope(context: TransformationContext): Scope;
41
39
  export declare function addScopeVariableDeclaration(scope: Scope, declaration: lua.VariableDeclarationStatement): void;
42
40
  export declare function hasReferencedUndefinedLocalFunction(context: TransformationContext, scope: Scope): boolean;
43
41
  export declare function hasReferencedSymbol(context: TransformationContext, scope: Scope, symbol: ts.Symbol): boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.performHoisting = exports.separateHoistedStatements = exports.isFunctionScopeWithDefinition = exports.hasReferencedSymbol = exports.hasReferencedUndefinedLocalFunction = exports.addScopeVariableDeclaration = exports.popScope = exports.pushScope = exports.findScope = exports.peekScope = exports.markSymbolAsReferencedInCurrentScopes = exports.walkScopesUp = exports.ScopeType = void 0;
3
+ exports.performHoisting = exports.separateHoistedStatements = exports.isFunctionScopeWithDefinition = exports.hasReferencedSymbol = exports.hasReferencedUndefinedLocalFunction = exports.addScopeVariableDeclaration = exports.findScope = exports.peekScope = exports.markSymbolAsReferencedInCurrentScopes = exports.walkScopesUp = exports.ScopeType = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../LuaAST");
6
6
  const utils_1 = require("../../utils");
@@ -18,12 +18,8 @@ var ScopeType;
18
18
  ScopeType[ScopeType["Catch"] = 128] = "Catch";
19
19
  ScopeType[ScopeType["LoopInitializer"] = 256] = "LoopInitializer";
20
20
  })(ScopeType = exports.ScopeType || (exports.ScopeType = {}));
21
- const scopeStacks = new WeakMap();
22
- function getScopeStack(context) {
23
- return (0, utils_1.getOrUpdate)(scopeStacks, context, () => []);
24
- }
25
21
  function* walkScopesUp(context) {
26
- const scopeStack = getScopeStack(context);
22
+ const scopeStack = context.scopeStack;
27
23
  for (let i = scopeStack.length - 1; i >= 0; --i) {
28
24
  const scope = scopeStack[i];
29
25
  yield scope;
@@ -31,7 +27,7 @@ function* walkScopesUp(context) {
31
27
  }
32
28
  exports.walkScopesUp = walkScopesUp;
33
29
  function markSymbolAsReferencedInCurrentScopes(context, symbolId, identifier) {
34
- for (const scope of getScopeStack(context)) {
30
+ for (const scope of context.scopeStack) {
35
31
  if (!scope.referencedSymbols) {
36
32
  scope.referencedSymbols = new Map();
37
33
  }
@@ -41,34 +37,21 @@ function markSymbolAsReferencedInCurrentScopes(context, symbolId, identifier) {
41
37
  }
42
38
  exports.markSymbolAsReferencedInCurrentScopes = markSymbolAsReferencedInCurrentScopes;
43
39
  function peekScope(context) {
44
- const scopeStack = getScopeStack(context);
40
+ const scopeStack = context.scopeStack;
45
41
  const scope = scopeStack[scopeStack.length - 1];
46
42
  (0, utils_1.assert)(scope);
47
43
  return scope;
48
44
  }
49
45
  exports.peekScope = peekScope;
50
46
  function findScope(context, scopeTypes) {
51
- return [...getScopeStack(context)].reverse().find(s => scopeTypes & s.type);
47
+ for (let i = context.scopeStack.length - 1; i >= 0; --i) {
48
+ const scope = context.scopeStack[i];
49
+ if (scopeTypes & scope.type) {
50
+ return scope;
51
+ }
52
+ }
52
53
  }
53
54
  exports.findScope = findScope;
54
- const scopeIdCounters = new WeakMap();
55
- function pushScope(context, scopeType) {
56
- var _a;
57
- const nextScopeId = ((_a = scopeIdCounters.get(context)) !== null && _a !== void 0 ? _a : 0) + 1;
58
- scopeIdCounters.set(context, nextScopeId);
59
- const scopeStack = getScopeStack(context);
60
- const scope = { type: scopeType, id: nextScopeId };
61
- scopeStack.push(scope);
62
- return scope;
63
- }
64
- exports.pushScope = pushScope;
65
- function popScope(context) {
66
- const scopeStack = getScopeStack(context);
67
- const scope = scopeStack.pop();
68
- (0, utils_1.assert)(scope);
69
- return scope;
70
- }
71
- exports.popScope = popScope;
72
55
  function addScopeVariableDeclaration(scope, declaration) {
73
56
  if (!scope.variableDeclarations) {
74
57
  scope.variableDeclarations = [];
@@ -8,4 +8,4 @@ export interface SymbolInfo {
8
8
  export declare function getSymbolInfo(context: TransformationContext, symbolId: lua.SymbolId): SymbolInfo | undefined;
9
9
  export declare function getSymbolIdOfSymbol(context: TransformationContext, symbol: ts.Symbol): lua.SymbolId | undefined;
10
10
  export declare function trackSymbolReference(context: TransformationContext, symbol: ts.Symbol, identifier: ts.Identifier): lua.SymbolId | undefined;
11
- export declare function getIdentifierSymbolId(context: TransformationContext, identifier: ts.Identifier): lua.SymbolId | undefined;
11
+ export declare function getIdentifierSymbolId(context: TransformationContext, identifier: ts.Identifier, symbol: ts.Symbol | undefined): lua.SymbolId | undefined;
@@ -1,35 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIdentifierSymbolId = exports.trackSymbolReference = exports.getSymbolIdOfSymbol = exports.getSymbolInfo = void 0;
4
- const utils_1 = require("../../utils");
5
4
  const spread_1 = require("../visitors/spread");
6
5
  const scope_1 = require("./scope");
7
- const symbolIdCounters = new WeakMap();
8
- function nextSymbolId(context) {
9
- var _a;
10
- const symbolId = ((_a = symbolIdCounters.get(context)) !== null && _a !== void 0 ? _a : 0) + 1;
11
- symbolIdCounters.set(context, symbolId);
12
- return symbolId;
13
- }
14
- const symbolInfoMap = new WeakMap();
15
- const symbolIdMaps = new WeakMap();
16
6
  function getSymbolInfo(context, symbolId) {
17
- return (0, utils_1.getOrUpdate)(symbolInfoMap, context, () => new Map()).get(symbolId);
7
+ return context.symbolInfoMap.get(symbolId);
18
8
  }
19
9
  exports.getSymbolInfo = getSymbolInfo;
20
10
  function getSymbolIdOfSymbol(context, symbol) {
21
- return (0, utils_1.getOrUpdate)(symbolIdMaps, context, () => new Map()).get(symbol);
11
+ return context.symbolIdMaps.get(symbol);
22
12
  }
23
13
  exports.getSymbolIdOfSymbol = getSymbolIdOfSymbol;
24
14
  function trackSymbolReference(context, symbol, identifier) {
25
- const symbolIds = (0, utils_1.getOrUpdate)(symbolIdMaps, context, () => new Map());
26
15
  // Track first time symbols are seen
27
- let symbolId = symbolIds.get(symbol);
16
+ let symbolId = context.symbolIdMaps.get(symbol);
28
17
  if (symbolId === undefined) {
29
- symbolId = nextSymbolId(context);
30
- symbolIds.set(symbol, symbolId);
31
- const symbolInfo = (0, utils_1.getOrUpdate)(symbolInfoMap, context, () => new Map());
32
- symbolInfo.set(symbolId, { symbol, firstSeenAtPos: identifier.pos });
18
+ symbolId = context.nextSymbolId();
19
+ context.symbolIdMaps.set(symbol, symbolId);
20
+ context.symbolInfoMap.set(symbolId, { symbol, firstSeenAtPos: identifier.pos });
33
21
  }
34
22
  // If isOptimizedVarArgSpread returns true, the identifier will not appear in the resulting Lua.
35
23
  // Only the optimized ellipses (...) will be used.
@@ -39,8 +27,7 @@ function trackSymbolReference(context, symbol, identifier) {
39
27
  return symbolId;
40
28
  }
41
29
  exports.trackSymbolReference = trackSymbolReference;
42
- function getIdentifierSymbolId(context, identifier) {
43
- const symbol = context.checker.getSymbolAtLocation(identifier);
30
+ function getIdentifierSymbolId(context, identifier, symbol) {
44
31
  if (symbol) {
45
32
  return trackSymbolReference(context, symbol, identifier);
46
33
  }
@@ -9,6 +9,7 @@ export declare function hasExportEquals(sourceFile: ts.SourceFile): boolean;
9
9
  export declare function findFirstNodeAbove<T extends ts.Node>(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined;
10
10
  export declare function findFirstNonOuterParent(node: ts.Node): ts.Node;
11
11
  export declare function getFirstDeclarationInFile(symbol: ts.Symbol, sourceFile: ts.SourceFile): ts.Declaration | undefined;
12
+ export declare function isStandardLibraryDeclaration(context: TransformationContext, declaration: ts.Declaration): boolean;
12
13
  export declare function isStandardLibraryType(context: TransformationContext, type: ts.Type, name: string | undefined): boolean;
13
14
  export declare function hasStandardLibrarySignature(context: TransformationContext, callExpression: ts.CallExpression): boolean;
14
15
  export declare function inferAssignedType(context: TransformationContext, expression: ts.Expression): ts.Type;
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isConstIdentifier = exports.getFunctionTypeForCall = exports.isExpressionWithEvaluationEffect = exports.getAllCallSignatures = exports.inferAssignedType = exports.hasStandardLibrarySignature = exports.isStandardLibraryType = exports.getFirstDeclarationInFile = exports.findFirstNonOuterParent = exports.findFirstNodeAbove = exports.hasExportEquals = void 0;
17
+ exports.isConstIdentifier = exports.getFunctionTypeForCall = exports.isExpressionWithEvaluationEffect = exports.getAllCallSignatures = exports.inferAssignedType = exports.hasStandardLibrarySignature = exports.isStandardLibraryType = exports.isStandardLibraryDeclaration = exports.getFirstDeclarationInFile = exports.findFirstNonOuterParent = exports.findFirstNodeAbove = exports.hasExportEquals = void 0;
18
18
  const ts = require("typescript");
19
19
  __exportStar(require("./nodes"), exports);
20
20
  __exportStar(require("./types"), exports);
@@ -62,6 +62,7 @@ function isStandardLibraryDeclaration(context, declaration) {
62
62
  }
63
63
  return context.program.isSourceFileDefaultLibrary(sourceFile);
64
64
  }
65
+ exports.isStandardLibraryDeclaration = isStandardLibraryDeclaration;
65
66
  function isStandardLibraryType(context, type, name) {
66
67
  const symbol = type.getSymbol();
67
68
  if (!symbol || (name ? symbol.name !== name : symbol.name === "__type")) {
@@ -1,12 +1,9 @@
1
1
  import * as ts from "typescript";
2
2
  import { TransformationContext } from "../../context";
3
- export declare function isTypeWithFlags(context: TransformationContext, type: ts.Type, flags: ts.TypeFlags): boolean;
4
- export declare function typeAlwaysSatisfies(context: TransformationContext, type: ts.Type, predicate: (type: ts.Type) => boolean): boolean;
5
- export declare function typeCanSatisfy(context: TransformationContext, type: ts.Type, predicate: (type: ts.Type) => boolean): boolean;
6
- export declare function isNullishType(context: TransformationContext, type: ts.Type): boolean;
3
+ export declare function typeAlwaysHasSomeOfFlags(context: TransformationContext, type: ts.Type, flags: ts.TypeFlags): boolean;
4
+ export declare function typeCanHaveSomeOfFlags(context: TransformationContext, type: ts.Type, flags: ts.TypeFlags): boolean;
7
5
  export declare function isStringType(context: TransformationContext, type: ts.Type): boolean;
8
6
  export declare function isNumberType(context: TransformationContext, type: ts.Type): boolean;
9
- export declare function isNullableType(context: TransformationContext, type: ts.Type, isType: (c: TransformationContext, t: ts.Type) => boolean): boolean;
10
7
  /**
11
8
  * Iterate over a type and its bases until the callback returns true.
12
9
  */
@@ -1,30 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNullableType = exports.isNumberType = exports.isStringType = exports.isNullishType = exports.typeCanSatisfy = exports.typeAlwaysSatisfies = exports.isTypeWithFlags = void 0;
3
+ exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0;
4
4
  const ts = require("typescript");
5
- function isTypeWithFlags(context, type, flags) {
6
- const predicate = (type) => (type.flags & flags) !== 0;
7
- return typeAlwaysSatisfies(context, type, predicate);
8
- }
9
- exports.isTypeWithFlags = isTypeWithFlags;
10
- function typeAlwaysSatisfies(context, type, predicate) {
5
+ function typeAlwaysHasSomeOfFlags(context, type, flags) {
11
6
  const baseConstraint = context.checker.getBaseConstraintOfType(type);
12
7
  if (baseConstraint) {
13
8
  type = baseConstraint;
14
9
  }
15
- if (predicate(type)) {
10
+ if (type.flags & flags) {
16
11
  return true;
17
12
  }
18
13
  if (type.isUnion()) {
19
- return type.types.every(t => typeAlwaysSatisfies(context, t, predicate));
14
+ return type.types.every(t => typeAlwaysHasSomeOfFlags(context, t, flags));
20
15
  }
21
16
  if (type.isIntersection()) {
22
- return type.types.some(t => typeAlwaysSatisfies(context, t, predicate));
17
+ return type.types.some(t => typeAlwaysHasSomeOfFlags(context, t, flags));
23
18
  }
24
19
  return false;
25
20
  }
26
- exports.typeAlwaysSatisfies = typeAlwaysSatisfies;
27
- function typeCanSatisfy(context, type, predicate) {
21
+ exports.typeAlwaysHasSomeOfFlags = typeAlwaysHasSomeOfFlags;
22
+ function typeCanHaveSomeOfFlags(context, type, flags) {
28
23
  const baseConstraint = context.checker.getBaseConstraintOfType(type);
29
24
  if (!baseConstraint) {
30
25
  // type parameter with no constraint can be anything, assume it might satisfy predicate
@@ -34,36 +29,29 @@ function typeCanSatisfy(context, type, predicate) {
34
29
  else {
35
30
  type = baseConstraint;
36
31
  }
37
- if (predicate(type)) {
32
+ if (type.flags & flags) {
38
33
  return true;
39
34
  }
40
35
  if (type.isUnion()) {
41
- return type.types.some(t => typeCanSatisfy(context, t, predicate));
36
+ return type.types.some(t => typeCanHaveSomeOfFlags(context, t, flags));
42
37
  }
43
38
  if (type.isIntersection()) {
44
- return type.types.some(t => typeCanSatisfy(context, t, predicate));
39
+ return type.types.some(t => typeCanHaveSomeOfFlags(context, t, flags));
45
40
  }
46
41
  return false;
47
42
  }
48
- exports.typeCanSatisfy = typeCanSatisfy;
49
- function isNullishType(context, type) {
50
- return isTypeWithFlags(context, type, ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.VoidLike);
51
- }
52
- exports.isNullishType = isNullishType;
43
+ exports.typeCanHaveSomeOfFlags = typeCanHaveSomeOfFlags;
53
44
  function isStringType(context, type) {
54
- return isTypeWithFlags(context, type, ts.TypeFlags.String | ts.TypeFlags.StringLike | ts.TypeFlags.StringLiteral);
45
+ return typeAlwaysHasSomeOfFlags(context, type, ts.TypeFlags.StringLike);
55
46
  }
56
47
  exports.isStringType = isStringType;
57
48
  function isNumberType(context, type) {
58
- return isTypeWithFlags(context, type, ts.TypeFlags.Number | ts.TypeFlags.NumberLike | ts.TypeFlags.NumberLiteral);
49
+ return typeAlwaysHasSomeOfFlags(context, type, ts.TypeFlags.NumberLike);
59
50
  }
60
51
  exports.isNumberType = isNumberType;
61
- function isNullableType(context, type, isType) {
62
- return (typeCanSatisfy(context, type, t => isType(context, t)) &&
63
- typeAlwaysSatisfies(context, type, t => isType(context, t) || isNullishType(context, t)));
64
- }
65
- exports.isNullableType = isNullableType;
66
52
  function isExplicitArrayType(context, type) {
53
+ if (context.checker.isArrayType(type) || context.checker.isTupleType(type))
54
+ return true;
67
55
  if (type.symbol) {
68
56
  const baseConstraint = context.checker.getBaseConstraintOfType(type);
69
57
  if (baseConstraint && baseConstraint !== type) {
@@ -73,25 +61,22 @@ function isExplicitArrayType(context, type) {
73
61
  if (type.isUnionOrIntersection()) {
74
62
  return type.types.some(t => isExplicitArrayType(context, t));
75
63
  }
76
- const flags = ts.NodeBuilderFlags.InTypeAlias | ts.NodeBuilderFlags.AllowEmptyTuple;
77
- let typeNode = context.checker.typeToTypeNode(type, undefined, flags);
78
- if (typeNode && ts.isTypeOperatorNode(typeNode) && typeNode.operator === ts.SyntaxKind.ReadonlyKeyword) {
79
- typeNode = typeNode.type;
80
- }
81
- return typeNode !== undefined && (ts.isArrayTypeNode(typeNode) || ts.isTupleTypeNode(typeNode));
64
+ return false;
82
65
  }
83
66
  /**
84
67
  * Iterate over a type and its bases until the callback returns true.
85
68
  */
86
69
  function forTypeOrAnySupertype(context, type, predicate) {
87
- var _a;
88
70
  if (predicate(type)) {
89
71
  return true;
90
72
  }
91
73
  if (!type.isClassOrInterface() && type.symbol) {
92
74
  type = context.checker.getDeclaredTypeOfSymbol(type.symbol);
93
75
  }
94
- return ((_a = type.getBaseTypes()) !== null && _a !== void 0 ? _a : []).some(superType => forTypeOrAnySupertype(context, superType, predicate));
76
+ const baseTypes = type.getBaseTypes();
77
+ if (!baseTypes)
78
+ return false;
79
+ return baseTypes.some(superType => forTypeOrAnySupertype(context, superType, predicate));
95
80
  }
96
81
  exports.forTypeOrAnySupertype = forTypeOrAnySupertype;
97
82
  function isArrayType(context, type) {
@@ -104,6 +89,8 @@ function isFunctionType(type) {
104
89
  exports.isFunctionType = isFunctionType;
105
90
  function canBeFalsy(context, type) {
106
91
  const strictNullChecks = context.options.strict === true || context.options.strictNullChecks === true;
92
+ if (!strictNullChecks && !type.isLiteral())
93
+ return true;
107
94
  const falsyFlags = ts.TypeFlags.Boolean |
108
95
  ts.TypeFlags.BooleanLiteral |
109
96
  ts.TypeFlags.Never |
@@ -112,17 +99,20 @@ function canBeFalsy(context, type) {
112
99
  ts.TypeFlags.Any |
113
100
  ts.TypeFlags.Undefined |
114
101
  ts.TypeFlags.Null;
115
- return typeCanSatisfy(context, type, type => (type.flags & falsyFlags) !== 0 || (!strictNullChecks && !type.isLiteral()));
102
+ return typeCanHaveSomeOfFlags(context, type, falsyFlags);
116
103
  }
117
104
  exports.canBeFalsy = canBeFalsy;
118
105
  function canBeFalsyWhenNotNull(context, type) {
106
+ const strictNullChecks = context.options.strict === true || context.options.strictNullChecks === true;
107
+ if (!strictNullChecks && !type.isLiteral())
108
+ return true;
119
109
  const falsyFlags = ts.TypeFlags.Boolean |
120
110
  ts.TypeFlags.BooleanLiteral |
121
111
  ts.TypeFlags.Never |
122
112
  ts.TypeFlags.Void |
123
113
  ts.TypeFlags.Unknown |
124
114
  ts.TypeFlags.Any;
125
- return typeCanSatisfy(context, type, type => (type.flags & falsyFlags) !== 0);
115
+ return typeCanHaveSomeOfFlags(context, type, falsyFlags);
126
116
  }
127
117
  exports.canBeFalsyWhenNotNull = canBeFalsyWhenNotNull;
128
118
  //# sourceMappingURL=types.js.map