Skip to content

Commit 7da9cd3

Browse files
authored
lexer: fix expression to decode surrogate pairs (#3278)
1 parent f42cee9 commit 7da9cd3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/language/__tests__/lexer-test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,21 @@ describe('Lexer', () => {
10401040
locations: [{ line: 1, column: 1 }],
10411041
});
10421042

1043+
expectSyntaxError('\uD83D\uDE00').to.deep.equal({
1044+
message: 'Syntax Error: Unexpected character: U+1F600.',
1045+
locations: [{ line: 1, column: 1 }],
1046+
});
1047+
1048+
expectSyntaxError('\uD800\uDC00').to.deep.equal({
1049+
message: 'Syntax Error: Unexpected character: U+10000.',
1050+
locations: [{ line: 1, column: 1 }],
1051+
});
1052+
1053+
expectSyntaxError('\uDBFF\uDFFF').to.deep.equal({
1054+
message: 'Syntax Error: Unexpected character: U+10FFFF.',
1055+
locations: [{ line: 1, column: 1 }],
1056+
});
1057+
10431058
expectSyntaxError('\uDEAD').to.deep.equal({
10441059
message: 'Syntax Error: Invalid character: U+DEAD.',
10451060
locations: [{ line: 1, column: 1 }],

src/language/lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function encodeSurrogatePair(point: number): string {
152152
}
153153

154154
function decodeSurrogatePair(leading: number, trailing: number): number {
155-
return 0x10000 | ((leading & 0x03ff) << 10) | (trailing & 0x03ff);
155+
return 0x10000 + (((leading & 0x03ff) << 10) | (trailing & 0x03ff));
156156
}
157157

158158
/**

0 commit comments

Comments
 (0)