From 532f92b88f7edcc2f6b98117841db3e5718b7262 Mon Sep 17 00:00:00 2001 From: Keith Mashinter Date: Sun, 26 Apr 2015 11:37:02 -0400 Subject: [PATCH 01/10] 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 da31878403a..7dc56382e14 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 98b5a170ae6..cb3fcfd599e 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 60d8e8e6515..e20f0414831 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 cc2fe7ff190..a3a228fc007 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 9e7e6ac7328..75eb7a954bb 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; /* From 16d7e5cad7df2173e18dfd1b41c78478248d1f4f Mon Sep 17 00:00:00 2001 From: Keith Mashinter Date: Sun, 26 Apr 2015 12:19:16 -0400 Subject: [PATCH 02/10] Compiler flag to specify line ending #1693 fix whitespace --- src/compiler/commandLineParser.ts | 4 ++-- src/compiler/diagnosticMessages.json | 18 +++++++++--------- src/compiler/program.ts | 2 +- src/compiler/types.ts | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7dc56382e14..9aab24637af 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -69,9 +69,9 @@ module ts { { name: "newLine", type: { "crlf": NewLineKind.CRLF, "lf": NewLineKind.LF }, - description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix, + description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix, paramType: Diagnostics.NEWLINE, - error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF + error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF }, { name: "noEmit", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e20f0414831..85f629cbcde 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1999,17 +1999,17 @@ "code": 6059 }, "Emit newline: 'CRLF' (dos) or 'LF' (unix).": { - "category": "Message", - "code": 6061 - }, + "category": "Message", + "code": 6061 + }, "NEWLINE": { - "category": "Message", - "code": 6062 - }, + "category": "Message", + "code": 6062 + }, "Argument for --newLine option must be 'CRLF' or 'LF'.": { - "category": "Error", - "code": 6063 - }, + "category": "Error", + "code": 6063 + }, "Variable '{0}' implicitly has an '{1}' type.": { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a3a228fc007..c54acd44a8c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -91,7 +91,7 @@ module ts { } } - let newLine = [sys.newLine, "\r\n", "\n"][options.newLine ? Number(options.newLine) : 0]; + let newLine = [sys.newLine, "\r\n", "\n"][options.newLine ? Number(options.newLine) : 0]; return { getSourceFile, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 75eb7a954bb..c5eceadedb1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1656,7 +1656,7 @@ module ts { locale?: string; mapRoot?: string; module?: ModuleKind; - newLine?: string; + newLine?: string; noEmit?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; @@ -1692,7 +1692,7 @@ module ts { export const enum NewLineKind { DEFAULT = 0, - CRLF = 1, + CRLF = 1, LF = 2, } From c1d2aeab84802f5b4235eb4ab2ddfbbab247f23d Mon Sep 17 00:00:00 2001 From: kmashint Date: Sun, 26 Apr 2015 21:32:51 -0400 Subject: [PATCH 03/10] 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 { From c783e3781a1ebab49b26396600b4cefed86824b4 Mon Sep 17 00:00:00 2001 From: kmashint Date: Sun, 26 Apr 2015 22:15:43 -0400 Subject: [PATCH 04/10] Compiler flag to specify line ending #1693 code review adjustments --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/program.ts | 2 +- src/compiler/types.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index cb3fcfd599e..5b5dfb50791 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -504,7 +504,7 @@ module ts { 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'." }, + 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/program.ts b/src/compiler/program.ts index 536dbfc7529..64a2ce2e57a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -91,7 +91,7 @@ module ts { } } - let newLine = + let newLine = options.newLine === NewLineKind.CarriageReturnLineFeed ? "\r\n" : options.newLine === NewLineKind.LineFeed ? "\n" : sys.newLine; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 06d5c14a3e8..86e680ca8b0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1656,7 +1656,7 @@ module ts { locale?: string; mapRoot?: string; module?: ModuleKind; - newLine?: string; + newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; From bcdf5bba640a3eda435f396aac46c2fb0c6d5cdd Mon Sep 17 00:00:00 2001 From: kmashint Date: Sun, 26 Apr 2015 22:15:43 -0400 Subject: [PATCH 05/10] Compiler flag to specify line ending #1693 code review adjustments --- src/compiler/diagnosticInformationMap.generated.ts | 6 +++--- src/compiler/diagnosticMessages.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5b5dfb50791..ea4c21e54b0 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -502,9 +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'." }, + Emit_newline_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Emit newline: 'CRLF' (dos) or 'LF' (unix)." }, + NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" }, + Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, 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 3ca3620c648..e74603f2bac 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2000,15 +2000,15 @@ }, "Emit newline: 'CRLF' (dos) or 'LF' (unix).": { "category": "Message", - "code": 6061 + "code": 6060 }, "NEWLINE": { "category": "Message", - "code": 6062 + "code": 6061 }, "Argument for 'newLine' option must be 'CRLF' or 'LF'.": { "category": "Error", - "code": 6063 + "code": 6062 }, From 2e0a55c4d352a7010f7dc05eeff1b584f2d70bcc Mon Sep 17 00:00:00 2001 From: kmashint Date: Sat, 2 May 2015 16:18:37 -0400 Subject: [PATCH 06/10] Compiler flag to specify line ending #1693 unit tests --- src/compiler/program.ts | 9 ++++--- src/harness/harness.ts | 26 ++++++++++++++++--- .../reference/newLineFlagWithCRLF.js | 9 +++++++ .../reference/newLineFlagWithCRLF.symbols | 8 ++++++ .../reference/newLineFlagWithCRLF.types | 11 ++++++++ .../baselines/reference/newLineFlagWithLF.js | 9 +++++++ .../reference/newLineFlagWithLF.symbols | 8 ++++++ .../reference/newLineFlagWithLF.types | 11 ++++++++ tests/cases/compiler/newLineFlagWithCR.ts | 4 +++ tests/cases/compiler/newLineFlagWithCRLF.ts | 4 +++ tests/cases/compiler/newLineFlagWithLF.ts | 4 +++ 11 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/newLineFlagWithCRLF.js create mode 100644 tests/baselines/reference/newLineFlagWithCRLF.symbols create mode 100644 tests/baselines/reference/newLineFlagWithCRLF.types create mode 100644 tests/baselines/reference/newLineFlagWithLF.js create mode 100644 tests/baselines/reference/newLineFlagWithLF.symbols create mode 100644 tests/baselines/reference/newLineFlagWithLF.types create mode 100644 tests/cases/compiler/newLineFlagWithCR.ts create mode 100644 tests/cases/compiler/newLineFlagWithCRLF.ts create mode 100644 tests/cases/compiler/newLineFlagWithLF.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 64a2ce2e57a..96e1773172b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -9,6 +9,9 @@ module ts { /** The version of the TypeScript compiler release */ export const version = "1.5.0"; + + const NEWLINE_CRLF = "\r\n"; + const NEWLINE_LF = "\n"; export function findConfigFile(searchPath: string): string { var fileName = "tsconfig.json"; @@ -91,9 +94,9 @@ module ts { } } - let newLine = - options.newLine === NewLineKind.CarriageReturnLineFeed ? "\r\n" : - options.newLine === NewLineKind.LineFeed ? "\n" : + let newLine = + options.newLine === NewLineKind.CarriageReturnLineFeed ? NEWLINE_CRLF : + options.newLine === NewLineKind.LineFeed ? NEWLINE_LF : sys.newLine; return { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 30ae22a9e4a..75e8d1e4590 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -805,6 +805,9 @@ module Harness { return result; } + const NEWLINE_CRLF = "\r\n"; + const NEWLINE_LF = "\n"; + export var defaultLibFileName = 'lib.d.ts'; export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); @@ -822,7 +825,8 @@ module Harness { scriptTarget: ts.ScriptTarget, useCaseSensitiveFileNames: boolean, // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host - currentDirectory?: string): ts.CompilerHost { + currentDirectory?: string, + newLineKind?: ts.NewLineKind): ts.CompilerHost { // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames function getCanonicalFileName(fileName: string): string { @@ -841,6 +845,11 @@ module Harness { }; inputFiles.forEach(register); + let newLine = + newLineKind === ts.NewLineKind.CarriageReturnLineFeed ? NEWLINE_CRLF : + newLineKind === ts.NewLineKind.LineFeed ? NEWLINE_LF : + ts.sys.newLine; + return { getCurrentDirectory, getSourceFile: (fn, languageVersion) => { @@ -869,7 +878,7 @@ module Harness { writeFile, getCanonicalFileName, useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, - getNewLine: () => ts.sys.newLine + getNewLine: () => newLine }; } @@ -1042,7 +1051,16 @@ module Harness { case 'newline': case 'newlines': - newLine = setting.value; + if (setting.value.toLowerCase() === 'crlf') { + options.newLine = ts.NewLineKind.CarriageReturnLineFeed; + } else if (setting.value.toLowerCase() === 'lf') { + options.newLine = ts.NewLineKind.LineFeed; + } else if (setting.value === '\\n') { + // Handle old usage, e.g. contextualTyping.ts:// @newline: \n + newLine = setting.value; + } else { + throw new Error('Unknown option for newLine: ' + setting.value); + } break; case 'comments': @@ -1103,7 +1121,7 @@ module Harness { var programFiles = inputFiles.concat(includeBuiltFiles).map(file => file.unitName); var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(includeBuiltFiles).concat(otherFiles), (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), - options.target, useCaseSensitiveFileNames, currentDirectory)); + options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine)); var emitResult = program.emit(); diff --git a/tests/baselines/reference/newLineFlagWithCRLF.js b/tests/baselines/reference/newLineFlagWithCRLF.js new file mode 100644 index 00000000000..ebf095e5fc7 --- /dev/null +++ b/tests/baselines/reference/newLineFlagWithCRLF.js @@ -0,0 +1,9 @@ +//// [newLineFlagWithCRLF.ts] +var x=1; +x=2; + + + +//// [newLineFlagWithCRLF.js] +var x = 1; +x = 2; diff --git a/tests/baselines/reference/newLineFlagWithCRLF.symbols b/tests/baselines/reference/newLineFlagWithCRLF.symbols new file mode 100644 index 00000000000..07825959fbe --- /dev/null +++ b/tests/baselines/reference/newLineFlagWithCRLF.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/newLineFlagWithCRLF.ts === +var x=1; +>x : Symbol(x, Decl(newLineFlagWithCRLF.ts, 0, 3)) + +x=2; +>x : Symbol(x, Decl(newLineFlagWithCRLF.ts, 0, 3)) + + diff --git a/tests/baselines/reference/newLineFlagWithCRLF.types b/tests/baselines/reference/newLineFlagWithCRLF.types new file mode 100644 index 00000000000..2663f4bbc7b --- /dev/null +++ b/tests/baselines/reference/newLineFlagWithCRLF.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/newLineFlagWithCRLF.ts === +var x=1; +>x : number +>1 : number + +x=2; +>x=2 : number +>x : number +>2 : number + + diff --git a/tests/baselines/reference/newLineFlagWithLF.js b/tests/baselines/reference/newLineFlagWithLF.js new file mode 100644 index 00000000000..be1b9ed644e --- /dev/null +++ b/tests/baselines/reference/newLineFlagWithLF.js @@ -0,0 +1,9 @@ +//// [newLineFlagWithLF.ts] +var x=1; +x=2; + + + +//// [newLineFlagWithLF.js] +var x = 1; +x = 2; diff --git a/tests/baselines/reference/newLineFlagWithLF.symbols b/tests/baselines/reference/newLineFlagWithLF.symbols new file mode 100644 index 00000000000..f4edf68dcb0 --- /dev/null +++ b/tests/baselines/reference/newLineFlagWithLF.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/newLineFlagWithLF.ts === +var x=1; +>x : Symbol(x, Decl(newLineFlagWithLF.ts, 0, 3)) + +x=2; +>x : Symbol(x, Decl(newLineFlagWithLF.ts, 0, 3)) + + diff --git a/tests/baselines/reference/newLineFlagWithLF.types b/tests/baselines/reference/newLineFlagWithLF.types new file mode 100644 index 00000000000..735f31d6c52 --- /dev/null +++ b/tests/baselines/reference/newLineFlagWithLF.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/newLineFlagWithLF.ts === +var x=1; +>x : number +>1 : number + +x=2; +>x=2 : number +>x : number +>2 : number + + diff --git a/tests/cases/compiler/newLineFlagWithCR.ts b/tests/cases/compiler/newLineFlagWithCR.ts new file mode 100644 index 00000000000..4a1fbbfe3d3 --- /dev/null +++ b/tests/cases/compiler/newLineFlagWithCR.ts @@ -0,0 +1,4 @@ +// @newline: CR +var x=1; +x=2; + diff --git a/tests/cases/compiler/newLineFlagWithCRLF.ts b/tests/cases/compiler/newLineFlagWithCRLF.ts new file mode 100644 index 00000000000..2a25ebc50d1 --- /dev/null +++ b/tests/cases/compiler/newLineFlagWithCRLF.ts @@ -0,0 +1,4 @@ +// @newline: CRLF +var x=1; +x=2; + diff --git a/tests/cases/compiler/newLineFlagWithLF.ts b/tests/cases/compiler/newLineFlagWithLF.ts new file mode 100644 index 00000000000..2f85a3a1e7f --- /dev/null +++ b/tests/cases/compiler/newLineFlagWithLF.ts @@ -0,0 +1,4 @@ +// @newline: LF +var x=1; +x=2; + From 47c4c125fe63b6499d22b571a727840fbb225db2 Mon Sep 17 00:00:00 2001 From: kmashint Date: Sat, 2 May 2015 17:48:14 -0400 Subject: [PATCH 07/10] Compiler flag to specify line ending #1693 unit test adjustments --- src/harness/harness.ts | 16 ++++++++-------- tests/cases/compiler/newLineFlagWithCR.ts | 4 ---- 2 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 tests/cases/compiler/newLineFlagWithCR.ts diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 75e8d1e4590..8c3c29beca2 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -826,7 +826,7 @@ module Harness { useCaseSensitiveFileNames: boolean, // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host currentDirectory?: string, - newLineKind?: ts.NewLineKind): ts.CompilerHost { + newLineKind?: ts.NewLineKind): ts.CompilerHost { // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames function getCanonicalFileName(fileName: string): string { @@ -1050,15 +1050,15 @@ module Harness { break; case 'newline': - case 'newlines': if (setting.value.toLowerCase() === 'crlf') { options.newLine = ts.NewLineKind.CarriageReturnLineFeed; - } else if (setting.value.toLowerCase() === 'lf') { - options.newLine = ts.NewLineKind.LineFeed; - } else if (setting.value === '\\n') { - // Handle old usage, e.g. contextualTyping.ts:// @newline: \n newLine = setting.value; - } else { + } + else if (setting.value.toLowerCase() === 'lf') { + options.newLine = ts.NewLineKind.LineFeed; + newLine = setting.value; + } + else { throw new Error('Unknown option for newLine: ' + setting.value); } break; @@ -1762,4 +1762,4 @@ module Harness { } // TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval -eval(Harness.tcServicesFile); \ No newline at end of file +eval(Harness.tcServicesFile); diff --git a/tests/cases/compiler/newLineFlagWithCR.ts b/tests/cases/compiler/newLineFlagWithCR.ts deleted file mode 100644 index 4a1fbbfe3d3..00000000000 --- a/tests/cases/compiler/newLineFlagWithCR.ts +++ /dev/null @@ -1,4 +0,0 @@ -// @newline: CR -var x=1; -x=2; - From 86bd1fc8941df2b5e2fc12aa137ea4b5691cc3ce Mon Sep 17 00:00:00 2001 From: kmashint Date: Sat, 2 May 2015 17:55:29 -0400 Subject: [PATCH 08/10] Compiler flag to specify line ending #1693 unit test adjustments --- tests/cases/compiler/contextualTyping.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/compiler/contextualTyping.ts b/tests/cases/compiler/contextualTyping.ts index e378fd82065..b3dfefdecfb 100644 --- a/tests/cases/compiler/contextualTyping.ts +++ b/tests/cases/compiler/contextualTyping.ts @@ -1,4 +1,4 @@ -// @newline: \n +// @newline: LF // @sourcemap: true // DEFAULT INTERFACES interface IFoo { From be3e3e7646697a7ff8be770d1ef588bc288fe2da Mon Sep 17 00:00:00 2001 From: kmashint Date: Sat, 2 May 2015 18:20:59 -0400 Subject: [PATCH 09/10] Compiler flag to specify line ending #1693 unit test adjustments --- src/harness/harness.ts | 8 +++++--- tests/cases/compiler/contextualTyping.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 8c3c29beca2..60a508e8625 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1052,17 +1052,19 @@ module Harness { case 'newline': if (setting.value.toLowerCase() === 'crlf') { options.newLine = ts.NewLineKind.CarriageReturnLineFeed; - newLine = setting.value; } else if (setting.value.toLowerCase() === 'lf') { options.newLine = ts.NewLineKind.LineFeed; - newLine = setting.value; } else { throw new Error('Unknown option for newLine: ' + setting.value); } break; + case 'normalizenewline': + newLine = setting.value; + break; + case 'comments': options.removeComments = setting.value === 'false'; break; @@ -1504,7 +1506,7 @@ module Harness { // List of allowed metadata names var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror", - "noimplicitany", "noresolve", "newline", "newlines", "emitbom", + "noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", "separatecompilation", "inlinesourcemap", "maproot", "sourceroot", diff --git a/tests/cases/compiler/contextualTyping.ts b/tests/cases/compiler/contextualTyping.ts index b3dfefdecfb..a50d542343a 100644 --- a/tests/cases/compiler/contextualTyping.ts +++ b/tests/cases/compiler/contextualTyping.ts @@ -1,4 +1,4 @@ -// @newline: LF +// @normalizenewline: \n // @sourcemap: true // DEFAULT INTERFACES interface IFoo { From 91fedf4df197689510c1134201e1ff50a5be56d0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 May 2015 13:21:39 -0700 Subject: [PATCH 10/10] Update description message and variable names --- src/compiler/commandLineParser.ts | 7 +++++-- src/compiler/diagnosticInformationMap.generated.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/program.ts | 10 +++++----- src/harness/harness.ts | 10 +++++----- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index bdf42d6011a..6a055aebf6a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -68,8 +68,11 @@ module ts { }, { name: "newLine", - type: { "crlf": NewLineKind.CarriageReturnLineFeed, "lf": NewLineKind.LineFeed }, - description: Diagnostics.Emit_newline_Colon_CRLF_dos_or_LF_unix, + type: { + "crlf": NewLineKind.CarriageReturnLineFeed, + "lf": NewLineKind.LineFeed + }, + description: Diagnostics.Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_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/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ea4c21e54b0..14163e81195 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -502,9 +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: 6060, category: DiagnosticCategory.Message, key: "Emit newline: 'CRLF' (dos) or 'LF' (unix)." }, + Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" }, - Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for 'newLine' option must be 'CRLF' or 'LF'." }, + Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, 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 e74603f2bac..18c98928dda 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1998,7 +1998,7 @@ "category": "Error", "code": 6059 }, - "Emit newline: 'CRLF' (dos) or 'LF' (unix).": { + "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix).": { "category": "Message", "code": 6060 }, @@ -2006,7 +2006,7 @@ "category": "Message", "code": 6061 }, - "Argument for 'newLine' option must be 'CRLF' or 'LF'.": { + "Argument for '--newLine' option must be 'CRLF' or 'LF'.": { "category": "Error", "code": 6062 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 96e1773172b..3ebd8740faa 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -9,9 +9,9 @@ module ts { /** The version of the TypeScript compiler release */ export const version = "1.5.0"; - - const NEWLINE_CRLF = "\r\n"; - const NEWLINE_LF = "\n"; + + const carriageReturnLineFeed = "\r\n"; + const lineFeed = "\n"; export function findConfigFile(searchPath: string): string { var fileName = "tsconfig.json"; @@ -95,8 +95,8 @@ module ts { } let newLine = - options.newLine === NewLineKind.CarriageReturnLineFeed ? NEWLINE_CRLF : - options.newLine === NewLineKind.LineFeed ? NEWLINE_LF : + options.newLine === NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed : + options.newLine === NewLineKind.LineFeed ? lineFeed : sys.newLine; return { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 60a508e8625..8e1bdbf07ee 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -805,8 +805,8 @@ module Harness { return result; } - const NEWLINE_CRLF = "\r\n"; - const NEWLINE_LF = "\n"; + const carriageReturnLineFeed = "\r\n"; + const lineFeed = "\n"; export var defaultLibFileName = 'lib.d.ts'; export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); @@ -846,9 +846,9 @@ module Harness { inputFiles.forEach(register); let newLine = - newLineKind === ts.NewLineKind.CarriageReturnLineFeed ? NEWLINE_CRLF : - newLineKind === ts.NewLineKind.LineFeed ? NEWLINE_LF : - ts.sys.newLine; + newLineKind === ts.NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed : + newLineKind === ts.NewLineKind.LineFeed ? lineFeed : + ts.sys.newLine; return { getCurrentDirectory,