Skip to content

Commit 35d848f

Browse files
committed
merging
1 parent 86e5773 commit 35d848f

File tree

6 files changed

+222
-222
lines changed

6 files changed

+222
-222
lines changed

tests/baselines/reference/APISample_compile.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
//// [APISample_compile.ts]
2-
3-
/*
4-
* Note: This test is a public API sample. The sample sources can be found
5-
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler
6-
* Please log a "breaking change" issue for any API breaking change affecting this issue
7-
*/
8-
9-
declare var process: any;
10-
declare var console: any;
11-
declare var os: any;
12-
13-
import ts = require("typescript");
14-
15-
export function compile(fileNames: string[], options: ts.CompilerOptions): void {
16-
var program = ts.createProgram(fileNames, options);
17-
var emitResult = program.emit();
18-
19-
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
20-
21-
allDiagnostics.forEach(diagnostic => {
22-
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
23-
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
24-
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
25-
});
26-
27-
var exitCode = emitResult.emitSkipped ? 1 : 0;
28-
console.log(`Process exiting with code '${exitCode}'.`);
29-
process.exit(exitCode);
30-
}
31-
32-
compile(process.argv.slice(2), {
33-
noEmitOnError: true, noImplicitAny: true,
34-
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
2+
3+
/*
4+
* Note: This test is a public API sample. The sample sources can be found
5+
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler
6+
* Please log a "breaking change" issue for any API breaking change affecting this issue
7+
*/
8+
9+
declare var process: any;
10+
declare var console: any;
11+
declare var os: any;
12+
13+
import ts = require("typescript");
14+
15+
export function compile(fileNames: string[], options: ts.CompilerOptions): void {
16+
var program = ts.createProgram(fileNames, options);
17+
var emitResult = program.emit();
18+
19+
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
20+
21+
allDiagnostics.forEach(diagnostic => {
22+
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
23+
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
24+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
25+
});
26+
27+
var exitCode = emitResult.emitSkipped ? 1 : 0;
28+
console.log(`Process exiting with code '${exitCode}'.`);
29+
process.exit(exitCode);
30+
}
31+
32+
compile(process.argv.slice(2), {
33+
noEmitOnError: true, noImplicitAny: true,
34+
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
3535
});
3636

3737
//// [APISample_compile.js]

tests/baselines/reference/APISample_linter.js

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
//// [APISample_linter.ts]
2-
3-
/*
4-
* Note: This test is a public API sample. The sample sources can be found
5-
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter
6-
* Please log a "breaking change" issue for any API breaking change affecting this issue
7-
*/
8-
9-
declare var process: any;
10-
declare var console: any;
11-
declare var readFileSync: any;
12-
13-
import * as ts from "typescript";
14-
15-
export function delint(sourceFile: ts.SourceFile) {
16-
delintNode(sourceFile);
17-
18-
function delintNode(node: ts.Node) {
19-
switch (node.kind) {
20-
case ts.SyntaxKind.ForStatement:
21-
case ts.SyntaxKind.ForInStatement:
22-
case ts.SyntaxKind.WhileStatement:
23-
case ts.SyntaxKind.DoStatement:
24-
if ((<ts.IterationStatement>node).statement.kind !== ts.SyntaxKind.Block) {
25-
report(node, "A looping statement's contents should be wrapped in a block body.");
26-
}
27-
break;
28-
29-
case ts.SyntaxKind.IfStatement:
30-
let ifStatement = (<ts.IfStatement>node);
31-
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
32-
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
33-
}
34-
if (ifStatement.elseStatement &&
35-
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
36-
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
37-
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
38-
}
39-
break;
40-
41-
case ts.SyntaxKind.BinaryExpression:
42-
let op = (<ts.BinaryExpression>node).operatorToken.kind;
43-
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
44-
report(node, "Use '===' and '!=='.")
45-
}
46-
break;
47-
}
48-
49-
ts.forEachChild(node, delintNode);
50-
}
51-
52-
function report(node: ts.Node, message: string) {
53-
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
54-
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
55-
}
56-
}
57-
58-
const fileNames = process.argv.slice(2);
59-
fileNames.forEach(fileName => {
60-
// Parse a file
61-
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
62-
63-
// delint it
64-
delint(sourceFile);
2+
3+
/*
4+
* Note: This test is a public API sample. The sample sources can be found
5+
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter
6+
* Please log a "breaking change" issue for any API breaking change affecting this issue
7+
*/
8+
9+
declare var process: any;
10+
declare var console: any;
11+
declare var readFileSync: any;
12+
13+
import * as ts from "typescript";
14+
15+
export function delint(sourceFile: ts.SourceFile) {
16+
delintNode(sourceFile);
17+
18+
function delintNode(node: ts.Node) {
19+
switch (node.kind) {
20+
case ts.SyntaxKind.ForStatement:
21+
case ts.SyntaxKind.ForInStatement:
22+
case ts.SyntaxKind.WhileStatement:
23+
case ts.SyntaxKind.DoStatement:
24+
if ((<ts.IterationStatement>node).statement.kind !== ts.SyntaxKind.Block) {
25+
report(node, "A looping statement's contents should be wrapped in a block body.");
26+
}
27+
break;
28+
29+
case ts.SyntaxKind.IfStatement:
30+
let ifStatement = (<ts.IfStatement>node);
31+
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
32+
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
33+
}
34+
if (ifStatement.elseStatement &&
35+
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
36+
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
37+
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
38+
}
39+
break;
40+
41+
case ts.SyntaxKind.BinaryExpression:
42+
let op = (<ts.BinaryExpression>node).operatorToken.kind;
43+
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
44+
report(node, "Use '===' and '!=='.")
45+
}
46+
break;
47+
}
48+
49+
ts.forEachChild(node, delintNode);
50+
}
51+
52+
function report(node: ts.Node, message: string) {
53+
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
54+
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
55+
}
56+
}
57+
58+
const fileNames = process.argv.slice(2);
59+
fileNames.forEach(fileName => {
60+
// Parse a file
61+
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
62+
63+
// delint it
64+
delint(sourceFile);
6565
});
6666

6767
//// [APISample_linter.js]

tests/baselines/reference/APISample_transform.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//// [APISample_transform.ts]
2-
3-
/*
4-
* Note: This test is a public API sample. The sample sources can be found
5-
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function
6-
* Please log a "breaking change" issue for any API breaking change affecting this issue
7-
*/
8-
9-
declare var console: any;
10-
11-
import * as ts from "typescript";
12-
13-
const source = "let x: string = 'string'";
14-
15-
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
16-
2+
3+
/*
4+
* Note: This test is a public API sample. The sample sources can be found
5+
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function
6+
* Please log a "breaking change" issue for any API breaking change affecting this issue
7+
*/
8+
9+
declare var console: any;
10+
11+
import * as ts from "typescript";
12+
13+
const source = "let x: string = 'string'";
14+
15+
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
16+
1717
console.log(JSON.stringify(result));
1818

1919
//// [APISample_transform.js]

0 commit comments

Comments
 (0)