unified

Project: micromark/micromark-extension-mdx-expression

Package: micromark-util-events-to-acorn@1.2.0

  1. Dependents: 0
  2. micromark utility to try and parse events w/ acorn
  1. micromark 37
  2. mdx 35
  3. expression 8
  4. factory 7

micromark-util-events-to-acorn

Build Coverage Downloads Size Sponsors Backers Chat

micromark utility to try and parse events with acorn.

Contents

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install micromark-util-events-to-acorn

In Deno with esm.sh:

import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@2'

In browsers with esm.sh:

<script type="module">
  import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@2?bundle'
</script>

Use

import {eventsToAcorn} from 'micromark-util-events-to-acorn'

// A factory that uses the utility:
/** @type {Tokenizer} */
function factoryMdxExpression(effects, ok, nok) {
  return start

  // …

    // …

    // Gnostic mode: parse w/ acorn.
    const result = eventsToAcorn(this.events.slice(eventStart), {
      acorn,
      acornOptions,
      start: pointStart,
      expression: true,
      allowEmpty,
      prefix: spread ? '({' : '',
      suffix: spread ? '})' : ''
    })

    // …

  // …
}

API

This module exports the identifier eventsToAcorn. There is no default export.

The export map supports the development condition. Run node --conditions development module.js to get instrumented dev code. Without this condition, production code is loaded.

eventsToAcorn(events, options)

Parameters
Returns

Result (Result).

Options

Configuration (TypeScript type).

Fields

Result

Result (TypeScript type).

Fields

Types

This package is fully typed with TypeScript. It exports the additional types Acorn, AcornOptions, Options, and Result.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, micromark-util-events-to-acorn@^2, compatible with Node.js 16.

This package works with micromark version 3 and later.

Security

This package is safe.

Contribute

See contributing.md in micromark/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer