Skip to content

Commit

Permalink
Merge branch 'master' into libReference
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed May 9, 2018
2 parents 6c35abe + 6f9dc2f commit 7d5c1bc
Show file tree
Hide file tree
Showing 200 changed files with 3,947 additions and 1,327 deletions.
172 changes: 100 additions & 72 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

105 changes: 100 additions & 5 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ namespace ts {
category: Diagnostics.Basic_Options,
description: Diagnostics.Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
},
{
name: "composite",
type: "boolean",
isTSConfigOnly: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Enable_project_compilation,
},
{
name: "removeComments",
type: "boolean",
Expand Down Expand Up @@ -827,12 +834,14 @@ namespace ts {
export function parseCommandLine(commandLine: ReadonlyArray<string>, readFile?: (path: string) => string | undefined): ParsedCommandLine {
const options: CompilerOptions = {};
const fileNames: string[] = [];
const projectReferences: ProjectReference[] | undefined = undefined;
const errors: Diagnostic[] = [];

parseStrings(commandLine);
return {
options,
fileNames,
projectReferences,
errors
};

Expand Down Expand Up @@ -946,6 +955,49 @@ namespace ts {
return optionNameMap.get(optionName);
}


export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
/**
* Reports config file diagnostics
*/
export interface ConfigFileDiagnosticsReporter {
/**
* Reports unrecoverable error when parsing config file
*/
onUnRecoverableConfigFileDiagnostic: DiagnosticReporter;
}

/**
* Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors
*/
export interface ParseConfigFileHost extends ParseConfigHost, ConfigFileDiagnosticsReporter {
getCurrentDirectory(): string;
}

/**
* Reads the config file, reports errors if any and exits if the config file cannot be found
*/
export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined {
let configFileText: string;
try {
configFileText = host.readFile(configFileName);
}
catch (e) {
const error = createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, configFileName, e.message);
host.onUnRecoverableConfigFileDiagnostic(error);
return undefined;
}
if (!configFileText) {
const error = createCompilerDiagnostic(Diagnostics.File_0_not_found, configFileName);
host.onUnRecoverableConfigFileDiagnostic(error);
return undefined;
}

const result = parseJsonText(configFileName, configFileText);
const cwd = host.getCurrentDirectory();
return parseJsonSourceFileConfigFileContent(result, host, getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd), optionsToExtend, getNormalizedAbsolutePath(configFileName, cwd));
}

/**
* Read tsconfig.json file
* @param fileName The path to the config file
Expand Down Expand Up @@ -1021,6 +1073,14 @@ namespace ts {
name: "extends",
type: "string"
},
{
name: "references",
type: "list",
element: {
name: "references",
type: "object"
}
},
{
name: "files",
type: "list",
Expand Down Expand Up @@ -1428,7 +1488,7 @@ namespace ts {
for (let i = 0; i < nameColumn.length; i++) {
const optionName = nameColumn[i];
const description = descriptionColumn[i];
result.push(optionName && `${tab}${tab}${optionName}${ description && (makePadding(marginLength - optionName.length + 2) + description)}`);
result.push(optionName && `${tab}${tab}${optionName}${description && (makePadding(marginLength - optionName.length + 2) + description)}`);
}
if (fileNames.length) {
result.push(`${tab}},`);
Expand Down Expand Up @@ -1512,12 +1572,13 @@ namespace ts {
const parsedConfig = parseConfig(json, sourceFile, host, basePath, configFileName, resolutionStack, errors);
const { raw } = parsedConfig;
const options = extend(existingOptions, parsedConfig.options || {});
options.configFilePath = configFileName;
options.configFilePath = configFileName && normalizeSlashes(configFileName);
setConfigFileInOptions(options, sourceFile);
const { fileNames, wildcardDirectories, spec } = getFileNames();
const { fileNames, wildcardDirectories, spec, projectReferences } = getFileNames();
return {
options,
fileNames,
projectReferences,
typeAcquisition: parsedConfig.typeAcquisition || getDefaultTypeAcquisition(),
raw,
errors,
Expand Down Expand Up @@ -1571,10 +1632,33 @@ namespace ts {
}

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

if (hasProperty(raw, "references") && !isNullOrUndefined(raw.references)) {
if (isArray(raw.references)) {
const references: ProjectReference[] = [];
for (const ref of raw.references) {
if (typeof ref.path !== "string") {
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "reference.path", "string");
}
else {
references.push({
path: getNormalizedAbsolutePath(ref.path, basePath),
originalPath: ref.path,
prepend: ref.prepend,
circular: ref.circular
});
}
}
result.projectReferences = references;
}
else {
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "references", "Array");
}
}

return result;
}

Expand Down Expand Up @@ -1863,6 +1947,9 @@ namespace ts {

const options = getDefaultCompilerOptions(configFileName);
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
if (configFileName) {
options.configFilePath = normalizeSlashes(configFileName);
}
return options;
}

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

const spec: ConfigFileSpecs = { filesSpecs, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories };
const spec: ConfigFileSpecs = { filesSpecs, referencesSpecs: undefined, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories };
return getFileNamesFromConfigSpecs(spec, basePath, options, host, extraFileExtensions);
}

Expand Down Expand Up @@ -2132,8 +2219,16 @@ namespace ts {

const literalFiles = arrayFrom(literalFileMap.values());
const wildcardFiles = arrayFrom(wildcardFileMap.values());
const projectReferences = spec.referencesSpecs && spec.referencesSpecs.map((r): ProjectReference => {
return {
...r,
path: getNormalizedAbsolutePath(r.path, basePath)
};
});

return {
fileNames: literalFiles.concat(wildcardFiles),
projectReferences,
wildcardDirectories,
spec
};
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,10 @@ namespace ts {
: moduleKind === ModuleKind.System;
}

export function getEmitDeclarations(compilerOptions: CompilerOptions): boolean {
return !!(compilerOptions.declaration || compilerOptions.composite);
}

export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | "alwaysStrict";

export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
Expand Down Expand Up @@ -2328,6 +2332,7 @@ namespace ts {
const reduced = [components[0]];
for (let i = 1; i < components.length; i++) {
const component = components[i];
if (!component) continue;
if (component === ".") continue;
if (component === "..") {
if (reduced.length > 1) {
Expand Down
48 changes: 47 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@
"category": "Error",
"code": 1322
},
"Dynamic import cannot be used when targeting ECMAScript 2015 modules.": {
"Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.": {
"category": "Error",
"code": 1323
},
Expand Down Expand Up @@ -3559,6 +3559,48 @@
"category": "Message",
"code": 6197
},
"All destructured elements are unused.": {
"category": "Error",
"code": 6198,
"reportsUnnecessary": true
},

"Projects to reference": {
"category": "Message",
"code": 6300
},
"Enable project compilation": {
"category": "Message",
"code": 6302
},
"Project references may not form a circular graph. Cycle detected: {0}": {
"category": "Error",
"code": 6202
},
"Composite projects may not disable declaration emit.": {
"category": "Error",
"code": 6304
},
"Output file '{0}' has not been built from source file '{1}'.": {
"category": "Error",
"code": 6305
},
"Referenced project '{0}' must have setting \"composite\": true.": {
"category": "Error",
"code": 6306
},
"File '{0}' is not in project file list. Projects must list all files or use an 'include' pattern.": {
"category": "Error",
"code": 6307
},
"Cannot prepend project '{0}' because it does not have 'outFile' set": {
"category": "Error",
"code": 6308
},
"Output file '{0}' from project '{1}' does not exist": {
"category": "Error",
"code": 6309
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
Expand Down Expand Up @@ -3956,6 +3998,10 @@
"category": "Message",
"code": 90008
},
"Remove destructuring": {
"category": "Message",
"code": 90009
},
"Import '{0}' from module \"{1}\"": {
"category": "Message",
"code": 90013
Expand Down
Loading

0 comments on commit 7d5c1bc

Please sign in to comment.