Skip to content

Commit 55fc62b

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map5
2 parents 8dbb8e7 + 7c5c664 commit 55fc62b

41 files changed

Lines changed: 2674 additions & 869 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ var harnessSources = harnessCoreSources.concat([
250250
"convertToBase64.ts",
251251
"transpile.ts",
252252
"reuseProgramStructure.ts",
253+
"textStorage.ts",
253254
"cachingInServerLSHost.ts",
254255
"moduleResolution.ts",
255256
"tsconfigParsing.ts",

src/compiler/checker.ts

Lines changed: 119 additions & 53 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ namespace ts {
840840
* @param basePath A root directory to resolve relative path entries in the config
841841
* file to. e.g. outDir
842842
*/
843-
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = []): ParsedCommandLine {
843+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], extraFileExtensions: FileExtensionInfo[] = []): ParsedCommandLine {
844844
const errors: Diagnostic[] = [];
845845
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
846846
const resolvedPath = toPath(configFileName || "", basePath, getCanonicalFileName);
@@ -980,7 +980,7 @@ namespace ts {
980980
includeSpecs = ["**/*"];
981981
}
982982

983-
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors);
983+
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors, extraFileExtensions);
984984

985985
if (result.fileNames.length === 0 && !hasProperty(json, "files") && resolutionStack.length === 0) {
986986
errors.push(
@@ -1185,7 +1185,7 @@ namespace ts {
11851185
* @param host The host used to resolve files and directories.
11861186
* @param errors An array for diagnostic reporting.
11871187
*/
1188-
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[]): ExpandResult {
1188+
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], extraFileExtensions: FileExtensionInfo[]): ExpandResult {
11891189
basePath = normalizePath(basePath);
11901190

11911191
// The exclude spec list is converted into a regular expression, which allows us to quickly
@@ -1219,7 +1219,7 @@ namespace ts {
12191219

12201220
// Rather than requery this for each file and filespec, we query the supported extensions
12211221
// once and store it on the expansion context.
1222-
const supportedExtensions = getSupportedExtensions(options);
1222+
const supportedExtensions = getSupportedExtensions(options, extraFileExtensions);
12231223

12241224
// Literal files are always included verbatim. An "include" or "exclude" specification cannot
12251225
// remove a literal file.

src/compiler/core.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,8 +2032,18 @@ namespace ts {
20322032
export const supportedJavascriptExtensions = [".js", ".jsx"];
20332033
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
20342034

2035-
export function getSupportedExtensions(options?: CompilerOptions): string[] {
2036-
return options && options.allowJs ? allSupportedExtensions : supportedTypeScriptExtensions;
2035+
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: FileExtensionInfo[]): string[] {
2036+
const needAllExtensions = options && options.allowJs;
2037+
if (!extraFileExtensions || extraFileExtensions.length === 0) {
2038+
return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
2039+
}
2040+
const extensions = (needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions).slice(0);
2041+
for (const extInfo of extraFileExtensions) {
2042+
if (needAllExtensions || extInfo.scriptKind === ScriptKind.TS) {
2043+
extensions.push(extInfo.extension);
2044+
}
2045+
}
2046+
return extensions;
20372047
}
20382048

20392049
export function hasJavaScriptFileExtension(fileName: string) {
@@ -2044,10 +2054,10 @@ namespace ts {
20442054
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
20452055
}
20462056

2047-
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) {
2057+
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, extraFileExtensions?: FileExtensionInfo[]) {
20482058
if (!fileName) { return false; }
20492059

2050-
for (const extension of getSupportedExtensions(compilerOptions)) {
2060+
for (const extension of getSupportedExtensions(compilerOptions, extraFileExtensions)) {
20512061
if (fileExtensionIs(fileName, extension)) {
20522062
return true;
20532063
}

src/compiler/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,7 @@ namespace ts {
29482948
typeParameter?: TypeParameter;
29492949
constraintType?: Type;
29502950
templateType?: Type;
2951+
modifiersType?: Type;
29512952
mapper?: TypeMapper; // Instantiation mapper
29522953
}
29532954

@@ -2983,6 +2984,8 @@ namespace ts {
29832984
}
29842985

29852986
export interface TypeVariable extends Type {
2987+
/* @internal */
2988+
resolvedApparentType: Type;
29862989
/* @internal */
29872990
resolvedIndexType: IndexType;
29882991
}
@@ -2995,8 +2998,6 @@ namespace ts {
29952998
/* @internal */
29962999
mapper?: TypeMapper; // Instantiation mapper
29973000
/* @internal */
2998-
resolvedApparentType: Type;
2999-
/* @internal */
30003001
isThisType?: boolean;
30013002
}
30023003

@@ -3005,6 +3006,7 @@ namespace ts {
30053006
export interface IndexedAccessType extends TypeVariable {
30063007
objectType: Type;
30073008
indexType: Type;
3009+
constraint?: Type;
30083010
}
30093011

30103012
// keyof T types (TypeFlags.Index)
@@ -3101,6 +3103,12 @@ namespace ts {
31013103
ThisProperty
31023104
}
31033105

3106+
export interface FileExtensionInfo {
3107+
extension: string;
3108+
scriptKind: ScriptKind;
3109+
isMixedContent: boolean;
3110+
}
3111+
31043112
export interface DiagnosticMessage {
31053113
key: string;
31063114
category: DiagnosticCategory;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/// <reference path="../harness.ts" />
2+
/// <reference path="../../server/scriptVersionCache.ts"/>
3+
/// <reference path="./tsserverProjectSystem.ts" />
4+
5+
namespace ts.textStorage {
6+
describe("Text storage", () => {
7+
const f = {
8+
path: "/a/app.ts",
9+
content: `
10+
let x = 1;
11+
let y = 2;
12+
function bar(a: number) {
13+
return a + 1;
14+
}`
15+
};
16+
17+
it("text based storage should be have exactly the same as script version cache", () => {
18+
19+
const host = ts.projectSystem.createServerHost([f]);
20+
21+
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));
22+
const ts2 = new server.TextStorage(host, server.asNormalizedPath(f.path));
23+
24+
ts1.useScriptVersionCache();
25+
ts2.useText();
26+
27+
const lineMap = computeLineStarts(f.content);
28+
29+
for (let line = 0; line < lineMap.length; line++) {
30+
const start = lineMap[line];
31+
const end = line === lineMap.length - 1 ? f.path.length : lineMap[line + 1];
32+
33+
for (let offset = 0; offset < end - start; offset++) {
34+
const pos1 = ts1.lineOffsetToPosition(line + 1, offset + 1);
35+
const pos2 = ts2.lineOffsetToPosition(line + 1, offset + 1);
36+
assert.isTrue(pos1 === pos2, `lineOffsetToPosition ${line + 1}-${offset + 1}: expected ${pos1} to equal ${pos2}`);
37+
}
38+
39+
const {start: start1, length: length1 } = ts1.lineToTextSpan(line);
40+
const {start: start2, length: length2 } = ts2.lineToTextSpan(line);
41+
assert.isTrue(start1 === start2, `lineToTextSpan ${line}::start:: expected ${start1} to equal ${start2}`);
42+
assert.isTrue(length1 === length2, `lineToTextSpan ${line}::length:: expected ${length1} to equal ${length2}`);
43+
}
44+
45+
for (let pos = 0; pos < f.content.length; pos++) {
46+
const { line: line1, offset: offset1 } = ts1.positionToLineOffset(pos);
47+
const { line: line2, offset: offset2 } = ts2.positionToLineOffset(pos);
48+
assert.isTrue(line1 === line2, `positionToLineOffset ${pos}::line:: expected ${line1} to equal ${line2}`);
49+
assert.isTrue(offset1 === offset2, `positionToLineOffset ${pos}::offset:: expected ${offset1} to equal ${offset2}`);
50+
}
51+
});
52+
53+
it("should switch to script version cache if necessary", () => {
54+
const host = ts.projectSystem.createServerHost([f]);
55+
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));
56+
57+
ts1.getSnapshot();
58+
assert.isTrue(!ts1.hasScriptVersionCache(), "should not have script version cache - 1");
59+
60+
ts1.edit(0, 5, " ");
61+
assert.isTrue(ts1.hasScriptVersionCache(), "have script version cache - 1");
62+
63+
ts1.useText();
64+
assert.isTrue(!ts1.hasScriptVersionCache(), "should not have script version cache - 2");
65+
66+
ts1.getLineInfo(0);
67+
assert.isTrue(ts1.hasScriptVersionCache(), "have script version cache - 2");
68+
})
69+
});
70+
}

0 commit comments

Comments
 (0)