{ } qjs-modules

location

Source: quickjs-location.c — module export: Location

Represents a position in a source text: line, column, character/byte offset and file name. Used by the lexer and other parsers.

Constructor

new Location([line, column, charOffset, file])   // length 1

Properties (enumerable)

PropertyRead/writeDescription
lineread-only1-based line number.
columnread-only1-based column number.
charOffsetread-onlyOffset in characters from the start.
byteOffsetread-onlyOffset in bytes from the start.
fileread/writeSource file name.

line, column, charOffset and byteOffset have no setter at all (assigning to them throws, same as any accessor property without one) - use copy() or nextChar() below to advance/update them. file is the only property that can be assigned directly.

Methods

MethodArgsDescription
equal(other)1Compares this location with another for equality.
clone()0Returns a copy of the location.
copy(other)1Overwrites this location in place with other's line/column/offsets/file (other may be a Location or a location-like object with line/column/file/charOffset/byteOffset, or lineNumber/columnNumber/fileName aliases).
nextChar(input)1Advances the location by one character - input may be a numeric code point, or an ArrayBuffer/typed array/string to decode the next UTF-8 codepoint from. Returns the number of bytes consumed.
toString()0Renders as file:line:column.
[Symbol.toPrimitive]()0Primitive coercion (string form; the "number" hint instead returns charOffset).

Static functions

FunctionArgsDescription
count(input)1Counts lines/columns by scanning a string, producing a Location.

Export list

Generated by utilities/doc-api.js from the location dump of utilities/api-surface.sh: 15 members. Edit the text above this block, not the block.

Location

class, constructible

  • static methods: count()
  • methods: clone(), copy(), equal(), nextChar(), toString(), [Symbol.toPrimitive]()
  • properties: byteOffset (get), charOffset (get), column (get), file (get/set), line (get), [Symbol.toStringTag]