Treat 0x0085 as whitespace, not as a line terminator. This matches ES5 and ES6.

This commit is contained in:
Cyrus Najmabadi 2015-03-20 16:49:21 -07:00
parent 0d2a5bbf7c
commit 9ae0815e21
13 changed files with 167 additions and 87 deletions

View File

@ -318,13 +318,38 @@ module ts {
let hasOwnProperty = Object.prototype.hasOwnProperty;
export function isWhiteSpace(ch: number): boolean {
return ch === CharacterCodes.space || ch === CharacterCodes.tab || ch === CharacterCodes.verticalTab || ch === CharacterCodes.formFeed ||
ch === CharacterCodes.nonBreakingSpace || ch === CharacterCodes.ogham || ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace ||
ch === CharacterCodes.narrowNoBreakSpace || ch === CharacterCodes.mathematicalSpace || ch === CharacterCodes.ideographicSpace || ch === CharacterCodes.byteOrderMark;
// Note: nextLine is in the Zs space, and should be considered to be a whitespace.
// It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript.
return ch === CharacterCodes.space ||
ch === CharacterCodes.tab ||
ch === CharacterCodes.verticalTab ||
ch === CharacterCodes.formFeed ||
ch === CharacterCodes.nonBreakingSpace ||
ch === CharacterCodes.nextLine ||
ch === CharacterCodes.ogham ||
ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace ||
ch === CharacterCodes.narrowNoBreakSpace ||
ch === CharacterCodes.mathematicalSpace ||
ch === CharacterCodes.ideographicSpace ||
ch === CharacterCodes.byteOrderMark;
}
export function isLineBreak(ch: number): boolean {
return ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn || ch === CharacterCodes.lineSeparator || ch === CharacterCodes.paragraphSeparator || ch === CharacterCodes.nextLine;
// ES5 7.3:
// The ECMAScript line terminator characters are listed in Table 3.
// Table 3 — Line Terminator Characters
// Code Unit Value Name Formal Name
// \u000A Line Feed <LF>
// \u000D Carriage Return <CR>
// \u2028 Line separator <LS>
// \u2029 Paragraph separator <PS>
// Only the characters in Table 3 are treated as line terminators. Other new line or line
// breaking characters are treated as white space but not as line terminators.
return ch === CharacterCodes.lineFeed ||
ch === CharacterCodes.carriageReturn ||
ch === CharacterCodes.lineSeparator ||
ch === CharacterCodes.paragraphSeparator;
}
function isDigit(ch: number): boolean {

View File

@ -0,0 +1,9 @@
//// [fileWithNextLine1.ts]
// Note: there is a nextline (0x85) in the string
// 0. It should be counted as a space and should not cause an error.
var v = '…';
//// [fileWithNextLine1.js]
// Note: there is a nextline (0x85) in the string
// 0. It should be counted as a space and should not cause an error.
var v = '…';

View File

@ -0,0 +1,6 @@
=== tests/cases/compiler/fileWithNextLine1.ts ===
// Note: there is a nextline (0x85) in the string
// 0. It should be counted as a space and should not cause an error.
var v = '…';
>v : string

View File

@ -0,0 +1,9 @@
//// [fileWithNextLine2.ts]
// Note: there is a nextline (0x85) char between the = and the 0.
// it should be treated like a space
var v =…0;
//// [fileWithNextLine2.js]
// Note: there is a nextline (0x85) char between the = and the 0.
// it should be treated like a space
var v = 0;

View File

@ -0,0 +1,6 @@
=== tests/cases/compiler/fileWithNextLine2.ts ===
// Note: there is a nextline (0x85) char between the = and the 0.
// it should be treated like a space
var v =…0;
>v : number

View File

@ -0,0 +1,9 @@
tests/cases/compiler/fileWithNextLine3.ts(3,1): error TS1108: A 'return' statement can only be used within a function body.
==== tests/cases/compiler/fileWithNextLine3.ts (1 errors) ====
// Note: there is a nextline (0x85) between the return and the
// 0. It should be counted as a space and should not trigger ASI
return…0;
~~~~~~
!!! error TS1108: A 'return' statement can only be used within a function body.

View File

@ -0,0 +1,9 @@
//// [fileWithNextLine3.ts]
// Note: there is a nextline (0x85) between the return and the
// 0. It should be counted as a space and should not trigger ASI
return…0;
//// [fileWithNextLine3.js]
// Note: there is a nextline (0x85) between the return and the
// 0. It should be counted as a space and should not trigger ASI
return 0;

View File

@ -1,2 +1,2 @@
//// [sourceMap-LineBreaks.js.map]
{"version":3,"file":"sourceMap-LineBreaks.js","sourceRoot":"","sources":["sourceMap-LineBreaks.ts"],"names":[],"mappings":"AAAA,IAAI,qBAAqB,GAAG,EAAE,CAAC;AAC/B,IAAI,0BAA0B,GAAG,EAAE,CAAC;AACpC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACzB,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACzB,IAAI,8BAA8B,GAAG,CAAC,CAAC;AACvC,IAAI,sBAAsB,GAAG,CAAC,CAAC;AAC/B,IAAI,8BAA8B,GAAG,CAAC,CAAC;AAEvC,IAAI,sCAAsC,GAAG,CAAC,CAAC;AAE/C,IAAI,yBAAyB,GAAG;OACzB,CAAC;AACR,IAAI,uCAAuC,GAAG;OACvC,CAAC;AACR,IAAI,+BAA+B,GAAG;OAC/B,CAAC;AAER,IAAI,8BAA8B,GAAG;OAC9B,CAAC;AACR,IAAI,mCAAmC,GAAG;OACnC,CAAC;AACR,IAAI,yBAAyB,GAAG;OACzB,CAAC"}
{"version":3,"file":"sourceMap-LineBreaks.js","sourceRoot":"","sources":["sourceMap-LineBreaks.ts"],"names":[],"mappings":"AAAA,IAAI,qBAAqB,GAAG,EAAE,CAAC;AAC/B,IAAI,0BAA0B,GAAG,EAAE,CAAC;AACpC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAAC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACnD,IAAI,8BAA8B,GAAG,CAAC,CAAC;AACvC,IAAI,sBAAsB,GAAG,CAAC,CAAC;AAC/B,IAAI,8BAA8B,GAAG,CAAC,CAAC;AAEvC,IAAI,sCAAsC,GAAG,CAAC,CAAC;AAE/C,IAAI,yBAAyB,GAAG;OACzB,CAAC;AACR,IAAI,uCAAuC,GAAG;OACvC,CAAC;AACR,IAAI,+BAA+B,GAAG;OAC/B,CAAC;AAER,IAAI,8BAA8B,GAAG;OAC9B,CAAC;AACR,IAAI,mCAAmC,GAAG;OACnC,CAAC;AACR,IAAI,yBAAyB,GAAG,gBAAgB,CAAC"}

View File

@ -78,18 +78,18 @@ sourceFile:sourceMap-LineBreaks.ts
5 > ^
6 > ^
7 > ^^^^^^^^^^^^^^^->
1->… >
1->…
2 >var
3 > endsWithLineFeed
4 > =
5 > 1
6 > ;
1->Emitted(4, 1) Source(4, 1) + SourceIndex(0)
2 >Emitted(4, 5) Source(4, 5) + SourceIndex(0)
3 >Emitted(4, 21) Source(4, 21) + SourceIndex(0)
4 >Emitted(4, 24) Source(4, 24) + SourceIndex(0)
5 >Emitted(4, 25) Source(4, 25) + SourceIndex(0)
6 >Emitted(4, 26) Source(4, 26) + SourceIndex(0)
1->Emitted(4, 1) Source(3, 27) + SourceIndex(0)
2 >Emitted(4, 5) Source(3, 31) + SourceIndex(0)
3 >Emitted(4, 21) Source(3, 47) + SourceIndex(0)
4 >Emitted(4, 24) Source(3, 50) + SourceIndex(0)
5 >Emitted(4, 25) Source(3, 51) + SourceIndex(0)
6 >Emitted(4, 26) Source(3, 52) + SourceIndex(0)
---
>>>var endsWithCarriageReturnLineFeed = 1;
1->
@ -105,12 +105,12 @@ sourceFile:sourceMap-LineBreaks.ts
4 > =
5 > 1
6 > ;
1->Emitted(5, 1) Source(5, 1) + SourceIndex(0)
2 >Emitted(5, 5) Source(5, 5) + SourceIndex(0)
3 >Emitted(5, 35) Source(5, 35) + SourceIndex(0)
4 >Emitted(5, 38) Source(5, 38) + SourceIndex(0)
5 >Emitted(5, 39) Source(5, 39) + SourceIndex(0)
6 >Emitted(5, 40) Source(5, 40) + SourceIndex(0)
1->Emitted(5, 1) Source(4, 1) + SourceIndex(0)
2 >Emitted(5, 5) Source(4, 5) + SourceIndex(0)
3 >Emitted(5, 35) Source(4, 35) + SourceIndex(0)
4 >Emitted(5, 38) Source(4, 38) + SourceIndex(0)
5 >Emitted(5, 39) Source(4, 39) + SourceIndex(0)
6 >Emitted(5, 40) Source(4, 40) + SourceIndex(0)
---
>>>var endsWithCarriageReturn = 1;
1 >
@ -127,12 +127,12 @@ sourceFile:sourceMap-LineBreaks.ts
4 > =
5 > 1
6 > ;
1 >Emitted(6, 1) Source(6, 1) + SourceIndex(0)
2 >Emitted(6, 5) Source(6, 5) + SourceIndex(0)
3 >Emitted(6, 27) Source(6, 27) + SourceIndex(0)
4 >Emitted(6, 30) Source(6, 30) + SourceIndex(0)
5 >Emitted(6, 31) Source(6, 31) + SourceIndex(0)
6 >Emitted(6, 32) Source(6, 32) + SourceIndex(0)
1 >Emitted(6, 1) Source(5, 1) + SourceIndex(0)
2 >Emitted(6, 5) Source(5, 5) + SourceIndex(0)
3 >Emitted(6, 27) Source(5, 27) + SourceIndex(0)
4 >Emitted(6, 30) Source(5, 30) + SourceIndex(0)
5 >Emitted(6, 31) Source(5, 31) + SourceIndex(0)
6 >Emitted(6, 32) Source(5, 32) + SourceIndex(0)
---
>>>var endsWithLineFeedCarriageReturn = 1;
1->
@ -148,12 +148,12 @@ sourceFile:sourceMap-LineBreaks.ts
4 > =
5 > 1
6 > ;
1->Emitted(7, 1) Source(7, 1) + SourceIndex(0)
2 >Emitted(7, 5) Source(7, 5) + SourceIndex(0)
3 >Emitted(7, 35) Source(7, 35) + SourceIndex(0)
4 >Emitted(7, 38) Source(7, 38) + SourceIndex(0)
5 >Emitted(7, 39) Source(7, 39) + SourceIndex(0)
6 >Emitted(7, 40) Source(7, 40) + SourceIndex(0)
1->Emitted(7, 1) Source(6, 1) + SourceIndex(0)
2 >Emitted(7, 5) Source(6, 5) + SourceIndex(0)
3 >Emitted(7, 35) Source(6, 35) + SourceIndex(0)
4 >Emitted(7, 38) Source(6, 38) + SourceIndex(0)
5 >Emitted(7, 39) Source(6, 39) + SourceIndex(0)
6 >Emitted(7, 40) Source(6, 40) + SourceIndex(0)
---
>>>var endsWithLineFeedCarriageReturnLineFeed = 1;
1->
@ -169,12 +169,12 @@ sourceFile:sourceMap-LineBreaks.ts
4 > =
5 > 1
6 > ;
1->Emitted(8, 1) Source(9, 1) + SourceIndex(0)
2 >Emitted(8, 5) Source(9, 5) + SourceIndex(0)
3 >Emitted(8, 43) Source(9, 43) + SourceIndex(0)
4 >Emitted(8, 46) Source(9, 46) + SourceIndex(0)
5 >Emitted(8, 47) Source(9, 47) + SourceIndex(0)
6 >Emitted(8, 48) Source(9, 48) + SourceIndex(0)
1->Emitted(8, 1) Source(8, 1) + SourceIndex(0)
2 >Emitted(8, 5) Source(8, 5) + SourceIndex(0)
3 >Emitted(8, 43) Source(8, 43) + SourceIndex(0)
4 >Emitted(8, 46) Source(8, 46) + SourceIndex(0)
5 >Emitted(8, 47) Source(8, 47) + SourceIndex(0)
6 >Emitted(8, 48) Source(8, 48) + SourceIndex(0)
---
>>>var stringLiteralWithLineFeed = "line 1\
1 >
@ -187,10 +187,10 @@ sourceFile:sourceMap-LineBreaks.ts
2 >var
3 > stringLiteralWithLineFeed
4 > =
1 >Emitted(9, 1) Source(11, 1) + SourceIndex(0)
2 >Emitted(9, 5) Source(11, 5) + SourceIndex(0)
3 >Emitted(9, 30) Source(11, 30) + SourceIndex(0)
4 >Emitted(9, 33) Source(11, 33) + SourceIndex(0)
1 >Emitted(9, 1) Source(10, 1) + SourceIndex(0)
2 >Emitted(9, 5) Source(10, 5) + SourceIndex(0)
3 >Emitted(9, 30) Source(10, 30) + SourceIndex(0)
4 >Emitted(9, 33) Source(10, 33) + SourceIndex(0)
---
>>>line 2";
1 >^^^^^^^
@ -199,8 +199,8 @@ sourceFile:sourceMap-LineBreaks.ts
1 >"line 1\
>line 2"
2 > ;
1 >Emitted(10, 8) Source(12, 8) + SourceIndex(0)
2 >Emitted(10, 9) Source(12, 9) + SourceIndex(0)
1 >Emitted(10, 8) Source(11, 8) + SourceIndex(0)
2 >Emitted(10, 9) Source(11, 9) + SourceIndex(0)
---
>>>var stringLiteralWithCarriageReturnLineFeed = "line 1\
1->
@ -212,10 +212,10 @@ sourceFile:sourceMap-LineBreaks.ts
2 >var
3 > stringLiteralWithCarriageReturnLineFeed
4 > =
1->Emitted(11, 1) Source(13, 1) + SourceIndex(0)
2 >Emitted(11, 5) Source(13, 5) + SourceIndex(0)
3 >Emitted(11, 44) Source(13, 44) + SourceIndex(0)
4 >Emitted(11, 47) Source(13, 47) + SourceIndex(0)
1->Emitted(11, 1) Source(12, 1) + SourceIndex(0)
2 >Emitted(11, 5) Source(12, 5) + SourceIndex(0)
3 >Emitted(11, 44) Source(12, 44) + SourceIndex(0)
4 >Emitted(11, 47) Source(12, 47) + SourceIndex(0)
---
>>>line 2";
1 >^^^^^^^
@ -224,8 +224,8 @@ sourceFile:sourceMap-LineBreaks.ts
1 >"line 1\
>line 2"
2 > ;
1 >Emitted(12, 8) Source(14, 8) + SourceIndex(0)
2 >Emitted(12, 9) Source(14, 9) + SourceIndex(0)
1 >Emitted(12, 8) Source(13, 8) + SourceIndex(0)
2 >Emitted(12, 9) Source(13, 9) + SourceIndex(0)
---
>>>var stringLiteralWithCarriageReturn = "line 1\ 1->
2 >^^^^
@ -236,10 +236,10 @@ sourceFile:sourceMap-LineBreaks.ts
2 >var
3 > stringLiteralWithCarriageReturn
4 > =
1->Emitted(13, 1) Source(15, 1) + SourceIndex(0)
2 >Emitted(13, 5) Source(15, 5) + SourceIndex(0)
3 >Emitted(13, 36) Source(15, 36) + SourceIndex(0)
4 >Emitted(13, 39) Source(15, 39) + SourceIndex(0)
1->Emitted(13, 1) Source(14, 1) + SourceIndex(0)
2 >Emitted(13, 5) Source(14, 5) + SourceIndex(0)
3 >Emitted(13, 36) Source(14, 36) + SourceIndex(0)
4 >Emitted(13, 39) Source(14, 39) + SourceIndex(0)
---
>>>line 2";
1 >^^^^^^^
@ -247,8 +247,8 @@ sourceFile:sourceMap-LineBreaks.ts
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >"line 1\ >line 2"
2 > ;
1 >Emitted(14, 8) Source(16, 8) + SourceIndex(0)
2 >Emitted(14, 9) Source(16, 9) + SourceIndex(0)
1 >Emitted(14, 8) Source(15, 8) + SourceIndex(0)
2 >Emitted(14, 9) Source(15, 9) + SourceIndex(0)
---
>>>var stringLiteralWithLineSeparator = "line 1\1->
2 >^^^^
@ -260,10 +260,10 @@ sourceFile:sourceMap-LineBreaks.ts
2 >var
3 > stringLiteralWithLineSeparator
4 > =
1->Emitted(15, 1) Source(18, 1) + SourceIndex(0)
2 >Emitted(15, 5) Source(18, 5) + SourceIndex(0)
3 >Emitted(15, 35) Source(18, 35) + SourceIndex(0)
4 >Emitted(15, 38) Source(18, 38) + SourceIndex(0)
1->Emitted(15, 1) Source(17, 1) + SourceIndex(0)
2 >Emitted(15, 5) Source(17, 5) + SourceIndex(0)
3 >Emitted(15, 35) Source(17, 35) + SourceIndex(0)
4 >Emitted(15, 38) Source(17, 38) + SourceIndex(0)
---
>>>line 2";
1 >^^^^^^^
@ -271,8 +271,8 @@ sourceFile:sourceMap-LineBreaks.ts
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >"line 1\ >line 2"
2 > ;
1 >Emitted(16, 8) Source(19, 8) + SourceIndex(0)
2 >Emitted(16, 9) Source(19, 9) + SourceIndex(0)
1 >Emitted(16, 8) Source(18, 8) + SourceIndex(0)
2 >Emitted(16, 9) Source(18, 9) + SourceIndex(0)
---
>>>var stringLiteralWithParagraphSeparator = "line 1\1->
2 >^^^^
@ -282,40 +282,38 @@ sourceFile:sourceMap-LineBreaks.ts
2 >var
3 > stringLiteralWithParagraphSeparator
4 > =
1->Emitted(17, 1) Source(20, 1) + SourceIndex(0)
2 >Emitted(17, 5) Source(20, 5) + SourceIndex(0)
3 >Emitted(17, 40) Source(20, 40) + SourceIndex(0)
4 >Emitted(17, 43) Source(20, 43) + SourceIndex(0)
1->Emitted(17, 1) Source(19, 1) + SourceIndex(0)
2 >Emitted(17, 5) Source(19, 5) + SourceIndex(0)
3 >Emitted(17, 40) Source(19, 40) + SourceIndex(0)
4 >Emitted(17, 43) Source(19, 43) + SourceIndex(0)
---
>>>line 2";
1 >^^^^^^^
2 > ^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >"line 1\ >line 2"
2 > ;
1 >Emitted(18, 8) Source(21, 8) + SourceIndex(0)
2 >Emitted(18, 9) Source(21, 9) + SourceIndex(0)
1 >Emitted(18, 8) Source(20, 8) + SourceIndex(0)
2 >Emitted(18, 9) Source(20, 9) + SourceIndex(0)
---
>>>var stringLiteralWithNextLine = "line 1\…1->
>>>var stringLiteralWithNextLine = "line 1\…line 2";
1->
2 >^^^^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^
4 > ^^^
5 > ^^^^^^^^^^^^^^^^
6 > ^
1-> >
2 >var
3 > stringLiteralWithNextLine
4 > =
1->Emitted(19, 1) Source(22, 1) + SourceIndex(0)
2 >Emitted(19, 5) Source(22, 5) + SourceIndex(0)
3 >Emitted(19, 30) Source(22, 30) + SourceIndex(0)
4 >Emitted(19, 33) Source(22, 33) + SourceIndex(0)
---
>>>line 2";
1 >^^^^^^^
2 > ^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >"line 1\… >line 2"
2 > ;
1 >Emitted(20, 8) Source(23, 8) + SourceIndex(0)
2 >Emitted(20, 9) Source(23, 9) + SourceIndex(0)
5 > "line 1\…line 2"
6 > ;
1->Emitted(19, 1) Source(21, 1) + SourceIndex(0)
2 >Emitted(19, 5) Source(21, 5) + SourceIndex(0)
3 >Emitted(19, 30) Source(21, 30) + SourceIndex(0)
4 >Emitted(19, 33) Source(21, 33) + SourceIndex(0)
5 >Emitted(19, 49) Source(21, 49) + SourceIndex(0)
6 >Emitted(19, 50) Source(21, 50) + SourceIndex(0)
---
>>>//# sourceMappingURL=sourceMap-LineBreaks.js.map

View File

@ -7,24 +7,24 @@ var endsWithCarriageReturnLineFeed = 1;
var endsWithCarriageReturn = 1; var endsWithLineFeedCarriageReturn = 1;
>endsWithNextLine : number
var endsWithLineFeedCarriageReturnLineFeed = 1;
>endsWithLineFeed : number
var endsWithLineFeedCarriageReturnLineFeed = 1;
>endsWithCarriageReturnLineFeed : number
var stringLiteralWithLineFeed = "line 1\
>endsWithCarriageReturn : number
line 2";
var stringLiteralWithLineFeed = "line 1\
>endsWithLineFeedCarriageReturn : number
var stringLiteralWithCarriageReturnLineFeed = "line 1\
line 2";
var stringLiteralWithCarriageReturnLineFeed = "line 1\
>endsWithLineFeedCarriageReturnLineFeed : number
line 2";
var stringLiteralWithCarriageReturn = "line 1\ line 2";
>stringLiteralWithLineFeed : string
var stringLiteralWithLineSeparator = "line 1\line 2";var stringLiteralWithParagraphSeparator = "line 1\line 2";var stringLiteralWithNextLine = "line 1\…line 2";
>stringLiteralWithCarriageReturnLineFeed : string

View File

@ -0,0 +1,3 @@
// Note: there is a nextline (0x85) in the string
// 0. It should be counted as a space and should not cause an error.
var v = '…';

View File

@ -0,0 +1,3 @@
// Note: there is a nextline (0x85) char between the = and the 0.
// it should be treated like a space
var v =…0;

View File

@ -0,0 +1,3 @@
// Note: there is a nextline (0x85) between the return and the
// 0. It should be counted as a space and should not trigger ASI
return…0;