Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Next Next commit
Add flag and update diagnostic messages
  • Loading branch information
andrewbranch committed Dec 7, 2022
commit 5ebc60689e10b9c4acb8dd8c7df48ed68c5dae4d
7 changes: 7 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,13 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
transpileOptionValue: true,
defaultValueDescription: false,
},
{
name: "verbatimModuleSyntax",
type: "boolean",
category: Diagnostics.Interop_Constraints,
description: Diagnostics.Do_not_transform_or_elide_any_imports_or_exports_not_marked_as_type_only_ensuring_they_are_written_in_the_output_file_s_format_based_on_the_module_setting,
defaultValueDescription: false,
},

// Strict Type Checks
{
Expand Down
42 changes: 33 additions & 9 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@
"category": "Error",
"code": 1203
},
"Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.": {
"Re-exporting a type when '{0}' is enabled requires using 'export type'.": {
"category": "Error",
"code": 1205
},
Expand All @@ -647,10 +647,6 @@
"category": "Error",
"code": 1207
},
"'{0}' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.": {
"category": "Error",
"code": 1208
},
"Invalid optional chain from new expression. Did you mean to call '{0}()'?": {
"category": "Error",
"code": 1209
Expand Down Expand Up @@ -875,7 +871,7 @@
"category": "Error",
"code": 1268
},
"Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided.": {
"Cannot use 'export import' on a type or type-only namespace when '{0}' is enabled.": {
"category": "Error",
"code": 1269
},
Expand Down Expand Up @@ -907,6 +903,14 @@
"category": "Error",
"code": 1276
},
"Namespaces are not allowed in global script files when '{0}' is enabled. If this file is not intended to be a global script, set 'moduleDetection' to 'force' or add an empty 'export {}' statement.": {
"category": "Error",
"code": 1277
},
"Top-level enums are not allowed in global script files when '{0}' is enabled. If this file is not intended to be a global script, set 'moduleDetection' to 'force' or add an empty 'export {}' statement.": {
"category": "Error",
"code": 1278
},

"'with' statements are not allowed in an async function block.": {
"category": "Error",
Expand Down Expand Up @@ -1436,7 +1440,7 @@
"category": "Error",
"code": 1446
},
"'{0}' resolves to a type-only declaration and must be re-exported using a type-only re-export when 'isolatedModules' is enabled.": {
"'{0}' resolves to a type-only declaration and must be re-exported using a type-only re-export when '{1}' is enabled.": {
"category": "Error",
"code": 1448
},
Expand Down Expand Up @@ -1549,6 +1553,14 @@
"category": "Message",
"code": 1483
},
"'{0}' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.": {
"category": "Error",
"code": 1484
},
"'{0}' resolves to a type-only declaration and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.": {
"category": "Error",
"code": 1485
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
Expand Down Expand Up @@ -3215,7 +3227,7 @@
"category": "Error",
"code": 2747
},
"Cannot access ambient const enums when the '--isolatedModules' flag is provided.": {
"Cannot access ambient const enums when '{0}' is enabled.": {
"category": "Error",
"code": 2748
},
Expand Down Expand Up @@ -4201,7 +4213,7 @@
"category": "Error",
"code": 5090
},
"Option 'preserveConstEnums' cannot be disabled when 'isolatedModules' is enabled.": {
"Option 'preserveConstEnums' cannot be disabled when '{0}' is enabled.": {
"category": "Error",
"code": 5091
},
Expand All @@ -4221,6 +4233,14 @@
"category": "Error",
"code": 5095
},
"Option '{0}' is redundant and cannot be specified with option '{1}'.": {
"category": "Error",
"code": 5096
},
"Option 'verbatimModuleSyntax' cannot be used when 'module' is set to 'UMD', 'AMD', or 'System'.": {
"category": "Error",
"code": 5097
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down Expand Up @@ -5919,6 +5939,10 @@
"category": "Message",
"code": 6803
},
"Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting.": {
"category": "Message",
"code": 6804
},

"one of:": {
"category": "Message",
Expand Down
18 changes: 17 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4211,7 +4211,23 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}

if (options.preserveValueImports && getEmitModuleKind(options) < ModuleKind.ES2015) {
createOptionValueDiagnostic("importsNotUsedAsValues", Diagnostics.Option_preserveValueImports_can_only_be_used_when_module_is_set_to_es2015_or_later);
createDiagnosticForOptionName(Diagnostics.Option_preserveValueImports_can_only_be_used_when_module_is_set_to_es2015_or_later, "preserveValueImports");
}

if (options.verbatimModuleSyntax) {
const moduleKind = getEmitModuleKind(options);
if (moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.UMD || moduleKind === ModuleKind.System) {
createDiagnosticForOptionName(Diagnostics.Option_verbatimModuleSyntax_cannot_be_used_when_module_is_set_to_UMD_AMD_or_System, "verbatimModuleSyntax");
}
if (options.isolatedModules) {
createDiagnosticForOptionName(Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, "isolatedModules", "verbatimModuleSyntax");
}
if (options.preserveValueImports) {
createDiagnosticForOptionName(Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, "preserveValueImports", "verbatimModuleSyntax");
}
if (options.importsNotUsedAsValues) {
createDiagnosticForOptionName(Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, "importsNotUsedAsValues", "verbatimModuleSyntax");
}
}

// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6797,6 +6797,7 @@ export interface CompilerOptions {
types?: string[];
/** Paths used to compute primary types search locations */
typeRoots?: string[];
verbatimModuleSyntax?: boolean;
/** @internal */ version?: boolean;
/** @internal */ watch?: boolean;
esModuleInterop?: boolean;
Expand Down
10 changes: 10 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7573,6 +7573,16 @@ export function hasJsonModuleEmitEnabled(options: CompilerOptions) {
}
}

/** @internal */
export function getIsolatedModules(options: CompilerOptions) {
return !!(options.isolatedModules || options.verbatimModuleSyntax);
}

/** @internal */
export function importNameElisionDisabled(options: CompilerOptions) {
return options.verbatimModuleSyntax || options.isolatedModules && options.preserveValueImports;
}

/** @internal */
export function unreachableCodeIsError(options: CompilerOptions): boolean {
return options.allowUnreachableCode === false;
Expand Down