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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.json && npm run build-lualib",
"build-lualib": "ts-node ./build_lualib.ts",
"pretest": "npm run lint && ts-node --transpile-only ./build_lualib.ts",
"build-lualib": "ts-node --files ./build_lualib.ts",
"pretest": "npm run lint && ts-node --files --transpile-only ./build_lualib.ts",
"test": "jest",
"lint": "npm run lint:tslint && npm run lint:prettier",
"lint:prettier": "prettier --check \"**/*.{js,ts,yml,json,md}\" || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
Expand All @@ -41,7 +41,7 @@
"dependencies": {
"resolve": "^1.11.0",
"source-map": "^0.7.3",
"typescript": "3.5.x"
"typescript": "^3.6.2"
},
"devDependencies": {
"@types/glob": "^7.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4458,7 +4458,7 @@ export class LuaTransformer {
}

protected transformArguments<T extends ts.Expression>(
params: ts.NodeArray<ts.Expression> | ts.Expression[],
params: readonly ts.Expression[],
sig?: ts.Signature,
context?: T
): tstl.Expression[] {
Expand Down
21 changes: 18 additions & 3 deletions src/TSHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export function getCustomDecorators(type: ts.Type, checker: ts.TypeChecker): Map
return decMap;
}

export function getCustomNodeDirectives(node: ts.Node): Map<DecoratorKind, Decorator> {
function getCustomNodeDirectives(node: ts.Node): Map<DecoratorKind, Decorator> {
const directivesMap = new Map<DecoratorKind, Decorator>();

ts.getJSDocTags(node).forEach(tag => {
Expand All @@ -419,10 +419,25 @@ export function getCustomNodeDirectives(node: ts.Node): Map<DecoratorKind, Decor
}

export function getCustomFileDirectives(file: ts.SourceFile): Map<DecoratorKind, Decorator> {
const directivesMap = new Map<DecoratorKind, Decorator>();

if (file.statements.length > 0) {
return getCustomNodeDirectives(file.statements[0]);
// Manually collect jsDoc because `getJSDocTags` includes tags only from closest comment
const jsDoc = file.statements[0].jsDoc;
if (jsDoc) {
// TODO(refactor): flatMap
const tags = jsDoc.reduce<ts.JSDocTag[]>((acc, x) => [...acc, ...(x.tags || [])], []);
tags.forEach(tag => {
const tagName = tag.tagName.text;
if (Decorator.isValid(tagName)) {
const dec = new Decorator(tagName, tag.comment ? tag.comment.split(" ") : []);
directivesMap.set(dec.kind, dec);
}
});
}
}
return new Map();

return directivesMap;
}

export function getCustomSignatureDirectives(
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { emitTranspiledFiles, OutputFile } from "./Emit";
import { transpile, TranspiledFile, TranspileResult } from "./Transpile";

export {
createDiagnosticReporter,
parseCommandLine,
ParsedCommandLine,
updateParsedConfigFile,
createDiagnosticReporter,
} from "./CommandLineParser";
export * from "./CompilerOptions";
export * from "./Emit";
Expand Down
7 changes: 7 additions & 0 deletions src/typescript-internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as ts from "typescript";

declare module "typescript" {
interface Statement {
jsDoc?: ts.JSDoc[];
}
}
10 changes: 9 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@
"noEmit": true,
"module": "commonjs"
},
"exclude": ["translation/transformation", "cli/errors", "cli/watch", "transpile/directories", "transpile/outFile"]
"include": [".", "../src"],
"exclude": [
"translation/transformation",
"cli/errors",
"cli/watch",
"transpile/directories",
"transpile/outFile",
"../src/lualib"
]
}
30 changes: 20 additions & 10 deletions test/unit/decorators/luaIterator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ test("forof lua iterator destructuring with existing variables", () => {
test("forof lua iterator tuple-return", () => {
const code = `
const arr = ["a", "b", "c"];
/** @luaIterator */
/** @tupleReturn */
/**
* @luaIterator
* @tupleReturn
*/
interface Iter extends Iterable<[string, string]> {}
function luaIter(): Iter {
let i = 0;
Expand All @@ -144,8 +146,10 @@ test("forof lua iterator tuple-return", () => {
test("forof lua iterator tuple-return with existing variables", () => {
const code = `
const arr = ["a", "b", "c"];
/** @luaIterator */
/** @tupleReturn */
/**
* @luaIterator
* @tupleReturn
*/
interface Iter extends Iterable<[string, string]> {}
function luaIter(): Iter {
let i = 0;
Expand All @@ -170,8 +174,10 @@ test("forof lua iterator tuple-return with existing variables", () => {

test("forof lua iterator tuple-return single variable", () => {
const code = `
/** @luaIterator */
/** @tupleReturn */
/**
* @luaIterator
* @tupleReturn
*/
interface Iter extends Iterable<[string, string]> {}
declare function luaIter(): Iter;
for (let x of luaIter()) {}
Expand All @@ -188,8 +194,10 @@ test("forof lua iterator tuple-return single variable", () => {

test("forof lua iterator tuple-return single existing variable", () => {
const code = `
/** @luaIterator */
/** @tupleReturn */
/**
* @luaIterator
* @tupleReturn
*/
interface Iter extends Iterable<[string, string]> {}
declare function luaIter(): Iter;
let x: [string, string];
Expand Down Expand Up @@ -235,8 +243,10 @@ test("forof forwarded lua iterator", () => {
test("forof forwarded lua iterator with tupleReturn", () => {
const code = `
const arr = ["a", "b", "c"];
/** @luaIterator */
/** @tupleReturn */
/**
* @luaIterator
* @tupleReturn
*/
interface Iter extends Iterable<[string, string]> {}
function luaIter(): Iter {
let i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ test.each(["noSelf", "noSelfInFile"])("noSelf function method argument (%p)", no
expect(util.transpileAndExecute(code, undefined, undefined, header)).toBe("foo");
});

test("noSelfInFile works when first statement has other annotations", () => {
util.testModule`
/** @noSelfInFile */

/** @internal */
function foo() {}

const test: (this: void) => void = foo;
`.expectToHaveNoDiagnostics();
});

test.each(["(this: void, s: string) => string", "(this: any, s: string) => string", "(s: string) => string"])(
"Function expression type inference in binary operator (%p)",
funcType => {
Expand Down
6 changes: 4 additions & 2 deletions test/unit/loops.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,10 @@ describe("for...of empty destructuring", () => {
test("luaIterator+tupleReturn", () => {
const code = `
const arr = [["a", "b"], ["c", "d"], ["e", "f"]];
/** @luaIterator */
/** @tupleReturn */
/**
* @luaIterator
* @tupleReturn
*/
interface Iter extends Iterable<[string, string]> {}
function luaIter(): Iter {
let it = 0;
Expand Down
7 changes: 4 additions & 3 deletions test/unit/tshelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ test("GetCustomDecorators multiple jsdoc", () => {
test("GetCustomDecorators multiple default jsdoc", () => {
const source = `
/**
* @description abc
* @phantom
* @compileMembersOnly */
* @description abc
* @phantom
* @compileMembersOnly
*/
enum TestEnum {
val1 = 0,
val2 = 2,
Expand Down