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

Function codePointAtPos

packages/babel-parser/src/tokenizer/index.ts:308–321  ·  view source on GitHub ↗
(pos: number)

Source from the content-addressed store, hash-verified

306 }
307
308 codePointAtPos(pos: number): number {
309 // The implementation is based on
310 // https://source.chromium.org/chromium/chromium/src/+/master:v8/src/builtins/builtins-string-gen.cc;l=1455;drc=221e331b49dfefadbc6fa40b0c68e6f97606d0b3;bpv=0;bpt=1
311 // We reimplement `codePointAt` because `codePointAt` is a V8 builtin which is not inlined by TurboFan (as of M91)
312 // since `input` is mostly ASCII, an inlined `charCodeAt` wins here
313 let cp = this.input.charCodeAt(pos);
314 if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
315 const trail = this.input.charCodeAt(pos);
316 if ((trail & 0xfc00) === 0xdc00) {
317 cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
318 }
319 }
320 return cp;
321 }
322
323 // Toggle strict mode. Re-reads the next number or string to please
324 // pedantic tests (`"use strict"; 010;` should fail).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected