Search


Search something to see results

AstArena

Css ast arena: ast nodes and value tokens.

The node data is read and written with the methods of the arena (getType, getName, getFirstChild, tokens, ...). See Arena and the Arena Memory guide for the memory usage.

Hierarchy (View Summary)

Index

Accessors

Constructors

Methods

node.AstArena.allocatenode.AstArena.appendChildnode.AstArena.appendChildListnode.AstArena.appendChildrennode.AstArena.appendFieldnode.AstArena.appendTokennode.AstArena.appendTokenListnode.AstArena.appendTokensnode.AstArena.childCountnode.AstArena.childrennode.AstArena.clonenode.AstArena.compactnode.AstArena.compactStringsnode.AstArena.copyLocationnode.AstArena.copySpannode.AstArena.copyTokennode.AstArena.createAtRulenode.AstArena.createBinaryExpressionnode.AstArena.createColornode.AstArena.createCommentnode.AstArena.createDeclarationnode.AstArena.createFractionnode.AstArena.createFunctionnode.AstArena.createListnode.AstArena.createRulenode.AstArena.createStyleSheetnode.AstArena.createTokennode.AstArena.denominatornode.AstArena.detachnode.AstArena.equalsIgnoreCasenode.AstArena.expandnode.AstArena.expandRulenode.AstArena.exportPropertiesnode.AstArena.exportTransferablesnode.AstArena.fieldnode.AstArena.fieldListnode.AstArena.fieldTokensnode.AstArena.findnode.AstArena.findAllnode.AstArena.findByValuenode.AstArena.findChildnode.AstArena.findLastnode.AstArena.findTokennode.AstArena.findValuenode.AstArena.fromObjectnode.AstArena.getCapacitynode.AstArena.getChildAtnode.AstArena.getColorTypenode.AstArena.getErrorsnode.AstArena.getFirstChildnode.AstArena.getFirstTokennode.AstArena.getFlagsnode.AstArena.getFractionnode.AstArena.getLastChildnode.AstArena.getLastIdnode.AstArena.getLastTokennode.AstArena.getLeftnode.AstArena.getLocationnode.AstArena.getNamenode.AstArena.getNextSiblingnode.AstArena.getNumericValuenode.AstArena.getOpnode.AstArena.getOp2node.AstArena.getParentnode.AstArena.getPreviousSiblingnode.AstArena.getRightnode.AstArena.getSelectornode.AstArena.getSourcenode.AstArena.getSourceIdnode.AstArena.getSpanEndnode.AstArena.getSpanStartnode.AstArena.getStatenode.AstArena.getStringCountnode.AstArena.getTokenAtnode.AstArena.getTypenode.AstArena.getUnitnode.AstArena.getValuenode.AstArena.getValueOwnernode.AstArena.getValueParentnode.AstArena.hasChildrennode.AstArena.hasFieldnode.AstArena.hasFlagsnode.AstArena.hasFractionnode.AstArena.hasLocationnode.AstArena.importnode.AstArena.importPropertiesnode.AstArena.indexOfnode.AstArena.insertAfternode.AstArena.insertBeforenode.AstArena.internStringnode.AstArena.isInvalidnode.AstArena.isMarkednode.AstArena.isNumericnode.AstArena.marknode.AstArena.moveChildrennode.AstArena.nodeFromObjectnode.AstArena.numeratornode.AstArena.prependChildrennode.AstArena.prependTokensnode.AstArena.recyclenode.AstArena.releasenode.AstArena.replaceChildnode.AstArena.replaceCompoundnode.AstArena.replaceCompoundLiteralnode.AstArena.replaceTokennode.AstArena.resetTokennode.AstArena.resizenode.AstArena.resolveStringnode.AstArena.setnode.AstArena.setChildAtnode.AstArena.setChildListnode.AstArena.setChildrennode.AstArena.setColorTypenode.AstArena.setErrorsnode.AstArena.setFieldnode.AstArena.setFirstChildnode.AstArena.setFirstTokennode.AstArena.setFlagsnode.AstArena.setFractionnode.AstArena.setLastChildnode.AstArena.setLeftnode.AstArena.setLocationnode.AstArena.setNamenode.AstArena.setNameStringnode.AstArena.setNextSiblingnode.AstArena.setNumericValuenode.AstArena.setOpnode.AstArena.setOp2node.AstArena.setParentnode.AstArena.setPreviousSiblingnode.AstArena.setRightnode.AstArena.setSelectornode.AstArena.setSpannode.AstArena.setSpandStartnode.AstArena.setSpanEndnode.AstArena.setStatenode.AstArena.setStrnode.AstArena.setTokenListnode.AstArena.setTokenLocationnode.AstArena.setTokensnode.AstArena.setTypenode.AstArena.setUnitnode.AstArena.setUnitStringnode.AstArena.setValuenode.AstArena.setValueStringnode.AstArena.siblingsnode.AstArena.sourceIndexnode.AstArena.spanLocationnode.AstArena.startsWithnode.AstArena.strnode.AstArena.subTokensnode.AstArena.takenode.AstArena.tokenCountnode.AstArena.tokenFromObjectnode.AstArena.tokensnode.AstArena.tokenToObjectnode.AstArena.toObjectnode.AstArena.toPlainObjectnode.AstArena.trimnode.AstArena.typeOfnode.AstArena.visitValuesnode.AstArena.walknode.AstArena.walkValuesnode.AstArena.fromTransferableArenaObjectsnode.AstArena.toTransferableArenaObject

Properties

  • get transferred(): boolean

    true when the column buffers have been transferred to another thread: the arena can no longer be used

    Returns boolean

Parameters

  • size: number = 4096

Returns AstArena

Returns number

append a single child node. faster than appendChildren()

Parameters

  • id: number
  • child: number

Returns void

append children. same as appendChildren with an array

Parameters

  • id: number
  • children: number[]

Returns void

Parameters

  • id: number
  • …children: number[]

Returns void

append tokens to a structured token field

Parameters

Returns void

append a single token. faster than appendTokens()

Parameters

  • id: number
  • token: number

Returns void

append tokens. same as appendTokens with an array

Parameters

  • id: number
  • children: number[]

Returns void

Parameters

  • id: number
  • …children: number[]

Returns void

number of children

Parameters

  • id: number

Returns number

child node ids

Parameters

  • id: number
  • Optionalfilter: (arena: this, id: number) => boolean

    called with the arena and the node id

Returns number[]

clone a node or a token. tokens are always cloned deeply

Parameters

  • id: number
  • deep: boolean = false

    also clone the children (rules) or the value tokens (declarations)

  • cloneMap: Map<number, number> | null = null

    map of the source ids to their clones

Returns number

drop the nodes that are not reachable from the root and renumber the remaining nodes in document order. the node ids change: ids obtained before the call (from visitors for instance) are no longer valid. the unused strings are dropped too

Parameters

  • Optionalerrors: ErrorDescription[] | null

    error descriptions whose node is remapped

Returns Uint32Array

mapping of the old ids to the new ids (0 when the node was dropped)

drop the interned strings that are no longer referenced by any node

Returns void

copy the source location of another node

Parameters

  • id: number
  • source: number

    node id

Returns void

copy the packed location of a node

Parameters

  • target: number
  • source: number

Returns void

copy the data columns of a token (type, values, unit, color type, location)

Parameters

  • target: number
  • source: number

Returns void

allocate an at-rule node

Parameters

  • typ: EnumToken
  • nam: string
  • val: string
  • block: boolean

    true if the at-rule has a block

  • tokens: number[] | null | undefined

    prelude tokens

  • state: EnumAstNodeStatus | null | undefined
  • errors: ErrorDescription[] | null | undefined

Returns number

allocate a binary expression token. the operator is stored in the numericValue column

Parameters

Returns number

allocate a color token

Parameters

  • val: string

    color name, hex value or color function name

  • kin: ColorType
  • Optionaltokens: number[] | null

    color function arguments

Returns number

allocate a comment node

Parameters

Returns number

allocate a declaration node

Parameters

Returns number

allocate a fraction token

Parameters

  • l: number

    numerator

  • r: number

    denominator

Returns number

allocate a function token

Parameters

  • typ: EnumToken

    function token type

  • name: string

    function name

  • Optionaltokens: number[] | null

    arguments

Returns number

allocate a list token (parens, attribute, wrapped values, ...)

Parameters

  • typ: EnumToken
  • Optionaltokens: number[] | null

Returns number

allocate a rule node

Parameters

Returns number

allocate a stylesheet node

Returns number

allocate a token. string values are interned, numeric values are stored in the numericValue column

Parameters

  • typ: EnumToken
  • Optionalval: string | number | null
  • Optionalunit: string | null

Returns number

denominator of a fraction token

Parameters

  • id: number

Returns number

detach a node from its parent

Parameters

  • id: number

Returns void

Parameters

  • node: number
  • key: "val" | "nam"
  • string: string

Returns boolean

Expand the css nesting rules of a stylesheet, a rule or an at-rule. The tree is expanded in place: the nested rules are moved into the parent of their rule and their selectors are resolved

const result = await parse(`.foo { color: red; .bar & { color: blue } }`);

result.arena.expand(result.ast);
console.log(render(result.arena, result.ast).code);

Parameters

  • ast: number

    node id

Returns number

the node id

expand a rule: the nested rules and at-rules are moved out of the rule, into parent before before. the rule is detached when it has no children left

Parameters

  • node: number
  • parent: number
  • before: number

    the expanded nodes are inserted before this child of parent. they are appended when 0

Returns void

structured-cloneable properties of the arena

Returns ArenaProperties

column buffers, in the order of arenaColumns. the spans buffer is shared with the spans32 view

Returns ArenaTransferables

first token of a structured token field (single token fields: l and r of binary expressions, op, ...)

Parameters

Returns number

list node holding the tokens of a structured token field. created when missing

Parameters

Returns number

tokens of a structured token field

Parameters

Returns number[]

Search the ast subtree and return the first match, in document order

// find the first declaration which name is 'aspect-ratio'
import { EnumToken, transform } from "@tbela99/css-parser";

const result = await transform(css);
const arena = result.arena;

const node = arena.find(result.ast, (arena, node) =>
arena.getType(node) == EnumToken.DeclarationNodeType && arena.getName(node) == 'aspect-ratio');

console.log(node == null ? null : arena.toObject(node));

Parameters

  • node: number

    node id

  • matcher: AstNodeMatcher

    called with the arena and the node id

Returns number | null

the node id or null

Search the ast subtree and return all matches, in document order

Parameters

  • node: number

    node id

  • matcher: AstNodeMatcher

    called with the arena and the node id

Returns number[]

Search the value tokens of the ast subtree and return the first match: the node that owns the token and the token

// find the first node which contains the length token '30px'
import { EnumToken, transform } from "@tbela99/css-parser";

const result = await transform(css);
const {node, value} = result.arena.findByValue(result.ast, (arena, value) =>
arena.getType(value) == EnumToken.LengthTokenType && arena.getNumericValue(value) == 30 && arena.getUnit(value) == 'px') ?? {};

Parameters

  • node: number

    node id

  • matcher: AstValueMatcher

    called with the arena and the token id

Returns { node: number; value: number } | null

Parameters

  • id: number
  • predicate: (id: number) => boolean

Returns number | null

Search the ast subtree in reverse order and return the first match (the last node in document order)

Parameters

  • node: number

    node id

  • matcher: AstNodeMatcher

    called with the arena and the node id

Returns number | null

find a token in the token list

Parameters

  • id: number
  • predicate: (arena: this, id: number) => boolean

    called with the arena and the token id

Returns number | null

Search a token and its descendants, or the value tokens of a node and their descendants, and return the first match

Parameters

  • node: number

    node or token id

  • matcher: AstValueMatcher

    called with the arena and the token id

Returns number | null

the token id or null

Import an object: an AstArenaNode or a plain object (PlainAstNode, PlainToken).

  • importing a view of this arena is a noop: its node id is returned, the node is not copied,
  • a view of another arena is copied with its descendants (see import),
  • a plain object is allocated in the arena. chi, val, l, r, ... are created recursively, they can be node ids, views or plain objects.

Parameters

Returns number

the node id

number of nodes the columns can hold before the arena grows. see getLastId for the last allocated id

Returns number

Parameters

  • id: number
  • index: number

Returns number | null

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns ErrorDescription[] | null

first child of a node. 0 when the node has no children

Parameters

  • id: number

Returns number

first token of the token list of a node or of a token (declaration value, selector / prelude tokens, function arguments). 0 when the list is empty

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

fraction token of a numeric token

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

last allocated node id. the ids of the arena are in the range 1 ... getLastId(), the detached nodes included

Returns number

last token of the token list of a node or of a token. 0 when the list is empty

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number[] | null

source location

Parameters

  • id: number

Returns SourceLocation | null

Parameters

  • id: number

Returns string

next sibling of a node or of a token. 0 for the last node / token of the list

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

previous sibling of a node or of a token. 0 for the first node / token of the list

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number[] | null

rule selector

Parameters

  • id: number

Returns string

source id of the node location

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

Parameters

  • id: number

Returns number

validation state bits

Parameters

  • id: number

Returns EnumAstNodeStatus

number of interned strings

Returns number

token at the given position of the token list

Parameters

  • id: number
  • index: number

Returns number | null

Parameters

  • id: number

Returns EnumToken

Parameters

  • id: number

Returns string

Parameters

  • id: number

Returns string

node that owns a value token: the declaration, the rule or the at-rule. 0 when the token is detached

Parameters

  • id: number

Returns number

parent of a value token: the node or the token that owns the token list, or the structured token that owns the field (the field list token is skipped). 0 when the token is detached

Parameters

  • id: number

Returns number

true if the node has a block (at-rules) or a children list

Parameters

  • id: number

Returns boolean

true if the field exists and is not empty

Parameters

Returns boolean

Parameters

  • id: number
  • flag: number

Returns boolean

true if the numeric token value is a fraction

Parameters

  • id: number

Returns boolean

true if the node has a source location

Parameters

  • id: number

Returns boolean

copy a node or a token of another arena into this arena

Parameters

  • source: AstArena
  • id: number
  • deep: boolean = true

    copy the children. defaults to true

Returns number

initialize the arena from exported properties and column buffers

Parameters

Returns void

index of a child in its parent's children (or tokens) list

Parameters

  • id: number

Returns number

insert nodes after a child

Parameters

  • reference: number
  • …nodes: number[]

Returns void

insert nodes before a child

Parameters

  • reference: number
  • …nodes: number[]

Returns void

Interns a string and returns its unique ID. If the string has already been interned, it returns the existing ID.

Parameters

  • str: string

Returns number

true if the node is invalid

Parameters

  • id: number

Returns boolean

true if the node is marked, see mark

Parameters

  • id: number

Returns boolean

true if the token is a numeric token (number, dimension, percentage, ...)

Parameters

  • id: number

Returns boolean

mark nodes to be released or trimmed later, see release and trim. the library never releases nor trims the arena by itself

Parameters

  • …ids: number[]

Returns void

move the children of a node into another node, in order

Parameters

  • from: number
  • to: number
  • before: number = 0

    the children are inserted before this child of to. they are appended when 0

Returns void

create an ast node from a plain object

Parameters

Returns number

numerator of a fraction token

Parameters

  • id: number

Returns number

prepend children

Parameters

  • id: number
  • …nodes: number[]

Returns void

prepend tokens to the token list

Parameters

  • id: number
  • …tokens: number[]

Returns void

recycle a detached leaf node (no parent, no children, no tokens) that is no longer referenced: its id is reused by the next allocation. the record is zeroed, so a stale reference reads an empty node

Parameters

  • id: number

Returns void

release nodes: detach them and drop their data (interned strings, errors). node ids are never reused: the memory is reclaimed by trim

Parameters

  • Optionalid: number

    the node to release. every marked node (and its descendants) is released when omitted

  • deep: boolean = false

    release the children and the tokens too

Returns void

replace a child with other nodes. the node itself may be part of the replacement

Parameters

  • id: number
  • …nodes: number[]

Returns void

Internal

replace the nesting selector '&' of a selector

Parameters

  • input: string
  • replace: string

Returns string

Parameters

  • selector: string
  • replace: string

Returns string

replace a token by other tokens in its parent token list

Parameters

  • id: number
  • …tokens: number[]

Returns void

reset a token to a new type. the values, the token list and the fields are dropped

Parameters

  • id: number
  • typ: EnumToken
  • Optionalval: string | number | null
  • Optionalunit: string | null

Returns void

Parameters

  • newSize: number

Returns void

Parameters

  • id: number

Returns string

set node data for a given id. The first argument is the id, the second is the type, the third is the string value, the fourth is the numeric value, and the fifth is the unit.

Parameters

Returns void

set node data for a given id. The first argument is the id, the second is the type, the third is the string value, the fourth is the numeric value, and the fifth is the unit.

Parameters

  • id: number
  • type: EnumToken
  • stringValue: number

Returns void

set node data for a given id. The first argument is the id, the second is the type, the third is the string value, and the fourth is the numeric value.

Parameters

  • id: number
  • type: EnumToken
  • stringValue: number
  • numericValue: number

Returns void

set node data for a given id. The first argument is the id, the second is the type, the third is the string value, the fourth is the numeric value, and the fifth is the unit.

Parameters

  • id: number
  • type: EnumToken
  • stringValue: number
  • numericValue: number
  • unit: number

Returns void

replace the child at the given index. the node is appended when the index is out of range

Parameters

  • id: number
  • index: number
  • child: number

Returns void

replace the children. same as setChildren with an array

Parameters

  • id: number
  • children: number[]

Returns void

Parameters

  • id: number
  • …children: number[]

Returns void

Parameters

  • id: number
  • colorType: number

Returns void

Parameters

Returns void

set the tokens of a structured token field

Parameters

Returns void

replace the first child

Parameters

  • id: number
  • firstChildId: number

Returns void

replace the first token

Parameters

  • id: number
  • firstTokenId: number

Returns void

Parameters

  • id: number
  • flags: number

Returns void

set the fraction value of a numeric token. the numeric value is set to the fraction value

Parameters

  • id: number
  • fraction: number | null

    fraction token id or null

Returns void

replace the last child

Parameters

  • id: number
  • lastChildId: number

Returns void

Parameters

  • id: number
  • …children: number[]

Returns void

set the source location

Parameters

  • id: number
  • srcId: number | null | undefined

    source id

  • sta: number | null | undefined

    start offset

  • end: number | null | undefined

    end offset

Returns void

Parameters

  • id: number
  • nameId: number

Returns void

set the at-rule / declaration name

Parameters

  • id: number
  • nam: string

Returns void

insert a node after another one

Parameters

  • id: number
  • nextSiblingId: number

Returns void

Parameters

  • id: number
  • numericValue: number

Returns void

Parameters

  • id: number
  • opId: number

Returns void

Parameters

  • id: number
  • op2Id: number

Returns void

Parameters

  • id: number
  • parentId: number

Returns void

insert a node before another one

Parameters

  • id: number
  • previousSiblingId: number

Returns void

Parameters

  • id: number
  • rightId: null

Returns void

Parameters

  • id: number
  • …rightId: number[]

Returns void

set the rule selector

Parameters

  • id: number
  • sel: string

Returns void

Parameters

  • id: number
  • sourceId: number
  • start: number
  • end: number

Returns void

Parameters

  • id: number
  • start: number

Returns void

Parameters

  • id: number
  • end: number

Returns void

set the validation state bits

Parameters

Returns void

set the string value of a token (val)

Parameters

  • id: number
  • value: string

Returns void

replace the token list. same as setTokens with an array

Parameters

  • id: number
  • tokens: number[]

Returns void

set the location of a token from the tokenizer values. the source index is the index of the source id in the sources table

Parameters

  • id: number
  • sourceIndex: number
  • sta: number
  • end: number

Returns void

Parameters

  • id: number
  • …children: number[]

Returns void

Parameters

Returns void

Parameters

  • id: number
  • unit: number

Returns void

set the unit of a token

Parameters

  • id: number
  • unit: string | null

Returns void

Parameters

  • id: number
  • valueId: number

Returns void

set the at-rule prelude / comment string value

Parameters

  • id: number
  • val: string

Returns void

the children of the parent of a node, the node included

Parameters

  • id: number
  • Optionalfilter: (arena: this, id: number) => boolean

    called with the arena and the node id

Returns number[]

index of a source id in the sources table

Parameters

  • srcId: number

Returns number

set the location from the start of a node to the end of another one

Parameters

  • id: number
  • start: number
  • end: number

Returns void

Parameters

  • node: number
  • key: "val" | "nam"
  • string: string

Returns boolean

string value of a token (val)

Parameters

  • id: number

Returns string

direct value tokens of a node or a token: the token list, then the tokens of the structured fields and the child tokens (fractions, unary expressions)

Parameters

  • id: number

Returns number[]

get a token that can be attached to a new parent: the token itself when it is detached, a deep clone otherwise. a token can only belong to one token list

Parameters

  • token: number

Returns number

number of tokens in the token list

Parameters

  • id: number

Returns number

create a token from a plain object

Parameters

Returns number

token ids of the token list: the declaration values, the selector / prelude tokens, the function arguments

Parameters

  • id: number
  • Optionalfilter: (arena: this, id: number) => boolean

    called with the arena and the token id

Returns number[]

export a token as a plain object (deep copy)

Parameters

  • id: number

Returns PlainToken

Object view of a node or a token: an AstArenaNode. The view does not copy the node: its properties read and write the arena. Importing the view in this arena (fromObject, visitor results, setters of the views) is a noop

function visitor(arena: AstArena, id: number) {

const node = arena.toObject(id);

console.log(node.typ, node.nam, node.val);
}

Parameters

  • id: number

    node or token id

Returns AstArenaNode

export a node or a token as a plain object (deep copy). JSON.stringify() of an AstArenaNode returns the plain object

Parameters

  • id: number

Returns PlainAstNode | PlainToken

reclaim the memory: release the marked nodes, then drop the nodes that are not reachable from the root and renumber the remaining ones, see compact. the ids obtained before the call are no longer valid

Parameters

  • Optionalerrors: ErrorDescription[] | null

    error descriptions whose node is remapped

Returns Uint32Array

mapping of the old ids to the new ids (0 when the node was dropped)

type of a node or a token. null when the id is null

Parameters

  • id: number | null | undefined

Returns EnumToken | null

Internal

call the visitor for the tokens and their children, in the order of walkValues (the children of a token are read after the visitor returns). no iterator or stack is created: use it when the visitor is not a closure

Parameters

  • tokens: number[]
  • visitor: (arena: this, token: number) => void

Returns void

Walk the ast nodes: the node and its descendants, in document order. The iterator returns node ids (and value tokens when attributes is set). The children of a node are read when the next node is requested: the current node can be modified or detached by the caller.

import {EnumToken, transform, WalkerOptionEnum} from '@tbela99/css-parser';

const result = await transform(css);
const arena = result.arena;

for (const node of arena.walk(result.ast)) {

console.log(EnumToken[arena.getType(node)], arena.getParent(node));
}

// the filter controls the walk, see WalkerOptionEnum
function filter(arena: AstArena, node: number) {

if (arena.getType(node) == EnumToken.RuleNodeType && arena.getSelector(node).includes('html')) {

// skip the children of the current node
return WalkerOptionEnum.IgnoreChildren;
}
}

for (const node of arena.walk(result.ast, filter)) {

console.log(EnumToken[arena.getType(node)]);
}

Parameters

  • node: number

    initial node id (or value token)

  • Optionalfilter: WalkerFilter | WalkerOptions | null

    filter function or walker options

  • Optionalreverse: boolean

    walk in reverse order

Returns IterableIterator<number>

Walk value tokens and their descendants (function arguments, structured token fields, ...), in document order. The iterator returns token ids. The children of a token are read when the next token is requested: the current token can be modified or replaced by the caller.

import {EnumToken, transform} from '@tbela99/css-parser';

const css = `
body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
`;

const result = await transform(css);
const arena = result.arena;
const declaration = arena.getFirstChild(arena.getFirstChild(result.ast));

// walk the value tokens of the declaration in reverse order
for (const value of arena.walkValues(declaration, null, true)) {

console.error([EnumToken[arena.getType(value)], arena.getValue(value)]);
}

Parameters

  • tokens: number | number[]

    token ids, or a node / token id: its value tokens are walked

  • Optionalfilter: WalkerValueFilter | WalkerValueOptions | null

    filter function, called with the arena, the token id and the event, or filter options

  • Optionalreverse: boolean

    walk in reverse order

Returns IterableIterator<number>

Create an arena from the objects produced by Arena.toTransferableArenaObject. The column buffers are used as is (zero copy): the typed arrays are views on the given buffers.

Type Parameters

Parameters

Returns T

an Arena or an AstArena depending on the class the method is called on

Export the arena as a structured-cloneable object and the list of its column buffers, to send an arena to a worker (or back to the main thread) without copying the node data.

The properties (strings, errors, ...) are cloned by postMessage(), the column buffers are moved when they are passed as the transfer list: the source arena must not be used afterwards (its columns are detached). The buffers are copied instead when the transfer list is omitted.

// main thread
const [properties, transferables] = AstArena.toTransferableArenaObject(result.arena);

worker.postMessage({ ast: result.ast, properties, transferables }, transferables);

// worker
const { ast, properties, transferables } = event.data;
const arena = AstArena.fromTransferableArenaObjects(properties, transferables);

Parameters

Returns [ArenaProperties, ArenaTransferables]

the arena properties and the column buffers, see ArenaProperties and ArenaTransferables

colorType: Uint8Array

color type. previously use as (node as ColorToken).kin

current: number = 1

last allocated node id. the next node is allocated with the id current + 1 (unless a recycled id is available). 0 is never allocated: it means "no node"

dataTypes: Uint8Array

node EnumToken type array

errors: Map<number, ErrorDescription[]> = ...

error cache

firstChild: Uint32Array

first child node id array

firstToken: Uint32Array

first token node id array

flags: Uint32Array

node flags

freeList: number = 0

head of the list of recycled node ids. the list is linked through the nextSibling column, see recycle

lastChild: Uint32Array

last child node id array

lastToken: Uint32Array

last token node id array

name: Uint32Array

node name string interner id array. used to store (node as AstRule | AstDeclaration | AstKeyframesAtRule).nam and (node as AstRule | AstKeyframesRule).sel

nextSibling: Uint32Array

next sibling node id array

numericValue: Float64Array

node numeric value array. previously used as (node as NumberToken | DimensionToken).val

optimized: (OptimizedSelector | null | undefined)[] = []

optimized selector (minification cache). sparse: only rules have an entry

parents: Uint32Array

parent node id array

previousSibling: Uint32Array

previous sibling node id array

raw: (RawSelectorTokens | null | undefined)[] = []

raw selector (minification cache). sparse: only rules have an entry

root: number = 1

root node

sources: number[] = []

source ids. spans store the index in this table (8 bits)

spans: BigUint64Array

token spans. 8 bits for source type. 28 bits for start position, 28 bits for end position. This allows us to store the start and end positions of tokens in a single 64-bit integer, which is more efficient than storing them separately.

spans32: Uint32Array

32 bits view of the spans: the low word holds the end position and the 4 low bits of the start position, the high word holds the 24 high bits of the start position and the source

stringIds: Map<string, number> = ...

string interner identifiers

strings: string[] = []

string interner values

stringValue: Uint32Array

node string value index array.

unit: Uint32Array

node unit string interner id array. previously used as (node as DimensionToken).unit