diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3c4b0577fb6..a200ebf67e0 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -136,6 +136,13 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.Show_verbose_diagnostic_information }, + { + name: "incremental", + shortName: "i", + type: "boolean", + category: Diagnostics.Basic_Options, + description: Diagnostics.Enable_incremental_compilation, + }, ]; /* @internal */ @@ -331,13 +338,6 @@ namespace ts { category: Diagnostics.Basic_Options, description: Diagnostics.Enable_project_compilation, }, - { - name: "incremental", - type: "boolean", - isTSConfigOnly: true, - category: Diagnostics.Basic_Options, - description: Diagnostics.Enable_incremental_compilation, - }, { name: "tsBuildInfoFile", type: "string", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9ae3e1ca77e..acc9a437ca1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3072,6 +3072,10 @@ "category": "Error", "code": 5073 }, + "Option '--incremental' can only be speicified when using tsconfig.": { + "category": "Error", + "code": 5074 + }, "Generates a sourcemap for each corresponding '.d.ts' file.": { "category": "Message", diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 979423cdfaa..2d8c4d5e4c3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2722,6 +2722,10 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_paths_cannot_be_used_without_specifying_baseUrl_option, "paths"); } + if (options.incremental && !options.configFilePath) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_speicified_when_using_tsconfig)); + } + if (options.composite) { if (options.declaration === false) { createDiagnosticForOptionName(Diagnostics.Composite_projects_may_not_disable_declaration_emit, "declaration"); diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index cc79c02f1d6..16e6e42272e 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -30,6 +30,7 @@ namespace ts { listEmittedFiles?: boolean; listFiles?: boolean; pretty?: boolean; + incremental?: boolean; traceResolution?: boolean; /* @internal */ diagnostics?: boolean; @@ -363,7 +364,7 @@ namespace ts { function getCompilerOptionsOfBuildOptions(buildOptions: BuildOptions): CompilerOptions { const result = {} as CompilerOptions; commonOptionsWithBuild.forEach(option => { - result[option.name] = buildOptions[option.name]; + if (hasProperty(buildOptions, option.name)) result[option.name] = buildOptions[option.name]; }); return result; } diff --git a/src/testRunner/unittests/config/commandLineParsing.ts b/src/testRunner/unittests/config/commandLineParsing.ts index c5a6c9a4869..33716841b79 100644 --- a/src/testRunner/unittests/config/commandLineParsing.ts +++ b/src/testRunner/unittests/config/commandLineParsing.ts @@ -370,16 +370,9 @@ namespace ts { // --lib es6 0.ts assertParseResult(["--incremental", "0.ts"], { - errors: [{ - messageText: "Option 'incremental' can only be specified in 'tsconfig.json' file.", - category: Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file.category, - code: Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file.code, - file: undefined, - start: undefined, - length: undefined, - }], + errors: [], fileNames: ["0.ts"], - options: {} + options: { incremental: true } }); }); }); @@ -477,16 +470,9 @@ namespace ts { // --lib es6 0.ts assertParseResult(["--incremental", "tests"], { - errors: [{ - messageText: "Unknown build option '--incremental'.", - category: Diagnostics.Unknown_build_option_0.category, - code: Diagnostics.Unknown_build_option_0.code, - file: undefined, - start: undefined, - length: undefined, - }], + errors: [], projects: ["tests"], - buildOptions: { } + buildOptions: { incremental: true } }); }); diff --git a/tests/baselines/reference/invalidIncremental.errors.txt b/tests/baselines/reference/invalidIncremental.errors.txt new file mode 100644 index 00000000000..6b6382e8f2e --- /dev/null +++ b/tests/baselines/reference/invalidIncremental.errors.txt @@ -0,0 +1,8 @@ +error TS5074: Option '--incremental' can only be speicified when using tsconfig. + + +!!! error TS5074: Option '--incremental' can only be speicified when using tsconfig. +==== tests/cases/compiler/invalidIncremental.ts (0 errors) ==== + const x = 10; + + \ No newline at end of file diff --git a/tests/baselines/reference/invalidIncremental.js b/tests/baselines/reference/invalidIncremental.js new file mode 100644 index 00000000000..4798b1d4fa3 --- /dev/null +++ b/tests/baselines/reference/invalidIncremental.js @@ -0,0 +1,7 @@ +//// [invalidIncremental.ts] +const x = 10; + + + +//// [invalidIncremental.js] +var x = 10; diff --git a/tests/baselines/reference/invalidIncremental.symbols b/tests/baselines/reference/invalidIncremental.symbols new file mode 100644 index 00000000000..840f3d76536 --- /dev/null +++ b/tests/baselines/reference/invalidIncremental.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/invalidIncremental.ts === +const x = 10; +>x : Symbol(x, Decl(invalidIncremental.ts, 0, 5)) + + diff --git a/tests/baselines/reference/invalidIncremental.types b/tests/baselines/reference/invalidIncremental.types new file mode 100644 index 00000000000..2035b6fa749 --- /dev/null +++ b/tests/baselines/reference/invalidIncremental.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/invalidIncremental.ts === +const x = 10; +>x : 10 +>10 : 10 + + diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index ec795e83e23..8e4ff517186 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json index b931fe1745a..7332496971f 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 6a437fd4c14..ebf7070cfa4 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index d1d8d42c433..25f9b39967a 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index c2bcb1307c1..fc1fb8ec631 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 37c1960d80d..dcff85de986 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["es5","es2015.promise"], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index ec795e83e23..8e4ff517186 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index bc24243c11f..112be7a95f9 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["es5","es2015.core"], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 1c16ed11416..4c4b740a122 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ @@ -14,7 +15,6 @@ // "outDir": "./", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "incremental": true, /* Enable incremental compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ diff --git a/tests/cases/compiler/invalidIncremental.ts b/tests/cases/compiler/invalidIncremental.ts new file mode 100644 index 00000000000..4a7c3e72de9 --- /dev/null +++ b/tests/cases/compiler/invalidIncremental.ts @@ -0,0 +1,4 @@ +// @incremental: true + +const x = 10; +