Skip to content

Commit ea93e92

Browse files
committed
Fix APISample tests to not depend on the existence of the ts namespace
The way we pull in the types for typescript in these tests only works when we include typescriptServices.d.ts into the project, which declares a global namespace, which then is reexported as the typescript package. This reexport is already what the current typescript.d.ts does, but now that we don't have the namespace at all, we can't do this. Instead, simulate the typescript package directly and point it at the correct d.ts file. This is a good chagne regardless of the module transform, and could be cherry-picked back to main early.
1 parent d375574 commit ea93e92

18 files changed

+98
-86
lines changed

tests/baselines/reference/APISample_Watch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_Watch.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_Watch.ts]

tests/baselines/reference/APISample_WatchWithDefaults.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_WatchWithDefaults.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_WatchWithDefaults.ts]

tests/baselines/reference/APISample_WatchWithOwnWatchHost.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_WatchWithOwnWatchHost.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_WatchWithOwnWatchHost.ts]

tests/baselines/reference/APISample_compile.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_compile.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_compile.ts]
@@ -75,5 +76,5 @@ function compile(fileNames, options) {
7576
exports.compile = compile;
7677
compile(process.argv.slice(2), {
7778
noEmitOnError: true, noImplicitAny: true,
78-
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
79+
target: 1 /* ts.ScriptTarget.ES5 */, module: ts.ModuleKind.CommonJS
7980
});

tests/baselines/reference/APISample_jsdoc.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_jsdoc.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_jsdoc.ts]
@@ -177,10 +178,10 @@ function getAnnotations(node) {
177178
}
178179
// these examples are artificial and mostly nonsensical
179180
function parseSpecificTags(node) {
180-
if (node.kind === ts.SyntaxKind.Parameter) {
181+
if (node.kind === 166 /* ts.SyntaxKind.Parameter */) {
181182
return ts.getJSDocParameterTags(node);
182183
}
183-
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
184+
if (node.kind === 259 /* ts.SyntaxKind.FunctionDeclaration */) {
184185
var func = node;
185186
if (ts.hasJSDocParameterTags(func)) {
186187
var flat = [];
@@ -194,11 +195,11 @@ function parseSpecificTags(node) {
194195
}
195196
}
196197
function getReturnTypeFromJSDoc(node) {
197-
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
198+
if (node.kind === 259 /* ts.SyntaxKind.FunctionDeclaration */) {
198199
return ts.getJSDocReturnType(node);
199200
}
200201
var type = ts.getJSDocType(node);
201-
if (type && type.kind === ts.SyntaxKind.FunctionType) {
202+
if (type && type.kind === 181 /* ts.SyntaxKind.FunctionType */) {
202203
return type.type;
203204
}
204205
}

tests/baselines/reference/APISample_linter.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_linter.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_linter.ts]
@@ -68,7 +69,8 @@ fileNames.forEach(fileName => {
6869

6970
// delint it
7071
delint(sourceFile);
71-
});
72+
});
73+
7274

7375
//// [APISample_linter.js]
7476
"use strict";
@@ -84,28 +86,28 @@ function delint(sourceFile) {
8486
delintNode(sourceFile);
8587
function delintNode(node) {
8688
switch (node.kind) {
87-
case ts.SyntaxKind.ForStatement:
88-
case ts.SyntaxKind.ForInStatement:
89-
case ts.SyntaxKind.WhileStatement:
90-
case ts.SyntaxKind.DoStatement:
91-
if (node.statement.kind !== ts.SyntaxKind.Block) {
89+
case 245 /* ts.SyntaxKind.ForStatement */:
90+
case 246 /* ts.SyntaxKind.ForInStatement */:
91+
case 244 /* ts.SyntaxKind.WhileStatement */:
92+
case 243 /* ts.SyntaxKind.DoStatement */:
93+
if (node.statement.kind !== 238 /* ts.SyntaxKind.Block */) {
9294
report(node, "A looping statement's contents should be wrapped in a block body.");
9395
}
9496
break;
95-
case ts.SyntaxKind.IfStatement:
97+
case 242 /* ts.SyntaxKind.IfStatement */:
9698
var ifStatement = node;
97-
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
99+
if (ifStatement.thenStatement.kind !== 238 /* ts.SyntaxKind.Block */) {
98100
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
99101
}
100102
if (ifStatement.elseStatement &&
101-
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
102-
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
103+
ifStatement.elseStatement.kind !== 238 /* ts.SyntaxKind.Block */ &&
104+
ifStatement.elseStatement.kind !== 242 /* ts.SyntaxKind.IfStatement */) {
103105
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
104106
}
105107
break;
106-
case ts.SyntaxKind.BinaryExpression:
108+
case 223 /* ts.SyntaxKind.BinaryExpression */:
107109
var op = node.operatorToken.kind;
108-
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
110+
if (op === 34 /* ts.SyntaxKind.EqualsEqualsToken */ || op == 35 /* ts.SyntaxKind.ExclamationEqualsToken */) {
109111
report(node, "Use '===' and '!=='.");
110112
}
111113
break;
@@ -121,7 +123,7 @@ exports.delint = delint;
121123
var fileNames = process.argv.slice(2);
122124
fileNames.forEach(function (fileName) {
123125
// Parse a file
124-
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015, /*setParentNodes */ true);
126+
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), 2 /* ts.ScriptTarget.ES2015 */, /*setParentNodes */ true);
125127
// delint it
126128
delint(sourceFile);
127129
});

tests/baselines/reference/APISample_parseConfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_parseConfig.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_parseConfig.ts]
@@ -40,7 +41,8 @@ export function createProgram(rootFiles: string[], compilerOptionsJson: string):
4041
return undefined;
4142
}
4243
return ts.createProgram(rootFiles, settings.options);
43-
}
44+
}
45+
4446

4547
//// [APISample_parseConfig.js]
4648
"use strict";

tests/baselines/reference/APISample_transform.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_transform.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_transform.ts]
@@ -20,7 +21,8 @@ const source = "let x: string = 'string'";
2021

2122
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
2223

23-
console.log(JSON.stringify(result));
24+
console.log(JSON.stringify(result));
25+
2426

2527
//// [APISample_transform.js]
2628
"use strict";

tests/baselines/reference/APISample_watcher.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_watcher.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_watcher.ts]

tests/cases/compiler/APISample_Watch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_Watch.ts

tests/cases/compiler/APISample_WatchWithDefaults.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_WatchWithDefaults.ts

tests/cases/compiler/APISample_WatchWithOwnWatchHost.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_WatchWithOwnWatchHost.ts

tests/cases/compiler/APISample_compile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_compile.ts

tests/cases/compiler/APISample_jsdoc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_jsdoc.ts

tests/cases/compiler/APISample_linter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_linter.ts
@@ -72,4 +72,4 @@ fileNames.forEach(fileName => {
7272

7373
// delint it
7474
delint(sourceFile);
75-
});
75+
});

tests/cases/compiler/APISample_parseConfig.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_parseConfig.ts
@@ -44,4 +44,4 @@ export function createProgram(rootFiles: string[], compilerOptionsJson: string):
4444
return undefined;
4545
}
4646
return ts.createProgram(rootFiles, settings.options);
47-
}
47+
}

tests/cases/compiler/APISample_transform.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_transform.ts
@@ -24,4 +24,4 @@ const source = "let x: string = 'string'";
2424

2525
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
2626

27-
console.log(JSON.stringify(result));
27+
console.log(JSON.stringify(result));

0 commit comments

Comments
 (0)