🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

View file

@ -0,0 +1,77 @@
/**
* @this {TokenizeContext}
* Context.
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful
* @param {TokenType} type
* Token type for whole (`{}`).
* @param {TokenType} markerType
* Token type for the markers (`{`, `}`).
* @param {TokenType} chunkType
* Token type for the value (`1`).
* @param {Acorn | null | undefined} [acorn]
* Object with `acorn.parse` and `acorn.parseExpressionAt`.
* @param {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn.
* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* @returns {State}
*/
export function factoryMdxExpression(
this: import('micromark-util-types').TokenizeContext,
effects: Effects,
ok: State,
type: TokenType,
markerType: TokenType,
chunkType: TokenType,
acorn?: Acorn | null | undefined,
acornOptions?: AcornOptions | null | undefined,
addResult?: boolean | null | undefined,
spread?: boolean | null | undefined,
allowEmpty?: boolean | null | undefined,
allowLazy?: boolean | null | undefined
): State
export type Program = import('estree').Program
export type Acorn = import('micromark-util-events-to-acorn').Acorn
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions
export type Effects = import('micromark-util-types').Effects
export type Point = import('micromark-util-types').Point
export type State = import('micromark-util-types').State
export type TokenType = import('micromark-util-types').TokenType
export type TokenizeContext = import('micromark-util-types').TokenizeContext
/**
* Good result.
*/
export type MdxSignalOk = {
/**
* Type.
*/
type: 'ok'
/**
* Value.
*/
estree: Program | undefined
}
/**
* Bad result.
*/
export type MdxSignalNok = {
/**
* Type.
*/
type: 'nok'
/**
* Value.
*/
message: VFileMessage
}
export type MdxSignal = MdxSignalOk | MdxSignalNok
import {VFileMessage} from 'vfile-message'

View file

@ -0,0 +1,347 @@
/**
* @typedef {import('estree').Program} Program
* @typedef {import('micromark-util-events-to-acorn').Acorn} Acorn
* @typedef {import('micromark-util-events-to-acorn').AcornOptions} AcornOptions
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenType} TokenType
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
/**
* @typedef MdxSignalOk
* Good result.
* @property {'ok'} type
* Type.
* @property {Program | undefined} estree
* Value.
*
* @typedef MdxSignalNok
* Bad result.
* @property {'nok'} type
* Type.
* @property {VFileMessage} message
* Value.
*
* @typedef {MdxSignalOk | MdxSignalNok} MdxSignal
*/
import {markdownLineEnding} from 'micromark-util-character'
import {eventsToAcorn} from 'micromark-util-events-to-acorn'
import {codes} from 'micromark-util-symbol/codes.js'
import {types} from 'micromark-util-symbol/types.js'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {ok as assert} from 'uvu/assert'
import {VFileMessage} from 'vfile-message'
/**
* @this {TokenizeContext}
* Context.
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful
* @param {TokenType} type
* Token type for whole (`{}`).
* @param {TokenType} markerType
* Token type for the markers (`{`, `}`).
* @param {TokenType} chunkType
* Token type for the value (`1`).
* @param {Acorn | null | undefined} [acorn]
* Object with `acorn.parse` and `acorn.parseExpressionAt`.
* @param {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn.
* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* @returns {State}
*/
// eslint-disable-next-line max-params
export function factoryMdxExpression(
effects,
ok,
type,
markerType,
chunkType,
acorn,
acornOptions,
addResult,
spread,
allowEmpty,
allowLazy
) {
const self = this
const eventStart = this.events.length + 3 // Add main and marker token
let size = 0
/** @type {Point} */
let pointStart
/** @type {Error} */
let lastCrash
return start
/**
* Start of an MDX expression.
*
* ```markdown
* > | a {Math.PI} c
* ^
* ```
*
* @type {State}
*/
function start(code) {
assert(code === codes.leftCurlyBrace, 'expected `{`')
effects.enter(type)
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
pointStart = self.now()
return before
}
/**
* Before data.
*
* ```markdown
* > | a {Math.PI} c
* ^
* ```
*
* @type {State}
*/
function before(code) {
if (code === codes.eof) {
throw (
lastCrash ||
new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
)
)
}
if (markdownLineEnding(code)) {
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return eolAfter
}
if (code === codes.rightCurlyBrace && size === 0) {
/** @type {MdxSignal} */
const next = acorn
? mdxExpressionParse.call(
self,
acorn,
acornOptions,
eventStart,
pointStart,
allowEmpty || false,
spread || false
)
: {type: 'ok', estree: undefined}
if (next.type === 'ok') {
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
const token = effects.exit(type)
if (addResult && next.estree) {
Object.assign(token, {estree: next.estree})
}
return ok
}
lastCrash = next.message
effects.enter(chunkType)
effects.consume(code)
return inside
}
effects.enter(chunkType)
return inside(code)
}
/**
* In data.
*
* ```markdown
* > | a {Math.PI} c
* ^
* ```
*
* @type {State}
*/
function inside(code) {
if (
(code === codes.rightCurlyBrace && size === 0) ||
code === codes.eof ||
markdownLineEnding(code)
) {
effects.exit(chunkType)
return before(code)
}
// Dont count if gnostic.
if (code === codes.leftCurlyBrace && !acorn) {
size += 1
} else if (code === codes.rightCurlyBrace) {
size -= 1
}
effects.consume(code)
return inside
}
/**
* After eol.
*
* ```markdown
* | a {b +
* > | c} d
* ^
* ```
*
* @type {State}
*/
function eolAfter(code) {
const now = self.now()
// Lazy continuation in a flow expression (or flow tag) is a syntax error.
if (
now.line !== pointStart.line &&
!allowLazy &&
self.parser.lazy[now.line]
) {
// `markdown-rs` uses:
// ``Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc``.
throw new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
)
}
// Idea: investigate if wed need to use more complex stripping.
// Take this example:
//
// ```markdown
// > aaa <b c={`
// > d
// > `} /> eee
// ```
//
// The block quote takes one space from each line, the paragraph doesnt.
// The intent above is *perhaps* for the split to be as `>␠␠|␠␠␠␠|d`,
// Currently, we *dont* do anything at all, its `>␠|␠␠␠␠␠|d` instead.
//
// Note: we used to have some handling here, and `markdown-rs` still does,
// which should be removed.
return before(code)
}
}
/**
* Mix of `markdown-rs`s `parse_expression` and `MdxExpressionParse`
* functionality, to wrap our `eventsToAcorn`.
*
* In the future, the plan is to realise the rust way, which allows arbitrary
* parsers.
*
* @this {TokenizeContext}
* @param {Acorn} acorn
* @param {AcornOptions | null | undefined} acornOptions
* @param {number} eventStart
* @param {Point} pointStart
* @param {boolean} allowEmpty
* @param {boolean} spread
* @returns {MdxSignal}
*/
// eslint-disable-next-line max-params
function mdxExpressionParse(
acorn,
acornOptions,
eventStart,
pointStart,
allowEmpty,
spread
) {
// Gnostic mode: parse w/ acorn.
const result = eventsToAcorn(this.events.slice(eventStart), {
acorn,
acornOptions,
start: pointStart,
expression: true,
allowEmpty,
prefix: spread ? '({' : '',
suffix: spread ? '})' : ''
})
const estree = result.estree
// Get the spread value.
if (spread && estree) {
// Should always be the case as we wrap in `d={}`
assert(estree.type === 'Program', 'expected program')
const head = estree.body[0]
assert(head, 'expected body')
// Can occur in some complex attributes.
/* c8 ignore next 11 */
if (
head.type !== 'ExpressionStatement' ||
head.expression.type !== 'ObjectExpression'
) {
throw new VFileMessage(
'Unexpected `' +
head.type +
'` in code: expected an object spread (`{...spread}`)',
positionFromEstree(head).start,
'micromark-extension-mdx-expression:non-spread'
)
} else if (head.expression.properties[1]) {
throw new VFileMessage(
'Unexpected extra content in spread: only a single spread is supported',
positionFromEstree(head.expression.properties[1]).start,
'micromark-extension-mdx-expression:spread-extra'
)
} else if (
head.expression.properties[0] &&
head.expression.properties[0].type !== 'SpreadElement'
) {
throw new VFileMessage(
'Unexpected `' +
head.expression.properties[0].type +
'` in code: only spread elements are supported',
positionFromEstree(head.expression.properties[0]).start,
'micromark-extension-mdx-expression:non-spread'
)
}
}
if (result.error) {
return {
type: 'nok',
message: new VFileMessage(
'Could not parse expression with acorn: ' + result.error.message,
{
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
'micromark-extension-mdx-expression:acorn'
)
}
}
return {type: 'ok', estree}
}

View file

@ -0,0 +1,77 @@
/**
* @this {TokenizeContext}
* Context.
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful
* @param {TokenType} type
* Token type for whole (`{}`).
* @param {TokenType} markerType
* Token type for the markers (`{`, `}`).
* @param {TokenType} chunkType
* Token type for the value (`1`).
* @param {Acorn | null | undefined} [acorn]
* Object with `acorn.parse` and `acorn.parseExpressionAt`.
* @param {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn.
* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* @returns {State}
*/
export function factoryMdxExpression(
this: import('micromark-util-types').TokenizeContext,
effects: Effects,
ok: State,
type: TokenType,
markerType: TokenType,
chunkType: TokenType,
acorn?: Acorn | null | undefined,
acornOptions?: AcornOptions | null | undefined,
addResult?: boolean | null | undefined,
spread?: boolean | null | undefined,
allowEmpty?: boolean | null | undefined,
allowLazy?: boolean | null | undefined
): State
export type Program = import('estree').Program
export type Acorn = import('micromark-util-events-to-acorn').Acorn
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions
export type Effects = import('micromark-util-types').Effects
export type Point = import('micromark-util-types').Point
export type State = import('micromark-util-types').State
export type TokenType = import('micromark-util-types').TokenType
export type TokenizeContext = import('micromark-util-types').TokenizeContext
/**
* Good result.
*/
export type MdxSignalOk = {
/**
* Type.
*/
type: 'ok'
/**
* Value.
*/
estree: Program | undefined
}
/**
* Bad result.
*/
export type MdxSignalNok = {
/**
* Type.
*/
type: 'nok'
/**
* Value.
*/
message: VFileMessage
}
export type MdxSignal = MdxSignalOk | MdxSignalNok
import {VFileMessage} from 'vfile-message'

338
node_modules/micromark-factory-mdx-expression/index.js generated vendored Normal file
View file

@ -0,0 +1,338 @@
/**
* @typedef {import('estree').Program} Program
* @typedef {import('micromark-util-events-to-acorn').Acorn} Acorn
* @typedef {import('micromark-util-events-to-acorn').AcornOptions} AcornOptions
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenType} TokenType
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
/**
* @typedef MdxSignalOk
* Good result.
* @property {'ok'} type
* Type.
* @property {Program | undefined} estree
* Value.
*
* @typedef MdxSignalNok
* Bad result.
* @property {'nok'} type
* Type.
* @property {VFileMessage} message
* Value.
*
* @typedef {MdxSignalOk | MdxSignalNok} MdxSignal
*/
import {markdownLineEnding} from 'micromark-util-character'
import {eventsToAcorn} from 'micromark-util-events-to-acorn'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {VFileMessage} from 'vfile-message'
/**
* @this {TokenizeContext}
* Context.
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful
* @param {TokenType} type
* Token type for whole (`{}`).
* @param {TokenType} markerType
* Token type for the markers (`{`, `}`).
* @param {TokenType} chunkType
* Token type for the value (`1`).
* @param {Acorn | null | undefined} [acorn]
* Object with `acorn.parse` and `acorn.parseExpressionAt`.
* @param {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn.
* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* @returns {State}
*/
// eslint-disable-next-line max-params
export function factoryMdxExpression(
effects,
ok,
type,
markerType,
chunkType,
acorn,
acornOptions,
addResult,
spread,
allowEmpty,
allowLazy
) {
const self = this
const eventStart = this.events.length + 3 // Add main and marker token
let size = 0
/** @type {Point} */
let pointStart
/** @type {Error} */
let lastCrash
return start
/**
* Start of an MDX expression.
*
* ```markdown
* > | a {Math.PI} c
* ^
* ```
*
* @type {State}
*/
function start(code) {
effects.enter(type)
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
pointStart = self.now()
return before
}
/**
* Before data.
*
* ```markdown
* > | a {Math.PI} c
* ^
* ```
*
* @type {State}
*/
function before(code) {
if (code === null) {
throw (
lastCrash ||
new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
)
)
}
if (markdownLineEnding(code)) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return eolAfter
}
if (code === 125 && size === 0) {
/** @type {MdxSignal} */
const next = acorn
? mdxExpressionParse.call(
self,
acorn,
acornOptions,
eventStart,
pointStart,
allowEmpty || false,
spread || false
)
: {
type: 'ok',
estree: undefined
}
if (next.type === 'ok') {
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
const token = effects.exit(type)
if (addResult && next.estree) {
Object.assign(token, {
estree: next.estree
})
}
return ok
}
lastCrash = next.message
effects.enter(chunkType)
effects.consume(code)
return inside
}
effects.enter(chunkType)
return inside(code)
}
/**
* In data.
*
* ```markdown
* > | a {Math.PI} c
* ^
* ```
*
* @type {State}
*/
function inside(code) {
if (
(code === 125 && size === 0) ||
code === null ||
markdownLineEnding(code)
) {
effects.exit(chunkType)
return before(code)
}
// Dont count if gnostic.
if (code === 123 && !acorn) {
size += 1
} else if (code === 125) {
size -= 1
}
effects.consume(code)
return inside
}
/**
* After eol.
*
* ```markdown
* | a {b +
* > | c} d
* ^
* ```
*
* @type {State}
*/
function eolAfter(code) {
const now = self.now()
// Lazy continuation in a flow expression (or flow tag) is a syntax error.
if (
now.line !== pointStart.line &&
!allowLazy &&
self.parser.lazy[now.line]
) {
// `markdown-rs` uses:
// ``Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc``.
throw new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
)
}
// Idea: investigate if wed need to use more complex stripping.
// Take this example:
//
// ```markdown
// > aaa <b c={`
// > d
// > `} /> eee
// ```
//
// The block quote takes one space from each line, the paragraph doesnt.
// The intent above is *perhaps* for the split to be as `>␠␠|␠␠␠␠|d`,
// Currently, we *dont* do anything at all, its `>␠|␠␠␠␠␠|d` instead.
//
// Note: we used to have some handling here, and `markdown-rs` still does,
// which should be removed.
return before(code)
}
}
/**
* Mix of `markdown-rs`s `parse_expression` and `MdxExpressionParse`
* functionality, to wrap our `eventsToAcorn`.
*
* In the future, the plan is to realise the rust way, which allows arbitrary
* parsers.
*
* @this {TokenizeContext}
* @param {Acorn} acorn
* @param {AcornOptions | null | undefined} acornOptions
* @param {number} eventStart
* @param {Point} pointStart
* @param {boolean} allowEmpty
* @param {boolean} spread
* @returns {MdxSignal}
*/
// eslint-disable-next-line max-params
function mdxExpressionParse(
acorn,
acornOptions,
eventStart,
pointStart,
allowEmpty,
spread
) {
// Gnostic mode: parse w/ acorn.
const result = eventsToAcorn(this.events.slice(eventStart), {
acorn,
acornOptions,
start: pointStart,
expression: true,
allowEmpty,
prefix: spread ? '({' : '',
suffix: spread ? '})' : ''
})
const estree = result.estree
// Get the spread value.
if (spread && estree) {
// Should always be the case as we wrap in `d={}`
const head = estree.body[0]
// Can occur in some complex attributes.
/* c8 ignore next 11 */
if (
head.type !== 'ExpressionStatement' ||
head.expression.type !== 'ObjectExpression'
) {
throw new VFileMessage(
'Unexpected `' +
head.type +
'` in code: expected an object spread (`{...spread}`)',
positionFromEstree(head).start,
'micromark-extension-mdx-expression:non-spread'
)
} else if (head.expression.properties[1]) {
throw new VFileMessage(
'Unexpected extra content in spread: only a single spread is supported',
positionFromEstree(head.expression.properties[1]).start,
'micromark-extension-mdx-expression:spread-extra'
)
} else if (
head.expression.properties[0] &&
head.expression.properties[0].type !== 'SpreadElement'
) {
throw new VFileMessage(
'Unexpected `' +
head.expression.properties[0].type +
'` in code: only spread elements are supported',
positionFromEstree(head.expression.properties[0]).start,
'micromark-extension-mdx-expression:non-spread'
)
}
}
if (result.error) {
return {
type: 'nok',
message: new VFileMessage(
'Could not parse expression with acorn: ' + result.error.message,
{
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
'micromark-extension-mdx-expression:acorn'
)
}
}
return {
type: 'ok',
estree
}
}

View file

@ -0,0 +1 @@
../../../uvu/bin.js

View file

@ -0,0 +1,61 @@
{
"name": "micromark-factory-mdx-expression",
"version": "1.0.9",
"description": "micromark factory to parse MDX expressions (found in JSX attributes, flow, text)",
"license": "MIT",
"keywords": [
"micromark",
"factory",
"mdx",
"expression"
],
"repository": "https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-factory-mdx-expression",
"bugs": "https://github.com/micromark/micromark-extension-mdx-expression/issues",
"funding": [
{
"type": "GitHub Sponsors",
"url": "https://github.com/sponsors/unifiedjs"
},
{
"type": "OpenCollective",
"url": "https://opencollective.com/unified"
}
],
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "dev/index.d.ts",
"files": [
"dev/",
"index.d.ts",
"index.js"
],
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"dependencies": {
"@types/estree": "^1.0.0",
"micromark-util-character": "^1.0.0",
"micromark-util-events-to-acorn": "^1.0.0",
"micromark-util-symbol": "^1.0.0",
"micromark-util-types": "^1.0.0",
"unist-util-position-from-estree": "^1.0.0",
"uvu": "^0.5.0",
"vfile-message": "^3.0.0"
},
"scripts": {
"build": "micromark-build"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

215
node_modules/micromark-factory-mdx-expression/readme.md generated vendored Normal file
View file

@ -0,0 +1,215 @@
# micromark-factory-mdx-expression
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
[micromark][] factory to parse MDX expressions (found in JSX attributes, flow,
text).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factoryMdxExpression(…)`](#factorymdxexpression)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install micromark-factory-mdx-expression
```
In Deno with [`esm.sh`][esmsh]:
```js
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@1?bundle'
</script>
```
## Use
```js
import {ok as assert} from 'uvu/assert'
import {factoryMdxExpression} from 'micromark-factory-mdx-expression'
import {codes} from 'micromark-util-symbol/codes'
// A micromark tokenizer that uses the factory:
/** @type {Tokenizer} */
function tokenizeFlowExpression(effects, ok, nok) {
return start
// …
/** @type {State} */
function start(code) {
assert(code === codes.leftCurlyBrace, 'expected `{`')
return factoryMdxExpression.call(
self,
effects,
factorySpace(effects, after, types.whitespace),
'mdxFlowExpression',
'mdxFlowExpressionMarker',
'mdxFlowExpressionChunk',
acorn,
acornOptions,
addResult,
spread,
allowEmpty
)(code)
}
// …
}
```
## API
This module exports the identifier
[`factoryMdxExpression`][api-factory-mdx-expression].
There is no default export.
The export map supports the [`development` condition][development].
Run `node --conditions development module.js` to get instrumented dev code.
Without this condition, production code is loaded.
### `factoryMdxExpression(…)`
###### Parameters
* `effects` (`Effects`)
— context
* `ok` (`State`)
— state switched to when successful
* `type` (`string`)
— token type for whole (`{}`)
* `markerType` (`string`)
— token type for the markers (`{`, `}`)
* `chunkType` (`string`)
— token type for the value (`1`)
* `acorn` (`Acorn`)
— object with `acorn.parse` and `acorn.parseExpressionAt`
* `acornOptions` ([`AcornOptions`][acorn-options])
— configuration for acorn
* `boolean` (`addResult`, default: `false`)
— add `estree` to token
* `boolean` (`spread`, default: `false`)
— support a spread (`{...a}`) only
* `boolean` (`allowEmpty`, default: `false`)
— support an empty expression
* `boolean` (`allowLazy`, default: `false`)
— support lazy continuation of an expression
###### Returns
`State`.
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`Acorn`][acorn] and
[`AcornOptions`][acorn-options].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 16+.
Our projects sometimes work with older versions, but this is not guaranteed.
These extensions work with `micromark` version 3+.
## Security
This package is safe.
## Contribute
See [`contributing.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 conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/micromark/micromark-extension-mdx-expression/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark-extension-mdx-expression/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-mdx-expression.svg
[coverage]: https://codecov.io/github/micromark/micromark-extension-mdx-expression
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-mdx-expression.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-mdx-expression
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-mdx-expression.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-mdx-expression
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark-extension-mdx-expression/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[typescript]: https://www.typescriptlang.org
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
[acorn]: https://github.com/acornjs/acorn
[acorn-options]: https://github.com/acornjs/acorn/blob/96c721dbf89d0ccc3a8c7f39e69ef2a6a3c04dfa/acorn/dist/acorn.d.ts#L16
[micromark]: https://github.com/micromark/micromark
[api-factory-mdx-expression]: #micromark-factory-mdx-expression