Skip to content

Commit 61c9f98

Browse files
committed
Merge branch 'master' into parse-jsdoc-with-ts-type-parser
2 parents 172db13 + e842182 commit 61c9f98

15 files changed

Lines changed: 95 additions & 87 deletions

src/compiler/core.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,21 @@ namespace ts {
15801580
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
15811581
}
15821582

1583+
/* @internal */
1584+
export function pathIsRelative(path: string): boolean {
1585+
return /^\.\.?($|[\\/])/.test(path);
1586+
}
1587+
15831588
export function isExternalModuleNameRelative(moduleName: string): boolean {
15841589
// TypeScript 1.0 spec (April 2014): 11.2.1
15851590
// An external module name is "relative" if the first term is "." or "..".
1586-
return /^\.\.?($|[\\/])/.test(moduleName);
1591+
// Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module.
1592+
return pathIsRelative(moduleName) || isRootedDiskPath(moduleName);
1593+
}
1594+
1595+
/** @deprecated Use `!isExternalModuleNameRelative(moduleName)` instead. */
1596+
export function moduleHasNonRelativeName(moduleName: string): boolean {
1597+
return !isExternalModuleNameRelative(moduleName);
15871598
}
15881599

15891600
export function getEmitScriptTarget(compilerOptions: CompilerOptions) {

src/compiler/moduleNameResolver.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ namespace ts {
5454
};
5555
}
5656

57-
export function moduleHasNonRelativeName(moduleName: string): boolean {
58-
return !(isRootedDiskPath(moduleName) || isExternalModuleNameRelative(moduleName));
59-
}
60-
6157
interface ModuleResolutionState {
6258
host: ModuleResolutionHost;
6359
compilerOptions: CompilerOptions;
@@ -318,7 +314,7 @@ namespace ts {
318314
}
319315

320316
function getOrCreateCacheForModuleName(nonRelativeModuleName: string) {
321-
if (!moduleHasNonRelativeName(nonRelativeModuleName)) {
317+
if (isExternalModuleNameRelative(nonRelativeModuleName)) {
322318
return undefined;
323319
}
324320
let perModuleNameCache = moduleNameToDirectoryMap.get(nonRelativeModuleName);
@@ -535,7 +531,7 @@ namespace ts {
535531
function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
536532
failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
537533

538-
if (moduleHasNonRelativeName(moduleName)) {
534+
if (!isExternalModuleNameRelative(moduleName)) {
539535
return tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, failedLookupLocations, state);
540536
}
541537
else {
@@ -711,7 +707,7 @@ namespace ts {
711707
return toSearchResult({ resolved, isExternalLibraryImport: false });
712708
}
713709

714-
if (moduleHasNonRelativeName(moduleName)) {
710+
if (!isExternalModuleNameRelative(moduleName)) {
715711
if (traceEnabled) {
716712
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);
717713
}
@@ -1024,7 +1020,7 @@ namespace ts {
10241020
}
10251021
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
10261022

1027-
if (moduleHasNonRelativeName(moduleName)) {
1023+
if (!isExternalModuleNameRelative(moduleName)) {
10281024
// Climb up parent directories looking for a module.
10291025
const resolved = forEachAncestorDirectory(containingDirectory, directory => {
10301026
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, traceEnabled, host);

src/compiler/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ namespace ts {
332332
const categoryColor = getCategoryFormat(diagnostic.category);
333333
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
334334
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }`;
335+
output += sys.newLine;
335336
}
336337
return output;
337338
}

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace ts {
6161
}
6262

6363
function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic, host: FormatDiagnosticsHost): void {
64-
sys.write(ts.formatDiagnosticsWithColorAndContext([diagnostic], host) + sys.newLine + sys.newLine);
64+
sys.write(ts.formatDiagnosticsWithColorAndContext([diagnostic], host) + sys.newLine);
6565
}
6666

6767
function reportWatchDiagnostic(diagnostic: Diagnostic) {

src/server/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ namespace ts.server {
227227
}));
228228
}
229229

230-
getFormattingEditsForRange(file: string, start: number, end: number, _options: ts.FormatCodeOptions): ts.TextChange[] {
230+
getFormattingEditsForRange(file: string, start: number, end: number, _options: FormatCodeOptions): ts.TextChange[] {
231231
const args: protocol.FormatRequestArgs = this.createFileLocationRequestArgsWithEndLineAndOffset(file, start, end);
232232

233233

src/server/editorServices.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace ts.server {
4545
* Any compiler options that might contain paths will be taken out.
4646
* Enum compiler options will be converted to strings.
4747
*/
48-
readonly compilerOptions: ts.CompilerOptions;
48+
readonly compilerOptions: CompilerOptions;
4949
// "extends", "files", "include", or "exclude" will be undefined if an external config is used.
5050
// Otherwise, we will use "true" if the property is present and "false" if it is missing.
5151
readonly extends: boolean | undefined;
@@ -201,7 +201,7 @@ namespace ts.server {
201201
* This helper function processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
202202
*/
203203
export function combineProjectOutput<T>(projects: Project[], action: (project: Project) => T[], comparer?: (a: T, b: T) => number, areEqual?: (a: T, b: T) => boolean) {
204-
const result = ts.flatMap(projects, action).sort(comparer);
204+
const result = flatMap(projects, action).sort(comparer);
205205
return projects.length > 1 ? deduplicate(result, areEqual) : result;
206206
}
207207

@@ -240,7 +240,7 @@ namespace ts.server {
240240
getFileName: x => x,
241241
getScriptKind: _ => undefined,
242242
hasMixedContent: (fileName, extraFileExtensions) => {
243-
const mixedContentExtensions = ts.map(ts.filter(extraFileExtensions, item => item.isMixedContent), item => item.extension);
243+
const mixedContentExtensions = map(filter(extraFileExtensions, item => item.isMixedContent), item => item.extension);
244244
return forEach(mixedContentExtensions, extension => fileExtensionIs(fileName, extension));
245245
}
246246
};
@@ -633,7 +633,7 @@ namespace ts.server {
633633
// If a change was made inside "folder/file", node will trigger the callback twice:
634634
// one with the fileName being "folder/file", and the other one with "folder".
635635
// We don't respond to the second one.
636-
if (fileName && !ts.isSupportedSourceFileName(fileName, project.getCompilerOptions(), this.hostConfiguration.extraFileExtensions)) {
636+
if (fileName && !isSupportedSourceFileName(fileName, project.getCompilerOptions(), this.hostConfiguration.extraFileExtensions)) {
637637
return;
638638
}
639639

@@ -1082,7 +1082,7 @@ namespace ts.server {
10821082
configFileName: configFileName(),
10831083
projectType: project instanceof server.ExternalProject ? "external" : "configured",
10841084
languageServiceEnabled: project.languageServiceEnabled,
1085-
version: ts.version,
1085+
version,
10861086
};
10871087
this.eventHandler({ eventName: ProjectInfoTelemetryEvent, data });
10881088

@@ -1092,7 +1092,7 @@ namespace ts.server {
10921092
}
10931093

10941094
const configFilePath = project instanceof server.ConfiguredProject && project.getConfigFilePath();
1095-
const base = ts.getBaseFileName(configFilePath);
1095+
const base = getBaseFileName(configFilePath);
10961096
return base === "tsconfig.json" || base === "jsconfig.json" ? base : "other";
10971097
}
10981098

src/server/lsHost.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/// <reference path="scriptInfo.ts" />
44

55
namespace ts.server {
6-
export class LSHost implements ts.LanguageServiceHost, ModuleResolutionHost {
7-
private compilationSettings: ts.CompilerOptions;
6+
export class LSHost implements LanguageServiceHost, ModuleResolutionHost {
7+
private compilationSettings: CompilerOptions;
88
private readonly resolvedModuleNames = createMap<Map<ResolvedModuleWithFailedLookupLocations>>();
99
private readonly resolvedTypeReferenceDirectives = createMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
1010
private readonly getCanonicalFileName: (fileName: string) => string;
@@ -17,7 +17,7 @@ namespace ts.server {
1717

1818
constructor(private readonly host: ServerHost, private project: Project, private readonly cancellationToken: HostCancellationToken) {
1919
this.cancellationToken = new ThrottledCancellationToken(cancellationToken, project.projectService.throttleWaitMilliseconds);
20-
this.getCanonicalFileName = ts.createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
20+
this.getCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
2121

2222
if (host.trace) {
2323
this.trace = s => host.trace(s);
@@ -29,7 +29,7 @@ namespace ts.server {
2929
: undefined;
3030
const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host);
3131
// return result immediately only if it is .ts, .tsx or .d.ts
32-
if (moduleHasNonRelativeName(moduleName) && !(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) {
32+
if (!isExternalModuleNameRelative(moduleName) && !(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) {
3333
// otherwise try to load typings from @types
3434

3535
// create different collection of failed lookup locations for second pass
@@ -99,7 +99,7 @@ namespace ts.server {
9999
}
100100
}
101101

102-
ts.Debug.assert(resolution !== undefined);
102+
Debug.assert(resolution !== undefined);
103103

104104
resolvedModules.push(getResult(resolution));
105105
}
@@ -177,7 +177,7 @@ namespace ts.server {
177177
return combinePaths(nodeModuleBinDir, getDefaultLibFileName(this.compilationSettings));
178178
}
179179

180-
getScriptSnapshot(filename: string): ts.IScriptSnapshot {
180+
getScriptSnapshot(filename: string): IScriptSnapshot {
181181
const scriptInfo = this.project.getScriptInfoLSHost(filename);
182182
if (scriptInfo) {
183183
return scriptInfo.getSnapshot();
@@ -238,7 +238,7 @@ namespace ts.server {
238238
this.resolvedTypeReferenceDirectives.delete(info.path);
239239
}
240240

241-
setCompilationSettings(opt: ts.CompilerOptions) {
241+
setCompilationSettings(opt: CompilerOptions) {
242242
if (changesAffectModuleResolution(this.compilationSettings, opt)) {
243243
this.resolvedModuleNames.clear();
244244
this.resolvedTypeReferenceDirectives.clear();

src/server/project.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace ts.server {
105105
export abstract class Project {
106106
private rootFiles: ScriptInfo[] = [];
107107
private rootFilesMap: Map<ScriptInfo> = createMap<ScriptInfo>();
108-
private program: ts.Program;
108+
private program: Program;
109109
private externalFiles: SortedReadonlyArray<string>;
110110
private missingFilesMap: Map<FileWatcher> = createMap<FileWatcher>();
111111

@@ -180,14 +180,14 @@ namespace ts.server {
180180
private readonly projectName: string,
181181
readonly projectKind: ProjectKind,
182182
readonly projectService: ProjectService,
183-
private documentRegistry: ts.DocumentRegistry,
183+
private documentRegistry: DocumentRegistry,
184184
hasExplicitListOfFiles: boolean,
185185
languageServiceEnabled: boolean,
186186
private compilerOptions: CompilerOptions,
187187
public compileOnSaveEnabled: boolean) {
188188

189189
if (!this.compilerOptions) {
190-
this.compilerOptions = ts.getDefaultCompilerOptions();
190+
this.compilerOptions = getDefaultCompilerOptions();
191191
this.compilerOptions.allowNonTsExtensions = true;
192192
this.compilerOptions.allowJs = true;
193193
}
@@ -201,7 +201,7 @@ namespace ts.server {
201201
this.lsHost = new LSHost(this.projectService.host, this, this.projectService.cancellationToken);
202202
this.lsHost.setCompilationSettings(this.compilerOptions);
203203

204-
this.languageService = ts.createLanguageService(this.lsHost, this.documentRegistry);
204+
this.languageService = createLanguageService(this.lsHost, this.documentRegistry);
205205

206206
if (!languageServiceEnabled) {
207207
this.disableLanguageService();
@@ -875,7 +875,7 @@ namespace ts.server {
875875
// Used to keep track of what directories are watched for this project
876876
directoriesWatchedForTsconfig: string[] = [];
877877

878-
constructor(projectService: ProjectService, documentRegistry: ts.DocumentRegistry, compilerOptions: CompilerOptions) {
878+
constructor(projectService: ProjectService, documentRegistry: DocumentRegistry, compilerOptions: CompilerOptions) {
879879
super(InferredProject.newName(),
880880
ProjectKind.Inferred,
881881
projectService,
@@ -948,7 +948,7 @@ namespace ts.server {
948948

949949
constructor(configFileName: NormalizedPath,
950950
projectService: ProjectService,
951-
documentRegistry: ts.DocumentRegistry,
951+
documentRegistry: DocumentRegistry,
952952
hasExplicitListOfFiles: boolean,
953953
compilerOptions: CompilerOptions,
954954
private wildcardDirectories: Map<WatchDirectoryFlags>,
@@ -1152,7 +1152,7 @@ namespace ts.server {
11521152
}
11531153

11541154
getEffectiveTypeRoots() {
1155-
return ts.getEffectiveTypeRoots(this.getCompilerOptions(), this.projectService.host) || [];
1155+
return getEffectiveTypeRoots(this.getCompilerOptions(), this.projectService.host) || [];
11561156
}
11571157
}
11581158

@@ -1164,7 +1164,7 @@ namespace ts.server {
11641164
private typeAcquisition: TypeAcquisition;
11651165
constructor(public externalProjectName: string,
11661166
projectService: ProjectService,
1167-
documentRegistry: ts.DocumentRegistry,
1167+
documentRegistry: DocumentRegistry,
11681168
compilerOptions: CompilerOptions,
11691169
languageServiceEnabled: boolean,
11701170
public compileOnSaveEnabled: boolean,

src/server/scriptInfo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ namespace ts.server {
7272
const lineMap = this.getLineMap();
7373
const start = lineMap[line]; // -1 since line is 1-based
7474
const end = line + 1 < lineMap.length ? lineMap[line + 1] : this.text.length;
75-
return ts.createTextSpanFromBounds(start, end);
75+
return createTextSpanFromBounds(start, end);
7676
}
7777
const index = this.svc.getSnapshot().index;
7878
const { lineText, absolutePosition } = index.lineNumberToInfo(line + 1);
7979
const len = lineText !== undefined ? lineText.length : index.absolutePositionOfStartOfLine(line + 2) - absolutePosition;
80-
return ts.createTextSpan(absolutePosition, len);
80+
return createTextSpan(absolutePosition, len);
8181
}
8282

8383
/**
@@ -147,7 +147,7 @@ namespace ts.server {
147147
* All projects that include this file
148148
*/
149149
readonly containingProjects: Project[] = [];
150-
private formatCodeSettings: ts.FormatCodeSettings;
150+
private formatCodeSettings: FormatCodeSettings;
151151
readonly path: Path;
152152

153153
private fileWatcher: FileWatcher;

src/server/scriptVersionCache.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ namespace ts.server {
248248
}
249249

250250
getTextChangeRange() {
251-
return ts.createTextChangeRange(ts.createTextSpan(this.pos, this.deleteLen),
251+
return createTextChangeRange(createTextSpan(this.pos, this.deleteLen),
252252
this.insertedText ? this.insertedText.length : 0);
253253
}
254254
}
@@ -337,21 +337,21 @@ namespace ts.server {
337337
getTextChangesBetweenVersions(oldVersion: number, newVersion: number) {
338338
if (oldVersion < newVersion) {
339339
if (oldVersion >= this.minVersion) {
340-
const textChangeRanges: ts.TextChangeRange[] = [];
340+
const textChangeRanges: TextChangeRange[] = [];
341341
for (let i = oldVersion + 1; i <= newVersion; i++) {
342342
const snap = this.versions[this.versionToIndex(i)];
343343
for (const textChange of snap.changesSincePreviousVersion) {
344344
textChangeRanges.push(textChange.getTextChangeRange());
345345
}
346346
}
347-
return ts.collapseTextChangeRangesAcrossMultipleVersions(textChangeRanges);
347+
return collapseTextChangeRangesAcrossMultipleVersions(textChangeRanges);
348348
}
349349
else {
350350
return undefined;
351351
}
352352
}
353353
else {
354-
return ts.unchangedTextChangeRange;
354+
return unchangedTextChangeRange;
355355
}
356356
}
357357

@@ -365,7 +365,7 @@ namespace ts.server {
365365
}
366366
}
367367

368-
export class LineIndexSnapshot implements ts.IScriptSnapshot {
368+
export class LineIndexSnapshot implements IScriptSnapshot {
369369
constructor(readonly version: number, readonly cache: ScriptVersionCache, readonly index: LineIndex, readonly changesSincePreviousVersion: ReadonlyArray<TextChange> = emptyArray) {
370370
}
371371

@@ -377,10 +377,10 @@ namespace ts.server {
377377
return this.index.root.charCount();
378378
}
379379

380-
getChangeRange(oldSnapshot: ts.IScriptSnapshot): ts.TextChangeRange {
380+
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange {
381381
if (oldSnapshot instanceof LineIndexSnapshot && this.cache === oldSnapshot.cache) {
382382
if (this.version <= oldSnapshot.version) {
383-
return ts.unchangedTextChangeRange;
383+
return unchangedTextChangeRange;
384384
}
385385
else {
386386
return this.cache.getTextChangesBetweenVersions(oldSnapshot.version, this.version);
@@ -539,7 +539,7 @@ namespace ts.server {
539539
}
540540

541541
static linesFromText(text: string) {
542-
const lineMap = ts.computeLineStarts(text);
542+
const lineMap = computeLineStarts(text);
543543

544544
if (lineMap.length === 0) {
545545
return { lines: <string[]>[], lineMap };

0 commit comments

Comments
 (0)