Skip to content

Commit f18280f

Browse files
Support TypeScript 4.7 (roblox-ts#1903)
* Update validateCompilerOptions.ts * Delete fileIsModule.ts * Update getCustomPreEmitDiagnostics.ts * Fix remaining import * Update versions * Fix getDiagnosticsProducingTypeChecker usage * Update tsconfigs with moduleDetection option * Remove unused noNonModule diagnostic and test * Fix breaking type change from TS 4.7 in map test * Update ts-expose-internals * Update test types * Use temporary override to fix ts-node dependency ts-node requires peerDependency on stable TS versions only so conflict is generated when 4.7.0-beta is used for main package.json override only applies to devDependency, and... ...is only used on building the compiler locally, so it should be fine. * Upgrade to stable TS, remove redundant override * Pin typescript version to 4.7.2 only * Remove `export {}`, format diagnostic tests * Update test types again * Bump ts-expose-internals back down to test CI * Update ts-expose-internals to 4.7.2 Co-authored-by: osyrisrblx <[email protected]>
1 parent 24f3481 commit f18280f

File tree

77 files changed

+388
-2159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+388
-2159
lines changed

package-lock.json

+338-1,981
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"lookpath": "^1.2.2",
5959
"prompts": "^2.4.1",
6060
"resolve": "^1.20.0",
61-
"typescript": "=4.6.2",
61+
"typescript": "=4.7.2",
6262
"yargs": "^17.2.0"
6363
},
6464
"devDependencies": {
@@ -67,6 +67,7 @@
6767
"@types/node": "^17.0.0",
6868
"@types/prompts": "^2.0.14",
6969
"@types/resolve": "^1.20.1",
70+
"@types/ts-expose-internals": "npm:[email protected]",
7071
"@types/yargs": "^17.0.3",
7172
"@typescript-eslint/eslint-plugin": "^5.0.0",
7273
"@typescript-eslint/parser": "^5.0.0",
@@ -78,8 +79,7 @@
7879
"mocha": "^10.0.0",
7980
"nyc": "^15.1.0",
8081
"prettier": "^2.4.1",
81-
"ts-expose-internals": "=4.6.4",
82-
"ttypescript": "^1.5.12",
82+
"ttypescript": "^1.5.13",
8383
"typescript-transform-paths": "^3.3.1"
8484
},
8585
"files": [

src/Project/classes/VirtualProject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class VirtualProject {
105105
.getFilePaths()
106106
.filter(v => v.endsWith(ts.Extension.Ts) || v.endsWith(ts.Extension.Tsx) || v.endsWith(ts.Extension.Dts));
107107
this.program = ts.createProgram(rootNames, this.compilerOptions, this.compilerHost, this.program);
108-
this.typeChecker = this.program.getDiagnosticsProducingTypeChecker();
108+
this.typeChecker = this.program.getTypeChecker();
109109

110110
const services = createTransformServices(this.program, this.typeChecker, this.data);
111111
const pathTranslator = new PathTranslator(ROOT_DIR, OUT_DIR, undefined, false);

src/Project/functions/compileFiles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function compileFiles(
163163

164164
if (DiagnosticService.hasErrors()) return { emitSkipped: true, diagnostics: DiagnosticService.flush() };
165165

166-
const typeChecker = proxyProgram.getDiagnosticsProducingTypeChecker();
166+
const typeChecker = proxyProgram.getTypeChecker();
167167
const services = createTransformServices(proxyProgram, typeChecker, data);
168168

169169
for (let i = 0; i < sourceFiles.length; i++) {

src/Project/functions/validateCompilerOptions.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ts from "typescript";
77
const ENFORCED_OPTIONS = {
88
target: ts.ScriptTarget.ESNext,
99
module: ts.ModuleKind.CommonJS,
10+
moduleDetection: ts.ModuleDetectionKind.Force,
1011
moduleResolution: ts.ModuleResolutionKind.NodeJs,
1112
noLib: true,
1213
strict: true,
@@ -48,6 +49,10 @@ export function validateCompilerOptions(opts: ts.CompilerOptions, nodeModulesPat
4849
errors.push(`${y(`"module"`)} must be ${y(`commonjs`)}`);
4950
}
5051

52+
if (opts.moduleDetection !== ENFORCED_OPTIONS.moduleDetection) {
53+
errors.push(`${y(`"moduleDetection"`)} must be ${y(`"force"`)}`);
54+
}
55+
5156
if (opts.moduleResolution !== ENFORCED_OPTIONS.moduleResolution) {
5257
errors.push(`${y(`"moduleResolution"`)} must be ${y(`"Node"`)}`);
5358
}

src/Project/util/getCustomPreEmitDiagnostics.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { fileIsModule } from "TSTransformer/preEmitDiagnostics/fileIsModule";
21
import ts from "typescript";
32

43
export type PreEmitChecker = (sourceFile: ts.SourceFile) => Array<ts.Diagnostic>;
5-
const PRE_EMIT_DIAGNOSTICS: Array<PreEmitChecker> = [fileIsModule];
4+
const PRE_EMIT_DIAGNOSTICS: Array<PreEmitChecker> = [];
65

76
export function getCustomPreEmitDiagnostics(sourceFile: ts.SourceFile) {
87
const diagnostics = new Array<ts.Diagnostic>();

src/Shared/diagnostics.ts

-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ export const errors = {
175175
noVarArgsMacroSpread: error("Macros which use variadric arguments do not support spread expressions!", issue(1149)),
176176

177177
// import/export
178-
noNonModule: error(
179-
"File does not have an import or export statement!",
180-
suggestion("Add `export {};` as the first line."),
181-
issue(1043),
182-
),
183178
noModuleSpecifierFile: error("Could not find file for import. Did you forget to `npm install`?"),
184179
noInvalidModule: error("You can only use npm scopes that are listed in your typeRoots."),
185180
noUnscopedModule: error("You cannot use modules directly under node_modules."),

src/TSTransformer/preEmitDiagnostics/fileIsModule.ts

-9
This file was deleted.

templates/model/src/index.server.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
print("Hello from model!");

templates/plugin/src/index.server.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/// <reference types="@rbxts/types/plugin" />
22

3-
export {};
4-
53
const toolbar = plugin.CreateToolbar("MyToolbar");
64
const button = toolbar.CreateButton("MyButton", "", "");
75

templates/tsconfig-default.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"resolveJsonModule": true,
1313
"experimentalDecorators": true,
1414
"forceConsistentCasingInFileNames": true,
15+
"moduleDetection": "force",
1516
"strict": true,
1617
"target": "ESNext",
1718
"typeRoots": ["node_modules/@rbxts"],

templates/tsconfig-package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"resolveJsonModule": true,
1313
"experimentalDecorators": true,
1414
"forceConsistentCasingInFileNames": true,
15+
"moduleDetection": "force",
1516
"strict": true,
1617
"target": "ESNext",
1718
"typeRoots": ["node_modules/@rbxts"],

tests/package-lock.json

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"@rbxts/compiler-types": "^1.3.2-types.0",
13+
"@rbxts/compiler-types": "^1.3.3-types.1",
1414
"@rbxts/roact": "^1.3.0-ts.7",
1515
"@rbxts/services": "^1.1.2",
1616
"@rbxts/testez": "^0.3.1-ts.6",
17-
"@rbxts/types": "^1.0.571"
17+
"@rbxts/types": "^1.0.593"
1818
}
1919
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export {};
2-
31
interface HasCallback {
42
callback: () => void;
53
}
64

75
const obj: HasCallback = {
86
callback() {},
9-
}
7+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export {};
2-
31
interface HasCallback {
42
callback: () => void;
53
}
64

75
const obj: HasCallback = {
8-
callback: function() {},
9-
}
6+
callback: function () {},
7+
};

tests/src/diagnostics/expectedFunctionGotMethod.3.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
interface MyWow {
42
callback: () => void;
53
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export {};
2-
31
interface HasMethod {
42
method(): void;
53
}
64

75
const obj: HasMethod = {
86
method: () => {},
9-
}
7+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export {};
2-
31
interface HasMethod {
42
method: (this: HasMethod) => void;
53
}
64

75
const obj: HasMethod = {
86
method: () => {},
9-
}
7+
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
interface HasMethod {
42
method(): void;
53
}
@@ -8,4 +6,4 @@ function method() {}
86

97
const obj: HasMethod = {
108
method,
11-
}
9+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export {};
2-
31
interface HasMethod {
42
method(): void;
53
}
64

75
const obj: HasMethod = {
86
method(this: void) {},
9-
}
7+
};

tests/src/diagnostics/expectedMethodGotFunction.5.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
interface MyWow {
42
method(): void;
53
}

tests/src/diagnostics/noAny.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
function foo(x: any) {
42
print(x.y);
53
}

tests/src/diagnostics/noArguments.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
function foo() {
42
print(arguments);
53
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
async function* foo() {
42
yield 1;
53
}

tests/src/diagnostics/noAwaitForOf.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export {};
2-
31
async function foo() {
4-
for await (const x of [1, 2, 3]) {}
2+
for await (const x of [1, 2, 3]) {
3+
}
54
}

tests/src/diagnostics/noBigInt.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
print(1n);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
class X {
42
__tostring() {}
53
}

tests/src/diagnostics/noComma.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
const x = (print(), 1);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
print(Array);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
debugger;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export {};
2-
31
let a: boolean;
42
let b: string | void;
53

6-
print([a, b] = pcall(() => {}));
4+
print(([a, b] = pcall(() => {})));

tests/src/diagnostics/noEnumMerging.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
enum A {
42
a,
53
}
-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
print(false == false);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
print(game.Archivable != false);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
for (const x in game) {
42
print(x);
53
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
3-
print(function foo() {})
1+
print(function foo() {});

tests/src/diagnostics/noGetterSetter.1.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
class X {
42
get x() {
53
return "x";
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
class X {
42
set x(value: number) {}
53
}

tests/src/diagnostics/noGlobalThis.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
print(globalThis);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
game.ChildAdded.Connect(game.Destroy);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
export {};
2-
31
const array = [1, 2, 3];
42
const x = array.push;

tests/src/diagnostics/noIndexWithoutCall.3.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export {};
2-
31
const array = [1, 2, 3];
42
const { push } = array;
53
const otherArray = [1, 2];
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
const nil = 1;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export {};
2-
31
const $id = 1;

0 commit comments

Comments
 (0)