Skip to content

Fix transpiling when options specify incremental or tsbuildinfofile #33216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ namespace ts {
type: "boolean",
category: Diagnostics.Basic_Options,
description: Diagnostics.Enable_incremental_compilation,
transpileOptionValue: undefined
},
{
name: "locale",
Expand Down Expand Up @@ -262,7 +263,8 @@ namespace ts {
affectsModuleResolution: true,
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation,
transpileOptionValue: undefined
},
{
name: "allowJs",
Expand Down Expand Up @@ -299,6 +301,7 @@ namespace ts {
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Generates_corresponding_d_ts_file,
transpileOptionValue: undefined
},
{
name: "declarationMap",
Expand All @@ -307,13 +310,15 @@ namespace ts {
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Generates_a_sourcemap_for_each_corresponding_d_ts_file,
transpileOptionValue: undefined
},
{
name: "emitDeclarationOnly",
type: "boolean",
affectsEmit: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Only_emit_d_ts_declaration_files,
transpileOptionValue: undefined
},
{
name: "sourceMap",
Expand All @@ -332,6 +337,7 @@ namespace ts {
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
transpileOptionValue: undefined
},
{
name: "outDir",
Expand Down Expand Up @@ -359,6 +365,7 @@ namespace ts {
isTSConfigOnly: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Enable_project_compilation,
transpileOptionValue: undefined
},
{
name: "tsBuildInfoFile",
Expand All @@ -368,6 +375,7 @@ namespace ts {
paramType: Diagnostics.FILE,
category: Diagnostics.Basic_Options,
description: Diagnostics.Specify_file_to_store_incremental_compilation_information,
transpileOptionValue: undefined
},
{
name: "removeComments",
Expand All @@ -384,6 +392,7 @@ namespace ts {
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Do_not_emit_outputs,
transpileOptionValue: undefined
},
{
name: "importHelpers",
Expand All @@ -403,7 +412,8 @@ namespace ts {
name: "isolatedModules",
type: "boolean",
category: Diagnostics.Basic_Options,
description: Diagnostics.Transpile_each_file_as_a_separate_module_similar_to_ts_transpileModule
description: Diagnostics.Transpile_each_file_as_a_separate_module_similar_to_ts_transpileModule,
transpileOptionValue: true
},

// Strict Type Checks
Expand Down Expand Up @@ -540,7 +550,8 @@ namespace ts {
affectsModuleResolution: true,
isTSConfigOnly: true,
category: Diagnostics.Module_Resolution_Options,
description: Diagnostics.A_series_of_entries_which_re_map_imports_to_lookup_locations_relative_to_the_baseUrl
description: Diagnostics.A_series_of_entries_which_re_map_imports_to_lookup_locations_relative_to_the_baseUrl,
transpileOptionValue: undefined
},
{
// this option can only be specified in tsconfig.json
Expand All @@ -555,7 +566,8 @@ namespace ts {
},
affectsModuleResolution: true,
category: Diagnostics.Module_Resolution_Options,
description: Diagnostics.List_of_root_folders_whose_combined_content_represents_the_structure_of_the_project_at_runtime
description: Diagnostics.List_of_root_folders_whose_combined_content_represents_the_structure_of_the_project_at_runtime,
transpileOptionValue: undefined
},
{
name: "typeRoots",
Expand All @@ -579,7 +591,8 @@ namespace ts {
affectsModuleResolution: true,
showInSimplifiedHelpView: true,
category: Diagnostics.Module_Resolution_Options,
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation,
transpileOptionValue: undefined
},
{
name: "allowSyntheticDefaultImports",
Expand Down Expand Up @@ -680,6 +693,7 @@ namespace ts {
category: Diagnostics.Advanced_Options,
paramType: Diagnostics.FILE,
description: Diagnostics.Deprecated_Use_outFile_instead_Concatenate_and_emit_output_to_single_file,
transpileOptionValue: undefined
},
{
name: "reactNamespace",
Expand Down Expand Up @@ -729,14 +743,20 @@ namespace ts {
type: "boolean",
affectsModuleResolution: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Do_not_include_the_default_library_file_lib_d_ts
description: Diagnostics.Do_not_include_the_default_library_file_lib_d_ts,
// We are not returning a sourceFile for lib file when asked by the program,
// so pass --noLib to avoid reporting a file not found error.
transpileOptionValue: true
},
{
name: "noResolve",
type: "boolean",
affectsModuleResolution: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Do_not_add_triple_slash_references_or_imported_modules_to_the_list_of_compiled_files
description: Diagnostics.Do_not_add_triple_slash_references_or_imported_modules_to_the_list_of_compiled_files,
// We are not doing a full typecheck, we are not resolving the whole context,
// so pass --noResolve to avoid reporting missing file errors.
transpileOptionValue: true
},
{
name: "stripInternal",
Expand Down Expand Up @@ -772,6 +792,7 @@ namespace ts {
affectsEmit: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported,
transpileOptionValue: undefined
},
{
name: "preserveConstEnums",
Expand All @@ -787,7 +808,8 @@ namespace ts {
isFilePath: true,
paramType: Diagnostics.DIRECTORY,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Output_directory_for_generated_declaration_files
description: Diagnostics.Output_directory_for_generated_declaration_files,
transpileOptionValue: undefined
},
{
name: "skipLibCheck",
Expand Down Expand Up @@ -880,6 +902,10 @@ namespace ts {
export const sourceFileAffectingCompilerOptions: ReadonlyArray<CommandLineOption> = optionDeclarations.filter(option =>
!!option.affectsSourceFile || !!option.affectsModuleResolution || !!option.affectsBindDiagnostics);

/* @internal */
export const transpileOptionValueCompilerOptions: ReadonlyArray<CommandLineOption> = optionDeclarations.filter(option =>
hasProperty(option, "transpileOptionValue"));

/* @internal */
export const buildOpts: CommandLineOption[] = [
...commonOptionsWithBuild,
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4930,6 +4930,7 @@ namespace ts {
affectsBindDiagnostics?: true; // true if this affects binding (currently same effect as `affectsSourceFile`)
affectsSemanticDiagnostics?: true; // true if option affects semantic diagnostics
affectsEmit?: true; // true if the options affects emit
transpileOptionValue?: boolean | undefined; // If set this means that the option should be set to this value when transpiling
}

/* @internal */
Expand Down
25 changes: 3 additions & 22 deletions src/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,16 @@ namespace ts {
}
}

options.isolatedModules = true;
for (const option of transpileOptionValueCompilerOptions) {
options[option.name] = option.transpileOptionValue;
}

// transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.
options.suppressOutputPathCheck = true;

// Filename can be non-ts file.
options.allowNonTsExtensions = true;

// We are not returning a sourceFile for lib file when asked by the program,
// so pass --noLib to avoid reporting a file not found error.
options.noLib = true;

// Clear out other settings that would not be used in transpiling this module
options.lib = undefined;
options.types = undefined;
options.noEmit = undefined;
options.noEmitOnError = undefined;
options.paths = undefined;
options.rootDirs = undefined;
options.declaration = undefined;
options.composite = undefined;
options.declarationDir = undefined;
options.out = undefined;
options.outFile = undefined;

// We are not doing a full typecheck, we are not resolving the whole context,
// so pass --noResolve to avoid reporting missing file errors.
options.noResolve = true;

// if jsx is specified then treat file as .tsx
const inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
const sourceFile = createSourceFile(inputFileName, input, options.target!); // TODO: GH#18217
Expand Down
12 changes: 12 additions & 0 deletions src/testRunner/unittests/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ var x = 0;`, {
options: { compilerOptions: { typeRoots: ["./folder"] }, fileName: "input.js", reportDiagnostics: true }
});

transpilesCorrectly("Supports setting 'incremental'", "x;", {
options: { compilerOptions: { incremental: true }, fileName: "input.js", reportDiagnostics: true }
});

transpilesCorrectly("Supports setting 'composite'", "x;", {
options: { compilerOptions: { composite: true }, fileName: "input.js", reportDiagnostics: true }
});

transpilesCorrectly("Supports setting 'tsbuildinfo'", "x;", {
options: { compilerOptions: { incremental: true, tsBuildInfoFile: "./folder/config.tsbuildinfo" }, fileName: "input.js", reportDiagnostics: true }
});

transpilesCorrectly("Correctly serialize metadata when transpile with CommonJS option",
`import * as ng from "angular2/core";` +
`declare function foo(...args: any[]);` +
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.