From bf42f5bd1c84b075eefa2af032d9c686ace39cc9 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 20 Jan 2019 12:12:19 +0800 Subject: [PATCH 1/8] avoid add missing member in declaration file --- src/services/codefixes/fixAddMissingMember.ts | 9 +++++++-- .../fourslash/addMemberInDeclarationFile.ts | 17 +++++++++++++++++ .../addMemberNotInNodeModulesDeclarationFile.ts | 13 +++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/addMemberInDeclarationFile.ts create mode 100644 tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 98ddee61f8e8d..5272b57418377 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -113,6 +113,11 @@ namespace ts.codefix { } type Info = EnumInfo | ClassOrInterfaceInfo; + function isInNodeModulesDeclarationFile(node: Node) { + const sourceFile = getSourceFileOfNode(node); + return sourceFile.isDeclarationFile && startsWith(sourceFile.resolvedPath, "node_modules/") || sourceFile.resolvedPath.indexOf("/node_modules/") !== -1; + } + function getInfo(tokenSourceFile: SourceFile, tokenPos: number, checker: TypeChecker): Info | undefined { // The identifier of the missing property. eg: // this.missing = 1; @@ -131,7 +136,7 @@ namespace ts.codefix { // Prefer to change the class instead of the interface if they are merged const classOrInterface = find(symbol.declarations, isClassLike) || find(symbol.declarations, isInterfaceDeclaration); - if (classOrInterface) { + if (classOrInterface && !isInNodeModulesDeclarationFile(classOrInterface)) { const makeStatic = ((leftExpressionType as TypeReference).target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol); const declSourceFile = classOrInterface.getSourceFile(); const inJs = isSourceFileJS(declSourceFile); @@ -139,7 +144,7 @@ namespace ts.codefix { return { kind: InfoKind.ClassOrInterface, token, parentDeclaration: classOrInterface, makeStatic, declSourceFile, inJs, call }; } const enumDeclaration = find(symbol.declarations, isEnumDeclaration); - if (enumDeclaration) { + if (enumDeclaration && !isInNodeModulesDeclarationFile(enumDeclaration)) { return { kind: InfoKind.Enum, token, parentDeclaration: enumDeclaration }; } return undefined; diff --git a/tests/cases/fourslash/addMemberInDeclarationFile.ts b/tests/cases/fourslash/addMemberInDeclarationFile.ts new file mode 100644 index 0000000000000..1d2e900512db8 --- /dev/null +++ b/tests/cases/fourslash/addMemberInDeclarationFile.ts @@ -0,0 +1,17 @@ +/// + +// @Filename: ./declarations.d.ts +//// interface Response {} + +// @Filename: foo.ts +//// import './declarations.d.ts' +//// declare const resp: Response +//// resp.test() + +goTo.file('foo.ts') + +verify.codeFixAvailable([ + { description: "Declare method 'test'" }, + { description: "Declare property 'test'" }, + { description: "Add index signature for property 'test'" } +]) diff --git a/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts b/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts new file mode 100644 index 0000000000000..efdbf3214bca2 --- /dev/null +++ b/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts @@ -0,0 +1,13 @@ +/// + +// @Filename: /node_modules/foo/declarations.d.ts +//// interface Response {} + +// @Filename: foo.ts +//// import '/node_modules/foo/declarations.d.ts' +//// declare const resp: Response +//// resp.test() + +goTo.file('foo.ts') + +verify.not.codeFixAvailable() From 09747e5c35a89d5911093d65e409e554dc8bed2f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 20 Mar 2019 13:59:12 -0700 Subject: [PATCH 2/8] Add test for current --incremental behaviour --- .../unittests/config/commandLineParsing.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/testRunner/unittests/config/commandLineParsing.ts b/src/testRunner/unittests/config/commandLineParsing.ts index 26a49df3dbb15..c5a6c9a486927 100644 --- a/src/testRunner/unittests/config/commandLineParsing.ts +++ b/src/testRunner/unittests/config/commandLineParsing.ts @@ -365,6 +365,23 @@ namespace ts { } }); }); + + it("parse --incremental", () => { + // --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, + }], + fileNames: ["0.ts"], + options: {} + }); + }); }); describe("unittests:: config:: commandLineParsing:: parseBuildOptions", () => { @@ -456,6 +473,23 @@ namespace ts { }); }); + it("parse build with --incremental ", () => { + // --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, + }], + projects: ["tests"], + buildOptions: { } + }); + }); + describe("Combining options that make no sense together", () => { function verifyInvalidCombination(flag1: keyof BuildOptions, flag2: keyof BuildOptions) { it(`--${flag1} and --${flag2} together is invalid`, () => { From 34c3233d1837d654632df772d28fd191ed3f180b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 20 Mar 2019 14:44:14 -0700 Subject: [PATCH 3/8] Allow --incremental to be command line option --- src/compiler/commandLineParser.ts | 14 ++++++------ src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/program.ts | 4 ++++ src/compiler/tsbuild.ts | 3 ++- .../unittests/config/commandLineParsing.ts | 22 ++++--------------- .../reference/invalidIncremental.errors.txt | 8 +++++++ .../baselines/reference/invalidIncremental.js | 7 ++++++ .../reference/invalidIncremental.symbols | 5 +++++ .../reference/invalidIncremental.types | 6 +++++ .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- tests/cases/compiler/invalidIncremental.ts | 4 ++++ 19 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 tests/baselines/reference/invalidIncremental.errors.txt create mode 100644 tests/baselines/reference/invalidIncremental.js create mode 100644 tests/baselines/reference/invalidIncremental.symbols create mode 100644 tests/baselines/reference/invalidIncremental.types create mode 100644 tests/cases/compiler/invalidIncremental.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3c4b0577fb664..a200ebf67e01b 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 9ae3e1ca77eae..acc9a437ca137 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 979423cdfaad0..2d8c4d5e4c3bb 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 cc79c02f1d69e..16e6e42272ea9 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 c5a6c9a486927..33716841b7949 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 0000000000000..6b6382e8f2e5d --- /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 0000000000000..4798b1d4fa3b6 --- /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 0000000000000..840f3d765367c --- /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 0000000000000..2035b6fa749ff --- /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 ec795e83e23d3..8e4ff5171868d 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 b931fe1745a65..7332496971fba 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 6a437fd4c14b5..ebf7070cfa4d4 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 d1d8d42c433ad..25f9b39967a8d 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 c2bcb1307c1fb..fc1fb8ec631d8 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 37c1960d80d36..dcff85de986d4 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 ec795e83e23d3..8e4ff5171868d 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 bc24243c11f5c..112be7a95f953 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 1c16ed114165f..4c4b740a12284 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 0000000000000..4a7c3e72de96e --- /dev/null +++ b/tests/cases/compiler/invalidIncremental.ts @@ -0,0 +1,4 @@ +// @incremental: true + +const x = 10; + From 722afc18bbcf7265df98ea35a91e1725ad53a6ce Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 21 Mar 2019 09:01:52 -0700 Subject: [PATCH 4/8] Fix typo --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 2 +- tests/baselines/reference/invalidIncremental.errors.txt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index acc9a437ca137..6638d2c409a1d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3072,7 +3072,7 @@ "category": "Error", "code": 5073 }, - "Option '--incremental' can only be speicified when using tsconfig.": { + "Option '--incremental' can only be specified when using tsconfig.": { "category": "Error", "code": 5074 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2d8c4d5e4c3bb..b65c8c0431cb0 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2723,7 +2723,7 @@ namespace ts { } if (options.incremental && !options.configFilePath) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_speicified_when_using_tsconfig)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_when_using_tsconfig)); } if (options.composite) { diff --git a/tests/baselines/reference/invalidIncremental.errors.txt b/tests/baselines/reference/invalidIncremental.errors.txt index 6b6382e8f2e5d..cdd19e67093f5 100644 --- a/tests/baselines/reference/invalidIncremental.errors.txt +++ b/tests/baselines/reference/invalidIncremental.errors.txt @@ -1,7 +1,7 @@ -error TS5074: Option '--incremental' can only be speicified when using tsconfig. +error TS5074: Option '--incremental' can only be specified when using tsconfig. -!!! error TS5074: Option '--incremental' can only be speicified when using tsconfig. +!!! error TS5074: Option '--incremental' can only be specified when using tsconfig. ==== tests/cases/compiler/invalidIncremental.ts (0 errors) ==== const x = 10; From 35470b3f3bdde41a4d975b84a5f8d40853b05952 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 25 Mar 2019 12:37:55 -0700 Subject: [PATCH 5/8] Make tsbuildInfoFile as commandline option to tsc (and not tsc -b) --- src/compiler/builder.ts | 6 ++-- src/compiler/commandLineParser.ts | 1 - src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 3 +- src/compiler/program.ts | 16 ++++++---- .../unittests/config/commandLineParsing.ts | 29 ++++++++++++++++++- src/tsc/tsc.ts | 27 ++++++----------- .../baselines/reference/incrementalConfig.js | 6 ++++ .../reference/incrementalConfig.symbols | 4 +++ .../reference/incrementalConfig.types | 5 ++++ .../reference/incrementalInvalid.errors.txt | 8 +++++ .../baselines/reference/incrementalInvalid.js | 7 +++++ .../reference/incrementalInvalid.symbols | 5 ++++ .../reference/incrementalInvalid.types | 6 ++++ tests/baselines/reference/incrementalOut.js | 7 +++++ .../reference/incrementalOut.symbols | 5 ++++ .../baselines/reference/incrementalOut.types | 6 ++++ .../reference/invalidIncremental.errors.txt | 8 ----- .../baselines/reference/invalidIncremental.js | 7 ----- .../reference/invalidIncremental.symbols | 5 ---- .../reference/invalidIncremental.types | 6 ---- tests/cases/compiler/incrementalConfig.ts | 8 +++++ ...idIncremental.ts => incrementalInvalid.ts} | 0 tests/cases/compiler/incrementalOut.ts | 5 ++++ 24 files changed, 125 insertions(+), 57 deletions(-) create mode 100644 tests/baselines/reference/incrementalConfig.js create mode 100644 tests/baselines/reference/incrementalConfig.symbols create mode 100644 tests/baselines/reference/incrementalConfig.types create mode 100644 tests/baselines/reference/incrementalInvalid.errors.txt create mode 100644 tests/baselines/reference/incrementalInvalid.js create mode 100644 tests/baselines/reference/incrementalInvalid.symbols create mode 100644 tests/baselines/reference/incrementalInvalid.types create mode 100644 tests/baselines/reference/incrementalOut.js create mode 100644 tests/baselines/reference/incrementalOut.symbols create mode 100644 tests/baselines/reference/incrementalOut.types delete mode 100644 tests/baselines/reference/invalidIncremental.errors.txt delete mode 100644 tests/baselines/reference/invalidIncremental.js delete mode 100644 tests/baselines/reference/invalidIncremental.symbols delete mode 100644 tests/baselines/reference/invalidIncremental.types create mode 100644 tests/cases/compiler/incrementalConfig.ts rename tests/cases/compiler/{invalidIncremental.ts => incrementalInvalid.ts} (100%) create mode 100644 tests/cases/compiler/incrementalOut.ts diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index faf51568241f5..f72f30b226cab 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -792,7 +792,7 @@ namespace ts { state, // When whole program is affected, do emit only once (eg when --out or --outFile is specified) // Otherwise just affected file - affected.emitBuildInfo(writeFile || host.writeFile, cancellationToken), + affected.emitBuildInfo(writeFile || maybeBind(host, host.writeFile), cancellationToken), affected, /*isPendingEmitFile*/ false, /*isBuildInfoEmit*/ true @@ -820,7 +820,7 @@ namespace ts { state, // When whole program is affected, do emit only once (eg when --out or --outFile is specified) // Otherwise just affected file - Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || host.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers), + Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers), affected, isPendingEmitFile ); @@ -862,7 +862,7 @@ namespace ts { }; } } - return Debug.assertDefined(state.program).emit(targetSourceFile, writeFile || host.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers); + return Debug.assertDefined(state.program).emit(targetSourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers); } /** diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index a200ebf67e01b..12a20e0df42e1 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -343,7 +343,6 @@ namespace ts { type: "string", isFilePath: true, paramType: Diagnostics.FILE, - isTSConfigOnly: true, category: Diagnostics.Basic_Options, description: Diagnostics.Specify_file_to_store_incremental_compilation_information, }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6638d2c409a1d..6cb498df8279e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3072,7 +3072,7 @@ "category": "Error", "code": 5073 }, - "Option '--incremental' can only be specified when using tsconfig.": { + "Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified.": { "category": "Error", "code": 5074 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index be867db68fb77..8f91e3d25c163 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -54,7 +54,7 @@ namespace ts { /*@internal*/ export function getOutputPathForBuildInfo(options: CompilerOptions) { const configFile = options.configFilePath; - if (!configFile || !isIncrementalCompilation(options)) return undefined; + if (!isIncrementalCompilation(options)) return undefined; if (options.tsBuildInfoFile) return options.tsBuildInfoFile; const outPath = options.outFile || options.out; let buildInfoExtensionLess: string; @@ -62,6 +62,7 @@ namespace ts { buildInfoExtensionLess = removeFileExtension(outPath); } else { + if (!configFile) return undefined; const configFileExtensionLess = removeFileExtension(configFile); buildInfoExtensionLess = options.outDir ? options.rootDir ? diff --git a/src/compiler/program.ts b/src/compiler/program.ts index b65c8c0431cb0..5bace99aa53d1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -198,7 +198,8 @@ namespace ts { getDirectories: (path: string) => system.getDirectories(path), realpath, readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth), - createDirectory: d => system.createDirectory(d) + createDirectory: d => system.createDirectory(d), + createHash: maybeBind(system, system.createHash) }; return compilerHost; } @@ -320,7 +321,10 @@ namespace ts { }; } - export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray { + // tslint:disable unified-signatures + export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; + /*@internal*/ export function getPreEmitDiagnostics(program: BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; + export function getPreEmitDiagnostics(program: Program | BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray { const diagnostics = [ ...program.getConfigFileParsingDiagnostics(), ...program.getOptionsDiagnostics(cancellationToken), @@ -335,6 +339,7 @@ namespace ts { return sortAndDeduplicateDiagnostics(diagnostics); } + // tslint:enable unified-signatures export interface FormatDiagnosticsHost { getCurrentDirectory(): string; @@ -2722,10 +2727,6 @@ 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_specified_when_using_tsconfig)); - } - if (options.composite) { if (options.declaration === false) { createDiagnosticForOptionName(Diagnostics.Composite_projects_may_not_disable_declaration_emit, "declaration"); @@ -2740,6 +2741,9 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "tsBuildInfoFile", "incremental", "composite"); } } + else if (options.incremental && !options.outFile && !options.out && !options.configFilePath) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified)); + } verifyProjectReferences(); diff --git a/src/testRunner/unittests/config/commandLineParsing.ts b/src/testRunner/unittests/config/commandLineParsing.ts index 33716841b7949..ccb2378c644a8 100644 --- a/src/testRunner/unittests/config/commandLineParsing.ts +++ b/src/testRunner/unittests/config/commandLineParsing.ts @@ -375,6 +375,16 @@ namespace ts { options: { incremental: true } }); }); + + it("parse --tsBuildInfoFile", () => { + // --lib es6 0.ts + assertParseResult(["--tsBuildInfoFile", "build.tsbuildinfo", "0.ts"], + { + errors: [], + fileNames: ["0.ts"], + options: { tsBuildInfoFile: "build.tsbuildinfo" } + }); + }); }); describe("unittests:: config:: commandLineParsing:: parseBuildOptions", () => { @@ -466,7 +476,7 @@ namespace ts { }); }); - it("parse build with --incremental ", () => { + it("parse build with --incremental", () => { // --lib es6 0.ts assertParseResult(["--incremental", "tests"], { @@ -476,6 +486,23 @@ namespace ts { }); }); + it("parse build with --tsBuildInfoFile", () => { + // --lib es6 0.ts + assertParseResult(["--tsBuildInfoFile", "build.tsbuildinfo", "tests"], + { + errors: [{ + messageText: "Unknown build option '--tsBuildInfoFile'.", + category: Diagnostics.Unknown_build_option_0.category, + code: Diagnostics.Unknown_build_option_0.code, + file: undefined, + start: undefined, + length: undefined + }], + projects: ["build.tsbuildinfo", "tests"], + buildOptions: { } + }); + }); + describe("Combining options that make no sense together", () => { function verifyInvalidCombination(flag1: keyof BuildOptions, flag2: keyof BuildOptions) { it(`--${flag1} and --${flag2} together is invalid`, () => { diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index 499848fdf923a..b8ee7e3c8d19b 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -165,6 +165,9 @@ namespace ts { reportWatchModeWithoutSysSupport(); createWatchOfFilesAndCompilerOptions(commandLine.fileNames, commandLineOptions); } + else if (isIncrementalCompilation(commandLineOptions)) { + performIncrementalCompilation(commandLine); + } else { performCompilation(commandLine.fileNames, /*references*/ undefined, commandLineOptions); } @@ -265,34 +268,22 @@ namespace ts { const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames()); changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, currentDirectory, getCanonicalFileName)); enableStatistics(options); - const oldProgram = readBuilderProgram(options, path => host.readFile(path)); const configFileParsingDiagnostics = getConfigFileParsingDiagnostics(config); - const programOptions: CreateProgramOptions = { - rootNames: fileNames, + const builderProgram = createEmitAndSemanticDiagnosticsBuilderProgram( + fileNames, options, - projectReferences, host, - configFileParsingDiagnostics: getConfigFileParsingDiagnostics(config), - }; - const program = createProgram(programOptions); - const builderProgram = createEmitAndSemanticDiagnosticsBuilderProgram( - program, - { - useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames, - createHash: maybeBind(sys, sys.createHash), - writeFile: (path, data, writeByteOrderMark) => sys.writeFile(path, data, writeByteOrderMark) - }, - oldProgram, - configFileParsingDiagnostics + readBuilderProgram(options, path => host.readFile(path)), + configFileParsingDiagnostics, + projectReferences ); - const exitStatus = emitFilesAndReportErrors( builderProgram, reportDiagnostic, s => sys.write(s + sys.newLine), createReportErrorSummary(options) ); - reportStatistics(program); + reportStatistics(builderProgram.getProgram()); return sys.exit(exitStatus); } diff --git a/tests/baselines/reference/incrementalConfig.js b/tests/baselines/reference/incrementalConfig.js new file mode 100644 index 0000000000000..b90c65b9f0901 --- /dev/null +++ b/tests/baselines/reference/incrementalConfig.js @@ -0,0 +1,6 @@ +//// [a.ts] +const x = 10; + + +//// [a.js] +var x = 10; diff --git a/tests/baselines/reference/incrementalConfig.symbols b/tests/baselines/reference/incrementalConfig.symbols new file mode 100644 index 0000000000000..05c35bcf58a68 --- /dev/null +++ b/tests/baselines/reference/incrementalConfig.symbols @@ -0,0 +1,4 @@ +=== /a.ts === +const x = 10; +>x : Symbol(x, Decl(a.ts, 0, 5)) + diff --git a/tests/baselines/reference/incrementalConfig.types b/tests/baselines/reference/incrementalConfig.types new file mode 100644 index 0000000000000..ed892fed2ba10 --- /dev/null +++ b/tests/baselines/reference/incrementalConfig.types @@ -0,0 +1,5 @@ +=== /a.ts === +const x = 10; +>x : 10 +>10 : 10 + diff --git a/tests/baselines/reference/incrementalInvalid.errors.txt b/tests/baselines/reference/incrementalInvalid.errors.txt new file mode 100644 index 0000000000000..6c88c5fc9d35f --- /dev/null +++ b/tests/baselines/reference/incrementalInvalid.errors.txt @@ -0,0 +1,8 @@ +error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified. + + +!!! error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified. +==== tests/cases/compiler/incrementalInvalid.ts (0 errors) ==== + const x = 10; + + \ No newline at end of file diff --git a/tests/baselines/reference/incrementalInvalid.js b/tests/baselines/reference/incrementalInvalid.js new file mode 100644 index 0000000000000..6ca4b1b2dada7 --- /dev/null +++ b/tests/baselines/reference/incrementalInvalid.js @@ -0,0 +1,7 @@ +//// [incrementalInvalid.ts] +const x = 10; + + + +//// [incrementalInvalid.js] +var x = 10; diff --git a/tests/baselines/reference/incrementalInvalid.symbols b/tests/baselines/reference/incrementalInvalid.symbols new file mode 100644 index 0000000000000..7a75ad5da9d2d --- /dev/null +++ b/tests/baselines/reference/incrementalInvalid.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/incrementalInvalid.ts === +const x = 10; +>x : Symbol(x, Decl(incrementalInvalid.ts, 0, 5)) + + diff --git a/tests/baselines/reference/incrementalInvalid.types b/tests/baselines/reference/incrementalInvalid.types new file mode 100644 index 0000000000000..90e391222dd4b --- /dev/null +++ b/tests/baselines/reference/incrementalInvalid.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/incrementalInvalid.ts === +const x = 10; +>x : 10 +>10 : 10 + + diff --git a/tests/baselines/reference/incrementalOut.js b/tests/baselines/reference/incrementalOut.js new file mode 100644 index 0000000000000..af73fb45a2209 --- /dev/null +++ b/tests/baselines/reference/incrementalOut.js @@ -0,0 +1,7 @@ +//// [incrementalOut.ts] +const x = 10; + + + +//// [output.js] +var x = 10; diff --git a/tests/baselines/reference/incrementalOut.symbols b/tests/baselines/reference/incrementalOut.symbols new file mode 100644 index 0000000000000..6ad1a4d76ee79 --- /dev/null +++ b/tests/baselines/reference/incrementalOut.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/incrementalOut.ts === +const x = 10; +>x : Symbol(x, Decl(incrementalOut.ts, 0, 5)) + + diff --git a/tests/baselines/reference/incrementalOut.types b/tests/baselines/reference/incrementalOut.types new file mode 100644 index 0000000000000..55b02107adf34 --- /dev/null +++ b/tests/baselines/reference/incrementalOut.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/incrementalOut.ts === +const x = 10; +>x : 10 +>10 : 10 + + diff --git a/tests/baselines/reference/invalidIncremental.errors.txt b/tests/baselines/reference/invalidIncremental.errors.txt deleted file mode 100644 index cdd19e67093f5..0000000000000 --- a/tests/baselines/reference/invalidIncremental.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -error TS5074: Option '--incremental' can only be specified when using tsconfig. - - -!!! error TS5074: Option '--incremental' can only be specified 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 deleted file mode 100644 index 4798b1d4fa3b6..0000000000000 --- a/tests/baselines/reference/invalidIncremental.js +++ /dev/null @@ -1,7 +0,0 @@ -//// [invalidIncremental.ts] -const x = 10; - - - -//// [invalidIncremental.js] -var x = 10; diff --git a/tests/baselines/reference/invalidIncremental.symbols b/tests/baselines/reference/invalidIncremental.symbols deleted file mode 100644 index 840f3d765367c..0000000000000 --- a/tests/baselines/reference/invalidIncremental.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== 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 deleted file mode 100644 index 2035b6fa749ff..0000000000000 --- a/tests/baselines/reference/invalidIncremental.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/invalidIncremental.ts === -const x = 10; ->x : 10 ->10 : 10 - - diff --git a/tests/cases/compiler/incrementalConfig.ts b/tests/cases/compiler/incrementalConfig.ts new file mode 100644 index 0000000000000..6ed172c837a68 --- /dev/null +++ b/tests/cases/compiler/incrementalConfig.ts @@ -0,0 +1,8 @@ +// @incremental: true + +// @Filename: /a.ts +const x = 10; + +// @Filename: /tsconfig.json +{ } + diff --git a/tests/cases/compiler/invalidIncremental.ts b/tests/cases/compiler/incrementalInvalid.ts similarity index 100% rename from tests/cases/compiler/invalidIncremental.ts rename to tests/cases/compiler/incrementalInvalid.ts diff --git a/tests/cases/compiler/incrementalOut.ts b/tests/cases/compiler/incrementalOut.ts new file mode 100644 index 0000000000000..4cd49dbba112d --- /dev/null +++ b/tests/cases/compiler/incrementalOut.ts @@ -0,0 +1,5 @@ +// @incremental: true +// @out: output.js + +const x = 10; + From 6deb9cdfc717ef6c2176172fb6eacf263c042f0a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 26 Mar 2019 16:03:06 -0700 Subject: [PATCH 6/8] Add test for incremental with --tsbuildinfo file without specifying --out or config --- tests/baselines/reference/incrementalTsBuildInfoFile.js | 8 ++++++++ .../reference/incrementalTsBuildInfoFile.symbols | 6 ++++++ .../baselines/reference/incrementalTsBuildInfoFile.types | 7 +++++++ tests/cases/compiler/incrementalTsBuildInfoFile.ts | 8 ++++++++ 4 files changed, 29 insertions(+) create mode 100644 tests/baselines/reference/incrementalTsBuildInfoFile.js create mode 100644 tests/baselines/reference/incrementalTsBuildInfoFile.symbols create mode 100644 tests/baselines/reference/incrementalTsBuildInfoFile.types create mode 100644 tests/cases/compiler/incrementalTsBuildInfoFile.ts diff --git a/tests/baselines/reference/incrementalTsBuildInfoFile.js b/tests/baselines/reference/incrementalTsBuildInfoFile.js new file mode 100644 index 0000000000000..cdb778d8dd551 --- /dev/null +++ b/tests/baselines/reference/incrementalTsBuildInfoFile.js @@ -0,0 +1,8 @@ +//// [a.ts] +const x = 10; + + + + +//// [a.js] +var x = 10; diff --git a/tests/baselines/reference/incrementalTsBuildInfoFile.symbols b/tests/baselines/reference/incrementalTsBuildInfoFile.symbols new file mode 100644 index 0000000000000..d596c6006d7ee --- /dev/null +++ b/tests/baselines/reference/incrementalTsBuildInfoFile.symbols @@ -0,0 +1,6 @@ +=== /a.ts === +const x = 10; +>x : Symbol(x, Decl(a.ts, 0, 5)) + + + diff --git a/tests/baselines/reference/incrementalTsBuildInfoFile.types b/tests/baselines/reference/incrementalTsBuildInfoFile.types new file mode 100644 index 0000000000000..ab563af0e56a8 --- /dev/null +++ b/tests/baselines/reference/incrementalTsBuildInfoFile.types @@ -0,0 +1,7 @@ +=== /a.ts === +const x = 10; +>x : 10 +>10 : 10 + + + diff --git a/tests/cases/compiler/incrementalTsBuildInfoFile.ts b/tests/cases/compiler/incrementalTsBuildInfoFile.ts new file mode 100644 index 0000000000000..51a9661187cb6 --- /dev/null +++ b/tests/cases/compiler/incrementalTsBuildInfoFile.ts @@ -0,0 +1,8 @@ +// @incremental: true +// @tsBuildInfoFile: /a.tsbuildinfo + + +// @Filename: /a.ts +const x = 10; + + From 9050d0fdf832b621ccc2643b829541c4d80282b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Wed, 27 Mar 2019 19:06:21 +0800 Subject: [PATCH 7/8] update external files api --- src/services/codefixes/fixAddMissingMember.ts | 15 +++++---------- .../addMemberNotInNodeModulesDeclarationFile.ts | 14 ++++++++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 5272b57418377..843d22554ed87 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -12,7 +12,7 @@ namespace ts.codefix { registerCodeFix({ errorCodes, getCodeActions(context) { - const info = getInfo(context.sourceFile, context.span.start, context.program.getTypeChecker()); + const info = getInfo(context.sourceFile, context.span.start, context.program.getTypeChecker(), context.program); if (!info) return undefined; if (info.kind === InfoKind.Enum) { @@ -37,7 +37,7 @@ namespace ts.codefix { return createCombinedCodeActions(textChanges.ChangeTracker.with(context, changes => { eachDiagnostic(context, errorCodes, diag => { - const info = getInfo(diag.file, diag.start, checker); + const info = getInfo(diag.file, diag.start, checker, context.program); if (!info || !addToSeen(seen, getNodeId(info.parentDeclaration) + "#" + info.token.text)) { return; } @@ -113,12 +113,7 @@ namespace ts.codefix { } type Info = EnumInfo | ClassOrInterfaceInfo; - function isInNodeModulesDeclarationFile(node: Node) { - const sourceFile = getSourceFileOfNode(node); - return sourceFile.isDeclarationFile && startsWith(sourceFile.resolvedPath, "node_modules/") || sourceFile.resolvedPath.indexOf("/node_modules/") !== -1; - } - - function getInfo(tokenSourceFile: SourceFile, tokenPos: number, checker: TypeChecker): Info | undefined { + function getInfo(tokenSourceFile: SourceFile, tokenPos: number, checker: TypeChecker, program: Program): Info | undefined { // The identifier of the missing property. eg: // this.missing = 1; // ^^^^^^^ @@ -136,7 +131,7 @@ namespace ts.codefix { // Prefer to change the class instead of the interface if they are merged const classOrInterface = find(symbol.declarations, isClassLike) || find(symbol.declarations, isInterfaceDeclaration); - if (classOrInterface && !isInNodeModulesDeclarationFile(classOrInterface)) { + if (classOrInterface && !program.isSourceFileFromExternalLibrary(classOrInterface.getSourceFile())) { const makeStatic = ((leftExpressionType as TypeReference).target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol); const declSourceFile = classOrInterface.getSourceFile(); const inJs = isSourceFileJS(declSourceFile); @@ -144,7 +139,7 @@ namespace ts.codefix { return { kind: InfoKind.ClassOrInterface, token, parentDeclaration: classOrInterface, makeStatic, declSourceFile, inJs, call }; } const enumDeclaration = find(symbol.declarations, isEnumDeclaration); - if (enumDeclaration && !isInNodeModulesDeclarationFile(enumDeclaration)) { + if (enumDeclaration && !program.isSourceFileFromExternalLibrary(enumDeclaration.getSourceFile())) { return { kind: InfoKind.Enum, token, parentDeclaration: enumDeclaration }; } return undefined; diff --git a/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts b/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts index efdbf3214bca2..3a97aeac6dd84 100644 --- a/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts +++ b/tests/cases/fourslash/addMemberNotInNodeModulesDeclarationFile.ts @@ -1,13 +1,19 @@ /// -// @Filename: /node_modules/foo/declarations.d.ts +// @noImplicitReferences: true +// @traceResolution: true + +// @Filename: /node_modules/foo/types.d.ts //// interface Response {} -// @Filename: foo.ts -//// import '/node_modules/foo/declarations.d.ts' +// @Filename: /node_modules/foo/package.json +//// { "types": "types.d.ts" } + +// @Filename: /foo.ts +//// import { Response } from 'foo' //// declare const resp: Response //// resp.test() -goTo.file('foo.ts') +goTo.file('/foo.ts') verify.not.codeFixAvailable() From cf8b3085118bb38540bb8c50032746f2cd244cc2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 29 Mar 2019 14:40:46 -0700 Subject: [PATCH 8/8] Add test for out file concat where command line --incremental flag changes between compilation --- src/testRunner/unittests/tsbuild/outFile.ts | 47 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/testRunner/unittests/tsbuild/outFile.ts b/src/testRunner/unittests/tsbuild/outFile.ts index 5328806565835..48beeef4f61da 100644 --- a/src/testRunner/unittests/tsbuild/outFile.ts +++ b/src/testRunner/unittests/tsbuild/outFile.ts @@ -197,8 +197,8 @@ namespace ts { dtsUnchangedExpectedReadFilesDependOrdered = undefined!; }); - function createSolutionBuilder(host: fakes.SolutionBuilderHost) { - return ts.createSolutionBuilder(host, ["/src/third"], { dry: false, force: false, verbose: true }); + function createSolutionBuilder(host: fakes.SolutionBuilderHost, baseOptions?: BuildOptions) { + return ts.createSolutionBuilder(host, ["/src/third"], { dry: false, force: false, verbose: true, ...(baseOptions || {}) }); } function getInitialExpectedReadFiles(additionalSourceFiles?: ReadonlyArray) { @@ -446,6 +446,49 @@ namespace ts { ); }); + it("rebuilds completely when command line incremental flag changes between non dts changes", () => { + const fs = outFileFs.shadow(); + // Make non composite third project + replaceText(fs, sources[project.third][source.config], `"composite": true,`, ""); + + // Build with command line incremental + const host = new fakes.SolutionBuilderHost(fs); + const builder = createSolutionBuilder(host, { incremental: true }); + builder.buildAllProjects(); + host.assertDiagnosticMessages(...initialExpectedDiagnostics); + host.clearDiagnostics(); + tick(); + + // Make non incremental build with change in file that doesnt affect dts + appendText(fs, relSources[project.first][source.ts][part.one], "console.log(s);"); + builder.resetBuildContext({ verbose: true }); + builder.buildAllProjects(); + host.assertDiagnosticMessages(getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]), + [Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, relSources[project.first][source.config], relOutputFiles[project.first][ext.js], relSources[project.first][source.ts][part.one]], + [Diagnostics.Building_project_0, sources[project.first][source.config]], + [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, relSources[project.second][source.config], relSources[project.second][source.ts][part.one], relOutputFiles[project.second][ext.js]], + [Diagnostics.Project_0_is_out_of_date_because_output_of_its_dependency_1_has_changed, relSources[project.third][source.config], "src/first"], + [Diagnostics.Building_project_0, sources[project.third][source.config]] + ); + host.clearDiagnostics(); + tick(); + + // Make incremental build with change in file that doesnt affect dts + appendText(fs, relSources[project.first][source.ts][part.one], "console.log(s);"); + builder.resetBuildContext({ verbose: true, incremental: true }); + builder.buildAllProjects(); + // Builds completely because tsbuildinfo is old. + host.assertDiagnosticMessages( + getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]), + [Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, relSources[project.first][source.config], relOutputFiles[project.first][ext.js], relSources[project.first][source.ts][part.one]], + [Diagnostics.Building_project_0, sources[project.first][source.config]], + [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, relSources[project.second][source.config], relSources[project.second][source.ts][part.one], relOutputFiles[project.second][ext.js]], + [Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, relSources[project.third][source.config], relOutputFiles[project.third][ext.buildinfo], "src/first"], + [Diagnostics.Building_project_0, sources[project.third][source.config]] + ); + host.clearDiagnostics(); + }); + describe("Prepend output with .tsbuildinfo", () => { // Prologues describe("Prologues", () => {