From 532f92b88f7edcc2f6b98117841db3e5718b7262 Mon Sep 17 00:00:00 2001 From: Keith Mashinter Date: Sun, 26 Apr 2015 11:37:02 -0400 Subject: [PATCH] Compiler flag to specify line ending #1693 --- src/compiler/commandLineParser.ts | 7 +++++++ src/compiler/diagnosticInformationMap.generated.ts | 3 +++ src/compiler/diagnosticMessages.json | 12 ++++++++++++ src/compiler/program.ts | 4 +++- src/compiler/types.ts | 7 +++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index da31878403a1c..7dc56382e1449 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -66,6 +66,13 @@ module ts { paramType: Diagnostics.KIND, error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd }, + { + name: "newLine", + type: { "crlf": NewLineKind.CRLF, "lf": NewLineKind.LF }, + description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix, + paramType: Diagnostics.NEWLINE, + error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF + }, { name: "noEmit", type: "boolean", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 98b5a170ae660..cb3fcfd599e72 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -502,6 +502,9 @@ module ts { Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, + Emit_newline_Colon_CRLF_dos_or_LF_unix: { code: 6061, category: DiagnosticCategory.Message, key: "Emit newline: 'CRLF' (dos) or 'LF' (unix)." }, + NEWLINE: { code: 6062, category: DiagnosticCategory.Message, key: "NEWLINE" }, + Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6063, category: DiagnosticCategory.Error, key: "Argument for --newLine option must be 'CRLF' or 'LF'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 60d8e8e651507..e20f0414831c1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1998,6 +1998,18 @@ "category": "Error", "code": 6059 }, + "Emit newline: 'CRLF' (dos) or 'LF' (unix).": { + "category": "Message", + "code": 6061 + }, + "NEWLINE": { + "category": "Message", + "code": 6062 + }, + "Argument for --newLine option must be 'CRLF' or 'LF'.": { + "category": "Error", + "code": 6063 + }, "Variable '{0}' implicitly has an '{1}' type.": { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index cc2fe7ff190f2..a3a228fc0070a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -91,6 +91,8 @@ module ts { } } + let newLine = [sys.newLine, "\r\n", "\n"][options.newLine ? Number(options.newLine) : 0]; + return { getSourceFile, getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)), @@ -98,7 +100,7 @@ module ts { getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()), useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames, getCanonicalFileName, - getNewLine: () => sys.newLine + getNewLine: () => newLine }; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9e7e6ac732804..75eb7a954bbb5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1656,6 +1656,7 @@ module ts { locale?: string; mapRoot?: string; module?: ModuleKind; + newLine?: string; noEmit?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; @@ -1689,6 +1690,12 @@ module ts { System = 4, } + export const enum NewLineKind { + DEFAULT = 0, + CRLF = 1, + LF = 2, + } + export interface LineAndCharacter { line: number; /*