-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Compiler flag to specify line ending #2921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
532f92b
16d7e5c
c1d2aea
c783e37
bcdf5bb
2e0a55c
47c4c12
86bd1fc
be3e3e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| options.newLine = ts.NewLineKind.LineFeed; | ||
| } else if (setting.value === '\\n') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see what happened; any idea how many other tests use that flag?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A grep search revealed only the contextualTyping.ts uses this other @newline flag as in the comment, no matches for @newlines plural. I could use newlineflag for this new option, or change the old seldom-used option to something more internal, e.g. @normalizeNewline since it seems to be used in normalizeLineEndings(...).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't even know why the heck we ever introduced that - I think @danquirk might've added it after we futzed with baselining issues, but I think it would be safe to assume we can use the LF flag here. |
||
| // 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(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| //// [newLineFlagWithCRLF.ts] | ||
| var x=1; | ||
| x=2; | ||
|
|
||
|
|
||
|
|
||
| //// [newLineFlagWithCRLF.js] | ||
| var x = 1; | ||
| x = 2; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| //// [newLineFlagWithLF.ts] | ||
| var x=1; | ||
| x=2; | ||
|
|
||
|
|
||
|
|
||
| //// [newLineFlagWithLF.js] | ||
| var x = 1; | ||
| x = 2; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // @newline: CR | ||
|
||
| var x=1; | ||
| x=2; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // @newline: CRLF | ||
| var x=1; | ||
| x=2; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // @newline: LF | ||
| var x=1; | ||
| x=2; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use tabs