Skip to content

Commit 8413d8d

Browse files
committed
Compiler flag to specify line ending microsoft#1693
1 parent 218e101 commit 8413d8d

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
@@ -57,6 +57,13 @@ module ts {
5757
paramType: Diagnostics.KIND,
5858
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_or_umd
5959
},
60+
{
61+
name: "newLine",
62+
type: { "crlf": NewLineKind.CRLF, "lf": NewLineKind.LF },
63+
description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix,
64+
paramType: Diagnostics.NEWLINE,
65+
error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
66+
},
6067
{
6168
name: "noEmit",
6269
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

+3
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ module ts {
499499
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
500500
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." },
501501
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." },
502+
Emit_newline_Colon_CRLF_dos_or_LF_unix: { code: 6061, category: DiagnosticCategory.Message, key: "Emit newline: 'CRLF' (dos) or 'LF' (unix)." },
503+
NEWLINE: { code: 6062, category: DiagnosticCategory.Message, key: "NEWLINE" },
504+
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6063, category: DiagnosticCategory.Error, key: "Argument for --newLine option must be 'CRLF' or 'LF'." },
502505
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
503506
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
504507
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
@@ -1984,6 +1984,18 @@
19841984
"category": "Error",
19851985
"code": 6059
19861986
},
1987+
"Emit newline: 'CRLF' (dos) or 'LF' (unix).": {
1988+
"category": "Message",
1989+
"code": 6061
1990+
},
1991+
"NEWLINE": {
1992+
"category": "Message",
1993+
"code": 6062
1994+
},
1995+
"Argument for --newLine option must be 'CRLF' or 'LF'.": {
1996+
"category": "Error",
1997+
"code": 6063
1998+
},
19871999

19882000

19892001
"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
@@ -1650,6 +1650,7 @@ module ts {
16501650
locale?: string;
16511651
mapRoot?: string;
16521652
module?: ModuleKind;
1653+
newLine?: string;
16531654
noEmit?: boolean;
16541655
noEmitOnError?: boolean;
16551656
noErrorTruncation?: boolean;
@@ -1681,6 +1682,12 @@ module ts {
16811682
UMD = 3,
16821683
}
16831684

1685+
export const enum NewLineKind {
1686+
DEFAULT = 0,
1687+
CRLF = 1,
1688+
LF = 2,
1689+
}
1690+
16841691
export interface LineAndCharacter {
16851692
line: number;
16861693
/*

0 commit comments

Comments
 (0)