MCPcopy
hub / github.com/vuejs/core / advancePositionWithMutation

Function advancePositionWithMutation

packages/compiler-core/src/utils.ts:252–274  ·  view source on GitHub ↗
(
  pos: Position,
  source: string,
  numberOfCharacters: number = source.length,
)

Source from the content-addressed store, hash-verified

250// advance by mutation without cloning (for performance reasons), since this
251// gets called a lot in the parser
252export function advancePositionWithMutation(
253 pos: Position,
254 source: string,
255 numberOfCharacters: number = source.length,
256): Position {
257 let linesCount = 0
258 let lastNewLinePos = -1
259 for (let i = 0; i < numberOfCharacters; i++) {
260 if (source.charCodeAt(i) === 10 /* newline char code */) {
261 linesCount++
262 lastNewLinePos = i
263 }
264 }
265
266 pos.offset += numberOfCharacters
267 pos.line += linesCount
268 pos.column =
269 lastNewLinePos === -1
270 ? pos.column + numberOfCharacters
271 : numberOfCharacters - lastNewLinePos
272
273 return pos
274}
275
276export function assert(condition: boolean, msg?: string): void {
277 /* v8 ignore next 3 */

Callers 2

pushFunction · 0.90
advancePositionWithCloneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected