Skip to content

Commit 532f92b

Browse files
committed
Compiler flag to specify line ending microsoft#1693
1 parent 1625a6c commit 532f92b

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

src/compiler/commandLineParser.ts

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module ts {
6666
paramType: Diagnostics.KIND,
6767
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
6868
},
69+
{
70+
name: "newLine",
71+
type: { "crlf": NewLineKind.CRLF, "lf": NewLineKind.LF },
72+
description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix,
73+
paramType: Diagnostics.NEWLINE,
74+
error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
75+
},
6976
{
7077
name: "noEmit",
7178
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

+3
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ module ts {
502502
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
503503
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." },
504504
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." },
505+
Emit_newline_Colon_CRLF_dos_or_LF_unix: { code: 6061, category: DiagnosticCategory.Message, key: "Emit newline: 'CRLF' (dos) or 'LF' (unix)." },
506+
NEWLINE: { code: 6062, category: DiagnosticCategory.Message, key: "NEWLINE" },
507+
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6063, category: DiagnosticCategory.Error, key: "Argument for --newLine option must be 'CRLF' or 'LF'." },
505508
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
506509
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
507510
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },

src/compiler/diagnosticMessages.json

+12
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,18 @@
19981998
"category": "Error",
19991999
"code": 6059
20002000
},
2001+
"Emit newline: 'CRLF' (dos) or 'LF' (unix).": {
2002+
"category": "Message",
2003+
"code": 6061
2004+
},
2005+
"NEWLINE": {
2006+
"category": "Message",
2007+
"code": 6062
2008+
},
2009+
"Argument for --newLine option must be 'CRLF' or 'LF'.": {
2010+
"category": "Error",
2011+
"code": 6063
2012+
},
20012013

20022014

20032015
"Variable '{0}' implicitly has an '{1}' type.": {

src/compiler/program.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ module ts {
9191
}
9292
}
9393

94+
let newLine = [sys.newLine, "\r\n", "\n"][options.newLine ? Number(options.newLine) : 0];
95+
9496
return {
9597
getSourceFile,
9698
getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)),
9799
writeFile,
98100
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
99101
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
100102
getCanonicalFileName,
101-
getNewLine: () => sys.newLine
103+
getNewLine: () => newLine
102104
};
103105
}
104106

src/compiler/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ module ts {
16561656
locale?: string;
16571657
mapRoot?: string;
16581658
module?: ModuleKind;
1659+
newLine?: string;
16591660
noEmit?: boolean;
16601661
noEmitHelpers?: boolean;
16611662
noEmitOnError?: boolean;
@@ -1689,6 +1690,12 @@ module ts {
16891690
System = 4,
16901691
}
16911692

1693+
export const enum NewLineKind {
1694+
DEFAULT = 0,
1695+
CRLF = 1,
1696+
LF = 2,
1697+
}
1698+
16921699
export interface LineAndCharacter {
16931700
line: number;
16941701
/*

0 commit comments

Comments
 (0)