Skip to content

Commit 11166d2

Browse files
committed
Merge branch 'kmashint-master'
2 parents bd47ae4 + 91fedf4 commit 11166d2

15 files changed

+131
-8
lines changed

src/compiler/commandLineParser.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ 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: {
72+
"crlf": NewLineKind.CarriageReturnLineFeed,
73+
"lf": NewLineKind.LineFeed
74+
},
75+
description: Diagnostics.Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
76+
paramType: Diagnostics.NEWLINE,
77+
error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
78+
},
6979
{
7080
name: "noEmit",
7181
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 3 additions & 0 deletions
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+
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)." },
506+
NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" },
507+
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, 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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,18 @@
19981998
"category": "Error",
19991999
"code": 6059
20002000
},
2001+
"Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix).": {
2002+
"category": "Message",
2003+
"code": 6060
2004+
},
2005+
"NEWLINE": {
2006+
"category": "Message",
2007+
"code": 6061
2008+
},
2009+
"Argument for '--newLine' option must be 'CRLF' or 'LF'.": {
2010+
"category": "Error",
2011+
"code": 6062
2012+
},
20012013

20022014

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

src/compiler/program.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module ts {
1010
/** The version of the TypeScript compiler release */
1111
export const version = "1.5.0";
1212

13+
const carriageReturnLineFeed = "\r\n";
14+
const lineFeed = "\n";
15+
1316
export function findConfigFile(searchPath: string): string {
1417
var fileName = "tsconfig.json";
1518
while (true) {
@@ -91,14 +94,19 @@ module ts {
9194
}
9295
}
9396

97+
let newLine =
98+
options.newLine === NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed :
99+
options.newLine === NewLineKind.LineFeed ? lineFeed :
100+
sys.newLine;
101+
94102
return {
95103
getSourceFile,
96104
getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)),
97105
writeFile,
98106
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
99107
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
100108
getCanonicalFileName,
101-
getNewLine: () => sys.newLine
109+
getNewLine: () => newLine
102110
};
103111
}
104112

src/compiler/types.ts

Lines changed: 6 additions & 0 deletions
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?: NewLineKind;
16591660
noEmit?: boolean;
16601661
noEmitHelpers?: boolean;
16611662
noEmitOnError?: boolean;
@@ -1689,6 +1690,11 @@ module ts {
16891690
System = 4,
16901691
}
16911692

1693+
export const enum NewLineKind {
1694+
CarriageReturnLineFeed = 0,
1695+
LineFeed = 1,
1696+
}
1697+
16921698
export interface LineAndCharacter {
16931699
line: number;
16941700
/*

src/harness/harness.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,9 @@ module Harness {
805805
return result;
806806
}
807807

808+
const carriageReturnLineFeed = "\r\n";
809+
const lineFeed = "\n";
810+
808811
export var defaultLibFileName = 'lib.d.ts';
809812
export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
810813
export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
@@ -822,7 +825,8 @@ module Harness {
822825
scriptTarget: ts.ScriptTarget,
823826
useCaseSensitiveFileNames: boolean,
824827
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
825-
currentDirectory?: string): ts.CompilerHost {
828+
currentDirectory?: string,
829+
newLineKind?: ts.NewLineKind): ts.CompilerHost {
826830

827831
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
828832
function getCanonicalFileName(fileName: string): string {
@@ -841,6 +845,11 @@ module Harness {
841845
};
842846
inputFiles.forEach(register);
843847

848+
let newLine =
849+
newLineKind === ts.NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed :
850+
newLineKind === ts.NewLineKind.LineFeed ? lineFeed :
851+
ts.sys.newLine;
852+
844853
return {
845854
getCurrentDirectory,
846855
getSourceFile: (fn, languageVersion) => {
@@ -869,7 +878,7 @@ module Harness {
869878
writeFile,
870879
getCanonicalFileName,
871880
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
872-
getNewLine: () => ts.sys.newLine
881+
getNewLine: () => newLine
873882
};
874883
}
875884

@@ -1041,7 +1050,18 @@ module Harness {
10411050
break;
10421051

10431052
case 'newline':
1044-
case 'newlines':
1053+
if (setting.value.toLowerCase() === 'crlf') {
1054+
options.newLine = ts.NewLineKind.CarriageReturnLineFeed;
1055+
}
1056+
else if (setting.value.toLowerCase() === 'lf') {
1057+
options.newLine = ts.NewLineKind.LineFeed;
1058+
}
1059+
else {
1060+
throw new Error('Unknown option for newLine: ' + setting.value);
1061+
}
1062+
break;
1063+
1064+
case 'normalizenewline':
10451065
newLine = setting.value;
10461066
break;
10471067

@@ -1103,7 +1123,7 @@ module Harness {
11031123
var programFiles = inputFiles.concat(includeBuiltFiles).map(file => file.unitName);
11041124
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(includeBuiltFiles).concat(otherFiles),
11051125
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
1106-
options.target, useCaseSensitiveFileNames, currentDirectory));
1126+
options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine));
11071127

11081128
var emitResult = program.emit();
11091129

@@ -1486,7 +1506,7 @@ module Harness {
14861506
// List of allowed metadata names
14871507
var fileMetadataNames = ["filename", "comments", "declaration", "module",
14881508
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
1489-
"noimplicitany", "noresolve", "newline", "newlines", "emitbom",
1509+
"noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom",
14901510
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
14911511
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
14921512
"separatecompilation", "inlinesourcemap", "maproot", "sourceroot",
@@ -1744,4 +1764,4 @@ module Harness {
17441764
}
17451765

17461766
// TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval
1747-
eval(Harness.tcServicesFile);
1767+
eval(Harness.tcServicesFile);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [newLineFlagWithCRLF.ts]
2+
var x=1;
3+
x=2;
4+
5+
6+
7+
//// [newLineFlagWithCRLF.js]
8+
var x = 1;
9+
x = 2;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/newLineFlagWithCRLF.ts ===
2+
var x=1;
3+
>x : Symbol(x, Decl(newLineFlagWithCRLF.ts, 0, 3))
4+
5+
x=2;
6+
>x : Symbol(x, Decl(newLineFlagWithCRLF.ts, 0, 3))
7+
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/newLineFlagWithCRLF.ts ===
2+
var x=1;
3+
>x : number
4+
>1 : number
5+
6+
x=2;
7+
>x=2 : number
8+
>x : number
9+
>2 : number
10+
11+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [newLineFlagWithLF.ts]
2+
var x=1;
3+
x=2;
4+
5+
6+
7+
//// [newLineFlagWithLF.js]
8+
var x = 1;
9+
x = 2;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/newLineFlagWithLF.ts ===
2+
var x=1;
3+
>x : Symbol(x, Decl(newLineFlagWithLF.ts, 0, 3))
4+
5+
x=2;
6+
>x : Symbol(x, Decl(newLineFlagWithLF.ts, 0, 3))
7+
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/newLineFlagWithLF.ts ===
2+
var x=1;
3+
>x : number
4+
>1 : number
5+
6+
x=2;
7+
>x=2 : number
8+
>x : number
9+
>2 : number
10+
11+

tests/cases/compiler/contextualTyping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @newline: \n
1+
// @normalizenewline: \n
22
// @sourcemap: true
33
// DEFAULT INTERFACES
44
interface IFoo {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @newline: CRLF
2+
var x=1;
3+
x=2;
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @newline: LF
2+
var x=1;
3+
x=2;
4+

0 commit comments

Comments
 (0)