From 532f92b88f7edcc2f6b98117841db3e5718b7262 Mon Sep 17 00:00:00 2001 From: Keith Mashinter Date: Sun, 26 Apr 2015 11:37:02 -0400 Subject: [PATCH 1/9] 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; /* From 16d7e5cad7df2173e18dfd1b41c78478248d1f4f Mon Sep 17 00:00:00 2001 From: Keith Mashinter Date: Sun, 26 Apr 2015 12:19:16 -0400 Subject: [PATCH 2/9] 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 7dc56382e1449..9aab24637af8f 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 e20f0414831c1..85f629cbcdec6 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 a3a228fc0070a..c54acd44a8ccb 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 75eb7a954bbb5..c5eceadedb147 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 3/9] 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 9aab24637af8f..bdf42d6011abb 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 85f629cbcdec6..3ca3620c648e0 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 c54acd44a8ccb..536dbfc75295a 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 c5eceadedb147..06d5c14a3e860 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 4/9] 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 cb3fcfd599e72..5b5dfb50791cc 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 536dbfc75295a..64a2ce2e57acf 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 06d5c14a3e860..86e680ca8b047 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 5/9] 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 5b5dfb50791cc..ea4c21e54b073 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 3ca3620c648e0..e74603f2bacfc 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 6/9] 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 64a2ce2e57acf..96e1773172b99 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 30ae22a9e4aad..75e8d1e4590a3 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 0000000000000..ebf095e5fc732 --- /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 0000000000000..07825959fbe3e --- /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 0000000000000..2663f4bbc7b67 --- /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 0000000000000..be1b9ed644ec8 --- /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 0000000000000..f4edf68dcb081 --- /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 0000000000000..735f31d6c524d --- /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 0000000000000..4a1fbbfe3d368 --- /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 0000000000000..2a25ebc50d1d1 --- /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 0000000000000..2f85a3a1e7f19 --- /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 7/9] Compiler flag to specify line ending #1693 unit test adjustments --- src/harness/harness.ts | 14 +++++++------- tests/cases/compiler/newLineFlagWithCR.ts | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) delete mode 100644 tests/cases/compiler/newLineFlagWithCR.ts diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 75e8d1e4590a3..8c3c29beca231 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') { + newLine = setting.value; + } + 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 { 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 4a1fbbfe3d368..0000000000000 --- 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 8/9] 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 e378fd8206521..b3dfefdecfb90 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 9/9] 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 8c3c29beca231..60a508e8625d7 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 b3dfefdecfb90..a50d542343a86 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 {