Skip to content

Commit 5735093

Browse files
ark120202Perryvw
authored andcommitted
Upgrade TypeScript to v3.6 (#714)
* Upgrade TypeScript to v3.6 * Add explicit reference to typescript-internal file * Include main project in test config includes * Exclude lualib from test tsconfig * Add noSelfInFile with other annotations test
1 parent 20a5d92 commit 5735093

File tree

11 files changed

+81
-27
lines changed

11 files changed

+81
-27
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"types": "dist/index.d.ts",
2020
"scripts": {
2121
"build": "tsc -p tsconfig.json && npm run build-lualib",
22-
"build-lualib": "ts-node ./build_lualib.ts",
23-
"pretest": "npm run lint && ts-node --transpile-only ./build_lualib.ts",
22+
"build-lualib": "ts-node --files ./build_lualib.ts",
23+
"pretest": "npm run lint && ts-node --files --transpile-only ./build_lualib.ts",
2424
"test": "jest",
2525
"lint": "npm run lint:tslint && npm run lint:prettier",
2626
"lint:prettier": "prettier --check \"**/*.{js,ts,yml,json,md}\" || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"resolve": "^1.11.0",
4343
"source-map": "^0.7.3",
44-
"typescript": "3.5.x"
44+
"typescript": "^3.6.2"
4545
},
4646
"devDependencies": {
4747
"@types/glob": "^7.1.1",

src/LuaTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4458,7 +4458,7 @@ export class LuaTransformer {
44584458
}
44594459

44604460
protected transformArguments<T extends ts.Expression>(
4461-
params: ts.NodeArray<ts.Expression> | ts.Expression[],
4461+
params: readonly ts.Expression[],
44624462
sig?: ts.Signature,
44634463
context?: T
44644464
): tstl.Expression[] {

src/TSHelper.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export function getCustomDecorators(type: ts.Type, checker: ts.TypeChecker): Map
404404
return decMap;
405405
}
406406

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

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

421421
export function getCustomFileDirectives(file: ts.SourceFile): Map<DecoratorKind, Decorator> {
422+
const directivesMap = new Map<DecoratorKind, Decorator>();
423+
422424
if (file.statements.length > 0) {
423-
return getCustomNodeDirectives(file.statements[0]);
425+
// Manually collect jsDoc because `getJSDocTags` includes tags only from closest comment
426+
const jsDoc = file.statements[0].jsDoc;
427+
if (jsDoc) {
428+
// TODO(refactor): flatMap
429+
const tags = jsDoc.reduce<ts.JSDocTag[]>((acc, x) => [...acc, ...(x.tags || [])], []);
430+
tags.forEach(tag => {
431+
const tagName = tag.tagName.text;
432+
if (Decorator.isValid(tagName)) {
433+
const dec = new Decorator(tagName, tag.comment ? tag.comment.split(" ") : []);
434+
directivesMap.set(dec.kind, dec);
435+
}
436+
});
437+
}
424438
}
425-
return new Map();
439+
440+
return directivesMap;
426441
}
427442

428443
export function getCustomSignatureDirectives(

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { emitTranspiledFiles, OutputFile } from "./Emit";
77
import { transpile, TranspiledFile, TranspileResult } from "./Transpile";
88

99
export {
10+
createDiagnosticReporter,
1011
parseCommandLine,
1112
ParsedCommandLine,
1213
updateParsedConfigFile,
13-
createDiagnosticReporter,
1414
} from "./CommandLineParser";
1515
export * from "./CompilerOptions";
1616
export * from "./Emit";

src/typescript-internal.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as ts from "typescript";
2+
3+
declare module "typescript" {
4+
interface Statement {
5+
jsDoc?: ts.JSDoc[];
6+
}
7+
}

test/tsconfig.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,13 @@
1313
"noEmit": true,
1414
"module": "commonjs"
1515
},
16-
"exclude": ["translation/transformation", "cli/errors", "cli/watch", "transpile/directories", "transpile/outFile"]
16+
"include": [".", "../src"],
17+
"exclude": [
18+
"translation/transformation",
19+
"cli/errors",
20+
"cli/watch",
21+
"transpile/directories",
22+
"transpile/outFile",
23+
"../src/lualib"
24+
]
1725
}

test/unit/decorators/luaIterator.spec.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ test("forof lua iterator destructuring with existing variables", () => {
119119
test("forof lua iterator tuple-return", () => {
120120
const code = `
121121
const arr = ["a", "b", "c"];
122-
/** @luaIterator */
123-
/** @tupleReturn */
122+
/**
123+
* @luaIterator
124+
* @tupleReturn
125+
*/
124126
interface Iter extends Iterable<[string, string]> {}
125127
function luaIter(): Iter {
126128
let i = 0;
@@ -144,8 +146,10 @@ test("forof lua iterator tuple-return", () => {
144146
test("forof lua iterator tuple-return with existing variables", () => {
145147
const code = `
146148
const arr = ["a", "b", "c"];
147-
/** @luaIterator */
148-
/** @tupleReturn */
149+
/**
150+
* @luaIterator
151+
* @tupleReturn
152+
*/
149153
interface Iter extends Iterable<[string, string]> {}
150154
function luaIter(): Iter {
151155
let i = 0;
@@ -170,8 +174,10 @@ test("forof lua iterator tuple-return with existing variables", () => {
170174

171175
test("forof lua iterator tuple-return single variable", () => {
172176
const code = `
173-
/** @luaIterator */
174-
/** @tupleReturn */
177+
/**
178+
* @luaIterator
179+
* @tupleReturn
180+
*/
175181
interface Iter extends Iterable<[string, string]> {}
176182
declare function luaIter(): Iter;
177183
for (let x of luaIter()) {}
@@ -188,8 +194,10 @@ test("forof lua iterator tuple-return single variable", () => {
188194

189195
test("forof lua iterator tuple-return single existing variable", () => {
190196
const code = `
191-
/** @luaIterator */
192-
/** @tupleReturn */
197+
/**
198+
* @luaIterator
199+
* @tupleReturn
200+
*/
193201
interface Iter extends Iterable<[string, string]> {}
194202
declare function luaIter(): Iter;
195203
let x: [string, string];
@@ -235,8 +243,10 @@ test("forof forwarded lua iterator", () => {
235243
test("forof forwarded lua iterator with tupleReturn", () => {
236244
const code = `
237245
const arr = ["a", "b", "c"];
238-
/** @luaIterator */
239-
/** @tupleReturn */
246+
/**
247+
* @luaIterator
248+
* @tupleReturn
249+
*/
240250
interface Iter extends Iterable<[string, string]> {}
241251
function luaIter(): Iter {
242252
let i = 0;

test/unit/functions/validation/functionExpressionTypeInference.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ test.each(["noSelf", "noSelfInFile"])("noSelf function method argument (%p)", no
1616
expect(util.transpileAndExecute(code, undefined, undefined, header)).toBe("foo");
1717
});
1818

19+
test("noSelfInFile works when first statement has other annotations", () => {
20+
util.testModule`
21+
/** @noSelfInFile */
22+
23+
/** @internal */
24+
function foo() {}
25+
26+
const test: (this: void) => void = foo;
27+
`.expectToHaveNoDiagnostics();
28+
});
29+
1930
test.each(["(this: void, s: string) => string", "(this: any, s: string) => string", "(s: string) => string"])(
2031
"Function expression type inference in binary operator (%p)",
2132
funcType => {

test/unit/loops.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,10 @@ describe("for...of empty destructuring", () => {
547547
test("luaIterator+tupleReturn", () => {
548548
const code = `
549549
const arr = [["a", "b"], ["c", "d"], ["e", "f"]];
550-
/** @luaIterator */
551-
/** @tupleReturn */
550+
/**
551+
* @luaIterator
552+
* @tupleReturn
553+
*/
552554
interface Iter extends Iterable<[string, string]> {}
553555
function luaIter(): Iter {
554556
let it = 0;

0 commit comments

Comments
 (0)