Skip to content

Commit

Permalink
lexer: fix expression to decode surrogate pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Sep 28, 2021
1 parent 564757f commit 3bf6197
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/language/__tests__/lexer-test.ts
Expand Up @@ -1040,6 +1040,21 @@ describe('Lexer', () => {
locations: [{ line: 1, column: 1 }],
});

expectSyntaxError('\uD83D\uDE00').to.deep.equal({
message: 'Syntax Error: Unexpected character: U+1F600.',
locations: [{ line: 1, column: 1 }],
});

expectSyntaxError('\uD800\uDC00').to.deep.equal({
message: 'Syntax Error: Unexpected character: U+10000.',
locations: [{ line: 1, column: 1 }],
});

expectSyntaxError('\uDBFF\uDFFF').to.deep.equal({
message: 'Syntax Error: Unexpected character: U+10FFFF.',
locations: [{ line: 1, column: 1 }],
});

expectSyntaxError('\uDEAD').to.deep.equal({
message: 'Syntax Error: Invalid character: U+DEAD.',
locations: [{ line: 1, column: 1 }],
Expand Down
2 changes: 1 addition & 1 deletion src/language/lexer.ts
Expand Up @@ -152,7 +152,7 @@ function encodeSurrogatePair(point: number): string {
}

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

/**
Expand Down

0 comments on commit 3bf6197

Please sign in to comment.