From c1d2aeab84802f5b4235eb4ab2ddfbbab247f23d Mon Sep 17 00:00:00 2001 From: kmashint Date: Sun, 26 Apr 2015 21:32:51 -0400 Subject: [PATCH] Compiler flag to specify line ending #1693 code review adjustments --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 7 +++++-- src/compiler/types.ts | 5 ++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 9aab24637af..bdf42d6011a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -68,7 +68,7 @@ module ts { }, { name: "newLine", - type: { "crlf": NewLineKind.CRLF, "lf": NewLineKind.LF }, + type: { "crlf": NewLineKind.CarriageReturnLineFeed, "lf": NewLineKind.LineFeed }, description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix, paramType: Diagnostics.NEWLINE, error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 85f629cbcde..3ca3620c648 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2006,7 +2006,7 @@ "category": "Message", "code": 6062 }, - "Argument for --newLine option must be 'CRLF' or 'LF'.": { + "Argument for 'newLine' option must be 'CRLF' or 'LF'.": { "category": "Error", "code": 6063 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c54acd44a8c..536dbfc7529 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -91,8 +91,11 @@ module ts { } } - let newLine = [sys.newLine, "\r\n", "\n"][options.newLine ? Number(options.newLine) : 0]; - + let newLine = + options.newLine === NewLineKind.CarriageReturnLineFeed ? "\r\n" : + options.newLine === NewLineKind.LineFeed ? "\n" : + sys.newLine; + return { getSourceFile, getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)), diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c5eceadedb1..06d5c14a3e8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1691,9 +1691,8 @@ module ts { } export const enum NewLineKind { - DEFAULT = 0, - CRLF = 1, - LF = 2, + CarriageReturnLineFeed = 0, + LineFeed = 1, } export interface LineAndCharacter {