From 64958669e1a0b25a9c0f02dd246c0beb7a40b995 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 24 Dec 2015 17:18:10 +0900 Subject: [PATCH 1/8] remove "this should be removed ..." codes --- src/services/shims.ts | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 6b656ea2738..c12c52fa201 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -333,11 +333,6 @@ namespace ts { } 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); } @@ -371,14 +366,7 @@ namespace ts { } public getDefaultLibFileName(options: CompilerOptions): string { - // Wrap the API changes for 1.5 release. This try/catch - // should be removed once TypeScript 1.5 has shipped. - try { - return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); - } - catch (e) { - return ""; - } + return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); } } @@ -411,17 +399,9 @@ namespace ts { } public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { - // Wrap the API changes for 1.5 release. This try/catch - // should be removed once TypeScript 1.5 has shipped. - // Also consider removing the optional designation for + // Consider removing the optional designation for // the exclude param at this time. - var encoded: string; - try { - encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); - } - catch (e) { - encoded = this.shimHost.readDirectory(rootDir, extension); - } + var encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); return JSON.parse(encoded); } @@ -889,9 +869,6 @@ namespace 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. - (output).emitOutputStatus = output.emitSkipped ? 1 : 0; return output; }); } From 6373cfff64dda36dcf23906e5726790ba29b15dd Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 24 Dec 2015 17:21:03 +0900 Subject: [PATCH 2/8] lets and template strings --- src/services/shims.ts | 202 +++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index c12c52fa201..86bf15539bf 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -60,7 +60,7 @@ namespace ts { getNewLine?(): string; getProjectVersion?(): string; useCaseSensitiveFileNames?(): boolean; - + getModuleResolutionsForFile?(fileName: string): string; } @@ -247,14 +247,14 @@ namespace ts { } public getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange { - var oldSnapshotShim = oldSnapshot; - var encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim); + let oldSnapshotShim = oldSnapshot; + let encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim); // TODO: should this be '==='? if (encoded == null) { return null; } - var decoded: { span: { start: number; length: number; }; newLength: number; } = JSON.parse(encoded); + let decoded: { span: { start: number; length: number; }; newLength: number; } = JSON.parse(encoded); return createTextChangeRange( createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); } @@ -272,9 +272,9 @@ namespace ts { private files: string[]; private loggingEnabled = false; private tracingEnabled = false; - + public resolveModuleNames: (moduleName: string[], containingFile: string) => ResolvedModule[]; - + constructor(private shimHost: LanguageServiceShimHost) { // if shimHost is a COM object then property check will become method call with no arguments. // 'in' does not have this effect. @@ -319,7 +319,7 @@ namespace ts { } public getCompilationSettings(): CompilerOptions { - var settingsJson = this.shimHost.getCompilationSettings(); + let settingsJson = this.shimHost.getCompilationSettings(); // TODO: should this be '==='? if (settingsJson == null || settingsJson == "") { throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings"); @@ -328,12 +328,12 @@ namespace ts { } public getScriptFileNames(): string[] { - var encoded = this.shimHost.getScriptFileNames(); + let encoded = this.shimHost.getScriptFileNames(); return this.files = JSON.parse(encoded); } public getScriptSnapshot(fileName: string): IScriptSnapshot { - var scriptSnapshot = this.shimHost.getScriptSnapshot(fileName); + let scriptSnapshot = this.shimHost.getScriptSnapshot(fileName); return scriptSnapshot && new ScriptSnapshotShimAdapter(scriptSnapshot); } @@ -342,7 +342,7 @@ namespace ts { } public getLocalizedDiagnosticMessages(): any { - var diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages(); + let diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages(); if (diagnosticMessagesJson == null || diagnosticMessagesJson == "") { return null; } @@ -357,7 +357,7 @@ namespace ts { } public getCancellationToken(): HostCancellationToken { - var hostCancellationToken = this.shimHost.getCancellationToken(); + let hostCancellationToken = this.shimHost.getCancellationToken(); return new ThrottledCancellationToken(hostCancellationToken); } @@ -381,8 +381,8 @@ namespace ts { } public isCancellationRequested(): boolean { - var time = Date.now(); - var duration = Math.abs(time - this.lastCancellationCheckTime); + let time = Date.now(); + let duration = Math.abs(time - this.lastCancellationCheckTime); if (duration > 10) { // Check no more than once every 10 ms. this.lastCancellationCheckTime = time; @@ -401,36 +401,37 @@ namespace ts { public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { // Consider removing the optional designation for // the exclude param at this time. - var encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); + let encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); return JSON.parse(encoded); } - + public fileExists(fileName: string): boolean { return this.shimHost.fileExists(fileName); } - + public readFile(fileName: string): string { return this.shimHost.readFile(fileName); } } function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any { + let start: number; if (logPerformance) { logger.log(actionDescription); - var start = Date.now(); + start = Date.now(); } - var result = action(); + let result = action(); if (logPerformance) { - var end = Date.now(); - logger.log(actionDescription + " completed in " + (end - start) + " msec"); - if (typeof (result) === "string") { - var str = result; + let end = Date.now(); + logger.log(`${actionDescription} completed in ${end - start} msec`); + if (typeof result === "string") { + let str = result; if (str.length > 128) { str = str.substring(0, 128) + "..."; } - logger.log(" result.length=" + str.length + ", result='" + JSON.stringify(str) + "'"); + logger.log(` result.length=${str.length}, result='${JSON.stringify(str)}'`); } } @@ -439,7 +440,7 @@ namespace ts { function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): string { try { - var result = simpleForwardCall(logger, actionDescription, action, logPerformance); + let result = simpleForwardCall(logger, actionDescription, action, logPerformance); return JSON.stringify({ result: result }); } catch (err) { @@ -461,7 +462,7 @@ namespace ts { } } - export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; code: number; } []{ + export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; code: number; }[] { return diagnostics.map(d => realizeDiagnostic(d, newLine)); } @@ -520,7 +521,7 @@ namespace ts { */ public refresh(throwOnError: boolean): void { this.forwardJSONCall( - "refresh(" + throwOnError + ")", + `refresh(${throwOnError})`, () => { return null; }); @@ -535,32 +536,32 @@ namespace ts { }); } - private realizeDiagnostics(diagnostics: Diagnostic[]): { message: string; start: number; length: number; category: string; }[]{ - var newLine = getNewLineOrDefaultFromHost(this.host); + private realizeDiagnostics(diagnostics: Diagnostic[]): { message: string; start: number; length: number; category: string; }[] { + let newLine = getNewLineOrDefaultFromHost(this.host); return ts.realizeDiagnostics(diagnostics, newLine); } public getSyntacticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( - "getSyntacticClassifications('" + fileName + "', " + start + ", " + length + ")", + `getSyntacticClassifications('${fileName}', ${start}, ${length})`, () => { - var classifications = this.languageService.getSyntacticClassifications(fileName, createTextSpan(start, length)); + let classifications = this.languageService.getSyntacticClassifications(fileName, createTextSpan(start, length)); return classifications; }); } public getSemanticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( - "getSemanticClassifications('" + fileName + "', " + start + ", " + length + ")", + `getSemanticClassifications('${fileName}', ${start}, ${length})`, () => { - var classifications = this.languageService.getSemanticClassifications(fileName, createTextSpan(start, length)); + let classifications = this.languageService.getSemanticClassifications(fileName, createTextSpan(start, length)); return classifications; }); } public getEncodedSyntacticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( - "getEncodedSyntacticClassifications('" + fileName + "', " + start + ", " + length + ")", + `getEncodedSyntacticClassifications('${fileName}', ${start}, ${length})`, () => { // directly serialize the spans out to a string. This is much faster to decode // on the managed side versus a full JSON array. @@ -570,7 +571,7 @@ namespace ts { public getEncodedSemanticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( - "getEncodedSemanticClassifications('" + fileName + "', " + start + ", " + length + ")", + `getEncodedSemanticClassifications('${fileName}', ${start}, ${length})`, () => { // directly serialize the spans out to a string. This is much faster to decode // on the managed side versus a full JSON array. @@ -580,18 +581,18 @@ namespace ts { public getSyntacticDiagnostics(fileName: string): string { return this.forwardJSONCall( - "getSyntacticDiagnostics('" + fileName + "')", + `getSyntacticDiagnostics('${fileName}')`, () => { - var diagnostics = this.languageService.getSyntacticDiagnostics(fileName); + let diagnostics = this.languageService.getSyntacticDiagnostics(fileName); return this.realizeDiagnostics(diagnostics); }); } public getSemanticDiagnostics(fileName: string): string { return this.forwardJSONCall( - "getSemanticDiagnostics('" + fileName + "')", + `getSemanticDiagnostics('${fileName}')`, () => { - var diagnostics = this.languageService.getSemanticDiagnostics(fileName); + let diagnostics = this.languageService.getSemanticDiagnostics(fileName); return this.realizeDiagnostics(diagnostics); }); } @@ -600,7 +601,7 @@ namespace ts { return this.forwardJSONCall( "getCompilerOptionsDiagnostics()", () => { - var diagnostics = this.languageService.getCompilerOptionsDiagnostics(); + let diagnostics = this.languageService.getCompilerOptionsDiagnostics(); return this.realizeDiagnostics(diagnostics); }); } @@ -613,9 +614,9 @@ namespace ts { */ public getQuickInfoAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getQuickInfoAtPosition('" + fileName + "', " + position + ")", + `getQuickInfoAtPosition('${fileName}', ${position})`, () => { - var quickInfo = this.languageService.getQuickInfoAtPosition(fileName, position); + let quickInfo = this.languageService.getQuickInfoAtPosition(fileName, position); return quickInfo; }); } @@ -629,9 +630,9 @@ namespace ts { */ public getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string { return this.forwardJSONCall( - "getNameOrDottedNameSpan('" + fileName + "', " + startPos + ", " + endPos + ")", + `getNameOrDottedNameSpan('${fileName}', ${startPos}, ${endPos})`, () => { - var spanInfo = this.languageService.getNameOrDottedNameSpan(fileName, startPos, endPos); + let spanInfo = this.languageService.getNameOrDottedNameSpan(fileName, startPos, endPos); return spanInfo; }); } @@ -642,9 +643,9 @@ namespace ts { */ public getBreakpointStatementAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getBreakpointStatementAtPosition('" + fileName + "', " + position + ")", + `getBreakpointStatementAtPosition('${fileName}', ${position})`, () => { - var spanInfo = this.languageService.getBreakpointStatementAtPosition(fileName, position); + let spanInfo = this.languageService.getBreakpointStatementAtPosition(fileName, position); return spanInfo; }); } @@ -653,9 +654,9 @@ namespace ts { public getSignatureHelpItems(fileName: string, position: number): string { return this.forwardJSONCall( - "getSignatureHelpItems('" + fileName + "', " + position + ")", + `getSignatureHelpItems('${fileName}', ${position})`, () => { - var signatureInfo = this.languageService.getSignatureHelpItems(fileName, position); + let signatureInfo = this.languageService.getSignatureHelpItems(fileName, position); return signatureInfo; }); } @@ -668,7 +669,7 @@ namespace ts { */ public getDefinitionAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getDefinitionAtPosition('" + fileName + "', " + position + ")", + `getDefinitionAtPosition('${fileName}', ${position})`, () => { return this.languageService.getDefinitionAtPosition(fileName, position); }); @@ -682,7 +683,7 @@ namespace ts { */ public getTypeDefinitionAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getTypeDefinitionAtPosition('" + fileName + "', " + position + ")", + `getTypeDefinitionAtPosition('${fileName}', ${position})`, () => { return this.languageService.getTypeDefinitionAtPosition(fileName, position); }); @@ -690,7 +691,7 @@ namespace ts { public getRenameInfo(fileName: string, position: number): string { return this.forwardJSONCall( - "getRenameInfo('" + fileName + "', " + position + ")", + `getRenameInfo('${fileName}', ${position})`, () => { return this.languageService.getRenameInfo(fileName, position); }); @@ -698,7 +699,7 @@ namespace ts { public findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): string { return this.forwardJSONCall( - "findRenameLocations('" + fileName + "', " + position + ", " + findInStrings + ", " + findInComments + ")", + `findRenameLocations('${fileName}', ${position}, ${findInStrings}, ${findInComments})`, () => { return this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments); }); @@ -707,9 +708,9 @@ namespace ts { /// GET BRACE MATCHING public getBraceMatchingAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getBraceMatchingAtPosition('" + fileName + "', " + position + ")", + `getBraceMatchingAtPosition('${fileName}', ${position})`, () => { - var textRanges = this.languageService.getBraceMatchingAtPosition(fileName, position); + let textRanges = this.languageService.getBraceMatchingAtPosition(fileName, position); return textRanges; }); } @@ -717,9 +718,9 @@ namespace ts { /// GET SMART INDENT public getIndentationAtPosition(fileName: string, position: number, options: string /*Services.EditorOptions*/): string { return this.forwardJSONCall( - "getIndentationAtPosition('" + fileName + "', " + position + ")", + `getIndentationAtPosition('${fileName}', ${position})`, () => { - var localOptions: EditorOptions = JSON.parse(options); + let localOptions: EditorOptions = JSON.parse(options); return this.languageService.getIndentationAtPosition(fileName, position, localOptions); }); } @@ -728,7 +729,7 @@ namespace ts { public getReferencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getReferencesAtPosition('" + fileName + "', " + position + ")", + `getReferencesAtPosition('${fileName}', ${position})`, () => { return this.languageService.getReferencesAtPosition(fileName, position); }); @@ -736,7 +737,7 @@ namespace ts { public findReferences(fileName: string, position: number): string { return this.forwardJSONCall( - "findReferences('" + fileName + "', " + position + ")", + `findReferences('${fileName}', ${position})`, () => { return this.languageService.findReferences(fileName, position); }); @@ -744,7 +745,7 @@ namespace ts { public getOccurrencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getOccurrencesAtPosition('" + fileName + "', " + position + ")", + `getOccurrencesAtPosition('${fileName}', ${position})`, () => { return this.languageService.getOccurrencesAtPosition(fileName, position); }); @@ -752,9 +753,9 @@ namespace ts { public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string { return this.forwardJSONCall( - "getDocumentHighlights('" + fileName + "', " + position + ")", + `getDocumentHighlights('${fileName}', ${position})`, () => { - var results = this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch)); + let results = this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch)); // workaround for VS document higlighting issue - keep only items from the initial file let normalizedName = normalizeSlashes(fileName).toLowerCase(); return filter(results, r => normalizeSlashes(r.fileName).toLowerCase() === normalizedName); @@ -770,9 +771,9 @@ namespace ts { */ public getCompletionsAtPosition(fileName: string, position: number) { return this.forwardJSONCall( - "getCompletionsAtPosition('" + fileName + "', " + position + ")", + `getCompletionsAtPosition('${fileName}', ${position})`, () => { - var completion = this.languageService.getCompletionsAtPosition(fileName, position); + let completion = this.languageService.getCompletionsAtPosition(fileName, position); return completion; }); } @@ -780,46 +781,46 @@ namespace ts { /** Get a string based representation of a completion list entry details */ public getCompletionEntryDetails(fileName: string, position: number, entryName: string) { return this.forwardJSONCall( - "getCompletionEntryDetails('" + fileName + "', " + position + ", " + entryName + ")", + `getCompletionEntryDetails('${fileName}', ${position}, ${entryName})`, () => { - var details = this.languageService.getCompletionEntryDetails(fileName, position, entryName); + let details = this.languageService.getCompletionEntryDetails(fileName, position, entryName); return details; }); } public getFormattingEditsForRange(fileName: string, start: number, end: number, options: string/*Services.FormatCodeOptions*/): string { return this.forwardJSONCall( - "getFormattingEditsForRange('" + fileName + "', " + start + ", " + end + ")", + `getFormattingEditsForRange('${fileName}', ${start}, ${end})`, () => { - var localOptions: ts.FormatCodeOptions = JSON.parse(options); - var edits = this.languageService.getFormattingEditsForRange(fileName, start, end, localOptions); + let localOptions: ts.FormatCodeOptions = JSON.parse(options); + let edits = this.languageService.getFormattingEditsForRange(fileName, start, end, localOptions); return edits; }); } public getFormattingEditsForDocument(fileName: string, options: string/*Services.FormatCodeOptions*/): string { return this.forwardJSONCall( - "getFormattingEditsForDocument('" + fileName + "')", + `getFormattingEditsForDocument('${fileName}')`, () => { - var localOptions: ts.FormatCodeOptions = JSON.parse(options); - var edits = this.languageService.getFormattingEditsForDocument(fileName, localOptions); + let localOptions: ts.FormatCodeOptions = JSON.parse(options); + let edits = this.languageService.getFormattingEditsForDocument(fileName, localOptions); return edits; }); } public getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string/*Services.FormatCodeOptions*/): string { return this.forwardJSONCall( - "getFormattingEditsAfterKeystroke('" + fileName + "', " + position + ", '" + key + "')", + `getFormattingEditsAfterKeystroke('${fileName}', ${position}, '${key}')`, () => { - var localOptions: ts.FormatCodeOptions = JSON.parse(options); - var edits = this.languageService.getFormattingEditsAfterKeystroke(fileName, position, key, localOptions); + let localOptions: ts.FormatCodeOptions = JSON.parse(options); + let edits = this.languageService.getFormattingEditsAfterKeystroke(fileName, position, key, localOptions); return edits; }); } public getDocCommentTemplateAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( - "getDocCommentTemplateAtPosition('" + fileName + "', " + position + ")", + `getDocCommentTemplateAtPosition('${fileName}', ${position})`, () => this.languageService.getDocCommentTemplateAtPosition(fileName, position) ); } @@ -829,36 +830,36 @@ namespace ts { /** Return a list of symbols that are interesting to navigate to */ public getNavigateToItems(searchValue: string, maxResultCount?: number): string { return this.forwardJSONCall( - "getNavigateToItems('" + searchValue + "', " + maxResultCount+ ")", + `getNavigateToItems('${searchValue}', ${maxResultCount})`, () => { - var items = this.languageService.getNavigateToItems(searchValue, maxResultCount); + let items = this.languageService.getNavigateToItems(searchValue, maxResultCount); return items; }); } public getNavigationBarItems(fileName: string): string { return this.forwardJSONCall( - "getNavigationBarItems('" + fileName + "')", + `getNavigationBarItems('${fileName}')`, () => { - var items = this.languageService.getNavigationBarItems(fileName); + let items = this.languageService.getNavigationBarItems(fileName); return items; }); } public getOutliningSpans(fileName: string): string { return this.forwardJSONCall( - "getOutliningSpans('" + fileName + "')", + `getOutliningSpans('${fileName}')`, () => { - var items = this.languageService.getOutliningSpans(fileName); + let items = this.languageService.getOutliningSpans(fileName); return items; }); } public getTodoComments(fileName: string, descriptors: string): string { return this.forwardJSONCall( - "getTodoComments('" + fileName + "')", + `getTodoComments('${fileName}')`, () => { - var items = this.languageService.getTodoComments(fileName, JSON.parse(descriptors)); + let items = this.languageService.getTodoComments(fileName, JSON.parse(descriptors)); return items; }); } @@ -866,9 +867,9 @@ namespace ts { /// Emit public getEmitOutput(fileName: string): string { return this.forwardJSONCall( - "getEmitOutput('" + fileName + "')", + `getEmitOutput('${fileName}')`, () => { - var output = this.languageService.getEmitOutput(fileName); + let output = this.languageService.getEmitOutput(fileName); return output; }); } @@ -895,12 +896,11 @@ namespace ts { /// COLORIZATION public getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string { - var classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics); - var items = classification.entries; - var result = ""; - for (var i = 0; i < items.length; i++) { - result += items[i].length + "\n"; - result += items[i].classification + "\n"; + let classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics); + let result = ""; + for (let item of classification.entries) { + result += item.length + "\n"; + result += item.classification + "\n"; } result += classification.finalLexState; return result; @@ -917,16 +917,16 @@ namespace ts { private forwardJSONCall(actionDescription: string, action: () => any): any { return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); } - + public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => { let compilerOptions = JSON.parse(compilerOptionsJson); const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); return { - resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName: undefined, + resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined, failedLookupLocations: result.failedLookupLocations }; - }); + }); } public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string { @@ -934,8 +934,8 @@ namespace ts { "getPreProcessedFileInfo('" + fileName + "')", () => { // for now treat files as JavaScript - var result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()), /* readImportFiles */ true, /* detectJavaScriptImports */ true); - var convertResult = { + let result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()), /* readImportFiles */ true, /* detectJavaScriptImports */ true); + let convertResult = { referencedFiles: [], importedFiles: [], ambientExternalModules: result.ambientExternalModules, @@ -963,7 +963,7 @@ namespace ts { public getTSConfigFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string { return this.forwardJSONCall( - "getTSConfigFileInfo('" + fileName + "')", + `getTSConfigFileInfo('${fileName}')`, () => { let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); @@ -977,7 +977,7 @@ namespace ts { }; } - var configFile = parseJsonConfigFileContent(result.config, this.host, getDirectoryPath(normalizeSlashes(fileName))); + let configFile = parseJsonConfigFileContent(result.config, this.host, getDirectoryPath(normalizeSlashes(fileName))); return { options: configFile.options, @@ -1012,8 +1012,8 @@ namespace ts { if (this.documentRegistry === undefined) { this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); } - var hostAdapter = new LanguageServiceShimHostAdapter(host); - var languageService = createLanguageService(hostAdapter, this.documentRegistry); + let hostAdapter = new LanguageServiceShimHostAdapter(host); + let languageService = createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService); } catch (err) { @@ -1034,7 +1034,7 @@ namespace ts { public createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim { try { - var adapter = new CoreServicesShimHostAdapter(host); + let adapter = new CoreServicesShimHostAdapter(host); return new CoreServicesShimObject(this, host, adapter); } catch (err) { @@ -1054,7 +1054,7 @@ namespace ts { } public unregisterShim(shim: Shim): void { - for (var i = 0, n = this._shims.length; i < n; i++) { + for (let i = 0, n = this._shims.length; i < n; i++) { if (this._shims[i] === shim) { delete this._shims[i]; return; From 55ae18b824a73da8e7b41597d6636b6c38c4a5e6 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Wed, 30 Dec 2015 14:23:47 -0800 Subject: [PATCH 3/8] update dom.generated.d.ts with latest version in TSJS repo --- src/lib/dom.generated.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 0dff2cedc39..0144d752b99 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -321,6 +321,7 @@ interface AudioContext extends EventTarget { destination: AudioDestinationNode; listener: AudioListener; sampleRate: number; + state: string; createAnalyser(): AnalyserNode; createBiquadFilter(): BiquadFilterNode; createBuffer(numberOfChannels: number, length: number, sampleRate: number): AudioBuffer; @@ -2774,6 +2775,7 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec tagName: string; id: string; className: string; + innerHTML: string; getAttribute(name?: string): string; getAttributeNS(namespaceURI: string, localName: string): string; getAttributeNode(name: string): Attr; @@ -2969,7 +2971,7 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec removeAttributeNode(oldAttr: Attr): Attr; requestFullscreen(): void; requestPointerLock(): void; - setAttribute(name?: string, value?: string): void; + setAttribute(name: string, value: string): void; setAttributeNS(namespaceURI: string, qualifiedName: string, value: string): void; setAttributeNode(newAttr: Attr): Attr; setAttributeNodeNS(newAttr: Attr): Attr; @@ -5512,7 +5514,7 @@ interface HTMLMediaElement extends HTMLElement { * Gets or sets the current playback position, in seconds. */ preload: string; - readyState: any; + readyState: number; /** * Returns a TimeRanges object that represents the ranges of the current media resource that can be seeked. */ @@ -6169,6 +6171,7 @@ interface HTMLSelectElement extends HTMLElement { * Returns whether an element will successfully validate based on forms validation rules and constraints. */ willValidate: boolean; + selectedOptions: HTMLCollection; /** * Adds an element to the areas, controlRange, or options collection. * @param element Variant of type Number that specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection. From 36af815bbabfc9d109336543ebb0fd4d85c67a12 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 6 Jan 2016 12:37:52 -0800 Subject: [PATCH 4/8] add optional 'directoryExists' method to hosts to reduce amount of disk probings that are known to fail --- src/compiler/program.ts | 36 ++- src/compiler/types.ts | 2 + src/harness/harnessLanguageService.ts | 4 + src/server/editorServices.ts | 3 +- src/services/services.ts | 8 +- src/services/shims.ts | 16 +- tests/cases/unittests/moduleResolution.ts | 263 ++++++++++++++-------- 7 files changed, 222 insertions(+), 110 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c9de6a0ed96..349c4a86efa 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -53,13 +53,13 @@ namespace ts { if (getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { const failedLookupLocations: string[] = []; const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); - let resolvedFileName = loadNodeModuleFromFile(supportedExtensions, candidate, failedLookupLocations, host); + let resolvedFileName = loadNodeModuleFromFile(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host); if (resolvedFileName) { return { resolvedModule: { resolvedFileName }, failedLookupLocations }; } - resolvedFileName = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, host); + resolvedFileName = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host); return resolvedFileName ? { resolvedModule: { resolvedFileName }, failedLookupLocations } : { resolvedModule: undefined, failedLookupLocations }; @@ -69,12 +69,22 @@ namespace ts { } } - function loadNodeModuleFromFile(extensions: string[], candidate: string, failedLookupLocation: string[], host: ModuleResolutionHost): string { + /* @internal */ + export function directoryProbablyExists(directoryName: string, host: { directoryExists?: (directoryName: string) => boolean } ): boolean { + // if host does not support 'directoryExists' assume that directory will exist + return !host.directoryExists || host.directoryExists(directoryName); + } + + /** + * @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary + * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations. + */ + function loadNodeModuleFromFile(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost): string { return forEach(extensions, tryLoad); function tryLoad(ext: string): string { const fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext; - if (host.fileExists(fileName)) { + if (!onlyRecordFailures && host.fileExists(fileName)) { return fileName; } else { @@ -84,9 +94,10 @@ namespace ts { } } - function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], host: ModuleResolutionHost): string { + function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost): string { const packageJsonPath = combinePaths(candidate, "package.json"); - if (host.fileExists(packageJsonPath)) { + const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, host); + if (directoryExists && host.fileExists(packageJsonPath)) { let jsonContent: { typings?: string }; @@ -100,7 +111,8 @@ namespace ts { } if (typeof jsonContent.typings === "string") { - const result = loadNodeModuleFromFile(extensions, normalizePath(combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host); + const path = normalizePath(combinePaths(candidate, jsonContent.typings)); + const result = loadNodeModuleFromFile(extensions, path, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(path), host), host); if (result) { return result; } @@ -111,7 +123,7 @@ namespace ts { failedLookupLocation.push(packageJsonPath); } - return loadNodeModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, host); + return loadNodeModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, host); } function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { @@ -121,14 +133,15 @@ namespace ts { const baseName = getBaseFileName(directory); if (baseName !== "node_modules") { const nodeModulesFolder = combinePaths(directory, "node_modules"); + const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, host); const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); // Load only typescript files irrespective of allowJs option if loading from node modules - let result = loadNodeModuleFromFile(supportedTypeScriptExtensions, candidate, failedLookupLocations, host); + let result = loadNodeModuleFromFile(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; } - result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, host); + result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; } @@ -281,7 +294,8 @@ namespace ts { getCanonicalFileName, getNewLine: () => newLine, fileExists: fileName => sys.fileExists(fileName), - readFile: fileName => sys.readFile(fileName) + readFile: fileName => sys.readFile(fileName), + directoryExists: directoryName => sys.directoryExists(directoryName) }; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 24f70373a8a..8fc5f5079fb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2649,6 +2649,8 @@ namespace ts { // readFile function is used to read arbitrary text files on disk, i.e. when resolution procedure needs the content of 'package.json' // to determine location of bundled typings for node module readFile(fileName: string): string; + + directoryExists?(directoryName: string): boolean; } export interface ResolvedModule { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index fb5b6ce92aa..a0cac439729 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -267,6 +267,10 @@ namespace Harness.LanguageService { log(s: string): void { this.nativeHost.log(s); } trace(s: string): void { this.nativeHost.trace(s); } error(s: string): void { this.nativeHost.error(s); } + directoryExists(directoryName: string): boolean { + // for tests pessimistically assume that directory always exists + return true; + } } class ClassifierShimProxy implements ts.Classifier { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index d78f7d40ef6..2c021106c74 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -100,7 +100,8 @@ namespace ts.server { this.filenameToScript = createFileMap(); this.moduleResolutionHost = { fileExists: fileName => this.fileExists(fileName), - readFile: fileName => this.host.readFile(fileName) + readFile: fileName => this.host.readFile(fileName), + directoryExists: directoryName => this.host.directoryExists(directoryName) }; } diff --git a/src/services/services.ts b/src/services/services.ts index 0fd4df19907..f2651163610 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1034,6 +1034,7 @@ namespace ts { * host specific questions using 'getScriptSnapshot'. */ resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; + directoryExists?(directoryName: string): boolean; } // @@ -1911,7 +1912,8 @@ namespace ts { getCurrentDirectory: () => "", getNewLine: () => newLine, fileExists: (fileName): boolean => fileName === inputFileName, - readFile: (fileName): string => "" + readFile: (fileName): string => "", + directoryExists: directoryExists => true }; const program = createProgram([inputFileName], options, compilerHost); @@ -2768,6 +2770,10 @@ namespace ts { // stub missing host functionality const entry = hostCache.getOrCreateEntry(fileName); return entry && entry.scriptSnapshot.getText(0, entry.scriptSnapshot.getLength()); + }, + directoryExists: directoryName => { + Debug.assert(!host.resolveModuleNames); + return directoryProbablyExists(directoryName, host); } }; diff --git a/src/services/shims.ts b/src/services/shims.ts index 6b656ea2738..397f86f871f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -62,6 +62,7 @@ namespace ts { useCaseSensitiveFileNames?(): boolean; getModuleResolutionsForFile?(fileName: string): string; + directoryExists(directoryName: string): boolean; } /** Public interface of the the of a config service shim instance.*/ @@ -274,6 +275,7 @@ namespace ts { private tracingEnabled = false; public resolveModuleNames: (moduleName: string[], containingFile: string) => ResolvedModule[]; + public directoryExists: (directoryName: string) => boolean; constructor(private shimHost: LanguageServiceShimHost) { // if shimHost is a COM object then property check will become method call with no arguments. @@ -287,6 +289,9 @@ namespace ts { }); }; } + if ("directoryExists" in this.shimHost) { + this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName); + } } public log(s: string): void { @@ -405,9 +410,14 @@ namespace ts { } } - export class CoreServicesShimHostAdapter implements ParseConfigHost { + export class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost { + public directoryExists: (directoryName: string) => boolean; + constructor(private shimHost: CoreServicesShimHost) { + if ("directoryExists" in this.shimHost) { + this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName); + } } public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { @@ -424,11 +434,11 @@ namespace ts { } return JSON.parse(encoded); } - + public fileExists(fileName: string): boolean { return this.shimHost.fileExists(fileName); } - + public readFile(fileName: string): string { return this.shimHost.readFile(fileName); } diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index 5b924650401..81d7c5f8b2e 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -26,15 +26,36 @@ module ts { content?: string } - function createModuleResolutionHost(...files: File[]): ModuleResolutionHost { + function createModuleResolutionHost(hasDirectoryExists: boolean, ...files: File[]): ModuleResolutionHost { let map = arrayToMap(files, f => f.name); - return { fileExists, readFile }; - - function fileExists(path: string): boolean { - return hasProperty(map, path); + if (hasDirectoryExists) { + const directories: Map = {}; + for (const f of files) { + let name = getDirectoryPath(f.name); + while (true) { + directories[name] = name; + let baseName = getDirectoryPath(name); + if (baseName === name) { + break; + } + name = baseName; + } + } + return { + readFile, + directoryExists: path => { + return hasProperty(directories, path); + }, + fileExists: path => { + assert.isTrue(hasProperty(directories, getDirectoryPath(path)), "'fileExists' request in non-existing directory"); + return hasProperty(map, path); + } + } + } + else { + return { readFile, fileExists: path => hasProperty(map, path), }; } - function readFile(path: string): string { return hasProperty(map, path) ? map[path].content : undefined; } @@ -51,9 +72,14 @@ module ts { function testLoadAsFile(containingFileName: string, moduleFileNameNoExt: string, moduleName: string): void { for (let ext of supportedTypeScriptExtensions) { + test(ext, /*hasDirectoryExists*/ false); + test(ext, /*hasDirectoryExists*/ true); + } + + function test(ext: string, hasDirectoryExists: boolean) { let containingFile = { name: containingFileName } let moduleFile = { name: moduleFileNameNoExt + ext } - let resolution = nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(containingFile, moduleFile)); + let resolution = nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); @@ -69,6 +95,7 @@ module ts { } assert.deepEqual(resolution.failedLookupLocations, failedLookupLocations); + } } @@ -89,14 +116,19 @@ module ts { }); function testLoadingFromPackageJson(containingFileName: string, packageJsonFileName: string, fieldRef: string, moduleFileName: string, moduleName: string): void { - let containingFile = { name: containingFileName }; - let packageJson = { name: packageJsonFileName, content: JSON.stringify({ "typings": fieldRef }) }; - let moduleFile = { name: moduleFileName }; - let resolution = nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(containingFile, packageJson, moduleFile)); - assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); - // expect three failed lookup location - attempt to load module as file with all supported extensions - assert.equal(resolution.failedLookupLocations.length, supportedTypeScriptExtensions.length); + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let containingFile = { name: containingFileName }; + let packageJson = { name: packageJsonFileName, content: JSON.stringify({ "typings": fieldRef }) }; + let moduleFile = { name: moduleFileName }; + let resolution = nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, moduleFile)); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); + // expect three failed lookup location - attempt to load module as file with all supported extensions + assert.equal(resolution.failedLookupLocations.length, supportedTypeScriptExtensions.length); + } } it("module name as directory - load from 'typings'", () => { @@ -107,16 +139,21 @@ module ts { }); function testTypingsIgnored(typings: any): void { - let containingFile = { name: "/a/b.ts" }; - let packageJson = { name: "/node_modules/b/package.json", content: JSON.stringify({ "typings": typings }) }; - let moduleFile = { name: "/a/b.d.ts" }; + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); - let indexPath = "/node_modules/b/index.d.ts"; - let indexFile = { name: indexPath } + function test(hasDirectoryExists: boolean) { + let containingFile = { name: "/a/b.ts" }; + let packageJson = { name: "/node_modules/b/package.json", content: JSON.stringify({ "typings": typings }) }; + let moduleFile = { name: "/a/b.d.ts" }; - let resolution = nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(containingFile, packageJson, moduleFile, indexFile)); + let indexPath = "/node_modules/b/index.d.ts"; + let indexFile = { name: indexPath } - assert.equal(resolution.resolvedModule.resolvedFileName, indexPath); + let resolution = nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, moduleFile, indexFile)); + + assert.equal(resolution.resolvedModule.resolvedFileName, indexPath); + } } it("module name as directory - handle invalid 'typings'", () => { @@ -128,89 +165,110 @@ module ts { }); it("module name as directory - load index.d.ts", () => { - let containingFile = { name: "/a/b/c.ts" }; - let packageJson = { name: "/a/b/foo/package.json", content: JSON.stringify({ main: "/c/d" }) }; - let indexFile = { name: "/a/b/foo/index.d.ts" }; - let resolution = nodeModuleNameResolver("./foo", containingFile.name, {}, createModuleResolutionHost(containingFile, packageJson, indexFile)); - assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name); - assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); - assert.deepEqual(resolution.failedLookupLocations, [ - "/a/b/foo.ts", - "/a/b/foo.tsx", - "/a/b/foo.d.ts", - "/a/b/foo/index.ts", - "/a/b/foo/index.tsx", - ]); + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let containingFile = { name: "/a/b/c.ts" }; + let packageJson = { name: "/a/b/foo/package.json", content: JSON.stringify({ main: "/c/d" }) }; + let indexFile = { name: "/a/b/foo/index.d.ts" }; + let resolution = nodeModuleNameResolver("./foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, indexFile)); + assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); + assert.deepEqual(resolution.failedLookupLocations, [ + "/a/b/foo.ts", + "/a/b/foo.tsx", + "/a/b/foo.d.ts", + "/a/b/foo/index.ts", + "/a/b/foo/index.tsx", + ]); + } }); }); describe("Node module resolution - non-relative paths", () => { it("load module as file - ts files not loaded", () => { - let containingFile = { name: "/a/b/c/d/e.ts" }; - let moduleFile = { name: "/a/b/node_modules/foo.ts" }; - let resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.deepEqual(resolution.failedLookupLocations, [ - "/a/b/c/d/node_modules/foo.ts", - "/a/b/c/d/node_modules/foo.tsx", - "/a/b/c/d/node_modules/foo.d.ts", - "/a/b/c/d/node_modules/foo/package.json", - "/a/b/c/d/node_modules/foo/index.ts", - "/a/b/c/d/node_modules/foo/index.tsx", - "/a/b/c/d/node_modules/foo/index.d.ts", - "/a/b/c/node_modules/foo.ts", - "/a/b/c/node_modules/foo.tsx", - "/a/b/c/node_modules/foo.d.ts", - "/a/b/c/node_modules/foo/package.json", - "/a/b/c/node_modules/foo/index.ts", - "/a/b/c/node_modules/foo/index.tsx", - "/a/b/c/node_modules/foo/index.d.ts", - ]) + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let containingFile = { name: "/a/b/c/d/e.ts" }; + let moduleFile = { name: "/a/b/node_modules/foo.ts" }; + let resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile)); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.deepEqual(resolution.failedLookupLocations, [ + "/a/b/c/d/node_modules/foo.ts", + "/a/b/c/d/node_modules/foo.tsx", + "/a/b/c/d/node_modules/foo.d.ts", + "/a/b/c/d/node_modules/foo/package.json", + "/a/b/c/d/node_modules/foo/index.ts", + "/a/b/c/d/node_modules/foo/index.tsx", + "/a/b/c/d/node_modules/foo/index.d.ts", + "/a/b/c/node_modules/foo.ts", + "/a/b/c/node_modules/foo.tsx", + "/a/b/c/node_modules/foo.d.ts", + "/a/b/c/node_modules/foo/package.json", + "/a/b/c/node_modules/foo/index.ts", + "/a/b/c/node_modules/foo/index.tsx", + "/a/b/c/node_modules/foo/index.d.ts", + ]) + } }); it("load module as file", () => { - let containingFile = { name: "/a/b/c/d/e.ts" }; - let moduleFile = { name: "/a/b/node_modules/foo.d.ts" }; - let resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let containingFile = { name: "/a/b/c/d/e.ts" }; + let moduleFile = { name: "/a/b/node_modules/foo.d.ts" }; + let resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile)); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); + } }); it("load module as directory", () => { - let containingFile = { name: "/a/node_modules/b/c/node_modules/d/e.ts" }; - let moduleFile = { name: "/a/node_modules/foo/index.d.ts" }; - let resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); - assert.deepEqual(resolution.failedLookupLocations, [ - "/a/node_modules/b/c/node_modules/d/node_modules/foo.ts", - "/a/node_modules/b/c/node_modules/d/node_modules/foo.tsx", - "/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts", - "/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json", - "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.ts", - "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.tsx", - "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.d.ts", - "/a/node_modules/b/c/node_modules/foo.ts", - "/a/node_modules/b/c/node_modules/foo.tsx", - "/a/node_modules/b/c/node_modules/foo.d.ts", - "/a/node_modules/b/c/node_modules/foo/package.json", - "/a/node_modules/b/c/node_modules/foo/index.ts", - "/a/node_modules/b/c/node_modules/foo/index.tsx", - "/a/node_modules/b/c/node_modules/foo/index.d.ts", - "/a/node_modules/b/node_modules/foo.ts", - "/a/node_modules/b/node_modules/foo.tsx", - "/a/node_modules/b/node_modules/foo.d.ts", - "/a/node_modules/b/node_modules/foo/package.json", - "/a/node_modules/b/node_modules/foo/index.ts", - "/a/node_modules/b/node_modules/foo/index.tsx", - "/a/node_modules/b/node_modules/foo/index.d.ts", - "/a/node_modules/foo.ts", - "/a/node_modules/foo.tsx", - "/a/node_modules/foo.d.ts", - "/a/node_modules/foo/package.json", - "/a/node_modules/foo/index.ts", - "/a/node_modules/foo/index.tsx" - ]); + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let containingFile = { name: "/a/node_modules/b/c/node_modules/d/e.ts" }; + let moduleFile = { name: "/a/node_modules/foo/index.d.ts" }; + let resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile)); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); + assert.deepEqual(resolution.failedLookupLocations, [ + "/a/node_modules/b/c/node_modules/d/node_modules/foo.ts", + "/a/node_modules/b/c/node_modules/d/node_modules/foo.tsx", + "/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts", + "/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json", + "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.ts", + "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.tsx", + "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.d.ts", + "/a/node_modules/b/c/node_modules/foo.ts", + "/a/node_modules/b/c/node_modules/foo.tsx", + "/a/node_modules/b/c/node_modules/foo.d.ts", + "/a/node_modules/b/c/node_modules/foo/package.json", + "/a/node_modules/b/c/node_modules/foo/index.ts", + "/a/node_modules/b/c/node_modules/foo/index.tsx", + "/a/node_modules/b/c/node_modules/foo/index.d.ts", + "/a/node_modules/b/node_modules/foo.ts", + "/a/node_modules/b/node_modules/foo.tsx", + "/a/node_modules/b/node_modules/foo.d.ts", + "/a/node_modules/b/node_modules/foo/package.json", + "/a/node_modules/b/node_modules/foo/index.ts", + "/a/node_modules/b/node_modules/foo/index.tsx", + "/a/node_modules/b/node_modules/foo/index.d.ts", + "/a/node_modules/foo.ts", + "/a/node_modules/foo.tsx", + "/a/node_modules/foo.d.ts", + "/a/node_modules/foo/package.json", + "/a/node_modules/foo/index.ts", + "/a/node_modules/foo/index.tsx" + ]); + + } }); }); @@ -400,4 +458,21 @@ import b = require("./moduleB.ts"); test(files, { module: ts.ModuleKind.CommonJS, forceConsistentCasingInFileNames: true }, "/a/B/c", /* useCaseSensitiveFileNames */ false, ["moduleD.ts"], []); }) }); + + function notImplemented(name: string): () => any { + return () => assert(`${name} is not implemented and should not be called`); + } + + describe("ModuleResolutionHost.directoryExists", () => { + it("No 'fileExists' calls if containing directory is missing", () => { + const host: ModuleResolutionHost = { + readFile: notImplemented("readFile"), + fileExists: notImplemented("fileExists"), + directoryExists: _ => false + }; + + const result = resolveModuleName("someName", "/a/b/c/d", { moduleResolution: ModuleResolutionKind.NodeJs }, host); + assert(!result.resolvedModule); + }); + }); } \ No newline at end of file From f0a4d6fd0be706950b58ceb5e88be7b8e7f0ef06 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 8 Jan 2016 02:00:20 +0900 Subject: [PATCH 5/8] enclose entryName --- src/services/shims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 31171ba2f98..0a48d5c2523 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -791,7 +791,7 @@ namespace ts { /** Get a string based representation of a completion list entry details */ public getCompletionEntryDetails(fileName: string, position: number, entryName: string) { return this.forwardJSONCall( - `getCompletionEntryDetails('${fileName}', ${position}, ${entryName})`, + `getCompletionEntryDetails('${fileName}', ${position}, '${entryName}')`, () => { let details = this.languageService.getCompletionEntryDetails(fileName, position, entryName); return details; From 5144603b3bcce421cd3dea08bdd75767b54800e5 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 8 Jan 2016 02:16:14 +0900 Subject: [PATCH 6/8] const everywhere --- src/services/shims.ts | 77 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 0a48d5c2523..88042d0e821 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -248,14 +248,14 @@ namespace ts { } public getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange { - let oldSnapshotShim = oldSnapshot; - let encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim); + const oldSnapshotShim = oldSnapshot; + const encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim); // TODO: should this be '==='? if (encoded == null) { return null; } - let decoded: { span: { start: number; length: number; }; newLength: number; } = JSON.parse(encoded); + const decoded: { span: { start: number; length: number; }; newLength: number; } = JSON.parse(encoded); return createTextChangeRange( createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); } @@ -282,7 +282,7 @@ namespace ts { // 'in' does not have this effect. if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = (moduleNames: string[], containingFile: string) => { - let resolutionsInFile = >JSON.parse(this.shimHost.getModuleResolutionsForFile(containingFile)); + const resolutionsInFile = >JSON.parse(this.shimHost.getModuleResolutionsForFile(containingFile)); return map(moduleNames, name => { const result = lookUp(resolutionsInFile, name); return result ? { resolvedFileName: result } : undefined; @@ -324,7 +324,7 @@ namespace ts { } public getCompilationSettings(): CompilerOptions { - let settingsJson = this.shimHost.getCompilationSettings(); + const settingsJson = this.shimHost.getCompilationSettings(); // TODO: should this be '==='? if (settingsJson == null || settingsJson == "") { throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings"); @@ -333,12 +333,12 @@ namespace ts { } public getScriptFileNames(): string[] { - let encoded = this.shimHost.getScriptFileNames(); + const encoded = this.shimHost.getScriptFileNames(); return this.files = JSON.parse(encoded); } public getScriptSnapshot(fileName: string): IScriptSnapshot { - let scriptSnapshot = this.shimHost.getScriptSnapshot(fileName); + const scriptSnapshot = this.shimHost.getScriptSnapshot(fileName); return scriptSnapshot && new ScriptSnapshotShimAdapter(scriptSnapshot); } @@ -347,7 +347,7 @@ namespace ts { } public getLocalizedDiagnosticMessages(): any { - let diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages(); + const diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages(); if (diagnosticMessagesJson == null || diagnosticMessagesJson == "") { return null; } @@ -362,7 +362,7 @@ namespace ts { } public getCancellationToken(): HostCancellationToken { - let hostCancellationToken = this.shimHost.getCancellationToken(); + const hostCancellationToken = this.shimHost.getCancellationToken(); return new ThrottledCancellationToken(hostCancellationToken); } @@ -386,8 +386,8 @@ namespace ts { } public isCancellationRequested(): boolean { - let time = Date.now(); - let duration = Math.abs(time - this.lastCancellationCheckTime); + const time = Date.now(); + const duration = Math.abs(time - this.lastCancellationCheckTime); if (duration > 10) { // Check no more than once every 10 ms. this.lastCancellationCheckTime = time; @@ -411,7 +411,7 @@ namespace ts { public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { // Consider removing the optional designation for // the exclude param at this time. - let encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); + const encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); return JSON.parse(encoded); } @@ -431,10 +431,10 @@ namespace ts { start = Date.now(); } - let result = action(); + const result = action(); if (logPerformance) { - let end = Date.now(); + const end = Date.now(); logger.log(`${actionDescription} completed in ${end - start} msec`); if (typeof result === "string") { let str = result; @@ -450,8 +450,8 @@ namespace ts { function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): string { try { - let result = simpleForwardCall(logger, actionDescription, action, logPerformance); - return JSON.stringify({ result: result }); + const result = simpleForwardCall(logger, actionDescription, action, logPerformance); + return JSON.stringify({ result }); } catch (err) { if (err instanceof OperationCanceledException) { @@ -547,7 +547,7 @@ namespace ts { } private realizeDiagnostics(diagnostics: Diagnostic[]): { message: string; start: number; length: number; category: string; }[] { - let newLine = getNewLineOrDefaultFromHost(this.host); + const newLine = getNewLineOrDefaultFromHost(this.host); return ts.realizeDiagnostics(diagnostics, newLine); } @@ -730,7 +730,7 @@ namespace ts { return this.forwardJSONCall( `getIndentationAtPosition('${fileName}', ${position})`, () => { - let localOptions: EditorOptions = JSON.parse(options); + const localOptions: EditorOptions = JSON.parse(options); return this.languageService.getIndentationAtPosition(fileName, position, localOptions); }); } @@ -765,9 +765,9 @@ namespace ts { return this.forwardJSONCall( `getDocumentHighlights('${fileName}', ${position})`, () => { - let results = this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch)); + const results = this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch)); // workaround for VS document higlighting issue - keep only items from the initial file - let normalizedName = normalizeSlashes(fileName).toLowerCase(); + const normalizedName = normalizeSlashes(fileName).toLowerCase(); return filter(results, r => normalizeSlashes(r.fileName).toLowerCase() === normalizedName); }); } @@ -802,9 +802,8 @@ namespace ts { return this.forwardJSONCall( `getFormattingEditsForRange('${fileName}', ${start}, ${end})`, () => { - let localOptions: ts.FormatCodeOptions = JSON.parse(options); - let edits = this.languageService.getFormattingEditsForRange(fileName, start, end, localOptions); - return edits; + const localOptions: ts.FormatCodeOptions = JSON.parse(options); + return this.languageService.getFormattingEditsForRange(fileName, start, end, localOptions); }); } @@ -812,9 +811,8 @@ namespace ts { return this.forwardJSONCall( `getFormattingEditsForDocument('${fileName}')`, () => { - let localOptions: ts.FormatCodeOptions = JSON.parse(options); - let edits = this.languageService.getFormattingEditsForDocument(fileName, localOptions); - return edits; + const localOptions: ts.FormatCodeOptions = JSON.parse(options); + return this.languageService.getFormattingEditsForDocument(fileName, localOptions); }); } @@ -822,9 +820,8 @@ namespace ts { return this.forwardJSONCall( `getFormattingEditsAfterKeystroke('${fileName}', ${position}, '${key}')`, () => { - let localOptions: ts.FormatCodeOptions = JSON.parse(options); - let edits = this.languageService.getFormattingEditsAfterKeystroke(fileName, position, key, localOptions); - return edits; + const localOptions: ts.FormatCodeOptions = JSON.parse(options); + return this.languageService.getFormattingEditsAfterKeystroke(fileName, position, key, localOptions); }); } @@ -906,9 +903,9 @@ namespace ts { /// COLORIZATION public getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string { - let classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics); + const classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics); let result = ""; - for (let item of classification.entries) { + for (const item of classification.entries) { result += item.length + "\n"; result += item.classification + "\n"; } @@ -930,7 +927,7 @@ namespace ts { public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => { - let compilerOptions = JSON.parse(compilerOptionsJson); + const compilerOptions = JSON.parse(compilerOptionsJson); const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); return { resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined, @@ -944,8 +941,8 @@ namespace ts { "getPreProcessedFileInfo('" + fileName + "')", () => { // for now treat files as JavaScript - let result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()), /* readImportFiles */ true, /* detectJavaScriptImports */ true); - let convertResult = { + const result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()), /* readImportFiles */ true, /* detectJavaScriptImports */ true); + const convertResult = { referencedFiles: [], importedFiles: [], ambientExternalModules: result.ambientExternalModules, @@ -975,9 +972,9 @@ namespace ts { return this.forwardJSONCall( `getTSConfigFileInfo('${fileName}')`, () => { - let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); + const text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - let result = parseConfigFileTextToJson(fileName, text); + const result = parseConfigFileTextToJson(fileName, text); if (result.error) { return { @@ -987,7 +984,7 @@ namespace ts { }; } - let configFile = parseJsonConfigFileContent(result.config, this.host, getDirectoryPath(normalizeSlashes(fileName))); + const configFile = parseJsonConfigFileContent(result.config, this.host, getDirectoryPath(normalizeSlashes(fileName))); return { options: configFile.options, @@ -1022,8 +1019,8 @@ namespace ts { if (this.documentRegistry === undefined) { this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); } - let hostAdapter = new LanguageServiceShimHostAdapter(host); - let languageService = createLanguageService(hostAdapter, this.documentRegistry); + const hostAdapter = new LanguageServiceShimHostAdapter(host); + const languageService = createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService); } catch (err) { @@ -1044,7 +1041,7 @@ namespace ts { public createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim { try { - let adapter = new CoreServicesShimHostAdapter(host); + const adapter = new CoreServicesShimHostAdapter(host); return new CoreServicesShimObject(this, host, adapter); } catch (err) { From 5cafd962e9c489a2a6aa9720932889e2eb2feb15 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 8 Jan 2016 02:24:32 +0900 Subject: [PATCH 7/8] thinner arrows --- src/services/shims.ts | 157 ++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 98 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 88042d0e821..4551013ff8d 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -276,7 +276,7 @@ namespace ts { public resolveModuleNames: (moduleName: string[], containingFile: string) => ResolvedModule[]; public directoryExists: (directoryName: string) => boolean; - + constructor(private shimHost: LanguageServiceShimHost) { // if shimHost is a COM object then property check will become method call with no arguments. // 'in' does not have this effect. @@ -401,7 +401,7 @@ namespace ts { export class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost { public directoryExists: (directoryName: string) => boolean; - + constructor(private shimHost: CoreServicesShimHost) { if ("directoryExists" in this.shimHost) { this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName); @@ -532,9 +532,8 @@ namespace ts { public refresh(throwOnError: boolean): void { this.forwardJSONCall( `refresh(${throwOnError})`, - () => { - return null; - }); + () => null + ); } public cleanupSemanticCache(): void { @@ -554,46 +553,40 @@ namespace ts { public getSyntacticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( `getSyntacticClassifications('${fileName}', ${start}, ${length})`, - () => { - let classifications = this.languageService.getSyntacticClassifications(fileName, createTextSpan(start, length)); - return classifications; - }); + () => this.languageService.getSyntacticClassifications(fileName, createTextSpan(start, length)) + ); } public getSemanticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( `getSemanticClassifications('${fileName}', ${start}, ${length})`, - () => { - let classifications = this.languageService.getSemanticClassifications(fileName, createTextSpan(start, length)); - return classifications; - }); + () => this.languageService.getSemanticClassifications(fileName, createTextSpan(start, length)) + ); } public getEncodedSyntacticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( `getEncodedSyntacticClassifications('${fileName}', ${start}, ${length})`, - () => { - // directly serialize the spans out to a string. This is much faster to decode - // on the managed side versus a full JSON array. - return convertClassifications(this.languageService.getEncodedSyntacticClassifications(fileName, createTextSpan(start, length))); - }); + // directly serialize the spans out to a string. This is much faster to decode + // on the managed side versus a full JSON array. + () => convertClassifications(this.languageService.getEncodedSyntacticClassifications(fileName, createTextSpan(start, length))) + ); } public getEncodedSemanticClassifications(fileName: string, start: number, length: number): string { return this.forwardJSONCall( `getEncodedSemanticClassifications('${fileName}', ${start}, ${length})`, - () => { - // directly serialize the spans out to a string. This is much faster to decode - // on the managed side versus a full JSON array. - return convertClassifications(this.languageService.getEncodedSemanticClassifications(fileName, createTextSpan(start, length))); - }); + // directly serialize the spans out to a string. This is much faster to decode + // on the managed side versus a full JSON array. + () => convertClassifications(this.languageService.getEncodedSemanticClassifications(fileName, createTextSpan(start, length))) + ); } public getSyntacticDiagnostics(fileName: string): string { return this.forwardJSONCall( `getSyntacticDiagnostics('${fileName}')`, () => { - let diagnostics = this.languageService.getSyntacticDiagnostics(fileName); + const diagnostics = this.languageService.getSyntacticDiagnostics(fileName); return this.realizeDiagnostics(diagnostics); }); } @@ -602,7 +595,7 @@ namespace ts { return this.forwardJSONCall( `getSemanticDiagnostics('${fileName}')`, () => { - let diagnostics = this.languageService.getSemanticDiagnostics(fileName); + const diagnostics = this.languageService.getSemanticDiagnostics(fileName); return this.realizeDiagnostics(diagnostics); }); } @@ -611,7 +604,7 @@ namespace ts { return this.forwardJSONCall( "getCompilerOptionsDiagnostics()", () => { - let diagnostics = this.languageService.getCompilerOptionsDiagnostics(); + const diagnostics = this.languageService.getCompilerOptionsDiagnostics(); return this.realizeDiagnostics(diagnostics); }); } @@ -625,10 +618,8 @@ namespace ts { public getQuickInfoAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getQuickInfoAtPosition('${fileName}', ${position})`, - () => { - let quickInfo = this.languageService.getQuickInfoAtPosition(fileName, position); - return quickInfo; - }); + () => this.languageService.getQuickInfoAtPosition(fileName, position) + ); } @@ -641,10 +632,8 @@ namespace ts { public getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string { return this.forwardJSONCall( `getNameOrDottedNameSpan('${fileName}', ${startPos}, ${endPos})`, - () => { - let spanInfo = this.languageService.getNameOrDottedNameSpan(fileName, startPos, endPos); - return spanInfo; - }); + () => this.languageService.getNameOrDottedNameSpan(fileName, startPos, endPos) + ); } /** @@ -654,10 +643,8 @@ namespace ts { public getBreakpointStatementAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getBreakpointStatementAtPosition('${fileName}', ${position})`, - () => { - let spanInfo = this.languageService.getBreakpointStatementAtPosition(fileName, position); - return spanInfo; - }); + () => this.languageService.getBreakpointStatementAtPosition(fileName, position) + ); } /// SIGNATUREHELP @@ -665,10 +652,8 @@ namespace ts { public getSignatureHelpItems(fileName: string, position: number): string { return this.forwardJSONCall( `getSignatureHelpItems('${fileName}', ${position})`, - () => { - let signatureInfo = this.languageService.getSignatureHelpItems(fileName, position); - return signatureInfo; - }); + () => this.languageService.getSignatureHelpItems(fileName, position) + ); } /// GOTO DEFINITION @@ -680,9 +665,8 @@ namespace ts { public getDefinitionAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getDefinitionAtPosition('${fileName}', ${position})`, - () => { - return this.languageService.getDefinitionAtPosition(fileName, position); - }); + () => this.languageService.getDefinitionAtPosition(fileName, position) + ); } /// GOTO Type @@ -694,35 +678,30 @@ namespace ts { public getTypeDefinitionAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getTypeDefinitionAtPosition('${fileName}', ${position})`, - () => { - return this.languageService.getTypeDefinitionAtPosition(fileName, position); - }); + () => this.languageService.getTypeDefinitionAtPosition(fileName, position) + ); } public getRenameInfo(fileName: string, position: number): string { return this.forwardJSONCall( `getRenameInfo('${fileName}', ${position})`, - () => { - return this.languageService.getRenameInfo(fileName, position); - }); + () => this.languageService.getRenameInfo(fileName, position) + ); } public findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): string { return this.forwardJSONCall( `findRenameLocations('${fileName}', ${position}, ${findInStrings}, ${findInComments})`, - () => { - return this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments); - }); + () => this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments) + ); } /// GET BRACE MATCHING public getBraceMatchingAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getBraceMatchingAtPosition('${fileName}', ${position})`, - () => { - let textRanges = this.languageService.getBraceMatchingAtPosition(fileName, position); - return textRanges; - }); + () => this.languageService.getBraceMatchingAtPosition(fileName, position) + ); } /// GET SMART INDENT @@ -740,25 +719,22 @@ namespace ts { public getReferencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getReferencesAtPosition('${fileName}', ${position})`, - () => { - return this.languageService.getReferencesAtPosition(fileName, position); - }); + () => this.languageService.getReferencesAtPosition(fileName, position) + ); } public findReferences(fileName: string, position: number): string { return this.forwardJSONCall( `findReferences('${fileName}', ${position})`, - () => { - return this.languageService.findReferences(fileName, position); - }); + () => this.languageService.findReferences(fileName, position) + ); } public getOccurrencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( `getOccurrencesAtPosition('${fileName}', ${position})`, - () => { - return this.languageService.getOccurrencesAtPosition(fileName, position); - }); + () => this.languageService.getOccurrencesAtPosition(fileName, position) + ); } public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string { @@ -782,20 +758,16 @@ namespace ts { public getCompletionsAtPosition(fileName: string, position: number) { return this.forwardJSONCall( `getCompletionsAtPosition('${fileName}', ${position})`, - () => { - let completion = this.languageService.getCompletionsAtPosition(fileName, position); - return completion; - }); + () => this.languageService.getCompletionsAtPosition(fileName, position) + ); } /** Get a string based representation of a completion list entry details */ public getCompletionEntryDetails(fileName: string, position: number, entryName: string) { return this.forwardJSONCall( `getCompletionEntryDetails('${fileName}', ${position}, '${entryName}')`, - () => { - let details = this.languageService.getCompletionEntryDetails(fileName, position, entryName); - return details; - }); + () => this.languageService.getCompletionEntryDetails(fileName, position, entryName) + ); } public getFormattingEditsForRange(fileName: string, start: number, end: number, options: string/*Services.FormatCodeOptions*/): string { @@ -838,47 +810,37 @@ namespace ts { public getNavigateToItems(searchValue: string, maxResultCount?: number): string { return this.forwardJSONCall( `getNavigateToItems('${searchValue}', ${maxResultCount})`, - () => { - let items = this.languageService.getNavigateToItems(searchValue, maxResultCount); - return items; - }); + () => this.languageService.getNavigateToItems(searchValue, maxResultCount) + ); } public getNavigationBarItems(fileName: string): string { return this.forwardJSONCall( `getNavigationBarItems('${fileName}')`, - () => { - let items = this.languageService.getNavigationBarItems(fileName); - return items; - }); + () => this.languageService.getNavigationBarItems(fileName) + ); } public getOutliningSpans(fileName: string): string { return this.forwardJSONCall( `getOutliningSpans('${fileName}')`, - () => { - let items = this.languageService.getOutliningSpans(fileName); - return items; - }); + () => this.languageService.getOutliningSpans(fileName) + ); } public getTodoComments(fileName: string, descriptors: string): string { return this.forwardJSONCall( `getTodoComments('${fileName}')`, - () => { - let items = this.languageService.getTodoComments(fileName, JSON.parse(descriptors)); - return items; - }); + () => this.languageService.getTodoComments(fileName, JSON.parse(descriptors)) + ); } /// Emit public getEmitOutput(fileName: string): string { return this.forwardJSONCall( `getEmitOutput('${fileName}')`, - () => { - let output = this.languageService.getEmitOutput(fileName); - return output; - }); + () => this.languageService.getEmitOutput(fileName) + ); } } @@ -997,9 +959,8 @@ namespace ts { public getDefaultCompilationSettings(): string { return this.forwardJSONCall( "getDefaultCompilationSettings()", - () => { - return getDefaultCompilerOptions(); - }); + () => getDefaultCompilerOptions() + ); } } From 4ef8e0bb734dd1041578aa155dae01787aa97828 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 8 Jan 2016 02:25:29 +0900 Subject: [PATCH 8/8] remove unneeded comment --- src/services/shims.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 4551013ff8d..90a015240f0 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -409,8 +409,6 @@ namespace ts { } public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { - // Consider removing the optional designation for - // the exclude param at this time. const encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); return JSON.parse(encoded); }