Skip to content

Commit d43b331

Browse files
committed
Merge branch 'master' into async-await
2 parents c4310f9 + f6fea1e commit d43b331

12 files changed

Lines changed: 100 additions & 9 deletions

File tree

src/lualib/SourceMapTraceBack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// TODO: In the future, change this to __TS__RegisterFileInfo and provide tstl interface to
22
// get some metadata about transpilation.
3+
declare function __TS__originalTraceback(this: void, thread?: LuaThread, message?: string, level?: number);
34
function __TS__SourceMapTraceBack(this: void, fileName: string, sourceMap: { [line: number]: number }): void {
45
globalThis.__TS__sourcemap = globalThis.__TS__sourcemap || {};
56
globalThis.__TS__sourcemap[fileName] = sourceMap;

src/transformation/utils/function-context.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,25 @@ function getSignatureDeclarations(
113113
): ts.SignatureDeclaration[] {
114114
return signatures.flatMap(signature => {
115115
const signatureDeclaration = signature.getDeclaration();
116+
let inferredType: ts.Type | undefined;
116117
if (
118+
ts.isMethodDeclaration(signatureDeclaration) &&
119+
ts.isObjectLiteralExpression(signatureDeclaration.parent) &&
120+
!getExplicitThisParameter(signatureDeclaration)
121+
) {
122+
inferredType = context.checker.getContextualTypeForObjectLiteralElement(signatureDeclaration);
123+
} else if (
117124
(ts.isFunctionExpression(signatureDeclaration) || ts.isArrowFunction(signatureDeclaration)) &&
118125
!getExplicitThisParameter(signatureDeclaration)
119126
) {
120127
// Infer type of function expressions/arrow functions
121-
const inferredType = inferAssignedType(context, signatureDeclaration);
122-
if (inferredType) {
123-
const inferredSignatures = getAllCallSignatures(inferredType);
124-
if (inferredSignatures.length > 0) {
125-
return inferredSignatures.map(s => s.getDeclaration());
126-
}
128+
inferredType = inferAssignedType(context, signatureDeclaration);
129+
}
130+
131+
if (inferredType) {
132+
const inferredSignatures = getAllCallSignatures(inferredType);
133+
if (inferredSignatures.length > 0) {
134+
return inferredSignatures.map(s => s.getDeclaration());
127135
}
128136
}
129137

src/transpilation/resolve.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ function resolveDependency(
188188
const possibleLuaProjectFiles = [
189189
resolvedPath + ".lua", // lua file in sources
190190
path.join(resolvedPath, "index.lua"), // lua index file in sources
191+
path.join(resolvedPath, "init.lua"), // lua looks for <require>/init.lua if it cannot find <require>.lua
191192
];
192193

193194
for (const possibleFile of possibleLuaProjectFiles) {

src/transpilation/transpile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function getProgramTranspileResult(
103103
options.noEmit = false;
104104

105105
const writeFile: ts.WriteFileCallback = (fileName, ...rest) => {
106-
if (!fileName.endsWith(".js") && !fileName.endsWith(".js.map")) {
106+
if (!fileName.endsWith(".js") && !fileName.endsWith(".js.map") && !fileName.endsWith(".json")) {
107107
writeFileResult(fileName, ...rest);
108108
}
109109
};

src/typescript-internal.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ declare module "typescript" {
2626

2727
interface TypeChecker {
2828
getElementTypeOfArrayType(type: Type): Type | undefined;
29+
getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike): Type | undefined;
2930
}
3031
}

test/transpile/module-resolution.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ describe("dependency with complicated inner structure", () => {
286286
otherFileUtil: "util",
287287
subsubresult: "result from subsub dir",
288288
utilResult: "util",
289+
subdirwithInitResult: "a",
289290
};
290291

291292
// Test fix for https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1055

test/transpile/module-resolution/project-with-complicated-dependency/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const otherFileResult = dependency1.otherFileFromDependency1();
44
export const utilResult = dependency1.callUtil();
55
export const otherFileUtil = dependency1.otherFileUtil();
66
export const subsubresult = dependency1.subsubdirfileResult;
7+
export const subdirwithInitResult = dependency1.subdirWithInitResult;

test/transpile/module-resolution/project-with-complicated-dependency/node_modules/dependency1/index.d.ts

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/transpile/module-resolution/project-with-complicated-dependency/node_modules/dependency1/index.lua

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/transpile/module-resolution/project-with-complicated-dependency/node_modules/dependency1/subdirwithinit/init.lua

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)