Skip to content

Commit a2d2f5a

Browse files
committed
Merge branch 'master' into complexRestParameterTypes
2 parents 9f4ae5f + f67d7e0 commit a2d2f5a

File tree

216 files changed

+43138
-32270
lines changed

Some content is hidden

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

216 files changed

+43138
-32270
lines changed

src/compiler/checker.ts

+219-156
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,11 @@ namespace ts {
815815
}
816816

817817
function getOptionNameMap(): OptionNameMap {
818-
if (optionNameMapCache) {
819-
return optionNameMapCache;
820-
}
818+
return optionNameMapCache || (optionNameMapCache = createOptionNameMap(optionDeclarations));
819+
}
821820

821+
/*@internal*/
822+
export function createOptionNameMap(optionDeclarations: ReadonlyArray<CommandLineOption>): OptionNameMap {
822823
const optionNameMap = createMap<CommandLineOption>();
823824
const shortOptionNames = createMap<string>();
824825
forEach(optionDeclarations, option => {
@@ -828,8 +829,7 @@ namespace ts {
828829
}
829830
});
830831

831-
optionNameMapCache = { optionNameMap, shortOptionNames };
832-
return optionNameMapCache;
832+
return { optionNameMap, shortOptionNames };
833833
}
834834

835835
/* @internal */
@@ -979,7 +979,12 @@ namespace ts {
979979
}
980980

981981
/** @internal */
982-
export function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
982+
export function getOptionFromName(optionName: string, allowShort?: boolean): CommandLineOption | undefined {
983+
return getOptionDeclarationFromName(getOptionNameMap, optionName, allowShort);
984+
}
985+
986+
/*@internal*/
987+
export function getOptionDeclarationFromName(getOptionNameMap: () => OptionNameMap, optionName: string, allowShort = false): CommandLineOption | undefined {
983988
optionName = optionName.toLowerCase();
984989
const { optionNameMap, shortOptionNames } = getOptionNameMap();
985990
// Try to translate short option names to their full equivalents.

src/compiler/diagnosticMessages.json

+5
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,11 @@
28962896
"category": "Error",
28972897
"code": 5071
28982898
},
2899+
"Unknown build option '{0}'.": {
2900+
"category": "Error",
2901+
"code": 5072
2902+
},
2903+
28992904

29002905
"Generates a sourcemap for each corresponding '.d.ts' file.": {
29012906
"category": "Message",

src/compiler/moduleSpecifiers.ts

+105-94
Large diffs are not rendered by default.

src/compiler/parser.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ namespace ts {
515515
performance.mark("beforeParse");
516516
let result: SourceFile;
517517
if (languageVersion === ScriptTarget.JSON) {
518-
result = Parser.parseJsonText(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes);
518+
result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON);
519519
}
520520
else {
521521
result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind);
@@ -689,8 +689,12 @@ namespace ts {
689689
if (scriptKind === ScriptKind.JSON) {
690690
const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes);
691691
convertToObjectWorker(result, result.parseDiagnostics, /*returnValue*/ false, /*knownRootOptions*/ undefined, /*jsonConversionNotifier*/ undefined);
692+
result.referencedFiles = emptyArray;
692693
result.typeReferenceDirectives = emptyArray;
694+
result.libReferenceDirectives = emptyArray;
693695
result.amdDependencies = emptyArray;
696+
result.hasNoDefaultLib = false;
697+
result.pragmas = emptyMap;
694698
return result;
695699
}
696700

@@ -7754,7 +7758,6 @@ namespace ts {
77547758
}
77557759
}
77567760

7757-
/*@internal*/
77587761
type PragmaDiagnosticReporter = (pos: number, length: number, message: DiagnosticMessage) => void;
77597762

77607763
/*@internal*/

src/compiler/program.ts

+37-42
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,24 @@ namespace ts {
6767
}
6868

6969
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
70+
return createCompilerHostWorker(options, setParentNodes);
71+
}
72+
/*@internal*/
73+
// TODO(shkamat): update this after reworking ts build API
74+
export function createCompilerHostWorker(options: CompilerOptions, setParentNodes?: boolean, system = sys): CompilerHost {
7075
const existingDirectories = createMap<boolean>();
7176

7277
function getCanonicalFileName(fileName: string): string {
7378
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
7479
// otherwise use toLowerCase as a canonical form.
75-
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
80+
return system.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
7681
}
7782

7883
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile | undefined {
7984
let text: string | undefined;
8085
try {
8186
performance.mark("beforeIORead");
82-
text = sys.readFile(fileName, options.charset);
87+
text = system.readFile(fileName, options.charset);
8388
performance.mark("afterIORead");
8489
performance.measure("I/O Read", "beforeIORead", "afterIORead");
8590
}
@@ -97,7 +102,7 @@ namespace ts {
97102
if (existingDirectories.has(directoryPath)) {
98103
return true;
99104
}
100-
if (sys.directoryExists(directoryPath)) {
105+
if (system.directoryExists(directoryPath)) {
101106
existingDirectories.set(directoryPath, true);
102107
return true;
103108
}
@@ -108,7 +113,7 @@ namespace ts {
108113
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
109114
const parentDirectory = getDirectoryPath(directoryPath);
110115
ensureDirectoriesExist(parentDirectory);
111-
sys.createDirectory(directoryPath);
116+
system.createDirectory(directoryPath);
112117
}
113118
}
114119

@@ -119,8 +124,8 @@ namespace ts {
119124
outputFingerprints = createMap<OutputFingerprint>();
120125
}
121126

122-
const hash = sys.createHash!(data); // TODO: GH#18217
123-
const mtimeBefore = sys.getModifiedTime!(fileName); // TODO: GH#18217
127+
const hash = system.createHash!(data); // TODO: GH#18217
128+
const mtimeBefore = system.getModifiedTime!(fileName); // TODO: GH#18217
124129

125130
if (mtimeBefore) {
126131
const fingerprint = outputFingerprints.get(fileName);
@@ -133,9 +138,9 @@ namespace ts {
133138
}
134139
}
135140

136-
sys.writeFile(fileName, data, writeByteOrderMark);
141+
system.writeFile(fileName, data, writeByteOrderMark);
137142

138-
const mtimeAfter = sys.getModifiedTime!(fileName) || missingFileModifiedTime; // TODO: GH#18217
143+
const mtimeAfter = system.getModifiedTime!(fileName) || missingFileModifiedTime; // TODO: GH#18217
139144

140145
outputFingerprints.set(fileName, {
141146
hash,
@@ -149,11 +154,11 @@ namespace ts {
149154
performance.mark("beforeIOWrite");
150155
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
151156

152-
if (isWatchSet(options) && sys.createHash && sys.getModifiedTime) {
157+
if (isWatchSet(options) && system.createHash && system.getModifiedTime) {
153158
writeFileIfUpdated(fileName, data, writeByteOrderMark);
154159
}
155160
else {
156-
sys.writeFile(fileName, data, writeByteOrderMark);
161+
system.writeFile(fileName, data, writeByteOrderMark);
157162
}
158163

159164
performance.mark("afterIOWrite");
@@ -167,32 +172,29 @@ namespace ts {
167172
}
168173

169174
function getDefaultLibLocation(): string {
170-
return getDirectoryPath(normalizePath(sys.getExecutingFilePath()));
175+
return getDirectoryPath(normalizePath(system.getExecutingFilePath()));
171176
}
172177

173-
const newLine = getNewLineCharacter(options);
174-
const realpath = sys.realpath && ((path: string) => sys.realpath!(path));
178+
const newLine = getNewLineCharacter(options, () => system.newLine);
179+
const realpath = system.realpath && ((path: string) => system.realpath!(path));
175180

176181
return {
177182
getSourceFile,
178183
getDefaultLibLocation,
179184
getDefaultLibFileName: options => combinePaths(getDefaultLibLocation(), getDefaultLibFileName(options)),
180185
writeFile,
181-
getCurrentDirectory: memoize(() => sys.getCurrentDirectory()),
182-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
186+
getCurrentDirectory: memoize(() => system.getCurrentDirectory()),
187+
useCaseSensitiveFileNames: () => system.useCaseSensitiveFileNames,
183188
getCanonicalFileName,
184189
getNewLine: () => newLine,
185-
fileExists: fileName => sys.fileExists(fileName),
186-
readFile: fileName => sys.readFile(fileName),
187-
trace: (s: string) => sys.write(s + newLine),
188-
directoryExists: directoryName => sys.directoryExists(directoryName),
189-
getEnvironmentVariable: name => sys.getEnvironmentVariable ? sys.getEnvironmentVariable(name) : "",
190-
getDirectories: (path: string) => sys.getDirectories(path),
190+
fileExists: fileName => system.fileExists(fileName),
191+
readFile: fileName => system.readFile(fileName),
192+
trace: (s: string) => system.write(s + newLine),
193+
directoryExists: directoryName => system.directoryExists(directoryName),
194+
getEnvironmentVariable: name => system.getEnvironmentVariable ? system.getEnvironmentVariable(name) : "",
195+
getDirectories: (path: string) => system.getDirectories(path),
191196
realpath,
192-
readDirectory: (path, extensions, include, exclude, depth) => sys.readDirectory(path, extensions, include, exclude, depth),
193-
getModifiedTime: sys.getModifiedTime && (path => sys.getModifiedTime!(path)),
194-
setModifiedTime: sys.setModifiedTime && ((path, date) => sys.setModifiedTime!(path, date)),
195-
deleteFile: sys.deleteFile && (path => sys.deleteFile!(path))
197+
readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth)
196198
};
197199
}
198200

@@ -2319,27 +2321,20 @@ namespace ts {
23192321
}
23202322

23212323
function computeCommonSourceDirectory(sourceFiles: SourceFile[]): string {
2322-
const fileNames: string[] = [];
2323-
for (const file of sourceFiles) {
2324-
if (!file.isDeclarationFile) {
2325-
fileNames.push(file.fileName);
2326-
}
2327-
}
2324+
const fileNames = mapDefined(sourceFiles, file => file.isDeclarationFile ? undefined : file.fileName);
23282325
return computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, getCanonicalFileName);
23292326
}
23302327

2331-
function checkSourceFilesBelongToPath(sourceFiles: SourceFile[], rootDirectory: string): boolean {
2328+
function checkSourceFilesBelongToPath(sourceFiles: ReadonlyArray<SourceFile>, rootDirectory: string): boolean {
23322329
let allFilesBelongToPath = true;
2333-
if (sourceFiles) {
2334-
const absoluteRootDirectoryPath = host.getCanonicalFileName(getNormalizedAbsolutePath(rootDirectory, currentDirectory));
2335-
2336-
for (const sourceFile of sourceFiles) {
2337-
if (!sourceFile.isDeclarationFile) {
2338-
const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
2339-
if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
2340-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, rootDirectory));
2341-
allFilesBelongToPath = false;
2342-
}
2330+
const absoluteRootDirectoryPath = host.getCanonicalFileName(getNormalizedAbsolutePath(rootDirectory, currentDirectory));
2331+
2332+
for (const sourceFile of sourceFiles) {
2333+
if (!sourceFile.isDeclarationFile) {
2334+
const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
2335+
if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
2336+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, rootDirectory));
2337+
allFilesBelongToPath = false;
23432338
}
23442339
}
23452340
}

src/compiler/transformers/declarations.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ namespace ts {
971971
}
972972
case SyntaxKind.FunctionDeclaration: {
973973
// Generators lose their generator-ness, excepting their return type
974-
return cleanup(updateFunctionDeclaration(
974+
const clean = cleanup(updateFunctionDeclaration(
975975
input,
976976
/*decorators*/ undefined,
977977
ensureModifiers(input, isPrivate),
@@ -982,6 +982,21 @@ namespace ts {
982982
ensureType(input, input.type),
983983
/*body*/ undefined
984984
));
985+
if (clean && resolver.isJSContainerFunctionDeclaration(input)) {
986+
const declarations = mapDefined(resolver.getPropertiesOfContainerFunction(input), p => {
987+
if (!isPropertyAccessExpression(p.valueDeclaration)) {
988+
return undefined;
989+
}
990+
const type = resolver.createTypeOfDeclaration(p.valueDeclaration, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker);
991+
const varDecl = createVariableDeclaration(unescapeLeadingUnderscores(p.escapedName), type, /*initializer*/ undefined);
992+
return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([varDecl]));
993+
});
994+
const namespaceDecl = createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input, isPrivate), input.name!, createModuleBlock(declarations), NodeFlags.Namespace);
995+
return [clean, namespaceDecl];
996+
}
997+
else {
998+
return clean;
999+
}
9851000
}
9861001
case SyntaxKind.ModuleDeclaration: {
9871002
needsDeclare = false;

0 commit comments

Comments
 (0)