Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Oct 19, 2021
1 parent b1d1338 commit 544591d
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/language/lexer.ts
Expand Up @@ -151,10 +151,6 @@ function encodeSurrogatePair(point: number): string {
);
}

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

/**
* Prints the code point (or end of file reference) at a given location in a
* source for use in error messages.
Expand All @@ -163,22 +159,18 @@ function decodeSurrogatePair(leading: number, trailing: number): number {
* code point form (ie. U+1234).
*/
function printCodePointAt(lexer: Lexer, location: number): string {
const body = lexer.source.body;
if (location >= body.length) {
const code = lexer.source.body.codePointAt(location);

if (code === undefined) {
return TokenKind.EOF;
} else if (code >= 0x0020 && code <= 0x007e) {
// Printable ASCII
const char = String.fromCodePoint(code);
return char === '"' ? "'\"'" : `"${char}"`;
}
const code = body.charCodeAt(location);
// Printable ASCII
if (code >= 0x0020 && code <= 0x007e) {
return code === 0x0022 ? "'\"'" : `"${body[location]}"`;
}

// Unicode code point
const point = isSupplementaryCodePoint(body, location)
? decodeSurrogatePair(code, body.charCodeAt(location + 1))
: code;
const zeroPad =
point > 0xfff ? '' : point > 0xff ? '0' : point > 0xf ? '00' : '000';
return `U+${zeroPad}${point.toString(16).toUpperCase()}`;
return 'U+' + code.toString(16).toUpperCase().padStart(4, '0');
}

/**
Expand Down

0 comments on commit 544591d

Please sign in to comment.