From 1c4f7119f8cf6b895eeb10c6631ce333786b45bf Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Oct 2014 15:21:07 -0700 Subject: [PATCH 01/18] Refactoring functions related to processImport --- src/services/compiler/precompile.ts | 172 +--------------------------- src/services/services.ts | 165 ++++++++++++++++++++++++++ src/services/shims.ts | 2 +- 3 files changed, 170 insertions(+), 169 deletions(-) diff --git a/src/services/compiler/precompile.ts b/src/services/compiler/precompile.ts index 3ff23d85bea..ea4f6364eff 100644 --- a/src/services/compiler/precompile.ts +++ b/src/services/compiler/precompile.ts @@ -20,7 +20,7 @@ module TypeScript { } // Note: This is being using by the host (VS) and is marshaled back and forth. When changing this make sure the changes - // are reflected in the managed side as well. + // are reflected in the managed side as well export interface IFileReference extends ILineAndCharacter { path: string; isResident: boolean; @@ -28,181 +28,17 @@ module TypeScript { length: number; } - /// - /// Preprocessing - /// export interface IPreProcessedFileInfo { referencedFiles: IFileReference[]; importedFiles: IFileReference[]; - diagnostics: Diagnostic[]; - isLibFile: boolean; + diagnostics: TypeScript.Diagnostic[]; + isLibFile: boolean } interface ITripleSlashDirectiveProperties { noDefaultLib: boolean; - diagnostics: Diagnostic[]; + diagnostics: TypeScript.Diagnostic[]; referencedFiles: IFileReference[]; } - function isNoDefaultLibMatch(comment: string): RegExpExecArray { - var isNoDefaultLibRegex = /^(\/\/\/\s*/gim; - return isNoDefaultLibRegex.exec(comment); - } - - export var tripleSlashReferenceRegExp = /^(\/\/\/\s*/; - - function getFileReferenceFromReferencePath(fileName: string, text: ISimpleText, position: number, comment: string, diagnostics: Diagnostic[]): IFileReference { - // First, just see if they've written: /// = 7 && fullReference[6] === "true"; - return { - line: 0, - character: 0, - position: 0, - length: 0, - path: switchToForwardSlashes(adjustedPath), - isResident: isResident - }; - } - } - } - - return null; - } - - var reportDiagnostic = () => { }; - - function processImports(text: ISimpleText, scanner: Scanner.IScanner, token: ISyntaxToken, importedFiles: IFileReference[]): void { - var lineChar = { line: -1, character: -1 }; - - var lineMap = text.lineMap(); - var start = new Date().getTime(); - // Look for: - // import foo = module("foo") - while (token.kind() !== SyntaxKind.EndOfFileToken) { - if (token.kind() === SyntaxKind.ImportKeyword) { - var importToken = token; - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (SyntaxFacts.isIdentifierNameOrAnyKeyword(token)) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (token.kind() === SyntaxKind.EqualsToken) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (token.kind() === SyntaxKind.ModuleKeyword || token.kind() === SyntaxKind.RequireKeyword) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (token.kind() === SyntaxKind.OpenParenToken) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - lineMap.fillLineAndCharacterFromPosition(TypeScript.start(importToken, text), lineChar); - - if (token.kind() === SyntaxKind.StringLiteral) { - var ref = { - line: lineChar.line, - character: lineChar.character, - position: TypeScript.start(token, text), - length: width(token), - path: stripStartAndEndQuotes(switchToForwardSlashes(token.text())), - isResident: false - }; - importedFiles.push(ref); - } - } - } - } - } - } - - token = scanner.scan(/*allowRegularExpression:*/ false); - } - - var totalTime = new Date().getTime() - start; - //TypeScript.fileResolutionScanImportsTime += totalTime; - } - - function processTripleSlashDirectives(fileName: string, text: ISimpleText, firstToken: ISyntaxToken): ITripleSlashDirectiveProperties { - var leadingTrivia = firstToken.leadingTrivia(text); - - var position = 0; - var lineChar = { line: -1, character: -1 }; - var noDefaultLib = false; - var diagnostics: Diagnostic[] = []; - var referencedFiles: IFileReference[] = []; - var lineMap = text.lineMap(); - - for (var i = 0, n = leadingTrivia.count(); i < n; i++) { - var trivia = leadingTrivia.syntaxTriviaAt(i); - - if (trivia.kind() === SyntaxKind.SingleLineCommentTrivia) { - var triviaText = trivia.fullText(); - var referencedCode = getFileReferenceFromReferencePath(fileName, text, position, triviaText, diagnostics); - - if (referencedCode) { - lineMap.fillLineAndCharacterFromPosition(position, lineChar); - referencedCode.position = position; - referencedCode.length = trivia.fullWidth(); - referencedCode.line = lineChar.line; - referencedCode.character = lineChar.character; - - referencedFiles.push(referencedCode); - } - - // is it a lib file? - var isNoDefaultLib = isNoDefaultLibMatch(triviaText); - if (isNoDefaultLib) { - noDefaultLib = isNoDefaultLib[3] === "true"; - } - } - - position += trivia.fullWidth(); - } - - return { noDefaultLib: noDefaultLib, diagnostics: diagnostics, referencedFiles: referencedFiles }; - } - - export function preProcessFile(fileName: string, sourceText: IScriptSnapshot, readImportFiles = true): IPreProcessedFileInfo { - var text = SimpleText.fromScriptSnapshot(sourceText); - var scanner = Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic); - - var firstToken = scanner.scan(/*allowRegularExpression:*/ false); - - // only search out dynamic mods - // if you find a dynamic mod, ignore every other mod inside, until you balance rcurlies - // var position - - var importedFiles: IFileReference[] = []; - if (readImportFiles) { - processImports(text, scanner, firstToken, importedFiles); - } - - var properties = processTripleSlashDirectives(fileName, text, firstToken); - - return { referencedFiles: properties.referencedFiles, importedFiles: importedFiles, isLibFile: properties.noDefaultLib, diagnostics: properties.diagnostics }; - } - - export function getReferencedFiles(fileName: string, sourceText: IScriptSnapshot): IFileReference[] { - return preProcessFile(fileName, sourceText, false).referencedFiles; - } } // Tools \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 5411cac8d0c..b64a5207b85 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -77,6 +77,15 @@ module ts { update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile; } + /// + /// Pre-processing + /// + interface ITripleSlashDirectiveProperties { + noDefaultLib: boolean; + diagnostics: TypeScript.Diagnostic[]; + referencedFiles: TypeScript.IFileReference[]; + } + var scanner: Scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ true); var emptyArray: any[] = []; @@ -1895,6 +1904,162 @@ module ts { }; } + export var tripleSlashReferenceRegExp = /^(\/\/\/\s*/; + export function preProcessFile(fileName: string, sourceText: TypeScript.IScriptSnapshot, readImportFiles = true): TypeScript.IPreProcessedFileInfo { + var reportDiagnostic = () => { } + function isNoDefaultLibMatch(comment: string): RegExpExecArray { + var isNoDefaultLibRegex = /^(\/\/\/\s*/gim; + return isNoDefaultLibRegex.exec(comment); + } + + function getFileReferenceFromReferencePath(fileName: string, text: TypeScript.ISimpleText, position: number, comment: string, diagnostics: TypeScript.Diagnostic[]): TypeScript.IFileReference { + // First, just see if they've written: /// = 7 && fullReference[6] === "true"; + return { + line: 0, + character: 0, + position: 0, + length: 0, + path: TypeScript.switchToForwardSlashes(adjustedPath), + isResident: isResident + }; + } + } + } + + return null; + } + + function processImports(text: TypeScript.ISimpleText, scanner: TypeScript.Scanner.IScanner, token: TypeScript.ISyntaxToken, importedFiles: TypeScript.IFileReference[]): void { + var lineChar = { line: -1, character: -1 }; + + var lineMap = text.lineMap(); + var start = new Date().getTime(); + // Look for: + // import foo = module("foo") + while (token.kind() !== TypeScript.SyntaxKind.EndOfFileToken) { + if (token.kind() === TypeScript.SyntaxKind.ImportKeyword) { + var importToken = token; + token = scanner.scan(/*allowRegularExpression:*/ false); + + if (TypeScript.SyntaxFacts.isIdentifierNameOrAnyKeyword(token)) { + token = scanner.scan(/*allowRegularExpression:*/ false); + + if (token.kind() === TypeScript.SyntaxKind.EqualsToken) { + token = scanner.scan(/*allowRegularExpression:*/ false); + + if (token.kind() === TypeScript.SyntaxKind.ModuleKeyword || token.kind() === TypeScript.SyntaxKind.RequireKeyword) { + token = scanner.scan(/*allowRegularExpression:*/ false); + + if (token.kind() === TypeScript.SyntaxKind.OpenParenToken) { + token = scanner.scan(/*allowRegularExpression:*/ false); + + lineMap.fillLineAndCharacterFromPosition(TypeScript.start(importToken, text), lineChar); + + if (token.kind() === TypeScript.SyntaxKind.StringLiteral) { + var ref = { + line: lineChar.line, + character: lineChar.character, + position: TypeScript.start(token, text), + length: TypeScript.width(token), + path: TypeScript.stripStartAndEndQuotes(TypeScript.switchToForwardSlashes(token.text())), + isResident: false + }; + importedFiles.push(ref); + } + } + } + } + } + } + + token = scanner.scan(/*allowRegularExpression:*/ false); + } + + var totalTime = new Date().getTime() - start; + //TypeScript.fileResolutionScanImportsTime += totalTime + } + + function processTripleSlashDirectives(fileName: string, text: TypeScript.ISimpleText, firstToken: TypeScript.ISyntaxToken): ITripleSlashDirectiveProperties { + var leadingTrivia = firstToken.leadingTrivia(text); + + var position = 0; + var lineChar = { line: -1, character: -1 }; + var noDefaultLib = false; + var diagnostics: TypeScript.Diagnostic[] = []; + var referencedFiles: TypeScript.IFileReference[] = []; + var lineMap = text.lineMap(); + + for (var i = 0, n = leadingTrivia.count(); i < n; i++) { + var trivia = leadingTrivia.syntaxTriviaAt(i); + + if (trivia.kind() === TypeScript.SyntaxKind.SingleLineCommentTrivia) { + var triviaText = trivia.fullText(); + var referencedCode = getFileReferenceFromReferencePath(fileName, text, position, triviaText, diagnostics); + + if (referencedCode) { + lineMap.fillLineAndCharacterFromPosition(position, lineChar); + referencedCode.position = position; + referencedCode.length = trivia.fullWidth(); + referencedCode.line = lineChar.line; + referencedCode.character = lineChar.character; + + referencedFiles.push(referencedCode); + } + + // is it a lib file? + var isNoDefaultLib = isNoDefaultLibMatch(triviaText); + if (isNoDefaultLib) { + noDefaultLib = isNoDefaultLib[3] === "true"; + } + } + + position += trivia.fullWidth(); + } + + return { noDefaultLib: noDefaultLib, diagnostics: diagnostics, referencedFiles: referencedFiles }; + } + + var text = TypeScript.SimpleText.fromScriptSnapshot(sourceText); + var scanner = TypeScript.Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic); + + var firstToken = scanner.scan(/*allowRegularExpression:*/ false); + + // only search out dynamic mods + // if you find a dynamic mod, ignore every other mod inside, until you balance rcurlies + // var position + + var importedFiles: TypeScript.IFileReference[] = []; + if (readImportFiles) { + processImports(text, scanner, firstToken, importedFiles); + } + + var properties = processTripleSlashDirectives(fileName, text, firstToken); + + return { referencedFiles: properties.referencedFiles, importedFiles: importedFiles, isLibFile: properties.noDefaultLib, diagnostics: properties.diagnostics }; + } + /// Helpers export function getNodeModifiers(node: Node): string { var flags = node.flags; diff --git a/src/services/shims.ts b/src/services/shims.ts index fdea0202323..4a31dc62331 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -847,7 +847,7 @@ module ts { return this.forwardJSONCall( "getPreProcessedFileInfo('" + fileName + "')", () => { - var result = TypeScript.preProcessFile(fileName, sourceText); + var result = ts.preProcessFile(fileName, sourceText); //TypeScript.preProcessFile(fileName, sourceText); return result; }); } From 1e4b4dfe91a35c807ba12de9e110db9f9b150776 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 22 Oct 2014 18:36:20 -0700 Subject: [PATCH 02/18] Refactoring preProcessFile to use new scanner --- src/services/compiler/precompile.ts | 44 ------- src/services/core/lineMap.ts | 5 + src/services/services.ts | 191 ++++++++++------------------ src/services/shims.ts | 3 +- 4 files changed, 74 insertions(+), 169 deletions(-) delete mode 100644 src/services/compiler/precompile.ts diff --git a/src/services/compiler/precompile.ts b/src/services/compiler/precompile.ts deleted file mode 100644 index ea4f6364eff..00000000000 --- a/src/services/compiler/precompile.ts +++ /dev/null @@ -1,44 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -module TypeScript { - export interface ILineAndCharacter { - line: number; - character: number; - } - - // Note: This is being using by the host (VS) and is marshaled back and forth. When changing this make sure the changes - // are reflected in the managed side as well - export interface IFileReference extends ILineAndCharacter { - path: string; - isResident: boolean; - position: number; - length: number; - } - - export interface IPreProcessedFileInfo { - referencedFiles: IFileReference[]; - importedFiles: IFileReference[]; - diagnostics: TypeScript.Diagnostic[]; - isLibFile: boolean - } - - interface ITripleSlashDirectiveProperties { - noDefaultLib: boolean; - diagnostics: TypeScript.Diagnostic[]; - referencedFiles: IFileReference[]; - } - -} // Tools \ No newline at end of file diff --git a/src/services/core/lineMap.ts b/src/services/core/lineMap.ts index 8820f55b920..e66198876a9 100644 --- a/src/services/core/lineMap.ts +++ b/src/services/core/lineMap.ts @@ -1,6 +1,11 @@ /// module TypeScript { + export interface ILineAndCharacter { + line: number; + character: number; + } + export class LineMap { public static empty = new LineMap(() => [0], 0); private _lineStarts: number[] = null; diff --git a/src/services/services.ts b/src/services/services.ts index b64a5207b85..a9a9ec7bf30 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -80,10 +80,20 @@ module ts { /// /// Pre-processing /// - interface ITripleSlashDirectiveProperties { - noDefaultLib: boolean; + // Note: This is being using by the host (VS) and is marshaled back and forth. When changing this make sure the changes + // are reflected in the managed side as well + // TODO (yuisu) : Consider merge with FileReference in types.ts + export interface IFileReference { + path: string; + position: number; + length: number; + } + + export interface PreProcessedFileInfo { + referencedFiles: IFileReference[]; + importedFiles: IFileReference[]; diagnostics: TypeScript.Diagnostic[]; - referencedFiles: TypeScript.IFileReference[]; + isLibFile: boolean } var scanner: Scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ true); @@ -1905,159 +1915,94 @@ module ts { } export var tripleSlashReferenceRegExp = /^(\/\/\/\s*/; - export function preProcessFile(fileName: string, sourceText: TypeScript.IScriptSnapshot, readImportFiles = true): TypeScript.IPreProcessedFileInfo { + export function preProcessFile(fileName: string, sourceText: TypeScript.IScriptSnapshot, readImportFiles = true): PreProcessedFileInfo { + var reportDiagnostic = () => { } + var text = sourceText.getText(0, sourceText.getLength()); + var referencedFiles: IFileReference[] = []; + var importedFiles: IFileReference[] = []; + function isNoDefaultLibMatch(comment: string): RegExpExecArray { var isNoDefaultLibRegex = /^(\/\/\/\s*/gim; return isNoDefaultLibRegex.exec(comment); } - function getFileReferenceFromReferencePath(fileName: string, text: TypeScript.ISimpleText, position: number, comment: string, diagnostics: TypeScript.Diagnostic[]): TypeScript.IFileReference { - // First, just see if they've written: /// = 7 && fullReference[6] === "true"; return { - line: 0, - character: 0, + // TODO (yuisu) : Move the function to util + path: TypeScript.switchToForwardSlashes(adjustedPath), position: 0, length: 0, - path: TypeScript.switchToForwardSlashes(adjustedPath), - isResident: isResident }; } } } - - return null; } - function processImports(text: TypeScript.ISimpleText, scanner: TypeScript.Scanner.IScanner, token: TypeScript.ISyntaxToken, importedFiles: TypeScript.IFileReference[]): void { - var lineChar = { line: -1, character: -1 }; + function processTripleSlashDirectives(): void { + var commentRanges = getLeadingCommentRanges(text, 0); + forEach(commentRanges, commentRange => { + var comment = text.substring(commentRange.pos, commentRange.end); + var referencedFile = getFileReferenceFromReferencePath(comment); + if (referencedFile) { + referencedFile.position = commentRange.pos; + referencedFile.length = commentRange.end - commentRange.pos; + referencedFiles.push(referencedFile); + } + }); + } - var lineMap = text.lineMap(); - var start = new Date().getTime(); + function processImport(): void { + var scanner = createScanner(getDefaultCompilerOptions().target, /*skipTrivia*/true, text); + + var token = scanner.scan(); // Look for: - // import foo = module("foo") - while (token.kind() !== TypeScript.SyntaxKind.EndOfFileToken) { - if (token.kind() === TypeScript.SyntaxKind.ImportKeyword) { - var importToken = token; - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (TypeScript.SyntaxFacts.isIdentifierNameOrAnyKeyword(token)) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (token.kind() === TypeScript.SyntaxKind.EqualsToken) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (token.kind() === TypeScript.SyntaxKind.ModuleKeyword || token.kind() === TypeScript.SyntaxKind.RequireKeyword) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - if (token.kind() === TypeScript.SyntaxKind.OpenParenToken) { - token = scanner.scan(/*allowRegularExpression:*/ false); - - lineMap.fillLineAndCharacterFromPosition(TypeScript.start(importToken, text), lineChar); - - if (token.kind() === TypeScript.SyntaxKind.StringLiteral) { - var ref = { - line: lineChar.line, - character: lineChar.character, - position: TypeScript.start(token, text), - length: TypeScript.width(token), - path: TypeScript.stripStartAndEndQuotes(TypeScript.switchToForwardSlashes(token.text())), - isResident: false + // import foo = module("foo"); + while (token !== SyntaxKind.EndOfFileToken) { + if (token === SyntaxKind.ImportKeyword) { + var startPosition = scanner.getTokenPos(); + token = scanner.scan(); + if (token === SyntaxKind.Identifier) { + token = scanner.scan(); + if (token === SyntaxKind.EqualsToken) { + token = scanner.scan(); + if (token === SyntaxKind.RequireKeyword) { + token = scanner.scan(); + if (token === SyntaxKind.OpenParenToken) { + token = scanner.scan(); + if (token === SyntaxKind.StringLiteral) { + var importPath = scanner.getTokenValue(); + var referencedFile = { + // TODO (yuisu) : Move the function to util + path: TypeScript.switchToForwardSlashes(importPath), + position: startPosition, + length: importPath.length }; - importedFiles.push(ref); + importedFiles.push(referencedFile); } } } } } } - - token = scanner.scan(/*allowRegularExpression:*/ false); + token = scanner.scan(); } - - var totalTime = new Date().getTime() - start; - //TypeScript.fileResolutionScanImportsTime += totalTime } - - function processTripleSlashDirectives(fileName: string, text: TypeScript.ISimpleText, firstToken: TypeScript.ISyntaxToken): ITripleSlashDirectiveProperties { - var leadingTrivia = firstToken.leadingTrivia(text); - - var position = 0; - var lineChar = { line: -1, character: -1 }; - var noDefaultLib = false; - var diagnostics: TypeScript.Diagnostic[] = []; - var referencedFiles: TypeScript.IFileReference[] = []; - var lineMap = text.lineMap(); - - for (var i = 0, n = leadingTrivia.count(); i < n; i++) { - var trivia = leadingTrivia.syntaxTriviaAt(i); - - if (trivia.kind() === TypeScript.SyntaxKind.SingleLineCommentTrivia) { - var triviaText = trivia.fullText(); - var referencedCode = getFileReferenceFromReferencePath(fileName, text, position, triviaText, diagnostics); - - if (referencedCode) { - lineMap.fillLineAndCharacterFromPosition(position, lineChar); - referencedCode.position = position; - referencedCode.length = trivia.fullWidth(); - referencedCode.line = lineChar.line; - referencedCode.character = lineChar.character; - - referencedFiles.push(referencedCode); - } - - // is it a lib file? - var isNoDefaultLib = isNoDefaultLibMatch(triviaText); - if (isNoDefaultLib) { - noDefaultLib = isNoDefaultLib[3] === "true"; - } - } - - position += trivia.fullWidth(); - } - - return { noDefaultLib: noDefaultLib, diagnostics: diagnostics, referencedFiles: referencedFiles }; - } - - var text = TypeScript.SimpleText.fromScriptSnapshot(sourceText); - var scanner = TypeScript.Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic); - - var firstToken = scanner.scan(/*allowRegularExpression:*/ false); - - // only search out dynamic mods - // if you find a dynamic mod, ignore every other mod inside, until you balance rcurlies - // var position - - var importedFiles: TypeScript.IFileReference[] = []; - if (readImportFiles) { - processImports(text, scanner, firstToken, importedFiles); - } - - var properties = processTripleSlashDirectives(fileName, text, firstToken); - - return { referencedFiles: properties.referencedFiles, importedFiles: importedFiles, isLibFile: properties.noDefaultLib, diagnostics: properties.diagnostics }; + processImport(); + processTripleSlashDirectives(); + return { referencedFiles: referencedFiles, importedFiles: importedFiles, isLibFile: false, diagnostics: [] }; } /// Helpers diff --git a/src/services/shims.ts b/src/services/shims.ts index 4a31dc62331..1f4af295788 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -16,7 +16,6 @@ /// /// -/// var debugObjectHost = (this); @@ -847,7 +846,7 @@ module ts { return this.forwardJSONCall( "getPreProcessedFileInfo('" + fileName + "')", () => { - var result = ts.preProcessFile(fileName, sourceText); //TypeScript.preProcessFile(fileName, sourceText); + var result = preProcessFile(fileName, sourceText); //TypeScript.preProcessFile(fileName, sourceText); return result; }); } From 32056cd15f901e1f50f0ee515f140d25e34b7040 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 22 Oct 2014 18:51:33 -0700 Subject: [PATCH 03/18] Move switchToForwardSlashes from pathUtils to utilities --- src/services/services.ts | 64 +++++++++++++++++++-------------------- src/services/utilities.ts | 5 +++ 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index a9a9ec7bf30..0ee5ba1fce4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1560,7 +1560,7 @@ module ts { var filenames = host.getScriptFileNames(); for (var i = 0, n = filenames.length; i < n; i++) { var filename = filenames[i]; - this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)] = { + this.filenameToEntry[switchToForwardSlashes(filename)] = { filename: filename, version: host.getScriptVersion(filename), isOpen: host.getScriptIsOpen(filename) @@ -1575,7 +1575,7 @@ module ts { } public getEntry(filename: string): HostFileInformation { - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); return lookUp(this.filenameToEntry, filename); } @@ -1935,14 +1935,13 @@ module ts { if (!isNoDefaultLib) { var fullReferenceRegEx = tripleSlashReferenceRegExp; var fullReference = fullReferenceRegEx.exec(comment); - var path: string = TypeScript.normalizePath(fullReference[3]); + var path: string = normalizePath(fullReference[3]); if (fullReference) { - var path: string = TypeScript.normalizePath(fullReference[3]); - var adjustedPath = TypeScript.normalizePath(path); + var path: string = normalizePath(fullReference[3]); + var adjustedPath = normalizePath(path); return { - // TODO (yuisu) : Move the function to util - path: TypeScript.switchToForwardSlashes(adjustedPath), + path: switchToForwardSlashes(adjustedPath), position: 0, length: 0, }; @@ -1985,8 +1984,7 @@ module ts { if (token === SyntaxKind.StringLiteral) { var importPath = scanner.getTokenValue(); var referencedFile = { - // TODO (yuisu) : Move the function to util - path: TypeScript.switchToForwardSlashes(importPath), + path: switchToForwardSlashes(importPath), position: startPosition, length: importPath.length }; @@ -2320,7 +2318,7 @@ module ts { function getSyntacticDiagnostics(filename: string) { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); return program.getDiagnostics(getSourceFile(filename).getSourceFile()); } @@ -2332,7 +2330,7 @@ module ts { function getSemanticDiagnostics(filename: string) { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename) + filename = switchToForwardSlashes(filename) var compilerOptions = program.getCompilerOptions(); var checker = getFullTypeCheckChecker(); var targetSourceFile = getSourceFile(filename); @@ -2580,7 +2578,7 @@ module ts { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); var sourceUnit = sourceFile.getSourceUnit(); @@ -2739,7 +2737,7 @@ module ts { function getCompletionEntryDetails(filename: string, position: number, entryName: string): CompletionEntryDetails { // Note: No need to call synchronizeHostData, as we have captured all the data we need // in the getCompletionsAtPosition earlier - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var session = activeCompletionSession; @@ -3195,7 +3193,7 @@ module ts { function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo { synchronizeHostData(); - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); var node = getTouchingPropertyName(sourceFile, position); if (!node) { @@ -3297,7 +3295,7 @@ module ts { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); var node = getTouchingPropertyName(sourceFile, position); @@ -3361,7 +3359,7 @@ module ts { function getOccurrencesAtPosition(filename: string, position: number): ReferenceEntry[] { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); var node = getTouchingWord(sourceFile, position); @@ -3814,7 +3812,7 @@ module ts { function findReferences(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { synchronizeHostData(); - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); var node = getTouchingPropertyName(sourceFile, position); @@ -4533,7 +4531,7 @@ module ts { function getEmitOutput(filename: string): EmitOutput { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var compilerOptions = program.getCompilerOptions(); var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output // If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false. @@ -4708,7 +4706,7 @@ module ts { function getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems { synchronizeHostData(); - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); return SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); @@ -4778,12 +4776,12 @@ module ts { /// Syntactic features function getSyntaxTree(filename: string): TypeScript.SyntaxTree { - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); return syntaxTreeCache.getCurrentFileSyntaxTree(filename); } function getCurrentSourceFile(filename: string): SourceFile { - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var currentSourceFile = syntaxTreeCache.getCurrentSourceFile(filename); return currentSourceFile; } @@ -4824,7 +4822,7 @@ module ts { } } - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var node = getTypeInfoEligiblePath(filename, startPos, false); if (!node) return null; @@ -4846,21 +4844,21 @@ module ts { function getBreakpointStatementAtPosition(filename: string, position: number) { // doesn't use compiler - no need to synchronize with host - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var syntaxtree = getSyntaxTree(filename); return TypeScript.Services.Breakpoints.getBreakpointLocation(syntaxtree, position); } function getNavigationBarItems(filename: string): NavigationBarItem[] { - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); return NavigationBar.getNavigationBarItems(getCurrentSourceFile(filename)); } function getSemanticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] { synchronizeHostData(); - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); @@ -4931,7 +4929,7 @@ module ts { function getSyntacticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] { // doesn't use compiler - no need to synchronize with host - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var sourceFile = getCurrentSourceFile(fileName); var result: ClassifiedSpan[] = []; @@ -5074,7 +5072,7 @@ module ts { function getOutliningSpans(filename: string): OutliningSpan[] { // doesn't use compiler - no need to synchronize with host - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var sourceFile = getCurrentSourceFile(filename); return OutliningElementsCollector.collectElements(sourceFile); } @@ -5133,7 +5131,7 @@ module ts { } function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) { - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var sourceFile = getCurrentSourceFile(filename); var options = new TypeScript.FormattingOptions(!editorOptions.ConvertTabsToSpaces, editorOptions.TabSize, editorOptions.IndentSize, editorOptions.NewLineCharacter) @@ -5163,21 +5161,21 @@ module ts { } function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] { - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var manager = getFormattingManager(fileName, options); return manager.formatSelection(start, end); } function getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[] { - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var manager = getFormattingManager(fileName, options); return manager.formatDocument(); } function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[] { - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var manager = getFormattingManager(fileName, options); @@ -5195,7 +5193,7 @@ module ts { } function getTodoComments(filename: string, descriptors: TodoCommentDescriptor[]): TodoComment[] { - filename = TypeScript.switchToForwardSlashes(filename); + filename = switchToForwardSlashes(filename); var sourceFile = getCurrentSourceFile(filename); @@ -5364,7 +5362,7 @@ module ts { function getRenameInfo(fileName: string, position: number): RenameInfo { synchronizeHostData(); - fileName = TypeScript.switchToForwardSlashes(fileName); + fileName = switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); var node = getTouchingWord(sourceFile, position); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 4ceb20fdcee..a3c2a23dd15 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -244,4 +244,9 @@ module ts { function isPropertyName(n: Node): boolean { return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n); } + + export var switchToForwardSlashesRegEx = /\\/g; + export function switchToForwardSlashes(path: string) { + return path.replace(switchToForwardSlashesRegEx, "/"); + } } \ No newline at end of file From 6b5f50afb7e3454e85a4781440c470f1064feec1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 22 Oct 2014 19:06:57 -0700 Subject: [PATCH 04/18] Add comment --- src/services/services.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/services.ts b/src/services/services.ts index 0ee5ba1fce4..4451a07508d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1927,6 +1927,7 @@ module ts { return isNoDefaultLibRegex.exec(comment); } + // TODO : merge this function with processReferenceComments in parser as both do similar functionality function getFileReferenceFromReferencePath(comment: string): IFileReference { var simpleReferenceRegEx = /^\/\/\/\s* Date: Fri, 24 Oct 2014 16:03:40 -0700 Subject: [PATCH 05/18] Refactoring getFileReferenceFromReferencePath for both parser and language service --- src/compiler/parser.ts | 80 +++++++++++++++++++++++++++++----------- src/services/services.ts | 65 +++++++++++--------------------- src/services/shims.ts | 4 +- 3 files changed, 82 insertions(+), 67 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c755205ee3a..6f9d72573e9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -20,7 +20,7 @@ module ts { interface ReferenceComments { referencedFiles: FileReference[]; amdDependencies: string[]; - } +} export function getSourceFileOfNode(node: Node): SourceFile { while (node && node.kind !== SyntaxKind.SourceFile) node = node.parent; @@ -641,6 +641,54 @@ module ts { nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext; } + + + interface ReferencePathMatchResult { + fileReference: FileReference + diagnostic: DiagnosticMessage + isNoDefaultLib: boolean + } + + // TODO (yuisu) : add referencedFiles array for filling in + export function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult { + var simpleReferenceRegEx = /^\/\/\/\s*/gim; + if (simpleReferenceRegEx.exec(comment)) { + if (isNoDefaultLibRegEx.exec(comment)) { + return { + fileReference: undefined, + diagnostic: undefined, + isNoDefaultLib: true + } + } + else { + var matchResult = fullTripleSlashReferencePathRegEx.exec(comment); + if (matchResult) { + var start = commentRange.pos; + var end = commentRange.end; + var fileRef = { + pos: start, + end: end, + filename: matchResult[3] + }; + return { + fileReference: fileRef, + diagnostic: undefined, + isNoDefaultLib: false + }; + } + else { + return { + fileReference: undefined, + diagnostic: Diagnostics.Invalid_reference_directive_syntax, + isNoDefaultLib: false + }; + } + } + } + return undefined; + } + export function isKeyword(token: SyntaxKind): boolean { return SyntaxKind.FirstKeyword <= token && token <= SyntaxKind.LastKeyword; } @@ -3896,28 +3944,16 @@ module ts { for (var i = 0; i < commentRanges.length; i++) { var range = commentRanges[i]; var comment = sourceText.substring(range.pos, range.end); - var simpleReferenceRegEx = /^\/\/\/\s*/gim; - if (isNoDefaultLibRegEx.exec(comment)) { - file.hasNoDefaultLib = true; + var referencePathMatchResult = getFileReferenceFromReferencePath(comment, range); + if (referencePathMatchResult) { + var fileReference = referencePathMatchResult.fileReference; + file.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib; + var diagnostic = referencePathMatchResult.diagnostic; + if (fileReference) { + referencedFiles.push(fileReference); } - else { - var matchResult = fullTripleSlashReferencePathRegEx.exec(comment); - var start = range.pos; - var end = range.end; - var length = end - start; - - if (!matchResult) { - errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax); - } - else { - referencedFiles.push({ - pos: start, - end: end, - filename: matchResult[3] - }); - } + if (diagnostic) { + errorAtPos(range.pos, range.end - range.pos, diagnostic); } } else { diff --git a/src/services/services.ts b/src/services/services.ts index 4451a07508d..1ef7ab605a1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1915,57 +1915,32 @@ module ts { } export var tripleSlashReferenceRegExp = /^(\/\/\/\s*/; - export function preProcessFile(fileName: string, sourceText: TypeScript.IScriptSnapshot, readImportFiles = true): PreProcessedFileInfo { - - var reportDiagnostic = () => { } - var text = sourceText.getText(0, sourceText.getLength()); + export function preProcessFile(sourceText: string, readImportFiles = true): PreProcessedFileInfo { var referencedFiles: IFileReference[] = []; var importedFiles: IFileReference[] = []; - - function isNoDefaultLibMatch(comment: string): RegExpExecArray { - var isNoDefaultLibRegex = /^(\/\/\/\s*/gim; - return isNoDefaultLibRegex.exec(comment); - } - - // TODO : merge this function with processReferenceComments in parser as both do similar functionality - function getFileReferenceFromReferencePath(comment: string): IFileReference { - var simpleReferenceRegEx = /^\/\/\/\s* { - var comment = text.substring(commentRange.pos, commentRange.end); - var referencedFile = getFileReferenceFromReferencePath(comment); - if (referencedFile) { - referencedFile.position = commentRange.pos; - referencedFile.length = commentRange.end - commentRange.pos; - referencedFiles.push(referencedFile); + var comment = sourceText.substring(commentRange.pos, commentRange.end); + var referencePathMatchResult = getFileReferenceFromReferencePath(comment, commentRange); + if (referencePathMatchResult) { + isNoDefaultLib = referencePathMatchResult.isNoDefaultLib; + var fileReference = referencePathMatchResult.fileReference; + if (fileReference) { + referencedFiles.push({ + path: switchToForwardSlashes(normalizePath(fileReference.filename)), + position: fileReference.pos, + length: fileReference.end - fileReference.pos, + }); + } } }); } function processImport(): void { - var scanner = createScanner(getDefaultCompilerOptions().target, /*skipTrivia*/true, text); + var scanner = createScanner(getDefaultCompilerOptions().target, /*skipTrivia*/true, sourceText); var token = scanner.scan(); // Look for: @@ -1999,9 +1974,13 @@ module ts { token = scanner.scan(); } } - processImport(); + + if (readImportFiles) { + processImport(); + } processTripleSlashDirectives(); - return { referencedFiles: referencedFiles, importedFiles: importedFiles, isLibFile: false, diagnostics: [] }; + // TODO (yuisu) : remove diagnostics array + return { referencedFiles: referencedFiles, importedFiles: importedFiles, isLibFile: isNoDefaultLib, diagnostics: [] }; } /// Helpers diff --git a/src/services/shims.ts b/src/services/shims.ts index 1f4af295788..ce5d4c7f823 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -842,11 +842,11 @@ module ts { return forwardJSONCall(this.logger, actionDescription, action); } - public getPreProcessedFileInfo(fileName: string, sourceText: TypeScript.IScriptSnapshot): string { + public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: TypeScript.IScriptSnapshot): string { return this.forwardJSONCall( "getPreProcessedFileInfo('" + fileName + "')", () => { - var result = preProcessFile(fileName, sourceText); //TypeScript.preProcessFile(fileName, sourceText); + var result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength())); return result; }); } From 95f6cbe760d8835fcba0d1b1273eff082413ed94 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 24 Oct 2014 16:03:59 -0700 Subject: [PATCH 06/18] Add unittests for preProcessFile --- Jakefile | 3 +- .../unittests/services/preProcessFile.ts | 101 ++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/cases/unittests/services/preProcessFile.ts diff --git a/Jakefile b/Jakefile index 34879a56691..821f755650c 100644 --- a/Jakefile +++ b/Jakefile @@ -82,7 +82,8 @@ var harnessSources = [ return path.join(harnessDirectory, f); }).concat([ "services/colorization.ts", - "services/documentRegistry.ts" + "services/documentRegistry.ts", + "services/preProcessFile.ts" ].map(function (f) { return path.join(unittestsDirectory, f); })); diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts new file mode 100644 index 00000000000..6a55b53c2d5 --- /dev/null +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -0,0 +1,101 @@ +/// +/// + +describe('preProcessFile', function () { + function test(sourceText: string, readImportFile: boolean, expectedPreProcess: ts.PreProcessedFileInfo): void { + debugger + var resultPreProcess = ts.preProcessFile(sourceText, readImportFile); + + var resultIsLibFile = resultPreProcess.isLibFile; + var resultImportedFiles = resultPreProcess.importedFiles; + var resultReferencedFiles = resultPreProcess.referencedFiles; + + var expectedIsLibFile = expectedPreProcess.isLibFile; + var expectedImportedFiles = expectedPreProcess.importedFiles; + var expectedReferencedFiles = expectedPreProcess.referencedFiles; + + assert.equal(resultIsLibFile, expectedIsLibFile, "Pre-processed file has different value for isLibFile. Expected: " + expectedPreProcess + ". Actual: " + resultIsLibFile); + + assert.equal(resultImportedFiles.length, expectedImportedFiles.length, + "Array's length of imported files does not match expected. Expected: " + expectedImportedFiles.length + ". Actual: " + resultImportedFiles.length); + + assert.equal(resultReferencedFiles.length, expectedReferencedFiles.length, + "Array's length of referenced files does not match expected. Expected: " + expectedReferencedFiles.length + ". Actual: " + resultReferencedFiles.length); + + for (var i = 0; i < expectedImportedFiles.length; ++i) { + var resultImportedFile = resultImportedFiles[i]; + var expectedImportedFile = expectedImportedFiles[i]; + + assert.equal(resultImportedFile.path, expectedImportedFile.path, "Imported file path does not match expected. Expected: " + expectedImportedFile.path + ". Actual: " + resultImportedFile.path + "."); + + assert.equal(resultImportedFile.position, expectedImportedFile.position, "Imported file position does not match expected. Expected: " + expectedImportedFile.position + ". Actual: " + resultImportedFile.position + "."); + + assert.equal(resultImportedFile.length, expectedImportedFile.length, "Imported file length does not match expected. Expected: " + expectedImportedFile.length + ". Actual: " + resultImportedFile.length + "."); + } + + for (var i = 0; i < expectedReferencedFiles.length; ++i) { + var resultReferencedFile = resultReferencedFiles[i]; + var expectedReferencedFile = expectedReferencedFiles[i]; + + assert.equal(resultReferencedFile.path, expectedReferencedFile.path, "Referenced file path does not match expected. Expected: " + expectedReferencedFile.path + ". Actual: " + resultReferencedFile.path + "."); + + assert.equal(resultReferencedFile.position, expectedReferencedFile.position, "Referenced file position does not match expected. Expected: " + expectedReferencedFile.position + ". Actual: " + resultReferencedFile.position + "."); + + assert.equal(resultReferencedFile.length, expectedReferencedFile.length, "Referenced file length does not match expected. Expected: " + expectedReferencedFile.length + ". Actual: " + resultReferencedFile.length + "."); + } + } + describe("test preProcessFiles", function () { + it("Correctly return referenced files from triple slash", function () { + test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, + { + referencedFiles: [{ path: "refFile1.ts", position: 0, length: 37 }, { path: "refFile2.ts", position: 38, length: 35 }, + { path: "refFile3.ts", position: 74, length: 35 }, { path: "refFile4d.ts", position: 110, length: 37 }], + importedFiles: [], + diagnostics: [], + isLibFile: false + }); + }), + + it("Invalid referenced files from triple slash", function () { + test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, + { + referencedFiles: [], + importedFiles: [], + diagnostics: [], + isLibFile: false + }); + }); + + it("Correctly return imported files", function () { + test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");", true, + { + referencedFiles: [], + importedFiles: [{ path: "r1.ts", position: 0, length: 5 }, { path: "r2.ts", position: 30, length: 5 }, { path: "r3.ts", position: 59, length: 5 }, + { path: "r4.ts", position: 88, length: 5 }, { path: "r5.ts", position: 116, length: 5 }], + diagnostics: [], + isLibFile: false + }); + }); + + it("Do not return imported files if readImportFiles argument is false", function () { + test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");", false, + { + referencedFiles: [], + importedFiles: [], + diagnostics: [], + isLibFile: false + }); + }); + + it("Correctly return referenced files and import files", function () { + test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\");", true, + { + referencedFiles: [{ path: "refFile1.ts", position: 0, length: 35 }, { path: "refFile2.ts", position: 36, length: 35 }], + importedFiles: [{ path: "r1.ts", position: 72, length: 5 }, { path: "r2.ts", position: 102, length: 5 }], + diagnostics: [], + isLibFile: false + }); + }); + }); +}); + From da108587031146ef5c68e8a268db7d08277b962d Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 24 Oct 2014 16:05:33 -0700 Subject: [PATCH 07/18] Fix indentation --- src/compiler/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6f9d72573e9..6ccae9fa86a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -20,7 +20,7 @@ module ts { interface ReferenceComments { referencedFiles: FileReference[]; amdDependencies: string[]; -} + } export function getSourceFileOfNode(node: Node): SourceFile { while (node && node.kind !== SyntaxKind.SourceFile) node = node.parent; From b37ddf388f45512f7e1d980f223288b57c4efe4b Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 24 Oct 2014 16:05:33 -0700 Subject: [PATCH 08/18] Fix indentation and space --- src/compiler/parser.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6f9d72573e9..912c3c1d265 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -20,7 +20,7 @@ module ts { interface ReferenceComments { referencedFiles: FileReference[]; amdDependencies: string[]; -} + } export function getSourceFileOfNode(node: Node): SourceFile { while (node && node.kind !== SyntaxKind.SourceFile) node = node.parent; @@ -641,8 +641,6 @@ module ts { nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext; } - - interface ReferencePathMatchResult { fileReference: FileReference diagnostic: DiagnosticMessage From 7f8b24c6cc8128b28a132a4c750d55e46023c4b9 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 27 Oct 2014 10:09:57 -0700 Subject: [PATCH 09/18] Fix getTokenPos for scanning import statement --- src/services/services.ts | 8 ++++---- tests/cases/unittests/services/preProcessFile.ts | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1ef7ab605a1..0fccd268469 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -80,8 +80,8 @@ module ts { /// /// Pre-processing /// - // Note: This is being using by the host (VS) and is marshaled back and forth. When changing this make sure the changes - // are reflected in the managed side as well + // Note: This is being using by the host (VS) and is marshaled back and forth. + // When changing this make sure the changes are reflected in the managed side as well // TODO (yuisu) : Consider merge with FileReference in types.ts export interface IFileReference { path: string; @@ -1947,7 +1947,6 @@ module ts { // import foo = module("foo"); while (token !== SyntaxKind.EndOfFileToken) { if (token === SyntaxKind.ImportKeyword) { - var startPosition = scanner.getTokenPos(); token = scanner.scan(); if (token === SyntaxKind.Identifier) { token = scanner.scan(); @@ -1959,9 +1958,10 @@ module ts { token = scanner.scan(); if (token === SyntaxKind.StringLiteral) { var importPath = scanner.getTokenValue(); + var pos = scanner.getTokenPos(); var referencedFile = { path: switchToForwardSlashes(importPath), - position: startPosition, + position: pos, length: importPath.length }; importedFiles.push(referencedFile); diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts index 6a55b53c2d5..29811f8270a 100644 --- a/tests/cases/unittests/services/preProcessFile.ts +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -1,7 +1,7 @@ /// /// -describe('preProcessFile', function () { +describe('PreProcessFile:', function () { function test(sourceText: string, readImportFile: boolean, expectedPreProcess: ts.PreProcessedFileInfo): void { debugger var resultPreProcess = ts.preProcessFile(sourceText, readImportFile); @@ -44,7 +44,7 @@ describe('preProcessFile', function () { assert.equal(resultReferencedFile.length, expectedReferencedFile.length, "Referenced file length does not match expected. Expected: " + expectedReferencedFile.length + ". Actual: " + resultReferencedFile.length + "."); } } - describe("test preProcessFiles", function () { + describe("Test preProcessFiles,", function () { it("Correctly return referenced files from triple slash", function () { test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, { @@ -70,8 +70,8 @@ describe('preProcessFile', function () { test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");", true, { referencedFiles: [], - importedFiles: [{ path: "r1.ts", position: 0, length: 5 }, { path: "r2.ts", position: 30, length: 5 }, { path: "r3.ts", position: 59, length: 5 }, - { path: "r4.ts", position: 88, length: 5 }, { path: "r5.ts", position: 116, length: 5 }], + importedFiles: [{ path: "r1.ts", position: 20, length: 5 }, { path: "r2.ts", position: 49, length: 5 }, { path: "r3.ts", position: 78, length: 5 }, + { path: "r4.ts", position: 106, length: 5 }, { path: "r5.ts", position: 138, length: 5 }], diagnostics: [], isLibFile: false }); @@ -91,7 +91,7 @@ describe('preProcessFile', function () { test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\");", true, { referencedFiles: [{ path: "refFile1.ts", position: 0, length: 35 }, { path: "refFile2.ts", position: 36, length: 35 }], - importedFiles: [{ path: "r1.ts", position: 72, length: 5 }, { path: "r2.ts", position: 102, length: 5 }], + importedFiles: [{ path: "r1.ts", position: 92, length: 5 }, { path: "r2.ts", position: 121, length: 5 }], diagnostics: [], isLibFile: false }); From 300c059d1f0526039e6cce33e7ca7f5da4e49e5f Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 27 Oct 2014 17:03:06 -0700 Subject: [PATCH 10/18] Remove diagnostic from pre-processing of files --- src/services/services.ts | 3 +-- tests/cases/unittests/services/preProcessFile.ts | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 0fccd268469..230fe4bebcb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -92,7 +92,6 @@ module ts { export interface PreProcessedFileInfo { referencedFiles: IFileReference[]; importedFiles: IFileReference[]; - diagnostics: TypeScript.Diagnostic[]; isLibFile: boolean } @@ -1980,7 +1979,7 @@ module ts { } processTripleSlashDirectives(); // TODO (yuisu) : remove diagnostics array - return { referencedFiles: referencedFiles, importedFiles: importedFiles, isLibFile: isNoDefaultLib, diagnostics: [] }; + return { referencedFiles: referencedFiles, importedFiles: importedFiles, isLibFile: isNoDefaultLib }; } /// Helpers diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts index 29811f8270a..8fbab29b7b9 100644 --- a/tests/cases/unittests/services/preProcessFile.ts +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -51,7 +51,6 @@ describe('PreProcessFile:', function () { referencedFiles: [{ path: "refFile1.ts", position: 0, length: 37 }, { path: "refFile2.ts", position: 38, length: 35 }, { path: "refFile3.ts", position: 74, length: 35 }, { path: "refFile4d.ts", position: 110, length: 37 }], importedFiles: [], - diagnostics: [], isLibFile: false }); }), @@ -61,7 +60,6 @@ describe('PreProcessFile:', function () { { referencedFiles: [], importedFiles: [], - diagnostics: [], isLibFile: false }); }); @@ -72,7 +70,6 @@ describe('PreProcessFile:', function () { referencedFiles: [], importedFiles: [{ path: "r1.ts", position: 20, length: 5 }, { path: "r2.ts", position: 49, length: 5 }, { path: "r3.ts", position: 78, length: 5 }, { path: "r4.ts", position: 106, length: 5 }, { path: "r5.ts", position: 138, length: 5 }], - diagnostics: [], isLibFile: false }); }); @@ -82,7 +79,6 @@ describe('PreProcessFile:', function () { { referencedFiles: [], importedFiles: [], - diagnostics: [], isLibFile: false }); }); @@ -92,7 +88,6 @@ describe('PreProcessFile:', function () { { referencedFiles: [{ path: "refFile1.ts", position: 0, length: 35 }, { path: "refFile2.ts", position: 36, length: 35 }], importedFiles: [{ path: "r1.ts", position: 92, length: 5 }, { path: "r2.ts", position: 121, length: 5 }], - diagnostics: [], isLibFile: false }); }); From acbc28d3e11ccd67d352c10a912f706b426c8419 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 27 Oct 2014 17:09:59 -0700 Subject: [PATCH 11/18] Add tests case for invalid syntax in import statement and triple slash reference --- .../unittests/services/preProcessFile.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts index 8fbab29b7b9..3417340f77e 100644 --- a/tests/cases/unittests/services/preProcessFile.ts +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -55,7 +55,7 @@ describe('PreProcessFile:', function () { }); }), - it("Invalid referenced files from triple slash", function () { + it("Do not return reference path because of invalid triple-slash syntax", function () { test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, { referencedFiles: [], @@ -83,6 +83,15 @@ describe('PreProcessFile:', function () { }); }); + it("Do not return import path because of invalid import syntax", function () { + test("import i1 require(\"r1.ts\"); import = require(\"r2.ts\") import i3= require(\"r3.ts\"); import i5", true, + { + referencedFiles: [], + importedFiles: [{ path: "r3.ts", position: 73, length: 5 }], + isLibFile: false + }); + }); + it("Correctly return referenced files and import files", function () { test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\");", true, { @@ -91,6 +100,15 @@ describe('PreProcessFile:', function () { isLibFile: false }); }); + + it("Correctly return referenced files and import files even with some invalid syntax", function () { + test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import = require(\"r2.ts\"); import i2 = require(\"r3.ts\");", true, + { + referencedFiles: [{ path: "refFile1.ts", position: 0, length: 35 }], + importedFiles: [{ path: "r1.ts", position: 91, length: 5 }, { path: "r3.ts", position: 148, length: 5 }], + isLibFile: false + }); + }); }); }); From 4f6ccab5e93be80251c11684431e0f57bf210162 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 28 Oct 2014 14:45:32 -0700 Subject: [PATCH 12/18] Move Convert FileReference to the shim --- src/harness/harnessLanguageService.ts | 4 ++ src/services/services.ts | 36 ++++------- src/services/shims.ts | 34 +++++++++- .../unittests/services/preProcessFile.ts | 64 +++++++++---------- 4 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 647d0729cbb..cf99bdce79c 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -258,6 +258,10 @@ module Harness.LanguageService { 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: TypeScript.IScriptSnapshot): TypeScript.SourceUnitSyntax { return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.ES5, TypeScript.isDTSFile(fileName)).sourceUnit(); diff --git a/src/services/services.ts b/src/services/services.ts index 230fe4bebcb..8293cb9c523 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -77,21 +77,9 @@ module ts { update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile; } - /// - /// Pre-processing - /// - // Note: This is being using by the host (VS) and is marshaled back and forth. - // When changing this make sure the changes are reflected in the managed side as well - // TODO (yuisu) : Consider merge with FileReference in types.ts - export interface IFileReference { - path: string; - position: number; - length: number; - } - export interface PreProcessedFileInfo { - referencedFiles: IFileReference[]; - importedFiles: IFileReference[]; + referencedFiles: FileReference[]; + importedFiles: FileReference[]; isLibFile: boolean } @@ -1915,8 +1903,8 @@ module ts { export var tripleSlashReferenceRegExp = /^(\/\/\/\s*/; export function preProcessFile(sourceText: string, readImportFiles = true): PreProcessedFileInfo { - var referencedFiles: IFileReference[] = []; - var importedFiles: IFileReference[] = []; + var referencedFiles: FileReference[] = []; + var importedFiles: FileReference[] = []; var isNoDefaultLib = false; function processTripleSlashDirectives(): void { @@ -1928,11 +1916,12 @@ module ts { isNoDefaultLib = referencePathMatchResult.isNoDefaultLib; var fileReference = referencePathMatchResult.fileReference; if (fileReference) { - referencedFiles.push({ + referencedFiles.push(fileReference); + /* referencedFiles.push({ path: switchToForwardSlashes(normalizePath(fileReference.filename)), position: fileReference.pos, length: fileReference.end - fileReference.pos, - }); + }); */ } } }); @@ -1958,12 +1947,11 @@ module ts { if (token === SyntaxKind.StringLiteral) { var importPath = scanner.getTokenValue(); var pos = scanner.getTokenPos(); - var referencedFile = { - path: switchToForwardSlashes(importPath), - position: pos, - length: importPath.length - }; - importedFiles.push(referencedFile); + importedFiles.push({ + filename: importPath, + pos: pos, + end: pos + importPath.length + }); } } } diff --git a/src/services/shims.ts b/src/services/shims.ts index ce5d4c7f823..c53575812c4 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -54,6 +54,17 @@ module ts { getDefaultLibFilename(): string; } + /// + /// Pre-processing + /// + // Note: This is being using by the host (VS) and is marshaled back and forth. + // When changing this make sure the changes are reflected in the managed side as well + interface IFileReference { + path: string; + position: number; + length: number; + } + /** Public interface of a language service instance shim. */ export interface ShimFactory { registerShim(shim: Shim): void; @@ -847,7 +858,28 @@ module ts { "getPreProcessedFileInfo('" + fileName + "')", () => { var result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength())); - return result; + var convertResult = { + referencedFiles: [], + importedFiles: [], + isLibFile: result.isLibFile + }; + + forEach(result.referencedFiles, refFile => { + convertResult.referencedFiles.push({ + path: switchToForwardSlashes(normalizePath(refFile.filename)), + position: refFile.pos, + length: refFile.end - refFile.pos + }); + }); + + forEach(result.importedFiles, importedFile => { + convertResult.importedFiles.push({ + path: switchToForwardSlashes(importedFile.filename), + position: importedFile.pos, + length: importedFile.end - importedFile.pos + }); + }); + return convertResult; }); } diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts index 3417340f77e..0a5fac5e24b 100644 --- a/tests/cases/unittests/services/preProcessFile.ts +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -26,88 +26,88 @@ describe('PreProcessFile:', function () { var resultImportedFile = resultImportedFiles[i]; var expectedImportedFile = expectedImportedFiles[i]; - assert.equal(resultImportedFile.path, expectedImportedFile.path, "Imported file path does not match expected. Expected: " + expectedImportedFile.path + ". Actual: " + resultImportedFile.path + "."); + assert.equal(resultImportedFile.filename, expectedImportedFile.filename, "Imported file path does not match expected. Expected: " + expectedImportedFile.filename + ". Actual: " + resultImportedFile.filename + "."); - assert.equal(resultImportedFile.position, expectedImportedFile.position, "Imported file position does not match expected. Expected: " + expectedImportedFile.position + ". Actual: " + resultImportedFile.position + "."); + assert.equal(resultImportedFile.pos, expectedImportedFile.pos, "Imported file position does not match expected. Expected: " + expectedImportedFile.pos + ". Actual: " + resultImportedFile.pos + "."); - assert.equal(resultImportedFile.length, expectedImportedFile.length, "Imported file length does not match expected. Expected: " + expectedImportedFile.length + ". Actual: " + resultImportedFile.length + "."); + assert.equal(resultImportedFile.end, expectedImportedFile.end, "Imported file length does not match expected. Expected: " + expectedImportedFile.end + ". Actual: " + resultImportedFile.end + "."); } for (var i = 0; i < expectedReferencedFiles.length; ++i) { var resultReferencedFile = resultReferencedFiles[i]; var expectedReferencedFile = expectedReferencedFiles[i]; - assert.equal(resultReferencedFile.path, expectedReferencedFile.path, "Referenced file path does not match expected. Expected: " + expectedReferencedFile.path + ". Actual: " + resultReferencedFile.path + "."); + assert.equal(resultReferencedFile.filename, expectedReferencedFile.filename, "Referenced file path does not match expected. Expected: " + expectedReferencedFile.filename + ". Actual: " + resultReferencedFile.filename + "."); - assert.equal(resultReferencedFile.position, expectedReferencedFile.position, "Referenced file position does not match expected. Expected: " + expectedReferencedFile.position + ". Actual: " + resultReferencedFile.position + "."); + assert.equal(resultReferencedFile.pos, expectedReferencedFile.pos, "Referenced file position does not match expected. Expected: " + expectedReferencedFile.pos + ". Actual: " + resultReferencedFile.pos + "."); - assert.equal(resultReferencedFile.length, expectedReferencedFile.length, "Referenced file length does not match expected. Expected: " + expectedReferencedFile.length + ". Actual: " + resultReferencedFile.length + "."); + assert.equal(resultReferencedFile.end, expectedReferencedFile.end, "Referenced file length does not match expected. Expected: " + expectedReferencedFile.end + ". Actual: " + resultReferencedFile.end + "."); } } describe("Test preProcessFiles,", function () { it("Correctly return referenced files from triple slash", function () { - test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, + test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, { - referencedFiles: [{ path: "refFile1.ts", position: 0, length: 37 }, { path: "refFile2.ts", position: 38, length: 35 }, - { path: "refFile3.ts", position: 74, length: 35 }, { path: "refFile4d.ts", position: 110, length: 37 }], - importedFiles: [], + referencedFiles: [{ filename: "refFile1.ts", pos: 0, end: 37 }, { filename: "refFile2.ts", pos: 38, end: 73 }, + { filename: "refFile3.ts", pos: 74, end: 109 }, { filename: "..\\refFile4d.ts", pos: 110, end: 150 }], + importedFiles: [], isLibFile: false }); - }), + }), - it("Do not return reference path because of invalid triple-slash syntax", function () { - test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, + it("Do not return reference path because of invalid triple-slash syntax", function () { + test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", true, { - referencedFiles: [], - importedFiles: [], + referencedFiles: [], + importedFiles: [], isLibFile: false }); - }); + }), it("Correctly return imported files", function () { test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");", true, { - referencedFiles: [], - importedFiles: [{ path: "r1.ts", position: 20, length: 5 }, { path: "r2.ts", position: 49, length: 5 }, { path: "r3.ts", position: 78, length: 5 }, - { path: "r4.ts", position: 106, length: 5 }, { path: "r5.ts", position: 138, length: 5 }], + referencedFiles: [], + importedFiles: [{ filename: "r1.ts", pos: 20, end: 25 }, { filename: "r2.ts", pos: 49, end: 54 }, { filename: "r3.ts", pos: 78, end: 83 }, + { filename: "r4.ts", pos: 106, end: 111 }, { filename: "r5.ts", pos: 138, end: 143 }], isLibFile: false }); - }); + }), it("Do not return imported files if readImportFiles argument is false", function () { test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");", false, { - referencedFiles: [], - importedFiles: [], + referencedFiles: [], + importedFiles: [], isLibFile: false }); - }); + }), it("Do not return import path because of invalid import syntax", function () { test("import i1 require(\"r1.ts\"); import = require(\"r2.ts\") import i3= require(\"r3.ts\"); import i5", true, { - referencedFiles: [], - importedFiles: [{ path: "r3.ts", position: 73, length: 5 }], + referencedFiles: [], + importedFiles: [{ filename: "r3.ts", pos: 73, end: 78 }], isLibFile: false }); - }); + }), it("Correctly return referenced files and import files", function () { test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\");", true, { - referencedFiles: [{ path: "refFile1.ts", position: 0, length: 35 }, { path: "refFile2.ts", position: 36, length: 35 }], - importedFiles: [{ path: "r1.ts", position: 92, length: 5 }, { path: "r2.ts", position: 121, length: 5 }], + referencedFiles: [{ filename: "refFile1.ts", pos: 0, end: 35 }, { filename: "refFile2.ts", pos: 36, end: 71 }], + importedFiles: [{ filename: "r1.ts", pos: 92, end: 97 }, { filename: "r2.ts", pos: 121, end: 126 }], isLibFile: false }); - }); + }), it("Correctly return referenced files and import files even with some invalid syntax", function () { test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import = require(\"r2.ts\"); import i2 = require(\"r3.ts\");", true, { - referencedFiles: [{ path: "refFile1.ts", position: 0, length: 35 }], - importedFiles: [{ path: "r1.ts", position: 91, length: 5 }, { path: "r3.ts", position: 148, length: 5 }], + referencedFiles: [{ filename: "refFile1.ts", pos: 0, end: 35 }], + importedFiles: [{ filename: "r1.ts", pos: 91, end: 96 }, { filename: "r3.ts", pos: 148, end: 153 }], isLibFile: false - }); + }) }); }); }); From 8541577d7ff9726c2c0549e4ec54e4d289b5cf3b Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 29 Oct 2014 13:58:27 -0700 Subject: [PATCH 13/18] Add fourslash support and tests cases --- src/harness/fourslash.ts | 91 +++++++++++++++++++++++++++------------- src/services/shims.ts | 2 +- 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 9dad3dddf60..fce4edddf0f 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -136,10 +136,11 @@ module FourSlash { outDir: 'outDir', sourceMap: 'sourceMap', sourceRoot: 'sourceRoot', + resolveReference: 'ResolveReference', // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file }; // List of allowed metadata names - var fileMetadataNames = [testOptMetadataNames.filename, testOptMetadataNames.emitThisFile]; + 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] @@ -236,6 +237,25 @@ module FourSlash { throw new Error("Operation should be cancelled"); } + // This function creates IScriptSnapshot object for testing getPreProcessedFileInfo + // Return object may lack some functionalities for other purposes. + function createScriptSnapShot(sourceText: string): TypeScript.IScriptSnapshot { + return { + getText: (start: number, end: number) => { + return sourceText.substr(start, end - start); + }, + getLength: () => { + return sourceText.length; + }, + getLineStartPositions: () => { + return []; + }, + getChangeRange: (oldSnapshot: TypeScript.IScriptSnapshot) => { + return undefined; + } + }; + } + export class TestState { // Language service instance public languageServiceShimHost: Harness.LanguageService.TypeScriptLS; @@ -274,9 +294,15 @@ module FourSlash { this.languageServiceShimHost.setCompilationSettings(compilationSettings); var inputFiles: { unitName: string; content: string }[] = []; + var startResolveFileRef: FourSlashFile = undefined; testData.files.forEach(file => { - var fixedPath = file.fileName.substr(file.fileName.indexOf('tests/')); + if (!startResolveFileRef && file.fileOptions[testOptMetadataNames.resolveReference]) { + startResolveFileRef = file; + } else if (startResolveFileRef) { + // If entry point for resolving file references is already specified, report duplication error + throw new Error("There exists a Fourslash file which has resolveReference flag specified; remove duplicated resolveReference flag"); + } }); // NEWTODO: disable resolution for now. @@ -294,33 +320,42 @@ module FourSlash { }); //} + if (startResolveFileRef) { + // Add the entry-point file itself into the languageServiceShimHost + this.languageServiceShimHost.addScript(startResolveFileRef.fileName, startResolveFileRef.content); - // NEWTODO: Re-implement commented-out section - //harnessCompiler.addInputFiles(inputFiles); - //try { - // var resolvedFiles = harnessCompiler.resolve(); - - // resolvedFiles.forEach(file => { - // if (!Harness.isLibraryFile(file.path)) { - // var fixedPath = file.path.substr(file.path.indexOf('tests/')); - // var content = harnessCompiler.getContentForFile(fixedPath); - // this.languageServiceShimHost.addScript(fixedPath, content); - // } - // }); - - // this.languageServiceShimHost.addScript('lib.d.ts', Harness.Compiler.libTextMinimal); - //} - //finally { - // // harness no longer needs the results of the above work, make sure the next test operations are in a clean state - // harnessCompiler.reset(); - //} - - /// NEWTODO: For now do not resolve, just use the input files - inputFiles.forEach(file => { - if (!Harness.isLibraryFile(file.unitName)) { - this.languageServiceShimHost.addScript(file.unitName, file.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; + referencedFiles.forEach(refFile => { + inputFiles.forEach(inputFile => { + // Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path + var appendRefFilePath = "tests/cases/fourslash/" + refFile.path; + if (appendRefFilePath === inputFile.unitName && !Harness.isLibraryFile(inputFile.unitName)) { + this.languageServiceShimHost.addScript(inputFile.unitName, inputFile.content); + } + }); + }); + importedFiles.forEach(importedFile => { + inputFiles.forEach(inputFile => { + // Fourslash insert tests/cases/fourslash into inputFile.unitName and import statement doesn't require ".ts" + // so convert them before making appropriate comparison + var appendRefFilePath = "tests/cases/fourslash/" + importedFile.path + ".ts"; + if (appendRefFilePath === inputFile.unitName && !Harness.isLibraryFile(inputFile.unitName)) { + this.languageServiceShimHost.addScript(inputFile.unitName, inputFile.content); + } + }); + }); + } else { + // resolveReference file-option is not specified then do not resolve any files and include all inputFiles + inputFiles.forEach(file => { + if (!Harness.isLibraryFile(file.unitName)) { + this.languageServiceShimHost.addScript(file.unitName, file.content); + } + }); + } this.languageServiceShimHost.addDefaultLibrary(); diff --git a/src/services/shims.ts b/src/services/shims.ts index c53575812c4..6e9c175dcde 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -59,7 +59,7 @@ module ts { /// // Note: This is being using by the host (VS) and is marshaled back and forth. // When changing this make sure the changes are reflected in the managed side as well - interface IFileReference { + export interface IFileReference { path: string; position: number; length: number; From dcbad6f6488c92fda1a7b4013d82b6317f020e77 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 29 Oct 2014 13:58:27 -0700 Subject: [PATCH 14/18] Add fourslash support and tests cases --- src/harness/fourslash.ts | 91 ++++++++++++++------ src/services/shims.ts | 2 +- tests/cases/fourslash/getPreProcessedFile.ts | 32 +++++++ 3 files changed, 96 insertions(+), 29 deletions(-) create mode 100644 tests/cases/fourslash/getPreProcessedFile.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 9dad3dddf60..fce4edddf0f 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -136,10 +136,11 @@ module FourSlash { outDir: 'outDir', sourceMap: 'sourceMap', sourceRoot: 'sourceRoot', + resolveReference: 'ResolveReference', // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file }; // List of allowed metadata names - var fileMetadataNames = [testOptMetadataNames.filename, testOptMetadataNames.emitThisFile]; + 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] @@ -236,6 +237,25 @@ module FourSlash { throw new Error("Operation should be cancelled"); } + // This function creates IScriptSnapshot object for testing getPreProcessedFileInfo + // Return object may lack some functionalities for other purposes. + function createScriptSnapShot(sourceText: string): TypeScript.IScriptSnapshot { + return { + getText: (start: number, end: number) => { + return sourceText.substr(start, end - start); + }, + getLength: () => { + return sourceText.length; + }, + getLineStartPositions: () => { + return []; + }, + getChangeRange: (oldSnapshot: TypeScript.IScriptSnapshot) => { + return undefined; + } + }; + } + export class TestState { // Language service instance public languageServiceShimHost: Harness.LanguageService.TypeScriptLS; @@ -274,9 +294,15 @@ module FourSlash { this.languageServiceShimHost.setCompilationSettings(compilationSettings); var inputFiles: { unitName: string; content: string }[] = []; + var startResolveFileRef: FourSlashFile = undefined; testData.files.forEach(file => { - var fixedPath = file.fileName.substr(file.fileName.indexOf('tests/')); + if (!startResolveFileRef && file.fileOptions[testOptMetadataNames.resolveReference]) { + startResolveFileRef = file; + } else if (startResolveFileRef) { + // If entry point for resolving file references is already specified, report duplication error + throw new Error("There exists a Fourslash file which has resolveReference flag specified; remove duplicated resolveReference flag"); + } }); // NEWTODO: disable resolution for now. @@ -294,33 +320,42 @@ module FourSlash { }); //} + if (startResolveFileRef) { + // Add the entry-point file itself into the languageServiceShimHost + this.languageServiceShimHost.addScript(startResolveFileRef.fileName, startResolveFileRef.content); - // NEWTODO: Re-implement commented-out section - //harnessCompiler.addInputFiles(inputFiles); - //try { - // var resolvedFiles = harnessCompiler.resolve(); - - // resolvedFiles.forEach(file => { - // if (!Harness.isLibraryFile(file.path)) { - // var fixedPath = file.path.substr(file.path.indexOf('tests/')); - // var content = harnessCompiler.getContentForFile(fixedPath); - // this.languageServiceShimHost.addScript(fixedPath, content); - // } - // }); - - // this.languageServiceShimHost.addScript('lib.d.ts', Harness.Compiler.libTextMinimal); - //} - //finally { - // // harness no longer needs the results of the above work, make sure the next test operations are in a clean state - // harnessCompiler.reset(); - //} - - /// NEWTODO: For now do not resolve, just use the input files - inputFiles.forEach(file => { - if (!Harness.isLibraryFile(file.unitName)) { - this.languageServiceShimHost.addScript(file.unitName, file.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; + referencedFiles.forEach(refFile => { + inputFiles.forEach(inputFile => { + // Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path + var appendRefFilePath = "tests/cases/fourslash/" + refFile.path; + if (appendRefFilePath === inputFile.unitName && !Harness.isLibraryFile(inputFile.unitName)) { + this.languageServiceShimHost.addScript(inputFile.unitName, inputFile.content); + } + }); + }); + importedFiles.forEach(importedFile => { + inputFiles.forEach(inputFile => { + // Fourslash insert tests/cases/fourslash into inputFile.unitName and import statement doesn't require ".ts" + // so convert them before making appropriate comparison + var appendRefFilePath = "tests/cases/fourslash/" + importedFile.path + ".ts"; + if (appendRefFilePath === inputFile.unitName && !Harness.isLibraryFile(inputFile.unitName)) { + this.languageServiceShimHost.addScript(inputFile.unitName, inputFile.content); + } + }); + }); + } else { + // resolveReference file-option is not specified then do not resolve any files and include all inputFiles + inputFiles.forEach(file => { + if (!Harness.isLibraryFile(file.unitName)) { + this.languageServiceShimHost.addScript(file.unitName, file.content); + } + }); + } this.languageServiceShimHost.addDefaultLibrary(); diff --git a/src/services/shims.ts b/src/services/shims.ts index c53575812c4..6e9c175dcde 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -59,7 +59,7 @@ module ts { /// // Note: This is being using by the host (VS) and is marshaled back and forth. // When changing this make sure the changes are reflected in the managed side as well - interface IFileReference { + export interface IFileReference { path: string; position: number; length: number; diff --git a/tests/cases/fourslash/getPreProcessedFile.ts b/tests/cases/fourslash/getPreProcessedFile.ts new file mode 100644 index 00000000000..43f48dc86ac --- /dev/null +++ b/tests/cases/fourslash/getPreProcessedFile.ts @@ -0,0 +1,32 @@ +/// + +// @Filename: refFile1.ts +//// class D { } + +// @Filename: refFile2.ts +//// export class E {} + +// @Filename: main.ts +// @ResolveReference: true +//// /// +//// /*1*/////*2*/ +//// /*3*/////*4*/ +//// import ref2 = require("refFile2"); +//// import noExistref2 = require(/*5*/"NotExistRefFile2"/*6*/); +//// import invalidRef1 /*7*/require/*8*/("refFile2"); +//// /*9*/import invalidRef2 = requi/*10*/("refFile2"); +//// var obj: /*11*/C/*12*/; +//// var obj1: D; +//// var obj2: ref2.E; + +goTo.file("main.ts"); +verify.numberOfErrorsInCurrentFile(7); +verify.errorExistsBetweenMarkers("1", "2"); +verify.errorExistsBetweenMarkers("3", "4"); +verify.errorExistsBetweenMarkers("5", "6"); +verify.errorExistsBetweenMarkers("7", "8"); +verify.errorExistsBetweenMarkers("9", "10"); +verify.errorExistsBetweenMarkers("11", "12"); + + + From 3c6d9c8173f3a7427474ce8090bfba161cb5ea6d Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 29 Oct 2014 14:27:43 -0700 Subject: [PATCH 15/18] Remove old commit and debugger flag --- src/compiler/parser.ts | 1 - src/services/services.ts | 6 ------ tests/cases/unittests/services/preProcessFile.ts | 1 - 3 files changed, 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 912c3c1d265..dd923323627 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -647,7 +647,6 @@ module ts { isNoDefaultLib: boolean } - // TODO (yuisu) : add referencedFiles array for filling in export function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult { var simpleReferenceRegEx = /^\/\/\/\s*/gim; diff --git a/src/services/services.ts b/src/services/services.ts index 8293cb9c523..702d1510df7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1901,7 +1901,6 @@ module ts { }; } - export var tripleSlashReferenceRegExp = /^(\/\/\/\s*/; export function preProcessFile(sourceText: string, readImportFiles = true): PreProcessedFileInfo { var referencedFiles: FileReference[] = []; var importedFiles: FileReference[] = []; @@ -1917,11 +1916,6 @@ module ts { var fileReference = referencePathMatchResult.fileReference; if (fileReference) { referencedFiles.push(fileReference); - /* referencedFiles.push({ - path: switchToForwardSlashes(normalizePath(fileReference.filename)), - position: fileReference.pos, - length: fileReference.end - fileReference.pos, - }); */ } } }); diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts index 0a5fac5e24b..88aa0f5e9ed 100644 --- a/tests/cases/unittests/services/preProcessFile.ts +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -3,7 +3,6 @@ describe('PreProcessFile:', function () { function test(sourceText: string, readImportFile: boolean, expectedPreProcess: ts.PreProcessedFileInfo): void { - debugger var resultPreProcess = ts.preProcessFile(sourceText, readImportFile); var resultIsLibFile = resultPreProcess.isLibFile; From 637001252c801cbf03324d1daa8887c3a1f72f33 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 29 Oct 2014 14:27:57 -0700 Subject: [PATCH 16/18] Address code review --- src/services/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 702d1510df7..3e47ec169b1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1922,8 +1922,7 @@ module ts { } function processImport(): void { - var scanner = createScanner(getDefaultCompilerOptions().target, /*skipTrivia*/true, sourceText); - + scanner.setText(sourceText); var token = scanner.scan(); // Look for: // import foo = module("foo"); @@ -1954,6 +1953,7 @@ module ts { } token = scanner.scan(); } + scanner.setText(undefined); } if (readImportFiles) { From db4f84653ba912e02c93eaeca3e7ab1cb6ae47b2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 29 Oct 2014 17:36:39 -0700 Subject: [PATCH 17/18] Fix indentation --- Jakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile b/Jakefile index 821f755650c..8454c85fac3 100644 --- a/Jakefile +++ b/Jakefile @@ -81,7 +81,7 @@ var harnessSources = [ ].map(function (f) { return path.join(harnessDirectory, f); }).concat([ - "services/colorization.ts", + "services/colorization.ts", "services/documentRegistry.ts", "services/preProcessFile.ts" ].map(function (f) { From e3579d14565819943eb55e280c21b35138fc7b2b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 30 Oct 2014 15:34:54 -0700 Subject: [PATCH 18/18] Address code review --- src/compiler/parser.ts | 10 +-- src/harness/fourslash.ts | 75 +++++++++----------- src/services/services.ts | 1 - tests/cases/fourslash/getPreProcessedFile.ts | 2 +- 4 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dd923323627..21e9a35e72b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -642,9 +642,9 @@ module ts { } interface ReferencePathMatchResult { - fileReference: FileReference - diagnostic: DiagnosticMessage - isNoDefaultLib: boolean + fileReference?: FileReference + diagnostic?: DiagnosticMessage + isNoDefaultLib?: boolean } export function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult { @@ -653,8 +653,6 @@ module ts { if (simpleReferenceRegEx.exec(comment)) { if (isNoDefaultLibRegEx.exec(comment)) { return { - fileReference: undefined, - diagnostic: undefined, isNoDefaultLib: true } } @@ -670,13 +668,11 @@ module ts { }; return { fileReference: fileRef, - diagnostic: undefined, isNoDefaultLib: false }; } else { return { - fileReference: undefined, diagnostic: Diagnostics.Invalid_reference_directive_syntax, isNoDefaultLib: false }; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index fce4edddf0f..e307747634d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -284,6 +284,16 @@ module FourSlash { private scenarioActions: string[] = []; private taoInvalidReason: string = null; + private inputFiles: ts.Map = {}; // 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); + } + } constructor(public testData: FourSlashData) { // Initialize the language service with all the scripts @@ -293,10 +303,11 @@ module FourSlash { var compilationSettings = convertGlobalOptionsToCompilationSettings(this.testData.globalOptions); this.languageServiceShimHost.setCompilationSettings(compilationSettings); - var inputFiles: { unitName: string; content: string }[] = []; var startResolveFileRef: FourSlashFile = undefined; - testData.files.forEach(file => { + ts.forEach(testData.files, file => { + // Create map between fileName and its content for easily looking up when resolveReference flag is specified + this.inputFiles[file.fileName] = file.content; if (!startResolveFileRef && file.fileOptions[testOptMetadataNames.resolveReference]) { startResolveFileRef = file; } else if (startResolveFileRef) { @@ -305,21 +316,6 @@ module FourSlash { } }); - // NEWTODO: disable resolution for now. - // If the last unit contains require( or /// reference then consider it the only input file - // and the rest will be added via resolution. If not, then assume we have multiple files - // with 0 references in any of them. We could be smarter here to allow scenarios like - // 2 files without references and 1 file with a reference but we have 0 tests like that - // at the moment and an exhaustive search of the test files for that content could be quite slow. - var lastFile = testData.files[testData.files.length - 1]; - //if (/require\(/.test(lastFile.content) || /reference\spath/.test(lastFile.content)) { - // inputFiles.push({ unitName: lastFile.fileName, content: lastFile.content }); - //} else { - inputFiles = testData.files.map(file => { - return { unitName: file.fileName, content: file.content }; - }); - //} - if (startResolveFileRef) { // Add the entry-point file itself into the languageServiceShimHost this.languageServiceShimHost.addScript(startResolveFileRef.fileName, startResolveFileRef.content); @@ -329,37 +325,36 @@ module FourSlash { var resolvedResult = jsonResolvedResult.result; var referencedFiles: ts.IFileReference[] = resolvedResult.referencedFiles; var importedFiles: ts.IFileReference[] = resolvedResult.importedFiles; - referencedFiles.forEach(refFile => { - inputFiles.forEach(inputFile => { - // Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path - var appendRefFilePath = "tests/cases/fourslash/" + refFile.path; - if (appendRefFilePath === inputFile.unitName && !Harness.isLibraryFile(inputFile.unitName)) { - this.languageServiceShimHost.addScript(inputFile.unitName, inputFile.content); - } - }); + + // 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; + this.addMatchedInputFile(referenceFilePath); }); - importedFiles.forEach(importedFile => { - inputFiles.forEach(inputFile => { - // Fourslash insert tests/cases/fourslash into inputFile.unitName and import statement doesn't require ".ts" - // so convert them before making appropriate comparison - var appendRefFilePath = "tests/cases/fourslash/" + importedFile.path + ".ts"; - if (appendRefFilePath === inputFile.unitName && !Harness.isLibraryFile(inputFile.unitName)) { - this.languageServiceShimHost.addScript(inputFile.unitName, inputFile.content); - } - }); + + // Add import files into language-service host + 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"; + this.addMatchedInputFile(importedFilePath); }); + + // Check if no-default-lib flag is false and if so add default library + if (!resolvedResult.isLibFile) { + this.languageServiceShimHost.addDefaultLibrary(); + } } else { // resolveReference file-option is not specified then do not resolve any files and include all inputFiles - inputFiles.forEach(file => { - if (!Harness.isLibraryFile(file.unitName)) { - this.languageServiceShimHost.addScript(file.unitName, file.content); + ts.forEachKey(this.inputFiles, fileName => { + if (!Harness.isLibraryFile(fileName)) { + this.languageServiceShimHost.addScript(fileName, this.inputFiles[fileName]); } }); + this.languageServiceShimHost.addDefaultLibrary(); } - this.languageServiceShimHost.addDefaultLibrary(); - - // Sneak into the language service and get its compiler so we can examine the syntax trees this.languageService = this.languageServiceShimHost.getLanguageService().languageService; var compilerState = (this.languageService).compiler; diff --git a/src/services/services.ts b/src/services/services.ts index 3e47ec169b1..a7a5398c945 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1960,7 +1960,6 @@ module ts { processImport(); } processTripleSlashDirectives(); - // TODO (yuisu) : remove diagnostics array return { referencedFiles: referencedFiles, importedFiles: importedFiles, isLibFile: isNoDefaultLib }; } diff --git a/tests/cases/fourslash/getPreProcessedFile.ts b/tests/cases/fourslash/getPreProcessedFile.ts index 43f48dc86ac..abd26bb6e4b 100644 --- a/tests/cases/fourslash/getPreProcessedFile.ts +++ b/tests/cases/fourslash/getPreProcessedFile.ts @@ -25,7 +25,7 @@ verify.errorExistsBetweenMarkers("1", "2"); verify.errorExistsBetweenMarkers("3", "4"); verify.errorExistsBetweenMarkers("5", "6"); verify.errorExistsBetweenMarkers("7", "8"); -verify.errorExistsBetweenMarkers("9", "10"); +verify.errorExistsBetweenMarkers("9", "10"); // At this position, there are two diagnostic messages: ';' expected, Cannot find name 'requi' verify.errorExistsBetweenMarkers("11", "12");