mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into thanksLua
Conflicts: src/compiler/emitter.ts tests/baselines/reference/FunctionPropertyAssignments5_es6.js tests/baselines/reference/computedPropertyNames9_ES6.js tests/baselines/reference/computedPropertyNamesDeclarationEmit3.js tests/baselines/reference/computedPropertyNamesDeclarationEmit4.js tests/baselines/reference/parserES5ComputedPropertyName3.js tests/baselines/reference/parserES5ComputedPropertyName4.js
This commit is contained in:
@@ -44,3 +44,4 @@ scripts/ior.js
|
||||
scripts/*.js.map
|
||||
coverage/
|
||||
internal/
|
||||
**/.DS_Store
|
||||
|
||||
@@ -382,6 +382,10 @@ compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright
|
||||
desc("Builds the full compiler and services");
|
||||
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile]);
|
||||
|
||||
// Local target to build only tsc.js
|
||||
desc("Builds only the compiler");
|
||||
task("tsc", ["generate-diagnostics", "lib", tscFile]);
|
||||
|
||||
// Local target to build the compiler and services
|
||||
desc("Sets release mode flag");
|
||||
task("release", function() {
|
||||
@@ -457,14 +461,16 @@ directory(builtLocalDirectory);
|
||||
var run = path.join(builtLocalDirectory, "run.js");
|
||||
compileFile(run, harnessSources, [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources), [], /*useBuiltCompiler:*/ true);
|
||||
|
||||
var internalTests = "internal/"
|
||||
|
||||
var localBaseline = "tests/baselines/local/";
|
||||
var refBaseline = "tests/baselines/reference/";
|
||||
|
||||
var localRwcBaseline = "tests/baselines/rwc/local/";
|
||||
var refRwcBaseline = "tests/baselines/rwc/reference/";
|
||||
var localRwcBaseline = path.join(internalTests, "baselines/rwc/local");
|
||||
var refRwcBaseline = path.join(internalTests, "baselines/rwc/reference");
|
||||
|
||||
var localTest262Baseline = "tests/baselines/test262/local/";
|
||||
var refTest262Baseline = "tests/baselines/test262/reference/";
|
||||
var localTest262Baseline = path.join(internalTests, "baselines/test262/local");
|
||||
var refTest262Baseline = path.join(internalTests, "baselines/test262/reference");
|
||||
|
||||
desc("Builds the test infrastructure using the built compiler");
|
||||
task("tests", ["local", run].concat(libraryTargets));
|
||||
@@ -497,11 +503,13 @@ function cleanTestDirs() {
|
||||
jake.rmRf(localBaseline);
|
||||
}
|
||||
|
||||
// Clean the local Rwc baselines directory
|
||||
// Clean the local Rwc baselines directory
|
||||
if (fs.existsSync(localRwcBaseline)) {
|
||||
jake.rmRf(localRwcBaseline);
|
||||
}
|
||||
|
||||
jake.mkdirP(localRwcBaseline);
|
||||
jake.mkdirP(localTest262Baseline);
|
||||
jake.mkdirP(localBaseline);
|
||||
}
|
||||
|
||||
@@ -513,8 +521,8 @@ function writeTestConfigFile(tests, testConfigFile) {
|
||||
}
|
||||
|
||||
function deleteTemporaryProjectOutput() {
|
||||
if (fs.existsSync(localBaseline + "projectOutput/")) {
|
||||
jake.rmRf(localBaseline + "projectOutput/");
|
||||
if (fs.existsSync(path.join(localBaseline, "projectOutput/"))) {
|
||||
jake.rmRf(path.join(localBaseline, "projectOutput/"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1908,7 +1908,7 @@ declare module Intl {
|
||||
second?: string;
|
||||
timeZoneName?: string;
|
||||
formatMatcher?: string;
|
||||
hour12: boolean;
|
||||
hour12?: boolean;
|
||||
}
|
||||
|
||||
interface ResolvedDateTimeFormatOptions {
|
||||
|
||||
Vendored
+1
-1
@@ -758,7 +758,7 @@ declare module Intl {
|
||||
second?: string;
|
||||
timeZoneName?: string;
|
||||
formatMatcher?: string;
|
||||
hour12: boolean;
|
||||
hour12?: boolean;
|
||||
}
|
||||
|
||||
interface ResolvedDateTimeFormatOptions {
|
||||
|
||||
Vendored
+1
-1
@@ -4884,7 +4884,7 @@ declare module Intl {
|
||||
second?: string;
|
||||
timeZoneName?: string;
|
||||
formatMatcher?: string;
|
||||
hour12: boolean;
|
||||
hour12?: boolean;
|
||||
}
|
||||
|
||||
interface ResolvedDateTimeFormatOptions {
|
||||
|
||||
Vendored
+1
-1
@@ -758,7 +758,7 @@ declare module Intl {
|
||||
second?: string;
|
||||
timeZoneName?: string;
|
||||
formatMatcher?: string;
|
||||
hour12: boolean;
|
||||
hour12?: boolean;
|
||||
}
|
||||
|
||||
interface ResolvedDateTimeFormatOptions {
|
||||
|
||||
+5083
-4763
File diff suppressed because it is too large
Load Diff
Vendored
+135
-84
@@ -676,7 +676,7 @@ declare module "typescript" {
|
||||
exportName: Identifier;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
@@ -684,42 +684,46 @@ declare module "typescript" {
|
||||
interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
getLineAndCharacterFromPosition(position: number): LineAndCharacter;
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
getLineStarts(): number[];
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {
|
||||
path: string;
|
||||
name: string;
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
referenceDiagnostics: Diagnostic[];
|
||||
parseDiagnostics: Diagnostic[];
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
semanticDiagnostics: Diagnostic[];
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node;
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
}
|
||||
interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getTypeChecker(): TypeChecker;
|
||||
getCommonSourceDirectory(): string;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
emittedLine: number;
|
||||
@@ -740,33 +744,22 @@ declare module "typescript" {
|
||||
sourceMapMappings: string;
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
Succeeded = 0,
|
||||
AllOutputGenerationSkipped = 1,
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
DeclarationGenerationSkipped = 3,
|
||||
EmitErrorsEncountered = 4,
|
||||
CompilerOptionsErrors = 5,
|
||||
enum ExitStatus {
|
||||
Success = 0,
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[];
|
||||
}
|
||||
interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -790,7 +783,7 @@ declare module "typescript" {
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
@@ -828,6 +821,7 @@ declare module "typescript" {
|
||||
WriteOwnNameForAnyLike = 16,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
InElementType = 64,
|
||||
UseFullyQualifiedType = 128,
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
@@ -855,15 +849,13 @@ declare module "typescript" {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticErrors(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
const enum SymbolFlags {
|
||||
@@ -1099,7 +1091,6 @@ declare module "typescript" {
|
||||
key: string;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
isEarly?: boolean;
|
||||
}
|
||||
interface DiagnosticMessageChain {
|
||||
messageText: string;
|
||||
@@ -1111,13 +1102,9 @@ declare module "typescript" {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
/**
|
||||
* Early error - any error (can be produced at parsing\binding\typechecking step) that blocks emit
|
||||
*/
|
||||
isEarly?: boolean;
|
||||
}
|
||||
enum DiagnosticCategory {
|
||||
Warning = 0,
|
||||
@@ -1154,6 +1141,7 @@ declare module "typescript" {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@@ -1173,7 +1161,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
interface CommandLineOption {
|
||||
@@ -1184,6 +1172,7 @@ declare module "typescript" {
|
||||
description?: DiagnosticMessage;
|
||||
paramType?: DiagnosticMessage;
|
||||
error?: DiagnosticMessage;
|
||||
experimental?: boolean;
|
||||
}
|
||||
const enum CharacterCodes {
|
||||
nullCharacter = 0,
|
||||
@@ -1314,10 +1303,10 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1358,15 +1347,14 @@ declare module "typescript" {
|
||||
}
|
||||
function tokenToString(t: SyntaxKind): string;
|
||||
function computeLineStarts(text: string): number[];
|
||||
function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number;
|
||||
function getLineAndCharacterOfPosition(lineStarts: number[], position: number): {
|
||||
line: number;
|
||||
character: number;
|
||||
};
|
||||
function positionToLineAndCharacter(text: string, pos: number): {
|
||||
function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number;
|
||||
function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number;
|
||||
function getLineStarts(sourceFile: SourceFile): number[];
|
||||
function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): {
|
||||
line: number;
|
||||
character: number;
|
||||
};
|
||||
function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter;
|
||||
function isWhiteSpace(ch: number): boolean;
|
||||
function isLineBreak(ch: number): boolean;
|
||||
function isOctalDigit(ch: number): boolean;
|
||||
@@ -1382,8 +1370,9 @@ declare module "typescript" {
|
||||
function createNode(kind: SyntaxKind): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function modifierToFlag(token: SyntaxKind): NodeFlags;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function isLeftHandSideExpression(expr: Expression): boolean;
|
||||
function isAssignmentOperator(token: SyntaxKind): boolean;
|
||||
}
|
||||
@@ -1392,7 +1381,9 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
}
|
||||
declare module "typescript" {
|
||||
var servicesVersion: string;
|
||||
@@ -1437,11 +1428,14 @@ declare module "typescript" {
|
||||
getDocumentationComment(): SymbolDisplayPart[];
|
||||
}
|
||||
interface SourceFile {
|
||||
isOpen: boolean;
|
||||
version: string;
|
||||
scriptSnapshot: IScriptSnapshot;
|
||||
nameTable: Map<string>;
|
||||
getNamedDeclarations(): Declaration[];
|
||||
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
|
||||
getLineStarts(): number[];
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
}
|
||||
/**
|
||||
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
|
||||
@@ -1453,12 +1447,6 @@ declare module "typescript" {
|
||||
getText(start: number, end: number): string;
|
||||
/** Gets the length of this script snapshot. */
|
||||
getLength(): number;
|
||||
/**
|
||||
* This call returns the array containing the start position of every line.
|
||||
* i.e."[0, 10, 55]". TODO: consider making this optional. The language service could
|
||||
* always determine this (albeit in a more expensive manner).
|
||||
*/
|
||||
getLineStartPositions(): number[];
|
||||
/**
|
||||
* Gets the TextChangeRange that describe how the text changed between this text and
|
||||
* an older version. This information is used by the incremental parser to determine
|
||||
@@ -1476,22 +1464,19 @@ declare module "typescript" {
|
||||
importedFiles: FileReference[];
|
||||
isLibFile: boolean;
|
||||
}
|
||||
interface Logger {
|
||||
log(s: string): void;
|
||||
trace(s: string): void;
|
||||
error(s: string): void;
|
||||
}
|
||||
interface LanguageServiceHost extends Logger {
|
||||
interface LanguageServiceHost {
|
||||
getCompilationSettings(): CompilerOptions;
|
||||
getNewLine?(): string;
|
||||
getScriptFileNames(): string[];
|
||||
getScriptVersion(fileName: string): string;
|
||||
getScriptIsOpen(fileName: string): boolean;
|
||||
getScriptSnapshot(fileName: string): IScriptSnapshot;
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
log?(s: string): void;
|
||||
trace?(s: string): void;
|
||||
error?(s: string): void;
|
||||
}
|
||||
interface LanguageService {
|
||||
cleanupSemanticCache(): void;
|
||||
@@ -1521,7 +1506,8 @@ declare module "typescript" {
|
||||
getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[];
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getProgram(): Program;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
dispose(): void;
|
||||
}
|
||||
interface ClassifiedSpan {
|
||||
@@ -1671,6 +1657,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
interface CompletionEntry {
|
||||
@@ -1700,7 +1687,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
}
|
||||
const enum OutputFileType {
|
||||
JavaScript = 0,
|
||||
@@ -1740,10 +1727,68 @@ declare module "typescript" {
|
||||
interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
}
|
||||
/**
|
||||
* The document registry represents a store of SourceFile objects that can be shared between
|
||||
* multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST)
|
||||
* of files in the context.
|
||||
* SourceFile objects account for most of the memory usage by the language service. Sharing
|
||||
* the same DocumentRegistry instance between different instances of LanguageService allow
|
||||
* for more efficient memory utilization since all projects will share at least the library
|
||||
* file (lib.d.ts).
|
||||
*
|
||||
* A more advanced use of the document registry is to serialize sourceFile objects to disk
|
||||
* and re-hydrate them when needed.
|
||||
*
|
||||
* To create a default DocumentRegistry, use createDocumentRegistry to create one, and pass it
|
||||
* to all subsequent createLanguageService calls.
|
||||
*/
|
||||
interface DocumentRegistry {
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean): SourceFile;
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile;
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
/**
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
* @parm scriptSnapshot Text of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
* Note: It is not allowed to call update on a SourceFile that was not acquired from this
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
* @parm scriptSnapshot Text of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
/**
|
||||
* Informs the DocumentRegistry that a file is not needed any longer.
|
||||
*
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
}
|
||||
class ScriptElementKind {
|
||||
static unknown: string;
|
||||
@@ -1814,11 +1859,17 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile;
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry): LanguageService;
|
||||
function createClassifier(host: Logger): Classifier;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
|
||||
function createClassifier(): Classifier;
|
||||
/**
|
||||
* Get the path of the default library file (lib.d.ts) as distributed with the typescript
|
||||
* node package.
|
||||
* The functionality is not supported if the ts module is consumed outside of a node module.
|
||||
*/
|
||||
function getDefaultLibFilePath(options: CompilerOptions): string;
|
||||
}
|
||||
|
||||
Vendored
+135
-84
@@ -676,7 +676,7 @@ declare module ts {
|
||||
exportName: Identifier;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
@@ -684,42 +684,46 @@ declare module ts {
|
||||
interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
getLineAndCharacterFromPosition(position: number): LineAndCharacter;
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
getLineStarts(): number[];
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {
|
||||
path: string;
|
||||
name: string;
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
referenceDiagnostics: Diagnostic[];
|
||||
parseDiagnostics: Diagnostic[];
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
semanticDiagnostics: Diagnostic[];
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node;
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
}
|
||||
interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getTypeChecker(): TypeChecker;
|
||||
getCommonSourceDirectory(): string;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
emittedLine: number;
|
||||
@@ -740,33 +744,22 @@ declare module ts {
|
||||
sourceMapMappings: string;
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
Succeeded = 0,
|
||||
AllOutputGenerationSkipped = 1,
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
DeclarationGenerationSkipped = 3,
|
||||
EmitErrorsEncountered = 4,
|
||||
CompilerOptionsErrors = 5,
|
||||
enum ExitStatus {
|
||||
Success = 0,
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[];
|
||||
}
|
||||
interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -790,7 +783,7 @@ declare module ts {
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
@@ -828,6 +821,7 @@ declare module ts {
|
||||
WriteOwnNameForAnyLike = 16,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
InElementType = 64,
|
||||
UseFullyQualifiedType = 128,
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
@@ -855,15 +849,13 @@ declare module ts {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticErrors(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
const enum SymbolFlags {
|
||||
@@ -1099,7 +1091,6 @@ declare module ts {
|
||||
key: string;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
isEarly?: boolean;
|
||||
}
|
||||
interface DiagnosticMessageChain {
|
||||
messageText: string;
|
||||
@@ -1111,13 +1102,9 @@ declare module ts {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
/**
|
||||
* Early error - any error (can be produced at parsing\binding\typechecking step) that blocks emit
|
||||
*/
|
||||
isEarly?: boolean;
|
||||
}
|
||||
enum DiagnosticCategory {
|
||||
Warning = 0,
|
||||
@@ -1154,6 +1141,7 @@ declare module ts {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@@ -1173,7 +1161,7 @@ declare module ts {
|
||||
}
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
interface CommandLineOption {
|
||||
@@ -1184,6 +1172,7 @@ declare module ts {
|
||||
description?: DiagnosticMessage;
|
||||
paramType?: DiagnosticMessage;
|
||||
error?: DiagnosticMessage;
|
||||
experimental?: boolean;
|
||||
}
|
||||
const enum CharacterCodes {
|
||||
nullCharacter = 0,
|
||||
@@ -1314,10 +1303,10 @@ declare module ts {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1358,15 +1347,14 @@ declare module ts {
|
||||
}
|
||||
function tokenToString(t: SyntaxKind): string;
|
||||
function computeLineStarts(text: string): number[];
|
||||
function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number;
|
||||
function getLineAndCharacterOfPosition(lineStarts: number[], position: number): {
|
||||
line: number;
|
||||
character: number;
|
||||
};
|
||||
function positionToLineAndCharacter(text: string, pos: number): {
|
||||
function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number;
|
||||
function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number;
|
||||
function getLineStarts(sourceFile: SourceFile): number[];
|
||||
function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): {
|
||||
line: number;
|
||||
character: number;
|
||||
};
|
||||
function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter;
|
||||
function isWhiteSpace(ch: number): boolean;
|
||||
function isLineBreak(ch: number): boolean;
|
||||
function isOctalDigit(ch: number): boolean;
|
||||
@@ -1382,8 +1370,9 @@ declare module ts {
|
||||
function createNode(kind: SyntaxKind): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function modifierToFlag(token: SyntaxKind): NodeFlags;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function isLeftHandSideExpression(expr: Expression): boolean;
|
||||
function isAssignmentOperator(token: SyntaxKind): boolean;
|
||||
}
|
||||
@@ -1392,7 +1381,9 @@ declare module ts {
|
||||
}
|
||||
declare module ts {
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
}
|
||||
declare module ts {
|
||||
var servicesVersion: string;
|
||||
@@ -1437,11 +1428,14 @@ declare module ts {
|
||||
getDocumentationComment(): SymbolDisplayPart[];
|
||||
}
|
||||
interface SourceFile {
|
||||
isOpen: boolean;
|
||||
version: string;
|
||||
scriptSnapshot: IScriptSnapshot;
|
||||
nameTable: Map<string>;
|
||||
getNamedDeclarations(): Declaration[];
|
||||
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
|
||||
getLineStarts(): number[];
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
}
|
||||
/**
|
||||
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
|
||||
@@ -1453,12 +1447,6 @@ declare module ts {
|
||||
getText(start: number, end: number): string;
|
||||
/** Gets the length of this script snapshot. */
|
||||
getLength(): number;
|
||||
/**
|
||||
* This call returns the array containing the start position of every line.
|
||||
* i.e."[0, 10, 55]". TODO: consider making this optional. The language service could
|
||||
* always determine this (albeit in a more expensive manner).
|
||||
*/
|
||||
getLineStartPositions(): number[];
|
||||
/**
|
||||
* Gets the TextChangeRange that describe how the text changed between this text and
|
||||
* an older version. This information is used by the incremental parser to determine
|
||||
@@ -1476,22 +1464,19 @@ declare module ts {
|
||||
importedFiles: FileReference[];
|
||||
isLibFile: boolean;
|
||||
}
|
||||
interface Logger {
|
||||
log(s: string): void;
|
||||
trace(s: string): void;
|
||||
error(s: string): void;
|
||||
}
|
||||
interface LanguageServiceHost extends Logger {
|
||||
interface LanguageServiceHost {
|
||||
getCompilationSettings(): CompilerOptions;
|
||||
getNewLine?(): string;
|
||||
getScriptFileNames(): string[];
|
||||
getScriptVersion(fileName: string): string;
|
||||
getScriptIsOpen(fileName: string): boolean;
|
||||
getScriptSnapshot(fileName: string): IScriptSnapshot;
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
log?(s: string): void;
|
||||
trace?(s: string): void;
|
||||
error?(s: string): void;
|
||||
}
|
||||
interface LanguageService {
|
||||
cleanupSemanticCache(): void;
|
||||
@@ -1521,7 +1506,8 @@ declare module ts {
|
||||
getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[];
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getProgram(): Program;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
dispose(): void;
|
||||
}
|
||||
interface ClassifiedSpan {
|
||||
@@ -1671,6 +1657,7 @@ declare module ts {
|
||||
}
|
||||
interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
interface CompletionEntry {
|
||||
@@ -1700,7 +1687,7 @@ declare module ts {
|
||||
}
|
||||
interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
}
|
||||
const enum OutputFileType {
|
||||
JavaScript = 0,
|
||||
@@ -1740,10 +1727,68 @@ declare module ts {
|
||||
interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
}
|
||||
/**
|
||||
* The document registry represents a store of SourceFile objects that can be shared between
|
||||
* multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST)
|
||||
* of files in the context.
|
||||
* SourceFile objects account for most of the memory usage by the language service. Sharing
|
||||
* the same DocumentRegistry instance between different instances of LanguageService allow
|
||||
* for more efficient memory utilization since all projects will share at least the library
|
||||
* file (lib.d.ts).
|
||||
*
|
||||
* A more advanced use of the document registry is to serialize sourceFile objects to disk
|
||||
* and re-hydrate them when needed.
|
||||
*
|
||||
* To create a default DocumentRegistry, use createDocumentRegistry to create one, and pass it
|
||||
* to all subsequent createLanguageService calls.
|
||||
*/
|
||||
interface DocumentRegistry {
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean): SourceFile;
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile;
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
/**
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
* @parm scriptSnapshot Text of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
* Note: It is not allowed to call update on a SourceFile that was not acquired from this
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
* @parm scriptSnapshot Text of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
/**
|
||||
* Informs the DocumentRegistry that a file is not needed any longer.
|
||||
*
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
}
|
||||
class ScriptElementKind {
|
||||
static unknown: string;
|
||||
@@ -1814,11 +1859,17 @@ declare module ts {
|
||||
isCancellationRequested(): boolean;
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile;
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry): LanguageService;
|
||||
function createClassifier(host: Logger): Classifier;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
|
||||
function createClassifier(): Classifier;
|
||||
/**
|
||||
* Get the path of the default library file (lib.d.ts) as distributed with the typescript
|
||||
* node package.
|
||||
* The functionality is not supported if the ts module is consumed outside of a node module.
|
||||
*/
|
||||
function getDefaultLibFilePath(options: CompilerOptions): string;
|
||||
}
|
||||
|
||||
+6634
-6274
File diff suppressed because it is too large
Load Diff
Vendored
+9
-9
@@ -35,6 +35,7 @@ declare module ts {
|
||||
function concatenate<T>(array1: T[], array2: T[]): T[];
|
||||
function deduplicate<T>(array: T[]): T[];
|
||||
function sum(array: any[], prop: string): number;
|
||||
function addRange<T>(to: T[], from: T[]): void;
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, undefined otherwise.
|
||||
*/
|
||||
@@ -67,9 +68,9 @@ declare module ts {
|
||||
function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic;
|
||||
function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain;
|
||||
function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain;
|
||||
function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic;
|
||||
function compareValues<T>(a: T, b: T): Comparison;
|
||||
function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): number;
|
||||
function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): Comparison;
|
||||
function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[];
|
||||
function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[];
|
||||
function normalizeSlashes(path: string): string;
|
||||
function getRootLength(path: string): number;
|
||||
@@ -79,10 +80,10 @@ declare module ts {
|
||||
function isUrl(path: string): boolean;
|
||||
function isRootedDiskPath(path: string): boolean;
|
||||
function getNormalizedPathComponents(path: string, currentDirectory: string): string[];
|
||||
function getNormalizedAbsolutePath(filename: string, currentDirectory: string): string;
|
||||
function getNormalizedAbsolutePath(fileName: string, currentDirectory: string): string;
|
||||
function getNormalizedPathFromPathComponents(pathComponents: string[]): string;
|
||||
function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean): string;
|
||||
function getBaseFilename(path: string): string;
|
||||
function getBaseFileName(path: string): string;
|
||||
function combinePaths(path1: string, path2: string): string;
|
||||
function fileExtensionIs(path: string, extension: string): boolean;
|
||||
function removeFileExtension(path: string): string;
|
||||
@@ -92,6 +93,7 @@ declare module ts {
|
||||
* Note that this doesn't actually wrap the input in double quotes.
|
||||
*/
|
||||
function escapeString(s: string): string;
|
||||
function getDefaultLibFileName(options: CompilerOptions): string;
|
||||
interface ObjectAllocator {
|
||||
getNodeConstructor(kind: SyntaxKind): new () => Node;
|
||||
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
|
||||
@@ -147,11 +149,10 @@ declare module ts {
|
||||
}
|
||||
interface EmitHost extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
getCommonSourceDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
getNewLine(): string;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
}
|
||||
function getSingleLineStringWriter(): StringSymbolWriter;
|
||||
function releaseStringWriter(writer: StringSymbolWriter): void;
|
||||
@@ -170,7 +171,7 @@ declare module ts {
|
||||
function unescapeIdentifier(identifier: string): string;
|
||||
function declarationNameToString(name: DeclarationName): string;
|
||||
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic;
|
||||
function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic;
|
||||
function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic;
|
||||
function getErrorSpanForNode(node: Node): Node;
|
||||
function isExternalModule(file: SourceFile): boolean;
|
||||
function isDeclarationFile(file: SourceFile): boolean;
|
||||
@@ -216,7 +217,6 @@ declare module ts {
|
||||
function isKeyword(token: SyntaxKind): boolean;
|
||||
function isTrivia(token: SyntaxKind): boolean;
|
||||
function isModifier(token: SyntaxKind): boolean;
|
||||
function createEmitHostFromProgram(program: Program): EmitHost;
|
||||
function textSpanEnd(span: TextSpan): number;
|
||||
function textSpanIsEmpty(span: TextSpan): boolean;
|
||||
function textSpanContainsPosition(span: TextSpan, position: number): boolean;
|
||||
@@ -246,7 +246,7 @@ declare module ts {
|
||||
declare module ts {
|
||||
var optionDeclarations: CommandLineOption[];
|
||||
function parseCommandLine(commandLine: string[]): ParsedCommandLine;
|
||||
function readConfigFile(filename: string): any;
|
||||
function readConfigFile(fileName: string): any;
|
||||
function parseConfigFile(json: any, basePath?: string): ParsedCommandLine;
|
||||
}
|
||||
declare module ts {
|
||||
|
||||
Vendored
+9
-9
@@ -35,6 +35,7 @@ declare module "typescript" {
|
||||
function concatenate<T>(array1: T[], array2: T[]): T[];
|
||||
function deduplicate<T>(array: T[]): T[];
|
||||
function sum(array: any[], prop: string): number;
|
||||
function addRange<T>(to: T[], from: T[]): void;
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, undefined otherwise.
|
||||
*/
|
||||
@@ -67,9 +68,9 @@ declare module "typescript" {
|
||||
function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic;
|
||||
function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain;
|
||||
function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain;
|
||||
function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic;
|
||||
function compareValues<T>(a: T, b: T): Comparison;
|
||||
function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): number;
|
||||
function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): Comparison;
|
||||
function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[];
|
||||
function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[];
|
||||
function normalizeSlashes(path: string): string;
|
||||
function getRootLength(path: string): number;
|
||||
@@ -79,10 +80,10 @@ declare module "typescript" {
|
||||
function isUrl(path: string): boolean;
|
||||
function isRootedDiskPath(path: string): boolean;
|
||||
function getNormalizedPathComponents(path: string, currentDirectory: string): string[];
|
||||
function getNormalizedAbsolutePath(filename: string, currentDirectory: string): string;
|
||||
function getNormalizedAbsolutePath(fileName: string, currentDirectory: string): string;
|
||||
function getNormalizedPathFromPathComponents(pathComponents: string[]): string;
|
||||
function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean): string;
|
||||
function getBaseFilename(path: string): string;
|
||||
function getBaseFileName(path: string): string;
|
||||
function combinePaths(path1: string, path2: string): string;
|
||||
function fileExtensionIs(path: string, extension: string): boolean;
|
||||
function removeFileExtension(path: string): string;
|
||||
@@ -92,6 +93,7 @@ declare module "typescript" {
|
||||
* Note that this doesn't actually wrap the input in double quotes.
|
||||
*/
|
||||
function escapeString(s: string): string;
|
||||
function getDefaultLibFileName(options: CompilerOptions): string;
|
||||
interface ObjectAllocator {
|
||||
getNodeConstructor(kind: SyntaxKind): new () => Node;
|
||||
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
|
||||
@@ -147,11 +149,10 @@ declare module "typescript" {
|
||||
}
|
||||
interface EmitHost extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
getCommonSourceDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
getNewLine(): string;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
}
|
||||
function getSingleLineStringWriter(): StringSymbolWriter;
|
||||
function releaseStringWriter(writer: StringSymbolWriter): void;
|
||||
@@ -170,7 +171,7 @@ declare module "typescript" {
|
||||
function unescapeIdentifier(identifier: string): string;
|
||||
function declarationNameToString(name: DeclarationName): string;
|
||||
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic;
|
||||
function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic;
|
||||
function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic;
|
||||
function getErrorSpanForNode(node: Node): Node;
|
||||
function isExternalModule(file: SourceFile): boolean;
|
||||
function isDeclarationFile(file: SourceFile): boolean;
|
||||
@@ -216,7 +217,6 @@ declare module "typescript" {
|
||||
function isKeyword(token: SyntaxKind): boolean;
|
||||
function isTrivia(token: SyntaxKind): boolean;
|
||||
function isModifier(token: SyntaxKind): boolean;
|
||||
function createEmitHostFromProgram(program: Program): EmitHost;
|
||||
function textSpanEnd(span: TextSpan): number;
|
||||
function textSpanIsEmpty(span: TextSpan): boolean;
|
||||
function textSpanContainsPosition(span: TextSpan, position: number): boolean;
|
||||
@@ -246,7 +246,7 @@ declare module "typescript" {
|
||||
declare module "typescript" {
|
||||
var optionDeclarations: CommandLineOption[];
|
||||
function parseCommandLine(commandLine: string[]): ParsedCommandLine;
|
||||
function readConfigFile(filename: string): any;
|
||||
function readConfigFile(fileName: string): any;
|
||||
function parseConfigFile(json: any, basePath?: string): ParsedCommandLine;
|
||||
}
|
||||
declare module "typescript" {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Run this PowerShell script to enable dev mode and/or a custom script for the TypeScript language service, e.g.
|
||||
|
||||
PS C:\> .\scripts\VSDevMode.ps1 -enableDevMode -tsScript C:\src\TypeScript\built\local\typescriptServices.js
|
||||
|
||||
Note: If you get security errors, try running powershell as an Administrator and with the "-executionPolicy remoteSigned" switch
|
||||
|
||||
.PARAMETER vsVersion
|
||||
Set to "12" for Dev12 (VS2013) or "14" (the default) for Dev14 (VS2015)
|
||||
|
||||
.PARAMETER enableDevMode
|
||||
Pass this switch to enable attaching a debugger to the language service
|
||||
|
||||
.PARAMETER tsScript
|
||||
The path to a custom language service script to use, e.g. "C:\src\TypeScript\built\local\typescriptServices.js"
|
||||
#>
|
||||
Param(
|
||||
[int]$vsVersion = 14,
|
||||
[switch]$enableDevMode,
|
||||
[string]$tsScript
|
||||
)
|
||||
|
||||
$vsRegKey = "HKCU:\Software\Microsoft\VisualStudio\${vsVersion}.0"
|
||||
$tsRegKey = "${vsRegKey}\TypeScriptLanguageService"
|
||||
|
||||
if($enableDevMode -ne $true -and $tsScript -eq ""){
|
||||
Throw "You must either enable language service debugging (-enableDevMode), set a custom script (-tsScript), or both"
|
||||
}
|
||||
|
||||
if(!(Test-Path $vsRegKey)){
|
||||
Throw "Visual Studio ${vsVersion} is not installed"
|
||||
}
|
||||
if(!(Test-Path $tsRegKey)){
|
||||
# Create the TypeScript subkey if it doesn't exist
|
||||
New-Item -path $tsRegKey
|
||||
}
|
||||
|
||||
if($tsScript -ne ""){
|
||||
if(!(Test-Path $tsScript)){
|
||||
Throw "Could not locate the TypeScript language service script at ${tsScript}"
|
||||
}
|
||||
Set-ItemProperty -path $tsRegKey -name CustomTypeScriptServicesFileLocation -value "${tsScript}"
|
||||
Write-Host "Enabled custom TypeScript language service at ${tsScript} for Dev${vsVersion}"
|
||||
}
|
||||
if($enableDevMode){
|
||||
Set-ItemProperty -path $tsRegKey -name EnableDevMode -value 1
|
||||
Write-Host "Enabled developer mode for Dev${vsVersion}"
|
||||
}
|
||||
+22
-5
@@ -1,6 +1,8 @@
|
||||
/// <reference path="parser.ts"/>
|
||||
|
||||
module ts {
|
||||
/* @internal */ export var bindTime = 0;
|
||||
|
||||
export const enum ModuleInstanceState {
|
||||
NonInstantiated = 0,
|
||||
Instantiated = 1,
|
||||
@@ -60,8 +62,13 @@ module ts {
|
||||
return declaration.name && declaration.name.kind === SyntaxKind.ComputedPropertyName;
|
||||
}
|
||||
|
||||
export function bindSourceFile(file: SourceFile) {
|
||||
export function bindSourceFile(file: SourceFile): void {
|
||||
var start = new Date().getTime();
|
||||
bindSourceFileWorker(file);
|
||||
bindTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
function bindSourceFileWorker(file: SourceFile): void {
|
||||
var parent: Node;
|
||||
var container: Node;
|
||||
var blockScopeContainer: Node;
|
||||
@@ -136,9 +143,9 @@ module ts {
|
||||
: Diagnostics.Duplicate_identifier_0;
|
||||
|
||||
forEach(symbol.declarations, declaration => {
|
||||
file.semanticDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
|
||||
});
|
||||
file.semanticDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
|
||||
|
||||
symbol = createSymbol(0, name);
|
||||
}
|
||||
@@ -159,7 +166,7 @@ module ts {
|
||||
if (node.name) {
|
||||
node.name.parent = node;
|
||||
}
|
||||
file.semanticDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
|
||||
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
|
||||
}
|
||||
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
|
||||
@@ -471,10 +478,20 @@ module ts {
|
||||
break;
|
||||
case SyntaxKind.SourceFile:
|
||||
if (isExternalModule(<SourceFile>node)) {
|
||||
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"', /*isBlockScopeContainer*/ true);
|
||||
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).fileName) + '"', /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.Block:
|
||||
// do not treat function block a block-scope container
|
||||
// all block-scope locals that reside in this block should go to the function locals.
|
||||
// Otherwise this won't be considered as redeclaration of a block scoped local:
|
||||
// function foo() {
|
||||
// let x;
|
||||
// var x;
|
||||
// }
|
||||
// 'var x' will be placed into the function locals and 'let x' - into the locals of the block
|
||||
bindChildren(node, 0, /*isBlockScopeContainer*/ !isAnyFunction(node.parent));
|
||||
break;
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
|
||||
+246
-192
@@ -5,6 +5,8 @@ module ts {
|
||||
var nextNodeId = 1;
|
||||
var nextMergeId = 1;
|
||||
|
||||
/* @internal */ export var checkTime = 0;
|
||||
|
||||
export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
|
||||
var Symbol = objectAllocator.getSymbolConstructor();
|
||||
var Type = objectAllocator.getTypeConstructor();
|
||||
@@ -48,12 +50,12 @@ module ts {
|
||||
getContextualType,
|
||||
getFullyQualifiedName,
|
||||
getResolvedSignature,
|
||||
getEnumMemberValue,
|
||||
getConstantValue,
|
||||
isValidPropertyAccess,
|
||||
getSignatureFromDeclaration,
|
||||
isImplementationOfOverload,
|
||||
getAliasedSymbol: resolveImport,
|
||||
getEmitResolver: () => emitResolver,
|
||||
getEmitResolver,
|
||||
};
|
||||
|
||||
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
@@ -104,8 +106,7 @@ module ts {
|
||||
var nodeLinks: NodeLinks[] = [];
|
||||
var potentialThisCollisions: Node[] = [];
|
||||
|
||||
var diagnostics: Diagnostic[] = [];
|
||||
var diagnosticsModified: boolean = false;
|
||||
var diagnostics = createDiagnosticCollection();
|
||||
|
||||
var primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = {
|
||||
"string": {
|
||||
@@ -122,16 +123,18 @@ module ts {
|
||||
}
|
||||
};
|
||||
|
||||
function addDiagnostic(diagnostic: Diagnostic) {
|
||||
diagnostics.push(diagnostic);
|
||||
diagnosticsModified = true;
|
||||
function getEmitResolver(sourceFile?: SourceFile) {
|
||||
// Ensure we have all the type information in place for this file so that all the
|
||||
// emitter questions of this resolver will return the right information.
|
||||
getDiagnostics(sourceFile);
|
||||
return emitResolver;
|
||||
}
|
||||
|
||||
function error(location: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
|
||||
var diagnostic = location
|
||||
? createDiagnosticForNode(location, message, arg0, arg1, arg2)
|
||||
: createCompilerDiagnostic(message, arg0, arg1, arg2);
|
||||
addDiagnostic(diagnostic);
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
|
||||
function createSymbol(flags: SymbolFlags, name: string): Symbol {
|
||||
@@ -538,7 +541,7 @@ module ts {
|
||||
}
|
||||
|
||||
var moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
|
||||
var searchPath = getDirectoryPath(getSourceFile(location).filename);
|
||||
var searchPath = getDirectoryPath(getSourceFile(location).fileName);
|
||||
|
||||
// Module names are escaped in our symbol table. However, string literal values aren't.
|
||||
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
|
||||
@@ -553,8 +556,8 @@ module ts {
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
var filename = normalizePath(combinePaths(searchPath, moduleName));
|
||||
var sourceFile = host.getSourceFile(filename + ".ts") || host.getSourceFile(filename + ".d.ts");
|
||||
var fileName = normalizePath(combinePaths(searchPath, moduleName));
|
||||
var sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts");
|
||||
if (sourceFile || isRelative) break;
|
||||
var parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) break;
|
||||
@@ -564,7 +567,7 @@ module ts {
|
||||
if (sourceFile.symbol) {
|
||||
return getResolvedExportSymbol(sourceFile.symbol);
|
||||
}
|
||||
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
|
||||
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.fileName);
|
||||
return;
|
||||
}
|
||||
error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
|
||||
@@ -3479,7 +3482,8 @@ module ts {
|
||||
if (containingMessageChain) {
|
||||
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
|
||||
}
|
||||
addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine()));
|
||||
|
||||
diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
|
||||
}
|
||||
return result !== Ternary.False;
|
||||
|
||||
@@ -5705,9 +5709,9 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
var diagnosticsCount = diagnostics.length;
|
||||
var modificationCount = diagnostics.getModificationCount();
|
||||
checkClassPropertyAccess(node, left, type, prop);
|
||||
return diagnostics.length === diagnosticsCount
|
||||
return diagnostics.getModificationCount() === modificationCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5818,10 +5822,74 @@ module ts {
|
||||
return unknownSignature;
|
||||
}
|
||||
|
||||
// Re-order candidate signatures into the result array. Assumes the result array to be empty.
|
||||
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
|
||||
// A nit here is that we reorder only signatures that belong to the same symbol,
|
||||
// so order how inherited signatures are processed is still preserved.
|
||||
// interface A { (x: string): void }
|
||||
// interface B extends A { (x: 'foo'): string }
|
||||
// var b: B;
|
||||
// b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
|
||||
function reorderCandidates(signatures: Signature[], result: Signature[]): void {
|
||||
var lastParent: Node;
|
||||
var lastSymbol: Symbol;
|
||||
var cutoffIndex: number = 0;
|
||||
var index: number;
|
||||
var specializedIndex: number = -1;
|
||||
var spliceIndex: number;
|
||||
Debug.assert(!result.length);
|
||||
for (var i = 0; i < signatures.length; i++) {
|
||||
var signature = signatures[i];
|
||||
var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
|
||||
var parent = signature.declaration && signature.declaration.parent;
|
||||
if (!lastSymbol || symbol === lastSymbol) {
|
||||
if (lastParent && parent === lastParent) {
|
||||
index++;
|
||||
}
|
||||
else {
|
||||
lastParent = parent;
|
||||
index = cutoffIndex;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// current declaration belongs to a different symbol
|
||||
// set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex
|
||||
index = cutoffIndex = result.length;
|
||||
lastParent = parent;
|
||||
}
|
||||
lastSymbol = symbol;
|
||||
|
||||
// specialized signatures always need to be placed before non-specialized signatures regardless
|
||||
// of the cutoff position; see GH#1133
|
||||
if (signature.hasStringLiterals) {
|
||||
specializedIndex++;
|
||||
spliceIndex = specializedIndex;
|
||||
// The cutoff index always needs to be greater than or equal to the specialized signature index
|
||||
// in order to prevent non-specialized signatures from being added before a specialized
|
||||
// signature.
|
||||
cutoffIndex++;
|
||||
}
|
||||
else {
|
||||
spliceIndex = index;
|
||||
}
|
||||
|
||||
result.splice(spliceIndex, 0, signature);
|
||||
}
|
||||
}
|
||||
|
||||
function getSpreadArgumentIndex(args: Expression[]): number {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i].kind === SyntaxKind.SpreadElementExpression) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature) {
|
||||
var adjustedArgCount: number;
|
||||
var typeArguments: NodeArray<TypeNode>;
|
||||
var callIsIncomplete: boolean;
|
||||
var adjustedArgCount: number; // Apparent number of arguments we will have in this call
|
||||
var typeArguments: NodeArray<TypeNode>; // Type arguments (undefined if none)
|
||||
var callIsIncomplete: boolean; // In incomplete call we want to be lenient when we have too few arguments
|
||||
|
||||
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
var tagExpression = <TaggedTemplateExpression>node;
|
||||
@@ -5866,35 +5934,29 @@ module ts {
|
||||
typeArguments = callExpression.typeArguments;
|
||||
}
|
||||
|
||||
Debug.assert(adjustedArgCount !== undefined, "'adjustedArgCount' undefined");
|
||||
Debug.assert(callIsIncomplete !== undefined, "'callIsIncomplete' undefined");
|
||||
|
||||
return checkArity(adjustedArgCount, typeArguments, callIsIncomplete, signature);
|
||||
|
||||
/**
|
||||
* @param adjustedArgCount The "apparent" number of arguments that we will have in this call.
|
||||
* @param typeArguments Type arguments node of the call if it exists; undefined otherwise.
|
||||
* @param callIsIncomplete Whether or not a call is unfinished, and we should be "lenient" when we have too few arguments.
|
||||
* @param signature The signature whose arity we are comparing.
|
||||
*/
|
||||
function checkArity(adjustedArgCount: number, typeArguments: NodeArray<TypeNode>, callIsIncomplete: boolean, signature: Signature): boolean {
|
||||
// Too many arguments implies incorrect arity.
|
||||
if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the user supplied type arguments, but the number of type arguments does not match
|
||||
// the declared number of type parameters, the call has an incorrect arity.
|
||||
var hasRightNumberOfTypeArgs = !typeArguments ||
|
||||
(signature.typeParameters && typeArguments.length === signature.typeParameters.length);
|
||||
if (!hasRightNumberOfTypeArgs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the call is incomplete, we should skip the lower bound check.
|
||||
var hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
|
||||
return callIsIncomplete || hasEnoughArguments;
|
||||
// If the user supplied type arguments, but the number of type arguments does not match
|
||||
// the declared number of type parameters, the call has an incorrect arity.
|
||||
var hasRightNumberOfTypeArgs = !typeArguments ||
|
||||
(signature.typeParameters && typeArguments.length === signature.typeParameters.length);
|
||||
if (!hasRightNumberOfTypeArgs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If spread arguments are present, check that they correspond to a rest parameter. If so, no
|
||||
// further checking is necessary.
|
||||
var spreadArgIndex = getSpreadArgumentIndex(args);
|
||||
if (spreadArgIndex >= 0) {
|
||||
return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1;
|
||||
}
|
||||
|
||||
// Too many arguments implies incorrect arity.
|
||||
if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the call is incomplete, we should skip the lower bound check.
|
||||
var hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
|
||||
return callIsIncomplete || hasEnoughArguments;
|
||||
}
|
||||
|
||||
// If type has a single call signature and no other members, return that signature. Otherwise, return undefined.
|
||||
@@ -5927,18 +5989,20 @@ module ts {
|
||||
// We perform two passes over the arguments. In the first pass we infer from all arguments, but use
|
||||
// wildcards for all context sensitive function expressions.
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i].kind === SyntaxKind.OmittedExpression) {
|
||||
continue;
|
||||
var arg = args[i];
|
||||
if (arg.kind !== SyntaxKind.OmittedExpression) {
|
||||
var paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
var argType = globalTemplateStringsArrayType;
|
||||
}
|
||||
else {
|
||||
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
|
||||
// context sensitive function expressions as wildcards
|
||||
var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
|
||||
var argType = checkExpressionWithContextualType(arg, paramType, mapper);
|
||||
}
|
||||
inferTypes(context, argType, paramType);
|
||||
}
|
||||
var parameterType = getTypeAtPosition(signature, i);
|
||||
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
inferTypes(context, globalTemplateStringsArrayType, parameterType);
|
||||
continue;
|
||||
}
|
||||
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
|
||||
// context sensitive function expressions as wildcards
|
||||
var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
|
||||
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType);
|
||||
}
|
||||
|
||||
// In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this
|
||||
@@ -5946,13 +6010,11 @@ module ts {
|
||||
// as we construct types for contextually typed parameters)
|
||||
if (excludeArgument) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i].kind === SyntaxKind.OmittedExpression) {
|
||||
continue;
|
||||
}
|
||||
// No need to special-case tagged templates; their excludeArgument value will be 'undefined'.
|
||||
// No need to check for omitted args and template expressions, their exlusion value is always undefined
|
||||
if (excludeArgument[i] === false) {
|
||||
var parameterType = getTypeAtPosition(signature, i);
|
||||
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, inferenceMapper), parameterType);
|
||||
var arg = args[i];
|
||||
var paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5990,37 +6052,24 @@ module ts {
|
||||
return typeArgumentsAreAssignable;
|
||||
}
|
||||
|
||||
function checkApplicableSignature(node: CallLikeExpression, args: Node[], signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[], reportErrors: boolean) {
|
||||
function checkApplicableSignature(node: CallLikeExpression, args: Expression[], signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[], reportErrors: boolean) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i];
|
||||
var argType: Type;
|
||||
|
||||
if (arg.kind === SyntaxKind.OmittedExpression) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var paramType = getTypeAtPosition(signature, i);
|
||||
|
||||
if (i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
// A tagged template expression has something of a
|
||||
// "virtual" parameter with the "cooked" strings array type.
|
||||
argType = globalTemplateStringsArrayType;
|
||||
}
|
||||
else {
|
||||
// String literals get string literal types unless we're reporting errors
|
||||
argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors
|
||||
? getStringLiteralType(<LiteralExpression>arg)
|
||||
: checkExpressionWithContextualType(<LiteralExpression>arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
|
||||
}
|
||||
|
||||
// Use argument expression as error location when reporting errors
|
||||
var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
|
||||
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1);
|
||||
if (!isValidArgument) {
|
||||
return false;
|
||||
if (arg.kind !== SyntaxKind.OmittedExpression) {
|
||||
// Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter)
|
||||
var paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
// A tagged template expression provides a special first argument, and string literals get string literal types
|
||||
// unless we're reporting errors
|
||||
var argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression ? globalTemplateStringsArrayType :
|
||||
arg.kind === SyntaxKind.StringLiteral && !reportErrors ? getStringLiteralType(<LiteralExpression>arg) :
|
||||
checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
|
||||
// Use argument expression as error location when reporting errors
|
||||
if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
|
||||
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6087,8 +6136,8 @@ module ts {
|
||||
}
|
||||
|
||||
var candidates = candidatesOutArray || [];
|
||||
// collectCandidates fills up the candidates array directly
|
||||
collectCandidates();
|
||||
// reorderCandidates fills up the candidates array directly
|
||||
reorderCandidates(signatures, candidates);
|
||||
if (!candidates.length) {
|
||||
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
|
||||
return resolveErrorCall(node);
|
||||
@@ -6278,60 +6327,6 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
|
||||
// A nit here is that we reorder only signatures that belong to the same symbol,
|
||||
// so order how inherited signatures are processed is still preserved.
|
||||
// interface A { (x: string): void }
|
||||
// interface B extends A { (x: 'foo'): string }
|
||||
// var b: B;
|
||||
// b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
|
||||
function collectCandidates(): void {
|
||||
var result = candidates;
|
||||
var lastParent: Node;
|
||||
var lastSymbol: Symbol;
|
||||
var cutoffIndex: number = 0;
|
||||
var index: number;
|
||||
var specializedIndex: number = -1;
|
||||
var spliceIndex: number;
|
||||
Debug.assert(!result.length);
|
||||
for (var i = 0; i < signatures.length; i++) {
|
||||
var signature = signatures[i];
|
||||
var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
|
||||
var parent = signature.declaration && signature.declaration.parent;
|
||||
if (!lastSymbol || symbol === lastSymbol) {
|
||||
if (lastParent && parent === lastParent) {
|
||||
index++;
|
||||
}
|
||||
else {
|
||||
lastParent = parent;
|
||||
index = cutoffIndex;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// current declaration belongs to a different symbol
|
||||
// set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex
|
||||
index = cutoffIndex = result.length;
|
||||
lastParent = parent;
|
||||
}
|
||||
lastSymbol = symbol;
|
||||
|
||||
// specialized signatures always need to be placed before non-specialized signatures regardless
|
||||
// of the cutoff position; see GH#1133
|
||||
if (signature.hasStringLiterals) {
|
||||
specializedIndex++;
|
||||
spliceIndex = specializedIndex;
|
||||
// The cutoff index always needs to be greater than or equal to the specialized signature index
|
||||
// in order to prevent non-specialized signatures from being added before a specialized
|
||||
// signature.
|
||||
cutoffIndex++;
|
||||
}
|
||||
else {
|
||||
spliceIndex = index;
|
||||
}
|
||||
|
||||
result.splice(spliceIndex, 0, signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveCallExpression(node: CallExpression, candidatesOutArray: Signature[]): Signature {
|
||||
@@ -6387,6 +6382,13 @@ module ts {
|
||||
}
|
||||
|
||||
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
|
||||
if (node.arguments && languageVersion < ScriptTarget.ES6) {
|
||||
var spreadIndex = getSpreadArgumentIndex(node.arguments);
|
||||
if (spreadIndex >= 0) {
|
||||
error(node.arguments[spreadIndex], Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
}
|
||||
|
||||
var expressionType = checkExpression(node.expression);
|
||||
// TS 1.0 spec: 4.11
|
||||
// If ConstructExpr is of type Any, Args can be any argument
|
||||
@@ -6532,9 +6534,14 @@ module ts {
|
||||
}
|
||||
|
||||
function getTypeAtPosition(signature: Signature, pos: number): Type {
|
||||
if (pos >= 0) {
|
||||
return signature.hasRestParameter ?
|
||||
pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
|
||||
pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
|
||||
}
|
||||
return signature.hasRestParameter ?
|
||||
pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
|
||||
pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
|
||||
getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) :
|
||||
anyArrayType;
|
||||
}
|
||||
|
||||
function assignContextualParameterTypes(signature: Signature, context: Signature, mapper: TypeMapper) {
|
||||
@@ -8191,32 +8198,61 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkCollisionWithConstDeclarations(node: VariableLikeDeclaration) {
|
||||
function checkVarDeclaredNamesNotShadowed(node: VariableDeclaration | BindingElement) {
|
||||
// - ScriptBody : StatementList
|
||||
// It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList
|
||||
// also occurs in the VarDeclaredNames of StatementList.
|
||||
|
||||
// - Block : { StatementList }
|
||||
// It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList
|
||||
// also occurs in the VarDeclaredNames of StatementList.
|
||||
|
||||
// Variable declarations are hoisted to the top of their function scope. They can shadow
|
||||
// block scoped declarations, which bind tighter. this will not be flagged as duplicate definition
|
||||
// by the binder as the declaration scope is different.
|
||||
// A non-initialized declaration is a no-op as the block declaration will resolve before the var
|
||||
// declaration. the problem is if the declaration has an initializer. this will act as a write to the
|
||||
// block declared value. this is fine for let, but not const.
|
||||
//
|
||||
// Only consider declarations with initializers, uninitialized var declarations will not
|
||||
// step on a const variable.
|
||||
// step on a let/const variable.
|
||||
// Do not consider let and const declarations, as duplicate block-scoped declarations
|
||||
// are handled by the binder.
|
||||
// We are only looking for var declarations that step on const declarations from a
|
||||
// We are only looking for var declarations that step on let\const declarations from a
|
||||
// different scope. e.g.:
|
||||
// var x = 0;
|
||||
// {
|
||||
// const x = 0;
|
||||
// var x = 0;
|
||||
// const x = 0; // localDeclarationSymbol obtained after name resolution will correspond to this declaration
|
||||
// var x = 0; // symbol for this declaration will be 'symbol'
|
||||
// }
|
||||
if (node.initializer && (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0) {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
if (symbol.flags & SymbolFlags.FunctionScopedVariable) {
|
||||
var localDeclarationSymbol = resolveName(node, (<Identifier>node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) {
|
||||
if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) {
|
||||
error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol));
|
||||
if (localDeclarationSymbol &&
|
||||
localDeclarationSymbol !== symbol &&
|
||||
localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) {
|
||||
if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) {
|
||||
|
||||
var varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList);
|
||||
var container =
|
||||
varDeclList.parent.kind === SyntaxKind.VariableStatement &&
|
||||
varDeclList.parent.parent;
|
||||
|
||||
// names of block-scoped and function scoped variables can collide only
|
||||
// if block scoped variable is defined in the function\module\source file scope (because of variable hoisting)
|
||||
var namesShareScope =
|
||||
container &&
|
||||
(container.kind === SyntaxKind.Block && isAnyFunction(container.parent) ||
|
||||
(container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) ||
|
||||
container.kind === SyntaxKind.SourceFile);
|
||||
|
||||
// here we know that function scoped variable is shadowed by block scoped one
|
||||
// if they are defined in the same scope - binder has already reported redeclaration error
|
||||
// otherwise if variable has an initializer - show error that initialization will fail
|
||||
// since LHS will be block scoped name instead of function scoped
|
||||
if (!namesShareScope) {
|
||||
var name = symbolToString(localDeclarationSymbol);
|
||||
error(getErrorSpanForNode(node), Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8313,7 +8349,9 @@ module ts {
|
||||
if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature) {
|
||||
// We know we don't have a binding pattern or computed name here
|
||||
checkExportsOnMergedDeclarations(node);
|
||||
checkCollisionWithConstDeclarations(node);
|
||||
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
|
||||
checkVarDeclaredNamesNotShadowed(<VariableDeclaration | BindingElement>node);
|
||||
}
|
||||
checkCollisionWithCapturedSuperVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithCapturedThisVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, <Identifier>node.name);
|
||||
@@ -8927,7 +8965,7 @@ module ts {
|
||||
|
||||
var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2);
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
|
||||
addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, host.getCompilerHost().getNewLine()));
|
||||
diagnostics.add(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9542,8 +9580,14 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
// Fully type check a source file and collect the relevant diagnostics.
|
||||
function checkSourceFile(node: SourceFile) {
|
||||
var start = new Date().getTime();
|
||||
checkSourceFileWorker(node);
|
||||
checkTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
// Fully type check a source file and collect the relevant diagnostics.
|
||||
function checkSourceFileWorker(node: SourceFile) {
|
||||
var links = getNodeLinks(node);
|
||||
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
|
||||
// Grammar checking
|
||||
@@ -9578,30 +9622,19 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getSortedDiagnostics(): Diagnostic[]{
|
||||
Debug.assert(produceDiagnostics, "diagnostics are available only in the full typecheck mode");
|
||||
|
||||
if (diagnosticsModified) {
|
||||
diagnostics.sort(compareDiagnostics);
|
||||
diagnostics = deduplicateSortedDiagnostics(diagnostics);
|
||||
diagnosticsModified = false;
|
||||
}
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
|
||||
throwIfNonDiagnosticsProducing();
|
||||
if (sourceFile) {
|
||||
checkSourceFile(sourceFile);
|
||||
return filter(getSortedDiagnostics(), d => d.file === sourceFile);
|
||||
return diagnostics.getDiagnostics(sourceFile.fileName);
|
||||
}
|
||||
forEach(host.getSourceFiles(), checkSourceFile);
|
||||
return getSortedDiagnostics();
|
||||
return diagnostics.getDiagnostics();
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[]{
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
throwIfNonDiagnosticsProducing();
|
||||
return filter(getSortedDiagnostics(), d => !d.file);
|
||||
return diagnostics.getGlobalDiagnostics();
|
||||
}
|
||||
|
||||
function throwIfNonDiagnosticsProducing() {
|
||||
@@ -9625,7 +9658,7 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]{
|
||||
function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[] {
|
||||
var symbols: SymbolTable = {};
|
||||
var memberFlags: NodeFlags = 0;
|
||||
function copySymbol(symbol: Symbol, meaning: SymbolFlags) {
|
||||
@@ -10011,7 +10044,7 @@ module ts {
|
||||
return getNamedMembers(propsByName);
|
||||
}
|
||||
|
||||
function getRootSymbols(symbol: Symbol): Symbol[]{
|
||||
function getRootSymbols(symbol: Symbol): Symbol[] {
|
||||
if (symbol.flags & SymbolFlags.UnionProperty) {
|
||||
var symbols: Symbol[] = [];
|
||||
var name = symbol.name;
|
||||
@@ -10119,11 +10152,6 @@ module ts {
|
||||
return isImportResolvedToValue(getSymbolOfNode(node));
|
||||
}
|
||||
|
||||
function hasSemanticDiagnostics(sourceFile?: SourceFile) {
|
||||
// Return true if there is any semantic error in a file or globally
|
||||
return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0;
|
||||
}
|
||||
|
||||
function isImportResolvedToValue(symbol: Symbol): boolean {
|
||||
var target = resolveImport(symbol);
|
||||
// const enums and modules that contain only const enums are not considered values from the emit perespective
|
||||
@@ -10177,7 +10205,11 @@ module ts {
|
||||
return getNodeLinks(node).enumMemberValue;
|
||||
}
|
||||
|
||||
function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number {
|
||||
function getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number {
|
||||
if (node.kind === SyntaxKind.EnumMember) {
|
||||
return getEnumMemberValue(<EnumMember>node);
|
||||
}
|
||||
|
||||
var symbol = getNodeLinks(node).resolvedSymbol;
|
||||
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
|
||||
var declaration = symbol.valueDeclaration;
|
||||
@@ -10216,9 +10248,7 @@ module ts {
|
||||
getExportAssignmentName,
|
||||
isReferencedImportDeclaration,
|
||||
getNodeCheckFlags,
|
||||
getEnumMemberValue,
|
||||
isTopLevelValueImportWithEntityName,
|
||||
hasSemanticDiagnostics,
|
||||
isDeclarationVisible,
|
||||
isImplementationOfOverload,
|
||||
writeTypeOfDeclaration,
|
||||
@@ -10234,14 +10264,15 @@ module ts {
|
||||
// Bind all source files and propagate errors
|
||||
forEach(host.getSourceFiles(), file => {
|
||||
bindSourceFile(file);
|
||||
forEach(file.semanticDiagnostics, addDiagnostic);
|
||||
});
|
||||
|
||||
// Initialize global symbol table
|
||||
forEach(host.getSourceFiles(), file => {
|
||||
if (!isExternalModule(file)) {
|
||||
extendSymbolTable(globals, file.locals);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize special symbols
|
||||
getSymbolLinks(undefinedSymbol).type = undefinedType;
|
||||
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
|
||||
@@ -10913,9 +10944,32 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var checkLetConstNames = languageVersion >= ScriptTarget.ES6 && (isLet(node) || isConst(node));
|
||||
|
||||
// 1. LexicalDeclaration : LetOrConst BindingList ;
|
||||
// It is a Syntax Error if the BoundNames of BindingList contains "let".
|
||||
// 2. ForDeclaration: ForDeclaration : LetOrConst ForBinding
|
||||
// It is a Syntax Error if the BoundNames of ForDeclaration contains "let".
|
||||
|
||||
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
||||
// and its Identifier is eval or arguments
|
||||
return checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
|
||||
return (checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name)) ||
|
||||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
|
||||
}
|
||||
|
||||
function checkGrammarNameInLetOrConstDeclarations(name: Identifier | BindingPattern): boolean {
|
||||
if (name.kind === SyntaxKind.Identifier) {
|
||||
if ((<Identifier>name).text === "let") {
|
||||
return grammarErrorOnNode(name, Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var elements = (<BindingPattern>name).elements;
|
||||
for (var i = 0; i < elements.length; ++i) {
|
||||
checkGrammarNameInLetOrConstDeclarations(elements[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarVariableDeclarationList(declarationList: VariableDeclarationList): boolean {
|
||||
@@ -11032,14 +11086,14 @@ module ts {
|
||||
if (!hasParseDiagnostics(sourceFile)) {
|
||||
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
|
||||
var start = scanToken(scanner, node.pos);
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
|
||||
diagnostics.add(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function grammarErrorAtPos(sourceFile: SourceFile, start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
|
||||
if (!hasParseDiagnostics(sourceFile)) {
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
|
||||
diagnostics.add(createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -11049,7 +11103,7 @@ module ts {
|
||||
if (!hasParseDiagnostics(sourceFile)) {
|
||||
var span = getErrorSpanForNode(node);
|
||||
var start = span.end > span.pos ? skipTrivia(sourceFile.text, span.pos) : span.pos;
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
|
||||
diagnostics.add(createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -11183,7 +11237,7 @@ module ts {
|
||||
if (!hasParseDiagnostics(sourceFile)) {
|
||||
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
|
||||
scanToken(scanner, node.pos);
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
|
||||
diagnostics.add(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ module ts {
|
||||
|
||||
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
|
||||
var options: CompilerOptions = {};
|
||||
var filenames: string[] = [];
|
||||
var fileNames: string[] = [];
|
||||
var errors: Diagnostic[] = [];
|
||||
var shortOptionNames: Map<string> = {};
|
||||
var optionNameMap: Map<CommandLineOption> = {};
|
||||
@@ -178,7 +178,7 @@ module ts {
|
||||
parseStrings(commandLine);
|
||||
return {
|
||||
options,
|
||||
filenames,
|
||||
fileNames,
|
||||
errors
|
||||
};
|
||||
|
||||
@@ -232,16 +232,16 @@ module ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
filenames.push(s);
|
||||
fileNames.push(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseResponseFile(filename: string) {
|
||||
var text = sys.readFile(filename);
|
||||
function parseResponseFile(fileName: string) {
|
||||
var text = sys.readFile(fileName);
|
||||
|
||||
if (!text) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.File_0_not_found, filename));
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.File_0_not_found, fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ module ts {
|
||||
pos++;
|
||||
}
|
||||
else {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Unterminated_quoted_string_in_response_file_0, filename));
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Unterminated_quoted_string_in_response_file_0, fileName));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -271,9 +271,9 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function readConfigFile(filename: string): any {
|
||||
export function readConfigFile(fileName: string): any {
|
||||
try {
|
||||
var text = sys.readFile(filename);
|
||||
var text = sys.readFile(fileName);
|
||||
return /\S/.test(text) ? JSON.parse(text) : {};
|
||||
}
|
||||
catch (e) {
|
||||
@@ -285,7 +285,7 @@ module ts {
|
||||
|
||||
return {
|
||||
options: getCompilerOptions(),
|
||||
filenames: getFiles(),
|
||||
fileNames: getFiles(),
|
||||
errors
|
||||
};
|
||||
|
||||
|
||||
+44
-42
@@ -118,6 +118,12 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function addRange<T>(to: T[], from: T[]): void {
|
||||
for (var i = 0, n = from.length; i < n; i++) {
|
||||
to.push(from[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, undefined otherwise.
|
||||
*/
|
||||
@@ -325,38 +331,6 @@ module ts {
|
||||
return headChain;
|
||||
}
|
||||
|
||||
export function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic {
|
||||
Debug.assert(start >= 0, "start must be non-negative, is " + start);
|
||||
Debug.assert(length >= 0, "length must be non-negative, is " + length);
|
||||
|
||||
var code = diagnosticChain.code;
|
||||
var category = diagnosticChain.category;
|
||||
var messageText = "";
|
||||
|
||||
var indent = 0;
|
||||
while (diagnosticChain) {
|
||||
if (indent) {
|
||||
messageText += newLine;
|
||||
|
||||
for (var i = 0; i < indent; i++) {
|
||||
messageText += " ";
|
||||
}
|
||||
}
|
||||
messageText += diagnosticChain.messageText;
|
||||
indent++;
|
||||
diagnosticChain = diagnosticChain.next;
|
||||
}
|
||||
|
||||
return {
|
||||
file,
|
||||
start,
|
||||
length,
|
||||
code,
|
||||
category,
|
||||
messageText
|
||||
};
|
||||
}
|
||||
|
||||
export function compareValues<T>(a: T, b: T): Comparison {
|
||||
if (a === b) return Comparison.EqualTo;
|
||||
if (a === undefined) return Comparison.LessThan;
|
||||
@@ -364,17 +338,45 @@ module ts {
|
||||
return a < b ? Comparison.LessThan : Comparison.GreaterThan;
|
||||
}
|
||||
|
||||
function getDiagnosticFilename(diagnostic: Diagnostic): string {
|
||||
return diagnostic.file ? diagnostic.file.filename : undefined;
|
||||
function getDiagnosticFileName(diagnostic: Diagnostic): string {
|
||||
return diagnostic.file ? diagnostic.file.fileName : undefined;
|
||||
}
|
||||
|
||||
export function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): number {
|
||||
return compareValues(getDiagnosticFilename(d1), getDiagnosticFilename(d2)) ||
|
||||
export function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): Comparison {
|
||||
return compareValues(getDiagnosticFileName(d1), getDiagnosticFileName(d2)) ||
|
||||
compareValues(d1.start, d2.start) ||
|
||||
compareValues(d1.length, d2.length) ||
|
||||
compareValues(d1.code, d2.code) ||
|
||||
compareValues(d1.messageText, d2.messageText) ||
|
||||
0;
|
||||
compareMessageText(d1.messageText, d2.messageText) ||
|
||||
Comparison.EqualTo;
|
||||
}
|
||||
|
||||
function compareMessageText(text1: string | DiagnosticMessageChain, text2: string | DiagnosticMessageChain): Comparison {
|
||||
while (text1 && text2) {
|
||||
// We still have both chains.
|
||||
var string1 = typeof text1 === "string" ? text1 : text1.messageText;
|
||||
var string2 = typeof text2 === "string" ? text2 : text2.messageText;
|
||||
|
||||
var res = compareValues(string1, string2);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
text1 = typeof text1 === "string" ? undefined : text1.next;
|
||||
text2 = typeof text2 === "string" ? undefined : text2.next;
|
||||
}
|
||||
|
||||
if (!text1 && !text2) {
|
||||
// if the chains are done, then these messages are the same.
|
||||
return Comparison.EqualTo;
|
||||
}
|
||||
|
||||
// We still have one chain remaining. The shorter chain should come first.
|
||||
return text1 ? Comparison.GreaterThan : Comparison.LessThan;
|
||||
}
|
||||
|
||||
export function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[]{
|
||||
return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics));
|
||||
}
|
||||
|
||||
export function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] {
|
||||
@@ -472,8 +474,8 @@ module ts {
|
||||
return normalizedPathComponents(path, rootLength);
|
||||
}
|
||||
|
||||
export function getNormalizedAbsolutePath(filename: string, currentDirectory: string) {
|
||||
return getNormalizedPathFromPathComponents(getNormalizedPathComponents(filename, currentDirectory));
|
||||
export function getNormalizedAbsolutePath(fileName: string, currentDirectory: string) {
|
||||
return getNormalizedPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
|
||||
}
|
||||
|
||||
export function getNormalizedPathFromPathComponents(pathComponents: string[]) {
|
||||
@@ -571,7 +573,7 @@ module ts {
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
export function getBaseFilename(path: string) {
|
||||
export function getBaseFileName(path: string) {
|
||||
var i = path.lastIndexOf(directorySeparator);
|
||||
return i < 0 ? path : path.substring(i + 1);
|
||||
}
|
||||
@@ -644,7 +646,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultLibFilename(options: CompilerOptions): string {
|
||||
export function getDefaultLibFileName(options: CompilerOptions): string {
|
||||
return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts";
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ module ts {
|
||||
Declaration_expected: { code: 1146, category: DiagnosticCategory.Error, key: "Declaration expected." },
|
||||
Import_declarations_in_an_internal_module_cannot_reference_an_external_module: { code: 1147, category: DiagnosticCategory.Error, key: "Import declarations in an internal module cannot reference an external module." },
|
||||
Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." },
|
||||
Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" },
|
||||
File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" },
|
||||
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
|
||||
var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." },
|
||||
let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." },
|
||||
@@ -303,6 +303,16 @@ module ts {
|
||||
this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." },
|
||||
super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." },
|
||||
A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." },
|
||||
Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2468, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." },
|
||||
Enum_declarations_must_all_be_const_or_non_const: { code: 2469, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
|
||||
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2470, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." },
|
||||
const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2471, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." },
|
||||
A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 2472, category: DiagnosticCategory.Error, key: "A const enum member can only be accessed using a string literal." },
|
||||
const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 2473, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." },
|
||||
const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 2474, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." },
|
||||
Property_0_does_not_exist_on_const_enum_1: { code: 2475, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'." },
|
||||
let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 2476, category: DiagnosticCategory.Error, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." },
|
||||
Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 2477, category: DiagnosticCategory.Error, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
@@ -372,13 +382,6 @@ module ts {
|
||||
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
|
||||
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
|
||||
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
|
||||
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
|
||||
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." },
|
||||
const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 4084, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." },
|
||||
A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 4085, category: DiagnosticCategory.Error, key: "A const enum member can only be accessed using a string literal." },
|
||||
const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." },
|
||||
const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." },
|
||||
Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'." },
|
||||
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
|
||||
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
|
||||
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
|
||||
@@ -451,6 +454,7 @@ module ts {
|
||||
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
|
||||
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
|
||||
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
|
||||
You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." },
|
||||
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },
|
||||
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." },
|
||||
The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." },
|
||||
|
||||
@@ -427,7 +427,7 @@
|
||||
"category": "Error",
|
||||
"code": 1148
|
||||
},
|
||||
"Filename '{0}' differs from already included filename '{1}' only in casing": {
|
||||
"File name '{0}' differs from already included file name '{1}' only in casing": {
|
||||
"category": "Error",
|
||||
"code": 1149
|
||||
},
|
||||
@@ -1204,6 +1204,46 @@
|
||||
"category": "Error",
|
||||
"code": 2466
|
||||
},
|
||||
"Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher.": {
|
||||
"category": "Error",
|
||||
"code": 2468
|
||||
},
|
||||
"Enum declarations must all be const or non-const.": {
|
||||
"category": "Error",
|
||||
"code": 2469
|
||||
},
|
||||
"In 'const' enum declarations member initializer must be constant expression.": {
|
||||
"category": "Error",
|
||||
"code": 2470
|
||||
},
|
||||
"'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment.": {
|
||||
"category": "Error",
|
||||
"code": 2471
|
||||
},
|
||||
"A const enum member can only be accessed using a string literal.": {
|
||||
"category": "Error",
|
||||
"code": 2472
|
||||
},
|
||||
"'const' enum member initializer was evaluated to a non-finite value.": {
|
||||
"category": "Error",
|
||||
"code": 2473
|
||||
},
|
||||
"'const' enum member initializer was evaluated to disallowed value 'NaN'.": {
|
||||
"category": "Error",
|
||||
"code": 2474
|
||||
},
|
||||
"Property '{0}' does not exist on 'const' enum '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 2475
|
||||
},
|
||||
"'let' is not allowed to be used as a name in 'let' or 'const' declarations.": {
|
||||
"category": "Error",
|
||||
"code": 2476
|
||||
},
|
||||
"Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 2477
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
@@ -1481,34 +1521,6 @@
|
||||
"category": "Error",
|
||||
"code": 4081
|
||||
},
|
||||
"Enum declarations must all be const or non-const.": {
|
||||
"category": "Error",
|
||||
"code": 4082
|
||||
},
|
||||
"In 'const' enum declarations member initializer must be constant expression.": {
|
||||
"category": "Error",
|
||||
"code": 4083
|
||||
},
|
||||
"'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment.": {
|
||||
"category": "Error",
|
||||
"code": 4084
|
||||
},
|
||||
"A const enum member can only be accessed using a string literal.": {
|
||||
"category": "Error",
|
||||
"code": 4085
|
||||
},
|
||||
"'const' enum member initializer was evaluated to a non-finite value.": {
|
||||
"category": "Error",
|
||||
"code": 4086
|
||||
},
|
||||
"'const' enum member initializer was evaluated to disallowed value 'NaN'.": {
|
||||
"category": "Error",
|
||||
"code": 4087
|
||||
},
|
||||
"Property '{0}' does not exist on 'const' enum '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4088
|
||||
},
|
||||
"The current host does not support the '{0}' option.": {
|
||||
"category": "Error",
|
||||
"code": 5001
|
||||
@@ -1798,6 +1810,10 @@
|
||||
"category": "Error",
|
||||
"code": 8000
|
||||
},
|
||||
"You cannot rename elements that are defined in the standard TypeScript library.": {
|
||||
"category": "Error",
|
||||
"code": 8001
|
||||
},
|
||||
"'yield' expressions are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9000
|
||||
|
||||
+263
-178
@@ -55,7 +55,7 @@ module ts {
|
||||
|
||||
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
|
||||
if (!isDeclarationFile(sourceFile)) {
|
||||
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
|
||||
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -314,7 +314,7 @@ module ts {
|
||||
}
|
||||
|
||||
function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) {
|
||||
var sourceFilePath = getNormalizedAbsolutePath(sourceFile.filename, host.getCurrentDirectory());
|
||||
var sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
|
||||
sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), "");
|
||||
return combinePaths(newDirPath, sourceFilePath);
|
||||
}
|
||||
@@ -325,15 +325,15 @@ module ts {
|
||||
var emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
|
||||
}
|
||||
else {
|
||||
var emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.filename);
|
||||
var emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName);
|
||||
}
|
||||
|
||||
return emitOutputFilePathWithoutExtension + extension;
|
||||
}
|
||||
|
||||
function writeFile(host: EmitHost, diagnostics: Diagnostic[], filename: string, data: string, writeByteOrderMark: boolean) {
|
||||
host.writeFile(filename, data, writeByteOrderMark, hostErrorMessage => {
|
||||
diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
|
||||
function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) {
|
||||
host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => {
|
||||
diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -825,7 +825,7 @@ module ts {
|
||||
function emitEnumMemberDeclaration(node: EnumMember) {
|
||||
emitJsDocComments(node);
|
||||
writeTextOfNode(currentSourceFile, node.name);
|
||||
var enumMemberValue = resolver.getEnumMemberValue(node);
|
||||
var enumMemberValue = resolver.getConstantValue(node);
|
||||
if (enumMemberValue !== undefined) {
|
||||
write(" = ");
|
||||
write(enumMemberValue.toString());
|
||||
@@ -1144,7 +1144,9 @@ module ts {
|
||||
if (accessor) {
|
||||
return accessor.kind === SyntaxKind.GetAccessor
|
||||
? accessor.type // Getter - return type
|
||||
: accessor.parameters[0].type; // Setter parameter type
|
||||
: accessor.parameters.length > 0
|
||||
? accessor.parameters[0].type // Setter parameter type
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1481,7 +1483,7 @@ module ts {
|
||||
|
||||
function writeReferencePath(referencedFile: SourceFile) {
|
||||
var declFileName = referencedFile.flags & NodeFlags.DeclarationFile
|
||||
? referencedFile.filename // Declaration file, use declaration file name
|
||||
? referencedFile.fileName // Declaration file, use declaration file name
|
||||
: shouldEmitToOwnFile(referencedFile, compilerOptions)
|
||||
? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
|
||||
: removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file
|
||||
@@ -1504,14 +1506,47 @@ module ts {
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
|
||||
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile?: SourceFile): EmitResult {
|
||||
// @internal
|
||||
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
|
||||
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile): EmitResult {
|
||||
var compilerOptions = host.getCompilerOptions();
|
||||
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
|
||||
var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
|
||||
var diagnostics: Diagnostic[] = [];
|
||||
var newLine = host.getNewLine();
|
||||
|
||||
if (targetSourceFile === undefined) {
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
|
||||
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js");
|
||||
emitFile(jsFilePath, sourceFile);
|
||||
}
|
||||
});
|
||||
|
||||
if (compilerOptions.out) {
|
||||
emitFile(compilerOptions.out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
|
||||
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
|
||||
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
|
||||
emitFile(jsFilePath, targetSourceFile);
|
||||
}
|
||||
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
|
||||
emitFile(compilerOptions.out);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort and make the unique list of diagnostics
|
||||
diagnostics = sortAndDeduplicateDiagnostics(diagnostics);
|
||||
|
||||
return {
|
||||
emitSkipped: false,
|
||||
diagnostics,
|
||||
sourceMaps: sourceMapDataList
|
||||
};
|
||||
|
||||
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
|
||||
var writer = createTextWriter(newLine);
|
||||
var write = writer.write;
|
||||
@@ -1575,6 +1610,25 @@ module ts {
|
||||
/** Sourcemap data that will get encoded */
|
||||
var sourceMapData: SourceMapData;
|
||||
|
||||
if (compilerOptions.sourceMap) {
|
||||
initializeEmitterWithSourceMaps();
|
||||
}
|
||||
|
||||
if (root) {
|
||||
emit(root);
|
||||
}
|
||||
else {
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
|
||||
emit(sourceFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
writeLine();
|
||||
writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM);
|
||||
return;
|
||||
|
||||
function initializeEmitterWithSourceMaps() {
|
||||
var sourceMapDir: string; // The directory in which sourcemap will be
|
||||
|
||||
@@ -1735,14 +1789,14 @@ module ts {
|
||||
var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir;
|
||||
|
||||
sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
|
||||
node.filename,
|
||||
node.fileName,
|
||||
host.getCurrentDirectory(),
|
||||
host.getCanonicalFileName,
|
||||
/*isAbsolutePathAnUrl*/ true));
|
||||
sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
|
||||
|
||||
// The one that can be used from program to get the actual source file
|
||||
sourceMapData.inputSourceFileNames.push(node.filename);
|
||||
sourceMapData.inputSourceFileNames.push(node.fileName);
|
||||
}
|
||||
|
||||
function recordScopeNameOfNode(node: Node, scopeName?: string) {
|
||||
@@ -1857,7 +1911,7 @@ module ts {
|
||||
}
|
||||
|
||||
// Initialize source map data
|
||||
var sourceMapJsFile = getBaseFilename(normalizeSlashes(jsFilePath));
|
||||
var sourceMapJsFile = getBaseFileName(normalizeSlashes(jsFilePath));
|
||||
sourceMapData = {
|
||||
sourceMapFilePath: jsFilePath + ".map",
|
||||
jsSourceMappingURL: sourceMapJsFile + ".map",
|
||||
@@ -1940,7 +1994,7 @@ module ts {
|
||||
break;
|
||||
}
|
||||
// _a .. _h, _j ... _z, _0, _1, ...
|
||||
name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0: 1) + CharacterCodes.a) : tempCount - 25);
|
||||
name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + CharacterCodes.a) : tempCount - 25);
|
||||
tempCount++;
|
||||
}
|
||||
var result = <Identifier>createNode(SyntaxKind.Identifier);
|
||||
@@ -2372,22 +2426,10 @@ module ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function emitArrayLiteral(node: ArrayLiteralExpression) {
|
||||
var elements = node.elements;
|
||||
var length = elements.length;
|
||||
if (length === 0) {
|
||||
write("[]");
|
||||
return;
|
||||
}
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
write("[");
|
||||
emitList(elements, 0, elements.length, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0,
|
||||
/*trailingComma*/ elements.hasTrailingComma);
|
||||
write("]");
|
||||
return;
|
||||
}
|
||||
function emitListWithSpread(elements: Expression[], multiLine: boolean, trailingComma: boolean) {
|
||||
var pos = 0;
|
||||
var group = 0;
|
||||
var length = elements.length;
|
||||
while (pos < length) {
|
||||
// Emit using the pattern <group0>.concat(<group1>, <group2>, ...)
|
||||
if (group === 1) {
|
||||
@@ -2408,8 +2450,7 @@ module ts {
|
||||
i++;
|
||||
}
|
||||
write("[");
|
||||
emitList(elements, pos, i - pos, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
|
||||
/*trailingComma*/ elements.hasTrailingComma);
|
||||
emitList(elements, pos, i - pos, multiLine, trailingComma && i === length);
|
||||
write("]");
|
||||
pos = i;
|
||||
}
|
||||
@@ -2420,6 +2461,23 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitArrayLiteral(node: ArrayLiteralExpression) {
|
||||
var elements = node.elements;
|
||||
if (elements.length === 0) {
|
||||
write("[]");
|
||||
}
|
||||
else if (languageVersion >= ScriptTarget.ES6) {
|
||||
write("[");
|
||||
emitList(elements, 0, elements.length, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
|
||||
/*trailingComma*/ elements.hasTrailingComma);
|
||||
write("]");
|
||||
}
|
||||
else {
|
||||
emitListWithSpread(elements, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
|
||||
/*trailingComma*/ elements.hasTrailingComma);
|
||||
}
|
||||
}
|
||||
|
||||
function emitObjectLiteralBody(node: ObjectLiteralExpression, numElements: number) {
|
||||
write("{");
|
||||
|
||||
@@ -2660,7 +2718,80 @@ module ts {
|
||||
write("]");
|
||||
}
|
||||
|
||||
function hasSpreadElement(elements: Expression[]) {
|
||||
return forEach(elements, e => e.kind === SyntaxKind.SpreadElementExpression);
|
||||
}
|
||||
|
||||
function skipParentheses(node: Expression): Expression {
|
||||
while (node.kind === SyntaxKind.ParenthesizedExpression || node.kind === SyntaxKind.TypeAssertionExpression) {
|
||||
node = (<ParenthesizedExpression | TypeAssertion>node).expression;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function emitCallTarget(node: Expression): Expression {
|
||||
if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword) {
|
||||
emit(node);
|
||||
return node;
|
||||
}
|
||||
var temp = createTempVariable(node);
|
||||
recordTempDeclaration(temp);
|
||||
write("(");
|
||||
emit(temp);
|
||||
write(" = ");
|
||||
emit(node);
|
||||
write(")");
|
||||
return temp;
|
||||
}
|
||||
|
||||
function emitCallWithSpread(node: CallExpression) {
|
||||
var target: Expression;
|
||||
var expr = skipParentheses(node.expression);
|
||||
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
// Target will be emitted as "this" argument
|
||||
target = emitCallTarget((<PropertyAccessExpression>expr).expression);
|
||||
write(".");
|
||||
emit((<PropertyAccessExpression>expr).name);
|
||||
}
|
||||
else if (expr.kind === SyntaxKind.ElementAccessExpression) {
|
||||
// Target will be emitted as "this" argument
|
||||
target = emitCallTarget((<PropertyAccessExpression>expr).expression);
|
||||
write("[");
|
||||
emit((<ElementAccessExpression>expr).argumentExpression);
|
||||
write("]");
|
||||
}
|
||||
else if (expr.kind === SyntaxKind.SuperKeyword) {
|
||||
target = expr;
|
||||
write("_super");
|
||||
}
|
||||
else {
|
||||
emit(node.expression);
|
||||
}
|
||||
write(".apply(");
|
||||
if (target) {
|
||||
if (target.kind === SyntaxKind.SuperKeyword) {
|
||||
// Calls of form super(...) and super.foo(...)
|
||||
emitThis(target);
|
||||
}
|
||||
else {
|
||||
// Calls of form obj.foo(...)
|
||||
emit(target);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Calls of form foo(...)
|
||||
write("void 0");
|
||||
}
|
||||
write(", ");
|
||||
emitListWithSpread(node.arguments, /*multiLine*/ false, /*trailingComma*/ false);
|
||||
write(")");
|
||||
}
|
||||
|
||||
function emitCallExpression(node: CallExpression) {
|
||||
if (languageVersion < ScriptTarget.ES6 && hasSpreadElement(node.arguments)) {
|
||||
emitCallWithSpread(node);
|
||||
return;
|
||||
}
|
||||
var superCall = false;
|
||||
if (node.expression.kind === SyntaxKind.SuperKeyword) {
|
||||
write("_super");
|
||||
@@ -2786,7 +2917,6 @@ module ts {
|
||||
write(tokenToString(node.operator));
|
||||
}
|
||||
|
||||
|
||||
function emitBinaryExpression(node: BinaryExpression) {
|
||||
if (languageVersion < ScriptTarget.ES6 && node.operator === SyntaxKind.EqualsToken &&
|
||||
(node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) {
|
||||
@@ -2809,7 +2939,21 @@ module ts {
|
||||
emit(node.whenFalse);
|
||||
}
|
||||
|
||||
function isSingleLineBlock(node: Node) {
|
||||
if (node && node.kind === SyntaxKind.Block) {
|
||||
var block = <Block>node;
|
||||
return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block);
|
||||
}
|
||||
}
|
||||
|
||||
function emitBlock(node: Block) {
|
||||
if (isSingleLineBlock(node)) {
|
||||
emitToken(SyntaxKind.OpenBraceToken, node.pos);
|
||||
write(" ");
|
||||
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);
|
||||
return;
|
||||
}
|
||||
|
||||
emitToken(SyntaxKind.OpenBraceToken, node.pos);
|
||||
increaseIndent();
|
||||
scopeEmitStart(node.parent);
|
||||
@@ -2982,6 +3126,11 @@ module ts {
|
||||
getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos));
|
||||
}
|
||||
|
||||
function nodeEndIsOnSameLineAsNodeStart(node1: Node, node2: Node) {
|
||||
return getLineOfLocalPosition(currentSourceFile, node1.end) ===
|
||||
getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos));
|
||||
}
|
||||
|
||||
function emitCaseOrDefaultClause(node: CaseOrDefaultClause) {
|
||||
if (node.kind === SyntaxKind.CaseClause) {
|
||||
write("case ");
|
||||
@@ -3481,73 +3630,79 @@ module ts {
|
||||
emitSignatureParameters(node);
|
||||
}
|
||||
|
||||
write(" {");
|
||||
scopeEmitStart(node);
|
||||
|
||||
if (!node.body) {
|
||||
writeLine();
|
||||
write("}");
|
||||
if (isSingleLineBlock(node.body)) {
|
||||
write(" { }");
|
||||
}
|
||||
else {
|
||||
increaseIndent();
|
||||
write(" {");
|
||||
scopeEmitStart(node);
|
||||
|
||||
emitDetachedComments(node.body.kind === SyntaxKind.Block ? (<Block>node.body).statements : node.body);
|
||||
|
||||
var startIndex = 0;
|
||||
if (node.body.kind === SyntaxKind.Block) {
|
||||
startIndex = emitDirectivePrologues((<Block>node.body).statements, /*startWithNewLine*/ true);
|
||||
}
|
||||
var outPos = writer.getTextPos();
|
||||
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitDefaultValueAssignments(node);
|
||||
emitRestParameter(node);
|
||||
if (node.body.kind !== SyntaxKind.Block && outPos === writer.getTextPos()) {
|
||||
decreaseIndent();
|
||||
write(" ");
|
||||
emitStart(node.body);
|
||||
write("return ");
|
||||
|
||||
// Don't emit comments on this body. We'll have already taken care of it above
|
||||
// when we called emitDetachedComments.
|
||||
emitNode(node.body, /*disableComments:*/ true);
|
||||
emitEnd(node.body);
|
||||
write(";");
|
||||
emitTempDeclarations(/*newLine*/ false);
|
||||
write(" ");
|
||||
emitStart(node.body);
|
||||
if (!node.body) {
|
||||
writeLine();
|
||||
write("}");
|
||||
emitEnd(node.body);
|
||||
}
|
||||
else {
|
||||
increaseIndent();
|
||||
|
||||
emitDetachedComments(node.body.kind === SyntaxKind.Block ? (<Block>node.body).statements : node.body);
|
||||
|
||||
var startIndex = 0;
|
||||
if (node.body.kind === SyntaxKind.Block) {
|
||||
emitLinesStartingAt((<Block>node.body).statements, startIndex);
|
||||
startIndex = emitDirectivePrologues((<Block>node.body).statements, /*startWithNewLine*/ true);
|
||||
}
|
||||
else {
|
||||
writeLine();
|
||||
emitLeadingComments(node.body);
|
||||
var outPos = writer.getTextPos();
|
||||
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitDefaultValueAssignments(node);
|
||||
emitRestParameter(node);
|
||||
if (node.body.kind !== SyntaxKind.Block && outPos === writer.getTextPos()) {
|
||||
decreaseIndent();
|
||||
write(" ");
|
||||
emitStart(node.body);
|
||||
write("return ");
|
||||
emit(node.body, /*disableComments:*/ true);
|
||||
|
||||
// Don't emit comments on this body. We'll have already taken care of it above
|
||||
// when we called emitDetachedComments.
|
||||
emitNode(node.body, /*disableComments:*/ true);
|
||||
emitEnd(node.body);
|
||||
write(";");
|
||||
emitTrailingComments(node.body);
|
||||
}
|
||||
emitTempDeclarations(/*newLine*/ true);
|
||||
writeLine();
|
||||
if (node.body.kind === SyntaxKind.Block) {
|
||||
emitLeadingCommentsOfPosition((<Block>node.body).statements.end);
|
||||
decreaseIndent();
|
||||
emitToken(SyntaxKind.CloseBraceToken, (<Block>node.body).statements.end);
|
||||
}
|
||||
else {
|
||||
decreaseIndent();
|
||||
emitTempDeclarations(/*newLine*/ false);
|
||||
write(" ");
|
||||
emitStart(node.body);
|
||||
write("}");
|
||||
emitEnd(node.body);
|
||||
}
|
||||
else {
|
||||
if (node.body.kind === SyntaxKind.Block) {
|
||||
emitLinesStartingAt((<Block>node.body).statements, startIndex);
|
||||
}
|
||||
else {
|
||||
writeLine();
|
||||
emitLeadingComments(node.body);
|
||||
write("return ");
|
||||
emit(node.body, /*disableComments:*/ true);
|
||||
write(";");
|
||||
emitTrailingComments(node.body);
|
||||
}
|
||||
emitTempDeclarations(/*newLine*/ true);
|
||||
writeLine();
|
||||
if (node.body.kind === SyntaxKind.Block) {
|
||||
emitLeadingCommentsOfPosition((<Block>node.body).statements.end);
|
||||
decreaseIndent();
|
||||
emitToken(SyntaxKind.CloseBraceToken, (<Block>node.body).statements.end);
|
||||
}
|
||||
else {
|
||||
decreaseIndent();
|
||||
emitStart(node.body);
|
||||
write("}");
|
||||
emitEnd(node.body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scopeEmitEnd();
|
||||
}
|
||||
|
||||
scopeEmitEnd();
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
@@ -3908,7 +4063,7 @@ module ts {
|
||||
|
||||
function writeEnumMemberDeclarationValue(member: EnumMember) {
|
||||
if (!member.initializer || isConst(member.parent)) {
|
||||
var value = resolver.getEnumMemberValue(member);
|
||||
var value = resolver.getConstantValue(member);
|
||||
if (value !== undefined) {
|
||||
write(value.toString());
|
||||
return;
|
||||
@@ -4054,11 +4209,25 @@ module ts {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sortAMDModules(amdModules: {name: string; path: string}[]) {
|
||||
// AMD modules with declared variable names go first
|
||||
return amdModules.sort((moduleA, moduleB) => {
|
||||
if (moduleA.name === moduleB.name) {
|
||||
return 0;
|
||||
} else if (!moduleA.name) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function emitAMDModule(node: SourceFile, startIndex: number) {
|
||||
var imports = getExternalImportDeclarations(node);
|
||||
writeLine();
|
||||
write("define(");
|
||||
sortAMDModules(node.amdDependencies);
|
||||
if (node.amdModuleName) {
|
||||
write("\"" + node.amdModuleName + "\", ");
|
||||
}
|
||||
@@ -4068,7 +4237,7 @@ module ts {
|
||||
emitLiteral(<LiteralExpression>getExternalModuleImportDeclarationExpression(imp));
|
||||
});
|
||||
forEach(node.amdDependencies, amdDependency => {
|
||||
var text = "\"" + amdDependency + "\"";
|
||||
var text = "\"" + amdDependency.path + "\"";
|
||||
write(", ");
|
||||
write(text);
|
||||
});
|
||||
@@ -4077,6 +4246,12 @@ module ts {
|
||||
write(", ");
|
||||
emit(imp.name);
|
||||
});
|
||||
forEach(node.amdDependencies, amdDependency => {
|
||||
if (amdDependency.name) {
|
||||
write(", ");
|
||||
write(amdDependency.name);
|
||||
}
|
||||
});
|
||||
write(") {");
|
||||
increaseIndent();
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
@@ -4388,7 +4563,6 @@ module ts {
|
||||
return leadingComments;
|
||||
}
|
||||
|
||||
|
||||
function getLeadingCommentsToEmit(node: Node) {
|
||||
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
|
||||
if (node.parent) {
|
||||
@@ -4506,24 +4680,6 @@ module ts {
|
||||
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
|
||||
emitComments(currentSourceFile, writer, pinnedComments, /*trailingSeparator*/ true, newLine, writeComment);
|
||||
}
|
||||
|
||||
if (compilerOptions.sourceMap) {
|
||||
initializeEmitterWithSourceMaps();
|
||||
}
|
||||
|
||||
if (root) {
|
||||
emit(root);
|
||||
}
|
||||
else {
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
|
||||
emit(sourceFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
writeLine();
|
||||
writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM);
|
||||
}
|
||||
|
||||
function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile) {
|
||||
@@ -4546,83 +4702,12 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
var hasSemanticDiagnostics = false;
|
||||
var isEmitBlocked = false;
|
||||
|
||||
if (targetSourceFile === undefined) {
|
||||
// No targetSourceFile is specified (e.g. calling emitter from batch compiler)
|
||||
hasSemanticDiagnostics = resolver.hasSemanticDiagnostics();
|
||||
isEmitBlocked = host.isEmitBlocked();
|
||||
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
|
||||
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js");
|
||||
emitFile(jsFilePath, sourceFile);
|
||||
}
|
||||
});
|
||||
|
||||
if (compilerOptions.out) {
|
||||
emitFile(compilerOptions.out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
|
||||
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
|
||||
// If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
|
||||
hasSemanticDiagnostics = resolver.hasSemanticDiagnostics(targetSourceFile);
|
||||
isEmitBlocked = host.isEmitBlocked(targetSourceFile);
|
||||
|
||||
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
|
||||
emitFile(jsFilePath, targetSourceFile);
|
||||
}
|
||||
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
|
||||
// Otherwise, if --out is specified and targetSourceFile is not a declaration file,
|
||||
// Emit all, non-external-module file, into one single output file
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) {
|
||||
hasSemanticDiagnostics = hasSemanticDiagnostics || resolver.hasSemanticDiagnostics(sourceFile);
|
||||
isEmitBlocked = isEmitBlocked || host.isEmitBlocked(sourceFile);
|
||||
}
|
||||
});
|
||||
|
||||
emitFile(compilerOptions.out);
|
||||
}
|
||||
}
|
||||
|
||||
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
|
||||
if (!isEmitBlocked) {
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
if (!hasSemanticDiagnostics && compilerOptions.declaration) {
|
||||
writeDeclarationFile(jsFilePath, sourceFile);
|
||||
}
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
|
||||
if (compilerOptions.declaration) {
|
||||
writeDeclarationFile(jsFilePath, sourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort and make the unique list of diagnostics
|
||||
diagnostics.sort(compareDiagnostics);
|
||||
diagnostics = deduplicateSortedDiagnostics(diagnostics);
|
||||
|
||||
// Update returnCode if there is any EmitterError
|
||||
var hasEmitterError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
|
||||
|
||||
// Check and update returnCode for syntactic and semantic
|
||||
var emitResultStatus: EmitReturnStatus;
|
||||
if (isEmitBlocked) {
|
||||
emitResultStatus = EmitReturnStatus.AllOutputGenerationSkipped;
|
||||
} else if (hasEmitterError) {
|
||||
emitResultStatus = EmitReturnStatus.EmitErrorsEncountered;
|
||||
} else if (hasSemanticDiagnostics && compilerOptions.declaration) {
|
||||
emitResultStatus = EmitReturnStatus.DeclarationGenerationSkipped;
|
||||
} else if (hasSemanticDiagnostics && !compilerOptions.declaration) {
|
||||
emitResultStatus = EmitReturnStatus.JSGeneratedWithSemanticErrors;
|
||||
} else {
|
||||
emitResultStatus = EmitReturnStatus.Succeeded;
|
||||
}
|
||||
|
||||
return {
|
||||
emitResultStatus,
|
||||
diagnostics,
|
||||
sourceMaps: sourceMapDataList
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+190
-104
@@ -3,6 +3,7 @@
|
||||
|
||||
module ts {
|
||||
var nodeConstructors = new Array<new () => Node>(SyntaxKind.Count);
|
||||
/* @internal */ export var parseTime = 0;
|
||||
|
||||
export function getNodeConstructor(kind: SyntaxKind): new () => Node {
|
||||
return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind));
|
||||
@@ -335,11 +336,16 @@ module ts {
|
||||
}
|
||||
|
||||
function fixupParentReferences(sourceFile: SourceFile) {
|
||||
// normally parent references are set during binding.
|
||||
// however here SourceFile data is used only for syntactic features so running the whole binding process is an overhead.
|
||||
// walk over the nodes and set parent references
|
||||
// normally parent references are set during binding. However, for clients that only need
|
||||
// a syntax tree, and no semantic features, then the binding process is an unnecessary
|
||||
// overhead. This functions allows us to set all the parents, without all the expense of
|
||||
// binding.
|
||||
|
||||
var parent: Node = sourceFile;
|
||||
function walk(n: Node): void {
|
||||
forEachChild(sourceFile, visitNode);
|
||||
return;
|
||||
|
||||
function visitNode(n: Node): void {
|
||||
// walk down setting parents that differ from the parent we think it should be. This
|
||||
// allows us to quickly bail out of setting parents for subtrees during incremental
|
||||
// parsing
|
||||
@@ -348,42 +354,53 @@ module ts {
|
||||
|
||||
var saveParent = parent;
|
||||
parent = n;
|
||||
forEachChild(n, walk);
|
||||
forEachChild(n, visitNode);
|
||||
parent = saveParent;
|
||||
}
|
||||
}
|
||||
|
||||
forEachChild(sourceFile, walk);
|
||||
}
|
||||
|
||||
export function getSyntacticDiagnostics(sourceFile: SourceFile) {
|
||||
if (!sourceFile.syntacticDiagnostics) {
|
||||
// Don't bother doing any grammar checks if there are already parser errors.
|
||||
// Otherwise we may end up with too many cascading errors.
|
||||
sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics);
|
||||
function shouldCheckNode(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.Identifier:
|
||||
return true;
|
||||
}
|
||||
return sourceFile.syntacticDiagnostics;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function moveElementEntirelyPastChangeRange(element: IncrementalElement, delta: number) {
|
||||
if (element.length) {
|
||||
function moveElementEntirelyPastChangeRange(element: IncrementalElement, isArray: boolean, delta: number, oldText: string, newText: string, aggressiveChecks: boolean) {
|
||||
if (isArray) {
|
||||
visitArray(<IncrementalNodeArray>element);
|
||||
}
|
||||
else {
|
||||
visitNode(<IncrementalNode>element);
|
||||
}
|
||||
return;
|
||||
|
||||
function visitNode(node: IncrementalNode) {
|
||||
if (aggressiveChecks && shouldCheckNode(node)) {
|
||||
var text = oldText.substring(node.pos, node.end);
|
||||
}
|
||||
|
||||
// Ditch any existing LS children we may have created. This way we can avoid
|
||||
// moving them forward.
|
||||
node._children = undefined;
|
||||
node.pos += delta;
|
||||
node.end += delta;
|
||||
|
||||
if (aggressiveChecks && shouldCheckNode(node)) {
|
||||
Debug.assert(text === newText.substring(node.pos, node.end));
|
||||
}
|
||||
|
||||
forEachChild(node, visitNode, visitArray);
|
||||
checkNodePositions(node, aggressiveChecks);
|
||||
}
|
||||
|
||||
function visitArray(array: IncrementalNodeArray) {
|
||||
array._children = undefined;
|
||||
array.pos += delta;
|
||||
array.end += delta;
|
||||
|
||||
@@ -396,6 +413,7 @@ module ts {
|
||||
function adjustIntersectingElement(element: IncrementalElement, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number) {
|
||||
Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
|
||||
Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
|
||||
Debug.assert(element.pos <= element.end);
|
||||
|
||||
// We have an element that intersects the change range in some way. It may have its
|
||||
// start, or its end (or both) in the changed range. We want to adjust any part
|
||||
@@ -467,14 +485,36 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function updateTokenPositionsAndMarkElements(node: IncrementalNode, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number): void {
|
||||
visitNode(node);
|
||||
function checkNodePositions(node: Node, aggressiveChecks: boolean) {
|
||||
if (aggressiveChecks) {
|
||||
var pos = node.pos;
|
||||
forEachChild(node, child => {
|
||||
Debug.assert(child.pos >= pos);
|
||||
pos = child.end;
|
||||
});
|
||||
Debug.assert(pos <= node.end);
|
||||
}
|
||||
}
|
||||
|
||||
function updateTokenPositionsAndMarkElements(
|
||||
sourceFile: IncrementalNode,
|
||||
changeStart: number,
|
||||
changeRangeOldEnd: number,
|
||||
changeRangeNewEnd: number,
|
||||
delta: number,
|
||||
oldText: string,
|
||||
newText: string,
|
||||
aggressiveChecks: boolean): void {
|
||||
|
||||
visitNode(sourceFile);
|
||||
return;
|
||||
|
||||
function visitNode(child: IncrementalNode) {
|
||||
Debug.assert(child.pos <= child.end);
|
||||
if (child.pos > changeRangeOldEnd) {
|
||||
// Node is entirely past the change range. We need to move both its pos and
|
||||
// end, forward or backward appropriately.
|
||||
moveElementEntirelyPastChangeRange(child, delta);
|
||||
moveElementEntirelyPastChangeRange(child, /*isArray:*/ false, delta, oldText, newText, aggressiveChecks);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -484,44 +524,50 @@ module ts {
|
||||
var fullEnd = child.end;
|
||||
if (fullEnd >= changeStart) {
|
||||
child.intersectsChange = true;
|
||||
child._children = undefined;
|
||||
|
||||
// Adjust the pos or end (or both) of the intersecting element accordingly.
|
||||
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
|
||||
forEachChild(child, visitNode, visitArray);
|
||||
|
||||
checkNodePositions(child, aggressiveChecks);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, the node is entirely before the change range. No need to do anything with it.
|
||||
Debug.assert(fullEnd < changeStart);
|
||||
}
|
||||
|
||||
function visitArray(array: IncrementalNodeArray) {
|
||||
Debug.assert(array.pos <= array.end);
|
||||
if (array.pos > changeRangeOldEnd) {
|
||||
// Array is entirely after the change range. We need to move it, and move any of
|
||||
// its children.
|
||||
moveElementEntirelyPastChangeRange(array, delta);
|
||||
moveElementEntirelyPastChangeRange(array, /*isArray:*/ true, delta, oldText, newText, aggressiveChecks);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Check if the element intersects the change range. If it does, then it is not
|
||||
// reusable. Also, we'll need to recurse to see what constituent portions we may
|
||||
// be able to use.
|
||||
var fullEnd = array.end;
|
||||
if (fullEnd >= changeStart) {
|
||||
array.intersectsChange = true;
|
||||
|
||||
// Adjust the pos or end (or both) of the intersecting array accordingly.
|
||||
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
visitNode(array[i]);
|
||||
}
|
||||
// Check if the element intersects the change range. If it does, then it is not
|
||||
// reusable. Also, we'll need to recurse to see what constituent portions we may
|
||||
// be able to use.
|
||||
var fullEnd = array.end;
|
||||
if (fullEnd >= changeStart) {
|
||||
array.intersectsChange = true;
|
||||
array._children = undefined;
|
||||
|
||||
// Adjust the pos or end (or both) of the intersecting array accordingly.
|
||||
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
visitNode(array[i]);
|
||||
}
|
||||
// else {
|
||||
// Otherwise, the array is entirely before the change range. No need to do anything with it.
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, the array is entirely before the change range. No need to do anything with it.
|
||||
Debug.assert(fullEnd < changeStart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function extendToAffectedRange(sourceFile: SourceFile, changeRange: TextChangeRange): TextChangeRange {
|
||||
// Consider the following code:
|
||||
// void foo() { /; }
|
||||
@@ -542,6 +588,7 @@ module ts {
|
||||
// start of the tree.
|
||||
for (var i = 0; start > 0 && i <= maxLookahead; i++) {
|
||||
var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start);
|
||||
Debug.assert(nearestNode.pos <= start);
|
||||
var position = nearestNode.pos;
|
||||
|
||||
start = Math.max(0, position - 1);
|
||||
@@ -648,6 +695,22 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkChangeRange(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks: boolean) {
|
||||
var oldText = sourceFile.text;
|
||||
if (textChangeRange) {
|
||||
Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
|
||||
|
||||
if (aggressiveChecks || Debug.shouldAssert(AssertionLevel.VeryAggressive)) {
|
||||
var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
|
||||
var newTextPrefix = newText.substr(0, textChangeRange.span.start);
|
||||
Debug.assert(oldTextPrefix === newTextPrefix);
|
||||
|
||||
var oldTextSuffix = oldText.substring(textSpanEnd(textChangeRange.span), oldText.length);
|
||||
var newTextSuffix = newText.substring(textSpanEnd(textChangeRangeNewSpan(textChangeRange)), newText.length);
|
||||
Debug.assert(oldTextSuffix === newTextSuffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
|
||||
// indicates what changed between the 'text' that this SourceFile has and the 'newText'.
|
||||
@@ -658,7 +721,10 @@ module ts {
|
||||
// from this SourceFile that are being held onto may change as a result (including
|
||||
// becoming detached from any SourceFile). It is recommended that this SourceFile not
|
||||
// be used once 'update' is called on it.
|
||||
export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile {
|
||||
export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile {
|
||||
aggressiveChecks = aggressiveChecks || Debug.shouldAssert(AssertionLevel.Aggressive);
|
||||
|
||||
checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks);
|
||||
if (textChangeRangeIsUnchanged(textChangeRange)) {
|
||||
// if the text didn't change, then we can just return our current source file as-is.
|
||||
return sourceFile;
|
||||
@@ -667,14 +733,32 @@ module ts {
|
||||
if (sourceFile.statements.length === 0) {
|
||||
// If we don't have any statements in the current source file, then there's no real
|
||||
// way to incrementally parse. So just do a full parse instead.
|
||||
return parseSourceFile(sourceFile.filename, newText, sourceFile.languageVersion,/*syntaxCursor*/ undefined, /*setNodeParents*/ true)
|
||||
return parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true)
|
||||
}
|
||||
|
||||
// Make sure we're not trying to incrementally update a source file more than once. Once
|
||||
// we do an update the original source file is considered unusbale from that point onwards.
|
||||
//
|
||||
// This is because we do incremental parsing in-place. i.e. we take nodes from the old
|
||||
// tree and give them new positions and parents. From that point on, trusting the old
|
||||
// tree at all is not possible as far too much of it may violate invariants.
|
||||
var incrementalSourceFile = <IncrementalNode><Node>sourceFile;
|
||||
Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed);
|
||||
incrementalSourceFile.hasBeenIncrementallyParsed = true;
|
||||
|
||||
var oldText = sourceFile.text;
|
||||
var syntaxCursor = createSyntaxCursor(sourceFile);
|
||||
|
||||
// Make the actual change larger so that we know to reparse anything whose lookahead
|
||||
// might have intersected the change.
|
||||
var changeRange = extendToAffectedRange(sourceFile, textChangeRange);
|
||||
checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks);
|
||||
|
||||
// Ensure that extending the affected range only moved the start of the change range
|
||||
// earlier in the file.
|
||||
Debug.assert(changeRange.span.start <= textChangeRange.span.start);
|
||||
Debug.assert(textSpanEnd(changeRange.span) === textSpanEnd(textChangeRange.span));
|
||||
Debug.assert(textSpanEnd(textChangeRangeNewSpan(changeRange)) === textSpanEnd(textChangeRangeNewSpan(textChangeRange)));
|
||||
|
||||
// The is the amount the nodes after the edit range need to be adjusted. It can be
|
||||
// positive (if the edit added characters), negative (if the edit deleted characters)
|
||||
@@ -682,8 +766,8 @@ module ts {
|
||||
var delta = textChangeRangeNewSpan(changeRange).length - changeRange.span.length;
|
||||
|
||||
// If we added or removed characters during the edit, then we need to go and adjust all
|
||||
// the nodes after the edit. Those nodes may move forward down (if we inserted chars)
|
||||
// or they may move backward (if we deleted chars).
|
||||
// the nodes after the edit. Those nodes may move forward (if we inserted chars) or they
|
||||
// may move backward (if we deleted chars).
|
||||
//
|
||||
// Doing this helps us out in two ways. First, it means that any nodes/tokens we want
|
||||
// to reuse are already at the appropriate position in the new text. That way when we
|
||||
@@ -700,8 +784,8 @@ module ts {
|
||||
//
|
||||
// Also, mark any syntax elements that intersect the changed span. We know, up front,
|
||||
// that we cannot reuse these elements.
|
||||
updateTokenPositionsAndMarkElements(<IncrementalNode><Node>sourceFile,
|
||||
changeRange.span.start, textSpanEnd(changeRange.span), textSpanEnd(textChangeRangeNewSpan(changeRange)), delta);
|
||||
updateTokenPositionsAndMarkElements(incrementalSourceFile,
|
||||
changeRange.span.start, textSpanEnd(changeRange.span), textSpanEnd(textChangeRangeNewSpan(changeRange)), delta, oldText, newText, aggressiveChecks);
|
||||
|
||||
// Now that we've set up our internal incremental state just proceed and parse the
|
||||
// source file in the normal fashion. When possible the parser will retrieve and
|
||||
@@ -713,7 +797,7 @@ module ts {
|
||||
// inconsistent tree. Setting the parents on the new tree should be very fast. We
|
||||
// will immediately bail out of walking any subtrees when we can see that their parents
|
||||
// are already correct.
|
||||
var result = parseSourceFile(sourceFile.filename, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true)
|
||||
var result = parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true)
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -741,6 +825,7 @@ module ts {
|
||||
}
|
||||
|
||||
interface IncrementalNode extends Node, IncrementalElement {
|
||||
hasBeenIncrementallyParsed: boolean
|
||||
}
|
||||
|
||||
interface IncrementalNodeArray extends NodeArray<IncrementalNode>, IncrementalElement {
|
||||
@@ -776,7 +861,7 @@ module ts {
|
||||
// Much of the time the parser will need the very next node in the array that
|
||||
// we just returned a node from.So just simply check for that case and move
|
||||
// forward in the array instead of searching for the node again.
|
||||
if (current && current.end === position && currentArrayIndex < currentArray.length) {
|
||||
if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) {
|
||||
currentArrayIndex++;
|
||||
current = currentArray[currentArrayIndex];
|
||||
}
|
||||
@@ -812,6 +897,7 @@ module ts {
|
||||
|
||||
// Recurse into the source file to find the highest node at this position.
|
||||
forEachChild(sourceFile, visitNode, visitArray);
|
||||
return;
|
||||
|
||||
function visitNode(node: Node) {
|
||||
if (position >= node.pos && position < node.end) {
|
||||
@@ -857,27 +943,33 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false): SourceFile {
|
||||
return parseSourceFile(filename, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes);
|
||||
|
||||
export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false): SourceFile {
|
||||
var start = new Date().getTime();
|
||||
var result = parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes);
|
||||
|
||||
parseTime += new Date().getTime() - start;
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile {
|
||||
function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile {
|
||||
var parsingContext: ParsingContext = 0;
|
||||
var identifiers: Map<string> = {};
|
||||
var identifierCount = 0;
|
||||
var nodeCount = 0;
|
||||
var scanner: Scanner;
|
||||
var token: SyntaxKind;
|
||||
|
||||
var sourceFile = <SourceFile>createNode(SyntaxKind.SourceFile, /*pos*/ 0);
|
||||
|
||||
sourceFile.pos = sourceFile.end = 0;
|
||||
sourceFile.referenceDiagnostics = [];
|
||||
sourceFile.pos = 0;
|
||||
sourceFile.end = sourceText.length;
|
||||
sourceFile.text = sourceText;
|
||||
|
||||
sourceFile.parseDiagnostics = [];
|
||||
sourceFile.semanticDiagnostics = [];
|
||||
sourceFile.bindDiagnostics = [];
|
||||
sourceFile.languageVersion = languageVersion;
|
||||
sourceFile.filename = normalizePath(filename);
|
||||
sourceFile.flags = fileExtensionIs(sourceFile.filename, ".d.ts") ? NodeFlags.DeclarationFile : 0;
|
||||
sourceFile.fileName = normalizePath(fileName);
|
||||
sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0;
|
||||
|
||||
// Flags that dictate what parsing context we're in. For example:
|
||||
// Whether or not we are in strict parsing mode. All that changes in strict parsing mode is
|
||||
@@ -956,15 +1048,8 @@ module ts {
|
||||
// attached to the EOF token.
|
||||
var parseErrorBeforeNextFinishedNode: boolean = false;
|
||||
|
||||
sourceFile.syntacticDiagnostics = undefined;
|
||||
sourceFile.referenceDiagnostics = [];
|
||||
sourceFile.parseDiagnostics = [];
|
||||
sourceFile.semanticDiagnostics = [];
|
||||
sourceFile.end = sourceText.length;
|
||||
sourceFile.text = sourceText;
|
||||
|
||||
// Create and prime the scanner before parsing the source elements.
|
||||
scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError);
|
||||
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError);
|
||||
token = nextToken();
|
||||
|
||||
processReferenceComments(sourceFile);
|
||||
@@ -983,6 +1068,7 @@ module ts {
|
||||
fixupParentReferences(sourceFile);
|
||||
}
|
||||
|
||||
syntaxCursor = undefined;
|
||||
return sourceFile;
|
||||
|
||||
function setContextFlag(val: Boolean, flag: ParserContextFlags) {
|
||||
@@ -1430,7 +1516,6 @@ module ts {
|
||||
case ParsingContext.TypeParameters:
|
||||
return isIdentifier();
|
||||
case ParsingContext.ArgumentExpressions:
|
||||
return token === SyntaxKind.CommaToken || isStartOfExpression();
|
||||
case ParsingContext.ArrayLiteralMembers:
|
||||
return token === SyntaxKind.CommaToken || token === SyntaxKind.DotDotDotToken || isStartOfExpression();
|
||||
case ParsingContext.Parameters:
|
||||
@@ -1583,8 +1668,8 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseListElement<T extends Node>(kind: ParsingContext, parseElement: () => T): T {
|
||||
var node = currentNode(kind);
|
||||
function parseListElement<T extends Node>(parsingContext: ParsingContext, parseElement: () => T): T {
|
||||
var node = currentNode(parsingContext);
|
||||
if (node) {
|
||||
return <T>consumeNode(node);
|
||||
}
|
||||
@@ -1741,29 +1826,10 @@ module ts {
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
|
||||
// Keep in sync with isStatement:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.VariableStatement:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
case SyntaxKind.ThrowStatement:
|
||||
case SyntaxKind.ReturnStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.BreakStatement:
|
||||
case SyntaxKind.ContinueStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
case SyntaxKind.WithStatement:
|
||||
case SyntaxKind.EmptyStatement:
|
||||
case SyntaxKind.TryStatement:
|
||||
case SyntaxKind.LabeledStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.DebuggerStatement:
|
||||
return true;
|
||||
}
|
||||
|
||||
return isReusableStatement(node);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1869,9 +1935,13 @@ module ts {
|
||||
}
|
||||
|
||||
function isReusableParameter(node: Node) {
|
||||
// TODO: this most likely needs the same initializer check that
|
||||
// isReusableVariableDeclaration has.
|
||||
return node.kind === SyntaxKind.Parameter;
|
||||
if (node.kind !== SyntaxKind.Parameter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// See the comment in isReusableVariableDeclaration for why we do this.
|
||||
var parameter = <ParameterDeclaration>node;
|
||||
return parameter.initializer === undefined;
|
||||
}
|
||||
|
||||
// Returns true if we should abort parsing.
|
||||
@@ -1886,7 +1956,7 @@ module ts {
|
||||
}
|
||||
|
||||
// Parses a comma-delimited list of elements
|
||||
function parseDelimitedList<T extends Node>(kind: ParsingContext, parseElement: () => T): NodeArray<T> {
|
||||
function parseDelimitedList<T extends Node>(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimeter?: boolean): NodeArray<T> {
|
||||
var saveParsingContext = parsingContext;
|
||||
parsingContext |= 1 << kind;
|
||||
var result = <NodeArray<T>>[];
|
||||
@@ -1900,11 +1970,24 @@ module ts {
|
||||
if (parseOptional(SyntaxKind.CommaToken)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
commaStart = -1; // Back to the state where the last token was not a comma
|
||||
if (isListTerminator(kind)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// We didn't get a comma, and the list wasn't terminated, explicitly parse
|
||||
// out a comma so we give a good error message.
|
||||
parseExpected(SyntaxKind.CommaToken);
|
||||
|
||||
// If the token was a semicolon, and the caller allows that, then skip it and
|
||||
// continue. This ensures we get back on track and don't result in tons of
|
||||
// parse errors. For example, this can happen when people do things like use
|
||||
// a semicolon to delimit object literal members. Note: we'll have already
|
||||
// reported an error when we called parseExpected above.
|
||||
if (considerSemicolonAsDelimeter && token === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) {
|
||||
nextToken();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3521,12 +3604,6 @@ module ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseAssignmentExpressionOrOmittedExpression(): Expression {
|
||||
return token === SyntaxKind.CommaToken
|
||||
? <Expression>createNode(SyntaxKind.OmittedExpression)
|
||||
: parseAssignmentExpressionOrHigher();
|
||||
}
|
||||
|
||||
function parseSpreadElement(): Expression {
|
||||
var node = <SpreadElementExpression>createNode(SyntaxKind.SpreadElementExpression);
|
||||
parseExpected(SyntaxKind.DotDotDotToken);
|
||||
@@ -3534,19 +3611,21 @@ module ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseArrayLiteralElement(): Expression {
|
||||
return token === SyntaxKind.DotDotDotToken ? parseSpreadElement() : parseAssignmentExpressionOrOmittedExpression();
|
||||
function parseArgumentOrArrayLiteralElement(): Expression {
|
||||
return token === SyntaxKind.DotDotDotToken ? parseSpreadElement() :
|
||||
token === SyntaxKind.CommaToken ? <Expression>createNode(SyntaxKind.OmittedExpression) :
|
||||
parseAssignmentExpressionOrHigher();
|
||||
}
|
||||
|
||||
function parseArgumentExpression(): Expression {
|
||||
return allowInAnd(parseAssignmentExpressionOrOmittedExpression);
|
||||
return allowInAnd(parseArgumentOrArrayLiteralElement);
|
||||
}
|
||||
|
||||
function parseArrayLiteralExpression(): ArrayLiteralExpression {
|
||||
var node = <ArrayLiteralExpression>createNode(SyntaxKind.ArrayLiteralExpression);
|
||||
parseExpected(SyntaxKind.OpenBracketToken);
|
||||
if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine;
|
||||
node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArrayLiteralElement);
|
||||
node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement);
|
||||
parseExpected(SyntaxKind.CloseBracketToken);
|
||||
return finishNode(node);
|
||||
}
|
||||
@@ -3606,7 +3685,7 @@ module ts {
|
||||
node.flags |= NodeFlags.MultiLine;
|
||||
}
|
||||
|
||||
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement);
|
||||
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimeter:*/ true);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
return finishNode(node);
|
||||
}
|
||||
@@ -4670,7 +4749,7 @@ module ts {
|
||||
function processReferenceComments(sourceFile: SourceFile): void {
|
||||
var triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText);
|
||||
var referencedFiles: FileReference[] = [];
|
||||
var amdDependencies: string[] = [];
|
||||
var amdDependencies: {path: string; name: string}[] = [];
|
||||
var amdModuleName: string;
|
||||
|
||||
// Keep scanning all the leading trivia in the file until we get to something that
|
||||
@@ -4697,7 +4776,7 @@ module ts {
|
||||
referencedFiles.push(fileReference);
|
||||
}
|
||||
if (diagnosticMessage) {
|
||||
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
|
||||
sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -4705,15 +4784,22 @@ module ts {
|
||||
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
|
||||
if (amdModuleNameMatchResult) {
|
||||
if (amdModuleName) {
|
||||
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
|
||||
sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
|
||||
}
|
||||
amdModuleName = amdModuleNameMatchResult[2];
|
||||
}
|
||||
|
||||
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s+path\s*=\s*('|")(.+?)\1/gim;
|
||||
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
|
||||
var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
|
||||
var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
|
||||
var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
|
||||
if (amdDependencyMatchResult) {
|
||||
amdDependencies.push(amdDependencyMatchResult[2]);
|
||||
var pathMatchResult = pathRegex.exec(comment);
|
||||
var nameMatchResult = nameRegex.exec(comment);
|
||||
if (pathMatchResult) {
|
||||
var amdDependency = {path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
|
||||
amdDependencies.push(amdDependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+171
-94
@@ -2,6 +2,8 @@
|
||||
/// <reference path="emitter.ts" />
|
||||
|
||||
module ts {
|
||||
/* @internal */ export var emitTime = 0;
|
||||
|
||||
export function createCompilerHost(options: CompilerOptions): CompilerHost {
|
||||
var currentDirectory: string;
|
||||
var existingDirectories: Map<boolean> = {};
|
||||
@@ -15,20 +17,20 @@ module ts {
|
||||
// returned by CScript sys environment
|
||||
var unsupportedFileEncodingErrorCode = -2147024809;
|
||||
|
||||
function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
|
||||
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
|
||||
try {
|
||||
var text = sys.readFile(filename, options.charset);
|
||||
var text = sys.readFile(fileName, options.charset);
|
||||
}
|
||||
catch (e) {
|
||||
if (onError) {
|
||||
onError(e.number === unsupportedFileEncodingErrorCode ?
|
||||
createCompilerDiagnostic(Diagnostics.Unsupported_file_encoding).messageText :
|
||||
e.message);
|
||||
onError(e.number === unsupportedFileEncodingErrorCode
|
||||
? createCompilerDiagnostic(Diagnostics.Unsupported_file_encoding).messageText
|
||||
: e.message);
|
||||
}
|
||||
text = "";
|
||||
}
|
||||
|
||||
return text !== undefined ? createSourceFile(filename, text, languageVersion) : undefined;
|
||||
return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined;
|
||||
}
|
||||
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
|
||||
@@ -64,7 +66,7 @@ module ts {
|
||||
|
||||
return {
|
||||
getSourceFile,
|
||||
getDefaultLibFilename: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFilename(options)),
|
||||
getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)),
|
||||
writeFile,
|
||||
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
@@ -73,159 +75,237 @@ module ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program {
|
||||
export function getPreEmitDiagnostics(program: Program): Diagnostic[] {
|
||||
var diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics());
|
||||
return sortAndDeduplicateDiagnostics(diagnostics);
|
||||
}
|
||||
|
||||
export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string {
|
||||
if (typeof messageText === "string") {
|
||||
return messageText;
|
||||
}
|
||||
else {
|
||||
var diagnosticChain = messageText;
|
||||
var result = "";
|
||||
|
||||
var indent = 0;
|
||||
while (diagnosticChain) {
|
||||
if (indent) {
|
||||
result += newLine;
|
||||
|
||||
for (var i = 0; i < indent; i++) {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
result += diagnosticChain.messageText;
|
||||
indent++;
|
||||
diagnosticChain = diagnosticChain.next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program {
|
||||
var program: Program;
|
||||
var files: SourceFile[] = [];
|
||||
var filesByName: Map<SourceFile> = {};
|
||||
var errors: Diagnostic[] = [];
|
||||
var diagnostics = createDiagnosticCollection();
|
||||
var seenNoDefaultLib = options.noLib;
|
||||
var commonSourceDirectory: string;
|
||||
host = host || createCompilerHost(options);
|
||||
|
||||
forEach(rootNames, name => processRootFile(name, false));
|
||||
if (!seenNoDefaultLib) {
|
||||
processRootFile(host.getDefaultLibFilename(options), true);
|
||||
processRootFile(host.getDefaultLibFileName(options), true);
|
||||
}
|
||||
verifyCompilerOptions();
|
||||
errors.sort(compareDiagnostics);
|
||||
|
||||
|
||||
var diagnosticsProducingTypeChecker: TypeChecker;
|
||||
var noDiagnosticsTypeChecker: TypeChecker;
|
||||
var emitHost: EmitHost;
|
||||
|
||||
program = {
|
||||
getSourceFile: getSourceFile,
|
||||
getSourceFiles: () => files,
|
||||
getCompilerOptions: () => options,
|
||||
getCompilerHost: () => host,
|
||||
getDiagnostics: getDiagnostics,
|
||||
getGlobalDiagnostics: getGlobalDiagnostics,
|
||||
getDeclarationDiagnostics: getDeclarationDiagnostics,
|
||||
getSyntacticDiagnostics,
|
||||
getGlobalDiagnostics,
|
||||
getSemanticDiagnostics,
|
||||
getDeclarationDiagnostics,
|
||||
getTypeChecker,
|
||||
getDiagnosticsProducingTypeChecker,
|
||||
getCommonSourceDirectory: () => commonSourceDirectory,
|
||||
emitFiles: invokeEmitter,
|
||||
isEmitBlocked,
|
||||
emit,
|
||||
getCurrentDirectory: host.getCurrentDirectory,
|
||||
getNodeCount: () => getDiagnosticsProducingTypeChecker().getNodeCount(),
|
||||
getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(),
|
||||
getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(),
|
||||
getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
|
||||
};
|
||||
return program;
|
||||
|
||||
function getEmitHost() {
|
||||
return emitHost || (emitHost = createEmitHostFromProgram(program));
|
||||
}
|
||||
|
||||
function isEmitBlocked(sourceFile?: SourceFile): boolean {
|
||||
if (options.noEmitOnError) {
|
||||
return getDiagnostics(sourceFile).length !== 0 || getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile).length !== 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
|
||||
return {
|
||||
getCanonicalFileName: host.getCanonicalFileName,
|
||||
getCommonSourceDirectory: program.getCommonSourceDirectory,
|
||||
getCompilerOptions: program.getCompilerOptions,
|
||||
getCurrentDirectory: host.getCurrentDirectory,
|
||||
getNewLine: host.getNewLine,
|
||||
getSourceFile: program.getSourceFile,
|
||||
getSourceFiles: program.getSourceFiles,
|
||||
writeFile: writeFileCallback || host.writeFile,
|
||||
};
|
||||
}
|
||||
|
||||
function getDiagnosticsProducingTypeChecker() {
|
||||
return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true));
|
||||
}
|
||||
|
||||
function getTypeChecker(produceDiagnostics: boolean) {
|
||||
if (produceDiagnostics) {
|
||||
return getDiagnosticsProducingTypeChecker();
|
||||
}
|
||||
else {
|
||||
return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, produceDiagnostics));
|
||||
}
|
||||
function getTypeChecker() {
|
||||
return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false));
|
||||
}
|
||||
|
||||
function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[]{
|
||||
var typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
typeChecker.getDiagnostics(targetSourceFile);
|
||||
var resolver = typeChecker.getEmitResolver();
|
||||
function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] {
|
||||
var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile);
|
||||
return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile);
|
||||
}
|
||||
|
||||
function invokeEmitter(targetSourceFile?: SourceFile) {
|
||||
var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver();
|
||||
return emitFiles(resolver, getEmitHost(), targetSourceFile);
|
||||
}
|
||||
|
||||
function getSourceFile(filename: string) {
|
||||
filename = host.getCanonicalFileName(filename);
|
||||
return hasProperty(filesByName, filename) ? filesByName[filename] : undefined;
|
||||
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback): EmitResult {
|
||||
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
|
||||
// immediately bail out.
|
||||
if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) {
|
||||
return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
|
||||
}
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
var emitResult = emitFiles(
|
||||
getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile),
|
||||
getEmitHost(writeFileCallback),
|
||||
sourceFile);
|
||||
|
||||
emitTime += new Date().getTime() - start;
|
||||
return emitResult;
|
||||
}
|
||||
|
||||
function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
|
||||
return sourceFile ? filter(errors, e => e.file === sourceFile) : errors;
|
||||
function getSourceFile(fileName: string) {
|
||||
fileName = host.getCanonicalFileName(fileName);
|
||||
return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined;
|
||||
}
|
||||
|
||||
function getDiagnosticsHelper(sourceFile: SourceFile, getDiagnostics: (sourceFile: SourceFile) => Diagnostic[]): Diagnostic[] {
|
||||
if (sourceFile) {
|
||||
return getDiagnostics(sourceFile);
|
||||
}
|
||||
|
||||
var allDiagnostics: Diagnostic[] = [];
|
||||
forEach(program.getSourceFiles(), sourceFile => {
|
||||
addRange(allDiagnostics, getDiagnostics(sourceFile));
|
||||
});
|
||||
|
||||
return sortAndDeduplicateDiagnostics(allDiagnostics);
|
||||
}
|
||||
|
||||
function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
|
||||
return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile);
|
||||
}
|
||||
|
||||
function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
|
||||
return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile);
|
||||
}
|
||||
|
||||
function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
|
||||
return sourceFile.parseDiagnostics;
|
||||
}
|
||||
|
||||
function getSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
|
||||
var typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
Debug.assert(!!sourceFile.bindDiagnostics);
|
||||
var bindDiagnostics = sourceFile.bindDiagnostics;
|
||||
var checkDiagnostics = typeChecker.getDiagnostics(sourceFile);
|
||||
var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
|
||||
|
||||
return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics);
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
return filter(errors, e => !e.file);
|
||||
var typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
var allDiagnostics: Diagnostic[] = [];
|
||||
addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
|
||||
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
|
||||
|
||||
return sortAndDeduplicateDiagnostics(allDiagnostics);
|
||||
}
|
||||
|
||||
function hasExtension(filename: string): boolean {
|
||||
return getBaseFilename(filename).indexOf(".") >= 0;
|
||||
function hasExtension(fileName: string): boolean {
|
||||
return getBaseFileName(fileName).indexOf(".") >= 0;
|
||||
}
|
||||
|
||||
function processRootFile(filename: string, isDefaultLib: boolean) {
|
||||
processSourceFile(normalizePath(filename), isDefaultLib);
|
||||
function processRootFile(fileName: string, isDefaultLib: boolean) {
|
||||
processSourceFile(normalizePath(fileName), isDefaultLib);
|
||||
}
|
||||
|
||||
function processSourceFile(filename: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
if (refEnd !== undefined && refPos !== undefined) {
|
||||
var start = refPos;
|
||||
var length = refEnd - refPos;
|
||||
}
|
||||
var diagnostic: DiagnosticMessage;
|
||||
if (hasExtension(filename)) {
|
||||
if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(filename), ".ts")) {
|
||||
if (hasExtension(fileName)) {
|
||||
if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) {
|
||||
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
|
||||
}
|
||||
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
|
||||
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
}
|
||||
else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) {
|
||||
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
|
||||
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (options.allowNonTsExtensions && !findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
|
||||
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
}
|
||||
else if (!findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) {
|
||||
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
filename += ".ts";
|
||||
fileName += ".ts";
|
||||
}
|
||||
}
|
||||
|
||||
if (diagnostic) {
|
||||
if (refFile) {
|
||||
errors.push(createFileDiagnostic(refFile, start, length, diagnostic, filename));
|
||||
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName));
|
||||
}
|
||||
else {
|
||||
errors.push(createCompilerDiagnostic(diagnostic, filename));
|
||||
diagnostics.add(createCompilerDiagnostic(diagnostic, fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get source file from normalized filename
|
||||
function findSourceFile(filename: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile {
|
||||
var canonicalName = host.getCanonicalFileName(filename);
|
||||
// Get source file from normalized fileName
|
||||
function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile {
|
||||
var canonicalName = host.getCanonicalFileName(fileName);
|
||||
if (hasProperty(filesByName, canonicalName)) {
|
||||
// We've already looked for this file, use cached result
|
||||
return getSourceFileFromCache(filename, canonicalName, /*useAbsolutePath*/ false);
|
||||
return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false);
|
||||
}
|
||||
else {
|
||||
var normalizedAbsolutePath = getNormalizedAbsolutePath(filename, host.getCurrentDirectory());
|
||||
var normalizedAbsolutePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
|
||||
var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
|
||||
if (hasProperty(filesByName, canonicalAbsolutePath)) {
|
||||
return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true);
|
||||
}
|
||||
|
||||
// We haven't looked for this file, do so now and cache result
|
||||
var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, hostErrorMessage => {
|
||||
var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => {
|
||||
if (refFile) {
|
||||
errors.push(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
|
||||
diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
|
||||
}
|
||||
else {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
|
||||
}
|
||||
});
|
||||
if (file) {
|
||||
@@ -235,7 +315,7 @@ module ts {
|
||||
filesByName[canonicalAbsolutePath] = file;
|
||||
|
||||
if (!options.noResolve) {
|
||||
var basePath = getDirectoryPath(filename);
|
||||
var basePath = getDirectoryPath(fileName);
|
||||
processReferencedFiles(file, basePath);
|
||||
processImportedModules(file, basePath);
|
||||
}
|
||||
@@ -245,20 +325,17 @@ module ts {
|
||||
else {
|
||||
files.push(file);
|
||||
}
|
||||
forEach(getSyntacticDiagnostics(file), e => {
|
||||
errors.push(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
return file;
|
||||
|
||||
function getSourceFileFromCache(filename: string, canonicalName: string, useAbsolutePath: boolean): SourceFile {
|
||||
function getSourceFileFromCache(fileName: string, canonicalName: string, useAbsolutePath: boolean): SourceFile {
|
||||
var file = filesByName[canonicalName];
|
||||
if (file && host.useCaseSensitiveFileNames()) {
|
||||
var sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename;
|
||||
var sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
|
||||
if (canonicalName !== sourceFileName) {
|
||||
errors.push(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName));
|
||||
diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
|
||||
}
|
||||
}
|
||||
return file;
|
||||
@@ -267,8 +344,8 @@ module ts {
|
||||
|
||||
function processReferencedFiles(file: SourceFile, basePath: string) {
|
||||
forEach(file.referencedFiles, ref => {
|
||||
var referencedFilename = isRootedDiskPath(ref.filename) ? ref.filename : combinePaths(basePath, ref.filename);
|
||||
processSourceFile(normalizePath(referencedFilename), /* isDefaultLib */ false, file, ref.pos, ref.end);
|
||||
var referencedFileName = isRootedDiskPath(ref.fileName) ? ref.fileName : combinePaths(basePath, ref.fileName);
|
||||
processSourceFile(normalizePath(referencedFileName), /* isDefaultLib */ false, file, ref.pos, ref.end);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -322,8 +399,8 @@ module ts {
|
||||
}
|
||||
});
|
||||
|
||||
function findModuleSourceFile(filename: string, nameLiteral: LiteralExpression) {
|
||||
return findSourceFile(filename, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos);
|
||||
function findModuleSourceFile(fileName: string, nameLiteral: LiteralExpression) {
|
||||
return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,10 +408,10 @@ module ts {
|
||||
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
|
||||
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
|
||||
if (options.mapRoot) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option));
|
||||
}
|
||||
if (options.sourceRoot) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -345,7 +422,7 @@ module ts {
|
||||
var externalModuleErrorSpan = getErrorSpanForNode(firstExternalModule.externalModuleIndicator);
|
||||
var errorStart = skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos);
|
||||
var errorLength = externalModuleErrorSpan.end - errorStart;
|
||||
errors.push(createFileDiagnostic(firstExternalModule, errorStart, errorLength, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
|
||||
diagnostics.add(createFileDiagnostic(firstExternalModule, errorStart, errorLength, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
|
||||
}
|
||||
|
||||
// there has to be common source directory if user specified --outdir || --sourcRoot
|
||||
@@ -359,14 +436,14 @@ module ts {
|
||||
forEach(files, sourceFile => {
|
||||
// Each file contributes into common source file path
|
||||
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
|
||||
&& !fileExtensionIs(sourceFile.filename, ".js")) {
|
||||
var sourcePathComponents = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory());
|
||||
&& !fileExtensionIs(sourceFile.fileName, ".js")) {
|
||||
var sourcePathComponents = getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory());
|
||||
sourcePathComponents.pop(); // FileName is not part of directory
|
||||
if (commonPathComponents) {
|
||||
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {
|
||||
if (commonPathComponents[i] !== sourcePathComponents[i]) {
|
||||
if (i === 0) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -399,11 +476,11 @@ module ts {
|
||||
|
||||
if (options.noEmit) {
|
||||
if (options.out || options.outDir) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
|
||||
}
|
||||
|
||||
if (options.declaration) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+101
-80
@@ -78,8 +78,8 @@ module ts {
|
||||
}
|
||||
|
||||
function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string {
|
||||
var diagnostic: Diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
|
||||
return diagnostic.messageText;
|
||||
var diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
|
||||
return <string>diagnostic.messageText;
|
||||
}
|
||||
|
||||
function reportDiagnostic(diagnostic: Diagnostic) {
|
||||
@@ -88,11 +88,11 @@ module ts {
|
||||
if (diagnostic.file) {
|
||||
var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
||||
|
||||
output += diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): ";
|
||||
output += diagnostic.file.fileName + "(" + loc.line + "," + loc.character + "): ";
|
||||
}
|
||||
|
||||
var category = DiagnosticCategory[diagnostic.category].toLowerCase();
|
||||
output += category + " TS" + diagnostic.code + ": " + diagnostic.messageText + sys.newLine;
|
||||
output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) + sys.newLine;
|
||||
|
||||
sys.write(output);
|
||||
}
|
||||
@@ -136,27 +136,27 @@ module ts {
|
||||
|
||||
function findConfigFile(): string {
|
||||
var searchPath = normalizePath(sys.getCurrentDirectory());
|
||||
var filename = "tsconfig.json";
|
||||
var fileName = "tsconfig.json";
|
||||
while (true) {
|
||||
if (sys.fileExists(filename)) {
|
||||
return filename;
|
||||
if (sys.fileExists(fileName)) {
|
||||
return fileName;
|
||||
}
|
||||
var parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
searchPath = parentPath;
|
||||
filename = "../" + filename;
|
||||
fileName = "../" + fileName;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function executeCommandLine(args: string[]): void {
|
||||
var commandLine = parseCommandLine(args);
|
||||
var configFilename: string; // Configuration file name (if any)
|
||||
var configFileName: string; // Configuration file name (if any)
|
||||
var configFileWatcher: FileWatcher; // Configuration file watcher
|
||||
var cachedProgram: Program; // Program cached from last compilation
|
||||
var rootFilenames: string[]; // Root filenames for compilation
|
||||
var rootFileNames: string[]; // Root fileNames for compilation
|
||||
var compilerOptions: CompilerOptions; // Compiler options for compilation
|
||||
var compilerHost: CompilerHost; // Compiler host
|
||||
var hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host
|
||||
@@ -165,7 +165,7 @@ module ts {
|
||||
if (commandLine.options.locale) {
|
||||
if (!isJSONSupported()) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"));
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
|
||||
}
|
||||
@@ -174,48 +174,48 @@ module ts {
|
||||
// setting up localization, report them and quit.
|
||||
if (commandLine.errors.length > 0) {
|
||||
reportDiagnostics(commandLine.errors);
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
|
||||
if (commandLine.options.version) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version));
|
||||
return sys.exit(EmitReturnStatus.Succeeded);
|
||||
return sys.exit(ExitStatus.Success);
|
||||
}
|
||||
|
||||
if (commandLine.options.help) {
|
||||
printVersion();
|
||||
printHelp();
|
||||
return sys.exit(EmitReturnStatus.Succeeded);
|
||||
return sys.exit(ExitStatus.Success);
|
||||
}
|
||||
|
||||
if (commandLine.options.project) {
|
||||
if (!isJSONSupported()) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"));
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
configFilename = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json"));
|
||||
if (commandLine.filenames.length !== 0) {
|
||||
configFileName = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json"));
|
||||
if (commandLine.fileNames.length !== 0) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
}
|
||||
else if (commandLine.filenames.length === 0 && isJSONSupported()) {
|
||||
configFilename = findConfigFile();
|
||||
else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
|
||||
configFileName = findConfigFile();
|
||||
}
|
||||
|
||||
if (commandLine.filenames.length === 0 && !configFilename) {
|
||||
if (commandLine.fileNames.length === 0 && !configFileName) {
|
||||
printVersion();
|
||||
printHelp();
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.Success);
|
||||
}
|
||||
|
||||
if (commandLine.options.watch) {
|
||||
if (!sys.watchFile) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
if (configFilename) {
|
||||
configFileWatcher = sys.watchFile(configFilename, configFileChanged);
|
||||
if (configFileName) {
|
||||
configFileWatcher = sys.watchFile(configFileName, configFileChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,22 +225,22 @@ module ts {
|
||||
function performCompilation() {
|
||||
|
||||
if (!cachedProgram) {
|
||||
if (configFilename) {
|
||||
var configObject = readConfigFile(configFilename);
|
||||
if (configFileName) {
|
||||
var configObject = readConfigFile(configFileName);
|
||||
if (!configObject) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFilename));
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName));
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFilename));
|
||||
var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFileName));
|
||||
if (configParseResult.errors.length > 0) {
|
||||
reportDiagnostics(configParseResult.errors);
|
||||
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
rootFilenames = configParseResult.filenames;
|
||||
rootFileNames = configParseResult.fileNames;
|
||||
compilerOptions = extend(commandLine.options, configParseResult.options);
|
||||
}
|
||||
else {
|
||||
rootFilenames = commandLine.filenames;
|
||||
rootFileNames = commandLine.fileNames;
|
||||
compilerOptions = commandLine.options;
|
||||
}
|
||||
compilerHost = createCompilerHost(compilerOptions);
|
||||
@@ -248,7 +248,7 @@ module ts {
|
||||
compilerHost.getSourceFile = getSourceFile;
|
||||
}
|
||||
|
||||
var compileResult = compile(rootFilenames, compilerOptions, compilerHost);
|
||||
var compileResult = compile(rootFileNames, compilerOptions, compilerHost);
|
||||
|
||||
if (!commandLine.options.watch) {
|
||||
return sys.exit(compileResult.exitStatus);
|
||||
@@ -258,20 +258,20 @@ module ts {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
|
||||
}
|
||||
|
||||
function getSourceFile(filename: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) {
|
||||
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) {
|
||||
// Return existing SourceFile object if one is available
|
||||
if (cachedProgram) {
|
||||
var sourceFile = cachedProgram.getSourceFile(filename);
|
||||
var sourceFile = cachedProgram.getSourceFile(fileName);
|
||||
// A modified source file has no watcher and should not be reused
|
||||
if (sourceFile && sourceFile.fileWatcher) {
|
||||
return sourceFile;
|
||||
}
|
||||
}
|
||||
// Use default host function
|
||||
var sourceFile = hostGetSourceFile(filename, languageVersion, onError);
|
||||
var sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
|
||||
if (sourceFile && commandLine.options.watch) {
|
||||
// Attach a file watcher
|
||||
sourceFile.fileWatcher = sys.watchFile(sourceFile.filename, () => sourceFileChanged(sourceFile));
|
||||
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile));
|
||||
}
|
||||
return sourceFile;
|
||||
}
|
||||
@@ -321,45 +321,22 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function compile(filenames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) {
|
||||
var parseStart = new Date().getTime();
|
||||
var program = createProgram(filenames, compilerOptions, compilerHost);
|
||||
function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) {
|
||||
ts.parseTime = 0;
|
||||
ts.bindTime = 0;
|
||||
ts.checkTime = 0;
|
||||
ts.emitTime = 0;
|
||||
|
||||
var bindStart = new Date().getTime();
|
||||
var errors: Diagnostic[] = program.getDiagnostics();
|
||||
var exitStatus: EmitReturnStatus;
|
||||
var start = new Date().getTime();
|
||||
|
||||
if (errors.length) {
|
||||
var checkStart = bindStart;
|
||||
var emitStart = bindStart;
|
||||
var reportStart = bindStart;
|
||||
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
|
||||
}
|
||||
else {
|
||||
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
|
||||
var checkStart = new Date().getTime();
|
||||
errors = checker.getDiagnostics();
|
||||
if (program.isEmitBlocked()) {
|
||||
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
|
||||
}
|
||||
else if (compilerOptions.noEmit) {
|
||||
exitStatus = EmitReturnStatus.Succeeded;
|
||||
}
|
||||
else {
|
||||
var emitStart = new Date().getTime();
|
||||
var emitOutput = program.emitFiles();
|
||||
var emitErrors = emitOutput.diagnostics;
|
||||
exitStatus = emitOutput.emitResultStatus;
|
||||
var reportStart = new Date().getTime();
|
||||
errors = concatenate(errors, emitErrors);
|
||||
}
|
||||
}
|
||||
var program = createProgram(fileNames, compilerOptions, compilerHost);
|
||||
var exitStatus = compileProgram();
|
||||
|
||||
reportDiagnostics(errors);
|
||||
var end = new Date().getTime() - start;
|
||||
|
||||
if (compilerOptions.listFiles) {
|
||||
forEach(program.getSourceFiles(), file => {
|
||||
sys.write(file.filename + sys.newLine);
|
||||
sys.write(file.fileName + sys.newLine);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -367,21 +344,65 @@ module ts {
|
||||
var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
|
||||
reportCountStatistic("Files", program.getSourceFiles().length);
|
||||
reportCountStatistic("Lines", countLines(program));
|
||||
reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0);
|
||||
reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0);
|
||||
reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0);
|
||||
reportCountStatistic("Types", checker ? checker.getTypeCount() : 0);
|
||||
reportCountStatistic("Nodes", program.getNodeCount());
|
||||
reportCountStatistic("Identifiers", program.getIdentifierCount());
|
||||
reportCountStatistic("Symbols", program.getSymbolCount());
|
||||
reportCountStatistic("Types", program.getTypeCount());
|
||||
|
||||
if (memoryUsed >= 0) {
|
||||
reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");
|
||||
}
|
||||
reportTimeStatistic("Parse time", bindStart - parseStart);
|
||||
reportTimeStatistic("Bind time", checkStart - bindStart);
|
||||
reportTimeStatistic("Check time", emitStart - checkStart);
|
||||
reportTimeStatistic("Emit time", reportStart - emitStart);
|
||||
reportTimeStatistic("Total time", reportStart - parseStart);
|
||||
|
||||
reportTimeStatistic("Parse time", ts.parseTime);
|
||||
reportTimeStatistic("Bind time", ts.bindTime);
|
||||
reportTimeStatistic("Check time", ts.checkTime);
|
||||
reportTimeStatistic("Emit time", ts.emitTime);
|
||||
reportTimeStatistic("Total time", end);
|
||||
}
|
||||
|
||||
return { program, exitStatus };
|
||||
|
||||
function compileProgram(): ExitStatus {
|
||||
// First get any syntactic errors.
|
||||
var diagnostics = program.getSyntacticDiagnostics();
|
||||
reportDiagnostics(diagnostics);
|
||||
|
||||
// If we didn't have any syntactic errors, then also try getting the global and
|
||||
// semantic errors.
|
||||
if (diagnostics.length === 0) {
|
||||
var diagnostics = program.getGlobalDiagnostics();
|
||||
reportDiagnostics(diagnostics);
|
||||
|
||||
if (diagnostics.length === 0) {
|
||||
var diagnostics = program.getSemanticDiagnostics();
|
||||
reportDiagnostics(diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
// If the user doesn't want us to emit, then we're done at this point.
|
||||
if (compilerOptions.noEmit) {
|
||||
return diagnostics.length
|
||||
? ExitStatus.DiagnosticsPresent_OutputsSkipped
|
||||
: ExitStatus.Success;
|
||||
}
|
||||
|
||||
// Otherwise, emit and report any errors we ran into.
|
||||
var emitOutput = program.emit();
|
||||
reportDiagnostics(emitOutput.diagnostics);
|
||||
|
||||
// If the emitter didn't emit anything, then pass that value along.
|
||||
if (emitOutput.emitSkipped) {
|
||||
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
|
||||
}
|
||||
|
||||
// The emitter emitted something, inform the caller if that happened in the presence
|
||||
// of diagnostics or not.
|
||||
if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
|
||||
ExitStatus.DiagnosticsPresent_OutputsGenerated;
|
||||
}
|
||||
|
||||
return ExitStatus.Success;
|
||||
}
|
||||
}
|
||||
|
||||
function printVersion() {
|
||||
|
||||
+96
-66
@@ -872,7 +872,7 @@ module ts {
|
||||
}
|
||||
|
||||
export interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export interface CommentRange extends TextRange {
|
||||
@@ -884,72 +884,79 @@ module ts {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {path: string; name: string}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node; // The first node that causes this file to be an external module
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
|
||||
// The first node that causes this file to be an external module
|
||||
externalModuleIndicator: Node;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
|
||||
/* @internal */ nodeCount: number;
|
||||
/* @internal */ identifierCount: number;
|
||||
/* @internal */ symbolCount: number;
|
||||
|
||||
// @internal
|
||||
// Diagnostics reported about the "///<reference" comments in the file.
|
||||
referenceDiagnostics: Diagnostic[];
|
||||
// File level diagnostics reported by the parser (includes diagnostics about /// references
|
||||
// as well as code diagnostics).
|
||||
/* @internal */ parseDiagnostics: Diagnostic[];
|
||||
|
||||
// @internal
|
||||
// Parse errors refer specifically to things the parser could not understand at all (like
|
||||
// missing tokens, or tokens it didn't know how to deal with).
|
||||
parseDiagnostics: Diagnostic[];
|
||||
|
||||
// @internal
|
||||
// File level diagnostics reported by the binder.
|
||||
semanticDiagnostics: Diagnostic[];
|
||||
/* @internal */ bindDiagnostics: Diagnostic[];
|
||||
|
||||
// @internal
|
||||
// Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics).
|
||||
// This field should never be used directly, use getSyntacticDiagnostics function instead.
|
||||
syntacticDiagnostics: Diagnostic[];
|
||||
|
||||
// @internal
|
||||
// Stores a line map for the file.
|
||||
// This field should never be used directly to obtain line map, use getLineMap function instead.
|
||||
lineMap: number[];
|
||||
/* @internal */ lineMap: number[];
|
||||
}
|
||||
|
||||
export interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
|
||||
export interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
|
||||
export interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
|
||||
// Gets a type checker that can be used to semantically analyze source fils in the program.
|
||||
// The 'produceDiagnostics' flag determines if the checker will produce diagnostics while
|
||||
// analyzing the code. It can be set to 'false' to make many type checking operaitons
|
||||
// faster. With this flag set, the checker can avoid codepaths only necessary to produce
|
||||
// diagnostics, but not necessary to answer semantic questions about the code.
|
||||
//
|
||||
// If 'produceDiagnostics' is false, then any calls to get diagnostics from the TypeChecker
|
||||
// will throw an invalid operation exception.
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getTypeChecker(): TypeChecker;
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
// For testing purposes only. Should not be used by any other consumers (including the
|
||||
// language service).
|
||||
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
|
||||
|
||||
/* @internal */ getNodeCount(): number;
|
||||
/* @internal */ getIdentifierCount(): number;
|
||||
/* @internal */ getSymbolCount(): number;
|
||||
/* @internal */ getTypeCount(): number;
|
||||
}
|
||||
|
||||
export interface SourceMapSpan {
|
||||
@@ -974,37 +981,33 @@ module ts {
|
||||
}
|
||||
|
||||
// Return code used by getEmitOutput function to indicate status of the function
|
||||
export enum EmitReturnStatus {
|
||||
Succeeded = 0, // All outputs generated if requested (.js, .map, .d.ts), no errors reported
|
||||
AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, nothing generated
|
||||
JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors
|
||||
DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors
|
||||
EmitErrorsEncountered = 4, // Emitter errors occurred during emitting process
|
||||
CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options, nothing generated
|
||||
export enum ExitStatus {
|
||||
// Compiler ran successfully. Either this was a simple do-nothing compilation (for example,
|
||||
// when -version or -help was provided, or this was a normal compilation, no diagnostics
|
||||
// were produced, and all outputs were generated successfully.
|
||||
Success = 0,
|
||||
|
||||
// Diagnostics were produced and because of them no code was generated.
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
|
||||
// Diagnostics were produced and outputs were generated in spite of them.
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
|
||||
export interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
|
||||
}
|
||||
|
||||
export interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
|
||||
export interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -1029,10 +1032,19 @@ module ts {
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
|
||||
// Returns the constant value of this enum member, or 'undefined' if the enum member has a computed value.
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
|
||||
// Should not be called directly. Should only be accessed through the Program instance.
|
||||
/* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/* @internal */ getGlobalDiagnostics(): Diagnostic[];
|
||||
/* @internal */ getEmitResolver(sourceFile?: SourceFile): EmitResolver;
|
||||
|
||||
/* @internal */ getNodeCount(): number;
|
||||
/* @internal */ getIdentifierCount(): number;
|
||||
/* @internal */ getSymbolCount(): number;
|
||||
/* @internal */ getTypeCount(): number;
|
||||
}
|
||||
|
||||
export interface SymbolDisplayBuilder {
|
||||
@@ -1117,8 +1129,6 @@ module ts {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
@@ -1126,7 +1136,7 @@ module ts {
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
|
||||
@@ -1430,7 +1440,7 @@ module ts {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
}
|
||||
@@ -1498,14 +1508,14 @@ module ts {
|
||||
|
||||
export interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
|
||||
export interface CommandLineOption {
|
||||
name: string;
|
||||
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
|
||||
isFilePath?: boolean; // True if option value is a path or filename
|
||||
isFilePath?: boolean; // True if option value is a path or fileName
|
||||
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
|
||||
description?: DiagnosticMessage; // The message describing what the command line switch does
|
||||
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
|
||||
@@ -1653,10 +1663,10 @@ module ts {
|
||||
}
|
||||
|
||||
export interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken? (): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1672,4 +1682,24 @@ module ts {
|
||||
span: TextSpan;
|
||||
newLength: number;
|
||||
}
|
||||
|
||||
// @internal
|
||||
export interface DiagnosticCollection {
|
||||
// Adds a diagnostic to this diagnostic collection.
|
||||
add(diagnostic: Diagnostic): void;
|
||||
|
||||
// Gets all the diagnostics that aren't associated with a file.
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
|
||||
// If fileName is provided, gets all the diagnostics associated with that file name.
|
||||
// Otherwise, returns all the diagnostics (global and file associated) in this colletion.
|
||||
getDiagnostics(fileName?: string): Diagnostic[];
|
||||
|
||||
// Gets a count of how many times this collection has been modified. This value changes
|
||||
// each time 'add' is called (regardless of whether or not an equivalent diagnostic was
|
||||
// already in the collection). As such, it can be used as a simple way to tell if any
|
||||
// operation caused diagnostics to be returned by storing and comparing the return value
|
||||
// of this method before/after the operation is performed.
|
||||
getModificationCount(): number;
|
||||
}
|
||||
}
|
||||
|
||||
+93
-22
@@ -25,13 +25,12 @@ module ts {
|
||||
|
||||
export interface EmitHost extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
getNewLine(): string;
|
||||
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
}
|
||||
|
||||
// Pool writers to avoid needing to allocate them for every symbol we write.
|
||||
@@ -110,7 +109,7 @@ module ts {
|
||||
export function nodePosToString(node: Node): string {
|
||||
var file = getSourceFileOfNode(node);
|
||||
var loc = getLineAndCharacterOfPosition(file, node.pos);
|
||||
return file.filename + "(" + loc.line + "," + loc.character + ")";
|
||||
return file.fileName + "(" + loc.line + "," + loc.character + ")";
|
||||
}
|
||||
|
||||
export function getStartPosOfNode(node: Node): number {
|
||||
@@ -199,12 +198,19 @@ module ts {
|
||||
return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic {
|
||||
export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic {
|
||||
node = getErrorSpanForNode(node);
|
||||
var file = getSourceFileOfNode(node);
|
||||
var start = skipTrivia(file.text, node.pos);
|
||||
var length = node.end - start;
|
||||
return flattenDiagnosticChain(file, start, length, messageChain, newLine);
|
||||
return {
|
||||
file,
|
||||
start,
|
||||
length,
|
||||
code: messageChain.code,
|
||||
category: messageChain.category,
|
||||
messageText: messageChain.next ? messageChain : messageChain.messageText
|
||||
};
|
||||
}
|
||||
|
||||
export function getErrorSpanForNode(node: Node): Node {
|
||||
@@ -746,7 +752,7 @@ module ts {
|
||||
|
||||
export function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile, reference: FileReference) {
|
||||
if (!host.getCompilerOptions().noResolve) {
|
||||
var referenceFileName = isRootedDiskPath(reference.filename) ? reference.filename : combinePaths(getDirectoryPath(sourceFile.filename), reference.filename);
|
||||
var referenceFileName = isRootedDiskPath(reference.fileName) ? reference.fileName : combinePaths(getDirectoryPath(sourceFile.fileName), reference.fileName);
|
||||
referenceFileName = getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory());
|
||||
return host.getSourceFile(referenceFileName);
|
||||
}
|
||||
@@ -804,7 +810,7 @@ module ts {
|
||||
fileReference: {
|
||||
pos: start,
|
||||
end: end,
|
||||
filename: matchResult[3]
|
||||
fileName: matchResult[3]
|
||||
},
|
||||
isNoDefaultLib: false
|
||||
};
|
||||
@@ -843,21 +849,6 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function createEmitHostFromProgram(program: Program): EmitHost {
|
||||
var compilerHost = program.getCompilerHost();
|
||||
return {
|
||||
getCanonicalFileName: compilerHost.getCanonicalFileName,
|
||||
getCommonSourceDirectory: program.getCommonSourceDirectory,
|
||||
getCompilerOptions: program.getCompilerOptions,
|
||||
getCurrentDirectory: compilerHost.getCurrentDirectory,
|
||||
getNewLine: compilerHost.getNewLine,
|
||||
getSourceFile: program.getSourceFile,
|
||||
getSourceFiles: program.getSourceFiles,
|
||||
isEmitBlocked: program.isEmitBlocked,
|
||||
writeFile: compilerHost.writeFile,
|
||||
};
|
||||
}
|
||||
|
||||
export function textSpanEnd(span: TextSpan) {
|
||||
return span.start + span.length
|
||||
}
|
||||
@@ -1068,4 +1059,84 @@ module ts {
|
||||
|
||||
return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN);
|
||||
}
|
||||
|
||||
// @internal
|
||||
export function createDiagnosticCollection(): DiagnosticCollection {
|
||||
var nonFileDiagnostics: Diagnostic[] = [];
|
||||
var fileDiagnostics: Map<Diagnostic[]> = {};
|
||||
|
||||
var diagnosticsModified = false;
|
||||
var modificationCount = 0;
|
||||
|
||||
return {
|
||||
add,
|
||||
getGlobalDiagnostics,
|
||||
getDiagnostics,
|
||||
getModificationCount
|
||||
};
|
||||
|
||||
function getModificationCount() {
|
||||
return modificationCount;
|
||||
}
|
||||
|
||||
function add(diagnostic: Diagnostic): void {
|
||||
var diagnostics: Diagnostic[];
|
||||
if (diagnostic.file) {
|
||||
diagnostics = fileDiagnostics[diagnostic.file.fileName];
|
||||
if (!diagnostics) {
|
||||
diagnostics = [];
|
||||
fileDiagnostics[diagnostic.file.fileName] = diagnostics;
|
||||
}
|
||||
}
|
||||
else {
|
||||
diagnostics = nonFileDiagnostics;
|
||||
}
|
||||
|
||||
diagnostics.push(diagnostic);
|
||||
diagnosticsModified = true;
|
||||
modificationCount++;
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
sortAndDeduplicate();
|
||||
return nonFileDiagnostics;
|
||||
}
|
||||
|
||||
function getDiagnostics(fileName?: string): Diagnostic[] {
|
||||
sortAndDeduplicate();
|
||||
if (fileName) {
|
||||
return fileDiagnostics[fileName] || [];
|
||||
}
|
||||
|
||||
var allDiagnostics: Diagnostic[] = [];
|
||||
function pushDiagnostic(d: Diagnostic) {
|
||||
allDiagnostics.push(d);
|
||||
}
|
||||
|
||||
forEach(nonFileDiagnostics, pushDiagnostic);
|
||||
|
||||
for (var key in fileDiagnostics) {
|
||||
if (hasProperty(fileDiagnostics, key)) {
|
||||
forEach(fileDiagnostics[key], pushDiagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
return sortAndDeduplicateDiagnostics(allDiagnostics);
|
||||
}
|
||||
|
||||
function sortAndDeduplicate() {
|
||||
if (!diagnosticsModified) {
|
||||
return;
|
||||
}
|
||||
|
||||
diagnosticsModified = false;
|
||||
nonFileDiagnostics = sortAndDeduplicateDiagnostics(nonFileDiagnostics);
|
||||
|
||||
for (var key in fileDiagnostics) {
|
||||
if (hasProperty(fileDiagnostics, key)) {
|
||||
fileDiagnostics[key] = sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,11 +256,40 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
it('Correct type baselines for ' + fileName, () => {
|
||||
// NEWTODO: Type baselines
|
||||
if (result.errors.length === 0) {
|
||||
Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => {
|
||||
// The full walker simulates the types that you would get from doing a full
|
||||
// compile. The pull walker simulates the types you get when you just do
|
||||
// a type query for a random node (like how the LS would do it). Most of the
|
||||
// time, these will be the same. However, occasionally, they can be different.
|
||||
// Specifically, when the compiler internally depends on symbol IDs to order
|
||||
// things, then we may see different results because symbols can be created in a
|
||||
// different order with 'pull' operations, and thus can produce slightly differing
|
||||
// output.
|
||||
//
|
||||
// For example, with a full type check, we may see a type outputed as: number | string
|
||||
// But with a pull type check, we may see it as: string | number
|
||||
//
|
||||
// These types are equivalent, but depend on what order the compiler observed
|
||||
// certain parts of the program.
|
||||
|
||||
var fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
|
||||
var pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
|
||||
|
||||
var fullTypes = generateTypes(fullWalker);
|
||||
var pullTypes = generateTypes(pullWalker);
|
||||
|
||||
if (fullTypes !== pullTypes) {
|
||||
Harness.Baseline.runBaseline('Correct full expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
|
||||
Harness.Baseline.runBaseline('Correct pull expression types for ' + fileName, justName.replace(/\.ts/, '.types.pull'), () => pullTypes);
|
||||
}
|
||||
else {
|
||||
Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
|
||||
}
|
||||
|
||||
function generateTypes(walker: TypeWriterWalker): string {
|
||||
var allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
|
||||
var typeLines: string[] = [];
|
||||
var typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
|
||||
var walker = new TypeWriterWalker(program);
|
||||
|
||||
allFiles.forEach(file => {
|
||||
var codeLines = file.content.split('\n');
|
||||
walker.getTypes(file.unitName).forEach(result => {
|
||||
@@ -299,7 +328,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
});
|
||||
|
||||
return typeLines.join('');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+140
-170
@@ -16,6 +16,7 @@
|
||||
/// <reference path='..\services\services.ts' />
|
||||
/// <reference path='harnessLanguageService.ts' />
|
||||
/// <reference path='harness.ts' />
|
||||
/// <reference path='fourslashRunner.ts' />
|
||||
|
||||
module FourSlash {
|
||||
ts.disableIncrementalParsing = false;
|
||||
@@ -118,7 +119,7 @@ module FourSlash {
|
||||
baselineFile: 'BaselineFile',
|
||||
declaration: 'declaration',
|
||||
emitThisFile: 'emitThisFile', // This flag is used for testing getEmitOutput feature. It allows test-cases to indicate what file to be output in multiple files project
|
||||
filename: 'Filename',
|
||||
fileName: 'Filename',
|
||||
mapRoot: 'mapRoot',
|
||||
module: 'module',
|
||||
out: 'out',
|
||||
@@ -129,7 +130,7 @@ module FourSlash {
|
||||
};
|
||||
|
||||
// List of allowed metadata names
|
||||
var fileMetadataNames = [testOptMetadataNames.filename, testOptMetadataNames.emitThisFile, testOptMetadataNames.resolveReference];
|
||||
var fileMetadataNames = [testOptMetadataNames.fileName, testOptMetadataNames.emitThisFile, testOptMetadataNames.resolveReference];
|
||||
var globalMetadataNames = [testOptMetadataNames.baselineFile, testOptMetadataNames.declaration,
|
||||
testOptMetadataNames.mapRoot, testOptMetadataNames.module, testOptMetadataNames.out,
|
||||
testOptMetadataNames.outDir, testOptMetadataNames.sourceMap, testOptMetadataNames.sourceRoot]
|
||||
@@ -245,11 +246,9 @@ module FourSlash {
|
||||
|
||||
export class TestState {
|
||||
// Language service instance
|
||||
public languageServiceShimHost: Harness.LanguageService.TypeScriptLS;
|
||||
private languageServiceAdapterHost: Harness.LanguageService.LanguageServiceAdapterHost;
|
||||
private languageService: ts.LanguageService;
|
||||
|
||||
// A reference to the language service's compiler state's compiler instance
|
||||
private compiler: () => { getSyntaxTree(fileName: string): ts.SourceFile };
|
||||
private cancellationToken: TestCancellationToken;
|
||||
|
||||
// The current caret position in the active file
|
||||
public currentCaretPosition = 0;
|
||||
@@ -263,31 +262,41 @@ module FourSlash {
|
||||
|
||||
public formatCodeOptions: ts.FormatCodeOptions;
|
||||
|
||||
public cancellationToken: TestCancellationToken;
|
||||
|
||||
private scenarioActions: string[] = [];
|
||||
private taoInvalidReason: string = null;
|
||||
|
||||
private inputFiles: ts.Map<string> = {}; // Map between inputFile's filename and its content for easily looking up when resolving references
|
||||
private inputFiles: ts.Map<string> = {}; // Map between inputFile's fileName and its content for easily looking up when resolving references
|
||||
|
||||
// Add input file which has matched file name with the given reference-file path.
|
||||
// This is necessary when resolveReference flag is specified
|
||||
private addMatchedInputFile(referenceFilePath: string) {
|
||||
var inputFile = this.inputFiles[referenceFilePath];
|
||||
if (inputFile && !Harness.isLibraryFile(referenceFilePath)) {
|
||||
this.languageServiceShimHost.addScript(referenceFilePath, inputFile);
|
||||
this.languageServiceAdapterHost.addScript(referenceFilePath, inputFile);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(public testData: FourSlashData) {
|
||||
// Initialize the language service with all the scripts
|
||||
private getLanguageServiceAdapter(testType: FourSlashTestType, cancellationToken: TestCancellationToken, compilationOptions: ts.CompilerOptions): Harness.LanguageService.LanguageServiceAdapter {
|
||||
switch (testType) {
|
||||
case FourSlashTestType.Native:
|
||||
return new Harness.LanguageService.NativeLanugageServiceAdapter(cancellationToken, compilationOptions);
|
||||
case FourSlashTestType.Shims:
|
||||
return new Harness.LanguageService.ShimLanugageServiceAdapter(cancellationToken, compilationOptions);
|
||||
default:
|
||||
throw new Error("Unknown FourSlash test type: ");
|
||||
}
|
||||
}
|
||||
|
||||
constructor(private basePath: string, private testType: FourSlashTestType, public testData: FourSlashData) {
|
||||
// Create a new Services Adapter
|
||||
this.cancellationToken = new TestCancellationToken();
|
||||
this.languageServiceShimHost = new Harness.LanguageService.TypeScriptLS(this.cancellationToken);
|
||||
var compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions);
|
||||
var languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions);
|
||||
this.languageServiceAdapterHost = languageServiceAdapter.getHost();
|
||||
this.languageService = languageServiceAdapter.getLanguageService();
|
||||
|
||||
var compilationSettings = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions);
|
||||
this.languageServiceShimHost.setCompilationSettings(compilationSettings);
|
||||
|
||||
var startResolveFileRef: FourSlashFile = undefined;
|
||||
// Initialize the language service with all the scripts
|
||||
var startResolveFileRef: FourSlashFile;
|
||||
|
||||
ts.forEach(testData.files, file => {
|
||||
// Create map between fileName and its content for easily looking up when resolveReference flag is specified
|
||||
@@ -302,18 +311,16 @@ module FourSlash {
|
||||
|
||||
if (startResolveFileRef) {
|
||||
// Add the entry-point file itself into the languageServiceShimHost
|
||||
this.languageServiceShimHost.addScript(startResolveFileRef.fileName, startResolveFileRef.content);
|
||||
this.languageServiceAdapterHost.addScript(startResolveFileRef.fileName, startResolveFileRef.content);
|
||||
|
||||
var jsonResolvedResult = JSON.parse(this.languageServiceShimHost.getCoreService().getPreProcessedFileInfo(startResolveFileRef.fileName,
|
||||
createScriptSnapShot(startResolveFileRef.content)));
|
||||
var resolvedResult = jsonResolvedResult.result;
|
||||
var referencedFiles: ts.IFileReference[] = resolvedResult.referencedFiles;
|
||||
var importedFiles: ts.IFileReference[] = resolvedResult.importedFiles;
|
||||
var resolvedResult = languageServiceAdapter.getPreProcessedFileInfo(startResolveFileRef.fileName, startResolveFileRef.content);
|
||||
var referencedFiles: ts.FileReference[] = resolvedResult.referencedFiles;
|
||||
var importedFiles: ts.FileReference[] = resolvedResult.importedFiles;
|
||||
|
||||
// Add triple reference files into language-service host
|
||||
ts.forEach(referencedFiles, referenceFile => {
|
||||
// Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path
|
||||
var referenceFilePath = "tests/cases/fourslash/" + referenceFile.path;
|
||||
var referenceFilePath = this.basePath + '/' + referenceFile.fileName;
|
||||
this.addMatchedInputFile(referenceFilePath);
|
||||
});
|
||||
|
||||
@@ -321,29 +328,24 @@ module FourSlash {
|
||||
ts.forEach(importedFiles, importedFile => {
|
||||
// Fourslash insert tests/cases/fourslash into inputFile.unitName and import statement doesn't require ".ts"
|
||||
// so convert them before making appropriate comparison
|
||||
var importedFilePath = "tests/cases/fourslash/" + importedFile.path + ".ts";
|
||||
var importedFilePath = this.basePath + '/' + importedFile.fileName + ".ts";
|
||||
this.addMatchedInputFile(importedFilePath);
|
||||
});
|
||||
|
||||
// Check if no-default-lib flag is false and if so add default library
|
||||
if (!resolvedResult.isLibFile) {
|
||||
this.languageServiceShimHost.addDefaultLibrary();
|
||||
this.languageServiceAdapterHost.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
|
||||
}
|
||||
} else {
|
||||
// resolveReference file-option is not specified then do not resolve any files and include all inputFiles
|
||||
ts.forEachKey(this.inputFiles, fileName => {
|
||||
if (!Harness.isLibraryFile(fileName)) {
|
||||
this.languageServiceShimHost.addScript(fileName, this.inputFiles[fileName]);
|
||||
this.languageServiceAdapterHost.addScript(fileName, this.inputFiles[fileName]);
|
||||
}
|
||||
});
|
||||
this.languageServiceShimHost.addDefaultLibrary();
|
||||
this.languageServiceAdapterHost.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
|
||||
}
|
||||
|
||||
// Sneak into the language service and get its compiler so we can examine the syntax trees
|
||||
this.languageService = this.languageServiceShimHost.getLanguageService().languageService;
|
||||
var compilerState = (<any>this.languageService).compiler;
|
||||
this.compiler = () => compilerState.compiler;
|
||||
|
||||
this.formatCodeOptions = {
|
||||
IndentSize: 4,
|
||||
TabSize: 4,
|
||||
@@ -360,15 +362,20 @@ module FourSlash {
|
||||
};
|
||||
|
||||
this.testData.files.forEach(file => {
|
||||
var filename = file.fileName.replace(Harness.IO.directoryName(file.fileName), '').substr(1);
|
||||
var filenameWithoutExtension = filename.substr(0, filename.lastIndexOf("."));
|
||||
this.scenarioActions.push('<CreateFileOnDisk FileId="' + filename + '" FileNameWithoutExtension="' + filenameWithoutExtension + '" FileExtension=".ts"><![CDATA[' + file.content + ']]></CreateFileOnDisk>');
|
||||
var fileName = file.fileName.replace(Harness.IO.directoryName(file.fileName), '').substr(1);
|
||||
var fileNameWithoutExtension = fileName.substr(0, fileName.lastIndexOf("."));
|
||||
this.scenarioActions.push('<CreateFileOnDisk FileId="' + fileName + '" FileNameWithoutExtension="' + fileNameWithoutExtension + '" FileExtension=".ts"><![CDATA[' + file.content + ']]></CreateFileOnDisk>');
|
||||
});
|
||||
|
||||
// Open the first file by default
|
||||
this.openFile(0);
|
||||
}
|
||||
|
||||
private getFileContent(fileName: string): string {
|
||||
var script = this.languageServiceAdapterHost.getScriptInfo(fileName);
|
||||
return script.content;
|
||||
}
|
||||
|
||||
// Entry points from fourslash.ts
|
||||
public goToMarker(name = '') {
|
||||
var marker = this.getMarkerByName(name);
|
||||
@@ -376,8 +383,8 @@ module FourSlash {
|
||||
this.openFile(marker.fileName);
|
||||
}
|
||||
|
||||
var scriptSnapshot = this.languageServiceShimHost.getScriptSnapshot(marker.fileName);
|
||||
if (marker.position === -1 || marker.position > scriptSnapshot.getLength()) {
|
||||
var content = this.getFileContent(marker.fileName);
|
||||
if (marker.position === -1 || marker.position > content.length) {
|
||||
throw new Error('Marker "' + name + '" has been invalidated by unrecoverable edits to the file.');
|
||||
}
|
||||
this.lastKnownMarker = name;
|
||||
@@ -387,14 +394,14 @@ module FourSlash {
|
||||
public goToPosition(pos: number) {
|
||||
this.currentCaretPosition = pos;
|
||||
|
||||
var lineStarts = ts.computeLineStarts(this.getCurrentFileContent());
|
||||
var lineStarts = ts.computeLineStarts(this.getFileContent(this.activeFile.fileName));
|
||||
var lineCharPos = ts.computeLineAndCharacterOfPosition(lineStarts, pos);
|
||||
this.scenarioActions.push('<MoveCaretToLineAndChar LineNumber="' + lineCharPos.line + '" CharNumber="' + lineCharPos.character + '" />');
|
||||
}
|
||||
|
||||
public moveCaretRight(count = 1) {
|
||||
this.currentCaretPosition += count;
|
||||
this.currentCaretPosition = Math.min(this.currentCaretPosition, this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength());
|
||||
this.currentCaretPosition = Math.min(this.currentCaretPosition, this.getFileContent(this.activeFile.fileName).length);
|
||||
if (count > 0) {
|
||||
this.scenarioActions.push('<MoveCaretRight NumberOfChars="' + count + '" />');
|
||||
} else {
|
||||
@@ -409,8 +416,8 @@ module FourSlash {
|
||||
var fileToOpen: FourSlashFile = this.findFile(indexOrName);
|
||||
fileToOpen.fileName = ts.normalizeSlashes(fileToOpen.fileName);
|
||||
this.activeFile = fileToOpen;
|
||||
var filename = fileToOpen.fileName.replace(Harness.IO.directoryName(fileToOpen.fileName), '').substr(1);
|
||||
this.scenarioActions.push('<OpenFile FileName="" SrcFileId="' + filename + '" FileId="' + filename + '" />');
|
||||
var fileName = fileToOpen.fileName.replace(Harness.IO.directoryName(fileToOpen.fileName), '').substr(1);
|
||||
this.scenarioActions.push('<OpenFile FileName="" SrcFileId="' + fileName + '" FileId="' + fileName + '" />');
|
||||
}
|
||||
|
||||
public verifyErrorExistsBetweenMarkers(startMarkerName: string, endMarkerName: string, negative: boolean) {
|
||||
@@ -453,7 +460,7 @@ module FourSlash {
|
||||
private getAllDiagnostics(): ts.Diagnostic[] {
|
||||
var diagnostics: ts.Diagnostic[] = [];
|
||||
|
||||
var fileNames = JSON.parse(this.languageServiceShimHost.getScriptFileNames());
|
||||
var fileNames = this.languageServiceAdapterHost.getFilenames();
|
||||
for (var i = 0, n = fileNames.length; i < n; i++) {
|
||||
diagnostics.push.apply(this.getDiagnostics(fileNames[i]));
|
||||
}
|
||||
@@ -513,7 +520,9 @@ module FourSlash {
|
||||
}
|
||||
|
||||
errors.forEach(function (error: ts.Diagnostic) {
|
||||
Harness.IO.log(" minChar: " + error.start + ", limChar: " + (error.start + error.length) + ", message: " + error.messageText + "\n");
|
||||
Harness.IO.log(" minChar: " + error.start +
|
||||
", limChar: " + (error.start + error.length) +
|
||||
", message: " + ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine) + "\n");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -662,7 +671,16 @@ module FourSlash {
|
||||
|
||||
Harness.IO.log(errorMsg);
|
||||
this.raiseError("Completion list is not empty at Caret");
|
||||
}
|
||||
}
|
||||
|
||||
public verifyCompletionListAllowsNewIdentifier(negative: boolean) {
|
||||
var completions = this.getCompletionListAtCaret();
|
||||
|
||||
if ((completions && !completions.isNewIdentifierLocation) && !negative) {
|
||||
this.raiseError("Expected builder completion entry");
|
||||
} else if ((completions && completions.isNewIdentifierLocation) && negative) {
|
||||
this.raiseError("Un-expected builder completion entry");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -730,7 +748,7 @@ module FourSlash {
|
||||
var localFiles = this.testData.files.map<string>(file => file.fileName);
|
||||
// Count only the references in local files. Filter the ones in lib and other files.
|
||||
ts.forEach(references, entry => {
|
||||
if (localFiles.some((filename) => filename === entry.fileName)) {
|
||||
if (localFiles.some((fileName) => fileName === entry.fileName)) {
|
||||
++referencesCount;
|
||||
}
|
||||
});
|
||||
@@ -794,7 +812,6 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; },
|
||||
displayParts: ts.SymbolDisplayPart[],
|
||||
documentation: ts.SymbolDisplayPart[]) {
|
||||
@@ -1138,16 +1155,24 @@ module FourSlash {
|
||||
// Loop through all the emittedFiles and emit them one by one
|
||||
emitFiles.forEach(emitFile => {
|
||||
var emitOutput = this.languageService.getEmitOutput(emitFile.fileName);
|
||||
var emitOutputStatus = emitOutput.emitOutputStatus;
|
||||
// Print emitOutputStatus in readable format
|
||||
resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus];
|
||||
resultString += "\n";
|
||||
resultString += "EmitSkipped: " + emitOutput.emitSkipped + ts.sys.newLine;
|
||||
|
||||
if (emitOutput.emitSkipped) {
|
||||
resultString += "Diagnostics:" + ts.sys.newLine;
|
||||
var diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram());
|
||||
for (var i = 0, n = diagnostics.length; i < n; i++) {
|
||||
resultString += " " + diagnostics[0].messageText + ts.sys.newLine;
|
||||
}
|
||||
}
|
||||
|
||||
emitOutput.outputFiles.forEach((outputFile, idx, array) => {
|
||||
var filename = "Filename : " + outputFile.name + "\n";
|
||||
resultString = resultString + filename + outputFile.text;
|
||||
var fileName = "FileName : " + outputFile.name + ts.sys.newLine;
|
||||
resultString = resultString + fileName + outputFile.text;
|
||||
});
|
||||
resultString += "\n";
|
||||
resultString += ts.sys.newLine;
|
||||
});
|
||||
|
||||
return resultString;
|
||||
},
|
||||
true /* run immediately */);
|
||||
@@ -1179,7 +1204,10 @@ module FourSlash {
|
||||
|
||||
if (errorList.length) {
|
||||
errorList.forEach(err => {
|
||||
Harness.IO.log("start: " + err.start + ", length: " + err.length + ", message: " + err.messageText);
|
||||
Harness.IO.log(
|
||||
"start: " + err.start +
|
||||
", length: " + err.length +
|
||||
", message: " + ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1189,8 +1217,7 @@ module FourSlash {
|
||||
var file = this.testData.files[i];
|
||||
var active = (this.activeFile === file);
|
||||
Harness.IO.log('=== Script (' + file.fileName + ') ' + (active ? '(active, cursor at |)' : '') + ' ===');
|
||||
var snapshot = this.languageServiceShimHost.getScriptSnapshot(file.fileName);
|
||||
var content = snapshot.getText(0, snapshot.getLength());
|
||||
var content = this.getFileContent(file.fileName);
|
||||
if (active) {
|
||||
content = content.substr(0, this.currentCaretPosition) + (makeCaretVisible ? '|' : "") + content.substr(this.currentCaretPosition);
|
||||
}
|
||||
@@ -1224,8 +1251,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
public printContext() {
|
||||
var fileNames: string[] = JSON.parse(this.languageServiceShimHost.getScriptFileNames());
|
||||
ts.forEach(fileNames, Harness.IO.log);
|
||||
ts.forEach(this.languageServiceAdapterHost.getFilenames(), Harness.IO.log);
|
||||
}
|
||||
|
||||
public deleteChar(count = 1) {
|
||||
@@ -1238,7 +1264,7 @@ module FourSlash {
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
// Make the edit
|
||||
this.languageServiceShimHost.editScript(this.activeFile.fileName, offset, offset + 1, ch);
|
||||
this.languageServiceAdapterHost.editScript(this.activeFile.fileName, offset, offset + 1, ch);
|
||||
this.updateMarkersForEdit(this.activeFile.fileName, offset, offset + 1, ch);
|
||||
|
||||
if (i % checkCadence === 0) {
|
||||
@@ -1265,7 +1291,7 @@ module FourSlash {
|
||||
public replace(start: number, length: number, text: string) {
|
||||
this.taoInvalidReason = 'replace NYI';
|
||||
|
||||
this.languageServiceShimHost.editScript(this.activeFile.fileName, start, start + length, text);
|
||||
this.languageServiceAdapterHost.editScript(this.activeFile.fileName, start, start + length, text);
|
||||
this.updateMarkersForEdit(this.activeFile.fileName, start, start + length, text);
|
||||
this.checkPostEditInvariants();
|
||||
}
|
||||
@@ -1280,7 +1306,7 @@ module FourSlash {
|
||||
for (var i = 0; i < count; i++) {
|
||||
offset--;
|
||||
// Make the edit
|
||||
this.languageServiceShimHost.editScript(this.activeFile.fileName, offset, offset + 1, ch);
|
||||
this.languageServiceAdapterHost.editScript(this.activeFile.fileName, offset, offset + 1, ch);
|
||||
this.updateMarkersForEdit(this.activeFile.fileName, offset, offset + 1, ch);
|
||||
|
||||
if (i % checkCadence === 0) {
|
||||
@@ -1325,7 +1351,7 @@ module FourSlash {
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
// Make the edit
|
||||
var ch = text.charAt(i);
|
||||
this.languageServiceShimHost.editScript(this.activeFile.fileName, offset, offset, ch);
|
||||
this.languageServiceAdapterHost.editScript(this.activeFile.fileName, offset, offset, ch);
|
||||
this.languageService.getBraceMatchingAtPosition(this.activeFile.fileName, offset);
|
||||
|
||||
this.updateMarkersForEdit(this.activeFile.fileName, offset, offset, ch);
|
||||
@@ -1368,7 +1394,7 @@ module FourSlash {
|
||||
|
||||
var start = this.currentCaretPosition;
|
||||
var offset = this.currentCaretPosition;
|
||||
this.languageServiceShimHost.editScript(this.activeFile.fileName, offset, offset, text);
|
||||
this.languageServiceAdapterHost.editScript(this.activeFile.fileName, offset, offset, text);
|
||||
this.updateMarkersForEdit(this.activeFile.fileName, offset, offset, text);
|
||||
this.checkPostEditInvariants();
|
||||
offset += text.length;
|
||||
@@ -1390,18 +1416,23 @@ module FourSlash {
|
||||
}
|
||||
|
||||
private checkPostEditInvariants() {
|
||||
if (this.testType !== FourSlashTestType.Native) {
|
||||
// getSourcefile() results can not be serialized. Only perform these verifications
|
||||
// if running against a native LS object.
|
||||
return;
|
||||
}
|
||||
|
||||
var incrementalSourceFile = this.languageService.getSourceFile(this.activeFile.fileName);
|
||||
Utils.assertInvariants(incrementalSourceFile, /*parent:*/ undefined);
|
||||
|
||||
var incrementalSyntaxDiagnostics = ts.getSyntacticDiagnostics(incrementalSourceFile);
|
||||
var incrementalSyntaxDiagnostics = incrementalSourceFile.parseDiagnostics;
|
||||
|
||||
// Check syntactic structure
|
||||
var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
|
||||
var content = snapshot.getText(0, snapshot.getLength());
|
||||
var content = this.getFileContent(this.activeFile.fileName);
|
||||
|
||||
var referenceSourceFile = ts.createLanguageServiceSourceFile(
|
||||
this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*setNodeParents:*/ false);
|
||||
var referenceSyntaxDiagnostics = ts.getSyntacticDiagnostics(referenceSourceFile);
|
||||
var referenceSyntaxDiagnostics = referenceSourceFile.parseDiagnostics;
|
||||
|
||||
Utils.assertDiagnosticsEquals(incrementalSyntaxDiagnostics, referenceSyntaxDiagnostics);
|
||||
Utils.assertStructuralEquals(incrementalSourceFile, referenceSourceFile);
|
||||
@@ -1411,7 +1442,7 @@ module FourSlash {
|
||||
// The caret can potentially end up between the \r and \n, which is confusing. If
|
||||
// that happens, move it back one character
|
||||
if (this.currentCaretPosition > 0) {
|
||||
var ch = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(this.currentCaretPosition - 1, this.currentCaretPosition);
|
||||
var ch = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition - 1, this.currentCaretPosition);
|
||||
if (ch === '\r') {
|
||||
this.currentCaretPosition--;
|
||||
}
|
||||
@@ -1424,10 +1455,9 @@ module FourSlash {
|
||||
var runningOffset = 0;
|
||||
edits = edits.sort((a, b) => a.span.start - b.span.start);
|
||||
// Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters
|
||||
var snapshot = this.languageServiceShimHost.getScriptSnapshot(fileName);
|
||||
var oldContent = snapshot.getText(0, snapshot.getLength());
|
||||
var oldContent = this.getFileContent(this.activeFile.fileName);
|
||||
for (var j = 0; j < edits.length; j++) {
|
||||
this.languageServiceShimHost.editScript(fileName, edits[j].span.start + runningOffset, ts.textSpanEnd(edits[j].span) + runningOffset, edits[j].newText);
|
||||
this.languageServiceAdapterHost.editScript(fileName, edits[j].span.start + runningOffset, ts.textSpanEnd(edits[j].span) + runningOffset, edits[j].newText);
|
||||
this.updateMarkersForEdit(fileName, edits[j].span.start + runningOffset, ts.textSpanEnd(edits[j].span) + runningOffset, edits[j].newText);
|
||||
var change = (edits[j].span.start - ts.textSpanEnd(edits[j].span)) + edits[j].newText.length;
|
||||
runningOffset += change;
|
||||
@@ -1436,8 +1466,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
if (isFormattingEdit) {
|
||||
snapshot = this.languageServiceShimHost.getScriptSnapshot(fileName);
|
||||
var newContent = snapshot.getText(0, snapshot.getLength());
|
||||
var newContent = this.getFileContent(fileName);
|
||||
|
||||
if (newContent.replace(/\s/g, '') !== oldContent.replace(/\s/g, '')) {
|
||||
this.raiseError('Formatting operation destroyed non-whitespace content');
|
||||
@@ -1484,7 +1513,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
public goToEOF() {
|
||||
var len = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength();
|
||||
var len = this.getFileContent(this.activeFile.fileName).length;
|
||||
this.goToPosition(len);
|
||||
}
|
||||
|
||||
@@ -1605,7 +1634,7 @@ module FourSlash {
|
||||
public verifyCurrentFileContent(text: string) {
|
||||
this.taoInvalidReason = 'verifyCurrentFileContent NYI';
|
||||
|
||||
var actual = this.getCurrentFileContent();
|
||||
var actual = this.getFileContent(this.activeFile.fileName);
|
||||
var replaceNewlines = (str: string) => str.replace(/\r\n/g, "\n");
|
||||
if (replaceNewlines(actual) !== replaceNewlines(text)) {
|
||||
throw new Error('verifyCurrentFileContent\n' +
|
||||
@@ -1617,7 +1646,7 @@ module FourSlash {
|
||||
public verifyTextAtCaretIs(text: string) {
|
||||
this.taoInvalidReason = 'verifyCurrentFileContent NYI';
|
||||
|
||||
var actual = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(this.currentCaretPosition, this.currentCaretPosition + text.length);
|
||||
var actual = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition, this.currentCaretPosition + text.length);
|
||||
if (actual !== text) {
|
||||
throw new Error('verifyTextAtCaretIs\n' +
|
||||
'\tExpected: "' + text + '"\n' +
|
||||
@@ -1635,7 +1664,7 @@ module FourSlash {
|
||||
'\t Actual: undefined');
|
||||
}
|
||||
|
||||
var actual = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(span.start, ts.textSpanEnd(span));
|
||||
var actual = this.getFileContent(this.activeFile.fileName).substring(span.start, ts.textSpanEnd(span));
|
||||
if (actual !== text) {
|
||||
this.raiseError('verifyCurrentNameOrDottedNameSpanText\n' +
|
||||
'\tExpected: "' + text + '"\n' +
|
||||
@@ -1709,8 +1738,8 @@ module FourSlash {
|
||||
|
||||
function jsonMismatchString() {
|
||||
return ts.sys.newLine +
|
||||
"expected: '" + ts.sys.newLine + JSON.stringify(expected,(k, v) => v, 2) + "'" + ts.sys.newLine +
|
||||
"actual: '" + ts.sys.newLine + JSON.stringify(actual,(k, v) => v, 2) + "'";
|
||||
"expected: '" + ts.sys.newLine + JSON.stringify(expected, (k, v) => v, 2) + "'" + ts.sys.newLine +
|
||||
"actual: '" + ts.sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1722,7 +1751,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
public verifySyntacticClassifications(expected: { classificationType: string; text: string }[]) {
|
||||
var actual = this.languageService.getSyntacticClassifications(this.activeFile.fileName,
|
||||
var actual = this.languageService.getSyntacticClassifications(this.activeFile.fileName,
|
||||
ts.createTextSpan(0, this.activeFile.content.length));
|
||||
|
||||
this.verifyClassifications(expected, actual);
|
||||
@@ -1798,69 +1827,6 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifyTypesAgainstFullCheckAtPositions(positions: number[]) {
|
||||
this.taoInvalidReason = 'verifyTypesAgainstFullCheckAtPositions impossible';
|
||||
|
||||
// Create a from-scratch LS to check against
|
||||
var referenceLanguageServiceShimHost = new Harness.LanguageService.TypeScriptLS();
|
||||
var referenceLanguageServiceShim = referenceLanguageServiceShimHost.getLanguageService();
|
||||
var referenceLanguageService = referenceLanguageServiceShim.languageService;
|
||||
|
||||
// Add lib.d.ts to the reference language service
|
||||
referenceLanguageServiceShimHost.addDefaultLibrary();
|
||||
|
||||
for (var i = 0; i < this.testData.files.length; i++) {
|
||||
var file = this.testData.files[i];
|
||||
|
||||
var snapshot = this.languageServiceShimHost.getScriptSnapshot(file.fileName);
|
||||
var content = snapshot.getText(0, snapshot.getLength());
|
||||
referenceLanguageServiceShimHost.addScript(this.testData.files[i].fileName, content);
|
||||
}
|
||||
|
||||
for (i = 0; i < positions.length; i++) {
|
||||
var nameOf = (type: ts.QuickInfo) => type ? ts.displayPartsToString(type.displayParts) : '(none)';
|
||||
|
||||
var pullName: string, refName: string;
|
||||
var anyFailed = false;
|
||||
|
||||
var errMsg = '';
|
||||
|
||||
try {
|
||||
var pullType = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
|
||||
pullName = nameOf(pullType);
|
||||
} catch (err1) {
|
||||
errMsg = 'Failed to get pull type check. Exception: ' + err1 + '\r\n';
|
||||
if (err1.stack) errMsg = errMsg + err1.stack;
|
||||
pullName = '(failed)';
|
||||
anyFailed = true;
|
||||
}
|
||||
|
||||
try {
|
||||
var referenceType = referenceLanguageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
|
||||
refName = nameOf(referenceType);
|
||||
} catch (err2) {
|
||||
errMsg = 'Failed to get full type check. Exception: ' + err2 + '\r\n';
|
||||
if (err2.stack) errMsg = errMsg + err2.stack;
|
||||
refName = '(failed)';
|
||||
anyFailed = true;
|
||||
}
|
||||
|
||||
var failure = anyFailed || (refName !== pullName);
|
||||
if (failure) {
|
||||
snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
|
||||
content = snapshot.getText(0, snapshot.getLength());
|
||||
var textAtPosition = content.substr(positions[i], 10);
|
||||
var positionDescription = 'Position ' + positions[i] + ' ("' + textAtPosition + '"...)';
|
||||
|
||||
if (anyFailed) {
|
||||
throw new Error('Exception thrown in language service for ' + positionDescription + '\r\n' + errMsg);
|
||||
} else if (refName !== pullName) {
|
||||
throw new Error('Pull/Full disagreement failed at ' + positionDescription + ' - expected full typecheck type "' + refName + '" to equal pull type "' + pullName + '".');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Check number of navigationItems which match both searchValue and matchKind.
|
||||
Report an error if expected value and actual value do not match.
|
||||
@@ -2047,12 +2013,11 @@ module FourSlash {
|
||||
// The current caret position (in line/col terms)
|
||||
var line = this.getCurrentCaretFilePosition().line;
|
||||
// The line/col of the start of this line
|
||||
var pos = this.languageServiceShimHost.lineColToPosition(this.activeFile.fileName, line, 1);
|
||||
var pos = this.languageServiceAdapterHost.lineColToPosition(this.activeFile.fileName, line, 1);
|
||||
// The index of the current file
|
||||
|
||||
// The text from the start of the line to the end of the file
|
||||
var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
|
||||
var text = snapshot.getText(pos, snapshot.getLength());
|
||||
var text = this.getFileContent(this.activeFile.fileName).substring(pos);
|
||||
|
||||
// Truncate to the first newline
|
||||
var newlinePos = text.indexOf('\n');
|
||||
@@ -2067,13 +2032,8 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
private getCurrentFileContent() {
|
||||
var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
|
||||
return snapshot.getText(0, snapshot.getLength());
|
||||
}
|
||||
|
||||
private getCurrentCaretFilePosition() {
|
||||
var result = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition);
|
||||
var result = this.languageServiceAdapterHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition);
|
||||
if (result.line >= 0) {
|
||||
result.line++;
|
||||
}
|
||||
@@ -2131,8 +2091,10 @@ module FourSlash {
|
||||
}
|
||||
} else if (typeof indexOrName === 'string') {
|
||||
var name = <string>indexOrName;
|
||||
// names are stored in the compiler with this relative path, this allows people to use goTo.file on just the filename
|
||||
name = name.indexOf('/') === -1 ? 'tests/cases/fourslash/' + name : name;
|
||||
|
||||
// names are stored in the compiler with this relative path, this allows people to use goTo.file on just the fileName
|
||||
name = name.indexOf('/') === -1 ? (this.basePath + '/' + name) : name;
|
||||
|
||||
var availableNames: string[] = [];
|
||||
var foundIt = false;
|
||||
for (var i = 0; i < this.testData.files.length; i++) {
|
||||
@@ -2158,7 +2120,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
private getLineColStringAtPosition(position: number) {
|
||||
var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, position);
|
||||
var pos = this.languageServiceAdapterHost.positionToZeroBasedLineCol(this.activeFile.fileName, position);
|
||||
return 'line ' + (pos.line + 1) + ', col ' + pos.character;
|
||||
}
|
||||
|
||||
@@ -2184,39 +2146,47 @@ module FourSlash {
|
||||
originalName: ''
|
||||
};
|
||||
}
|
||||
|
||||
public setCancelled(numberOfCalls: number): void {
|
||||
this.cancellationToken.setCancelled(numberOfCalls)
|
||||
}
|
||||
|
||||
public resetCancelled(): void {
|
||||
this.cancellationToken.resetCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
// TOOD: should these just use the Harness's stdout/stderr?
|
||||
var fsOutput = new Harness.Compiler.WriterAggregator();
|
||||
var fsErrors = new Harness.Compiler.WriterAggregator();
|
||||
export var xmlData: TestXmlData[] = [];
|
||||
export function runFourSlashTest(fileName: string) {
|
||||
export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string) {
|
||||
var content = Harness.IO.readFile(fileName);
|
||||
var xml = runFourSlashTestContent(content, fileName);
|
||||
var xml = runFourSlashTestContent(basePath, testType, content, fileName);
|
||||
xmlData.push(xml);
|
||||
}
|
||||
|
||||
export function runFourSlashTestContent(content: string, fileName: string): TestXmlData {
|
||||
export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): TestXmlData {
|
||||
// Parse out the files and their metadata
|
||||
var testData = parseTestData(content, fileName);
|
||||
var testData = parseTestData(basePath, content, fileName);
|
||||
|
||||
currentTestState = new TestState(testData);
|
||||
currentTestState = new TestState(basePath, testType, testData);
|
||||
|
||||
var result = '';
|
||||
var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFilename, content: undefined },
|
||||
var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined },
|
||||
{ unitName: fileName, content: content }],
|
||||
(fn, contents) => result = contents,
|
||||
ts.ScriptTarget.Latest,
|
||||
ts.sys.useCaseSensitiveFileNames);
|
||||
// TODO (drosen): We need to enforce checking on these tests.
|
||||
var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
|
||||
var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true);
|
||||
var program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
|
||||
|
||||
var errors = program.getDiagnostics().concat(checker.getDiagnostics());
|
||||
if (errors.length > 0) {
|
||||
throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => e.messageText).join('\r\n'));
|
||||
var diagnostics = ts.getPreEmitDiagnostics(program);
|
||||
if (diagnostics.length > 0) {
|
||||
throw new Error('Error compiling ' + fileName + ': ' +
|
||||
diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n'));
|
||||
}
|
||||
program.emitFiles();
|
||||
program.emit();
|
||||
result = result || ''; // Might have an empty fourslash file
|
||||
|
||||
// Compile and execute the test
|
||||
@@ -2243,7 +2213,7 @@ module FourSlash {
|
||||
return lines.map(s => s.substr(1)).join('\n');
|
||||
}
|
||||
|
||||
function parseTestData(contents: string, fileName: string): FourSlashData {
|
||||
function parseTestData(basePath: string, contents: string, fileName: string): FourSlashData {
|
||||
// Regex for parsing options in the format "@Alpha: Value of any sort"
|
||||
var optionRegex = /^\s*@(\w+): (.*)\s*/;
|
||||
|
||||
@@ -2296,8 +2266,8 @@ module FourSlash {
|
||||
if (globalMetadataNamesIndex === -1) {
|
||||
if (fileMetadataNamesIndex === -1) {
|
||||
throw new Error('Unrecognized metadata name "' + match[1] + '". Available global metadata names are: ' + globalMetadataNames.join(', ') + '; file metadata names are: ' + fileMetadataNames.join(', '));
|
||||
} else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(testOptMetadataNames.filename)) {
|
||||
// Found an @Filename directive, if this is not the first then create a new subfile
|
||||
} else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(testOptMetadataNames.fileName)) {
|
||||
// Found an @FileName directive, if this is not the first then create a new subfile
|
||||
if (currentFileContent) {
|
||||
var file = parseFileContent(currentFileContent, currentFileName, markerPositions, markers, ranges);
|
||||
file.fileOptions = currentFileOptions;
|
||||
@@ -2311,7 +2281,7 @@ module FourSlash {
|
||||
currentFileName = fileName;
|
||||
}
|
||||
|
||||
currentFileName = 'tests/cases/fourslash/' + match[2];
|
||||
currentFileName = basePath + '/' + match[2];
|
||||
currentFileOptions[match[1]] = match[2];
|
||||
} else {
|
||||
// Add other fileMetadata flag
|
||||
|
||||
@@ -2,19 +2,35 @@
|
||||
///<reference path='harness.ts'/>
|
||||
///<reference path='runnerbase.ts' />
|
||||
|
||||
class FourslashRunner extends RunnerBase {
|
||||
public basePath = 'tests/cases/fourslash';
|
||||
const enum FourSlashTestType {
|
||||
Native,
|
||||
Shims
|
||||
}
|
||||
|
||||
constructor() {
|
||||
class FourSlashRunner extends RunnerBase {
|
||||
protected basePath: string;
|
||||
protected testSuiteName: string;
|
||||
|
||||
constructor(private testType: FourSlashTestType) {
|
||||
super();
|
||||
switch (testType) {
|
||||
case FourSlashTestType.Native:
|
||||
this.basePath = 'tests/cases/fourslash';
|
||||
this.testSuiteName = 'fourslash';
|
||||
break;
|
||||
case FourSlashTestType.Shims:
|
||||
this.basePath = 'tests/cases/fourslash/shims';
|
||||
this.testSuiteName = 'fourslash-shims';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public initializeTests() {
|
||||
if (this.tests.length === 0) {
|
||||
this.tests = this.enumerateFiles(this.basePath, /\.ts/i);
|
||||
this.tests = this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false });
|
||||
}
|
||||
|
||||
describe("fourslash tests", () => {
|
||||
describe(this.testSuiteName, () => {
|
||||
this.tests.forEach((fn: string) => {
|
||||
fn = ts.normalizeSlashes(fn);
|
||||
var justName = fn.replace(/^.*[\\\/]/, '');
|
||||
@@ -24,8 +40,8 @@ class FourslashRunner extends RunnerBase {
|
||||
if (testIndex >= 0) fn = fn.substr(testIndex);
|
||||
|
||||
if (justName && !justName.match(/fourslash\.ts$/i) && !justName.match(/\.d\.ts$/i)) {
|
||||
it('FourSlash test ' + justName + ' runs correctly', function () {
|
||||
FourSlash.runFourSlashTest(fn);
|
||||
it(this.testSuiteName + ' test ' + justName + ' runs correctly',() => {
|
||||
FourSlash.runFourSlashTest(this.basePath, this.testType, fn);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -82,9 +98,9 @@ class FourslashRunner extends RunnerBase {
|
||||
}
|
||||
}
|
||||
|
||||
class GeneratedFourslashRunner extends FourslashRunner {
|
||||
constructor() {
|
||||
super();
|
||||
class GeneratedFourslashRunner extends FourSlashRunner {
|
||||
constructor(testType: FourSlashTestType) {
|
||||
super(testType);
|
||||
this.basePath += '/generated/';
|
||||
}
|
||||
}
|
||||
+96
-83
@@ -19,6 +19,7 @@
|
||||
/// <reference path='external\mocha.d.ts'/>
|
||||
/// <reference path='external\chai.d.ts'/>
|
||||
/// <reference path='sourceMapRecorder.ts'/>
|
||||
/// <reference path='runnerbase.ts'/>
|
||||
|
||||
declare var require: any;
|
||||
declare var process: any;
|
||||
@@ -52,7 +53,7 @@ module Utils {
|
||||
|
||||
export var currentExecutionEnvironment = getExecutionEnvironment();
|
||||
|
||||
export function evalFile(fileContents: string, filename: string, nodeContext?: any) {
|
||||
export function evalFile(fileContents: string, fileName: string, nodeContext?: any) {
|
||||
var environment = getExecutionEnvironment();
|
||||
switch (environment) {
|
||||
case ExecutionEnvironment.CScript:
|
||||
@@ -62,9 +63,9 @@ module Utils {
|
||||
case ExecutionEnvironment.Node:
|
||||
var vm = require('vm');
|
||||
if (nodeContext) {
|
||||
vm.runInNewContext(fileContents, nodeContext, filename);
|
||||
vm.runInNewContext(fileContents, nodeContext, fileName);
|
||||
} else {
|
||||
vm.runInThisContext(fileContents, filename);
|
||||
vm.runInThisContext(fileContents, fileName);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -183,7 +184,7 @@ module Utils {
|
||||
return {
|
||||
start: diagnostic.start,
|
||||
length: diagnostic.length,
|
||||
messageText: diagnostic.messageText,
|
||||
messageText: ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine),
|
||||
category: (<any>ts).DiagnosticCategory[diagnostic.category],
|
||||
code: diagnostic.code
|
||||
};
|
||||
@@ -305,7 +306,9 @@ module Utils {
|
||||
|
||||
assert.equal(d1.start, d2.start, "d1.start !== d2.start");
|
||||
assert.equal(d1.length, d2.length, "d1.length !== d2.length");
|
||||
assert.equal(d1.messageText, d2.messageText, "d1.messageText !== d2.messageText");
|
||||
assert.equal(
|
||||
ts.flattenDiagnosticMessageText(d1.messageText, ts.sys.newLine),
|
||||
ts.flattenDiagnosticMessageText(d2.messageText, ts.sys.newLine), "d1.messageText !== d2.messageText");
|
||||
assert.equal(d1.category, d2.category, "d1.category !== d2.category");
|
||||
assert.equal(d1.code, d2.code, "d1.code !== d2.code");
|
||||
}
|
||||
@@ -389,9 +392,9 @@ module Harness {
|
||||
writeFile(path: string, contents: string): void;
|
||||
directoryName(path: string): string;
|
||||
createDirectory(path: string): void;
|
||||
fileExists(filename: string): boolean;
|
||||
fileExists(fileName: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
deleteFile(filename: string): void;
|
||||
deleteFile(fileName: string): void;
|
||||
listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[];
|
||||
log(text: string): void;
|
||||
getMemoryUsage? (): number;
|
||||
@@ -621,7 +624,7 @@ module Harness {
|
||||
// root of the server
|
||||
if (dirPath.match(/localhost:\d+$/) || dirPath.match(/localhost:\d+\/$/)) {
|
||||
dirPath = null;
|
||||
// path + filename
|
||||
// path + fileName
|
||||
} else if (dirPath.indexOf('.') === -1) {
|
||||
dirPath = dirPath.substring(0, dirPath.lastIndexOf('/'));
|
||||
// path
|
||||
@@ -689,29 +692,27 @@ module Harness {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
module Harness {
|
||||
var tcServicesFilename = "typescriptServices.js";
|
||||
var tcServicesFileName = "typescriptServices.js";
|
||||
|
||||
export var libFolder: string;
|
||||
switch (Utils.getExecutionEnvironment()) {
|
||||
case Utils.ExecutionEnvironment.CScript:
|
||||
libFolder = "built/local/";
|
||||
tcServicesFilename = "built/local/typescriptServices.js";
|
||||
tcServicesFileName = "built/local/typescriptServices.js";
|
||||
break;
|
||||
case Utils.ExecutionEnvironment.Node:
|
||||
libFolder = "built/local/";
|
||||
tcServicesFilename = "built/local/typescriptServices.js";
|
||||
tcServicesFileName = "built/local/typescriptServices.js";
|
||||
break;
|
||||
case Utils.ExecutionEnvironment.Browser:
|
||||
libFolder = "built/local/";
|
||||
tcServicesFilename = "built/local/typescriptServices.js";
|
||||
tcServicesFileName = "built/local/typescriptServices.js";
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown context');
|
||||
}
|
||||
export var tcServicesFile = IO.readFile(tcServicesFilename);
|
||||
export var tcServicesFile = IO.readFile(tcServicesFileName);
|
||||
|
||||
export interface SourceMapEmitterCallback {
|
||||
(emittedFile: string, emittedLine: number, emittedColumn: number, sourceFile: string, sourceLine: number, sourceColumn: number, sourceName: string): void;
|
||||
@@ -794,13 +795,21 @@ module Harness {
|
||||
}
|
||||
}
|
||||
|
||||
export var defaultLibFileName = 'lib.d.ts';
|
||||
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
|
||||
export var defaultES6LibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
|
||||
export function createSourceFileAndAssertInvariants(fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, assertInvariants = true) {
|
||||
// Only set the parent nodes if we're asserting invariants. We don't need them otherwise.
|
||||
var result = ts.createSourceFile(fileName, sourceText, languageVersion, /*setParentNodes:*/ assertInvariants);
|
||||
if (assertInvariants) {
|
||||
Utils.assertInvariants(result, /*parent:*/ undefined);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export var defaultLibFileName = 'lib.d.ts';
|
||||
export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
|
||||
export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
|
||||
|
||||
// Cache these between executions so we don't have to re-parse them for every test
|
||||
export var fourslashFilename = 'fourslash.ts';
|
||||
export var fourslashFileName = 'fourslash.ts';
|
||||
export var fourslashSourceFile: ts.SourceFile;
|
||||
|
||||
export function getCanonicalFileName(fileName: string): string {
|
||||
@@ -819,14 +828,14 @@ module Harness {
|
||||
return useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
var filemap: { [filename: string]: ts.SourceFile; } = {};
|
||||
var filemap: { [fileName: string]: ts.SourceFile; } = {};
|
||||
var getCurrentDirectory = currentDirectory === undefined ? ts.sys.getCurrentDirectory : () => currentDirectory;
|
||||
|
||||
// Register input files
|
||||
function register(file: { unitName: string; content: string; }) {
|
||||
if (file.content !== undefined) {
|
||||
var filename = ts.normalizeSlashes(file.unitName);
|
||||
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, scriptTarget);
|
||||
var fileName = ts.normalizeSlashes(file.unitName);
|
||||
filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget);
|
||||
}
|
||||
};
|
||||
inputFiles.forEach(register);
|
||||
@@ -841,9 +850,9 @@ module Harness {
|
||||
var canonicalAbsolutePath = getCanonicalFileName(ts.getNormalizedAbsolutePath(fn, currentDirectory));
|
||||
return Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(canonicalAbsolutePath)) ? filemap[canonicalAbsolutePath] : undefined;
|
||||
}
|
||||
else if (fn === fourslashFilename) {
|
||||
var tsFn = 'tests/cases/fourslash/' + fourslashFilename;
|
||||
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), scriptTarget);
|
||||
else if (fn === fourslashFileName) {
|
||||
var tsFn = 'tests/cases/fourslash/' + fourslashFileName;
|
||||
fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget);
|
||||
return fourslashSourceFile;
|
||||
}
|
||||
else {
|
||||
@@ -854,7 +863,7 @@ module Harness {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
getDefaultLibFilename: options => defaultLibFileName,
|
||||
getDefaultLibFileName: options => defaultLibFileName,
|
||||
writeFile,
|
||||
getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
|
||||
@@ -919,7 +928,8 @@ module Harness {
|
||||
settingsCallback?: (settings: ts.CompilerOptions) => void,
|
||||
options?: ts.CompilerOptions,
|
||||
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
|
||||
currentDirectory?: string) {
|
||||
currentDirectory?: string,
|
||||
assertInvariants = true) {
|
||||
|
||||
options = options || { noResolve: false };
|
||||
options.target = options.target || ts.ScriptTarget.ES3;
|
||||
@@ -935,7 +945,7 @@ module Harness {
|
||||
var useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
|
||||
this.settings.forEach(setting => {
|
||||
switch (setting.flag.toLowerCase()) {
|
||||
// "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve"
|
||||
// "fileName", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve"
|
||||
case "module":
|
||||
case "modulegentarget":
|
||||
if (typeof setting.value === 'string') {
|
||||
@@ -1066,38 +1076,30 @@ module Harness {
|
||||
var filemap: { [name: string]: ts.SourceFile; } = {};
|
||||
var register = (file: { unitName: string; content: string; }) => {
|
||||
if (file.content !== undefined) {
|
||||
var filename = ts.normalizeSlashes(file.unitName);
|
||||
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target);
|
||||
var fileName = ts.normalizeSlashes(file.unitName);
|
||||
filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, options.target, assertInvariants);
|
||||
}
|
||||
};
|
||||
inputFiles.forEach(register);
|
||||
otherFiles.forEach(register);
|
||||
|
||||
var fileOutputs: GeneratedFile[] = [];
|
||||
|
||||
|
||||
var programFiles = inputFiles.map(file => file.unitName);
|
||||
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(otherFiles),
|
||||
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
|
||||
options.target, useCaseSensitiveFileNames, currentDirectory));
|
||||
|
||||
var checker = program.getTypeChecker(/*produceDiagnostics*/ true);
|
||||
|
||||
var isEmitBlocked = program.isEmitBlocked();
|
||||
|
||||
// only emit if there weren't parse errors
|
||||
var emitResult: ts.EmitResult;
|
||||
if (!isEmitBlocked) {
|
||||
emitResult = program.emitFiles();
|
||||
}
|
||||
var emitResult = program.emit();
|
||||
|
||||
var errors: HarnessDiagnostic[] = [];
|
||||
program.getDiagnostics().concat(checker.getDiagnostics()).concat(emitResult ? emitResult.diagnostics : []).forEach(err => {
|
||||
ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => {
|
||||
// TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now
|
||||
errors.push(getMinimalDiagnostic(err));
|
||||
});
|
||||
this.lastErrors = errors;
|
||||
|
||||
var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined);
|
||||
var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps);
|
||||
onComplete(result, program);
|
||||
|
||||
// reset what newline means in case the last test changed it
|
||||
@@ -1148,12 +1150,12 @@ module Harness {
|
||||
var sourceFileName: string;
|
||||
if (ts.isExternalModule(sourceFile) || !options.out) {
|
||||
if (options.outDir) {
|
||||
var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, result.currentDirectoryForProgram);
|
||||
var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, result.currentDirectoryForProgram);
|
||||
sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), "");
|
||||
sourceFileName = ts.combinePaths(options.outDir, sourceFilePath);
|
||||
}
|
||||
else {
|
||||
sourceFileName = sourceFile.filename;
|
||||
sourceFileName = sourceFile.fileName;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1184,12 +1186,12 @@ module Harness {
|
||||
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
|
||||
var errorLineInfo = err.file ? err.file.getLineAndCharacterFromPosition(err.start) : { line: 0, character: 0 };
|
||||
return {
|
||||
filename: err.file && err.file.filename,
|
||||
fileName: err.file && err.file.fileName,
|
||||
start: err.start,
|
||||
end: err.start + err.length,
|
||||
line: errorLineInfo.line,
|
||||
character: errorLineInfo.character,
|
||||
message: err.messageText,
|
||||
message: ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine),
|
||||
category: ts.DiagnosticCategory[err.category].toLowerCase(),
|
||||
code: err.code
|
||||
};
|
||||
@@ -1199,8 +1201,8 @@ module Harness {
|
||||
// This is basically copied from tsc.ts's reportError to replicate what tsc does
|
||||
var errorOutput = "";
|
||||
ts.forEach(diagnostics, diagnotic => {
|
||||
if (diagnotic.filename) {
|
||||
errorOutput += diagnotic.filename + "(" + diagnotic.line + "," + diagnotic.character + "): ";
|
||||
if (diagnotic.fileName) {
|
||||
errorOutput += diagnotic.fileName + "(" + diagnotic.line + "," + diagnotic.character + "): ";
|
||||
}
|
||||
|
||||
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + ts.sys.newLine;
|
||||
@@ -1210,7 +1212,7 @@ module Harness {
|
||||
}
|
||||
|
||||
function compareDiagnostics(d1: HarnessDiagnostic, d2: HarnessDiagnostic) {
|
||||
return ts.compareValues(d1.filename, d2.filename) ||
|
||||
return ts.compareValues(d1.fileName, d2.fileName) ||
|
||||
ts.compareValues(d1.start, d2.start) ||
|
||||
ts.compareValues(d1.end, d2.end) ||
|
||||
ts.compareValues(d1.code, d2.code) ||
|
||||
@@ -1236,14 +1238,14 @@ module Harness {
|
||||
}
|
||||
|
||||
// Report global errors
|
||||
var globalErrors = diagnostics.filter(err => !err.filename);
|
||||
var globalErrors = diagnostics.filter(err => !err.fileName);
|
||||
globalErrors.forEach(outputErrorText);
|
||||
|
||||
// 'merge' the lines of each input file with any errors associated with it
|
||||
inputFiles.filter(f => f.content !== undefined).forEach(inputFile => {
|
||||
// Filter down to the errors in the file
|
||||
var fileErrors = diagnostics.filter(e => {
|
||||
var errFn = e.filename;
|
||||
var errFn = e.fileName;
|
||||
return errFn && errFn === inputFile.unitName;
|
||||
});
|
||||
|
||||
@@ -1307,12 +1309,12 @@ module Harness {
|
||||
});
|
||||
|
||||
var numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => {
|
||||
return diagnostic.filename && isLibraryFile(diagnostic.filename);
|
||||
return diagnostic.fileName && isLibraryFile(diagnostic.fileName);
|
||||
});
|
||||
|
||||
var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => {
|
||||
// Count an error generated from tests262-harness folder.This should only apply for test262
|
||||
return diagnostic.filename && diagnostic.filename.indexOf("test262-harness") >= 0;
|
||||
return diagnostic.fileName && diagnostic.fileName.indexOf("test262-harness") >= 0;
|
||||
});
|
||||
|
||||
// Verify we didn't miss any errors in total
|
||||
@@ -1323,7 +1325,7 @@ module Harness {
|
||||
}
|
||||
|
||||
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
|
||||
// Collect, test, and sort the filenames
|
||||
// Collect, test, and sort the fileNames
|
||||
function cleanName(fn: string) {
|
||||
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');
|
||||
return fn.substr(lastSlash + 1).toLowerCase();
|
||||
@@ -1336,7 +1338,7 @@ module Harness {
|
||||
// Some extra spacing if this isn't the first file
|
||||
if (result.length) result = result + '\r\n\r\n';
|
||||
|
||||
// Filename header + content
|
||||
// FileName header + content
|
||||
result = result + '/*====== ' + outputFile.fileName + ' ======*/\r\n';
|
||||
if (clean) {
|
||||
result = result + clean(outputFile.code);
|
||||
@@ -1366,7 +1368,7 @@ module Harness {
|
||||
}
|
||||
|
||||
export interface HarnessDiagnostic {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
start: number;
|
||||
end: number;
|
||||
line: number;
|
||||
@@ -1481,7 +1483,7 @@ module Harness {
|
||||
return opts;
|
||||
}
|
||||
|
||||
/** Given a test file containing // @Filename directives, return an array of named units of code to be added to an existing compiler instance */
|
||||
/** Given a test file containing // @FileName directives, return an array of named units of code to be added to an existing compiler instance */
|
||||
export function makeUnitsFromTest(code: string, fileName: string): { settings: CompilerSetting[]; testUnitData: TestUnitData[]; } {
|
||||
var settings = extractCompilerSettings(code);
|
||||
|
||||
@@ -1569,26 +1571,37 @@ module Harness {
|
||||
export interface BaselineOptions {
|
||||
LineEndingSensitive?: boolean;
|
||||
Subfolder?: string;
|
||||
Baselinefolder?: string;
|
||||
}
|
||||
|
||||
export function localPath(fileName: string, subfolder?: string) {
|
||||
return baselinePath(fileName, 'local', subfolder);
|
||||
export function localPath(fileName: string, baselineFolder?: string, subfolder?: string) {
|
||||
if (baselineFolder === undefined) {
|
||||
return baselinePath(fileName, 'local', 'tests/baselines', subfolder);
|
||||
}
|
||||
else {
|
||||
return baselinePath(fileName, 'local', baselineFolder, subfolder);
|
||||
}
|
||||
}
|
||||
|
||||
function referencePath(fileName: string, subfolder?: string) {
|
||||
return baselinePath(fileName, 'reference', subfolder);
|
||||
function referencePath(fileName: string, baselineFolder?: string, subfolder?: string) {
|
||||
if (baselineFolder === undefined) {
|
||||
return baselinePath(fileName, 'reference', 'tests/baselines', subfolder);
|
||||
}
|
||||
else {
|
||||
return baselinePath(fileName, 'reference', baselineFolder, subfolder);
|
||||
}
|
||||
}
|
||||
|
||||
function baselinePath(fileName: string, type: string, subfolder?: string) {
|
||||
function baselinePath(fileName: string, type: string, baselineFolder: string, subfolder?: string) {
|
||||
if (subfolder !== undefined) {
|
||||
return Harness.userSpecifiedroot + 'tests/baselines/' + subfolder + '/' + type + '/' + fileName;
|
||||
return Harness.userSpecifiedroot + baselineFolder + '/' + subfolder + '/' + type + '/' + fileName;
|
||||
} else {
|
||||
return Harness.userSpecifiedroot + 'tests/baselines/' + type + '/' + fileName;
|
||||
return Harness.userSpecifiedroot + baselineFolder + '/' + type + '/' + fileName;
|
||||
}
|
||||
}
|
||||
|
||||
var fileCache: { [idx: string]: boolean } = {};
|
||||
function generateActual(actualFilename: string, generateContent: () => string): string {
|
||||
function generateActual(actualFileName: string, generateContent: () => string): string {
|
||||
// For now this is written using TypeScript, because sys is not available when running old test cases.
|
||||
// But we need to move to sys once we have
|
||||
// Creates the directory including its parent if not already present
|
||||
@@ -1607,11 +1620,11 @@ module Harness {
|
||||
}
|
||||
|
||||
// Create folders if needed
|
||||
createDirectoryStructure(Harness.IO.directoryName(actualFilename));
|
||||
createDirectoryStructure(Harness.IO.directoryName(actualFileName));
|
||||
|
||||
// Delete the actual file in case it fails
|
||||
if (IO.fileExists(actualFilename)) {
|
||||
IO.deleteFile(actualFilename);
|
||||
if (IO.fileExists(actualFileName)) {
|
||||
IO.deleteFile(actualFileName);
|
||||
}
|
||||
|
||||
var actual = generateContent();
|
||||
@@ -1623,13 +1636,13 @@ module Harness {
|
||||
// Store the content in the 'local' folder so we
|
||||
// can accept it later (manually)
|
||||
if (actual !== null) {
|
||||
IO.writeFile(actualFilename, actual);
|
||||
IO.writeFile(actualFileName, actual);
|
||||
}
|
||||
|
||||
return actual;
|
||||
}
|
||||
|
||||
function compareToBaseline(actual: string, relativeFilename: string, opts: BaselineOptions) {
|
||||
function compareToBaseline(actual: string, relativeFileName: string, opts: BaselineOptions) {
|
||||
// actual is now either undefined (the generator had an error), null (no file requested),
|
||||
// or some real output of the function
|
||||
if (actual === undefined) {
|
||||
@@ -1637,15 +1650,15 @@ module Harness {
|
||||
return;
|
||||
}
|
||||
|
||||
var refFilename = referencePath(relativeFilename, opts && opts.Subfolder);
|
||||
var refFileName = referencePath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);
|
||||
|
||||
if (actual === null) {
|
||||
actual = '<no content>';
|
||||
}
|
||||
|
||||
var expected = '<no content>';
|
||||
if (IO.fileExists(refFilename)) {
|
||||
expected = IO.readFile(refFilename);
|
||||
if (IO.fileExists(refFileName)) {
|
||||
expected = IO.readFile(refFileName);
|
||||
}
|
||||
|
||||
var lineEndingSensitive = opts && opts.LineEndingSensitive;
|
||||
@@ -1658,34 +1671,34 @@ module Harness {
|
||||
return { expected, actual };
|
||||
}
|
||||
|
||||
function writeComparison(expected: string, actual: string, relativeFilename: string, actualFilename: string, descriptionForDescribe: string) {
|
||||
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) {
|
||||
var encoded_actual = (new Buffer(actual)).toString('utf8')
|
||||
if (expected != encoded_actual) {
|
||||
// Overwrite & issue error
|
||||
var errMsg = 'The baseline file ' + relativeFilename + ' has changed';
|
||||
var errMsg = 'The baseline file ' + relativeFileName + ' has changed';
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
export function runBaseline(
|
||||
descriptionForDescribe: string,
|
||||
relativeFilename: string,
|
||||
relativeFileName: string,
|
||||
generateContent: () => string,
|
||||
runImmediately = false,
|
||||
opts?: BaselineOptions): void {
|
||||
|
||||
var actual = <string>undefined;
|
||||
var actualFilename = localPath(relativeFilename, opts && opts.Subfolder);
|
||||
var actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);
|
||||
|
||||
if (runImmediately) {
|
||||
actual = generateActual(actualFilename, generateContent);
|
||||
var comparison = compareToBaseline(actual, relativeFilename, opts);
|
||||
writeComparison(comparison.expected, comparison.actual, relativeFilename, actualFilename, descriptionForDescribe);
|
||||
actual = generateActual(actualFileName, generateContent);
|
||||
var comparison = compareToBaseline(actual, relativeFileName, opts);
|
||||
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName, descriptionForDescribe);
|
||||
} else {
|
||||
actual = generateActual(actualFilename, generateContent);
|
||||
actual = generateActual(actualFileName, generateContent);
|
||||
|
||||
var comparison = compareToBaseline(actual, relativeFilename, opts);
|
||||
writeComparison(comparison.expected, comparison.actual, relativeFilename, actualFilename, descriptionForDescribe);
|
||||
var comparison = compareToBaseline(actual, relativeFileName, opts);
|
||||
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName, descriptionForDescribe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path='..\services\services.ts' />
|
||||
/// <reference path='..\services\shims.ts' />
|
||||
/// <reference path='harness.ts' />
|
||||
|
||||
module Harness.LanguageService {
|
||||
export class ScriptInfo {
|
||||
@@ -54,12 +55,11 @@ module Harness.LanguageService {
|
||||
}
|
||||
}
|
||||
|
||||
class ScriptSnapshotShim implements ts.ScriptSnapshotShim {
|
||||
private lineMap: number[] = null;
|
||||
private textSnapshot: string;
|
||||
private version: number;
|
||||
class ScriptSnapshot implements ts.IScriptSnapshot {
|
||||
public textSnapshot: string;
|
||||
public version: number;
|
||||
|
||||
constructor(private scriptInfo: ScriptInfo) {
|
||||
constructor(public scriptInfo: ScriptInfo) {
|
||||
this.textSnapshot = scriptInfo.content;
|
||||
this.version = scriptInfo.version;
|
||||
}
|
||||
@@ -72,9 +72,28 @@ module Harness.LanguageService {
|
||||
return this.textSnapshot.length;
|
||||
}
|
||||
|
||||
public getChangeRange(oldScript: ts.IScriptSnapshot): ts.TextChangeRange {
|
||||
var oldShim = <ScriptSnapshot>oldScript;
|
||||
return this.scriptInfo.getTextChangeRangeBetweenVersions(oldShim.version, this.version);
|
||||
}
|
||||
}
|
||||
|
||||
class ScriptSnapshotProxy implements ts.ScriptSnapshotShim {
|
||||
constructor(public scriptSnapshot: ts.IScriptSnapshot) {
|
||||
}
|
||||
|
||||
public getText(start: number, end: number): string {
|
||||
return this.scriptSnapshot.getText(start, end);
|
||||
}
|
||||
|
||||
public getLength(): number {
|
||||
return this.scriptSnapshot.getLength();
|
||||
}
|
||||
|
||||
public getChangeRange(oldScript: ts.ScriptSnapshotShim): string {
|
||||
var oldShim = <ScriptSnapshotShim>oldScript;
|
||||
var range = this.scriptInfo.getTextChangeRangeBetweenVersions(oldShim.version, this.version);
|
||||
var oldShim = <ScriptSnapshotProxy>oldScript;
|
||||
|
||||
var range = this.scriptSnapshot.getChangeRange(oldShim.scriptSnapshot);
|
||||
if (range === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -94,71 +113,38 @@ module Harness.LanguageService {
|
||||
}
|
||||
}
|
||||
|
||||
export class NonCachingDocumentRegistry implements ts.DocumentRegistry {
|
||||
public static Instance: ts.DocumentRegistry = new NonCachingDocumentRegistry();
|
||||
|
||||
public acquireDocument(
|
||||
fileName: string,
|
||||
compilationSettings: ts.CompilerOptions,
|
||||
scriptSnapshot: ts.IScriptSnapshot,
|
||||
version: string): ts.SourceFile {
|
||||
var sourceFile = ts.createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), compilationSettings.target);
|
||||
sourceFile.version = version;
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
public updateDocument(
|
||||
document: ts.SourceFile,
|
||||
fileName: string,
|
||||
compilationSettings: ts.CompilerOptions,
|
||||
scriptSnapshot: ts.IScriptSnapshot,
|
||||
version: string,
|
||||
textChangeRange: ts.TextChangeRange
|
||||
): ts.SourceFile {
|
||||
return ts.updateLanguageServiceSourceFile(document, scriptSnapshot, version, textChangeRange);
|
||||
}
|
||||
|
||||
public releaseDocument(fileName: string, compilationSettings: ts.CompilerOptions): void {
|
||||
// no op since this class doesn't cache anything
|
||||
}
|
||||
export interface LanguageServiceAdapter {
|
||||
getHost(): LanguageServiceAdapterHost;
|
||||
getLanguageService(): ts.LanguageService;
|
||||
getClassifier(): ts.Classifier;
|
||||
getPreProcessedFileInfo(fileName: string, fileContents: string): ts.PreProcessedFileInfo;
|
||||
}
|
||||
export class TypeScriptLS implements ts.LanguageServiceShimHost {
|
||||
private ls: ts.LanguageServiceShim = null;
|
||||
|
||||
private fileNameToScript: ts.Map<ScriptInfo> = {};
|
||||
private settings: ts.CompilerOptions = {};
|
||||
|
||||
constructor(private cancellationToken: ts.CancellationToken = CancellationToken.None) {
|
||||
export class LanguageServiceAdapterHost {
|
||||
protected fileNameToScript: ts.Map<ScriptInfo> = {};
|
||||
|
||||
constructor(protected cancellationToken: ts.CancellationToken = CancellationToken.None,
|
||||
protected settings = ts.getDefaultCompilerOptions()) {
|
||||
}
|
||||
|
||||
public trace(s: string) {
|
||||
public getNewLine(): string {
|
||||
return "\r\n";
|
||||
}
|
||||
|
||||
public addDefaultLibrary() {
|
||||
this.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
|
||||
public getFilenames(): string[] {
|
||||
var fileNames: string[] = [];
|
||||
ts.forEachKey(this.fileNameToScript,(fileName) => { fileNames.push(fileName); });
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
public getHostIdentifier(): string {
|
||||
return "TypeScriptLS";
|
||||
}
|
||||
|
||||
public addFile(fileName: string) {
|
||||
var code = Harness.IO.readFile(fileName);
|
||||
this.addScript(fileName, code);
|
||||
}
|
||||
|
||||
private getScriptInfo(fileName: string): ScriptInfo {
|
||||
public getScriptInfo(fileName: string): ScriptInfo {
|
||||
return ts.lookUp(this.fileNameToScript, fileName);
|
||||
}
|
||||
|
||||
public addScript(fileName: string, content: string) {
|
||||
public addScript(fileName: string, content: string): void {
|
||||
this.fileNameToScript[fileName] = new ScriptInfo(fileName, content);
|
||||
}
|
||||
|
||||
private contains(fileName: string): boolean {
|
||||
return ts.hasProperty(this.fileNameToScript, fileName);
|
||||
}
|
||||
|
||||
public updateScript(fileName: string, content: string) {
|
||||
var script = this.getScriptInfo(fileName);
|
||||
if (script !== null) {
|
||||
@@ -179,107 +165,10 @@ module Harness.LanguageService {
|
||||
throw new Error("No script with name '" + fileName + "'");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ILogger implementation
|
||||
//
|
||||
public information(): boolean { return false; }
|
||||
public debug(): boolean { return true; }
|
||||
public warning(): boolean { return true; }
|
||||
public error(): boolean { return true; }
|
||||
public fatal(): boolean { return true; }
|
||||
|
||||
public log(s: string): void {
|
||||
// For debugging...
|
||||
//TypeScript.Environment.standardOut.WriteLine("TypeScriptLS:" + s);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// LanguageServiceShimHost implementation
|
||||
//
|
||||
|
||||
/// Returns json for Tools.CompilationSettings
|
||||
public getCompilationSettings(): string {
|
||||
return JSON.stringify(this.settings);
|
||||
}
|
||||
|
||||
public getCancellationToken(): ts.CancellationToken {
|
||||
return this.cancellationToken;
|
||||
}
|
||||
|
||||
public getCurrentDirectory(): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
public getDefaultLibFilename(): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
public getScriptFileNames(): string {
|
||||
var fileNames: string[] = [];
|
||||
ts.forEachKey(this.fileNameToScript,(fileName) => { fileNames.push(fileName); });
|
||||
return JSON.stringify(fileNames);
|
||||
}
|
||||
|
||||
public getScriptSnapshot(fileName: string): ts.ScriptSnapshotShim {
|
||||
if (this.contains(fileName)) {
|
||||
return new ScriptSnapshotShim(this.getScriptInfo(fileName));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getScriptVersion(fileName: string): string {
|
||||
if (this.contains(fileName)) {
|
||||
return this.getScriptInfo(fileName).version.toString();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getLocalizedDiagnosticMessages(): string {
|
||||
return JSON.stringify({});
|
||||
}
|
||||
|
||||
/** Return a new instance of the language service shim, up-to-date wrt to typecheck.
|
||||
* To access the non-shim (i.e. actual) language service, use the "ls.languageService" property.
|
||||
*/
|
||||
public getLanguageService(): ts.LanguageServiceShim {
|
||||
this.ls = new TypeScript.Services.TypeScriptServicesFactory().createLanguageServiceShim(this);
|
||||
return this.ls;
|
||||
}
|
||||
|
||||
public setCompilationSettings(settings: ts.CompilerOptions) {
|
||||
for (var key in settings) {
|
||||
if (settings.hasOwnProperty(key)) {
|
||||
this.settings[key] = settings[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Return a new instance of the classifier service shim */
|
||||
public getClassifier(): ts.ClassifierShim {
|
||||
return new TypeScript.Services.TypeScriptServicesFactory().createClassifierShim(this);
|
||||
}
|
||||
|
||||
public getCoreService(): ts.CoreServicesShim {
|
||||
return new TypeScript.Services.TypeScriptServicesFactory().createCoreServicesShim(this);
|
||||
}
|
||||
|
||||
/** Parse file given its source text */
|
||||
public parseSourceText(fileName: string, sourceText: ts.IScriptSnapshot): ts.SourceFile {
|
||||
var result = ts.createSourceFile(fileName, sourceText.getText(0, sourceText.getLength()), ts.ScriptTarget.Latest);
|
||||
result.version = "1";
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Parse a file on disk given its fileName */
|
||||
public parseFile(fileName: string) {
|
||||
var sourceText = ts.ScriptSnapshot.fromString(Harness.IO.readFile(fileName));
|
||||
return this.parseSourceText(fileName, sourceText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line 1 based index
|
||||
* @param col 1 based index
|
||||
*/
|
||||
* @param line 1 based index
|
||||
* @param col 1 based index
|
||||
*/
|
||||
public lineColToPosition(fileName: string, line: number, col: number): number {
|
||||
var script: ScriptInfo = this.fileNameToScript[fileName];
|
||||
assert.isNotNull(script);
|
||||
@@ -290,9 +179,9 @@ module Harness.LanguageService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line 0 based index
|
||||
* @param col 0 based index
|
||||
*/
|
||||
* @param line 0 based index
|
||||
* @param col 0 based index
|
||||
*/
|
||||
public positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter {
|
||||
var script: ScriptInfo = this.fileNameToScript[fileName];
|
||||
assert.isNotNull(script);
|
||||
@@ -303,105 +192,254 @@ module Harness.LanguageService {
|
||||
assert.isTrue(result.character >= 1);
|
||||
return { line: result.line - 1, character: result.character - 1 };
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify that applying edits to sourceFileName result in the content of the file baselineFileName */
|
||||
public checkEdits(sourceFileName: string, baselineFileName: string, edits: ts.TextChange[]) {
|
||||
var script = Harness.IO.readFile(sourceFileName);
|
||||
var formattedScript = this.applyEdits(script, edits);
|
||||
var baseline = Harness.IO.readFile(baselineFileName);
|
||||
/// Native adapter
|
||||
class NativeLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceHost {
|
||||
getCompilationSettings(): ts.CompilerOptions { return this.settings; }
|
||||
getCancellationToken(): ts.CancellationToken { return this.cancellationToken; }
|
||||
getCurrentDirectory(): string { return ""; }
|
||||
getDefaultLibFileName(): string { return ""; }
|
||||
getScriptFileNames(): string[] { return this.getFilenames(); }
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
|
||||
var script = this.getScriptInfo(fileName);
|
||||
return script ? new ScriptSnapshot(script) : undefined;
|
||||
}
|
||||
getScriptVersion(fileName: string): string {
|
||||
var script = this.getScriptInfo(fileName);
|
||||
return script ? script.version.toString() : undefined;
|
||||
}
|
||||
log(s: string): void { }
|
||||
trace(s: string): void { }
|
||||
error(s: string): void { }
|
||||
}
|
||||
|
||||
function noDiff(text1: string, text2: string) {
|
||||
text1 = text1.replace(/^\s+|\s+$/g, "").replace(/\r\n?/g, "\n");
|
||||
text2 = text2.replace(/^\s+|\s+$/g, "").replace(/\r\n?/g, "\n");
|
||||
export class NativeLanugageServiceAdapter implements LanguageServiceAdapter {
|
||||
private host: NativeLanguageServiceHost;
|
||||
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
|
||||
this.host = new NativeLanguageServiceHost(cancellationToken, options);
|
||||
}
|
||||
getHost() { return this.host; }
|
||||
getLanguageService(): ts.LanguageService { return ts.createLanguageService(this.host); }
|
||||
getClassifier(): ts.Classifier { return ts.createClassifier(); }
|
||||
getPreProcessedFileInfo(fileName: string, fileContents: string): ts.PreProcessedFileInfo { return ts.preProcessFile(fileContents); }
|
||||
}
|
||||
|
||||
if (text1 !== text2) {
|
||||
var errorString = "";
|
||||
var text1Lines = text1.split(/\n/);
|
||||
var text2Lines = text2.split(/\n/);
|
||||
for (var i = 0; i < text1Lines.length; i++) {
|
||||
if (text1Lines[i] !== text2Lines[i]) {
|
||||
errorString += "Difference at line " + (i + 1) + ":\n";
|
||||
errorString += " Left File: " + text1Lines[i] + "\n";
|
||||
errorString += " Right File: " + text2Lines[i] + "\n\n";
|
||||
}
|
||||
}
|
||||
throw (new Error(errorString));
|
||||
}
|
||||
}
|
||||
assert.isTrue(noDiff(formattedScript, baseline));
|
||||
assert.equal(formattedScript, baseline);
|
||||
/// Shim adapter
|
||||
class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost {
|
||||
private nativeHost: NativeLanguageServiceHost;
|
||||
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
|
||||
super(cancellationToken, options);
|
||||
this.nativeHost = new NativeLanguageServiceHost(cancellationToken, options);
|
||||
}
|
||||
|
||||
getFilenames(): string[] { return this.nativeHost.getFilenames(); }
|
||||
getScriptInfo(fileName: string): ScriptInfo { return this.nativeHost.getScriptInfo(fileName); }
|
||||
addScript(fileName: string, content: string): void { this.nativeHost.addScript(fileName, content); }
|
||||
updateScript(fileName: string, content: string): void { return this.nativeHost.updateScript(fileName, content); }
|
||||
editScript(fileName: string, minChar: number, limChar: number, newText: string): void { this.nativeHost.editScript(fileName, minChar, limChar, newText); }
|
||||
lineColToPosition(fileName: string, line: number, col: number): number { return this.nativeHost.lineColToPosition(fileName, line, col); }
|
||||
positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineCol(fileName, position); }
|
||||
|
||||
/** Apply an array of text edits to a string, and return the resulting string. */
|
||||
public applyEdits(content: string, edits: ts.TextChange[]): string {
|
||||
var result = content;
|
||||
edits = this.normalizeEdits(edits);
|
||||
|
||||
for (var i = edits.length - 1; i >= 0; i--) {
|
||||
var edit = edits[i];
|
||||
var prefix = result.substring(0, edit.span.start);
|
||||
var middle = edit.newText;
|
||||
var suffix = result.substring(ts.textSpanEnd(edit.span));
|
||||
result = prefix + middle + suffix;
|
||||
}
|
||||
return result;
|
||||
getCompilationSettings(): string { return JSON.stringify(this.nativeHost.getCompilationSettings()); }
|
||||
getCancellationToken(): ts.CancellationToken { return this.nativeHost.getCancellationToken(); }
|
||||
getCurrentDirectory(): string { return this.nativeHost.getCurrentDirectory(); }
|
||||
getDefaultLibFileName(): string { return this.nativeHost.getDefaultLibFileName(); }
|
||||
getScriptFileNames(): string { return JSON.stringify(this.nativeHost.getScriptFileNames()); }
|
||||
getScriptSnapshot(fileName: string): ts.ScriptSnapshotShim {
|
||||
var nativeScriptSnapshot = this.nativeHost.getScriptSnapshot(fileName);
|
||||
return nativeScriptSnapshot && new ScriptSnapshotProxy(nativeScriptSnapshot);
|
||||
}
|
||||
getScriptVersion(fileName: string): string { return this.nativeHost.getScriptVersion(fileName); }
|
||||
getLocalizedDiagnosticMessages(): string { return JSON.stringify({}); }
|
||||
log(s: string): void { this.nativeHost.log(s); }
|
||||
trace(s: string): void { this.nativeHost.trace(s); }
|
||||
error(s: string): void { this.nativeHost.error(s); }
|
||||
}
|
||||
|
||||
/** Normalize an array of edits by removing overlapping entries and sorting entries on the minChar position. */
|
||||
private normalizeEdits(edits: ts.TextChange[]): ts.TextChange[] {
|
||||
var result: ts.TextChange[] = [];
|
||||
class ClassifierShimProxy implements ts.Classifier {
|
||||
constructor(private shim: ts.ClassifierShim) {
|
||||
}
|
||||
getClassificationsForLine(text: string, lexState: ts.EndOfLineState, classifyKeywordsInGenerics?: boolean): ts.ClassificationResult {
|
||||
var result = this.shim.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics).split('\n');
|
||||
var entries: ts.ClassificationInfo[] = [];
|
||||
var i = 0;
|
||||
var position = 0;
|
||||
|
||||
function mapEdits(edits: ts.TextChange[]): { edit: ts.TextChange; index: number; }[] {
|
||||
var result: { edit: ts.TextChange; index: number; }[] = [];
|
||||
for (var i = 0; i < edits.length; i++) {
|
||||
result.push({ edit: edits[i], index: i });
|
||||
}
|
||||
return result;
|
||||
for (; i < result.length - 1; i += 2) {
|
||||
var t = entries[i / 2] = {
|
||||
length: parseInt(result[i]),
|
||||
classification: parseInt(result[i + 1])
|
||||
};
|
||||
|
||||
assert.isTrue(t.length > 0, "Result length should be greater than 0, got :" + t.length);
|
||||
position += t.length;
|
||||
}
|
||||
var finalLexState = parseInt(result[result.length - 1]);
|
||||
|
||||
var temp = mapEdits(edits).sort(function (a, b) {
|
||||
var result = a.edit.span.start - b.edit.span.start;
|
||||
if (result === 0)
|
||||
result = a.index - b.index;
|
||||
return result;
|
||||
assert.equal(position, text.length, "Expected cumulative length of all entries to match the length of the source. expected: " + text.length + ", but got: " + position);
|
||||
|
||||
return {
|
||||
finalLexState,
|
||||
entries
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function unwrapJSONCallResult(result: string): any {
|
||||
var parsedResult = JSON.parse(result);
|
||||
if (parsedResult.error) {
|
||||
throw new Error("Language Service Shim Error: " + JSON.stringify(parsedResult.error));
|
||||
}
|
||||
else if (parsedResult.canceled) {
|
||||
throw new ts.OperationCanceledException();
|
||||
}
|
||||
return parsedResult.result;
|
||||
}
|
||||
|
||||
class LanguageServiceShimProxy implements ts.LanguageService {
|
||||
constructor(private shim: ts.LanguageServiceShim) {
|
||||
}
|
||||
private unwrappJSONCallResult(result: string): any {
|
||||
var parsedResult = JSON.parse(result);
|
||||
if (parsedResult.error) {
|
||||
throw new Error("Language Service Shim Error: " + JSON.stringify(parsedResult.error));
|
||||
}
|
||||
return parsedResult.result;
|
||||
}
|
||||
cleanupSemanticCache(): void {
|
||||
this.shim.cleanupSemanticCache();
|
||||
}
|
||||
getSyntacticDiagnostics(fileName: string): ts.Diagnostic[] {
|
||||
return unwrapJSONCallResult(this.shim.getSyntacticDiagnostics(fileName));
|
||||
}
|
||||
getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
|
||||
return unwrapJSONCallResult(this.shim.getSemanticDiagnostics(fileName));
|
||||
}
|
||||
getCompilerOptionsDiagnostics(): ts.Diagnostic[] {
|
||||
return unwrapJSONCallResult(this.shim.getCompilerOptionsDiagnostics());
|
||||
}
|
||||
getSyntacticClassifications(fileName: string, span: ts.TextSpan): ts.ClassifiedSpan[] {
|
||||
return unwrapJSONCallResult(this.shim.getSyntacticClassifications(fileName, span.start, span.length));
|
||||
}
|
||||
getSemanticClassifications(fileName: string, span: ts.TextSpan): ts.ClassifiedSpan[] {
|
||||
return unwrapJSONCallResult(this.shim.getSemanticClassifications(fileName, span.start, span.length));
|
||||
}
|
||||
getCompletionsAtPosition(fileName: string, position: number): ts.CompletionInfo {
|
||||
return unwrapJSONCallResult(this.shim.getCompletionsAtPosition(fileName, position));
|
||||
}
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): ts.CompletionEntryDetails {
|
||||
return unwrapJSONCallResult(this.shim.getCompletionEntryDetails(fileName, position, entryName));
|
||||
}
|
||||
getQuickInfoAtPosition(fileName: string, position: number): ts.QuickInfo {
|
||||
return unwrapJSONCallResult(this.shim.getQuickInfoAtPosition(fileName, position));
|
||||
}
|
||||
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): ts.TextSpan {
|
||||
return unwrapJSONCallResult(this.shim.getNameOrDottedNameSpan(fileName, startPos, endPos));
|
||||
}
|
||||
getBreakpointStatementAtPosition(fileName: string, position: number): ts.TextSpan {
|
||||
return unwrapJSONCallResult(this.shim.getBreakpointStatementAtPosition(fileName, position));
|
||||
}
|
||||
getSignatureHelpItems(fileName: string, position: number): ts.SignatureHelpItems {
|
||||
return unwrapJSONCallResult(this.shim.getSignatureHelpItems(fileName, position));
|
||||
}
|
||||
getRenameInfo(fileName: string, position: number): ts.RenameInfo {
|
||||
return unwrapJSONCallResult(this.shim.getRenameInfo(fileName, position));
|
||||
}
|
||||
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ts.RenameLocation[] {
|
||||
return unwrapJSONCallResult(this.shim.findRenameLocations(fileName, position, findInStrings, findInComments));
|
||||
}
|
||||
getDefinitionAtPosition(fileName: string, position: number): ts.DefinitionInfo[] {
|
||||
return unwrapJSONCallResult(this.shim.getDefinitionAtPosition(fileName, position));
|
||||
}
|
||||
getReferencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] {
|
||||
return unwrapJSONCallResult(this.shim.getReferencesAtPosition(fileName, position));
|
||||
}
|
||||
getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] {
|
||||
return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position));
|
||||
}
|
||||
getNavigateToItems(searchValue: string): ts.NavigateToItem[] {
|
||||
return unwrapJSONCallResult(this.shim.getNavigateToItems(searchValue));
|
||||
}
|
||||
getNavigationBarItems(fileName: string): ts.NavigationBarItem[] {
|
||||
return unwrapJSONCallResult(this.shim.getNavigationBarItems(fileName));
|
||||
}
|
||||
getOutliningSpans(fileName: string): ts.OutliningSpan[] {
|
||||
return unwrapJSONCallResult(this.shim.getOutliningSpans(fileName));
|
||||
}
|
||||
getTodoComments(fileName: string, descriptors: ts.TodoCommentDescriptor[]): ts.TodoComment[] {
|
||||
return unwrapJSONCallResult(this.shim.getTodoComments(fileName, JSON.stringify(descriptors)));
|
||||
}
|
||||
getBraceMatchingAtPosition(fileName: string, position: number): ts.TextSpan[] {
|
||||
return unwrapJSONCallResult(this.shim.getBraceMatchingAtPosition(fileName, position));
|
||||
}
|
||||
getIndentationAtPosition(fileName: string, position: number, options: ts.EditorOptions): number {
|
||||
return unwrapJSONCallResult(this.shim.getIndentationAtPosition(fileName, position, JSON.stringify(options)));
|
||||
}
|
||||
getFormattingEditsForRange(fileName: string, start: number, end: number, options: ts.FormatCodeOptions): ts.TextChange[] {
|
||||
return unwrapJSONCallResult(this.shim.getFormattingEditsForRange(fileName, start, end, JSON.stringify(options)));
|
||||
}
|
||||
getFormattingEditsForDocument(fileName: string, options: ts.FormatCodeOptions): ts.TextChange[] {
|
||||
return unwrapJSONCallResult(this.shim.getFormattingEditsForDocument(fileName, JSON.stringify(options)));
|
||||
}
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: ts.FormatCodeOptions): ts.TextChange[] {
|
||||
return unwrapJSONCallResult(this.shim.getFormattingEditsAfterKeystroke(fileName, position, key, JSON.stringify(options)));
|
||||
}
|
||||
getEmitOutput(fileName: string): ts.EmitOutput {
|
||||
return unwrapJSONCallResult(this.shim.getEmitOutput(fileName));
|
||||
}
|
||||
getProgram(): ts.Program {
|
||||
throw new Error("Program can not be marshaled across the shim layer.");
|
||||
}
|
||||
getSourceFile(fileName: string): ts.SourceFile {
|
||||
throw new Error("SourceFile can not be marshaled across the shim layer.");
|
||||
}
|
||||
dispose(): void { this.shim.dispose({}); }
|
||||
}
|
||||
|
||||
export class ShimLanugageServiceAdapter implements LanguageServiceAdapter {
|
||||
private host: ShimLanguageServiceHost;
|
||||
private factory: ts.TypeScriptServicesFactory;
|
||||
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
|
||||
this.host = new ShimLanguageServiceHost(cancellationToken, options);
|
||||
this.factory = new TypeScript.Services.TypeScriptServicesFactory();
|
||||
}
|
||||
getHost() { return this.host; }
|
||||
getLanguageService(): ts.LanguageService { return new LanguageServiceShimProxy(this.factory.createLanguageServiceShim(this.host)); }
|
||||
getClassifier(): ts.Classifier { return new ClassifierShimProxy(this.factory.createClassifierShim(this.host)); }
|
||||
getPreProcessedFileInfo(fileName: string, fileContents: string): ts.PreProcessedFileInfo {
|
||||
var shimResult: {
|
||||
referencedFiles: ts.IFileReference[];
|
||||
importedFiles: ts.IFileReference[];
|
||||
isLibFile: boolean;
|
||||
};
|
||||
|
||||
var coreServicesShim = this.factory.createCoreServicesShim(this.host);
|
||||
shimResult = unwrapJSONCallResult(coreServicesShim.getPreProcessedFileInfo(fileName, ts.ScriptSnapshot.fromString(fileContents)));
|
||||
|
||||
var convertResult: ts.PreProcessedFileInfo = {
|
||||
referencedFiles: [],
|
||||
importedFiles: [],
|
||||
isLibFile: shimResult.isLibFile
|
||||
};
|
||||
|
||||
ts.forEach(shimResult.referencedFiles, refFile => {
|
||||
convertResult.referencedFiles.push({
|
||||
fileName: refFile.path,
|
||||
pos: refFile.position,
|
||||
end: refFile.position + refFile.length
|
||||
});
|
||||
});
|
||||
|
||||
var current = 0;
|
||||
var next = 1;
|
||||
while (current < temp.length) {
|
||||
var currentEdit = temp[current].edit;
|
||||
ts.forEach(shimResult.importedFiles, importedFile => {
|
||||
convertResult.importedFiles.push({
|
||||
fileName: importedFile.path,
|
||||
pos: importedFile.position,
|
||||
end: importedFile.position + importedFile.length
|
||||
});
|
||||
});
|
||||
|
||||
// Last edit
|
||||
if (next >= temp.length) {
|
||||
result.push(currentEdit);
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
var nextEdit = temp[next].edit;
|
||||
|
||||
var gap = nextEdit.span.start - ts.textSpanEnd(currentEdit.span);
|
||||
|
||||
// non-overlapping edits
|
||||
if (gap >= 0) {
|
||||
result.push(currentEdit);
|
||||
current = next;
|
||||
next++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// overlapping edits: for now, we only support ignoring an next edit
|
||||
// entirely contained in the current edit.
|
||||
if (ts.textSpanEnd(currentEdit.span) >= ts.textSpanEnd(nextEdit.span)) {
|
||||
next++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
throw new Error("Trying to apply overlapping edits");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return convertResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,18 +60,18 @@ interface IOLog {
|
||||
}
|
||||
|
||||
interface PlaybackControl {
|
||||
startReplayFromFile(logFilename: string): void;
|
||||
startReplayFromFile(logFileName: string): void;
|
||||
startReplayFromString(logContents: string): void;
|
||||
startReplayFromData(log: IOLog): void;
|
||||
endReplay(): void;
|
||||
startRecord(logFilename: string): void;
|
||||
startRecord(logFileName: string): void;
|
||||
endRecord(): void;
|
||||
}
|
||||
|
||||
module Playback {
|
||||
var recordLog: IOLog = undefined;
|
||||
var replayLog: IOLog = undefined;
|
||||
var recordLogFilenameBase = '';
|
||||
var recordLogFileNameBase = '';
|
||||
|
||||
interface Memoized<T> {
|
||||
(s: string): T;
|
||||
@@ -130,8 +130,8 @@ module Playback {
|
||||
replayLog = undefined;
|
||||
};
|
||||
|
||||
wrapper.startRecord = (filenameBase) => {
|
||||
recordLogFilenameBase = filenameBase;
|
||||
wrapper.startRecord = (fileNameBase) => {
|
||||
recordLogFileNameBase = fileNameBase;
|
||||
recordLog = createEmptyLog();
|
||||
};
|
||||
}
|
||||
@@ -176,7 +176,7 @@ module Playback {
|
||||
|
||||
function findResultByPath<T>(wrapper: { resolvePath(s: string): string }, logArray: { path: string; result?: T }[], expectedPath: string, defaultValue?: T): T {
|
||||
var normalizedName = ts.normalizeSlashes(expectedPath).toLowerCase();
|
||||
// Try to find the result through normal filename
|
||||
// Try to find the result through normal fileName
|
||||
for (var i = 0; i < logArray.length; i++) {
|
||||
if (ts.normalizeSlashes(logArray[i].path).toLowerCase() === normalizedName) {
|
||||
return logArray[i].result;
|
||||
@@ -231,7 +231,7 @@ module Playback {
|
||||
wrapper.endRecord = () => {
|
||||
if (recordLog !== undefined) {
|
||||
var i = 0;
|
||||
var fn = () => recordLogFilenameBase + i + '.json';
|
||||
var fn = () => recordLogFileNameBase + i + '.json';
|
||||
while (underlying.fileExists(fn())) i++;
|
||||
underlying.writeFile(fn(), JSON.stringify(recordLog));
|
||||
recordLog = undefined;
|
||||
|
||||
@@ -91,8 +91,8 @@ class ProjectRunner extends RunnerBase {
|
||||
// We have these two separate locations because when comparing baselines the baseline verifier will delete the existing file
|
||||
// so even if it was created by compiler in that location, the file will be deleted by verified before we can read it
|
||||
// so lets keep these two locations separate
|
||||
function getProjectOutputFolder(filename: string, moduleKind: ts.ModuleKind) {
|
||||
return Harness.Baseline.localPath("projectOutput/" + testCaseJustName + "/" + moduleNameToString(moduleKind) + "/" + filename);
|
||||
function getProjectOutputFolder(fileName: string, moduleKind: ts.ModuleKind) {
|
||||
return Harness.Baseline.localPath("projectOutput/" + testCaseJustName + "/" + moduleNameToString(moduleKind) + "/" + fileName);
|
||||
}
|
||||
|
||||
function cleanProjectUrl(url: string) {
|
||||
@@ -123,28 +123,24 @@ class ProjectRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
function compileProjectFiles(moduleKind: ts.ModuleKind, getInputFiles: ()=> string[],
|
||||
getSourceFileText: (filename: string) => string,
|
||||
writeFile: (filename: string, data: string, writeByteOrderMark: boolean) => void): CompileProjectFilesResult {
|
||||
getSourceFileText: (fileName: string) => string,
|
||||
writeFile: (fileName: string, data: string, writeByteOrderMark: boolean) => void): CompileProjectFilesResult {
|
||||
|
||||
var program = ts.createProgram(getInputFiles(), createCompilerOptions(), createCompilerHost());
|
||||
var errors = program.getDiagnostics();
|
||||
var sourceMapData: ts.SourceMapData[] = null;
|
||||
if (!errors.length) {
|
||||
var checker = program.getTypeChecker(/*produceDiagnostics:*/ true);
|
||||
errors = checker.getDiagnostics();
|
||||
var emitResult = program.emitFiles();
|
||||
errors = ts.concatenate(errors, emitResult.diagnostics);
|
||||
sourceMapData = emitResult.sourceMaps;
|
||||
var errors = ts.getPreEmitDiagnostics(program);
|
||||
|
||||
// Clean up source map data that will be used in baselining
|
||||
if (sourceMapData) {
|
||||
for (var i = 0; i < sourceMapData.length; i++) {
|
||||
for (var j = 0; j < sourceMapData[i].sourceMapSources.length; j++) {
|
||||
sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]);
|
||||
}
|
||||
sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL);
|
||||
sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot);
|
||||
var emitResult = program.emit();
|
||||
errors = ts.concatenate(errors, emitResult.diagnostics);
|
||||
var sourceMapData = emitResult.sourceMaps;
|
||||
|
||||
// Clean up source map data that will be used in baselining
|
||||
if (sourceMapData) {
|
||||
for (var i = 0; i < sourceMapData.length; i++) {
|
||||
for (var j = 0; j < sourceMapData[i].sourceMapSources.length; j++) {
|
||||
sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]);
|
||||
}
|
||||
sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL);
|
||||
sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,15 +164,15 @@ class ProjectRunner extends RunnerBase {
|
||||
};
|
||||
}
|
||||
|
||||
function getSourceFile(filename: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
|
||||
function getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
|
||||
var sourceFile: ts.SourceFile = undefined;
|
||||
if (filename === Harness.Compiler.defaultLibFileName) {
|
||||
if (fileName === Harness.Compiler.defaultLibFileName) {
|
||||
sourceFile = languageVersion === ts.ScriptTarget.ES6 ? Harness.Compiler.defaultES6LibSourceFile : Harness.Compiler.defaultLibSourceFile;
|
||||
}
|
||||
else {
|
||||
var text = getSourceFileText(filename);
|
||||
var text = getSourceFileText(fileName);
|
||||
if (text !== undefined) {
|
||||
sourceFile = ts.createSourceFile(filename, text, languageVersion);
|
||||
sourceFile = Harness.Compiler.createSourceFileAndAssertInvariants(fileName, text, languageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +182,7 @@ class ProjectRunner extends RunnerBase {
|
||||
function createCompilerHost(): ts.CompilerHost {
|
||||
return {
|
||||
getSourceFile,
|
||||
getDefaultLibFilename: options => Harness.Compiler.defaultLibFileName,
|
||||
getDefaultLibFileName: options => Harness.Compiler.defaultLibFileName,
|
||||
writeFile,
|
||||
getCurrentDirectory,
|
||||
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
|
||||
@@ -211,11 +207,11 @@ class ProjectRunner extends RunnerBase {
|
||||
nonSubfolderDiskFiles,
|
||||
};
|
||||
|
||||
function getSourceFileText(filename: string): string {
|
||||
function getSourceFileText(fileName: string): string {
|
||||
try {
|
||||
var text = ts.sys.readFile(ts.isRootedDiskPath(filename)
|
||||
? filename
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename));
|
||||
var text = ts.sys.readFile(ts.isRootedDiskPath(fileName)
|
||||
? fileName
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(fileName));
|
||||
}
|
||||
catch (e) {
|
||||
// text doesn't get defined.
|
||||
@@ -223,30 +219,30 @@ class ProjectRunner extends RunnerBase {
|
||||
return text;
|
||||
}
|
||||
|
||||
function writeFile(filename: string, data: string, writeByteOrderMark: boolean) {
|
||||
var diskFileName = ts.isRootedDiskPath(filename)
|
||||
? filename
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename);
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) {
|
||||
var diskFileName = ts.isRootedDiskPath(fileName)
|
||||
? fileName
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(fileName);
|
||||
|
||||
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName,
|
||||
getCurrentDirectory(), Harness.Compiler.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false);
|
||||
if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") {
|
||||
// If the generated output file resides in the parent folder or is rooted path,
|
||||
// we need to instead create files that can live in the project reference folder
|
||||
// but make sure extension of these files matches with the filename the compiler asked to write
|
||||
// but make sure extension of these files matches with the fileName the compiler asked to write
|
||||
diskRelativeName = "diskFile" + nonSubfolderDiskFiles++ +
|
||||
(Harness.Compiler.isDTS(filename) ? ".d.ts" :
|
||||
Harness.Compiler.isJS(filename) ? ".js" : ".js.map");
|
||||
(Harness.Compiler.isDTS(fileName) ? ".d.ts" :
|
||||
Harness.Compiler.isJS(fileName) ? ".js" : ".js.map");
|
||||
}
|
||||
|
||||
if (Harness.Compiler.isJS(filename)) {
|
||||
if (Harness.Compiler.isJS(fileName)) {
|
||||
// Make sure if there is URl we have it cleaned up
|
||||
var indexOfSourceMapUrl = data.lastIndexOf("//# sourceMappingURL=");
|
||||
if (indexOfSourceMapUrl != -1) {
|
||||
data = data.substring(0, indexOfSourceMapUrl + 21) + cleanProjectUrl(data.substring(indexOfSourceMapUrl + 21));
|
||||
}
|
||||
}
|
||||
else if (Harness.Compiler.isJSMap(filename)) {
|
||||
else if (Harness.Compiler.isJSMap(fileName)) {
|
||||
// Make sure sources list is cleaned
|
||||
var sourceMapData = JSON.parse(data);
|
||||
for (var i = 0; i < sourceMapData.sources.length; i++) {
|
||||
@@ -269,26 +265,26 @@ class ProjectRunner extends RunnerBase {
|
||||
ensureDirectoryStructure(ts.getDirectoryPath(ts.normalizePath(outputFilePath)));
|
||||
ts.sys.writeFile(outputFilePath, data, writeByteOrderMark);
|
||||
|
||||
outputFiles.push({ emittedFileName: filename, code: data, fileName: diskRelativeName, writeByteOrderMark: writeByteOrderMark });
|
||||
outputFiles.push({ emittedFileName: fileName, code: data, fileName: diskRelativeName, writeByteOrderMark: writeByteOrderMark });
|
||||
}
|
||||
}
|
||||
|
||||
function compileCompileDTsFiles(compilerResult: BatchCompileProjectTestCaseResult) {
|
||||
var allInputFiles: { emittedFileName: string; code: string; }[] = [];
|
||||
var compilerOptions = compilerResult.program.getCompilerOptions();
|
||||
var compilerHost = compilerResult.program.getCompilerHost();
|
||||
|
||||
ts.forEach(compilerResult.program.getSourceFiles(), sourceFile => {
|
||||
if (Harness.Compiler.isDTS(sourceFile.filename)) {
|
||||
allInputFiles.unshift({ emittedFileName: sourceFile.filename, code: sourceFile.text });
|
||||
if (Harness.Compiler.isDTS(sourceFile.fileName)) {
|
||||
allInputFiles.unshift({ emittedFileName: sourceFile.fileName, code: sourceFile.text });
|
||||
}
|
||||
else if (ts.shouldEmitToOwnFile(sourceFile, compilerResult.program.getCompilerOptions())) {
|
||||
if (compilerOptions.outDir) {
|
||||
var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, compilerHost.getCurrentDirectory());
|
||||
var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, compilerResult.program.getCurrentDirectory());
|
||||
sourceFilePath = sourceFilePath.replace(compilerResult.program.getCommonSourceDirectory(), "");
|
||||
var emitOutputFilePathWithoutExtension = ts.removeFileExtension(ts.combinePaths(compilerOptions.outDir, sourceFilePath));
|
||||
}
|
||||
else {
|
||||
var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename);
|
||||
var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
|
||||
}
|
||||
|
||||
var outputDtsFileName = emitOutputFilePathWithoutExtension + ".d.ts";
|
||||
@@ -311,19 +307,19 @@ class ProjectRunner extends RunnerBase {
|
||||
function getInputFiles() {
|
||||
return ts.map(allInputFiles, outputFile => outputFile.emittedFileName);
|
||||
}
|
||||
function getSourceFileText(filename: string): string {
|
||||
return ts.forEach(allInputFiles, inputFile => inputFile.emittedFileName === filename ? inputFile.code : undefined);
|
||||
function getSourceFileText(fileName: string): string {
|
||||
return ts.forEach(allInputFiles, inputFile => inputFile.emittedFileName === fileName ? inputFile.code : undefined);
|
||||
}
|
||||
|
||||
function writeFile(filename: string, data: string, writeByteOrderMark: boolean) {
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
function getErrorsBaseline(compilerResult: CompileProjectFilesResult) {
|
||||
var inputFiles = ts.map(ts.filter(compilerResult.program.getSourceFiles(),
|
||||
sourceFile => sourceFile.filename !== "lib.d.ts"),
|
||||
sourceFile => sourceFile.fileName !== "lib.d.ts"),
|
||||
sourceFile => {
|
||||
return { unitName: sourceFile.filename, content: sourceFile.text };
|
||||
return { unitName: sourceFile.fileName, content: sourceFile.text };
|
||||
});
|
||||
var diagnostics = ts.map(compilerResult.errors, error => Harness.Compiler.getMinimalDiagnostic(error));
|
||||
|
||||
@@ -348,7 +344,7 @@ class ProjectRunner extends RunnerBase {
|
||||
baselineCheck: testCase.baselineCheck,
|
||||
runTest: testCase.runTest,
|
||||
bug: testCase.bug,
|
||||
resolvedInputFiles: ts.map(compilerResult.program.getSourceFiles(), inputFile => inputFile.filename),
|
||||
resolvedInputFiles: ts.map(compilerResult.program.getSourceFiles(), inputFile => inputFile.fileName),
|
||||
emittedFiles: ts.map(compilerResult.outputFiles, outputFile => outputFile.emittedFileName)
|
||||
};
|
||||
|
||||
|
||||
@@ -61,10 +61,13 @@ if (testConfigFile !== '') {
|
||||
runners.push(new ProjectRunner());
|
||||
break;
|
||||
case 'fourslash':
|
||||
runners.push(new FourslashRunner());
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Native));
|
||||
break;
|
||||
case 'fourslash-shims':
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
|
||||
break;
|
||||
case 'fourslash-generated':
|
||||
runners.push(new GeneratedFourslashRunner());
|
||||
runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native));
|
||||
break;
|
||||
case 'rwc':
|
||||
runners.push(new RWCRunner());
|
||||
@@ -90,7 +93,8 @@ if (runners.length === 0) {
|
||||
}
|
||||
|
||||
// language services
|
||||
runners.push(new FourslashRunner());
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Native));
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
|
||||
//runners.push(new GeneratedFourslashRunner());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class RunnerBase {
|
||||
throw new Error('method not implemented');
|
||||
}
|
||||
|
||||
/** Replaces instances of full paths with filenames only */
|
||||
/** Replaces instances of full paths with fileNames only */
|
||||
static removeFullPaths(path: string) {
|
||||
var fixedPath = path;
|
||||
|
||||
|
||||
@@ -26,7 +26,10 @@ module RWC {
|
||||
var otherFiles: { unitName: string; content: string; }[] = [];
|
||||
var compilerResult: Harness.Compiler.CompilerResult;
|
||||
var compilerOptions: ts.CompilerOptions;
|
||||
var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' };
|
||||
var baselineOpts: Harness.Baseline.BaselineOptions = {
|
||||
Subfolder: 'rwc',
|
||||
Baselinefolder: 'internal/baselines'
|
||||
};
|
||||
var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2];
|
||||
var currentDirectory: string;
|
||||
|
||||
@@ -56,7 +59,7 @@ module RWC {
|
||||
runWithIOLog(ioLog, () => {
|
||||
harnessCompiler.reset();
|
||||
// Load the files
|
||||
ts.forEach(opts.filenames, fileName => {
|
||||
ts.forEach(opts.fileNames, fileName => {
|
||||
inputFiles.push(getHarnessCompilerInputUnit(fileName));
|
||||
});
|
||||
|
||||
@@ -87,7 +90,8 @@ module RWC {
|
||||
/*settingsCallback*/ undefined, opts.options,
|
||||
// Since all Rwc json file specified current directory in its json file, we need to pass this information to compilerHost
|
||||
// so that when the host is asked for current directory, it should give the value from json rather than from process
|
||||
currentDirectory);
|
||||
currentDirectory,
|
||||
/*assertInvariants:*/ false);
|
||||
});
|
||||
|
||||
function getHarnessCompilerInputUnit(fileName: string) {
|
||||
@@ -170,7 +174,7 @@ module RWC {
|
||||
}
|
||||
|
||||
class RWCRunner extends RunnerBase {
|
||||
private static sourcePath = "tests/cases/rwc/";
|
||||
private static sourcePath = "internal/cases/rwc/";
|
||||
|
||||
/** Setup the runner's tests so that they are ready to be executed by the harness
|
||||
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
|
||||
@@ -183,7 +187,7 @@ class RWCRunner extends RunnerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private runTest(jsonFilename: string) {
|
||||
RWC.runRWCTest(jsonFilename);
|
||||
private runTest(jsonFileName: string) {
|
||||
RWC.runRWCTest(jsonFileName);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
/// <reference path='syntacticCleaner.ts' />
|
||||
|
||||
class Test262BaselineRunner extends RunnerBase {
|
||||
private static basePath = 'tests/cases/test262';
|
||||
private static basePath = 'internal/cases/test262';
|
||||
private static helpersFilePath = 'tests/cases/test262-harness/helpers.d.ts';
|
||||
private static helperFile = {
|
||||
unitName: Test262BaselineRunner.helpersFilePath,
|
||||
@@ -15,7 +15,10 @@ class Test262BaselineRunner extends RunnerBase {
|
||||
target: ts.ScriptTarget.Latest,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
};
|
||||
private static baselineOptions: Harness.Baseline.BaselineOptions = { Subfolder: 'test262' };
|
||||
private static baselineOptions: Harness.Baseline.BaselineOptions = {
|
||||
Subfolder: 'test262',
|
||||
Baselinefolder: 'internal/baselines'
|
||||
};
|
||||
|
||||
private static getTestFilePath(filename: string): string {
|
||||
return Test262BaselineRunner.basePath + "/" + filename;
|
||||
|
||||
@@ -12,10 +12,12 @@ class TypeWriterWalker {
|
||||
|
||||
private checker: ts.TypeChecker;
|
||||
|
||||
constructor(private program: ts.Program) {
|
||||
constructor(private program: ts.Program, fullTypeCheck: boolean) {
|
||||
// Consider getting both the diagnostics checker and the non-diagnostics checker to verify
|
||||
// they are consistent.
|
||||
this.checker = program.getTypeChecker(/*produceDiagnostics:*/ true);
|
||||
this.checker = fullTypeCheck
|
||||
? program.getDiagnosticsProducingTypeChecker()
|
||||
: program.getTypeChecker();
|
||||
}
|
||||
|
||||
public getTypes(fileName: string): TypeWriterResult[] {
|
||||
|
||||
Vendored
+1
-1
@@ -82,7 +82,7 @@ declare module Intl {
|
||||
second?: string;
|
||||
timeZoneName?: string;
|
||||
formatMatcher?: string;
|
||||
hour12: boolean;
|
||||
hour12?: boolean;
|
||||
}
|
||||
|
||||
interface ResolvedDateTimeFormatOptions {
|
||||
|
||||
@@ -404,9 +404,9 @@ module ts.NavigationBar {
|
||||
}
|
||||
|
||||
hasGlobalNode = true;
|
||||
var rootName = isExternalModule(node) ?
|
||||
"\"" + escapeString(getBaseFilename(removeFileExtension(normalizePath(node.filename)))) + "\"" :
|
||||
"<global>"
|
||||
var rootName = isExternalModule(node)
|
||||
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\""
|
||||
: "<global>"
|
||||
|
||||
return getNavigationBarItem(rootName,
|
||||
ts.ScriptElementKind.moduleElement,
|
||||
|
||||
+460
-275
File diff suppressed because it is too large
Load Diff
+36
-15
@@ -51,7 +51,8 @@ module ts {
|
||||
getLocalizedDiagnosticMessages(): string;
|
||||
getCancellationToken(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: string): string;
|
||||
getDefaultLibFileName(options: string): string;
|
||||
getNewLine?(): string;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -89,6 +90,7 @@ module ts {
|
||||
getCompilerOptionsDiagnostics(): string;
|
||||
|
||||
getSyntacticClassifications(fileName: string, start: number, length: number): string;
|
||||
getSemanticClassifications(fileName: string, start: number, length: number): string;
|
||||
|
||||
getCompletionsAtPosition(fileName: string, position: number): string;
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): string;
|
||||
@@ -163,7 +165,7 @@ module ts {
|
||||
}
|
||||
|
||||
export interface ClassifierShim extends Shim {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string;
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string;
|
||||
}
|
||||
|
||||
export interface CoreServicesShim extends Shim {
|
||||
@@ -203,6 +205,8 @@ module ts {
|
||||
}
|
||||
|
||||
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {
|
||||
private files: string[];
|
||||
|
||||
constructor(private shimHost: LanguageServiceShimHost) {
|
||||
}
|
||||
|
||||
@@ -229,10 +233,15 @@ module ts {
|
||||
|
||||
public getScriptFileNames(): string[] {
|
||||
var encoded = this.shimHost.getScriptFileNames();
|
||||
return JSON.parse(encoded);
|
||||
return this.files = JSON.parse(encoded);
|
||||
}
|
||||
|
||||
public getScriptSnapshot(fileName: string): IScriptSnapshot {
|
||||
// Shim the API changes for 1.5 release. This should be removed once
|
||||
// TypeScript 1.5 has shipped.
|
||||
if (this.files && this.files.indexOf(fileName) < 0) {
|
||||
return undefined;
|
||||
}
|
||||
var scriptSnapshot = this.shimHost.getScriptSnapshot(fileName);
|
||||
return scriptSnapshot && new ScriptSnapshotShimAdapter(scriptSnapshot);
|
||||
}
|
||||
@@ -264,8 +273,8 @@ module ts {
|
||||
return this.shimHost.getCurrentDirectory();
|
||||
}
|
||||
|
||||
public getDefaultLibFilename(options: CompilerOptions): string {
|
||||
return this.shimHost.getDefaultLibFilename(JSON.stringify(options));
|
||||
public getDefaultLibFileName(options: CompilerOptions): string {
|
||||
return this.shimHost.getDefaultLibFileName(JSON.stringify(options));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,9 +376,14 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
private static realizeDiagnostic(diagnostic: Diagnostic): { message: string; start: number; length: number; category: string; } {
|
||||
private realizeDiagnostics(diagnostics: Diagnostic[]): { message: string; start: number; length: number; category: string; }[]{
|
||||
var newLine = this.getNewLine();
|
||||
return diagnostics.map(d => this.realizeDiagnostic(d, newLine));
|
||||
}
|
||||
|
||||
private realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } {
|
||||
return {
|
||||
message: diagnostic.messageText,
|
||||
message: flattenDiagnosticMessageText(diagnostic.messageText, newLine),
|
||||
start: diagnostic.start,
|
||||
length: diagnostic.length,
|
||||
/// TODO: no need for the tolowerCase call
|
||||
@@ -396,12 +410,16 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
private getNewLine(): string {
|
||||
return this.host.getNewLine ? this.host.getNewLine() : "\r\n";
|
||||
}
|
||||
|
||||
public getSyntacticDiagnostics(fileName: string): string {
|
||||
return this.forwardJSONCall(
|
||||
"getSyntacticDiagnostics('" + fileName + "')",
|
||||
() => {
|
||||
var errors = this.languageService.getSyntacticDiagnostics(fileName);
|
||||
return errors.map(LanguageServiceShimObject.realizeDiagnostic);
|
||||
var diagnostics = this.languageService.getSyntacticDiagnostics(fileName);
|
||||
return this.realizeDiagnostics(diagnostics);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -409,8 +427,8 @@ module ts {
|
||||
return this.forwardJSONCall(
|
||||
"getSemanticDiagnostics('" + fileName + "')",
|
||||
() => {
|
||||
var errors = this.languageService.getSemanticDiagnostics(fileName);
|
||||
return errors.map(LanguageServiceShimObject.realizeDiagnostic);
|
||||
var diagnostics = this.languageService.getSemanticDiagnostics(fileName);
|
||||
return this.realizeDiagnostics(diagnostics);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -418,8 +436,8 @@ module ts {
|
||||
return this.forwardJSONCall(
|
||||
"getCompilerOptionsDiagnostics()",
|
||||
() => {
|
||||
var errors = this.languageService.getCompilerOptionsDiagnostics();
|
||||
return errors.map(LanguageServiceShimObject.realizeDiagnostic)
|
||||
var diagnostics = this.languageService.getCompilerOptionsDiagnostics();
|
||||
return this.realizeDiagnostics(diagnostics);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -652,6 +670,9 @@ module ts {
|
||||
"getEmitOutput('" + fileName + "')",
|
||||
() => {
|
||||
var output = this.languageService.getEmitOutput(fileName);
|
||||
// Shim the API changes for 1.5 release. This should be removed once
|
||||
// TypeScript 1.5 has shipped.
|
||||
(<any>output).emitOutputStatus = output.emitSkipped ? 1 : 0;
|
||||
return output;
|
||||
});
|
||||
}
|
||||
@@ -701,7 +722,7 @@ module ts {
|
||||
|
||||
forEach(result.referencedFiles, refFile => {
|
||||
convertResult.referencedFiles.push({
|
||||
path: normalizePath(refFile.filename),
|
||||
path: normalizePath(refFile.fileName),
|
||||
position: refFile.pos,
|
||||
length: refFile.end - refFile.pos
|
||||
});
|
||||
@@ -709,7 +730,7 @@ module ts {
|
||||
|
||||
forEach(result.importedFiles, importedFile => {
|
||||
convertResult.importedFiles.push({
|
||||
path: normalizeSlashes(importedFile.filename),
|
||||
path: normalizeSlashes(importedFile.fileName),
|
||||
position: importedFile.pos,
|
||||
length: importedFile.end - importedFile.pos
|
||||
});
|
||||
|
||||
@@ -295,8 +295,8 @@ module ts.SignatureHelp {
|
||||
var tagExpression = <TaggedTemplateExpression>templateExpression.parent;
|
||||
Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression);
|
||||
|
||||
// If we're just after a template tail, don't show signature help.
|
||||
if (node.kind === SyntaxKind.TemplateTail && position >= node.getEnd() && !(<LiteralExpression>node).isUnterminated) {
|
||||
// If we're just after a template tail, don't show signature help.
|
||||
if (node.kind === SyntaxKind.TemplateTail && !isInsideTemplateLiteral(<LiteralExpression>node, position)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,26 +10,24 @@
|
||||
|
||||
declare var process: any;
|
||||
declare var console: any;
|
||||
declare var os: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
|
||||
export function compile(filenames: string[], options: ts.CompilerOptions): void {
|
||||
var host = ts.createCompilerHost(options);
|
||||
var program = ts.createProgram(filenames, options, host);
|
||||
var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true);
|
||||
var result = program.emitFiles();
|
||||
export function compile(fileNames: string[], options: ts.CompilerOptions): void {
|
||||
var program = ts.createProgram(fileNames, options);
|
||||
var emitResult = program.emit();
|
||||
|
||||
var allDiagnostics = program.getDiagnostics()
|
||||
.concat(checker.getDiagnostics())
|
||||
.concat(result.diagnostics);
|
||||
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
|
||||
console.log(`${diagnostic.file.filename} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`);
|
||||
console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`);
|
||||
});
|
||||
|
||||
console.log(`Process exiting with code '${result.emitResultStatus}'.`);
|
||||
process.exit(result.emitResultStatus);
|
||||
var exitCode = emitResult.emitSkipped ? 1 : 0;
|
||||
console.log(`Process exiting with code '${exitCode}'.`);
|
||||
process.exit(exitCode);
|
||||
}
|
||||
|
||||
compile(process.argv.slice(2), {
|
||||
@@ -715,7 +713,7 @@ declare module "typescript" {
|
||||
exportName: Identifier;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
@@ -723,34 +721,46 @@ declare module "typescript" {
|
||||
interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {
|
||||
path: string;
|
||||
name: string;
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node;
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
}
|
||||
interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getTypeChecker(): TypeChecker;
|
||||
getCommonSourceDirectory(): string;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
emittedLine: number;
|
||||
@@ -771,33 +781,22 @@ declare module "typescript" {
|
||||
sourceMapMappings: string;
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
Succeeded = 0,
|
||||
AllOutputGenerationSkipped = 1,
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
DeclarationGenerationSkipped = 3,
|
||||
EmitErrorsEncountered = 4,
|
||||
CompilerOptionsErrors = 5,
|
||||
enum ExitStatus {
|
||||
Success = 0,
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[];
|
||||
}
|
||||
interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -821,7 +820,7 @@ declare module "typescript" {
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
@@ -887,15 +886,13 @@ declare module "typescript" {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
const enum SymbolFlags {
|
||||
@@ -1142,7 +1139,7 @@ declare module "typescript" {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
}
|
||||
@@ -1201,7 +1198,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
interface CommandLineOption {
|
||||
@@ -1343,10 +1340,10 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1410,10 +1407,9 @@ declare module "typescript" {
|
||||
function createNode(kind: SyntaxKind): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function modifierToFlag(token: SyntaxKind): NodeFlags;
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function isLeftHandSideExpression(expr: Expression): boolean;
|
||||
function isAssignmentOperator(token: SyntaxKind): boolean;
|
||||
}
|
||||
@@ -1422,7 +1418,9 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
}
|
||||
declare module "typescript" {
|
||||
var servicesVersion: string;
|
||||
@@ -1474,7 +1472,6 @@ declare module "typescript" {
|
||||
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
|
||||
getLineStarts(): number[];
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
}
|
||||
/**
|
||||
@@ -1513,7 +1510,7 @@ declare module "typescript" {
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
log?(s: string): void;
|
||||
trace?(s: string): void;
|
||||
error?(s: string): void;
|
||||
@@ -1547,7 +1544,7 @@ declare module "typescript" {
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
getProgram(): Program;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
dispose(): void;
|
||||
}
|
||||
interface ClassifiedSpan {
|
||||
@@ -1697,6 +1694,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
interface CompletionEntry {
|
||||
@@ -1726,7 +1724,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
}
|
||||
const enum OutputFileType {
|
||||
JavaScript = 0,
|
||||
@@ -1743,6 +1741,9 @@ declare module "typescript" {
|
||||
InMultiLineCommentTrivia = 1,
|
||||
InSingleQuoteStringLiteral = 2,
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
InTemplateMiddleOrTail = 5,
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
}
|
||||
enum TokenClass {
|
||||
Punctuation = 0,
|
||||
@@ -1764,7 +1765,26 @@ declare module "typescript" {
|
||||
classification: TokenClass;
|
||||
}
|
||||
interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
}
|
||||
/**
|
||||
* The document registry represents a store of SourceFile objects that can be shared between
|
||||
@@ -1783,11 +1803,11 @@ declare module "typescript" {
|
||||
*/
|
||||
interface DocumentRegistry {
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1796,9 +1816,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -1806,7 +1826,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1817,17 +1837,17 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
/**
|
||||
* Informs the DocumentRegistry that a file is not needed any longer.
|
||||
*
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
}
|
||||
class ScriptElementKind {
|
||||
static unknown: string;
|
||||
@@ -1898,9 +1918,9 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
|
||||
@@ -1921,18 +1941,17 @@ declare module "typescript" {
|
||||
* Please log a "breaking change" issue for any API breaking change affecting this issue
|
||||
*/
|
||||
var ts = require("typescript");
|
||||
function compile(filenames, options) {
|
||||
var host = ts.createCompilerHost(options);
|
||||
var program = ts.createProgram(filenames, options, host);
|
||||
var checker = ts.createTypeChecker(program, true);
|
||||
var result = program.emitFiles();
|
||||
var allDiagnostics = program.getDiagnostics().concat(checker.getDiagnostics()).concat(result.diagnostics);
|
||||
function compile(fileNames, options) {
|
||||
var program = ts.createProgram(fileNames, options);
|
||||
var emitResult = program.emit();
|
||||
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
allDiagnostics.forEach(function (diagnostic) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
|
||||
console.log(diagnostic.file.filename + " (" + lineChar.line + "," + lineChar.character + "): " + diagnostic.messageText);
|
||||
console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL));
|
||||
});
|
||||
console.log("Process exiting with code '" + result.emitResultStatus + "'.");
|
||||
process.exit(result.emitResultStatus);
|
||||
var exitCode = emitResult.emitSkipped ? 1 : 0;
|
||||
console.log("Process exiting with code '" + exitCode + "'.");
|
||||
process.exit(exitCode);
|
||||
}
|
||||
exports.compile = compile;
|
||||
compile(process.argv.slice(2), {
|
||||
|
||||
@@ -12,79 +12,55 @@ declare var process: any;
|
||||
declare var console: any;
|
||||
>console : any
|
||||
|
||||
declare var os: any;
|
||||
>os : any
|
||||
|
||||
import ts = require("typescript");
|
||||
>ts : typeof ts
|
||||
|
||||
export function compile(filenames: string[], options: ts.CompilerOptions): void {
|
||||
>compile : (filenames: string[], options: ts.CompilerOptions) => void
|
||||
>filenames : string[]
|
||||
export function compile(fileNames: string[], options: ts.CompilerOptions): void {
|
||||
>compile : (fileNames: string[], options: ts.CompilerOptions) => void
|
||||
>fileNames : string[]
|
||||
>options : ts.CompilerOptions
|
||||
>ts : unknown
|
||||
>CompilerOptions : ts.CompilerOptions
|
||||
|
||||
var host = ts.createCompilerHost(options);
|
||||
>host : ts.CompilerHost
|
||||
>ts.createCompilerHost(options) : ts.CompilerHost
|
||||
>ts.createCompilerHost : (options: ts.CompilerOptions) => ts.CompilerHost
|
||||
var program = ts.createProgram(fileNames, options);
|
||||
>program : ts.Program
|
||||
>ts.createProgram(fileNames, options) : ts.Program
|
||||
>ts.createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
|
||||
>ts : typeof ts
|
||||
>createCompilerHost : (options: ts.CompilerOptions) => ts.CompilerHost
|
||||
>createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
|
||||
>fileNames : string[]
|
||||
>options : ts.CompilerOptions
|
||||
|
||||
var program = ts.createProgram(filenames, options, host);
|
||||
var emitResult = program.emit();
|
||||
>emitResult : ts.EmitResult
|
||||
>program.emit() : ts.EmitResult
|
||||
>program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult
|
||||
>program : ts.Program
|
||||
>ts.createProgram(filenames, options, host) : 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
|
||||
>filenames : string[]
|
||||
>options : ts.CompilerOptions
|
||||
>host : ts.CompilerHost
|
||||
>emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult
|
||||
|
||||
var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true);
|
||||
>checker : ts.TypeChecker
|
||||
>ts.createTypeChecker(program, /*produceDiagnostics*/ true) : ts.TypeChecker
|
||||
>ts.createTypeChecker : (host: ts.TypeCheckerHost, produceDiagnostics: boolean) => ts.TypeChecker
|
||||
>ts : typeof ts
|
||||
>createTypeChecker : (host: ts.TypeCheckerHost, produceDiagnostics: boolean) => ts.TypeChecker
|
||||
>program : ts.Program
|
||||
|
||||
var result = program.emitFiles();
|
||||
>result : ts.EmitResult
|
||||
>program.emitFiles() : ts.EmitResult
|
||||
>program.emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
|
||||
>program : ts.Program
|
||||
>emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
|
||||
|
||||
var allDiagnostics = program.getDiagnostics()
|
||||
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
>allDiagnostics : ts.Diagnostic[]
|
||||
>program.getDiagnostics() .concat(checker.getDiagnostics()) .concat(result.diagnostics) : ts.Diagnostic[]
|
||||
>program.getDiagnostics() .concat(checker.getDiagnostics()) .concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
>program.getDiagnostics() .concat(checker.getDiagnostics()) : ts.Diagnostic[]
|
||||
>program.getDiagnostics() .concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
>program.getDiagnostics() : ts.Diagnostic[]
|
||||
>program.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
|
||||
>ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics) : ts.Diagnostic[]
|
||||
>ts.getPreEmitDiagnostics(program).concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): 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
|
||||
>getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
|
||||
|
||||
.concat(checker.getDiagnostics())
|
||||
>concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
>checker.getDiagnostics() : ts.Diagnostic[]
|
||||
>checker.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
|
||||
>checker : ts.TypeChecker
|
||||
>getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
|
||||
|
||||
.concat(result.diagnostics);
|
||||
>concat : { <U extends ts.Diagnostic[]>(...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
|
||||
>result.diagnostics : ts.Diagnostic[]
|
||||
>result : ts.EmitResult
|
||||
>emitResult.diagnostics : ts.Diagnostic[]
|
||||
>emitResult : ts.EmitResult
|
||||
>diagnostics : ts.Diagnostic[]
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
>allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.filename} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); }) : void
|
||||
>allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }) : 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.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.filename} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); } : (diagnostic: ts.Diagnostic) => void
|
||||
>diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); } : (diagnostic: ts.Diagnostic) => void
|
||||
>diagnostic : ts.Diagnostic
|
||||
|
||||
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
|
||||
@@ -99,50 +75,60 @@ export function compile(filenames: string[], options: ts.CompilerOptions): void
|
||||
>diagnostic : ts.Diagnostic
|
||||
>start : number
|
||||
|
||||
console.log(`${diagnostic.file.filename} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`);
|
||||
>console.log(`${diagnostic.file.filename} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`) : any
|
||||
console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`);
|
||||
>console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>diagnostic.file.filename : string
|
||||
>diagnostic.file.fileName : string
|
||||
>diagnostic.file : ts.SourceFile
|
||||
>diagnostic : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
>filename : string
|
||||
>fileName : string
|
||||
>lineChar.line : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>line : number
|
||||
>lineChar.character : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>character : number
|
||||
>diagnostic.messageText : string
|
||||
>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
|
||||
>messageText : string | ts.DiagnosticMessageChain
|
||||
>os.EOL : any
|
||||
>os : any
|
||||
>EOL : any
|
||||
|
||||
});
|
||||
|
||||
console.log(`Process exiting with code '${result.emitResultStatus}'.`);
|
||||
>console.log(`Process exiting with code '${result.emitResultStatus}'.`) : any
|
||||
var exitCode = emitResult.emitSkipped ? 1 : 0;
|
||||
>exitCode : number
|
||||
>emitResult.emitSkipped ? 1 : 0 : number
|
||||
>emitResult.emitSkipped : boolean
|
||||
>emitResult : ts.EmitResult
|
||||
>emitSkipped : boolean
|
||||
|
||||
console.log(`Process exiting with code '${exitCode}'.`);
|
||||
>console.log(`Process exiting with code '${exitCode}'.`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>result.emitResultStatus : ts.EmitReturnStatus
|
||||
>result : ts.EmitResult
|
||||
>emitResultStatus : ts.EmitReturnStatus
|
||||
>exitCode : number
|
||||
|
||||
process.exit(result.emitResultStatus);
|
||||
>process.exit(result.emitResultStatus) : any
|
||||
process.exit(exitCode);
|
||||
>process.exit(exitCode) : any
|
||||
>process.exit : any
|
||||
>process : any
|
||||
>exit : any
|
||||
>result.emitResultStatus : ts.EmitReturnStatus
|
||||
>result : ts.EmitResult
|
||||
>emitResultStatus : ts.EmitReturnStatus
|
||||
>exitCode : number
|
||||
}
|
||||
|
||||
compile(process.argv.slice(2), {
|
||||
>compile(process.argv.slice(2), { noEmitOnError: true, noImplicitAny: true, target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS}) : void
|
||||
>compile : (filenames: string[], options: ts.CompilerOptions) => void
|
||||
>compile : (fileNames: string[], options: ts.CompilerOptions) => void
|
||||
>process.argv.slice(2) : any
|
||||
>process.argv.slice : any
|
||||
>process.argv : any
|
||||
@@ -2180,8 +2166,8 @@ declare module "typescript" {
|
||||
>FileReference : FileReference
|
||||
>TextRange : TextRange
|
||||
|
||||
filename: string;
|
||||
>filename : string
|
||||
fileName: string;
|
||||
>fileName : string
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
>CommentRange : CommentRange
|
||||
@@ -2203,15 +2189,22 @@ declare module "typescript" {
|
||||
>endOfFileToken : Node
|
||||
>Node : Node
|
||||
|
||||
filename: string;
|
||||
>filename : string
|
||||
fileName: string;
|
||||
>fileName : string
|
||||
|
||||
text: string;
|
||||
>text : string
|
||||
|
||||
amdDependencies: string[];
|
||||
>amdDependencies : string[]
|
||||
amdDependencies: {
|
||||
>amdDependencies : { path: string; name: string; }[]
|
||||
|
||||
path: string;
|
||||
>path : string
|
||||
|
||||
name: string;
|
||||
>name : string
|
||||
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
>amdModuleName : string
|
||||
|
||||
@@ -2226,15 +2219,6 @@ declare module "typescript" {
|
||||
>externalModuleIndicator : Node
|
||||
>Node : Node
|
||||
|
||||
nodeCount: number;
|
||||
>nodeCount : number
|
||||
|
||||
identifierCount: number;
|
||||
>identifierCount : number
|
||||
|
||||
symbolCount: number;
|
||||
>symbolCount : number
|
||||
|
||||
languageVersion: ScriptTarget;
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
@@ -2250,13 +2234,23 @@ declare module "typescript" {
|
||||
>getCompilerOptions : () => CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
>fileName : string
|
||||
>data : string
|
||||
>writeByteOrderMark : boolean
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
>Program : Program
|
||||
@@ -2266,12 +2260,26 @@ declare module "typescript" {
|
||||
>getSourceFiles : () => SourceFile[]
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getCompilerHost(): CompilerHost;
|
||||
>getCompilerHost : () => CompilerHost
|
||||
>CompilerHost : CompilerHost
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
|
||||
>targetSourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>writeFile : WriteFileCallback
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
>EmitResult : EmitResult
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
@@ -2280,30 +2288,24 @@ declare module "typescript" {
|
||||
>getGlobalDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
>getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
>getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
|
||||
>produceDiagnostics : boolean
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getTypeChecker(): TypeChecker;
|
||||
>getTypeChecker : () => TypeChecker
|
||||
>TypeChecker : TypeChecker
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
>getCommonSourceDirectory : () => string
|
||||
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
>emitFiles : (targetSourceFile?: SourceFile) => EmitResult
|
||||
>targetSourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>EmitResult : EmitResult
|
||||
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
>isEmitBlocked : (sourceFile?: SourceFile) => boolean
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
>SourceMapSpan : SourceMapSpan
|
||||
@@ -2357,33 +2359,23 @@ declare module "typescript" {
|
||||
>sourceMapDecodedMappings : SourceMapSpan[]
|
||||
>SourceMapSpan : SourceMapSpan
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
enum ExitStatus {
|
||||
>ExitStatus : ExitStatus
|
||||
|
||||
Succeeded = 0,
|
||||
>Succeeded : EmitReturnStatus
|
||||
Success = 0,
|
||||
>Success : ExitStatus
|
||||
|
||||
AllOutputGenerationSkipped = 1,
|
||||
>AllOutputGenerationSkipped : EmitReturnStatus
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
>DiagnosticsPresent_OutputsSkipped : ExitStatus
|
||||
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
>JSGeneratedWithSemanticErrors : EmitReturnStatus
|
||||
|
||||
DeclarationGenerationSkipped = 3,
|
||||
>DeclarationGenerationSkipped : EmitReturnStatus
|
||||
|
||||
EmitErrorsEncountered = 4,
|
||||
>EmitErrorsEncountered : EmitReturnStatus
|
||||
|
||||
CompilerOptionsErrors = 5,
|
||||
>CompilerOptionsErrors : EmitReturnStatus
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
>DiagnosticsPresent_OutputsGenerated : ExitStatus
|
||||
}
|
||||
interface EmitResult {
|
||||
>EmitResult : EmitResult
|
||||
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
>emitResultStatus : EmitReturnStatus
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
emitSkipped: boolean;
|
||||
>emitSkipped : boolean
|
||||
|
||||
diagnostics: Diagnostic[];
|
||||
>diagnostics : Diagnostic[]
|
||||
@@ -2400,48 +2392,18 @@ declare module "typescript" {
|
||||
>getCompilerOptions : () => CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
getCompilerHost(): CompilerHost;
|
||||
>getCompilerHost : () => CompilerHost
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
getSourceFiles(): SourceFile[];
|
||||
>getSourceFiles : () => SourceFile[]
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
}
|
||||
interface TypeChecker {
|
||||
>TypeChecker : TypeChecker
|
||||
|
||||
getEmitResolver(): EmitResolver;
|
||||
>getEmitResolver : () => EmitResolver
|
||||
>EmitResolver : EmitResolver
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
>getGlobalDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getNodeCount(): number;
|
||||
>getNodeCount : () => number
|
||||
|
||||
getIdentifierCount(): number;
|
||||
>getIdentifierCount : () => number
|
||||
|
||||
getSymbolCount(): number;
|
||||
>getSymbolCount : () => number
|
||||
|
||||
getTypeCount(): number;
|
||||
>getTypeCount : () => number
|
||||
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
|
||||
>symbol : Symbol
|
||||
@@ -2591,10 +2553,12 @@ declare module "typescript" {
|
||||
>symbol : Symbol
|
||||
>Symbol : Symbol
|
||||
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
>getEnumMemberValue : (node: EnumMember) => number
|
||||
>node : EnumMember
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
|
||||
>EnumMember : EnumMember
|
||||
>PropertyAccessExpression : PropertyAccessExpression
|
||||
>ElementAccessExpression : ElementAccessExpression
|
||||
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
|
||||
@@ -2881,16 +2845,6 @@ declare module "typescript" {
|
||||
>Node : Node
|
||||
>NodeCheckFlags : NodeCheckFlags
|
||||
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
>getEnumMemberValue : (node: EnumMember) => number
|
||||
>node : EnumMember
|
||||
>EnumMember : EnumMember
|
||||
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
>hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
>isDeclarationVisible : (node: Declaration) => boolean
|
||||
>node : Declaration
|
||||
@@ -2942,9 +2896,10 @@ declare module "typescript" {
|
||||
>Node : Node
|
||||
>SymbolVisibilityResult : SymbolVisibilityResult
|
||||
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
|
||||
>EnumMember : EnumMember
|
||||
>PropertyAccessExpression : PropertyAccessExpression
|
||||
>ElementAccessExpression : ElementAccessExpression
|
||||
|
||||
@@ -3685,8 +3640,9 @@ declare module "typescript" {
|
||||
length: number;
|
||||
>length : number
|
||||
|
||||
messageText: string;
|
||||
>messageText : string
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
>messageText : string | DiagnosticMessageChain
|
||||
>DiagnosticMessageChain : DiagnosticMessageChain
|
||||
|
||||
category: DiagnosticCategory;
|
||||
>category : DiagnosticCategory
|
||||
@@ -3848,8 +3804,8 @@ declare module "typescript" {
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
filenames: string[];
|
||||
>filenames : string[]
|
||||
fileNames: string[];
|
||||
>fileNames : string[]
|
||||
|
||||
errors: Diagnostic[];
|
||||
>errors : Diagnostic[]
|
||||
@@ -4267,17 +4223,17 @@ declare module "typescript" {
|
||||
interface CompilerHost {
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
>getSourceFile : (filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
>getSourceFile : (fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) => SourceFile
|
||||
>fileName : string
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
>getDefaultLibFilename : (options: CompilerOptions) => string
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
>getDefaultLibFileName : (options: CompilerOptions) => string
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
@@ -4285,13 +4241,9 @@ declare module "typescript" {
|
||||
>getCancellationToken : () => CancellationToken
|
||||
>CancellationToken : CancellationToken
|
||||
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
>writeFile : (filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
|
||||
>filename : string
|
||||
>data : string
|
||||
>writeByteOrderMark : boolean
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
writeFile: WriteFileCallback;
|
||||
>writeFile : WriteFileCallback
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
@@ -4539,19 +4491,14 @@ declare module "typescript" {
|
||||
>SyntaxKind : SyntaxKind
|
||||
>NodeFlags : NodeFlags
|
||||
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>newText : string
|
||||
>textChangeRange : TextChangeRange
|
||||
>TextChangeRange : TextChangeRange
|
||||
>aggressiveChecks : boolean
|
||||
>SourceFile : SourceFile
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
@@ -4559,9 +4506,9 @@ declare module "typescript" {
|
||||
>node : Node
|
||||
>Node : Node
|
||||
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
>createSourceFile : (filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean) => SourceFile
|
||||
>filename : string
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean) => SourceFile
|
||||
>fileName : string
|
||||
>sourceText : string
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
@@ -4593,8 +4540,20 @@ declare module "typescript" {
|
||||
>CompilerOptions : CompilerOptions
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
>createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
>getPreEmitDiagnostics : (program: Program) => Diagnostic[]
|
||||
>program : Program
|
||||
>Program : Program
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string
|
||||
>messageText : string | DiagnosticMessageChain
|
||||
>DiagnosticMessageChain : DiagnosticMessageChain
|
||||
>newLine : string
|
||||
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program
|
||||
>rootNames : string[]
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
@@ -4789,10 +4748,6 @@ declare module "typescript" {
|
||||
>line : number
|
||||
>character : number
|
||||
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
>getSyntacticDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
>newText : string
|
||||
@@ -4885,8 +4840,8 @@ declare module "typescript" {
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
>getDefaultLibFilename : (options: CompilerOptions) => string
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
>getDefaultLibFileName : (options: CompilerOptions) => string
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
@@ -5075,9 +5030,9 @@ declare module "typescript" {
|
||||
>getProgram : () => Program
|
||||
>Program : Program
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
dispose(): void;
|
||||
@@ -5473,6 +5428,9 @@ declare module "typescript" {
|
||||
isMemberCompletion: boolean;
|
||||
>isMemberCompletion : boolean
|
||||
|
||||
isNewIdentifierLocation: boolean;
|
||||
>isNewIdentifierLocation : boolean
|
||||
|
||||
entries: CompletionEntry[];
|
||||
>entries : CompletionEntry[]
|
||||
>CompletionEntry : CompletionEntry
|
||||
@@ -5540,9 +5498,8 @@ declare module "typescript" {
|
||||
>outputFiles : OutputFile[]
|
||||
>OutputFile : OutputFile
|
||||
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
>emitOutputStatus : EmitReturnStatus
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
emitSkipped: boolean;
|
||||
>emitSkipped : boolean
|
||||
}
|
||||
const enum OutputFileType {
|
||||
>OutputFileType : OutputFileType
|
||||
@@ -5582,6 +5539,15 @@ declare module "typescript" {
|
||||
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
>InDoubleQuoteStringLiteral : EndOfLineState
|
||||
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
>InTemplateHeadOrNoSubstitutionTemplate : EndOfLineState
|
||||
|
||||
InTemplateMiddleOrTail = 5,
|
||||
>InTemplateMiddleOrTail : EndOfLineState
|
||||
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
>InTemplateSubstitutionPosition : EndOfLineState
|
||||
}
|
||||
enum TokenClass {
|
||||
>TokenClass : TokenClass
|
||||
@@ -5637,12 +5603,31 @@ declare module "typescript" {
|
||||
interface Classifier {
|
||||
>Classifier : Classifier
|
||||
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
>getClassificationsForLine : (text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean) => ClassificationResult
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
>getClassificationsForLine : (text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean) => ClassificationResult
|
||||
>text : string
|
||||
>lexState : EndOfLineState
|
||||
>EndOfLineState : EndOfLineState
|
||||
>classifyKeywordsInGenerics : boolean
|
||||
>syntacticClassifierAbsent : boolean
|
||||
>ClassificationResult : ClassificationResult
|
||||
}
|
||||
/**
|
||||
@@ -5664,11 +5649,11 @@ declare module "typescript" {
|
||||
>DocumentRegistry : DocumentRegistry
|
||||
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -5677,9 +5662,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
>acquireDocument : (filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string) => SourceFile
|
||||
>filename : string
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
>acquireDocument : (fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string) => SourceFile
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5688,7 +5673,7 @@ declare module "typescript" {
|
||||
>SourceFile : SourceFile
|
||||
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -5696,7 +5681,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -5707,11 +5692,11 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateDocument : (sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateDocument : (sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>filename : string
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5727,12 +5712,12 @@ declare module "typescript" {
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
>releaseDocument : (filename: string, compilationSettings: CompilerOptions) => void
|
||||
>filename : string
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
>releaseDocument : (fileName: string, compilationSettings: CompilerOptions) => void
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
}
|
||||
@@ -5932,9 +5917,9 @@ declare module "typescript" {
|
||||
throwIfCancellationRequested(): void;
|
||||
>throwIfCancellationRequested : () => void
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
>createLanguageServiceSourceFile : (filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
|
||||
>filename : string
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
|
||||
>fileName : string
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
>IScriptSnapshot : IScriptSnapshot
|
||||
>scriptTarget : ScriptTarget
|
||||
@@ -5946,8 +5931,8 @@ declare module "typescript" {
|
||||
var disableIncrementalParsing: boolean;
|
||||
>disableIncrementalParsing : boolean
|
||||
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateLanguageServiceSourceFile : (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
>updateLanguageServiceSourceFile : (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5955,6 +5940,7 @@ declare module "typescript" {
|
||||
>version : string
|
||||
>textChangeRange : TextChangeRange
|
||||
>TextChangeRange : TextChangeRange
|
||||
>aggressiveChecks : boolean
|
||||
>SourceFile : SourceFile
|
||||
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
|
||||
@@ -52,14 +52,14 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
|
||||
function report(node: ts.Node, message: string) {
|
||||
var lineChar = sourceFile.getLineAndCharacterFromPosition(node.getStart());
|
||||
console.log(`${sourceFile.filename} (${lineChar.line},${lineChar.character}): ${message}`)
|
||||
console.log(`${sourceFile.fileName} (${lineChar.line},${lineChar.character}): ${message}`)
|
||||
}
|
||||
}
|
||||
|
||||
var filenames = process.argv.slice(2);
|
||||
filenames.forEach(filename => {
|
||||
var 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);
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
|
||||
// delint it
|
||||
delint(sourceFile);
|
||||
@@ -744,7 +744,7 @@ declare module "typescript" {
|
||||
exportName: Identifier;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
@@ -752,34 +752,46 @@ declare module "typescript" {
|
||||
interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {
|
||||
path: string;
|
||||
name: string;
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node;
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
}
|
||||
interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getTypeChecker(): TypeChecker;
|
||||
getCommonSourceDirectory(): string;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
emittedLine: number;
|
||||
@@ -800,33 +812,22 @@ declare module "typescript" {
|
||||
sourceMapMappings: string;
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
Succeeded = 0,
|
||||
AllOutputGenerationSkipped = 1,
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
DeclarationGenerationSkipped = 3,
|
||||
EmitErrorsEncountered = 4,
|
||||
CompilerOptionsErrors = 5,
|
||||
enum ExitStatus {
|
||||
Success = 0,
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[];
|
||||
}
|
||||
interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -850,7 +851,7 @@ declare module "typescript" {
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
@@ -916,15 +917,13 @@ declare module "typescript" {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
const enum SymbolFlags {
|
||||
@@ -1171,7 +1170,7 @@ declare module "typescript" {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
}
|
||||
@@ -1230,7 +1229,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
interface CommandLineOption {
|
||||
@@ -1372,10 +1371,10 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1439,10 +1438,9 @@ declare module "typescript" {
|
||||
function createNode(kind: SyntaxKind): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function modifierToFlag(token: SyntaxKind): NodeFlags;
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function isLeftHandSideExpression(expr: Expression): boolean;
|
||||
function isAssignmentOperator(token: SyntaxKind): boolean;
|
||||
}
|
||||
@@ -1451,7 +1449,9 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
}
|
||||
declare module "typescript" {
|
||||
var servicesVersion: string;
|
||||
@@ -1503,7 +1503,6 @@ declare module "typescript" {
|
||||
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
|
||||
getLineStarts(): number[];
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
}
|
||||
/**
|
||||
@@ -1542,7 +1541,7 @@ declare module "typescript" {
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
log?(s: string): void;
|
||||
trace?(s: string): void;
|
||||
error?(s: string): void;
|
||||
@@ -1576,7 +1575,7 @@ declare module "typescript" {
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
getProgram(): Program;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
dispose(): void;
|
||||
}
|
||||
interface ClassifiedSpan {
|
||||
@@ -1726,6 +1725,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
interface CompletionEntry {
|
||||
@@ -1755,7 +1755,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
}
|
||||
const enum OutputFileType {
|
||||
JavaScript = 0,
|
||||
@@ -1772,6 +1772,9 @@ declare module "typescript" {
|
||||
InMultiLineCommentTrivia = 1,
|
||||
InSingleQuoteStringLiteral = 2,
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
InTemplateMiddleOrTail = 5,
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
}
|
||||
enum TokenClass {
|
||||
Punctuation = 0,
|
||||
@@ -1793,7 +1796,26 @@ declare module "typescript" {
|
||||
classification: TokenClass;
|
||||
}
|
||||
interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
}
|
||||
/**
|
||||
* The document registry represents a store of SourceFile objects that can be shared between
|
||||
@@ -1812,11 +1834,11 @@ declare module "typescript" {
|
||||
*/
|
||||
interface DocumentRegistry {
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1825,9 +1847,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -1835,7 +1857,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1846,17 +1868,17 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
/**
|
||||
* Informs the DocumentRegistry that a file is not needed any longer.
|
||||
*
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
}
|
||||
class ScriptElementKind {
|
||||
static unknown: string;
|
||||
@@ -1927,9 +1949,9 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
|
||||
@@ -1982,14 +2004,14 @@ function delint(sourceFile) {
|
||||
}
|
||||
function report(node, message) {
|
||||
var lineChar = sourceFile.getLineAndCharacterFromPosition(node.getStart());
|
||||
console.log(sourceFile.filename + " (" + lineChar.line + "," + lineChar.character + "): " + message);
|
||||
console.log(sourceFile.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + message);
|
||||
}
|
||||
}
|
||||
exports.delint = delint;
|
||||
var filenames = process.argv.slice(2);
|
||||
filenames.forEach(function (filename) {
|
||||
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, fs.readFileSync(fileName).toString(), 2 /* ES6 */, true);
|
||||
// delint it
|
||||
delint(sourceFile);
|
||||
});
|
||||
|
||||
@@ -235,14 +235,14 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
>node : ts.Node
|
||||
>getStart : (sourceFile?: ts.SourceFile) => number
|
||||
|
||||
console.log(`${sourceFile.filename} (${lineChar.line},${lineChar.character}): ${message}`)
|
||||
>console.log(`${sourceFile.filename} (${lineChar.line},${lineChar.character}): ${message}`) : any
|
||||
console.log(`${sourceFile.fileName} (${lineChar.line},${lineChar.character}): ${message}`)
|
||||
>console.log(`${sourceFile.fileName} (${lineChar.line},${lineChar.character}): ${message}`) : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>sourceFile.filename : string
|
||||
>sourceFile.fileName : string
|
||||
>sourceFile : ts.SourceFile
|
||||
>filename : string
|
||||
>fileName : string
|
||||
>lineChar.line : number
|
||||
>lineChar : ts.LineAndCharacter
|
||||
>line : number
|
||||
@@ -253,8 +253,8 @@ export function delint(sourceFile: ts.SourceFile) {
|
||||
}
|
||||
}
|
||||
|
||||
var filenames = process.argv.slice(2);
|
||||
>filenames : any
|
||||
var fileNames = process.argv.slice(2);
|
||||
>fileNames : any
|
||||
>process.argv.slice(2) : any
|
||||
>process.argv.slice : any
|
||||
>process.argv : any
|
||||
@@ -262,29 +262,29 @@ var filenames = process.argv.slice(2);
|
||||
>argv : any
|
||||
>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 : any
|
||||
>filenames : 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 : 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 : 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 : any
|
||||
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(filename, fs.readFileSync(filename).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
|
||||
var sourceFile = ts.createSourceFile(fileName, fs.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: string, sourceText: string, languageVersion: ts.ScriptTarget, setParentNodes?: boolean) => ts.SourceFile
|
||||
>ts.createSourceFile(fileName, fs.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
|
||||
>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 : any
|
||||
>filename : any
|
||||
>fileName : any
|
||||
>toString : any
|
||||
>ts.ScriptTarget.ES6 : ts.ScriptTarget
|
||||
>ts.ScriptTarget : typeof ts.ScriptTarget
|
||||
@@ -2310,8 +2310,8 @@ declare module "typescript" {
|
||||
>FileReference : FileReference
|
||||
>TextRange : TextRange
|
||||
|
||||
filename: string;
|
||||
>filename : string
|
||||
fileName: string;
|
||||
>fileName : string
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
>CommentRange : CommentRange
|
||||
@@ -2333,15 +2333,22 @@ declare module "typescript" {
|
||||
>endOfFileToken : Node
|
||||
>Node : Node
|
||||
|
||||
filename: string;
|
||||
>filename : string
|
||||
fileName: string;
|
||||
>fileName : string
|
||||
|
||||
text: string;
|
||||
>text : string
|
||||
|
||||
amdDependencies: string[];
|
||||
>amdDependencies : string[]
|
||||
amdDependencies: {
|
||||
>amdDependencies : { path: string; name: string; }[]
|
||||
|
||||
path: string;
|
||||
>path : string
|
||||
|
||||
name: string;
|
||||
>name : string
|
||||
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
>amdModuleName : string
|
||||
|
||||
@@ -2356,15 +2363,6 @@ declare module "typescript" {
|
||||
>externalModuleIndicator : Node
|
||||
>Node : Node
|
||||
|
||||
nodeCount: number;
|
||||
>nodeCount : number
|
||||
|
||||
identifierCount: number;
|
||||
>identifierCount : number
|
||||
|
||||
symbolCount: number;
|
||||
>symbolCount : number
|
||||
|
||||
languageVersion: ScriptTarget;
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
@@ -2380,13 +2378,23 @@ declare module "typescript" {
|
||||
>getCompilerOptions : () => CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
>fileName : string
|
||||
>data : string
|
||||
>writeByteOrderMark : boolean
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
>Program : Program
|
||||
@@ -2396,12 +2404,26 @@ declare module "typescript" {
|
||||
>getSourceFiles : () => SourceFile[]
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getCompilerHost(): CompilerHost;
|
||||
>getCompilerHost : () => CompilerHost
|
||||
>CompilerHost : CompilerHost
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
|
||||
>targetSourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>writeFile : WriteFileCallback
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
>EmitResult : EmitResult
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
@@ -2410,30 +2432,24 @@ declare module "typescript" {
|
||||
>getGlobalDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
>getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
>getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
|
||||
>produceDiagnostics : boolean
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getTypeChecker(): TypeChecker;
|
||||
>getTypeChecker : () => TypeChecker
|
||||
>TypeChecker : TypeChecker
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
>getCommonSourceDirectory : () => string
|
||||
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
>emitFiles : (targetSourceFile?: SourceFile) => EmitResult
|
||||
>targetSourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>EmitResult : EmitResult
|
||||
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
>isEmitBlocked : (sourceFile?: SourceFile) => boolean
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
>SourceMapSpan : SourceMapSpan
|
||||
@@ -2487,33 +2503,23 @@ declare module "typescript" {
|
||||
>sourceMapDecodedMappings : SourceMapSpan[]
|
||||
>SourceMapSpan : SourceMapSpan
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
enum ExitStatus {
|
||||
>ExitStatus : ExitStatus
|
||||
|
||||
Succeeded = 0,
|
||||
>Succeeded : EmitReturnStatus
|
||||
Success = 0,
|
||||
>Success : ExitStatus
|
||||
|
||||
AllOutputGenerationSkipped = 1,
|
||||
>AllOutputGenerationSkipped : EmitReturnStatus
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
>DiagnosticsPresent_OutputsSkipped : ExitStatus
|
||||
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
>JSGeneratedWithSemanticErrors : EmitReturnStatus
|
||||
|
||||
DeclarationGenerationSkipped = 3,
|
||||
>DeclarationGenerationSkipped : EmitReturnStatus
|
||||
|
||||
EmitErrorsEncountered = 4,
|
||||
>EmitErrorsEncountered : EmitReturnStatus
|
||||
|
||||
CompilerOptionsErrors = 5,
|
||||
>CompilerOptionsErrors : EmitReturnStatus
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
>DiagnosticsPresent_OutputsGenerated : ExitStatus
|
||||
}
|
||||
interface EmitResult {
|
||||
>EmitResult : EmitResult
|
||||
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
>emitResultStatus : EmitReturnStatus
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
emitSkipped: boolean;
|
||||
>emitSkipped : boolean
|
||||
|
||||
diagnostics: Diagnostic[];
|
||||
>diagnostics : Diagnostic[]
|
||||
@@ -2530,48 +2536,18 @@ declare module "typescript" {
|
||||
>getCompilerOptions : () => CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
getCompilerHost(): CompilerHost;
|
||||
>getCompilerHost : () => CompilerHost
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
getSourceFiles(): SourceFile[];
|
||||
>getSourceFiles : () => SourceFile[]
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
}
|
||||
interface TypeChecker {
|
||||
>TypeChecker : TypeChecker
|
||||
|
||||
getEmitResolver(): EmitResolver;
|
||||
>getEmitResolver : () => EmitResolver
|
||||
>EmitResolver : EmitResolver
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
>getGlobalDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getNodeCount(): number;
|
||||
>getNodeCount : () => number
|
||||
|
||||
getIdentifierCount(): number;
|
||||
>getIdentifierCount : () => number
|
||||
|
||||
getSymbolCount(): number;
|
||||
>getSymbolCount : () => number
|
||||
|
||||
getTypeCount(): number;
|
||||
>getTypeCount : () => number
|
||||
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
|
||||
>symbol : Symbol
|
||||
@@ -2721,10 +2697,12 @@ declare module "typescript" {
|
||||
>symbol : Symbol
|
||||
>Symbol : Symbol
|
||||
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
>getEnumMemberValue : (node: EnumMember) => number
|
||||
>node : EnumMember
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
|
||||
>EnumMember : EnumMember
|
||||
>PropertyAccessExpression : PropertyAccessExpression
|
||||
>ElementAccessExpression : ElementAccessExpression
|
||||
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
|
||||
@@ -3011,16 +2989,6 @@ declare module "typescript" {
|
||||
>Node : Node
|
||||
>NodeCheckFlags : NodeCheckFlags
|
||||
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
>getEnumMemberValue : (node: EnumMember) => number
|
||||
>node : EnumMember
|
||||
>EnumMember : EnumMember
|
||||
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
>hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
>isDeclarationVisible : (node: Declaration) => boolean
|
||||
>node : Declaration
|
||||
@@ -3072,9 +3040,10 @@ declare module "typescript" {
|
||||
>Node : Node
|
||||
>SymbolVisibilityResult : SymbolVisibilityResult
|
||||
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
|
||||
>EnumMember : EnumMember
|
||||
>PropertyAccessExpression : PropertyAccessExpression
|
||||
>ElementAccessExpression : ElementAccessExpression
|
||||
|
||||
@@ -3815,8 +3784,9 @@ declare module "typescript" {
|
||||
length: number;
|
||||
>length : number
|
||||
|
||||
messageText: string;
|
||||
>messageText : string
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
>messageText : string | DiagnosticMessageChain
|
||||
>DiagnosticMessageChain : DiagnosticMessageChain
|
||||
|
||||
category: DiagnosticCategory;
|
||||
>category : DiagnosticCategory
|
||||
@@ -3978,8 +3948,8 @@ declare module "typescript" {
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
filenames: string[];
|
||||
>filenames : string[]
|
||||
fileNames: string[];
|
||||
>fileNames : string[]
|
||||
|
||||
errors: Diagnostic[];
|
||||
>errors : Diagnostic[]
|
||||
@@ -4397,17 +4367,17 @@ declare module "typescript" {
|
||||
interface CompilerHost {
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
>getSourceFile : (filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
>getSourceFile : (fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) => SourceFile
|
||||
>fileName : string
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
>getDefaultLibFilename : (options: CompilerOptions) => string
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
>getDefaultLibFileName : (options: CompilerOptions) => string
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
@@ -4415,13 +4385,9 @@ declare module "typescript" {
|
||||
>getCancellationToken : () => CancellationToken
|
||||
>CancellationToken : CancellationToken
|
||||
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
>writeFile : (filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
|
||||
>filename : string
|
||||
>data : string
|
||||
>writeByteOrderMark : boolean
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
writeFile: WriteFileCallback;
|
||||
>writeFile : WriteFileCallback
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
@@ -4669,19 +4635,14 @@ declare module "typescript" {
|
||||
>SyntaxKind : SyntaxKind
|
||||
>NodeFlags : NodeFlags
|
||||
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>newText : string
|
||||
>textChangeRange : TextChangeRange
|
||||
>TextChangeRange : TextChangeRange
|
||||
>aggressiveChecks : boolean
|
||||
>SourceFile : SourceFile
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
@@ -4689,9 +4650,9 @@ declare module "typescript" {
|
||||
>node : Node
|
||||
>Node : Node
|
||||
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
>createSourceFile : (filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean) => SourceFile
|
||||
>filename : string
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean) => SourceFile
|
||||
>fileName : string
|
||||
>sourceText : string
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
@@ -4723,8 +4684,20 @@ declare module "typescript" {
|
||||
>CompilerOptions : CompilerOptions
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
>createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
>getPreEmitDiagnostics : (program: Program) => Diagnostic[]
|
||||
>program : Program
|
||||
>Program : Program
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string
|
||||
>messageText : string | DiagnosticMessageChain
|
||||
>DiagnosticMessageChain : DiagnosticMessageChain
|
||||
>newLine : string
|
||||
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program
|
||||
>rootNames : string[]
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
@@ -4919,10 +4892,6 @@ declare module "typescript" {
|
||||
>line : number
|
||||
>character : number
|
||||
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
>getSyntacticDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
>newText : string
|
||||
@@ -5015,8 +4984,8 @@ declare module "typescript" {
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
>getDefaultLibFilename : (options: CompilerOptions) => string
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
>getDefaultLibFileName : (options: CompilerOptions) => string
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
@@ -5205,9 +5174,9 @@ declare module "typescript" {
|
||||
>getProgram : () => Program
|
||||
>Program : Program
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
dispose(): void;
|
||||
@@ -5603,6 +5572,9 @@ declare module "typescript" {
|
||||
isMemberCompletion: boolean;
|
||||
>isMemberCompletion : boolean
|
||||
|
||||
isNewIdentifierLocation: boolean;
|
||||
>isNewIdentifierLocation : boolean
|
||||
|
||||
entries: CompletionEntry[];
|
||||
>entries : CompletionEntry[]
|
||||
>CompletionEntry : CompletionEntry
|
||||
@@ -5670,9 +5642,8 @@ declare module "typescript" {
|
||||
>outputFiles : OutputFile[]
|
||||
>OutputFile : OutputFile
|
||||
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
>emitOutputStatus : EmitReturnStatus
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
emitSkipped: boolean;
|
||||
>emitSkipped : boolean
|
||||
}
|
||||
const enum OutputFileType {
|
||||
>OutputFileType : OutputFileType
|
||||
@@ -5712,6 +5683,15 @@ declare module "typescript" {
|
||||
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
>InDoubleQuoteStringLiteral : EndOfLineState
|
||||
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
>InTemplateHeadOrNoSubstitutionTemplate : EndOfLineState
|
||||
|
||||
InTemplateMiddleOrTail = 5,
|
||||
>InTemplateMiddleOrTail : EndOfLineState
|
||||
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
>InTemplateSubstitutionPosition : EndOfLineState
|
||||
}
|
||||
enum TokenClass {
|
||||
>TokenClass : TokenClass
|
||||
@@ -5767,12 +5747,31 @@ declare module "typescript" {
|
||||
interface Classifier {
|
||||
>Classifier : Classifier
|
||||
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
>getClassificationsForLine : (text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean) => ClassificationResult
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
>getClassificationsForLine : (text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean) => ClassificationResult
|
||||
>text : string
|
||||
>lexState : EndOfLineState
|
||||
>EndOfLineState : EndOfLineState
|
||||
>classifyKeywordsInGenerics : boolean
|
||||
>syntacticClassifierAbsent : boolean
|
||||
>ClassificationResult : ClassificationResult
|
||||
}
|
||||
/**
|
||||
@@ -5794,11 +5793,11 @@ declare module "typescript" {
|
||||
>DocumentRegistry : DocumentRegistry
|
||||
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -5807,9 +5806,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
>acquireDocument : (filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string) => SourceFile
|
||||
>filename : string
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
>acquireDocument : (fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string) => SourceFile
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5818,7 +5817,7 @@ declare module "typescript" {
|
||||
>SourceFile : SourceFile
|
||||
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -5826,7 +5825,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -5837,11 +5836,11 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateDocument : (sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateDocument : (sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>filename : string
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5857,12 +5856,12 @@ declare module "typescript" {
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
>releaseDocument : (filename: string, compilationSettings: CompilerOptions) => void
|
||||
>filename : string
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
>releaseDocument : (fileName: string, compilationSettings: CompilerOptions) => void
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
}
|
||||
@@ -6062,9 +6061,9 @@ declare module "typescript" {
|
||||
throwIfCancellationRequested(): void;
|
||||
>throwIfCancellationRequested : () => void
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
>createLanguageServiceSourceFile : (filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
|
||||
>filename : string
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
|
||||
>fileName : string
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
>IScriptSnapshot : IScriptSnapshot
|
||||
>scriptTarget : ScriptTarget
|
||||
@@ -6076,8 +6075,8 @@ declare module "typescript" {
|
||||
var disableIncrementalParsing: boolean;
|
||||
>disableIncrementalParsing : boolean
|
||||
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateLanguageServiceSourceFile : (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
>updateLanguageServiceSourceFile : (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -6085,6 +6084,7 @@ declare module "typescript" {
|
||||
>version : string
|
||||
>textChangeRange : TextChangeRange
|
||||
>TextChangeRange : TextChangeRange
|
||||
>aggressiveChecks : boolean
|
||||
>SourceFile : SourceFile
|
||||
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
|
||||
@@ -12,6 +12,7 @@ declare var process: any;
|
||||
declare var console: any;
|
||||
declare var fs: any;
|
||||
declare var path: any;
|
||||
declare var os: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
|
||||
@@ -27,16 +28,16 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
|
||||
// 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;
|
||||
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",
|
||||
getDefaultLibFileName: () => "lib.d.ts",
|
||||
useCaseSensitiveFileNames: () => false,
|
||||
getCanonicalFileName: (filename) => filename,
|
||||
getCanonicalFileName: (fileName) => fileName,
|
||||
getCurrentDirectory: () => "",
|
||||
getNewLine: () => "\n"
|
||||
};
|
||||
@@ -45,18 +46,17 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost);
|
||||
|
||||
// Query for early errors
|
||||
var errors = program.getDiagnostics();
|
||||
// Do not generate code in the presence of early errors
|
||||
if (!errors.length) {
|
||||
// Type check and get semantic errors
|
||||
var checker = program.getTypeChecker(true);
|
||||
errors = checker.getDiagnostics();
|
||||
// Generate output
|
||||
program.emitFiles();
|
||||
}
|
||||
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.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; })
|
||||
errors: errors.map(function (e) {
|
||||
return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): "
|
||||
+ ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -745,7 +745,7 @@ declare module "typescript" {
|
||||
exportName: Identifier;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
@@ -753,34 +753,46 @@ declare module "typescript" {
|
||||
interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {
|
||||
path: string;
|
||||
name: string;
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node;
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
}
|
||||
interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getTypeChecker(): TypeChecker;
|
||||
getCommonSourceDirectory(): string;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
emittedLine: number;
|
||||
@@ -801,33 +813,22 @@ declare module "typescript" {
|
||||
sourceMapMappings: string;
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
Succeeded = 0,
|
||||
AllOutputGenerationSkipped = 1,
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
DeclarationGenerationSkipped = 3,
|
||||
EmitErrorsEncountered = 4,
|
||||
CompilerOptionsErrors = 5,
|
||||
enum ExitStatus {
|
||||
Success = 0,
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[];
|
||||
}
|
||||
interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -851,7 +852,7 @@ declare module "typescript" {
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
@@ -917,15 +918,13 @@ declare module "typescript" {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
const enum SymbolFlags {
|
||||
@@ -1172,7 +1171,7 @@ declare module "typescript" {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
}
|
||||
@@ -1231,7 +1230,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
interface CommandLineOption {
|
||||
@@ -1373,10 +1372,10 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1440,10 +1439,9 @@ declare module "typescript" {
|
||||
function createNode(kind: SyntaxKind): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function modifierToFlag(token: SyntaxKind): NodeFlags;
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function isLeftHandSideExpression(expr: Expression): boolean;
|
||||
function isAssignmentOperator(token: SyntaxKind): boolean;
|
||||
}
|
||||
@@ -1452,7 +1450,9 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
}
|
||||
declare module "typescript" {
|
||||
var servicesVersion: string;
|
||||
@@ -1504,7 +1504,6 @@ declare module "typescript" {
|
||||
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
|
||||
getLineStarts(): number[];
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
}
|
||||
/**
|
||||
@@ -1543,7 +1542,7 @@ declare module "typescript" {
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
log?(s: string): void;
|
||||
trace?(s: string): void;
|
||||
error?(s: string): void;
|
||||
@@ -1577,7 +1576,7 @@ declare module "typescript" {
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
getProgram(): Program;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
dispose(): void;
|
||||
}
|
||||
interface ClassifiedSpan {
|
||||
@@ -1727,6 +1726,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
interface CompletionEntry {
|
||||
@@ -1756,7 +1756,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
}
|
||||
const enum OutputFileType {
|
||||
JavaScript = 0,
|
||||
@@ -1773,6 +1773,9 @@ declare module "typescript" {
|
||||
InMultiLineCommentTrivia = 1,
|
||||
InSingleQuoteStringLiteral = 2,
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
InTemplateMiddleOrTail = 5,
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
}
|
||||
enum TokenClass {
|
||||
Punctuation = 0,
|
||||
@@ -1794,7 +1797,26 @@ declare module "typescript" {
|
||||
classification: TokenClass;
|
||||
}
|
||||
interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
}
|
||||
/**
|
||||
* The document registry represents a store of SourceFile objects that can be shared between
|
||||
@@ -1813,11 +1835,11 @@ declare module "typescript" {
|
||||
*/
|
||||
interface DocumentRegistry {
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1826,9 +1848,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -1836,7 +1858,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1847,17 +1869,17 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
/**
|
||||
* Informs the DocumentRegistry that a file is not needed any longer.
|
||||
*
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
}
|
||||
class ScriptElementKind {
|
||||
static unknown: string;
|
||||
@@ -1928,9 +1950,9 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
|
||||
@@ -1962,34 +1984,28 @@ function transform(contents, compilerOptions) {
|
||||
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;
|
||||
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"; },
|
||||
getDefaultLibFileName: function () { return "lib.d.ts"; },
|
||||
useCaseSensitiveFileNames: function () { return false; },
|
||||
getCanonicalFileName: function (filename) { return filename; },
|
||||
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 = program.getDiagnostics();
|
||||
// Do not generate code in the presence of early errors
|
||||
if (!errors.length) {
|
||||
// Type check and get semantic errors
|
||||
var checker = program.getTypeChecker(true);
|
||||
errors = checker.getDiagnostics();
|
||||
// Generate output
|
||||
program.emitFiles();
|
||||
}
|
||||
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.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText;
|
||||
return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ declare var fs: any;
|
||||
declare var path: any;
|
||||
>path : any
|
||||
|
||||
declare var os: any;
|
||||
>os : any
|
||||
|
||||
import ts = require("typescript");
|
||||
>ts : typeof ts
|
||||
|
||||
@@ -60,32 +63,32 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
|
||||
// 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; }
|
||||
>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
|
||||
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
|
||||
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
|
||||
>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.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
|
||||
>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
|
||||
>fileName : any
|
||||
>target : any
|
||||
>undefined : undefined
|
||||
|
||||
@@ -111,19 +114,19 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
>writeByteOrderMark : any
|
||||
|
||||
},
|
||||
getDefaultLibFilename: () => "lib.d.ts",
|
||||
>getDefaultLibFilename : () => string
|
||||
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
|
||||
getCanonicalFileName: (fileName) => fileName,
|
||||
>getCanonicalFileName : (fileName: any) => any
|
||||
>(fileName) => fileName : (fileName: any) => any
|
||||
>fileName : any
|
||||
>fileName : any
|
||||
|
||||
getCurrentDirectory: () => "",
|
||||
>getCurrentDirectory : () => string
|
||||
@@ -139,75 +142,66 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
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.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
|
||||
>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; }
|
||||
>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 = program.getDiagnostics();
|
||||
var errors = ts.getPreEmitDiagnostics(program);
|
||||
>errors : ts.Diagnostic[]
|
||||
>program.getDiagnostics() : ts.Diagnostic[]
|
||||
>program.getDiagnostics : (sourceFile?: ts.SourceFile) => 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
|
||||
>getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
|
||||
|
||||
// Do not generate code in the presence of early errors
|
||||
if (!errors.length) {
|
||||
>!errors.length : boolean
|
||||
>errors.length : number
|
||||
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[]
|
||||
>length : number
|
||||
|
||||
// Type check and get semantic errors
|
||||
var checker = program.getTypeChecker(true);
|
||||
>checker : ts.TypeChecker
|
||||
>program.getTypeChecker(true) : ts.TypeChecker
|
||||
>program.getTypeChecker : (produceDiagnostics: boolean) => ts.TypeChecker
|
||||
>program : ts.Program
|
||||
>getTypeChecker : (produceDiagnostics: boolean) => ts.TypeChecker
|
||||
|
||||
errors = checker.getDiagnostics();
|
||||
>errors = checker.getDiagnostics() : 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[]
|
||||
>checker.getDiagnostics() : ts.Diagnostic[]
|
||||
>checker.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
|
||||
>checker : ts.TypeChecker
|
||||
>getDiagnostics : (sourceFile?: ts.SourceFile) => 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[]
|
||||
|
||||
// Generate output
|
||||
program.emitFiles();
|
||||
>program.emitFiles() : ts.EmitResult
|
||||
>program.emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
|
||||
>program : ts.Program
|
||||
>emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
|
||||
}
|
||||
return {
|
||||
>{ outputs: outputs, errors: errors.map(function (e) { return e.file.filename + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) } : { outputs: any[]; errors: string[]; }
|
||||
>{ outputs: outputs, errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) } : { outputs: any[]; errors: string[]; }
|
||||
|
||||
outputs: outputs,
|
||||
>outputs : any[]
|
||||
>outputs : any[]
|
||||
|
||||
errors: errors.map(function (e) { return e.file.filename + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; })
|
||||
errors: errors.map(function (e) {
|
||||
>errors : string[]
|
||||
>errors.map(function (e) { return e.file.filename + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) : string[]
|
||||
>errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + 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.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; } : (e: ts.Diagnostic) => string
|
||||
>function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); } : (e: ts.Diagnostic) => string
|
||||
>e : ts.Diagnostic
|
||||
>e.file.filename + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText : string
|
||||
>e.file.filename + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " : string
|
||||
>e.file.filename + "(" + e.file.getLineAndCharacterFromPosition(e.start).line : string
|
||||
>e.file.filename + "(" : string
|
||||
>e.file.filename : string
|
||||
|
||||
return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): "
|
||||
>e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string
|
||||
>e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " : string
|
||||
>e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line : string
|
||||
>e.file.fileName + "(" : string
|
||||
>e.file.fileName : string
|
||||
>e.file : ts.SourceFile
|
||||
>e : ts.Diagnostic
|
||||
>file : ts.SourceFile
|
||||
>filename : string
|
||||
>fileName : string
|
||||
>e.file.getLineAndCharacterFromPosition(e.start).line : number
|
||||
>e.file.getLineAndCharacterFromPosition(e.start) : ts.LineAndCharacter
|
||||
>e.file.getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter
|
||||
@@ -219,10 +213,20 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
|
||||
>e : ts.Diagnostic
|
||||
>start : number
|
||||
>line : number
|
||||
>e.messageText : string
|
||||
>e : ts.Diagnostic
|
||||
>messageText : string
|
||||
|
||||
+ 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
|
||||
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2258,8 +2262,8 @@ declare module "typescript" {
|
||||
>FileReference : FileReference
|
||||
>TextRange : TextRange
|
||||
|
||||
filename: string;
|
||||
>filename : string
|
||||
fileName: string;
|
||||
>fileName : string
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
>CommentRange : CommentRange
|
||||
@@ -2281,15 +2285,22 @@ declare module "typescript" {
|
||||
>endOfFileToken : Node
|
||||
>Node : Node
|
||||
|
||||
filename: string;
|
||||
>filename : string
|
||||
fileName: string;
|
||||
>fileName : string
|
||||
|
||||
text: string;
|
||||
>text : string
|
||||
|
||||
amdDependencies: string[];
|
||||
>amdDependencies : string[]
|
||||
amdDependencies: {
|
||||
>amdDependencies : { path: string; name: string; }[]
|
||||
|
||||
path: string;
|
||||
>path : string
|
||||
|
||||
name: string;
|
||||
>name : string
|
||||
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
>amdModuleName : string
|
||||
|
||||
@@ -2304,15 +2315,6 @@ declare module "typescript" {
|
||||
>externalModuleIndicator : Node
|
||||
>Node : Node
|
||||
|
||||
nodeCount: number;
|
||||
>nodeCount : number
|
||||
|
||||
identifierCount: number;
|
||||
>identifierCount : number
|
||||
|
||||
symbolCount: number;
|
||||
>symbolCount : number
|
||||
|
||||
languageVersion: ScriptTarget;
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
@@ -2328,13 +2330,23 @@ declare module "typescript" {
|
||||
>getCompilerOptions : () => CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
>fileName : string
|
||||
>data : string
|
||||
>writeByteOrderMark : boolean
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
>Program : Program
|
||||
@@ -2344,12 +2356,26 @@ declare module "typescript" {
|
||||
>getSourceFiles : () => SourceFile[]
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getCompilerHost(): CompilerHost;
|
||||
>getCompilerHost : () => CompilerHost
|
||||
>CompilerHost : CompilerHost
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
|
||||
>targetSourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>writeFile : WriteFileCallback
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
>EmitResult : EmitResult
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
@@ -2358,30 +2384,24 @@ declare module "typescript" {
|
||||
>getGlobalDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
>getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
>getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
|
||||
>produceDiagnostics : boolean
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getTypeChecker(): TypeChecker;
|
||||
>getTypeChecker : () => TypeChecker
|
||||
>TypeChecker : TypeChecker
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
>getCommonSourceDirectory : () => string
|
||||
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
>emitFiles : (targetSourceFile?: SourceFile) => EmitResult
|
||||
>targetSourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>EmitResult : EmitResult
|
||||
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
>isEmitBlocked : (sourceFile?: SourceFile) => boolean
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
>SourceMapSpan : SourceMapSpan
|
||||
@@ -2435,33 +2455,23 @@ declare module "typescript" {
|
||||
>sourceMapDecodedMappings : SourceMapSpan[]
|
||||
>SourceMapSpan : SourceMapSpan
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
enum ExitStatus {
|
||||
>ExitStatus : ExitStatus
|
||||
|
||||
Succeeded = 0,
|
||||
>Succeeded : EmitReturnStatus
|
||||
Success = 0,
|
||||
>Success : ExitStatus
|
||||
|
||||
AllOutputGenerationSkipped = 1,
|
||||
>AllOutputGenerationSkipped : EmitReturnStatus
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
>DiagnosticsPresent_OutputsSkipped : ExitStatus
|
||||
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
>JSGeneratedWithSemanticErrors : EmitReturnStatus
|
||||
|
||||
DeclarationGenerationSkipped = 3,
|
||||
>DeclarationGenerationSkipped : EmitReturnStatus
|
||||
|
||||
EmitErrorsEncountered = 4,
|
||||
>EmitErrorsEncountered : EmitReturnStatus
|
||||
|
||||
CompilerOptionsErrors = 5,
|
||||
>CompilerOptionsErrors : EmitReturnStatus
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
>DiagnosticsPresent_OutputsGenerated : ExitStatus
|
||||
}
|
||||
interface EmitResult {
|
||||
>EmitResult : EmitResult
|
||||
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
>emitResultStatus : EmitReturnStatus
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
emitSkipped: boolean;
|
||||
>emitSkipped : boolean
|
||||
|
||||
diagnostics: Diagnostic[];
|
||||
>diagnostics : Diagnostic[]
|
||||
@@ -2478,48 +2488,18 @@ declare module "typescript" {
|
||||
>getCompilerOptions : () => CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
getCompilerHost(): CompilerHost;
|
||||
>getCompilerHost : () => CompilerHost
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
getSourceFiles(): SourceFile[];
|
||||
>getSourceFiles : () => SourceFile[]
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
}
|
||||
interface TypeChecker {
|
||||
>TypeChecker : TypeChecker
|
||||
|
||||
getEmitResolver(): EmitResolver;
|
||||
>getEmitResolver : () => EmitResolver
|
||||
>EmitResolver : EmitResolver
|
||||
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
>getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
>getGlobalDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
getNodeCount(): number;
|
||||
>getNodeCount : () => number
|
||||
|
||||
getIdentifierCount(): number;
|
||||
>getIdentifierCount : () => number
|
||||
|
||||
getSymbolCount(): number;
|
||||
>getSymbolCount : () => number
|
||||
|
||||
getTypeCount(): number;
|
||||
>getTypeCount : () => number
|
||||
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
|
||||
>symbol : Symbol
|
||||
@@ -2669,10 +2649,12 @@ declare module "typescript" {
|
||||
>symbol : Symbol
|
||||
>Symbol : Symbol
|
||||
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
>getEnumMemberValue : (node: EnumMember) => number
|
||||
>node : EnumMember
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
|
||||
>EnumMember : EnumMember
|
||||
>PropertyAccessExpression : PropertyAccessExpression
|
||||
>ElementAccessExpression : ElementAccessExpression
|
||||
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
|
||||
@@ -2959,16 +2941,6 @@ declare module "typescript" {
|
||||
>Node : Node
|
||||
>NodeCheckFlags : NodeCheckFlags
|
||||
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
>getEnumMemberValue : (node: EnumMember) => number
|
||||
>node : EnumMember
|
||||
>EnumMember : EnumMember
|
||||
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
>hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
>isDeclarationVisible : (node: Declaration) => boolean
|
||||
>node : Declaration
|
||||
@@ -3020,9 +2992,10 @@ declare module "typescript" {
|
||||
>Node : Node
|
||||
>SymbolVisibilityResult : SymbolVisibilityResult
|
||||
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
|
||||
>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
|
||||
>EnumMember : EnumMember
|
||||
>PropertyAccessExpression : PropertyAccessExpression
|
||||
>ElementAccessExpression : ElementAccessExpression
|
||||
|
||||
@@ -3763,8 +3736,9 @@ declare module "typescript" {
|
||||
length: number;
|
||||
>length : number
|
||||
|
||||
messageText: string;
|
||||
>messageText : string
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
>messageText : string | DiagnosticMessageChain
|
||||
>DiagnosticMessageChain : DiagnosticMessageChain
|
||||
|
||||
category: DiagnosticCategory;
|
||||
>category : DiagnosticCategory
|
||||
@@ -3926,8 +3900,8 @@ declare module "typescript" {
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
filenames: string[];
|
||||
>filenames : string[]
|
||||
fileNames: string[];
|
||||
>fileNames : string[]
|
||||
|
||||
errors: Diagnostic[];
|
||||
>errors : Diagnostic[]
|
||||
@@ -4345,17 +4319,17 @@ declare module "typescript" {
|
||||
interface CompilerHost {
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
>getSourceFile : (filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
>getSourceFile : (fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) => SourceFile
|
||||
>fileName : string
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
>getDefaultLibFilename : (options: CompilerOptions) => string
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
>getDefaultLibFileName : (options: CompilerOptions) => string
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
@@ -4363,13 +4337,9 @@ declare module "typescript" {
|
||||
>getCancellationToken : () => CancellationToken
|
||||
>CancellationToken : CancellationToken
|
||||
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
>writeFile : (filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
|
||||
>filename : string
|
||||
>data : string
|
||||
>writeByteOrderMark : boolean
|
||||
>onError : (message: string) => void
|
||||
>message : string
|
||||
writeFile: WriteFileCallback;
|
||||
>writeFile : WriteFileCallback
|
||||
>WriteFileCallback : WriteFileCallback
|
||||
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
@@ -4617,19 +4587,14 @@ declare module "typescript" {
|
||||
>SyntaxKind : SyntaxKind
|
||||
>NodeFlags : NodeFlags
|
||||
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>newText : string
|
||||
>textChangeRange : TextChangeRange
|
||||
>TextChangeRange : TextChangeRange
|
||||
>aggressiveChecks : boolean
|
||||
>SourceFile : SourceFile
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
@@ -4637,9 +4602,9 @@ declare module "typescript" {
|
||||
>node : Node
|
||||
>Node : Node
|
||||
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
>createSourceFile : (filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean) => SourceFile
|
||||
>filename : string
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
>createSourceFile : (fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean) => SourceFile
|
||||
>fileName : string
|
||||
>sourceText : string
|
||||
>languageVersion : ScriptTarget
|
||||
>ScriptTarget : ScriptTarget
|
||||
@@ -4671,8 +4636,20 @@ declare module "typescript" {
|
||||
>CompilerOptions : CompilerOptions
|
||||
>CompilerHost : CompilerHost
|
||||
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
>createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
>getPreEmitDiagnostics : (program: Program) => Diagnostic[]
|
||||
>program : Program
|
||||
>Program : Program
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string
|
||||
>messageText : string | DiagnosticMessageChain
|
||||
>DiagnosticMessageChain : DiagnosticMessageChain
|
||||
>newLine : string
|
||||
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program
|
||||
>rootNames : string[]
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
@@ -4867,10 +4844,6 @@ declare module "typescript" {
|
||||
>line : number
|
||||
>character : number
|
||||
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
>getSyntacticDiagnostics : () => Diagnostic[]
|
||||
>Diagnostic : Diagnostic
|
||||
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
>newText : string
|
||||
@@ -4963,8 +4936,8 @@ declare module "typescript" {
|
||||
getCurrentDirectory(): string;
|
||||
>getCurrentDirectory : () => string
|
||||
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
>getDefaultLibFilename : (options: CompilerOptions) => string
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
>getDefaultLibFileName : (options: CompilerOptions) => string
|
||||
>options : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
|
||||
@@ -5153,9 +5126,9 @@ declare module "typescript" {
|
||||
>getProgram : () => Program
|
||||
>Program : Program
|
||||
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
>getSourceFile : (filename: string) => SourceFile
|
||||
>filename : string
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
>getSourceFile : (fileName: string) => SourceFile
|
||||
>fileName : string
|
||||
>SourceFile : SourceFile
|
||||
|
||||
dispose(): void;
|
||||
@@ -5551,6 +5524,9 @@ declare module "typescript" {
|
||||
isMemberCompletion: boolean;
|
||||
>isMemberCompletion : boolean
|
||||
|
||||
isNewIdentifierLocation: boolean;
|
||||
>isNewIdentifierLocation : boolean
|
||||
|
||||
entries: CompletionEntry[];
|
||||
>entries : CompletionEntry[]
|
||||
>CompletionEntry : CompletionEntry
|
||||
@@ -5618,9 +5594,8 @@ declare module "typescript" {
|
||||
>outputFiles : OutputFile[]
|
||||
>OutputFile : OutputFile
|
||||
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
>emitOutputStatus : EmitReturnStatus
|
||||
>EmitReturnStatus : EmitReturnStatus
|
||||
emitSkipped: boolean;
|
||||
>emitSkipped : boolean
|
||||
}
|
||||
const enum OutputFileType {
|
||||
>OutputFileType : OutputFileType
|
||||
@@ -5660,6 +5635,15 @@ declare module "typescript" {
|
||||
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
>InDoubleQuoteStringLiteral : EndOfLineState
|
||||
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
>InTemplateHeadOrNoSubstitutionTemplate : EndOfLineState
|
||||
|
||||
InTemplateMiddleOrTail = 5,
|
||||
>InTemplateMiddleOrTail : EndOfLineState
|
||||
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
>InTemplateSubstitutionPosition : EndOfLineState
|
||||
}
|
||||
enum TokenClass {
|
||||
>TokenClass : TokenClass
|
||||
@@ -5715,12 +5699,31 @@ declare module "typescript" {
|
||||
interface Classifier {
|
||||
>Classifier : Classifier
|
||||
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
>getClassificationsForLine : (text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean) => ClassificationResult
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
>getClassificationsForLine : (text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean) => ClassificationResult
|
||||
>text : string
|
||||
>lexState : EndOfLineState
|
||||
>EndOfLineState : EndOfLineState
|
||||
>classifyKeywordsInGenerics : boolean
|
||||
>syntacticClassifierAbsent : boolean
|
||||
>ClassificationResult : ClassificationResult
|
||||
}
|
||||
/**
|
||||
@@ -5742,11 +5745,11 @@ declare module "typescript" {
|
||||
>DocumentRegistry : DocumentRegistry
|
||||
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -5755,9 +5758,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
>acquireDocument : (filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string) => SourceFile
|
||||
>filename : string
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
>acquireDocument : (fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string) => SourceFile
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5766,7 +5769,7 @@ declare module "typescript" {
|
||||
>SourceFile : SourceFile
|
||||
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -5774,7 +5777,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -5785,11 +5788,11 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateDocument : (sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateDocument : (sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>filename : string
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -5805,12 +5808,12 @@ declare module "typescript" {
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
>releaseDocument : (filename: string, compilationSettings: CompilerOptions) => void
|
||||
>filename : string
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
>releaseDocument : (fileName: string, compilationSettings: CompilerOptions) => void
|
||||
>fileName : string
|
||||
>compilationSettings : CompilerOptions
|
||||
>CompilerOptions : CompilerOptions
|
||||
}
|
||||
@@ -6010,9 +6013,9 @@ declare module "typescript" {
|
||||
throwIfCancellationRequested(): void;
|
||||
>throwIfCancellationRequested : () => void
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
>createLanguageServiceSourceFile : (filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
|
||||
>filename : string
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
|
||||
>fileName : string
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
>IScriptSnapshot : IScriptSnapshot
|
||||
>scriptTarget : ScriptTarget
|
||||
@@ -6024,8 +6027,8 @@ declare module "typescript" {
|
||||
var disableIncrementalParsing: boolean;
|
||||
>disableIncrementalParsing : boolean
|
||||
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
>updateLanguageServiceSourceFile : (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange) => SourceFile
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
>updateLanguageServiceSourceFile : (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean) => SourceFile
|
||||
>sourceFile : SourceFile
|
||||
>SourceFile : SourceFile
|
||||
>scriptSnapshot : IScriptSnapshot
|
||||
@@ -6033,6 +6036,7 @@ declare module "typescript" {
|
||||
>version : string
|
||||
>textChangeRange : TextChangeRange
|
||||
>TextChangeRange : TextChangeRange
|
||||
>aggressiveChecks : boolean
|
||||
>SourceFile : SourceFile
|
||||
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
|
||||
@@ -15,40 +15,40 @@ declare var path: any;
|
||||
|
||||
import ts = require("typescript");
|
||||
|
||||
function watch(rootFilenames: string[], options: ts.CompilerOptions) {
|
||||
function watch(rootFileNames: string[], options: ts.CompilerOptions) {
|
||||
var files: ts.Map<{ version: number }> = {};
|
||||
|
||||
// initialize the list of files
|
||||
rootFilenames.forEach(filename => {
|
||||
files[filename] = { version: 0 };
|
||||
rootFileNames.forEach(fileName => {
|
||||
files[fileName] = { version: 0 };
|
||||
});
|
||||
|
||||
// Create the language service host to allow the LS to communicate with the host
|
||||
var servicesHost: ts.LanguageServiceHost = {
|
||||
getScriptFileNames: () => rootFilenames,
|
||||
getScriptVersion: (filename) => files[filename] && files[filename].version.toString(),
|
||||
getScriptSnapshot: (filename) => {
|
||||
if (!fs.existsSync(filename)) {
|
||||
getScriptFileNames: () => rootFileNames,
|
||||
getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(),
|
||||
getScriptSnapshot: (fileName) => {
|
||||
if (!fs.existsSync(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return ts.ScriptSnapshot.fromString(fs.readFileSync(filename).toString());
|
||||
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
|
||||
},
|
||||
getCurrentDirectory: () => process.cwd(),
|
||||
getCompilationSettings: () => options,
|
||||
getDefaultLibFilename: (options) => ts.getDefaultLibFilePath(options),
|
||||
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
||||
};
|
||||
|
||||
// Create the language service files
|
||||
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry())
|
||||
|
||||
// Now let's watch the files
|
||||
rootFilenames.forEach(filename => {
|
||||
rootFileNames.forEach(fileName => {
|
||||
// First time around, emit all files
|
||||
emitFile(filename);
|
||||
emitFile(fileName);
|
||||
|
||||
// Add a watch on the file to handle next change
|
||||
fs.watchFile(filename,
|
||||
fs.watchFile(fileName,
|
||||
{ persistent: true, interval: 250 },
|
||||
(curr, prev) => {
|
||||
// Check timestamp
|
||||
@@ -57,22 +57,22 @@ function watch(rootFilenames: string[], options: ts.CompilerOptions) {
|
||||
}
|
||||
|
||||
// Update the version to signal a change in the file
|
||||
files[filename].version++;
|
||||
files[fileName].version++;
|
||||
|
||||
// write the changes to disk
|
||||
emitFile(filename);
|
||||
emitFile(fileName);
|
||||
});
|
||||
});
|
||||
|
||||
function emitFile(filename: string) {
|
||||
var output = services.getEmitOutput(filename);
|
||||
function emitFile(fileName: string) {
|
||||
var output = services.getEmitOutput(fileName);
|
||||
|
||||
if (output.emitOutputStatus === ts.EmitReturnStatus.Succeeded) {
|
||||
console.log(`Emitting ${filename}`);
|
||||
if (!output.emitSkipped) {
|
||||
console.log(`Emitting ${fileName}`);
|
||||
}
|
||||
else {
|
||||
console.log(`Emitting ${filename} failed`);
|
||||
logErrors(filename);
|
||||
console.log(`Emitting ${fileName} failed`);
|
||||
logErrors(fileName);
|
||||
}
|
||||
|
||||
output.outputFiles.forEach(o => {
|
||||
@@ -80,15 +80,15 @@ function watch(rootFilenames: string[], options: ts.CompilerOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
function logErrors(filename: string) {
|
||||
function logErrors(fileName: string) {
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
.concat(services.getSyntacticDiagnostics(filename))
|
||||
.concat(services.getSemanticDiagnostics(filename));
|
||||
.concat(services.getSyntacticDiagnostics(fileName))
|
||||
.concat(services.getSemanticDiagnostics(fileName));
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
if (diagnostic.file) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
|
||||
console.log(` Error ${diagnostic.file.filename} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`);
|
||||
console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
|
||||
}
|
||||
else {
|
||||
console.log(` Error: ${diagnostic.messageText}`);
|
||||
@@ -99,7 +99,7 @@ function watch(rootFilenames: string[], options: ts.CompilerOptions) {
|
||||
|
||||
// Initialize files constituting the program as all .ts files in the current directory
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
filter(filename=> filename.length >= 3 && filename.substr(filename.length - 3, 3) === ".ts");
|
||||
filter(fileName=> fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts");
|
||||
|
||||
// Start the watcher
|
||||
watch(currentDirectoryFiles, { module: ts.ModuleKind.CommonJS });
|
||||
@@ -782,7 +782,7 @@ declare module "typescript" {
|
||||
exportName: Identifier;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
filename: string;
|
||||
fileName: string;
|
||||
}
|
||||
interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
@@ -790,34 +790,46 @@ declare module "typescript" {
|
||||
interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
filename: string;
|
||||
fileName: string;
|
||||
text: string;
|
||||
amdDependencies: string[];
|
||||
amdDependencies: {
|
||||
path: string;
|
||||
name: string;
|
||||
}[];
|
||||
amdModuleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
hasNoDefaultLib: boolean;
|
||||
externalModuleIndicator: Node;
|
||||
nodeCount: number;
|
||||
identifierCount: number;
|
||||
symbolCount: number;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
}
|
||||
interface ScriptReferenceHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
interface WriteFileCallback {
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
}
|
||||
interface Program extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getCompilerHost(): CompilerHost;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
* will be invoked when writing the javascript and declaration files.
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
getTypeChecker(produceDiagnostics: boolean): TypeChecker;
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getTypeChecker(): TypeChecker;
|
||||
getCommonSourceDirectory(): string;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
interface SourceMapSpan {
|
||||
emittedLine: number;
|
||||
@@ -838,33 +850,22 @@ declare module "typescript" {
|
||||
sourceMapMappings: string;
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
enum EmitReturnStatus {
|
||||
Succeeded = 0,
|
||||
AllOutputGenerationSkipped = 1,
|
||||
JSGeneratedWithSemanticErrors = 2,
|
||||
DeclarationGenerationSkipped = 3,
|
||||
EmitErrorsEncountered = 4,
|
||||
CompilerOptionsErrors = 5,
|
||||
enum ExitStatus {
|
||||
Success = 0,
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
DiagnosticsPresent_OutputsGenerated = 2,
|
||||
}
|
||||
interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
sourceMaps: SourceMapData[];
|
||||
}
|
||||
interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getCompilerHost(): CompilerHost;
|
||||
getSourceFiles(): SourceFile[];
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
}
|
||||
interface TypeChecker {
|
||||
getEmitResolver(): EmitResolver;
|
||||
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getNodeCount(): number;
|
||||
getIdentifierCount(): number;
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -888,7 +889,7 @@ declare module "typescript" {
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
@@ -954,15 +955,13 @@ declare module "typescript" {
|
||||
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
|
||||
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
hasSemanticDiagnostics(sourceFile?: SourceFile): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||
}
|
||||
const enum SymbolFlags {
|
||||
@@ -1209,7 +1208,7 @@ declare module "typescript" {
|
||||
file: SourceFile;
|
||||
start: number;
|
||||
length: number;
|
||||
messageText: string;
|
||||
messageText: string | DiagnosticMessageChain;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
}
|
||||
@@ -1268,7 +1267,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
filenames: string[];
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
interface CommandLineOption {
|
||||
@@ -1410,10 +1409,10 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
interface CompilerHost {
|
||||
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
|
||||
writeFile: WriteFileCallback;
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
@@ -1477,10 +1476,9 @@ declare module "typescript" {
|
||||
function createNode(kind: SyntaxKind): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function modifierToFlag(token: SyntaxKind): NodeFlags;
|
||||
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean;
|
||||
function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
|
||||
function isLeftHandSideExpression(expr: Expression): boolean;
|
||||
function isAssignmentOperator(token: SyntaxKind): boolean;
|
||||
}
|
||||
@@ -1489,7 +1487,9 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program;
|
||||
}
|
||||
declare module "typescript" {
|
||||
var servicesVersion: string;
|
||||
@@ -1541,7 +1541,6 @@ declare module "typescript" {
|
||||
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
|
||||
getLineStarts(): number[];
|
||||
getPositionFromLineAndCharacter(line: number, character: number): number;
|
||||
getSyntacticDiagnostics(): Diagnostic[];
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
}
|
||||
/**
|
||||
@@ -1580,7 +1579,7 @@ declare module "typescript" {
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
log?(s: string): void;
|
||||
trace?(s: string): void;
|
||||
error?(s: string): void;
|
||||
@@ -1614,7 +1613,7 @@ declare module "typescript" {
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
getProgram(): Program;
|
||||
getSourceFile(filename: string): SourceFile;
|
||||
getSourceFile(fileName: string): SourceFile;
|
||||
dispose(): void;
|
||||
}
|
||||
interface ClassifiedSpan {
|
||||
@@ -1764,6 +1763,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
interface CompletionEntry {
|
||||
@@ -1793,7 +1793,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
emitSkipped: boolean;
|
||||
}
|
||||
const enum OutputFileType {
|
||||
JavaScript = 0,
|
||||
@@ -1810,6 +1810,9 @@ declare module "typescript" {
|
||||
InMultiLineCommentTrivia = 1,
|
||||
InSingleQuoteStringLiteral = 2,
|
||||
InDoubleQuoteStringLiteral = 3,
|
||||
InTemplateHeadOrNoSubstitutionTemplate = 4,
|
||||
InTemplateMiddleOrTail = 5,
|
||||
InTemplateSubstitutionPosition = 6,
|
||||
}
|
||||
enum TokenClass {
|
||||
Punctuation = 0,
|
||||
@@ -1831,7 +1834,26 @@ declare module "typescript" {
|
||||
classification: TokenClass;
|
||||
}
|
||||
interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
|
||||
/**
|
||||
* Gives lexical classifications of tokens on a line without any syntactic context.
|
||||
* For instance, a token consisting of the text 'string' can be either an identifier
|
||||
* named 'string' or the keyword 'string', however, because this classifier is not aware,
|
||||
* it relies on certain heuristics to give acceptable results. For classifications where
|
||||
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
|
||||
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
|
||||
* lexical, syntactic, and semantic classifiers may issue the best user experience.
|
||||
*
|
||||
* @param text The text of a line to classify.
|
||||
* @param lexState The state of the lexical classifier at the end of the previous line.
|
||||
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
|
||||
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
|
||||
* certain heuristics may be used in its place; however, if there is a
|
||||
* syntactic classifier (syntacticClassifierAbsent=false), certain
|
||||
* classifications which may be incorrectly categorized will be given
|
||||
* back as Identifiers in order to allow the syntactic classifier to
|
||||
* subsume the classification.
|
||||
*/
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
|
||||
}
|
||||
/**
|
||||
* The document registry represents a store of SourceFile objects that can be shared between
|
||||
@@ -1850,11 +1872,11 @@ declare module "typescript" {
|
||||
*/
|
||||
interface DocumentRegistry {
|
||||
/**
|
||||
* Request a stored SourceFile with a given filename and compilationSettings.
|
||||
* Request a stored SourceFile with a given fileName and compilationSettings.
|
||||
* The first call to acquire will call createLanguageServiceSourceFile to generate
|
||||
* the SourceFile if was not found in the registry.
|
||||
*
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1863,9 +1885,9 @@ declare module "typescript" {
|
||||
* @parm version Current version of the file. Only used if the file was not found
|
||||
* in the registry and a new one was created.
|
||||
*/
|
||||
acquireDocument(filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile;
|
||||
/**
|
||||
* Request an updated version of an already existing SourceFile with a given filename
|
||||
* Request an updated version of an already existing SourceFile with a given fileName
|
||||
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
|
||||
* to get an updated SourceFile.
|
||||
*
|
||||
@@ -1873,7 +1895,7 @@ declare module "typescript" {
|
||||
* registry originally.
|
||||
*
|
||||
* @param sourceFile The original sourceFile object to update
|
||||
* @param filename The name of the file requested
|
||||
* @param fileName The name of the file requested
|
||||
* @param compilationSettings Some compilation settings like target affects the
|
||||
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
|
||||
* multiple copies of the same file for different compilation settings.
|
||||
@@ -1884,17 +1906,17 @@ declare module "typescript" {
|
||||
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
|
||||
* was not found in the registry and a new one was created.
|
||||
*/
|
||||
updateDocument(sourceFile: SourceFile, filename: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
/**
|
||||
* Informs the DocumentRegistry that a file is not needed any longer.
|
||||
*
|
||||
* Note: It is not allowed to call release on a SourceFile that was not acquired from
|
||||
* this registry originally.
|
||||
*
|
||||
* @param filename The name of the file to be released
|
||||
* @param fileName The name of the file to be released
|
||||
* @param compilationSettings The compilation settings used to acquire the file
|
||||
*/
|
||||
releaseDocument(filename: string, compilationSettings: CompilerOptions): void;
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
|
||||
}
|
||||
class ScriptElementKind {
|
||||
static unknown: string;
|
||||
@@ -1965,9 +1987,9 @@ declare module "typescript" {
|
||||
isCancellationRequested(): boolean;
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
|
||||
@@ -1988,63 +2010,63 @@ declare module "typescript" {
|
||||
* Please log a "breaking change" issue for any API breaking change affecting this issue
|
||||
*/
|
||||
var ts = require("typescript");
|
||||
function watch(rootFilenames, options) {
|
||||
function watch(rootFileNames, options) {
|
||||
var files = {};
|
||||
// initialize the list of files
|
||||
rootFilenames.forEach(function (filename) {
|
||||
files[filename] = { version: 0 };
|
||||
rootFileNames.forEach(function (fileName) {
|
||||
files[fileName] = { version: 0 };
|
||||
});
|
||||
// Create the language service host to allow the LS to communicate with the host
|
||||
var servicesHost = {
|
||||
getScriptFileNames: function () { return rootFilenames; },
|
||||
getScriptVersion: function (filename) { return files[filename] && files[filename].version.toString(); },
|
||||
getScriptSnapshot: function (filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
getScriptFileNames: function () { return rootFileNames; },
|
||||
getScriptVersion: function (fileName) { return files[fileName] && files[fileName].version.toString(); },
|
||||
getScriptSnapshot: function (fileName) {
|
||||
if (!fs.existsSync(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
return ts.ScriptSnapshot.fromString(fs.readFileSync(filename).toString());
|
||||
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
|
||||
},
|
||||
getCurrentDirectory: function () { return process.cwd(); },
|
||||
getCompilationSettings: function () { return options; },
|
||||
getDefaultLibFilename: function (options) { return ts.getDefaultLibFilePath(options); }
|
||||
getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(options); }
|
||||
};
|
||||
// Create the language service files
|
||||
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
|
||||
// Now let's watch the files
|
||||
rootFilenames.forEach(function (filename) {
|
||||
rootFileNames.forEach(function (fileName) {
|
||||
// First time around, emit all files
|
||||
emitFile(filename);
|
||||
emitFile(fileName);
|
||||
// Add a watch on the file to handle next change
|
||||
fs.watchFile(filename, { persistent: true, interval: 250 }, function (curr, prev) {
|
||||
fs.watchFile(fileName, { persistent: true, interval: 250 }, function (curr, prev) {
|
||||
// Check timestamp
|
||||
if (+curr.mtime <= +prev.mtime) {
|
||||
return;
|
||||
}
|
||||
// Update the version to signal a change in the file
|
||||
files[filename].version++;
|
||||
files[fileName].version++;
|
||||
// write the changes to disk
|
||||
emitFile(filename);
|
||||
emitFile(fileName);
|
||||
});
|
||||
});
|
||||
function emitFile(filename) {
|
||||
var output = services.getEmitOutput(filename);
|
||||
if (output.emitOutputStatus === 0 /* Succeeded */) {
|
||||
console.log("Emitting " + filename);
|
||||
function emitFile(fileName) {
|
||||
var output = services.getEmitOutput(fileName);
|
||||
if (!output.emitSkipped) {
|
||||
console.log("Emitting " + fileName);
|
||||
}
|
||||
else {
|
||||
console.log("Emitting " + filename + " failed");
|
||||
logErrors(filename);
|
||||
console.log("Emitting " + fileName + " failed");
|
||||
logErrors(fileName);
|
||||
}
|
||||
output.outputFiles.forEach(function (o) {
|
||||
fs.writeFileSync(o.name, o.text, "utf8");
|
||||
});
|
||||
}
|
||||
function logErrors(filename) {
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics().concat(services.getSyntacticDiagnostics(filename)).concat(services.getSemanticDiagnostics(filename));
|
||||
function logErrors(fileName) {
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics().concat(services.getSyntacticDiagnostics(fileName)).concat(services.getSemanticDiagnostics(fileName));
|
||||
allDiagnostics.forEach(function (diagnostic) {
|
||||
if (diagnostic.file) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
|
||||
console.log(" Error " + diagnostic.file.filename + " (" + lineChar.line + "," + lineChar.character + "): " + diagnostic.messageText);
|
||||
console.log(" Error " + diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
||||
}
|
||||
else {
|
||||
console.log(" Error: " + diagnostic.messageText);
|
||||
@@ -2053,6 +2075,6 @@ function watch(rootFilenames, options) {
|
||||
}
|
||||
}
|
||||
// Initialize files constituting the program as all .ts files in the current directory
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).filter(function (filename) { return filename.length >= 3 && filename.substr(filename.length - 3, 3) === ".ts"; });
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).filter(function (fileName) { return fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"; });
|
||||
// Start the watcher
|
||||
watch(currentDirectoryFiles, { module: 1 /* CommonJS */ });
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,5 +2,4 @@
|
||||
var v = (public x: string) => { };
|
||||
|
||||
//// [ArrowFunctionExpression1.js]
|
||||
var v = function (x) {
|
||||
};
|
||||
var v = function (x) { };
|
||||
|
||||
+1
-2
@@ -58,8 +58,7 @@ var clodule1 = (function () {
|
||||
})();
|
||||
var clodule1;
|
||||
(function (clodule1) {
|
||||
function f(x) {
|
||||
}
|
||||
function f(x) { }
|
||||
})(clodule1 || (clodule1 = {}));
|
||||
var clodule2 = (function () {
|
||||
function clodule2() {
|
||||
|
||||
+1
-2
@@ -19,8 +19,7 @@ module clodule {
|
||||
var clodule = (function () {
|
||||
function clodule() {
|
||||
}
|
||||
clodule.fn = function (id) {
|
||||
};
|
||||
clodule.fn = function (id) { };
|
||||
return clodule;
|
||||
})();
|
||||
var clodule;
|
||||
|
||||
+1
-2
@@ -19,8 +19,7 @@ module clodule {
|
||||
var clodule = (function () {
|
||||
function clodule() {
|
||||
}
|
||||
clodule.fn = function (id) {
|
||||
};
|
||||
clodule.fn = function (id) { };
|
||||
return clodule;
|
||||
})();
|
||||
var clodule;
|
||||
|
||||
@@ -8,7 +8,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
};
|
||||
C.prototype.foo = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -8,7 +8,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
};
|
||||
C.prototype.bar = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -8,7 +8,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[1] = function () {
|
||||
};
|
||||
C.prototype[1] = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -8,7 +8,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype["bar"] = function () {
|
||||
};
|
||||
C.prototype["bar"] = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = function * yield() { }
|
||||
|
||||
//// [FunctionDeclaration12_es6.js]
|
||||
var v = , yield = function () {
|
||||
};
|
||||
var v = , yield = function () { };
|
||||
|
||||
@@ -3,5 +3,4 @@ function foo();
|
||||
function bar() { }
|
||||
|
||||
//// [FunctionDeclaration4.js]
|
||||
function bar() {
|
||||
}
|
||||
function bar() { }
|
||||
|
||||
@@ -6,6 +6,5 @@
|
||||
|
||||
//// [FunctionDeclaration6.js]
|
||||
{
|
||||
function bar() {
|
||||
}
|
||||
function bar() { }
|
||||
}
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = function * () { }
|
||||
|
||||
//// [FunctionExpression1_es6.js]
|
||||
var v = function () {
|
||||
};
|
||||
var v = function () { };
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = function * foo() { }
|
||||
|
||||
//// [FunctionExpression2_es6.js]
|
||||
var v = function foo() {
|
||||
};
|
||||
var v = function foo() { };
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = { *foo() { } }
|
||||
|
||||
//// [FunctionPropertyAssignments1_es6.js]
|
||||
var v = { foo: function () {
|
||||
} };
|
||||
var v = { foo: function () { } };
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = { *() { } }
|
||||
|
||||
//// [FunctionPropertyAssignments2_es6.js]
|
||||
var v = { : function () {
|
||||
} };
|
||||
var v = { : function () { } };
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = { *{ } }
|
||||
|
||||
//// [FunctionPropertyAssignments3_es6.js]
|
||||
var v = { : function () {
|
||||
} };
|
||||
var v = { : function () { } };
|
||||
|
||||
@@ -2,6 +2,5 @@
|
||||
var v = { *[foo()]() { } }
|
||||
|
||||
//// [FunctionPropertyAssignments5_es6.js]
|
||||
var v = (_a = {}, _a[foo()] = function () {
|
||||
}, _a);
|
||||
var v = (_a = {}, _a[foo()] = function () { }, _a);
|
||||
var _a;
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
var v = { *<T>() { } }
|
||||
|
||||
//// [FunctionPropertyAssignments6_es6.js]
|
||||
var v = { : function () {
|
||||
} };
|
||||
var v = { : function () { } };
|
||||
|
||||
@@ -8,8 +8,7 @@ var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "Foo", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
};
|
||||
C.prototype.foo = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
};
|
||||
C.prototype.foo = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[foo] = function () {
|
||||
};
|
||||
C.prototype[foo] = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype. = function () {
|
||||
};
|
||||
C.prototype. = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
};
|
||||
C.prototype.foo = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.m = function () {
|
||||
};
|
||||
C.prototype.m = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.m = function () {
|
||||
};
|
||||
C.m = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.m = function () {
|
||||
};
|
||||
C.m = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -7,7 +7,6 @@ class C {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.m = function () {
|
||||
};
|
||||
C.prototype.m = function () { };
|
||||
return C;
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts ===
|
||||
enum Color { R, G, B }
|
||||
>Color : Color
|
||||
>R : Color
|
||||
>G : Color
|
||||
>B : Color
|
||||
|
||||
function f1(x: Color | string) {
|
||||
>f1 : (x: string | Color) => void
|
||||
>x : string | Color
|
||||
>Color : Color
|
||||
|
||||
if (typeof x === "number") {
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Color
|
||||
|
||||
var y = x;
|
||||
>y : Color
|
||||
>x : Color
|
||||
|
||||
var y: Color;
|
||||
>y : Color
|
||||
>Color : Color
|
||||
}
|
||||
else {
|
||||
var z = x;
|
||||
>z : string
|
||||
>x : string
|
||||
|
||||
var z: string;
|
||||
>z : string
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Color | string | string[]) {
|
||||
>f2 : (x: string | Color | string[]) => void
|
||||
>x : string | Color | string[]
|
||||
>Color : Color
|
||||
|
||||
if (typeof x === "object") {
|
||||
>typeof x === "object" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Color | string[]
|
||||
|
||||
var y = x;
|
||||
>y : string[]
|
||||
>x : string[]
|
||||
|
||||
var y: string[];
|
||||
>y : string[]
|
||||
}
|
||||
if (typeof x === "number") {
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Color | string[]
|
||||
|
||||
var z = x;
|
||||
>z : Color
|
||||
>x : Color
|
||||
|
||||
var z: Color;
|
||||
>z : Color
|
||||
>Color : Color
|
||||
}
|
||||
else {
|
||||
var w = x;
|
||||
>w : string | string[]
|
||||
>x : string | string[]
|
||||
|
||||
var w: string | string[];
|
||||
>w : string | string[]
|
||||
}
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Color | string[]
|
||||
|
||||
var a = x;
|
||||
>a : string
|
||||
>x : string
|
||||
|
||||
var a: string;
|
||||
>a : string
|
||||
}
|
||||
else {
|
||||
var b = x;
|
||||
>b : Color | string[]
|
||||
>x : Color | string[]
|
||||
|
||||
var b: Color | string[];
|
||||
>b : Color | string[]
|
||||
>Color : Color
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ class E {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.privateMethod = function () {
|
||||
};
|
||||
C.privateMethod = function () { };
|
||||
Object.defineProperty(C, "privateGetter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -60,13 +59,11 @@ var C = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "privateSetter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
C.protectedMethod = function () {
|
||||
};
|
||||
C.protectedMethod = function () { };
|
||||
Object.defineProperty(C, "protectedGetter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -75,13 +72,11 @@ var C = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "protectedSetter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
C.publicMethod = function () {
|
||||
};
|
||||
C.publicMethod = function () { };
|
||||
Object.defineProperty(C, "publicGetter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -90,8 +85,7 @@ var C = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "publicSetter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -101,8 +95,7 @@ var C = (function () {
|
||||
var D = (function () {
|
||||
function D() {
|
||||
}
|
||||
D.privateMethod = function () {
|
||||
};
|
||||
D.privateMethod = function () { };
|
||||
Object.defineProperty(D, "privateGetter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -111,13 +104,11 @@ var D = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(D, "privateSetter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
D.protectedMethod = function () {
|
||||
};
|
||||
D.protectedMethod = function () { };
|
||||
Object.defineProperty(D, "protectedGetter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -126,13 +117,11 @@ var D = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(D, "protectedSetter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
D.publicMethod = function () {
|
||||
};
|
||||
D.publicMethod = function () { };
|
||||
Object.defineProperty(D, "publicGetter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -141,8 +130,7 @@ var D = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(D, "publicSetter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -152,8 +140,7 @@ var D = (function () {
|
||||
var E = (function () {
|
||||
function E() {
|
||||
}
|
||||
E.prototype.method = function () {
|
||||
};
|
||||
E.prototype.method = function () { };
|
||||
Object.defineProperty(E.prototype, "getter", {
|
||||
get: function () {
|
||||
return 0;
|
||||
@@ -162,8 +149,7 @@ var E = (function () {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(E.prototype, "setter", {
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -10,14 +10,12 @@ var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "X", {
|
||||
set: function (v) {
|
||||
},
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "X", {
|
||||
set: function (v2) {
|
||||
},
|
||||
set: function (v2) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -52,6 +52,5 @@ var x = {
|
||||
}
|
||||
};
|
||||
var y = {
|
||||
set b(v) {
|
||||
}
|
||||
set b(v) { }
|
||||
};
|
||||
|
||||
@@ -49,6 +49,5 @@ var x = {
|
||||
}
|
||||
};
|
||||
var y = {
|
||||
set b(v) {
|
||||
}
|
||||
set b(v) { }
|
||||
};
|
||||
|
||||
@@ -10,16 +10,12 @@ var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "X", {
|
||||
set: function (v) {
|
||||
if (v === void 0) { v = 0; }
|
||||
},
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "X", {
|
||||
set: function (v2) {
|
||||
if (v2 === void 0) { v2 = 0; }
|
||||
},
|
||||
set: function (v2) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -10,22 +10,12 @@ var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "X", {
|
||||
set: function () {
|
||||
var v = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
v[_i - 0] = arguments[_i];
|
||||
}
|
||||
},
|
||||
set: function () { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "X", {
|
||||
set: function () {
|
||||
var v2 = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
v2[_i - 0] = arguments[_i];
|
||||
}
|
||||
},
|
||||
set: function () { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -21,8 +21,7 @@ var LanguageSpec_section_4_5_error_cases = (function () {
|
||||
get: function () {
|
||||
return "";
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -30,8 +29,7 @@ var LanguageSpec_section_4_5_error_cases = (function () {
|
||||
get: function () {
|
||||
return "";
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -50,8 +50,7 @@ var LanguageSpec_section_4_5_inference = (function () {
|
||||
get: function () {
|
||||
return new B();
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -59,8 +58,7 @@ var LanguageSpec_section_4_5_inference = (function () {
|
||||
get: function () {
|
||||
return new B();
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -68,8 +66,7 @@ var LanguageSpec_section_4_5_inference = (function () {
|
||||
get: function () {
|
||||
return new B();
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -77,8 +74,7 @@ var LanguageSpec_section_4_5_inference = (function () {
|
||||
get: function () {
|
||||
return new B();
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -86,8 +82,7 @@ var LanguageSpec_section_4_5_inference = (function () {
|
||||
get: function () {
|
||||
return new B();
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -95,8 +90,7 @@ var LanguageSpec_section_4_5_inference = (function () {
|
||||
get: function () {
|
||||
return new B();
|
||||
},
|
||||
set: function (a) {
|
||||
},
|
||||
set: function (a) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
@@ -40,13 +40,11 @@ var r19 = a + { a: '' };
|
||||
var r20 = a + ((a: string) => { return a });
|
||||
|
||||
//// [additionOperatorWithAnyAndEveryType.js]
|
||||
function foo() {
|
||||
}
|
||||
function foo() { }
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.foo = function () {
|
||||
};
|
||||
C.foo = function () { };
|
||||
return C;
|
||||
})();
|
||||
var E;
|
||||
|
||||
@@ -41,13 +41,11 @@ var r19 = E.a + C.foo();
|
||||
var r20 = E.a + M;
|
||||
|
||||
//// [additionOperatorWithInvalidOperands.js]
|
||||
function foo() {
|
||||
}
|
||||
function foo() { }
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.foo = function () {
|
||||
};
|
||||
C.foo = function () { };
|
||||
return C;
|
||||
})();
|
||||
var E;
|
||||
|
||||
@@ -44,5 +44,4 @@ var r7 = null + d;
|
||||
var r8 = null + true;
|
||||
var r9 = null + { a: '' };
|
||||
var r10 = null + foo();
|
||||
var r11 = null + (function () {
|
||||
});
|
||||
var r11 = null + (function () { });
|
||||
|
||||
@@ -74,7 +74,6 @@ function foo(t, u) {
|
||||
var r16 = t + undefined;
|
||||
var r17 = t + t;
|
||||
var r18 = t + u;
|
||||
var r19 = t + (function () {
|
||||
});
|
||||
var r19 = t + (function () { });
|
||||
var r20 = t + [];
|
||||
}
|
||||
|
||||
@@ -44,5 +44,4 @@ var r7 = undefined + d;
|
||||
var r8 = undefined + true;
|
||||
var r9 = undefined + { a: '' };
|
||||
var r10 = undefined + foo();
|
||||
var r11 = undefined + (function () {
|
||||
});
|
||||
var r11 = undefined + (function () { });
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
=== tests/cases/compiler/aliasUsageInOrExpression_main.ts ===
|
||||
import Backbone = require("aliasUsageInOrExpression_backbone");
|
||||
>Backbone : typeof Backbone
|
||||
|
||||
import moduleA = require("aliasUsageInOrExpression_moduleA");
|
||||
>moduleA : typeof moduleA
|
||||
|
||||
interface IHasVisualizationModel {
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
|
||||
VisualizationModel: typeof Backbone.Model;
|
||||
>VisualizationModel : typeof Backbone.Model
|
||||
>Backbone : typeof Backbone
|
||||
>Model : typeof Backbone.Model
|
||||
}
|
||||
var i: IHasVisualizationModel;
|
||||
>i : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
|
||||
var d1 = i || moduleA;
|
||||
>d1 : typeof moduleA
|
||||
>i || moduleA : typeof moduleA
|
||||
>i : IHasVisualizationModel
|
||||
>moduleA : typeof moduleA
|
||||
|
||||
var d2: IHasVisualizationModel = i || moduleA;
|
||||
>d2 : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
>i || moduleA : typeof moduleA
|
||||
>i : IHasVisualizationModel
|
||||
>moduleA : typeof moduleA
|
||||
|
||||
var d2: IHasVisualizationModel = moduleA || i;
|
||||
>d2 : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
>moduleA || i : typeof moduleA
|
||||
>moduleA : typeof moduleA
|
||||
>i : IHasVisualizationModel
|
||||
|
||||
var e: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null || { x: moduleA };
|
||||
>e : { x: IHasVisualizationModel; }
|
||||
>x : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
><{ x: IHasVisualizationModel }>null || { x: moduleA } : { x: IHasVisualizationModel; }
|
||||
><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; }
|
||||
>x : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
>{ x: moduleA } : { x: typeof moduleA; }
|
||||
>x : typeof moduleA
|
||||
>moduleA : typeof moduleA
|
||||
|
||||
var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x: moduleA } : null;
|
||||
>f : { x: IHasVisualizationModel; }
|
||||
>x : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: typeof moduleA; }
|
||||
><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; }
|
||||
>x : IHasVisualizationModel
|
||||
>IHasVisualizationModel : IHasVisualizationModel
|
||||
>{ x: moduleA } : { x: typeof moduleA; }
|
||||
>x : typeof moduleA
|
||||
>moduleA : typeof moduleA
|
||||
|
||||
=== tests/cases/compiler/aliasUsageInOrExpression_backbone.ts ===
|
||||
export class Model {
|
||||
>Model : Model
|
||||
|
||||
public someData: string;
|
||||
>someData : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/aliasUsageInOrExpression_moduleA.ts ===
|
||||
import Backbone = require("aliasUsageInOrExpression_backbone");
|
||||
>Backbone : typeof Backbone
|
||||
|
||||
export class VisualizationModel extends Backbone.Model {
|
||||
>VisualizationModel : VisualizationModel
|
||||
>Backbone : unknown
|
||||
>Model : Backbone.Model
|
||||
|
||||
// interesting stuff here
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/amdDependencyCommentName1.ts (1 errors) ====
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
|
||||
import m1 = require("m2")
|
||||
~~~~
|
||||
!!! error TS2307: Cannot find external module 'm2'.
|
||||
m1.f();
|
||||
@@ -0,0 +1,10 @@
|
||||
//// [amdDependencyCommentName1.ts]
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
|
||||
import m1 = require("m2")
|
||||
m1.f();
|
||||
|
||||
//// [amdDependencyCommentName1.js]
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
var m1 = require("m2");
|
||||
m1.f();
|
||||
@@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find external module 'm2'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/amdDependencyCommentName2.ts (1 errors) ====
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
|
||||
import m1 = require("m2")
|
||||
~~~~
|
||||
!!! error TS2307: Cannot find external module 'm2'.
|
||||
m1.f();
|
||||
@@ -0,0 +1,11 @@
|
||||
//// [amdDependencyCommentName2.ts]
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
|
||||
import m1 = require("m2")
|
||||
m1.f();
|
||||
|
||||
//// [amdDependencyCommentName2.js]
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
define(["require", "exports", "m2", "bar"], function (require, exports, m1, b) {
|
||||
m1.f();
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find external module 'm2'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/amdDependencyCommentName3.ts (1 errors) ====
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
///<amd-dependency path='foo'/>
|
||||
///<amd-dependency path='goo' name='c'/>
|
||||
|
||||
import m1 = require("m2")
|
||||
~~~~
|
||||
!!! error TS2307: Cannot find external module 'm2'.
|
||||
m1.f();
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [amdDependencyCommentName3.ts]
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
///<amd-dependency path='foo'/>
|
||||
///<amd-dependency path='goo' name='c'/>
|
||||
|
||||
import m1 = require("m2")
|
||||
m1.f();
|
||||
|
||||
//// [amdDependencyCommentName3.js]
|
||||
///<amd-dependency path='bar' name='b'/>
|
||||
///<amd-dependency path='foo'/>
|
||||
///<amd-dependency path='goo' name='c'/>
|
||||
define(["require", "exports", "m2", "bar", "goo", "foo"], function (require, exports, m1, b, c) {
|
||||
m1.f();
|
||||
});
|
||||
@@ -118,8 +118,7 @@ var E;
|
||||
E[E["A"] = 0] = "A";
|
||||
})(E || (E = {}));
|
||||
var r3 = foo3(a); // any
|
||||
function f() {
|
||||
}
|
||||
function f() { }
|
||||
var f;
|
||||
(function (f) {
|
||||
f.bar = 1;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user