Skip to content
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

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

Merged
merged 1 commit into from
Mar 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes this CharacterCodes.enQuad <= ch && 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 {
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/fileWithNextLine1.js
Original file line number Diff line number Diff line change
@@ -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 = '…';
6 changes: 6 additions & 0 deletions tests/baselines/reference/fileWithNextLine1.types
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions tests/baselines/reference/fileWithNextLine2.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions tests/baselines/reference/fileWithNextLine2.types
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions tests/baselines/reference/fileWithNextLine3.errors.txt
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions tests/baselines/reference/fileWithNextLine3.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion tests/baselines/reference/sourceMap-LineBreaks.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 74 additions & 76 deletions tests/baselines/reference/sourceMap-LineBreaks.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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->
Expand All @@ -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 >
Expand All @@ -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->
Expand All @@ -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->
Expand All @@ -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 >
Expand All @@ -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 >^^^^^^^
Expand All @@ -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->
Expand All @@ -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 >^^^^^^^
Expand All @@ -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 >^^^^
Expand All @@ -236,19 +236,19 @@ 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 >^^^^^^^
2 > ^
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 >^^^^
Expand All @@ -260,19 +260,19 @@ 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 >^^^^^^^
2 > ^
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 >^^^^
Expand All @@ -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
Expand Down
Loading