Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,682 changes: 2,200 additions & 1,482 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
"@types/jest": "^27.5.2",
"@types/node": "^13.7.7",
"@types/resolve": "1.14.0",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint": "^8.23.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.8.7",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"eslint": "^8.34.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^26.9.0",
"fs-extra": "^8.1.0",
"javascript-stringify": "^2.0.1",
"jest": "^28.1.3",
"jest-circus": "^29.0.1",
"jest-circus": "^29.4.2",
"lua-types": "^2.13.0",
"lua-wasm-bindings": "^0.3.1",
"prettier": "^2.3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/ArrayFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function arrayLikeStep(this: ArrayLike<unknown>, index: number): LuaMultiReturn<
const arrayLikeIterator: (
this: void,
arr: ArrayLike<unknown> | Iterable<unknown>
) => LuaIterable<LuaMultiReturn<[number, unknown]>> = (arr => {
) => LuaIterable<LuaMultiReturn<[number, unknown]>> = ((arr: any) => {
if (typeof arr.length === "number") return $multi(arrayLikeStep, arr, 0);
return __TS__Iterator(arr);
}) as any;
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/ArrayReduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function __TS__ArrayReduce<TElement, TAccumulator>(
const len = this.length;

let k = 0;
let accumulator: TAccumulator = undefined;
let accumulator: TAccumulator = undefined!;

// Check if initial value is present in function call
if (__TS__CountVarargs(...initial) !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/ArrayReduceRight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function __TS__ArrayReduceRight<TElement, TAccumulator>(
const len = this.length;

let k = len - 1;
let accumulator: TAccumulator = undefined;
let accumulator: TAccumulator = undefined!;

// Check if initial value is present in function call
if (__TS__CountVarargs(...initial) !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/ArraySetLength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function __TS__ArraySetLength<T>(this: T[], length: number): number {
throw `invalid array length: ${length}`;
}
for (const i of $range(length + 1, this.length)) {
this[i - 1] = undefined;
this[i - 1] = undefined!;
}
return length;
}
8 changes: 4 additions & 4 deletions src/lualib/ArraySplice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export function __TS__ArraySplice<T>(this: T[], ...args: any[]): T[] {
if (this[from - 1]) {
this[to - 1] = this[from - 1];
} else {
this[to - 1] = undefined;
this[to - 1] = undefined!;
}
}
for (const k of $range(len - actualDeleteCount + itemCount + 1, len)) {
this[k - 1] = undefined;
this[k - 1] = undefined!;
}
} else if (itemCount > actualDeleteCount) {
for (const k of $range(len - actualDeleteCount, start + 1, -1)) {
Expand All @@ -72,7 +72,7 @@ export function __TS__ArraySplice<T>(this: T[], ...args: any[]): T[] {
if (this[from - 1]) {
this[to - 1] = this[from - 1];
} else {
this[to - 1] = undefined;
this[to - 1] = undefined!;
}
}
}
Expand All @@ -84,7 +84,7 @@ export function __TS__ArraySplice<T>(this: T[], ...args: any[]): T[] {
}

for (const k of $range(this.length, len - actualDeleteCount + itemCount + 1, -1)) {
this[k - 1] = undefined;
this[k - 1] = undefined!;
}

return out;
Expand Down
4 changes: 2 additions & 2 deletions src/lualib/Decorate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export function __TS__Decorate<TTarget extends AnyTable, TKey extends keyof TTar

for (let i = decorators.length; i >= 0; i--) {
const decorator = decorators[i];
if (decorator) {
if (decorator !== undefined) {
const oldResult = result;

if (key === undefined) {
result = decorator(result);
} else if (desc === true) {
const value = rawget(target, key);
const descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) || {
const descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) ?? {
configurable: true,
writable: true,
value,
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/DecorateParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Decorator } from "./Decorator";

type ParamDecorator<TTarget extends AnyTable, TKey extends keyof TTarget> = (
target: TTarget,
key: TKey,
key: TKey | undefined,
index: number
) => TTarget;
export function __TS__DecorateParam<TTarget extends AnyTable, TKey extends keyof TTarget>(
Expand Down
4 changes: 2 additions & 2 deletions src/lualib/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getErrorStack(constructor: () => any): string {

function wrapErrorToString<T extends Error>(getDescription: (this: T) => string): (this: T) => string {
return function (this: Error): string {
const description = getDescription.call(this);
const description = getDescription.call(this as T);
const caller = debug.getinfo(3, "f");
// @ts-ignore Fails when compiled with Lua 5.0 types
const isClassicLua = _VERSION.includes("Lua 5.0") || _VERSION === "Lua 5.1";
Expand All @@ -54,7 +54,7 @@ export const Error: ErrorConstructor = initErrorClass(
constructor(public message = "") {
this.stack = getErrorStack((this.constructor as any).new);
const metatable = getmetatable(this);
if (!metatable.__errorToStringPatched) {
if (metatable && !metatable.__errorToStringPatched) {
metatable.__errorToStringPatched = true;
metatable.__tostring = wrapErrorToString(metatable.__tostring);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lualib/InstanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function __TS__InstanceOf(this: void, obj: LuaClassInstance, classTbl: Lu

if (classTbl[Symbol.hasInstance] !== undefined) {
// eslint-disable-next-line no-implicit-coercion
return !!classTbl[Symbol.hasInstance](obj);
return !!classTbl[Symbol.hasInstance]!(obj);
}

if (typeof obj === "object") {
Expand All @@ -14,7 +14,7 @@ export function __TS__InstanceOf(this: void, obj: LuaClassInstance, classTbl: Lu
if (luaClass === classTbl) {
return true;
}
luaClass = luaClass.____super;
luaClass = luaClass.____super!;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/LuaIteratorSpread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function __TS__LuaIteratorSpread<TKey, TValue, TState>(
results.push([key, value]);
[key, value] = this(state, key);
}
return $multi(...results);
return $multi(...results) as LuaMultiReturn<Array<[TKey, TValue]>>;
}
34 changes: 17 additions & 17 deletions src/lualib/Map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Map<K, V> {
export class Map<K extends AnyNotNil, V> {
public static [Symbol.species] = Map;
public [Symbol.toStringTag] = "Map";

Expand Down Expand Up @@ -52,24 +52,24 @@ export class Map<K, V> {
// Do order bookkeeping
const next = this.nextKey.get(key);
const previous = this.previousKey.get(key);
if (next && previous) {
if (next !== undefined && previous !== undefined) {
this.nextKey.set(previous, next);
this.previousKey.set(next, previous);
} else if (next) {
} else if (next !== undefined) {
this.firstKey = next;
this.previousKey.set(next, undefined);
} else if (previous) {
this.previousKey.set(next, undefined!);
} else if (previous !== undefined) {
this.lastKey = previous;
this.nextKey.set(previous, undefined);
this.nextKey.set(previous, undefined!);
} else {
this.firstKey = undefined;
this.lastKey = undefined;
}

this.nextKey.set(key, undefined);
this.previousKey.set(key, undefined);
this.nextKey.set(key, undefined!);
this.previousKey.set(key, undefined!);
}
this.items.set(key, undefined);
this.items.set(key, undefined!);

return contains;
}
Expand Down Expand Up @@ -100,8 +100,8 @@ export class Map<K, V> {
this.firstKey = key;
this.lastKey = key;
} else if (isNewValue) {
this.nextKey.set(this.lastKey, key);
this.previousKey.set(key, this.lastKey);
this.nextKey.set(this.lastKey!, key);
this.previousKey.set(key, this.lastKey!);
this.lastKey = key;
}

Expand All @@ -120,8 +120,8 @@ export class Map<K, V> {
return this;
},
next(): IteratorResult<[K, V]> {
const result = { done: !key, value: [key, items.get(key)] as [K, V] };
key = nextKey.get(key);
const result = { done: !key, value: [key, items.get(key!)] as [K, V] };
key = nextKey.get(key!);
return result;
},
};
Expand All @@ -136,8 +136,8 @@ export class Map<K, V> {
},
next(): IteratorResult<K> {
const result = { done: !key, value: key };
key = nextKey.get(key);
return result;
key = nextKey.get(key!);
return result as IteratorResult<K>;
},
};
}
Expand All @@ -150,8 +150,8 @@ export class Map<K, V> {
return this;
},
next(): IteratorResult<V> {
const result = { done: !key, value: items.get(key) };
key = nextKey.get(key);
const result = { done: !key, value: items.get(key!) };
key = nextKey.get(key!);
return result;
},
};
Expand Down
7 changes: 5 additions & 2 deletions src/lualib/ObjectEntries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export function __TS__ObjectEntries(this: void, obj: any): Array<string | number> {
const result = [];
export function __TS__ObjectEntries<TKey extends string | number, TValue>(
this: void,
obj: Record<TKey, TValue>
): Array<[TKey, TValue]> {
const result: Array<[TKey, TValue]> = [];
let len = 0;
for (const key in obj) {
len++;
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/ObjectGetOwnPropertyDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export function __TS__ObjectGetOwnPropertyDescriptor(
const metatable = getmetatable(object);
if (!metatable) return;
if (!rawget(metatable, "_descriptors")) return;
return rawget(metatable, "_descriptors")[key];
return rawget(metatable, "_descriptors")![key];
}
2 changes: 1 addition & 1 deletion src/lualib/ObjectGetOwnPropertyDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export function __TS__ObjectGetOwnPropertyDescriptors(
): Record<any, PropertyDescriptor | undefined> {
const metatable = getmetatable(object);
if (!metatable) return {};
return rawget(metatable, "_descriptors") || {};
return rawget(metatable, "_descriptors") ?? {};
}
2 changes: 1 addition & 1 deletion src/lualib/ParseFloat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { __TS__Match } from "./Match";
export function __TS__ParseFloat(this: void, numberString: string): number {
// Check if string is infinity
const [infinityMatch] = __TS__Match(numberString, "^%s*(-?Infinity)");
if (infinityMatch) {
if (infinityMatch !== undefined) {
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
return infinityMatch[0] === "-" ? -Infinity : Infinity;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/ParseInt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function __TS__ParseInt(this: void, numberString: string, base?: number):
if (base === undefined) {
base = 10;
const [hexMatch] = __TS__Match(numberString, "^%s*-?0[xX]");
if (hexMatch) {
if (hexMatch !== undefined) {
base = 16;
numberString = __TS__Match(hexMatch, "-")[0]
? "-" + numberString.substring(hexMatch.length)
Expand Down
10 changes: 6 additions & 4 deletions src/lualib/Promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function promiseDeferred<T>() {
reject = rej;
});

// @ts-ignore This is alright because TS doesnt understand the callback will immediately be called
return { promise, resolve, reject };
}

Expand All @@ -36,6 +37,7 @@ export class __TS__Promise<T> implements Promise<T> {
private rejectedCallbacks: Array<RejectCallback<unknown>> = [];
private finallyCallbacks: Array<() => void> = [];

// @ts-ignore
public [Symbol.toStringTag]: string; // Required to implement interface, no output Lua

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
Expand Down Expand Up @@ -81,7 +83,7 @@ export class __TS__Promise<T> implements Promise<T> {

if (isFulfilled) {
// If promise already resolved, immediately call callback
internalCallback(this.value);
internalCallback(this.value!);
}
} else {
// We always want to resolve our child promise if this promise is resolved, even if we have no handler
Expand All @@ -103,7 +105,7 @@ export class __TS__Promise<T> implements Promise<T> {

if (isFulfilled) {
// If promise already resolved, also resolve returned promise
resolve(this.value);
resolve(this.value!);
}

if (isRejected) {
Expand Down Expand Up @@ -175,7 +177,7 @@ export class __TS__Promise<T> implements Promise<T> {
resolve: FulfillCallback<TResult1 | TResult2, unknown>,
reject: RejectCallback<unknown>
) {
return value => {
return (value: T) => {
try {
this.handleCallbackData(f(value), resolve, reject);
} catch (e) {
Expand All @@ -195,7 +197,7 @@ export class __TS__Promise<T> implements Promise<T> {
if (nextpromise.state === PromiseState.Fulfilled) {
// If a handler function returns an already fulfilled promise,
// the promise returned by then gets fulfilled with that promise's value
resolve(nextpromise.value);
resolve(nextpromise.value!);
} else if (nextpromise.state === PromiseState.Rejected) {
// If a handler function returns an already rejected promise,
// the promise returned by then gets fulfilled with that promise's value
Expand Down
Loading