Skip to content

Commit 3fc1f26

Browse files
authored
Update tests in prep for ES5 deprecation, target default change (#63066)
1 parent c1592ad commit 3fc1f26

File tree

23,058 files changed

+416516
-99734
lines changed

Some content is hidden

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

23,058 files changed

+416516
-99734
lines changed

src/testRunner/unittests/tsserver/getEditsForFileRename.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ describe("unittests:: tsserver:: getEditsForFileRename::", () => {
2727
};
2828
const tsconfig: File = {
2929
path: "/home/src/projects/project/tsconfig.json",
30-
content: "{}",
30+
content: `{ "compilerOptions": { "module": "commonjs" } }`,
3131
};
3232

3333
const host = TestServerHost.createServerHost([userTs, newTs, tsconfig]);
34-
const options: ts.CompilerOptions = {};
34+
const options: ts.CompilerOptions = { module: ts.ModuleKind.CommonJS };
3535
const moduleResolutionCache = ts.createModuleResolutionCache(host.getCurrentDirectory(), ts.createGetCanonicalFileName(host.useCaseSensitiveFileNames), options);
3636
const lsHost: ts.LanguageServiceHost = {
3737
getCompilationSettings: () => options,

src/testRunner/unittests/tsserver/typingsInstaller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,7 @@ describe("unittests:: tsserver:: typingsInstaller:: recomputing resolutions of u
24952495
host,
24962496
installAction: typingFiles,
24972497
});
2498+
setCompilerOptionsForInferredProjectsRequestForSession({ module: ts.ModuleKind.CommonJS }, session);
24982499
openFilesForSession([app], session);
24992500

25002501
const proj = session.getProjectService().inferredProjects[0];

tests/baselines/reference/2dArrays.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@ class Board {
1818
}
1919

2020
//// [2dArrays.js]
21-
var Cell = /** @class */ (function () {
22-
function Cell() {
23-
}
24-
return Cell;
25-
}());
26-
var Ship = /** @class */ (function () {
27-
function Ship() {
21+
class Cell {
22+
}
23+
class Ship {
24+
constructor() {
2825
this.isSunk = false;
2926
}
30-
return Ship;
31-
}());
32-
var Board = /** @class */ (function () {
33-
function Board() {
27+
}
28+
class Board {
29+
constructor() {
3430
this.ships = [];
3531
this.cells = [];
3632
}
37-
Board.prototype.allShipsSunk = function () {
33+
allShipsSunk() {
3834
return this.ships.every(function (val) { return val.isSunk; });
39-
};
40-
return Board;
41-
}());
35+
}
36+
}

tests/baselines/reference/APISample_Watch.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ watchMain();
9191
* Please log a "breaking change" issue for any API breaking change affecting this issue
9292
*/
9393
Object.defineProperty(exports, "__esModule", { value: true });
94-
var ts = require("typescript");
95-
var formatHost = {
96-
getCanonicalFileName: function (path) { return path; },
94+
const ts = require("typescript");
95+
const formatHost = {
96+
getCanonicalFileName: path => path,
9797
getCurrentDirectory: ts.sys.getCurrentDirectory,
98-
getNewLine: function () { return ts.sys.newLine; },
98+
getNewLine: () => ts.sys.newLine,
9999
};
100100
function watchMain() {
101-
var configPath = ts.findConfigFile(/*searchPath*/ "./", ts.sys.fileExists, "tsconfig.json");
101+
const configPath = ts.findConfigFile(/*searchPath*/ "./", ts.sys.fileExists, "tsconfig.json");
102102
if (!configPath) {
103103
throw new Error("Could not find a valid 'tsconfig.json'.");
104104
}
@@ -112,16 +112,16 @@ function watchMain() {
112112
// Between `createEmitAndSemanticDiagnosticsBuilderProgram` and `createSemanticDiagnosticsBuilderProgram`, the only difference is emit.
113113
// For pure type-checking scenarios, or when another tool/process handles emit, using `createSemanticDiagnosticsBuilderProgram` may be more desirable.
114114
// Note that there is another overload for `createWatchCompilerHost` that takes a set of root files.
115-
var host = ts.createWatchCompilerHost(configPath, {}, ts.sys, ts.createSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportWatchStatusChanged);
115+
const host = ts.createWatchCompilerHost(configPath, {}, ts.sys, ts.createSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportWatchStatusChanged);
116116
// You can technically override any given hook on the host, though you probably don't need to.
117117
// Note that we're assuming `origCreateProgram` and `origPostProgramCreate` doesn't use `this` at all.
118-
var origCreateProgram = host.createProgram;
119-
host.createProgram = function (rootNames, options, host, oldProgram) {
118+
const origCreateProgram = host.createProgram;
119+
host.createProgram = (rootNames, options, host, oldProgram) => {
120120
console.log("** We're about to create the program! **");
121121
return origCreateProgram(rootNames, options, host, oldProgram);
122122
};
123-
var origPostProgramCreate = host.afterProgramCreate;
124-
host.afterProgramCreate = function (program) {
123+
const origPostProgramCreate = host.afterProgramCreate;
124+
host.afterProgramCreate = program => {
125125
console.log("** We finished making the program! **");
126126
origPostProgramCreate(program);
127127
};

tests/baselines/reference/APISample_WatchWithDefaults.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ watchMain();
6363
* Please log a "breaking change" issue for any API breaking change affecting this issue
6464
*/
6565
Object.defineProperty(exports, "__esModule", { value: true });
66-
var ts = require("typescript");
66+
const ts = require("typescript");
6767
function watchMain() {
68-
var configPath = ts.findConfigFile(/*searchPath*/ "./", ts.sys.fileExists, "tsconfig.json");
68+
const configPath = ts.findConfigFile(/*searchPath*/ "./", ts.sys.fileExists, "tsconfig.json");
6969
if (!configPath) {
7070
throw new Error("Could not find a valid 'tsconfig.json'.");
7171
}
@@ -79,16 +79,16 @@ function watchMain() {
7979
// Between `createEmitAndSemanticDiagnosticsBuilderProgram` and `createSemanticDiagnosticsBuilderProgram`, the only difference is emit.
8080
// For pure type-checking scenarios, or when another tool/process handles emit, using `createSemanticDiagnosticsBuilderProgram` may be more desirable.
8181
// Note that there is another overload for `createWatchCompilerHost` that takes a set of root files.
82-
var host = ts.createWatchCompilerHost(configPath, {}, ts.sys);
82+
const host = ts.createWatchCompilerHost(configPath, {}, ts.sys);
8383
// You can technically override any given hook on the host, though you probably don't need to.
8484
// Note that we're assuming `origCreateProgram` and `origPostProgramCreate` doesn't use `this` at all.
85-
var origCreateProgram = host.createProgram;
86-
host.createProgram = function (rootNames, options, host, oldProgram) {
85+
const origCreateProgram = host.createProgram;
86+
host.createProgram = (rootNames, options, host, oldProgram) => {
8787
console.log("** We're about to create the program! **");
8888
return origCreateProgram(rootNames, options, host, oldProgram);
8989
};
90-
var origPostProgramCreate = host.afterProgramCreate;
91-
host.afterProgramCreate = function (program) {
90+
const origPostProgramCreate = host.afterProgramCreate;
91+
host.afterProgramCreate = program => {
9292
console.log("** We finished making the program! **");
9393
origPostProgramCreate(program);
9494
};

tests/baselines/reference/APISample_WatchWithOwnWatchHost.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ watchMain();
7070
* Please log a "breaking change" issue for any API breaking change affecting this issue
7171
*/
7272
Object.defineProperty(exports, "__esModule", { value: true });
73-
var ts = require("typescript");
73+
const ts = require("typescript");
7474
function watchMain() {
7575
// get list of files and compiler options somehow
76-
var files = [];
77-
var options = {};
78-
var host = {
76+
const files = [];
77+
const options = {};
78+
const host = {
7979
rootFiles: files,
80-
options: options,
81-
useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; },
82-
getNewLine: function () { return ts.sys.newLine; },
80+
options,
81+
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
82+
getNewLine: () => ts.sys.newLine,
8383
getCurrentDirectory: ts.sys.getCurrentDirectory,
84-
getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(options); },
84+
getDefaultLibFileName: options => ts.getDefaultLibFilePath(options),
8585
fileExists: ts.sys.fileExists,
8686
readFile: ts.sys.readFile,
8787
directoryExists: ts.sys.directoryExists,
@@ -94,13 +94,13 @@ function watchMain() {
9494
};
9595
// You can technically override any given hook on the host, though you probably don't need to.
9696
// Note that we're assuming `origCreateProgram` and `origPostProgramCreate` doesn't use `this` at all.
97-
var origCreateProgram = host.createProgram;
98-
host.createProgram = function (rootNames, options, host, oldProgram) {
97+
const origCreateProgram = host.createProgram;
98+
host.createProgram = (rootNames, options, host, oldProgram) => {
9999
console.log("** We're about to create the program! **");
100100
return origCreateProgram(rootNames, options, host, oldProgram);
101101
};
102-
var origPostProgramCreate = host.afterProgramCreate;
103-
host.afterProgramCreate = function (program) {
102+
const origPostProgramCreate = host.afterProgramCreate;
103+
host.afterProgramCreate = program => {
104104
console.log("** We finished making the program! **");
105105
origPostProgramCreate(program);
106106
};

tests/baselines/reference/APISample_compile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ compile(process.argv.slice(2), {
5555
*/
5656
Object.defineProperty(exports, "__esModule", { value: true });
5757
exports.compile = compile;
58-
var ts = require("typescript");
58+
const ts = require("typescript");
5959
function compile(fileNames, options) {
6060
var program = ts.createProgram(fileNames, options);
6161
var emitResult = program.emit();
6262
var allDiagnostics = ts.getPreEmitDiagnostics(program);
63-
allDiagnostics.forEach(function (diagnostic) {
63+
allDiagnostics.forEach(diagnostic => {
6464
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
6565
if (!diagnostic.file) {
6666
console.log(message);
6767
return;
6868
}
69-
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
70-
console.log("".concat(diagnostic.file.fileName, " (").concat(line + 1, ",").concat(character + 1, "): ").concat(message));
69+
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
70+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
7171
});
7272
var exitCode = emitResult.emitSkipped ? 1 : 0;
73-
console.log("Process exiting with code '".concat(exitCode, "'."));
73+
console.log(`Process exiting with code '${exitCode}'.`);
7474
process.exit(exitCode);
7575
}
7676
compile(process.argv.slice(2), {

tests/baselines/reference/APISample_jsdoc.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,26 +163,25 @@ var __importStar = (this && this.__importStar) || (function () {
163163
};
164164
})();
165165
Object.defineProperty(exports, "__esModule", { value: true });
166-
var ts = __importStar(require("typescript"));
166+
const ts = __importStar(require("typescript"));
167167
// excerpted from https://github.com/YousefED/typescript-json-schema
168168
// (converted from a method and modified; for example, `this: any` to compensate, among other changes)
169169
function parseCommentsIntoDefinition(symbol, definition, otherAnnotations) {
170-
var _this = this;
171170
if (!symbol) {
172171
return;
173172
}
174173
// the comments for a symbol
175-
var comments = symbol.getDocumentationComment(undefined);
174+
let comments = symbol.getDocumentationComment(undefined);
176175
if (comments.length) {
177-
definition.description = comments.map(function (comment) { return comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n"); }).join("");
176+
definition.description = comments.map(comment => comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n")).join("");
178177
}
179178
// jsdocs are separate from comments
180-
var jsdocs = symbol.getJsDocTags(this.checker);
181-
jsdocs.forEach(function (doc) {
179+
const jsdocs = symbol.getJsDocTags(this.checker);
180+
jsdocs.forEach(doc => {
182181
// if we have @TJS-... annotations, we have to parse them
183-
var name = doc.name, text = doc.text;
184-
if (_this.userValidationKeywords[name]) {
185-
definition[name] = _this.parseValue(text);
182+
const { name, text } = doc;
183+
if (this.userValidationKeywords[name]) {
184+
definition[name] = this.parseValue(text);
186185
}
187186
else {
188187
// special annotations
@@ -191,17 +190,16 @@ function parseCommentsIntoDefinition(symbol, definition, otherAnnotations) {
191190
});
192191
}
193192
function getAnnotations(node) {
194-
var _this = this;
195-
var symbol = node.symbol;
193+
const symbol = node.symbol;
196194
if (!symbol) {
197195
return undefined;
198196
}
199-
var jsDocTags = symbol.getJsDocTags(this.checker);
197+
const jsDocTags = symbol.getJsDocTags(this.checker);
200198
if (!jsDocTags || !jsDocTags.length) {
201199
return undefined;
202200
}
203-
var annotations = jsDocTags.reduce(function (result, jsDocTag) {
204-
var value = _this.parseJsDocTag(jsDocTag);
201+
const annotations = jsDocTags.reduce((result, jsDocTag) => {
202+
const value = this.parseJsDocTag(jsDocTag);
205203
if (value !== undefined) {
206204
result[jsDocTag.name] = value;
207205
}
@@ -215,13 +213,12 @@ function parseSpecificTags(node) {
215213
return ts.getJSDocParameterTags(node);
216214
}
217215
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
218-
var func = node;
216+
const func = node;
219217
if (ts.hasJSDocParameterTags(func)) {
220-
var flat = [];
221-
for (var _i = 0, _a = func.parameters.map(ts.getJSDocParameterTags); _i < _a.length; _i++) {
222-
var tags = _a[_i];
218+
const flat = [];
219+
for (const tags of func.parameters.map(ts.getJSDocParameterTags)) {
223220
if (tags)
224-
flat.push.apply(flat, tags);
221+
flat.push(...tags);
225222
}
226223
return flat;
227224
}
@@ -231,7 +228,7 @@ function getReturnTypeFromJSDoc(node) {
231228
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
232229
return ts.getJSDocReturnType(node);
233230
}
234-
var type = ts.getJSDocType(node);
231+
let type = ts.getJSDocType(node);
235232
if (type && type.kind === ts.SyntaxKind.FunctionType) {
236233
return type.type;
237234
}
@@ -240,11 +237,11 @@ function getAllTags(node) {
240237
ts.getJSDocTags(node);
241238
}
242239
function getSomeOtherTags(node) {
243-
var tags = [];
240+
const tags = [];
244241
tags.push(ts.getJSDocAugmentsTag(node));
245242
tags.push(ts.getJSDocClassTag(node));
246243
tags.push(ts.getJSDocReturnTag(node));
247-
var type = ts.getJSDocTypeTag(node);
244+
const type = ts.getJSDocTypeTag(node);
248245
if (type) {
249246
tags.push(type);
250247
}

tests/baselines/reference/APISample_linter.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var __importStar = (this && this.__importStar) || (function () {
114114
})();
115115
Object.defineProperty(exports, "__esModule", { value: true });
116116
exports.delint = delint;
117-
var ts = __importStar(require("typescript"));
117+
const ts = __importStar(require("typescript"));
118118
function delint(sourceFile) {
119119
delintNode(sourceFile);
120120
function delintNode(node) {
@@ -128,7 +128,7 @@ function delint(sourceFile) {
128128
}
129129
break;
130130
case ts.SyntaxKind.IfStatement:
131-
var ifStatement = node;
131+
let ifStatement = node;
132132
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
133133
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
134134
}
@@ -139,7 +139,7 @@ function delint(sourceFile) {
139139
}
140140
break;
141141
case ts.SyntaxKind.BinaryExpression:
142-
var op = node.operatorToken.kind;
142+
let op = node.operatorToken.kind;
143143
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
144144
report(node, "Use '===' and '!=='.");
145145
}
@@ -148,14 +148,14 @@ function delint(sourceFile) {
148148
ts.forEachChild(node, delintNode);
149149
}
150150
function report(node, message) {
151-
var _a = sourceFile.getLineAndCharacterOfPosition(node.getStart()), line = _a.line, character = _a.character;
152-
console.log("".concat(sourceFile.fileName, " (").concat(line + 1, ",").concat(character + 1, "): ").concat(message));
151+
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
152+
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
153153
}
154154
}
155-
var fileNames = process.argv.slice(2);
156-
fileNames.forEach(function (fileName) {
155+
const fileNames = process.argv.slice(2);
156+
fileNames.forEach(fileName => {
157157
// Parse a file
158-
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015, /*setParentNodes */ true);
158+
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015, /*setParentNodes */ true);
159159
// delint it
160160
delint(sourceFile);
161161
});

tests/baselines/reference/APISample_parseConfig.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,23 @@ export function createProgram(rootFiles: string[], compilerOptionsJson: string):
5353
*/
5454
Object.defineProperty(exports, "__esModule", { value: true });
5555
exports.createProgram = createProgram;
56-
var ts = require("typescript");
56+
const ts = require("typescript");
5757
function printError(error) {
5858
if (!error) {
5959
return;
6060
}
61-
console.log("".concat(error.file && error.file.fileName, ": ").concat(error.messageText));
61+
console.log(`${error.file && error.file.fileName}: ${error.messageText}`);
6262
}
6363
function createProgram(rootFiles, compilerOptionsJson) {
64-
var _a = ts.parseConfigFileTextToJson("tsconfig.json", compilerOptionsJson), config = _a.config, error = _a.error;
64+
const { config, error } = ts.parseConfigFileTextToJson("tsconfig.json", compilerOptionsJson);
6565
if (error) {
6666
printError(error);
6767
return undefined;
6868
}
69-
var basePath = process.cwd();
70-
var settings = ts.convertCompilerOptionsFromJson(config.config["compilerOptions"], basePath);
69+
const basePath = process.cwd();
70+
const settings = ts.convertCompilerOptionsFromJson(config.config["compilerOptions"], basePath);
7171
if (!settings.options) {
72-
for (var _i = 0, _b = settings.errors; _i < _b.length; _i++) {
73-
var err = _b[_i];
72+
for (const err of settings.errors) {
7473
printError(err);
7574
}
7675
return undefined;

0 commit comments

Comments
 (0)