MCPcopy Create free account
hub / github.com/babel/babel / readCodePoint

Function readCodePoint

packages/babel-helper-string-parser/src/index.ts:406–450  ·  view source on GitHub ↗
(
  input: string,
  pos: number,
  lineStart: number,
  curLine: number,
  throwOnInvalid: boolean,
  errors: CodePointErrorHandlers,
)

Source from the content-addressed store, hash-verified

404};
405
406export function readCodePoint(
407 input: string,
408 pos: number,
409 lineStart: number,
410 curLine: number,
411 throwOnInvalid: boolean,
412 errors: CodePointErrorHandlers,
413) {
414 const ch = input.charCodeAt(pos);
415 let code;
416
417 if (ch === charCodes.leftCurlyBrace) {
418 ++pos;
419 ({ code, pos } = readHexChar(
420 input,
421 pos,
422 lineStart,
423 curLine,
424 input.indexOf("}", pos) - pos,
425 true,
426 throwOnInvalid,
427 errors,
428 ));
429 ++pos;
430 if (code !== null && code > 0x10ffff) {
431 if (throwOnInvalid) {
432 errors.invalidCodePoint(pos, lineStart, curLine);
433 } else {
434 return { code: null, pos };
435 }
436 }
437 } else {
438 ({ code, pos } = readHexChar(
439 input,
440 pos,
441 lineStart,
442 curLine,
443 4,
444 false,
445 throwOnInvalid,
446 errors,
447 ));
448 }
449 return { code, pos };
450}

Callers 2

readCodePointFunction · 0.90
readEscapedCharFunction · 0.70

Calls 1

readHexCharFunction · 0.85

Tested by

no test coverage detected