mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Update APISample tests for 1.5-alpha release
This commit is contained in:
parent
35d8536c75
commit
8ceebaa985
@ -21,8 +21,9 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
|
||||
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
|
||||
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)}`);
|
||||
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}`);
|
||||
});
|
||||
|
||||
var exitCode = emitResult.emitSkipped ? 1 : 0;
|
||||
@ -2040,8 +2041,9 @@ function compile(fileNames, options) {
|
||||
var emitResult = program.emit();
|
||||
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
allDiagnostics.forEach(function (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));
|
||||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
|
||||
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
||||
console.log(diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message);
|
||||
});
|
||||
var exitCode = emitResult.emitSkipped ? 1 : 0;
|
||||
console.log("Process exiting with code '" + exitCode + "'.");
|
||||
|
||||
@ -56,15 +56,16 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
|
||||
>diagnostics : ts.Diagnostic[]
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
>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
|
||||
>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
|
||||
>allDiagnostics.forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void
|
||||
>allDiagnostics : ts.Diagnostic[]
|
||||
>forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void
|
||||
>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
|
||||
>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
|
||||
>diagnostic : ts.Diagnostic
|
||||
|
||||
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
>lineChar : ts.LineAndCharacter
|
||||
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
>line : number
|
||||
>character : number
|
||||
>diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start) : ts.LineAndCharacter
|
||||
>diagnostic.file.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
|
||||
>diagnostic.file : ts.SourceFile
|
||||
@ -75,8 +76,18 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
|
||||
>diagnostic : ts.Diagnostic
|
||||
>start : number
|
||||
|
||||
console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`);
|
||||
>console.log(`${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`) : any
|
||||
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
||||
>message : string
|
||||
>ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n') : string
|
||||
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>ts : typeof ts
|
||||
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>diagnostic.messageText : string | ts.DiagnosticMessageChain
|
||||
>diagnostic : ts.Diagnostic
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
|
||||
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
>console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
@ -85,24 +96,11 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
|
||||
>diagnostic : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
>fileName : string
|
||||
>lineChar.line + 1 : number
|
||||
>lineChar.line : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>line + 1 : number
|
||||
>line : number
|
||||
>lineChar.character + 1 : number
|
||||
>lineChar.character : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>character + 1 : number
|
||||
>character : number
|
||||
>ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL) : string
|
||||
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>ts : typeof ts
|
||||
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>diagnostic.messageText : string | ts.DiagnosticMessageChain
|
||||
>diagnostic : ts.Diagnostic
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
>os.EOL : any
|
||||
>os : any
|
||||
>EOL : any
|
||||
>message : string
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@
|
||||
|
||||
declare var process: any;
|
||||
declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var readFileSync: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
|
||||
export function delint(sourceFile: ts.SourceFile) {
|
||||
delintNode(sourceFile);
|
||||
@ -27,21 +27,22 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
report(node, "A looping statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.IfStatement:
|
||||
var ifStatement = (<ts.IfStatement>node);
|
||||
let ifStatement = (<ts.IfStatement>node);
|
||||
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
|
||||
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
if (ifStatement.elseStatement &&
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.BinaryExpression:
|
||||
var op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
let op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
report(node, "Use '===' and '!=='.")
|
||||
}
|
||||
break;
|
||||
@ -51,20 +52,19 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
}
|
||||
|
||||
function report(node: ts.Node, message: string) {
|
||||
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`)
|
||||
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
var fileNames = process.argv.slice(2);
|
||||
const fileNames = process.argv.slice(2);
|
||||
fileNames.forEach(fileName => {
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
|
||||
// delint it
|
||||
delint(sourceFile);
|
||||
});
|
||||
|
||||
});
|
||||
//// [typescript.d.ts]
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
@ -2084,13 +2084,14 @@ function delint(sourceFile) {
|
||||
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
if (ifStatement.elseStatement &&
|
||||
ifStatement.elseStatement.kind !== 179 /* Block */ && ifStatement.elseStatement.kind !== 183 /* IfStatement */) {
|
||||
ifStatement.elseStatement.kind !== 179 /* Block */ &&
|
||||
ifStatement.elseStatement.kind !== 183 /* IfStatement */) {
|
||||
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
break;
|
||||
case 169 /* BinaryExpression */:
|
||||
var op = node.operatorToken.kind;
|
||||
if (op === 28 /* EqualsEqualsToken */ || op === 29 /* ExclamationEqualsToken */) {
|
||||
if (op === 28 /* EqualsEqualsToken */ || op == 29 /* ExclamationEqualsToken */) {
|
||||
report(node, "Use '===' and '!=='.");
|
||||
}
|
||||
break;
|
||||
@ -2098,15 +2099,15 @@ function delint(sourceFile) {
|
||||
ts.forEachChild(node, delintNode);
|
||||
}
|
||||
function report(node, message) {
|
||||
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
console.log(sourceFile.fileName + " (" + (lineChar.line + 1) + "," + (lineChar.character + 1) + "): " + message);
|
||||
var _a = sourceFile.getLineAndCharacterOfPosition(node.getStart()), line = _a.line, character = _a.character;
|
||||
console.log(sourceFile.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message);
|
||||
}
|
||||
}
|
||||
exports.delint = delint;
|
||||
var fileNames = process.argv.slice(2);
|
||||
fileNames.forEach(function (fileName) {
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), 2 /* ES6 */, true);
|
||||
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), 2 /* ES6 */, true);
|
||||
// delint it
|
||||
delint(sourceFile);
|
||||
});
|
||||
|
||||
@ -12,10 +12,10 @@ declare var process: any;
|
||||
declare var console: any;
|
||||
>console : any
|
||||
|
||||
declare var fs: any;
|
||||
>fs : any
|
||||
declare var readFileSync: any;
|
||||
>readFileSync : any
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
>ts : typeof ts
|
||||
|
||||
export function delint(sourceFile: ts.SourceFile) {
|
||||
@ -91,6 +91,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>node : ts.Node
|
||||
}
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.IfStatement:
|
||||
>ts.SyntaxKind.IfStatement : ts.SyntaxKind
|
||||
>ts.SyntaxKind : typeof ts.SyntaxKind
|
||||
@ -98,7 +99,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>IfStatement : ts.SyntaxKind
|
||||
|
||||
var ifStatement = (<ts.IfStatement>node);
|
||||
let ifStatement = (<ts.IfStatement>node);
|
||||
>ifStatement : ts.IfStatement
|
||||
>(<ts.IfStatement>node) : ts.IfStatement
|
||||
><ts.IfStatement>node : ts.IfStatement
|
||||
@ -127,13 +128,13 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>thenStatement : ts.Statement
|
||||
}
|
||||
if (ifStatement.elseStatement &&
|
||||
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
|
||||
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
|
||||
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block : boolean
|
||||
>ifStatement.elseStatement : ts.Statement
|
||||
>ifStatement : ts.IfStatement
|
||||
>elseStatement : ts.Statement
|
||||
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
|
||||
>ifStatement.elseStatement.kind !== ts.SyntaxKind.Block : boolean
|
||||
>ifStatement.elseStatement.kind : ts.SyntaxKind
|
||||
>ifStatement.elseStatement : ts.Statement
|
||||
@ -145,6 +146,8 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>ts : typeof ts
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>Block : ts.SyntaxKind
|
||||
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
>ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
|
||||
>ifStatement.elseStatement.kind : ts.SyntaxKind
|
||||
>ifStatement.elseStatement : ts.Statement
|
||||
@ -173,7 +176,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>BinaryExpression : ts.SyntaxKind
|
||||
|
||||
var op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
let op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
>op : ts.SyntaxKind
|
||||
>(<ts.BinaryExpression>node).operatorToken.kind : ts.SyntaxKind
|
||||
>(<ts.BinaryExpression>node).operatorToken : ts.Node
|
||||
@ -185,8 +188,8 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>operatorToken : ts.Node
|
||||
>kind : ts.SyntaxKind
|
||||
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
>op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
>op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
>op === ts.SyntaxKind.EqualsEqualsToken : boolean
|
||||
>op : ts.SyntaxKind
|
||||
>ts.SyntaxKind.EqualsEqualsToken : ts.SyntaxKind
|
||||
@ -194,7 +197,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>ts : typeof ts
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>EqualsEqualsToken : ts.SyntaxKind
|
||||
>op === ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
>op == ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
>op : ts.SyntaxKind
|
||||
>ts.SyntaxKind.ExclamationEqualsToken : ts.SyntaxKind
|
||||
>ts.SyntaxKind : typeof ts.SyntaxKind
|
||||
@ -226,8 +229,9 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>Node : ts.Node
|
||||
>message : string
|
||||
|
||||
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
>lineChar : ts.LineAndCharacter
|
||||
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
>line : number
|
||||
>character : number
|
||||
>sourceFile.getLineAndCharacterOfPosition(node.getStart()) : ts.LineAndCharacter
|
||||
>sourceFile.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
|
||||
>sourceFile : ts.SourceFile
|
||||
@ -237,27 +241,23 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>node : ts.Node
|
||||
>getStart : (sourceFile?: ts.SourceFile) => number
|
||||
|
||||
console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`)
|
||||
>console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`) : any
|
||||
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
>console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>sourceFile.fileName : string
|
||||
>sourceFile : ts.SourceFile
|
||||
>fileName : string
|
||||
>lineChar.line + 1 : number
|
||||
>lineChar.line : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>line + 1 : number
|
||||
>line : number
|
||||
>lineChar.character + 1 : number
|
||||
>lineChar.character : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>character + 1 : number
|
||||
>character : number
|
||||
>message : string
|
||||
}
|
||||
}
|
||||
|
||||
var fileNames = process.argv.slice(2);
|
||||
const fileNames = process.argv.slice(2);
|
||||
>fileNames : any
|
||||
>process.argv.slice(2) : any
|
||||
>process.argv.slice : any
|
||||
@ -267,26 +267,24 @@ var fileNames = process.argv.slice(2);
|
||||
>slice : any
|
||||
|
||||
fileNames.forEach(fileName => {
|
||||
>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
|
||||
>fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);}) : any
|
||||
>fileNames.forEach : any
|
||||
>fileNames : any
|
||||
>forEach : any
|
||||
>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
|
||||
>fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);} : (fileName: any) => void
|
||||
>fileName : any
|
||||
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
>sourceFile : ts.SourceFile
|
||||
>ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true) : ts.SourceFile
|
||||
>ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true) : ts.SourceFile
|
||||
>ts.createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>ts : typeof ts
|
||||
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>fileName : any
|
||||
>fs.readFileSync(fileName).toString() : any
|
||||
>fs.readFileSync(fileName).toString : any
|
||||
>fs.readFileSync(fileName) : any
|
||||
>fs.readFileSync : any
|
||||
>fs : any
|
||||
>readFileSync(fileName).toString() : any
|
||||
>readFileSync(fileName).toString : any
|
||||
>readFileSync(fileName) : any
|
||||
>readFileSync : any
|
||||
>fileName : any
|
||||
>toString : any
|
||||
@ -303,7 +301,6 @@ fileNames.forEach(fileName => {
|
||||
>sourceFile : ts.SourceFile
|
||||
|
||||
});
|
||||
|
||||
=== typescript.d.ts ===
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
@ -12,10 +12,10 @@ declare var process: any;
|
||||
declare var console: any;
|
||||
>console : any
|
||||
|
||||
declare var fs: any;
|
||||
>fs : any
|
||||
declare var readFileSync: any;
|
||||
>readFileSync : any
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
>ts : typeof ts
|
||||
|
||||
export function delint(sourceFile: ts.SourceFile) {
|
||||
@ -91,6 +91,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>node : ts.Node
|
||||
}
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.IfStatement:
|
||||
>ts.SyntaxKind.IfStatement : ts.SyntaxKind
|
||||
>ts.SyntaxKind : typeof ts.SyntaxKind
|
||||
@ -98,7 +99,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>IfStatement : ts.SyntaxKind
|
||||
|
||||
var ifStatement = (<ts.IfStatement>node);
|
||||
let ifStatement = (<ts.IfStatement>node);
|
||||
>ifStatement : ts.IfStatement
|
||||
>(<ts.IfStatement>node) : ts.IfStatement
|
||||
><ts.IfStatement>node : ts.IfStatement
|
||||
@ -127,13 +128,13 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>thenStatement : ts.Statement
|
||||
}
|
||||
if (ifStatement.elseStatement &&
|
||||
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
|
||||
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
|
||||
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block : boolean
|
||||
>ifStatement.elseStatement : ts.Statement
|
||||
>ifStatement : ts.IfStatement
|
||||
>elseStatement : ts.Statement
|
||||
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
|
||||
>ifStatement.elseStatement.kind !== ts.SyntaxKind.Block : boolean
|
||||
>ifStatement.elseStatement.kind : ts.SyntaxKind
|
||||
>ifStatement.elseStatement : ts.Statement
|
||||
@ -145,6 +146,8 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>ts : typeof ts
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>Block : ts.SyntaxKind
|
||||
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
>ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
|
||||
>ifStatement.elseStatement.kind : ts.SyntaxKind
|
||||
>ifStatement.elseStatement : ts.Statement
|
||||
@ -173,7 +176,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>BinaryExpression : ts.SyntaxKind
|
||||
|
||||
var op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
let op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
>op : ts.SyntaxKind
|
||||
>(<ts.BinaryExpression>node).operatorToken.kind : ts.SyntaxKind
|
||||
>(<ts.BinaryExpression>node).operatorToken : ts.Node
|
||||
@ -185,8 +188,8 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>operatorToken : ts.Node
|
||||
>kind : ts.SyntaxKind
|
||||
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
>op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
>op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
>op === ts.SyntaxKind.EqualsEqualsToken : boolean
|
||||
>op : ts.SyntaxKind
|
||||
>ts.SyntaxKind.EqualsEqualsToken : ts.SyntaxKind
|
||||
@ -194,7 +197,7 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>ts : typeof ts
|
||||
>SyntaxKind : typeof ts.SyntaxKind
|
||||
>EqualsEqualsToken : ts.SyntaxKind
|
||||
>op === ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
>op == ts.SyntaxKind.ExclamationEqualsToken : boolean
|
||||
>op : ts.SyntaxKind
|
||||
>ts.SyntaxKind.ExclamationEqualsToken : ts.SyntaxKind
|
||||
>ts.SyntaxKind : typeof ts.SyntaxKind
|
||||
@ -226,8 +229,9 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>Node : ts.Node
|
||||
>message : string
|
||||
|
||||
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
>lineChar : ts.LineAndCharacter
|
||||
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
>line : number
|
||||
>character : number
|
||||
>sourceFile.getLineAndCharacterOfPosition(node.getStart()) : ts.LineAndCharacter
|
||||
>sourceFile.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
|
||||
>sourceFile : ts.SourceFile
|
||||
@ -237,27 +241,23 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>node : ts.Node
|
||||
>getStart : (sourceFile?: ts.SourceFile) => number
|
||||
|
||||
console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`)
|
||||
>console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`) : any
|
||||
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
>console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>sourceFile.fileName : string
|
||||
>sourceFile : ts.SourceFile
|
||||
>fileName : string
|
||||
>lineChar.line + 1 : number
|
||||
>lineChar.line : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>line + 1 : number
|
||||
>line : number
|
||||
>lineChar.character + 1 : number
|
||||
>lineChar.character : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>character + 1 : number
|
||||
>character : number
|
||||
>message : string
|
||||
}
|
||||
}
|
||||
|
||||
var fileNames = process.argv.slice(2);
|
||||
const fileNames = process.argv.slice(2);
|
||||
>fileNames : any
|
||||
>process.argv.slice(2) : any
|
||||
>process.argv.slice : any
|
||||
@ -267,26 +267,24 @@ var fileNames = process.argv.slice(2);
|
||||
>slice : any
|
||||
|
||||
fileNames.forEach(fileName => {
|
||||
>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
|
||||
>fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);}) : any
|
||||
>fileNames.forEach : any
|
||||
>fileNames : any
|
||||
>forEach : any
|
||||
>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
|
||||
>fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);} : (fileName: any) => void
|
||||
>fileName : any
|
||||
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
>sourceFile : ts.SourceFile
|
||||
>ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true) : ts.SourceFile
|
||||
>ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true) : ts.SourceFile
|
||||
>ts.createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>ts : typeof ts
|
||||
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>fileName : any
|
||||
>fs.readFileSync(fileName).toString() : any
|
||||
>fs.readFileSync(fileName).toString : any
|
||||
>fs.readFileSync(fileName) : any
|
||||
>fs.readFileSync : any
|
||||
>fs : any
|
||||
>readFileSync(fileName).toString() : any
|
||||
>readFileSync(fileName).toString : any
|
||||
>readFileSync(fileName) : any
|
||||
>readFileSync : any
|
||||
>fileName : any
|
||||
>toString : any
|
||||
@ -303,7 +301,6 @@ fileNames.forEach(fileName => {
|
||||
>sourceFile : ts.SourceFile
|
||||
|
||||
});
|
||||
|
||||
=== typescript.d.ts ===
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
@ -8,62 +8,13 @@
|
||||
* Please log a "breaking change" issue for any API breaking change affecting this issue
|
||||
*/
|
||||
|
||||
declare var process: any;
|
||||
declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var path: any;
|
||||
declare var os: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
|
||||
function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
// Sources
|
||||
var files = {
|
||||
"file.ts": contents,
|
||||
"lib.d.ts": fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString()
|
||||
};
|
||||
const source = "let x: string = 'string'";
|
||||
|
||||
// Generated outputs
|
||||
var outputs = [];
|
||||
|
||||
// Create a compilerHost object to allow the compiler to read and write files
|
||||
var compilerHost = {
|
||||
getSourceFile: (fileName, target) => {
|
||||
return files[fileName] !== undefined ?
|
||||
ts.createSourceFile(fileName, files[fileName], target) : undefined;
|
||||
},
|
||||
writeFile: (name, text, writeByteOrderMark) => {
|
||||
outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark });
|
||||
},
|
||||
getDefaultLibFileName: () => "lib.d.ts",
|
||||
useCaseSensitiveFileNames: () => false,
|
||||
getCanonicalFileName: (fileName) => fileName,
|
||||
getCurrentDirectory: () => "",
|
||||
getNewLine: () => "\n"
|
||||
};
|
||||
|
||||
// Create a program from inputs
|
||||
var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost);
|
||||
|
||||
// Query for early errors
|
||||
var errors = ts.getPreEmitDiagnostics(program);
|
||||
var emitResult = program.emit();
|
||||
|
||||
errors = errors.concat(emitResult.diagnostics);
|
||||
|
||||
return {
|
||||
outputs: outputs,
|
||||
errors: errors.map(function (e) {
|
||||
return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): "
|
||||
+ ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// Calling our transform function using a simple TypeScript variable declarations,
|
||||
// and loading the default library like:
|
||||
var source = "var x: number = 'string'";
|
||||
var result = transform(source);
|
||||
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
|
||||
|
||||
console.log(JSON.stringify(result));
|
||||
//// [typescript.d.ts]
|
||||
@ -2067,46 +2018,6 @@ declare module "typescript" {
|
||||
* Please log a "breaking change" issue for any API breaking change affecting this issue
|
||||
*/
|
||||
var ts = require("typescript");
|
||||
function transform(contents, compilerOptions) {
|
||||
if (compilerOptions === void 0) { compilerOptions = {}; }
|
||||
// Sources
|
||||
var files = {
|
||||
"file.ts": contents,
|
||||
"lib.d.ts": fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString()
|
||||
};
|
||||
// Generated outputs
|
||||
var outputs = [];
|
||||
// Create a compilerHost object to allow the compiler to read and write files
|
||||
var compilerHost = {
|
||||
getSourceFile: function (fileName, target) {
|
||||
return files[fileName] !== undefined ?
|
||||
ts.createSourceFile(fileName, files[fileName], target) : undefined;
|
||||
},
|
||||
writeFile: function (name, text, writeByteOrderMark) {
|
||||
outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark });
|
||||
},
|
||||
getDefaultLibFileName: function () { return "lib.d.ts"; },
|
||||
useCaseSensitiveFileNames: function () { return false; },
|
||||
getCanonicalFileName: function (fileName) { return fileName; },
|
||||
getCurrentDirectory: function () { return ""; },
|
||||
getNewLine: function () { return "\n"; }
|
||||
};
|
||||
// Create a program from inputs
|
||||
var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost);
|
||||
// Query for early errors
|
||||
var errors = ts.getPreEmitDiagnostics(program);
|
||||
var emitResult = program.emit();
|
||||
errors = errors.concat(emitResult.diagnostics);
|
||||
return {
|
||||
outputs: outputs,
|
||||
errors: errors.map(function (e) {
|
||||
return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): "
|
||||
+ ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
})
|
||||
};
|
||||
}
|
||||
// Calling our transform function using a simple TypeScript variable declarations,
|
||||
// and loading the default library like:
|
||||
var source = "var x: number = 'string'";
|
||||
var result = transform(source);
|
||||
var source = "let x: string = 'string'";
|
||||
var result = ts.transpile(source, { module: 1 /* CommonJS */ });
|
||||
console.log(JSON.stringify(result));
|
||||
|
||||
@ -6,242 +6,29 @@
|
||||
* Please log a "breaking change" issue for any API breaking change affecting this issue
|
||||
*/
|
||||
|
||||
declare var process: any;
|
||||
>process : any
|
||||
|
||||
declare var console: any;
|
||||
>console : any
|
||||
|
||||
declare var fs: any;
|
||||
>fs : any
|
||||
|
||||
declare var path: any;
|
||||
>path : any
|
||||
|
||||
declare var os: any;
|
||||
>os : any
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
>ts : typeof ts
|
||||
|
||||
function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
>transform : (contents: string, compilerOptions?: ts.CompilerOptions) => { outputs: any[]; errors: string[]; }
|
||||
>contents : string
|
||||
>compilerOptions : ts.CompilerOptions
|
||||
>ts : unknown
|
||||
>CompilerOptions : ts.CompilerOptions
|
||||
>{} : { [x: string]: undefined; }
|
||||
|
||||
// Sources
|
||||
var files = {
|
||||
>files : { "file.ts": string; "lib.d.ts": any; }
|
||||
>{ "file.ts": contents, "lib.d.ts": fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString() } : { "file.ts": string; "lib.d.ts": any; }
|
||||
|
||||
"file.ts": contents,
|
||||
>contents : string
|
||||
|
||||
"lib.d.ts": fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString()
|
||||
>fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString() : any
|
||||
>fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString : any
|
||||
>fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)) : any
|
||||
>fs.readFileSync : any
|
||||
>fs : any
|
||||
>readFileSync : any
|
||||
>ts.getDefaultLibFilePath(compilerOptions) : string
|
||||
>ts.getDefaultLibFilePath : (options: ts.CompilerOptions) => string
|
||||
>ts : typeof ts
|
||||
>getDefaultLibFilePath : (options: ts.CompilerOptions) => string
|
||||
>compilerOptions : ts.CompilerOptions
|
||||
>toString : any
|
||||
|
||||
};
|
||||
|
||||
// Generated outputs
|
||||
var outputs = [];
|
||||
>outputs : any[]
|
||||
>[] : undefined[]
|
||||
|
||||
// Create a compilerHost object to allow the compiler to read and write files
|
||||
var compilerHost = {
|
||||
>compilerHost : { getSourceFile: (fileName: any, target: any) => ts.SourceFile; writeFile: (name: any, text: any, writeByteOrderMark: any) => void; getDefaultLibFileName: () => string; useCaseSensitiveFileNames: () => boolean; getCanonicalFileName: (fileName: any) => any; getCurrentDirectory: () => string; getNewLine: () => string; }
|
||||
>{ getSourceFile: (fileName, target) => { return files[fileName] !== undefined ? ts.createSourceFile(fileName, files[fileName], target) : undefined; }, writeFile: (name, text, writeByteOrderMark) => { outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark }); }, getDefaultLibFileName: () => "lib.d.ts", useCaseSensitiveFileNames: () => false, getCanonicalFileName: (fileName) => fileName, getCurrentDirectory: () => "", getNewLine: () => "\n" } : { getSourceFile: (fileName: any, target: any) => ts.SourceFile; writeFile: (name: any, text: any, writeByteOrderMark: any) => void; getDefaultLibFileName: () => string; useCaseSensitiveFileNames: () => boolean; getCanonicalFileName: (fileName: any) => any; getCurrentDirectory: () => string; getNewLine: () => string; }
|
||||
|
||||
getSourceFile: (fileName, target) => {
|
||||
>getSourceFile : (fileName: any, target: any) => ts.SourceFile
|
||||
>(fileName, target) => { return files[fileName] !== undefined ? ts.createSourceFile(fileName, files[fileName], target) : undefined; } : (fileName: any, target: any) => ts.SourceFile
|
||||
>fileName : any
|
||||
>target : any
|
||||
|
||||
return files[fileName] !== undefined ?
|
||||
>files[fileName] !== undefined ? ts.createSourceFile(fileName, files[fileName], target) : undefined : ts.SourceFile
|
||||
>files[fileName] !== undefined : boolean
|
||||
>files[fileName] : any
|
||||
>files : { "file.ts": string; "lib.d.ts": any; }
|
||||
>fileName : any
|
||||
>undefined : undefined
|
||||
|
||||
ts.createSourceFile(fileName, files[fileName], target) : undefined;
|
||||
>ts.createSourceFile(fileName, files[fileName], target) : ts.SourceFile
|
||||
>ts.createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>ts : typeof ts
|
||||
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>fileName : any
|
||||
>files[fileName] : any
|
||||
>files : { "file.ts": string; "lib.d.ts": any; }
|
||||
>fileName : any
|
||||
>target : any
|
||||
>undefined : undefined
|
||||
|
||||
},
|
||||
writeFile: (name, text, writeByteOrderMark) => {
|
||||
>writeFile : (name: any, text: any, writeByteOrderMark: any) => void
|
||||
>(name, text, writeByteOrderMark) => { outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark }); } : (name: any, text: any, writeByteOrderMark: any) => void
|
||||
>name : any
|
||||
>text : any
|
||||
>writeByteOrderMark : any
|
||||
|
||||
outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark });
|
||||
>outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark }) : number
|
||||
>outputs.push : (...items: any[]) => number
|
||||
>outputs : any[]
|
||||
>push : (...items: any[]) => number
|
||||
>{ name: name, text: text, writeByteOrderMark: writeByteOrderMark } : { name: any; text: any; writeByteOrderMark: any; }
|
||||
>name : any
|
||||
>name : any
|
||||
>text : any
|
||||
>text : any
|
||||
>writeByteOrderMark : any
|
||||
>writeByteOrderMark : any
|
||||
|
||||
},
|
||||
getDefaultLibFileName: () => "lib.d.ts",
|
||||
>getDefaultLibFileName : () => string
|
||||
>() => "lib.d.ts" : () => string
|
||||
|
||||
useCaseSensitiveFileNames: () => false,
|
||||
>useCaseSensitiveFileNames : () => boolean
|
||||
>() => false : () => boolean
|
||||
|
||||
getCanonicalFileName: (fileName) => fileName,
|
||||
>getCanonicalFileName : (fileName: any) => any
|
||||
>(fileName) => fileName : (fileName: any) => any
|
||||
>fileName : any
|
||||
>fileName : any
|
||||
|
||||
getCurrentDirectory: () => "",
|
||||
>getCurrentDirectory : () => string
|
||||
>() => "" : () => string
|
||||
|
||||
getNewLine: () => "\n"
|
||||
>getNewLine : () => string
|
||||
>() => "\n" : () => string
|
||||
|
||||
};
|
||||
|
||||
// Create a program from inputs
|
||||
var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost);
|
||||
>program : ts.Program
|
||||
>ts.createProgram(["file.ts"], compilerOptions, compilerHost) : ts.Program
|
||||
>ts.createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
|
||||
>ts : typeof ts
|
||||
>createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
|
||||
>["file.ts"] : string[]
|
||||
>compilerOptions : ts.CompilerOptions
|
||||
>compilerHost : { getSourceFile: (fileName: any, target: any) => ts.SourceFile; writeFile: (name: any, text: any, writeByteOrderMark: any) => void; getDefaultLibFileName: () => string; useCaseSensitiveFileNames: () => boolean; getCanonicalFileName: (fileName: any) => any; getCurrentDirectory: () => string; getNewLine: () => string; }
|
||||
|
||||
// Query for early errors
|
||||
var errors = ts.getPreEmitDiagnostics(program);
|
||||
>errors : ts.Diagnostic[]
|
||||
>ts.getPreEmitDiagnostics(program) : ts.Diagnostic[]
|
||||
>ts.getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[]
|
||||
>ts : typeof ts
|
||||
>getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[]
|
||||
>program : ts.Program
|
||||
|
||||
var emitResult = program.emit();
|
||||
>emitResult : ts.EmitResult
|
||||
>program.emit() : ts.EmitResult
|
||||
>program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult
|
||||
>program : ts.Program
|
||||
>emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult
|
||||
|
||||
errors = errors.concat(emitResult.diagnostics);
|
||||
>errors = errors.concat(emitResult.diagnostics) : ts.Diagnostic[]
|
||||
>errors : ts.Diagnostic[]
|
||||
>errors.concat(emitResult.diagnostics) : ts.Diagnostic[]
|
||||
>errors.concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
>errors : ts.Diagnostic[]
|
||||
>concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
>emitResult.diagnostics : ts.Diagnostic[]
|
||||
>emitResult : ts.EmitResult
|
||||
>diagnostics : ts.Diagnostic[]
|
||||
|
||||
return {
|
||||
>{ outputs: outputs, errors: errors.map(function (e) { return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) } : { outputs: any[]; errors: string[]; }
|
||||
|
||||
outputs: outputs,
|
||||
>outputs : any[]
|
||||
>outputs : any[]
|
||||
|
||||
errors: errors.map(function (e) {
|
||||
>errors : string[]
|
||||
>errors.map(function (e) { return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) : string[]
|
||||
>errors.map : <U>(callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => U, thisArg?: any) => U[]
|
||||
>errors : ts.Diagnostic[]
|
||||
>map : <U>(callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => U, thisArg?: any) => U[]
|
||||
>function (e) { return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); } : (e: ts.Diagnostic) => string
|
||||
>e : ts.Diagnostic
|
||||
|
||||
return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): "
|
||||
>e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string
|
||||
>e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): " : string
|
||||
>e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) : string
|
||||
>e.file.fileName + "(" : string
|
||||
>e.file.fileName : string
|
||||
>e.file : ts.SourceFile
|
||||
>e : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
>fileName : string
|
||||
>(e.file.getLineAndCharacterOfPosition(e.start).line + 1) : number
|
||||
>e.file.getLineAndCharacterOfPosition(e.start).line + 1 : number
|
||||
>e.file.getLineAndCharacterOfPosition(e.start).line : number
|
||||
>e.file.getLineAndCharacterOfPosition(e.start) : ts.LineAndCharacter
|
||||
>e.file.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
|
||||
>e.file : ts.SourceFile
|
||||
>e : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
>getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
|
||||
>e.start : number
|
||||
>e : ts.Diagnostic
|
||||
>start : number
|
||||
>line : number
|
||||
|
||||
+ ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
>ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string
|
||||
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>ts : typeof ts
|
||||
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>e.messageText : string | ts.DiagnosticMessageChain
|
||||
>e : ts.Diagnostic
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
>os.EOL : any
|
||||
>os : any
|
||||
>EOL : any
|
||||
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// Calling our transform function using a simple TypeScript variable declarations,
|
||||
// and loading the default library like:
|
||||
var source = "var x: number = 'string'";
|
||||
const source = "let x: string = 'string'";
|
||||
>source : string
|
||||
|
||||
var result = transform(source);
|
||||
>result : { outputs: any[]; errors: string[]; }
|
||||
>transform(source) : { outputs: any[]; errors: string[]; }
|
||||
>transform : (contents: string, compilerOptions?: ts.CompilerOptions) => { outputs: any[]; errors: string[]; }
|
||||
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
|
||||
>result : string
|
||||
>ts.transpile(source, { module: ts.ModuleKind.CommonJS }) : string
|
||||
>ts.transpile : (input: string, compilerOptions?: ts.CompilerOptions, fileName?: string, diagnostics?: ts.Diagnostic[]) => string
|
||||
>ts : typeof ts
|
||||
>transpile : (input: string, compilerOptions?: ts.CompilerOptions, fileName?: string, diagnostics?: ts.Diagnostic[]) => string
|
||||
>source : string
|
||||
>{ module: ts.ModuleKind.CommonJS } : { [x: string]: ts.ModuleKind; module: ts.ModuleKind; }
|
||||
>module : ts.ModuleKind
|
||||
>ts.ModuleKind.CommonJS : ts.ModuleKind
|
||||
>ts.ModuleKind : typeof ts.ModuleKind
|
||||
>ts : typeof ts
|
||||
>ModuleKind : typeof ts.ModuleKind
|
||||
>CommonJS : ts.ModuleKind
|
||||
|
||||
console.log(JSON.stringify(result));
|
||||
>console.log(JSON.stringify(result)) : any
|
||||
@ -252,7 +39,7 @@ console.log(JSON.stringify(result));
|
||||
>JSON.stringify : { (value: any): string; (value: any, replacer: (key: string, value: any) => any): string; (value: any, replacer: any[]): string; (value: any, replacer: (key: string, value: any) => any, space: any): string; (value: any, replacer: any[], space: any): string; }
|
||||
>JSON : JSON
|
||||
>stringify : { (value: any): string; (value: any, replacer: (key: string, value: any) => any): string; (value: any, replacer: any[]): string; (value: any, replacer: (key: string, value: any) => any, space: any): string; (value: any, replacer: any[], space: any): string; }
|
||||
>result : { outputs: any[]; errors: string[]; }
|
||||
>result : string
|
||||
|
||||
=== typescript.d.ts ===
|
||||
/*! *****************************************************************************
|
||||
|
||||
@ -13,10 +13,10 @@ declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var path: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
|
||||
function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
var files: ts.Map<{ version: number }> = {};
|
||||
const files: ts.Map<{ version: number }> = {};
|
||||
|
||||
// initialize the list of files
|
||||
rootFileNames.forEach(fileName => {
|
||||
@ -24,7 +24,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
});
|
||||
|
||||
// Create the language service host to allow the LS to communicate with the host
|
||||
var servicesHost: ts.LanguageServiceHost = {
|
||||
const servicesHost: ts.LanguageServiceHost = {
|
||||
getScriptFileNames: () => rootFileNames,
|
||||
getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(),
|
||||
getScriptSnapshot: (fileName) => {
|
||||
@ -40,7 +40,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
};
|
||||
|
||||
// Create the language service files
|
||||
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
|
||||
// Now let's watch the files
|
||||
rootFileNames.forEach(fileName => {
|
||||
@ -65,7 +65,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
});
|
||||
|
||||
function emitFile(fileName: string) {
|
||||
var output = services.getEmitOutput(fileName);
|
||||
let output = services.getEmitOutput(fileName);
|
||||
|
||||
if (!output.emitSkipped) {
|
||||
console.log(`Emitting ${fileName}`);
|
||||
@ -81,24 +81,25 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
}
|
||||
|
||||
function logErrors(fileName: string) {
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
let allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
.concat(services.getSyntacticDiagnostics(fileName))
|
||||
.concat(services.getSemanticDiagnostics(fileName));
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
||||
if (diagnostic.file) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
console.log(` Error ${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
|
||||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
}
|
||||
else {
|
||||
console.log(` Error: ${diagnostic.messageText}`);
|
||||
console.log(` Error: ${message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize files constituting the program as all .ts files in the current directory
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
const currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
filter(fileName=> fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts");
|
||||
|
||||
// Start the watcher
|
||||
@ -2160,12 +2161,13 @@ function watch(rootFileNames, options) {
|
||||
.concat(services.getSyntacticDiagnostics(fileName))
|
||||
.concat(services.getSemanticDiagnostics(fileName));
|
||||
allDiagnostics.forEach(function (diagnostic) {
|
||||
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
||||
if (diagnostic.file) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
console.log(" Error " + diagnostic.file.fileName + " (" + (lineChar.line + 1) + "," + (lineChar.character + 1) + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
||||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
|
||||
console.log(" Error " + diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message);
|
||||
}
|
||||
else {
|
||||
console.log(" Error: " + diagnostic.messageText);
|
||||
console.log(" Error: " + message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ declare var fs: any;
|
||||
declare var path: any;
|
||||
>path : any
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
>ts : typeof ts
|
||||
|
||||
function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
@ -28,7 +28,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
>ts : unknown
|
||||
>CompilerOptions : ts.CompilerOptions
|
||||
|
||||
var files: ts.Map<{ version: number }> = {};
|
||||
const files: ts.Map<{ version: number }> = {};
|
||||
>files : ts.Map<{ version: number; }>
|
||||
>ts : unknown
|
||||
>Map : ts.Map<T>
|
||||
@ -55,7 +55,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
});
|
||||
|
||||
// Create the language service host to allow the LS to communicate with the host
|
||||
var servicesHost: ts.LanguageServiceHost = {
|
||||
const servicesHost: ts.LanguageServiceHost = {
|
||||
>servicesHost : ts.LanguageServiceHost
|
||||
>ts : unknown
|
||||
>LanguageServiceHost : ts.LanguageServiceHost
|
||||
@ -143,7 +143,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
};
|
||||
|
||||
// Create the language service files
|
||||
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
>services : ts.LanguageService
|
||||
>ts.createLanguageService(servicesHost, ts.createDocumentRegistry()) : ts.LanguageService
|
||||
>ts.createLanguageService : (host: ts.LanguageServiceHost, documentRegistry?: ts.DocumentRegistry) => ts.LanguageService
|
||||
@ -225,7 +225,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
>emitFile : (fileName: string) => void
|
||||
>fileName : string
|
||||
|
||||
var output = services.getEmitOutput(fileName);
|
||||
let output = services.getEmitOutput(fileName);
|
||||
>output : ts.EmitOutput
|
||||
>services.getEmitOutput(fileName) : ts.EmitOutput
|
||||
>services.getEmitOutput : (fileName: string) => ts.EmitOutput
|
||||
@ -289,7 +289,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
>logErrors : (fileName: string) => void
|
||||
>fileName : string
|
||||
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
let allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
>allDiagnostics : ts.Diagnostic[]
|
||||
>services.getCompilerOptionsDiagnostics() .concat(services.getSyntacticDiagnostics(fileName)) .concat(services.getSemanticDiagnostics(fileName)) : ts.Diagnostic[]
|
||||
>services.getCompilerOptionsDiagnostics() .concat(services.getSyntacticDiagnostics(fileName)) .concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
@ -317,20 +317,31 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
>fileName : string
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
>allDiagnostics.forEach(diagnostic => { if (diagnostic.file) { var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`); } else { console.log(` Error: ${diagnostic.messageText}`); } }) : void
|
||||
>allDiagnostics.forEach(diagnostic => { let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); if (diagnostic.file) { let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); } else { console.log(` Error: ${message}`); } }) : void
|
||||
>allDiagnostics.forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void
|
||||
>allDiagnostics : ts.Diagnostic[]
|
||||
>forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void
|
||||
>diagnostic => { if (diagnostic.file) { var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`); } else { console.log(` Error: ${diagnostic.messageText}`); } } : (diagnostic: ts.Diagnostic) => void
|
||||
>diagnostic => { let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); if (diagnostic.file) { let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); } else { console.log(` Error: ${message}`); } } : (diagnostic: ts.Diagnostic) => void
|
||||
>diagnostic : ts.Diagnostic
|
||||
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
||||
>message : string
|
||||
>ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n") : string
|
||||
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>ts : typeof ts
|
||||
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>diagnostic.messageText : string | ts.DiagnosticMessageChain
|
||||
>diagnostic : ts.Diagnostic
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
|
||||
if (diagnostic.file) {
|
||||
>diagnostic.file : ts.SourceFile
|
||||
>diagnostic : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
|
||||
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
>lineChar : ts.LineAndCharacter
|
||||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
>line : number
|
||||
>character : number
|
||||
>diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start) : ts.LineAndCharacter
|
||||
>diagnostic.file.getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
|
||||
>diagnostic.file : ts.SourceFile
|
||||
@ -341,8 +352,8 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
>diagnostic : ts.Diagnostic
|
||||
>start : number
|
||||
|
||||
console.log(` Error ${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
|
||||
>console.log(` Error ${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`) : any
|
||||
console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
>console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
@ -351,38 +362,26 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
>diagnostic : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
>fileName : string
|
||||
>lineChar.line + 1 : number
|
||||
>lineChar.line : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>line + 1 : number
|
||||
>line : number
|
||||
>lineChar.character + 1 : number
|
||||
>lineChar.character : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>character + 1 : number
|
||||
>character : number
|
||||
>ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n") : string
|
||||
>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>ts : typeof ts
|
||||
>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string
|
||||
>diagnostic.messageText : string | ts.DiagnosticMessageChain
|
||||
>diagnostic : ts.Diagnostic
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
>message : string
|
||||
}
|
||||
else {
|
||||
console.log(` Error: ${diagnostic.messageText}`);
|
||||
>console.log(` Error: ${diagnostic.messageText}`) : any
|
||||
console.log(` Error: ${message}`);
|
||||
>console.log(` Error: ${message}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>diagnostic.messageText : string | ts.DiagnosticMessageChain
|
||||
>diagnostic : ts.Diagnostic
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
>message : string
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize files constituting the program as all .ts files in the current directory
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
const currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
>currentDirectoryFiles : any
|
||||
>fs.readdirSync(process.cwd()). filter(fileName=> fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts") : any
|
||||
>fs.readdirSync(process.cwd()). filter : any
|
||||
|
||||
@ -21,8 +21,9 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
|
||||
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
|
||||
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)}`);
|
||||
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}`);
|
||||
});
|
||||
|
||||
var exitCode = emitResult.emitSkipped ? 1 : 0;
|
||||
|
||||
@ -10,9 +10,9 @@
|
||||
|
||||
declare var process: any;
|
||||
declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var readFileSync: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
|
||||
export function delint(sourceFile: ts.SourceFile) {
|
||||
delintNode(sourceFile);
|
||||
@ -27,21 +27,22 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
report(node, "A looping statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.IfStatement:
|
||||
var ifStatement = (<ts.IfStatement>node);
|
||||
let ifStatement = (<ts.IfStatement>node);
|
||||
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
|
||||
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
if (ifStatement.elseStatement &&
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
|
||||
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
|
||||
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
|
||||
}
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.BinaryExpression:
|
||||
var op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
let op = (<ts.BinaryExpression>node).operatorToken.kind;
|
||||
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
|
||||
report(node, "Use '===' and '!=='.")
|
||||
}
|
||||
break;
|
||||
@ -51,16 +52,16 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
}
|
||||
|
||||
function report(node: ts.Node, message: string) {
|
||||
var lineChar = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
console.log(`${sourceFile.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${message}`)
|
||||
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
||||
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
var fileNames = process.argv.slice(2);
|
||||
const fileNames = process.argv.slice(2);
|
||||
fileNames.forEach(fileName => {
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
|
||||
// delint it
|
||||
delint(sourceFile);
|
||||
});
|
||||
});
|
||||
@ -8,61 +8,12 @@
|
||||
* Please log a "breaking change" issue for any API breaking change affecting this issue
|
||||
*/
|
||||
|
||||
declare var process: any;
|
||||
declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var path: any;
|
||||
declare var os: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
|
||||
function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
// Sources
|
||||
var files = {
|
||||
"file.ts": contents,
|
||||
"lib.d.ts": fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString()
|
||||
};
|
||||
const source = "let x: string = 'string'";
|
||||
|
||||
// Generated outputs
|
||||
var outputs = [];
|
||||
|
||||
// Create a compilerHost object to allow the compiler to read and write files
|
||||
var compilerHost = {
|
||||
getSourceFile: (fileName, target) => {
|
||||
return files[fileName] !== undefined ?
|
||||
ts.createSourceFile(fileName, files[fileName], target) : undefined;
|
||||
},
|
||||
writeFile: (name, text, writeByteOrderMark) => {
|
||||
outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark });
|
||||
},
|
||||
getDefaultLibFileName: () => "lib.d.ts",
|
||||
useCaseSensitiveFileNames: () => false,
|
||||
getCanonicalFileName: (fileName) => fileName,
|
||||
getCurrentDirectory: () => "",
|
||||
getNewLine: () => "\n"
|
||||
};
|
||||
|
||||
// Create a program from inputs
|
||||
var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost);
|
||||
|
||||
// Query for early errors
|
||||
var errors = ts.getPreEmitDiagnostics(program);
|
||||
var emitResult = program.emit();
|
||||
|
||||
errors = errors.concat(emitResult.diagnostics);
|
||||
|
||||
return {
|
||||
outputs: outputs,
|
||||
errors: errors.map(function (e) {
|
||||
return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): "
|
||||
+ ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// Calling our transform function using a simple TypeScript variable declarations,
|
||||
// and loading the default library like:
|
||||
var source = "var x: number = 'string'";
|
||||
var result = transform(source);
|
||||
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
|
||||
|
||||
console.log(JSON.stringify(result));
|
||||
@ -13,10 +13,10 @@ declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var path: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
import * as ts from "typescript";
|
||||
|
||||
function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
var files: ts.Map<{ version: number }> = {};
|
||||
const files: ts.Map<{ version: number }> = {};
|
||||
|
||||
// initialize the list of files
|
||||
rootFileNames.forEach(fileName => {
|
||||
@ -24,7 +24,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
});
|
||||
|
||||
// Create the language service host to allow the LS to communicate with the host
|
||||
var servicesHost: ts.LanguageServiceHost = {
|
||||
const servicesHost: ts.LanguageServiceHost = {
|
||||
getScriptFileNames: () => rootFileNames,
|
||||
getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(),
|
||||
getScriptSnapshot: (fileName) => {
|
||||
@ -40,7 +40,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
};
|
||||
|
||||
// Create the language service files
|
||||
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
|
||||
// Now let's watch the files
|
||||
rootFileNames.forEach(fileName => {
|
||||
@ -65,7 +65,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
});
|
||||
|
||||
function emitFile(fileName: string) {
|
||||
var output = services.getEmitOutput(fileName);
|
||||
let output = services.getEmitOutput(fileName);
|
||||
|
||||
if (!output.emitSkipped) {
|
||||
console.log(`Emitting ${fileName}`);
|
||||
@ -81,24 +81,25 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
}
|
||||
|
||||
function logErrors(fileName: string) {
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
let allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
.concat(services.getSyntacticDiagnostics(fileName))
|
||||
.concat(services.getSemanticDiagnostics(fileName));
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
||||
if (diagnostic.file) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
console.log(` Error ${diagnostic.file.fileName} (${lineChar.line + 1},${lineChar.character + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
|
||||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
}
|
||||
else {
|
||||
console.log(` Error: ${diagnostic.messageText}`);
|
||||
console.log(` Error: ${message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize files constituting the program as all .ts files in the current directory
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
const currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
filter(fileName=> fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts");
|
||||
|
||||
// Start the watcher
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user