micromark-util-events-to-acorn
!Buildbuild-badgebuild
!Coveragecoverage-badgecoverage
!Downloadsdownloads-badgedownloads
!Sizesize-badgesize
!Sponsorssponsors-badgeopencollective
!Backersbackers-badgeopencollective
!Chatchat-badgechatmicromark utility to try and parse events with acorn.
Contents
* [`eventsToAcorn(events, options)`](#eventstoacornevents-options)
* [`Options`](#options)
* [`Result`](#result)
Install
This package is ESM onlyesm. In Node.js (version 16+), install with npm:npm install micromark-util-events-to-acorn
In Deno with
esm.sh
esmsh:import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@2'
In browsers with
esm.sh
esmsh:<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 identifiereventsToAcorn
api-events-to-acorn.
There is no default export.The export map supports the
development
conditiondevelopment.
Run node --conditions development module.js
to get instrumented dev code.
Without this condition, production code is loaded.eventsToAcorn(events, options)
Parameters
events
(Array<Event>
)
— events
options
(Options
api-options)
— configuration (required)
Returns
Result (Result
api-result).Options
Configuration (TypeScript type).Fields
— typically `acorn`, object with `parse` and `parseExpressionAt` fields
tokenTypes
(Array<TokenType>
, required)
— names of (void) tokens to consider as data; `'lineEnding'` is always
included
acornOptions
(AcornOptions
acorn-options, optional)
— configuration for `acorn`
start
(Point
, optional, required ifallowEmpty
)
— place where events start
prefix
(string
, default:''
)
— text to place before events
suffix
(string
, default:''
)
— text to place after events
expression
(boolean
, default:false
)
— whether this is a program or expression
allowEmpty
(boolean
, default:false
)
— whether an empty expression is allowed (programs are always allowed to be
empty)
Result
Result (TypeScript type).Fields
— Program
error
(Error
orundefined
)
— error if unparseable
swallow
(boolean
)
— whether the error, if there is one, can be swallowed and more JavaScript
could be valid
Types
This package is fully typed with TypeScript. It exports the additional typesAcorn
acorn,
AcornOptions
acorn-options, Options
api-options, and
Result
api-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
Seecontributing.md
contributing in micromark/.github
health for ways
to get started.
See support.md
support for ways to get help.This project has a code of conductcoc. By interacting with this repository, organisation, or community you agree to abide by its terms.