Skip to content

Commit 8ceebaa

Browse files
committed
Update APISample tests for 1.5-alpha release
1 parent 35d8536 commit 8ceebaa

13 files changed

+197
-549
lines changed

tests/baselines/reference/APISample_compile.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
2121
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
2222

2323
allDiagnostics.forEach(diagnostic => {
24-
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
25-
console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`);
24+
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
25+
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
26+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
2627
});
2728

2829
var exitCode = emitResult.emitSkipped ? 1 : 0;
@@ -2040,8 +2041,9 @@ function compile(fileNames, options) {
20402041
var emitResult = program.emit();
20412042
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
20422043
allDiagnostics.forEach(function (diagnostic) {
2043-
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
2044-
console.log(diagnostic.file.fileName + " (" + (lineChar.line + 1) + "," + (lineChar.character + 1) + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL));
2044+
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
2045+
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
2046+
console.log(diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message);
20452047
});
20462048
var exitCode = emitResult.emitSkipped ? 1 : 0;
20472049
console.log("Process exiting with code '" + exitCode + "'.");

tests/baselines/reference/APISample_compile.types

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
5656
>diagnostics : ts.Diagnostic[]
5757

5858
allDiagnostics.forEach(diagnostic => {
59-
>allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }) : void
59+
>allDiagnostics.forEach(diagnostic => { var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); }) : void
6060
>allDiagnostics.forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void
6161
>allDiagnostics : ts.Diagnostic[]
6262
>forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void
63-
>diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); } : (diagnostic: ts.Diagnostic) => void
63+
>diagnostic => { var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); } : (diagnostic: ts.Diagnostic) => void
6464
>diagnostic : ts.Diagnostic
6565

66-
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
67-
>lineChar : ts.LineAndCharacter
66+
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
67+
>line : number
68+
>character : number
6869
>diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start) : ts.LineAndCharacter
6970
>diagnostic.file.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
7071
>diagnostic.file : ts.SourceFile
@@ -75,8 +76,18 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
7576
>diagnostic : ts.Diagnostic
7677
>start : number
7778

78-
console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`);
79-
>console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`) : any
79+
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
80+
>message : string
81+
>ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n') : string
82+
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
83+
>ts : typeof ts
84+
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
85+
>diagnostic.messageText : string | ts.DiagnosticMessageChain
86+
>diagnostic : ts.Diagnostic
87+
>messageText : string | ts.DiagnosticMessageChain
88+
89+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
90+
>console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`) : any
8091
>console.log : any
8192
>console : any
8293
>log : any
@@ -85,24 +96,11 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
8596
>diagnostic : ts.Diagnostic
8697
>file : ts.SourceFile
8798
>fileName : string
88-
>lineChar.line + 1 : number
89-
>lineChar.line : number
90-
>lineChar : ts.LineAndCharacter
99+
>line + 1 : number
91100
>line : number
92-
>lineChar.character + 1 : number
93-
>lineChar.character : number
94-
>lineChar : ts.LineAndCharacter
101+
>character + 1 : number
95102
>character : number
96-
>ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL) : string
97-
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
98-
>ts : typeof ts
99-
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
100-
>diagnostic.messageText : string | ts.DiagnosticMessageChain
101-
>diagnostic : ts.Diagnostic
102-
>messageText : string | ts.DiagnosticMessageChain
103-
>os.EOL : any
104-
>os : any
105-
>EOL : any
103+
>message : string
106104

107105
});
108106

tests/baselines/reference/APISample_linter.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
declare var process: any;
1212
declare var console: any;
13-
declare var fs: any;
13+
declare var readFileSync: any;
1414

15-
import ts = require("typescript");
15+
import * as ts from "typescript";
1616

1717
export function delint(sourceFile: ts.SourceFile) {
1818
delintNode(sourceFile);
@@ -27,21 +27,22 @@ export function delint(sourceFile: ts.SourceFile) {
2727
report(node, "A looping statement's contents should be wrapped in a block body.");
2828
}
2929
break;
30+
3031
case ts.SyntaxKind.IfStatement:
31-
var ifStatement = (<ts.IfStatement>node);
32+
let ifStatement = (<ts.IfStatement>node);
3233
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
3334
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
3435
}
3536
if (ifStatement.elseStatement &&
36-
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
37+
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
38+
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
3739
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
3840
}
3941
break;
4042

4143
case ts.SyntaxKind.BinaryExpression:
42-
var op = (<ts.BinaryExpression>node).operatorToken.kind;
43-
44-
if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
44+
let op = (<ts.BinaryExpression>node).operatorToken.kind;
45+
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
4546
report(node, "Use '===' and '!=='.")
4647
}
4748
break;
@@ -51,20 +52,19 @@ export function delint(sourceFile: ts.SourceFile) {
5152
}
5253

5354
function report(node: ts.Node, message: string) {
54-
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
55-
console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`)
55+
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
56+
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
5657
}
5758
}
5859

59-
var fileNames = process.argv.slice(2);
60+
const fileNames = process.argv.slice(2);
6061
fileNames.forEach(fileName => {
6162
// Parse a file
62-
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
63+
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
6364

6465
// delint it
6566
delint(sourceFile);
66-
});
67-
67+
});
6868
//// [typescript.d.ts]
6969
/*! *****************************************************************************
7070
Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2084,29 +2084,30 @@ function delint(sourceFile) {
20842084
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
20852085
}
20862086
if (ifStatement.elseStatement &&
2087-
ifStatement.elseStatement.kind !== 179 /* Block */ && ifStatement.elseStatement.kind !== 183 /* IfStatement */) {
2087+
ifStatement.elseStatement.kind !== 179 /* Block */ &&
2088+
ifStatement.elseStatement.kind !== 183 /* IfStatement */) {
20882089
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
20892090
}
20902091
break;
20912092
case 169 /* BinaryExpression */:
20922093
var op = node.operatorToken.kind;
2093-
if (op === 28 /* EqualsEqualsToken */ || op === 29 /* ExclamationEqualsToken */) {
2094+
if (op === 28 /* EqualsEqualsToken */ || op == 29 /* ExclamationEqualsToken */) {
20942095
report(node, "Use '===' and '!=='.");
20952096
}
20962097
break;
20972098
}
20982099
ts.forEachChild(node, delintNode);
20992100
}
21002101
function report(node, message) {
2101-
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
2102-
console.log(sourceFile.fileName + " (" + (lineChar.line + 1) + "," + (lineChar.character + 1) + "): " + message);
2102+
var _a = sourceFile.getLineAndCharacterOfPosition(node.getStart()), line = _a.line, character = _a.character;
2103+
console.log(sourceFile.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message);
21032104
}
21042105
}
21052106
exports.delint = delint;
21062107
var fileNames = process.argv.slice(2);
21072108
fileNames.forEach(function (fileName) {
21082109
// Parse a file
2109-
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), 2 /* ES6 */, true);
2110+
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), 2 /* ES6 */, true);
21102111
// delint it
21112112
delint(sourceFile);
21122113
});

tests/baselines/reference/APISample_linter.types

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ declare var process: any;
1212
declare var console: any;
1313
>console : any
1414

15-
declare var fs: any;
16-
>fs : any
15+
declare var readFileSync: any;
16+
>readFileSync : any
1717

18-
import ts = require("typescript");
18+
import * as ts from "typescript";
1919
>ts : typeof ts
2020

2121
export function delint(sourceFile: ts.SourceFile) {
@@ -91,14 +91,15 @@ export function delint(sourceFile: ts.SourceFile) {
9191
>node : ts.Node
9292
}
9393
break;
94+
9495
case ts.SyntaxKind.IfStatement:
9596
>ts.SyntaxKind.IfStatement : ts.SyntaxKind
9697
>ts.SyntaxKind : typeof ts.SyntaxKind
9798
>ts : typeof ts
9899
>SyntaxKind : typeof ts.SyntaxKind
99100
>IfStatement : ts.SyntaxKind
100101

101-
var ifStatement = (<ts.IfStatement>node);
102+
let ifStatement = (<ts.IfStatement>node);
102103
>ifStatement : ts.IfStatement
103104
>(<ts.IfStatement>node) : ts.IfStatement
104105
><ts.IfStatement>node : ts.IfStatement
@@ -127,13 +128,13 @@ export function delint(sourceFile: ts.SourceFile) {
127128
>thenStatement : ts.Statement
128129
}
129130
if (ifStatement.elseStatement &&
130-
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
131+
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
131132
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block : boolean
132133
>ifStatement.elseStatement : ts.Statement
133134
>ifStatement : ts.IfStatement
134135
>elseStatement : ts.Statement
135136

136-
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
137+
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
137138
>ifStatement.elseStatement.kind !== ts.SyntaxKind.Block : boolean
138139
>ifStatement.elseStatement.kind : ts.SyntaxKind
139140
>ifStatement.elseStatement : ts.Statement
@@ -145,6 +146,8 @@ export function delint(sourceFile: ts.SourceFile) {
145146
>ts : typeof ts
146147
>SyntaxKind : typeof ts.SyntaxKind
147148
>Block : ts.SyntaxKind
149+
150+
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
148151
>ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
149152
>ifStatement.elseStatement.kind : ts.SyntaxKind
150153
>ifStatement.elseStatement : ts.Statement
@@ -173,7 +176,7 @@ export function delint(sourceFile: ts.SourceFile) {
173176
>SyntaxKind : typeof ts.SyntaxKind
174177
>BinaryExpression : ts.SyntaxKind
175178

176-
var op = (<ts.BinaryExpression>node).operatorToken.kind;
179+
let op = (<ts.BinaryExpression>node).operatorToken.kind;
177180
>op : ts.SyntaxKind
178181
>(<ts.BinaryExpression>node).operatorToken.kind : ts.SyntaxKind
179182
>(<ts.BinaryExpression>node).operatorToken : ts.Node
@@ -185,16 +188,16 @@ export function delint(sourceFile: ts.SourceFile) {
185188
>operatorToken : ts.Node
186189
>kind : ts.SyntaxKind
187190

188-
if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
189-
>op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken : boolean
191+
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
192+
>op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken : boolean
190193
>op === ts.SyntaxKind.EqualsEqualsToken : boolean
191194
>op : ts.SyntaxKind
192195
>ts.SyntaxKind.EqualsEqualsToken : ts.SyntaxKind
193196
>ts.SyntaxKind : typeof ts.SyntaxKind
194197
>ts : typeof ts
195198
>SyntaxKind : typeof ts.SyntaxKind
196199
>EqualsEqualsToken : ts.SyntaxKind
197-
>op === ts.SyntaxKind.ExclamationEqualsToken : boolean
200+
>op == ts.SyntaxKind.ExclamationEqualsToken : boolean
198201
>op : ts.SyntaxKind
199202
>ts.SyntaxKind.ExclamationEqualsToken : ts.SyntaxKind
200203
>ts.SyntaxKind : typeof ts.SyntaxKind
@@ -226,8 +229,9 @@ export function delint(sourceFile: ts.SourceFile) {
226229
>Node : ts.Node
227230
>message : string
228231

229-
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
230-
>lineChar : ts.LineAndCharacter
232+
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
233+
>line : number
234+
>character : number
231235
>sourceFile.getLineAndCharacterOfPosition(node.getStart()) : ts.LineAndCharacter
232236
>sourceFile.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
233237
>sourceFile : ts.SourceFile
@@ -237,27 +241,23 @@ export function delint(sourceFile: ts.SourceFile) {
237241
>node : ts.Node
238242
>getStart : (sourceFile?: ts.SourceFile) => number
239243

240-
console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`)
241-
>console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`) : any
244+
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
245+
>console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`) : any
242246
>console.log : any
243247
>console : any
244248
>log : any
245249
>sourceFile.fileName : string
246250
>sourceFile : ts.SourceFile
247251
>fileName : string
248-
>lineChar.line + 1 : number
249-
>lineChar.line : number
250-
>lineChar : ts.LineAndCharacter
252+
>line + 1 : number
251253
>line : number
252-
>lineChar.character + 1 : number
253-
>lineChar.character : number
254-
>lineChar : ts.LineAndCharacter
254+
>character + 1 : number
255255
>character : number
256256
>message : string
257257
}
258258
}
259259

260-
var fileNames = process.argv.slice(2);
260+
const fileNames = process.argv.slice(2);
261261
>fileNames : any
262262
>process.argv.slice(2) : any
263263
>process.argv.slice : any
@@ -267,26 +267,24 @@ var fileNames = process.argv.slice(2);
267267
>slice : any
268268

269269
fileNames.forEach(fileName => {
270-
>fileNames.forEach(fileName => { // Parse a file var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);}) : any
270+
>fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);}) : any
271271
>fileNames.forEach : any
272272
>fileNames : any
273273
>forEach : any
274-
>fileName => { // Parse a file var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);} : (fileName: any) => void
274+
>fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);} : (fileName: any) => void
275275
>fileName : any
276276

277277
// Parse a file
278-
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
278+
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
279279
>sourceFile : ts.SourceFile
280-
>ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true) : ts.SourceFile
280+
>ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true) : ts.SourceFile
281281
>ts.createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
282282
>ts : typeof ts
283283
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
284284
>fileName : any
285-
>fs.readFileSync(fileName).toString() : any
286-
>fs.readFileSync(fileName).toString : any
287-
>fs.readFileSync(fileName) : any
288-
>fs.readFileSync : any
289-
>fs : any
285+
>readFileSync(fileName).toString() : any
286+
>readFileSync(fileName).toString : any
287+
>readFileSync(fileName) : any
290288
>readFileSync : any
291289
>fileName : any
292290
>toString : any
@@ -303,7 +301,6 @@ fileNames.forEach(fileName => {
303301
>sourceFile : ts.SourceFile
304302

305303
});
306-
307304
=== typescript.d.ts ===
308305
/*! *****************************************************************************
309306
Copyright (c) Microsoft Corporation. All rights reserved.

0 commit comments

Comments
 (0)