Merge branch 'kmashint-master'

This commit is contained in:
Mohamed Hegazy 2015-05-04 13:23:24 -07:00
commit 11166d2f08
15 changed files with 131 additions and 8 deletions

View File

@ -66,6 +66,16 @@ module ts {
paramType: Diagnostics.KIND,
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
},
{
name: "newLine",
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
},
{
name: "noEmit",
type: "boolean",

View File

@ -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." },
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'." },
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." },

View File

@ -1998,6 +1998,18 @@
"category": "Error",
"code": 6059
},
"Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix).": {
"category": "Message",
"code": 6060
},
"NEWLINE": {
"category": "Message",
"code": 6061
},
"Argument for '--newLine' option must be 'CRLF' or 'LF'.": {
"category": "Error",
"code": 6062
},
"Variable '{0}' implicitly has an '{1}' type.": {

View File

@ -10,6 +10,9 @@ module ts {
/** The version of the TypeScript compiler release */
export const version = "1.5.0";
const carriageReturnLineFeed = "\r\n";
const lineFeed = "\n";
export function findConfigFile(searchPath: string): string {
var fileName = "tsconfig.json";
while (true) {
@ -91,6 +94,11 @@ module ts {
}
}
let newLine =
options.newLine === NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed :
options.newLine === NewLineKind.LineFeed ? lineFeed :
sys.newLine;
return {
getSourceFile,
getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)),
@ -98,7 +106,7 @@ module ts {
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
getCanonicalFileName,
getNewLine: () => sys.newLine
getNewLine: () => newLine
};
}

View File

@ -1656,6 +1656,7 @@ module ts {
locale?: string;
mapRoot?: string;
module?: ModuleKind;
newLine?: NewLineKind;
noEmit?: boolean;
noEmitHelpers?: boolean;
noEmitOnError?: boolean;
@ -1689,6 +1690,11 @@ module ts {
System = 4,
}
export const enum NewLineKind {
CarriageReturnLineFeed = 0,
LineFeed = 1,
}
export interface LineAndCharacter {
line: number;
/*

View File

@ -805,6 +805,9 @@ module Harness {
return result;
}
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);
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 ? carriageReturnLineFeed :
newLineKind === ts.NewLineKind.LineFeed ? lineFeed :
ts.sys.newLine;
return {
getCurrentDirectory,
getSourceFile: (fn, languageVersion) => {
@ -869,7 +878,7 @@ module Harness {
writeFile,
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
getNewLine: () => ts.sys.newLine
getNewLine: () => newLine
};
}
@ -1041,7 +1050,18 @@ 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 {
throw new Error('Unknown option for newLine: ' + setting.value);
}
break;
case 'normalizenewline':
newLine = setting.value;
break;
@ -1103,7 +1123,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();
@ -1486,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",
@ -1744,4 +1764,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);
eval(Harness.tcServicesFile);

View File

@ -0,0 +1,9 @@
//// [newLineFlagWithCRLF.ts]
var x=1;
x=2;
//// [newLineFlagWithCRLF.js]
var x = 1;
x = 2;

View File

@ -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))

View File

@ -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

View File

@ -0,0 +1,9 @@
//// [newLineFlagWithLF.ts]
var x=1;
x=2;
//// [newLineFlagWithLF.js]
var x = 1;
x = 2;

View File

@ -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))

View File

@ -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

View File

@ -1,4 +1,4 @@
// @newline: \n
// @normalizenewline: \n
// @sourcemap: true
// DEFAULT INTERFACES
interface IFoo {

View File

@ -0,0 +1,4 @@
// @newline: CRLF
var x=1;
x=2;

View File

@ -0,0 +1,4 @@
// @newline: LF
var x=1;
x=2;