Skip to content

Commit 99cb2ad

Browse files
committed
Merge branch 'master' into libReference
2 parents 6c35abe + 6f9dc2f commit 99cb2ad

File tree

200 files changed

+3947
-1327
lines changed

Some content is hidden

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

200 files changed

+3947
-1327
lines changed

src/compiler/checker.ts

+100-72
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+100-5
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ namespace ts {
248248
category: Diagnostics.Basic_Options,
249249
description: Diagnostics.Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
250250
},
251+
{
252+
name: "composite",
253+
type: "boolean",
254+
isTSConfigOnly: true,
255+
category: Diagnostics.Basic_Options,
256+
description: Diagnostics.Enable_project_compilation,
257+
},
251258
{
252259
name: "removeComments",
253260
type: "boolean",
@@ -827,12 +834,14 @@ namespace ts {
827834
export function parseCommandLine(commandLine: ReadonlyArray<string>, readFile?: (path: string) => string | undefined): ParsedCommandLine {
828835
const options: CompilerOptions = {};
829836
const fileNames: string[] = [];
837+
const projectReferences: ProjectReference[] | undefined = undefined;
830838
const errors: Diagnostic[] = [];
831839

832840
parseStrings(commandLine);
833841
return {
834842
options,
835843
fileNames,
844+
projectReferences,
836845
errors
837846
};
838847

@@ -946,6 +955,49 @@ namespace ts {
946955
return optionNameMap.get(optionName);
947956
}
948957

958+
959+
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
960+
/**
961+
* Reports config file diagnostics
962+
*/
963+
export interface ConfigFileDiagnosticsReporter {
964+
/**
965+
* Reports unrecoverable error when parsing config file
966+
*/
967+
onUnRecoverableConfigFileDiagnostic: DiagnosticReporter;
968+
}
969+
970+
/**
971+
* Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors
972+
*/
973+
export interface ParseConfigFileHost extends ParseConfigHost, ConfigFileDiagnosticsReporter {
974+
getCurrentDirectory(): string;
975+
}
976+
977+
/**
978+
* Reads the config file, reports errors if any and exits if the config file cannot be found
979+
*/
980+
export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined {
981+
let configFileText: string;
982+
try {
983+
configFileText = host.readFile(configFileName);
984+
}
985+
catch (e) {
986+
const error = createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, configFileName, e.message);
987+
host.onUnRecoverableConfigFileDiagnostic(error);
988+
return undefined;
989+
}
990+
if (!configFileText) {
991+
const error = createCompilerDiagnostic(Diagnostics.File_0_not_found, configFileName);
992+
host.onUnRecoverableConfigFileDiagnostic(error);
993+
return undefined;
994+
}
995+
996+
const result = parseJsonText(configFileName, configFileText);
997+
const cwd = host.getCurrentDirectory();
998+
return parseJsonSourceFileConfigFileContent(result, host, getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd), optionsToExtend, getNormalizedAbsolutePath(configFileName, cwd));
999+
}
1000+
9491001
/**
9501002
* Read tsconfig.json file
9511003
* @param fileName The path to the config file
@@ -1021,6 +1073,14 @@ namespace ts {
10211073
name: "extends",
10221074
type: "string"
10231075
},
1076+
{
1077+
name: "references",
1078+
type: "list",
1079+
element: {
1080+
name: "references",
1081+
type: "object"
1082+
}
1083+
},
10241084
{
10251085
name: "files",
10261086
type: "list",
@@ -1428,7 +1488,7 @@ namespace ts {
14281488
for (let i = 0; i < nameColumn.length; i++) {
14291489
const optionName = nameColumn[i];
14301490
const description = descriptionColumn[i];
1431-
result.push(optionName && `${tab}${tab}${optionName}${ description && (makePadding(marginLength - optionName.length + 2) + description)}`);
1491+
result.push(optionName && `${tab}${tab}${optionName}${description && (makePadding(marginLength - optionName.length + 2) + description)}`);
14321492
}
14331493
if (fileNames.length) {
14341494
result.push(`${tab}},`);
@@ -1512,12 +1572,13 @@ namespace ts {
15121572
const parsedConfig = parseConfig(json, sourceFile, host, basePath, configFileName, resolutionStack, errors);
15131573
const { raw } = parsedConfig;
15141574
const options = extend(existingOptions, parsedConfig.options || {});
1515-
options.configFilePath = configFileName;
1575+
options.configFilePath = configFileName && normalizeSlashes(configFileName);
15161576
setConfigFileInOptions(options, sourceFile);
1517-
const { fileNames, wildcardDirectories, spec } = getFileNames();
1577+
const { fileNames, wildcardDirectories, spec, projectReferences } = getFileNames();
15181578
return {
15191579
options,
15201580
fileNames,
1581+
projectReferences,
15211582
typeAcquisition: parsedConfig.typeAcquisition || getDefaultTypeAcquisition(),
15221583
raw,
15231584
errors,
@@ -1571,10 +1632,33 @@ namespace ts {
15711632
}
15721633

15731634
const result = matchFileNames(filesSpecs, includeSpecs, excludeSpecs, configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath, options, host, errors, extraFileExtensions, sourceFile);
1574-
if (result.fileNames.length === 0 && !hasProperty(raw, "files") && resolutionStack.length === 0) {
1635+
if (result.fileNames.length === 0 && !hasProperty(raw, "files") && resolutionStack.length === 0 && !hasProperty(raw, "references")) {
15751636
errors.push(getErrorForNoInputFiles(result.spec, configFileName));
15761637
}
15771638

1639+
if (hasProperty(raw, "references") && !isNullOrUndefined(raw.references)) {
1640+
if (isArray(raw.references)) {
1641+
const references: ProjectReference[] = [];
1642+
for (const ref of raw.references) {
1643+
if (typeof ref.path !== "string") {
1644+
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "reference.path", "string");
1645+
}
1646+
else {
1647+
references.push({
1648+
path: getNormalizedAbsolutePath(ref.path, basePath),
1649+
originalPath: ref.path,
1650+
prepend: ref.prepend,
1651+
circular: ref.circular
1652+
});
1653+
}
1654+
}
1655+
result.projectReferences = references;
1656+
}
1657+
else {
1658+
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "references", "Array");
1659+
}
1660+
}
1661+
15781662
return result;
15791663
}
15801664

@@ -1863,6 +1947,9 @@ namespace ts {
18631947

18641948
const options = getDefaultCompilerOptions(configFileName);
18651949
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
1950+
if (configFileName) {
1951+
options.configFilePath = normalizeSlashes(configFileName);
1952+
}
18661953
return options;
18671954
}
18681955

@@ -2061,7 +2148,7 @@ namespace ts {
20612148
// new entries in these paths.
20622149
const wildcardDirectories = getWildcardDirectories(validatedIncludeSpecs, validatedExcludeSpecs, basePath, host.useCaseSensitiveFileNames);
20632150

2064-
const spec: ConfigFileSpecs = { filesSpecs, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories };
2151+
const spec: ConfigFileSpecs = { filesSpecs, referencesSpecs: undefined, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories };
20652152
return getFileNamesFromConfigSpecs(spec, basePath, options, host, extraFileExtensions);
20662153
}
20672154

@@ -2132,8 +2219,16 @@ namespace ts {
21322219

21332220
const literalFiles = arrayFrom(literalFileMap.values());
21342221
const wildcardFiles = arrayFrom(wildcardFileMap.values());
2222+
const projectReferences = spec.referencesSpecs && spec.referencesSpecs.map((r): ProjectReference => {
2223+
return {
2224+
...r,
2225+
path: getNormalizedAbsolutePath(r.path, basePath)
2226+
};
2227+
});
2228+
21352229
return {
21362230
fileNames: literalFiles.concat(wildcardFiles),
2231+
projectReferences,
21372232
wildcardDirectories,
21382233
spec
21392234
};

src/compiler/core.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,10 @@ namespace ts {
20682068
: moduleKind === ModuleKind.System;
20692069
}
20702070

2071+
export function getEmitDeclarations(compilerOptions: CompilerOptions): boolean {
2072+
return !!(compilerOptions.declaration || compilerOptions.composite);
2073+
}
2074+
20712075
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | "alwaysStrict";
20722076

20732077
export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
@@ -2328,6 +2332,7 @@ namespace ts {
23282332
const reduced = [components[0]];
23292333
for (let i = 1; i < components.length; i++) {
23302334
const component = components[i];
2335+
if (!component) continue;
23312336
if (component === ".") continue;
23322337
if (component === "..") {
23332338
if (reduced.length > 1) {

src/compiler/diagnosticMessages.json

+47-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@
895895
"category": "Error",
896896
"code": 1322
897897
},
898-
"Dynamic import cannot be used when targeting ECMAScript 2015 modules.": {
898+
"Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.": {
899899
"category": "Error",
900900
"code": 1323
901901
},
@@ -3559,6 +3559,48 @@
35593559
"category": "Message",
35603560
"code": 6197
35613561
},
3562+
"All destructured elements are unused.": {
3563+
"category": "Error",
3564+
"code": 6198,
3565+
"reportsUnnecessary": true
3566+
},
3567+
3568+
"Projects to reference": {
3569+
"category": "Message",
3570+
"code": 6300
3571+
},
3572+
"Enable project compilation": {
3573+
"category": "Message",
3574+
"code": 6302
3575+
},
3576+
"Project references may not form a circular graph. Cycle detected: {0}": {
3577+
"category": "Error",
3578+
"code": 6202
3579+
},
3580+
"Composite projects may not disable declaration emit.": {
3581+
"category": "Error",
3582+
"code": 6304
3583+
},
3584+
"Output file '{0}' has not been built from source file '{1}'.": {
3585+
"category": "Error",
3586+
"code": 6305
3587+
},
3588+
"Referenced project '{0}' must have setting \"composite\": true.": {
3589+
"category": "Error",
3590+
"code": 6306
3591+
},
3592+
"File '{0}' is not in project file list. Projects must list all files or use an 'include' pattern.": {
3593+
"category": "Error",
3594+
"code": 6307
3595+
},
3596+
"Cannot prepend project '{0}' because it does not have 'outFile' set": {
3597+
"category": "Error",
3598+
"code": 6308
3599+
},
3600+
"Output file '{0}' from project '{1}' does not exist": {
3601+
"category": "Error",
3602+
"code": 6309
3603+
},
35623604

35633605
"Variable '{0}' implicitly has an '{1}' type.": {
35643606
"category": "Error",
@@ -3956,6 +3998,10 @@
39563998
"category": "Message",
39573999
"code": 90008
39584000
},
4001+
"Remove destructuring": {
4002+
"category": "Message",
4003+
"code": 90009
4004+
},
39594005
"Import '{0}' from module \"{1}\"": {
39604006
"category": "Message",
39614007
"code": 90013

0 commit comments

Comments
 (0)