Skip to content

Commit 9c0e64d

Browse files
committed
fix merge issues, restore tests
1 parent 912e685 commit 9c0e64d

11 files changed

+97
-473
lines changed

src/compiler/binder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference path="utilities.ts"/>
2-
/// <reference path="moduleNameResolver.ts"/>
32
/// <reference path="parser.ts"/>
43

54
/* @internal */

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference path="moduleNameResolver.ts"/>
12
/// <reference path="binder.ts"/>
23

34
/* @internal */

src/compiler/core.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,78 @@ namespace ts {
18891889
: ((fileName) => fileName.toLowerCase());
18901890
}
18911891

1892+
/**
1893+
* patternStrings contains both pattern strings (containing "*") and regular strings.
1894+
* Return an exact match if possible, or a pattern match, or undefined.
1895+
* (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
1896+
*/
1897+
/* @internal */
1898+
export function matchPatternOrExact(patternStrings: string[], candidate: string): string | Pattern | undefined {
1899+
const patterns: Pattern[] = [];
1900+
for (const patternString of patternStrings) {
1901+
const pattern = tryParsePattern(patternString);
1902+
if (pattern) {
1903+
patterns.push(pattern);
1904+
}
1905+
else if (patternString === candidate) {
1906+
// pattern was matched as is - no need to search further
1907+
return patternString;
1908+
}
1909+
}
1910+
1911+
return findBestPatternMatch(patterns, _ => _, candidate);
1912+
}
1913+
1914+
/* @internal */
1915+
export function patternText({prefix, suffix}: Pattern): string {
1916+
return `${prefix}*${suffix}`;
1917+
}
1918+
1919+
/**
1920+
* Given that candidate matches pattern, returns the text matching the '*'.
1921+
* E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar"
1922+
*/
1923+
/* @internal */
1924+
export function matchedText(pattern: Pattern, candidate: string): string {
1925+
Debug.assert(isPatternMatch(pattern, candidate));
1926+
return candidate.substr(pattern.prefix.length, candidate.length - pattern.suffix.length);
1927+
}
1928+
1929+
/** Return the object corresponding to the best pattern to match `candidate`. */
1930+
/* @internal */
1931+
export function findBestPatternMatch<T>(values: T[], getPattern: (value: T) => Pattern, candidate: string): T | undefined {
1932+
let matchedValue: T | undefined = undefined;
1933+
// use length of prefix as betterness criteria
1934+
let longestMatchPrefixLength = -1;
1935+
1936+
for (const v of values) {
1937+
const pattern = getPattern(v);
1938+
if (isPatternMatch(pattern, candidate) && pattern.prefix.length > longestMatchPrefixLength) {
1939+
longestMatchPrefixLength = pattern.prefix.length;
1940+
matchedValue = v;
1941+
}
1942+
}
1943+
1944+
return matchedValue;
1945+
}
1946+
1947+
function isPatternMatch({prefix, suffix}: Pattern, candidate: string) {
1948+
return candidate.length >= prefix.length + suffix.length &&
1949+
startsWith(candidate, prefix) &&
1950+
endsWith(candidate, suffix);
1951+
}
1952+
1953+
/* @internal */
1954+
export function tryParsePattern(pattern: string): Pattern | undefined {
1955+
// This should be verified outside of here and a proper error thrown.
1956+
Debug.assert(hasZeroOrOneAsteriskCharacter(pattern));
1957+
const indexOfStar = pattern.indexOf("*");
1958+
return indexOfStar === -1 ? undefined : {
1959+
prefix: pattern.substr(0, indexOfStar),
1960+
suffix: pattern.substr(indexOfStar + 1)
1961+
};
1962+
}
1963+
18921964
export function positionIsSynthesized(pos: number): boolean {
18931965
// This is a fast way of testing the following conditions:
18941966
// pos === undefined || pos === null || isNaN(pos) || pos < 0;

src/compiler/emitter.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ namespace ts {
1313
_i = 0x10000000, // Use/preference flag for '_i'
1414
}
1515

16+
const id = (s: SourceFile) => s;
17+
const nullTransformers: Transformer[] = [ctx => id];
18+
1619
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
1720
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean): EmitResult {
1821
const delimiters = createDelimiterMap();
@@ -192,7 +195,7 @@ const _super = (function (geti, seti) {
192195
const emittedFilesList: string[] = compilerOptions.listEmittedFiles ? [] : undefined;
193196
const emitterDiagnostics = createDiagnosticCollection();
194197
const newLine = host.getNewLine();
195-
const transformers = getTransformers(compilerOptions);
198+
const transformers: Transformer[] = emitOnlyDtsFiles ? nullTransformers : getTransformers(compilerOptions);
196199
const writer = createTextWriter(newLine);
197200
const {
198201
write,
@@ -271,7 +274,9 @@ const _super = (function (geti, seti) {
271274
function emitFile(jsFilePath: string, sourceMapFilePath: string, declarationFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean) {
272275
// Make sure not to write js file and source map file if any of them cannot be written
273276
if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit) {
274-
printFile(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
277+
if (!emitOnlyDtsFiles) {
278+
printFile(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
279+
}
275280
}
276281
else {
277282
emitSkipped = true;
@@ -282,7 +287,9 @@ const _super = (function (geti, seti) {
282287
}
283288

284289
if (!emitSkipped && emittedFilesList) {
285-
emittedFilesList.push(jsFilePath);
290+
if (!emitOnlyDtsFiles) {
291+
emittedFilesList.push(jsFilePath);
292+
}
286293
if (sourceMapFilePath) {
287294
emittedFilesList.push(sourceMapFilePath);
288295
}

src/compiler/moduleNameResolver.ts

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -512,75 +512,6 @@ namespace ts {
512512
}
513513
}
514514

515-
/**
516-
* patternStrings contains both pattern strings (containing "*") and regular strings.
517-
* Return an exact match if possible, or a pattern match, or undefined.
518-
* (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
519-
*/
520-
function matchPatternOrExact(patternStrings: string[], candidate: string): string | Pattern | undefined {
521-
const patterns: Pattern[] = [];
522-
for (const patternString of patternStrings) {
523-
const pattern = tryParsePattern(patternString);
524-
if (pattern) {
525-
patterns.push(pattern);
526-
}
527-
else if (patternString === candidate) {
528-
// pattern was matched as is - no need to search further
529-
return patternString;
530-
}
531-
}
532-
533-
return findBestPatternMatch(patterns, _ => _, candidate);
534-
}
535-
536-
function patternText({prefix, suffix}: Pattern): string {
537-
return `${prefix}*${suffix}`;
538-
}
539-
540-
/**
541-
* Given that candidate matches pattern, returns the text matching the '*'.
542-
* E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar"
543-
*/
544-
function matchedText(pattern: Pattern, candidate: string): string {
545-
Debug.assert(isPatternMatch(pattern, candidate));
546-
return candidate.substr(pattern.prefix.length, candidate.length - pattern.suffix.length);
547-
}
548-
549-
/** Return the object corresponding to the best pattern to match `candidate`. */
550-
/* @internal */
551-
export function findBestPatternMatch<T>(values: T[], getPattern: (value: T) => Pattern, candidate: string): T | undefined {
552-
let matchedValue: T | undefined = undefined;
553-
// use length of prefix as betterness criteria
554-
let longestMatchPrefixLength = -1;
555-
556-
for (const v of values) {
557-
const pattern = getPattern(v);
558-
if (isPatternMatch(pattern, candidate) && pattern.prefix.length > longestMatchPrefixLength) {
559-
longestMatchPrefixLength = pattern.prefix.length;
560-
matchedValue = v;
561-
}
562-
}
563-
564-
return matchedValue;
565-
}
566-
567-
function isPatternMatch({prefix, suffix}: Pattern, candidate: string) {
568-
return candidate.length >= prefix.length + suffix.length &&
569-
startsWith(candidate, prefix) &&
570-
endsWith(candidate, suffix);
571-
}
572-
573-
/* @internal */
574-
export function tryParsePattern(pattern: string): Pattern | undefined {
575-
// This should be verified outside of here and a proper error thrown.
576-
Debug.assert(hasZeroOrOneAsteriskCharacter(pattern));
577-
const indexOfStar = pattern.indexOf("*");
578-
return indexOfStar === -1 ? undefined : {
579-
prefix: pattern.substr(0, indexOfStar),
580-
suffix: pattern.substr(indexOfStar + 1)
581-
};
582-
}
583-
584515
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
585516
const containingDirectory = getDirectoryPath(containingFile);
586517
const supportedExtensions = getSupportedExtensions(compilerOptions);

src/services/services.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,8 @@ namespace ts {
945945
let program: Program;
946946
let lastProjectVersion: string;
947947

948+
let lastTypesRootVersion = 0;
949+
948950
const useCaseSensitivefileNames = false;
949951
const cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
950952

@@ -993,6 +995,13 @@ namespace ts {
993995
}
994996
}
995997

998+
const typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
999+
if (lastTypesRootVersion !== typeRootsVersion) {
1000+
log("TypeRoots version has changed; provide new program");
1001+
program = undefined;
1002+
lastTypesRootVersion = typeRootsVersion;
1003+
}
1004+
9961005
// Get a fresh cache of the host information
9971006
let hostCache = new HostCache(host, getCanonicalFileName);
9981007

src/services/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ namespace ts {
148148
readFile?(path: string, encoding?: string): string;
149149
fileExists?(path: string): boolean;
150150

151+
/*
152+
* LS host can optionally implement these methods to support automatic updating when new type libraries are installed
153+
*/
154+
getTypeRootsVersion?(): number;
155+
151156
/*
152157
* LS host can optionally implement this method if it wants to be completely in charge of module name resolution.
153158
* if implementation is omitted then language service will use built-in module resolution logic and get answers to

tests/baselines/reference/assignmentTypeNarrowing_BACKUP_22380.types

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)