Function parse_sync_raw

Source
pub unsafe fn parse_sync_raw(
    filename: String,
    buffer: Uint8Array,
    source_len: u32,
    options: Option<ParserOptions>,
)
Expand description

Parses AST into provided Uint8Array buffer.

Source text must be written into the start of the buffer, and its length (in UTF-8 bytes) provided as source_len.

This function will parse the source, and write the AST into the buffer, starting at the end.

It also writes to the very end of the buffer the offset of Program within the buffer.

Caller can deserialize data from the buffer on JS side.

§SAFETY

Caller must ensure:

  • Source text is written into start of the buffer.
  • Source text’s UTF-8 byte length is source_len.
  • The 1st source_len bytes of the buffer comprises a valid UTF-8 string.

If source text is originally a JS string on JS side, and converted to a buffer with Buffer.from(str) or new TextEncoder().encode(str), this guarantees it’s valid UTF-8.

§Panics

Panics if source text is too long, or AST takes more memory than is available in the buffer.