deploy: v0.12 fix 存档key名

This commit is contained in:
2026-06-24 03:09:02 +00:00
parent 7a08d49fe3
commit e0a5281119
58743 changed files with 7297269 additions and 39505 deletions
+64
View File
@@ -0,0 +1,64 @@
/**
* @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 (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression (default: `false`).
* @returns {State}
*/
export function factoryMdxExpression(this: 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;
/**
* 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 = MdxSignalNok | MdxSignalOk;
import type { Effects } from 'micromark-util-types';
import type { State } from 'micromark-util-types';
import type { TokenType } from 'micromark-util-types';
import type { Acorn } from 'micromark-util-events-to-acorn';
import type { AcornOptions } from 'micromark-util-events-to-acorn';
import type { TokenizeContext } from 'micromark-util-types';
import type { Program } from 'estree';
import { VFileMessage } from 'vfile-message';
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAmDA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,qEAzBW,OAAO,MAEP,KAAK,QAEL,SAAS,cAET,SAAS,aAET,SAAS,UAET,KAAK,GAAG,IAAI,GAAG,SAAS,iBAExB,YAAY,GAAG,IAAI,GAAG,SAAS,cAE/B,OAAO,GAAG,IAAI,GAAG,SAAS,WAE1B,OAAO,GAAG,IAAI,GAAG,SAAS,eAE1B,OAAO,GAAG,IAAI,GAAG,SAAS,cAE1B,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,KAAK,CA6MjB;;;;;;;;UAhRa,IAAI;;;;YAEJ,OAAO,GAAG,SAAS;;;;;;;;;UAKnB,KAAK;;;;aAEL,YAAY;;wBAGb,YAAY,GAAG,WAAW;6BAlB6B,sBAAsB;2BAAtB,sBAAsB;+BAAtB,sBAAsB;2BADpD,gCAAgC;kCAAhC,gCAAgC;qCACF,sBAAsB;6BAFhE,QAAQ;6BA6BP,eAAe"}
+404
View File
@@ -0,0 +1,404 @@
/**
* @import {Program} from 'estree'
* @import {Acorn, AcornOptions} from 'micromark-util-events-to-acorn'
* @import {Effects, Point, State, TokenType, TokenizeContext} from 'micromark-util-types'
*/
/**
* @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 {MdxSignalNok | MdxSignalOk} MdxSignal
*/
import {ok as assert} from 'devlop'
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding, markdownSpace} from 'micromark-util-character'
import {eventsToAcorn} from 'micromark-util-events-to-acorn'
import {codes, types} from 'micromark-util-symbol'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {VFileMessage} from 'vfile-message'
// Tab-size to eat has to be the same as what we serialize as.
// While in some places in markdown thats 4, in JS its more common as 2.
// Which is whats also in `mdast-util-mdx-jsx`:
// <https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/40b951b/lib/index.js#L52>
const indentSize = 2
const trouble =
'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression'
const unexpectedEndOfFileHash =
'#unexpected-end-of-file-in-expression-expected-a-corresponding-closing-brace-for-'
const unexpectedLazyHash =
'#unexpected-lazy-line-in-expression-in-container-expected-line-to-be-prefixed'
const nonSpreadHash =
'#unexpected-type-in-code-expected-an-object-spread-spread'
const spreadExtraHash =
'#unexpected-extra-content-in-spread-only-a-single-spread-is-supported'
const acornHash = '#could-not-parse-expression-with-acorn'
/**
* @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 (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression (default: `false`).
* @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) {
if (lastCrash) throw lastCrash
const error = new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
{
place: self.now(),
ruleId: 'unexpected-eof',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + unexpectedEndOfFileHash
throw error
}
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,
chunkType,
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]
) {
const error = new VFileMessage(
'Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc',
{
place: self.now(),
ruleId: 'unexpected-lazy',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + unexpectedLazyHash
throw error
}
// Note: `markdown-rs` uses `4`, but we use `2`.
//
// Idea: investigate if wed need to use more complex stripping.
// Take this example:
//
// ```markdown
// > aaa <b c={`
// > d
// > `} /> eee
// ```
//
// Currently, the “paragraph” starts at `> | aaa`, so for the next line
// here we split it into `>␠|␠␠|␠␠␠d` (prefix, this indent here,
// expression data).
if (markdownSpace(code)) {
return factorySpace(
effects,
before,
types.linePrefix,
indentSize + 1
)(code)
}
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 {TokenType} chunkType
* @param {number} eventStart
* @param {Point} pointStart
* @param {boolean} allowEmpty
* @param {boolean} spread
* @returns {MdxSignal}
*/
// eslint-disable-next-line max-params
function mdxExpressionParse(
acorn,
acornOptions,
chunkType,
eventStart,
pointStart,
allowEmpty,
spread
) {
// Gnostic mode: parse w/ acorn.
const result = eventsToAcorn(this.events.slice(eventStart), {
acorn,
tokenTypes: [chunkType],
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')
if (
head.type !== 'ExpressionStatement' ||
head.expression.type !== 'ObjectExpression'
) {
const place = positionFromEstree(head)
assert(place, 'expected position')
const error = new VFileMessage(
'Unexpected `' +
head.type +
'` in code: expected an object spread (`{...spread}`)',
{
place: place.start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + nonSpreadHash
throw error
}
if (head.expression.properties[1]) {
const place = positionFromEstree(head.expression.properties[1])
assert(place, 'expected position')
const error = new VFileMessage(
'Unexpected extra content in spread: only a single spread is supported',
{
place: place.start,
ruleId: 'spread-extra',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + spreadExtraHash
throw error
}
if (
head.expression.properties[0] &&
head.expression.properties[0].type !== 'SpreadElement'
) {
const place = positionFromEstree(head.expression.properties[0])
assert(place, 'expected position')
const error = new VFileMessage(
'Unexpected `' +
head.expression.properties[0].type +
'` in code: only spread elements are supported',
{
place: place.start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + nonSpreadHash
throw error
}
}
if (result.error) {
const error = new VFileMessage('Could not parse expression with acorn', {
cause: result.error,
place: {
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
ruleId: 'acorn',
source: 'micromark-extension-mdx-expression'
})
error.url = trouble + acornHash
return {type: 'nok', message: error}
}
return {type: 'ok', estree}
}
+64
View File
@@ -0,0 +1,64 @@
/**
* @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 (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression (default: `false`).
* @returns {State}
*/
export function factoryMdxExpression(this: 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;
/**
* 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 = MdxSignalNok | MdxSignalOk;
import type { Effects } from 'micromark-util-types';
import type { State } from 'micromark-util-types';
import type { TokenType } from 'micromark-util-types';
import type { Acorn } from 'micromark-util-events-to-acorn';
import type { AcornOptions } from 'micromark-util-events-to-acorn';
import type { TokenizeContext } from 'micromark-util-types';
import type { Program } from 'estree';
import { VFileMessage } from 'vfile-message';
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAmDA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,qEAzBW,OAAO,MAEP,KAAK,QAEL,SAAS,cAET,SAAS,aAET,SAAS,UAET,KAAK,GAAG,IAAI,GAAG,SAAS,iBAExB,YAAY,GAAG,IAAI,GAAG,SAAS,cAE/B,OAAO,GAAG,IAAI,GAAG,SAAS,WAE1B,OAAO,GAAG,IAAI,GAAG,SAAS,eAE1B,OAAO,GAAG,IAAI,GAAG,SAAS,cAE1B,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,KAAK,CA6MjB;;;;;;;;UAhRa,IAAI;;;;YAEJ,OAAO,GAAG,SAAS;;;;;;;;;UAKnB,KAAK;;;;aAEL,YAAY;;wBAGb,YAAY,GAAG,WAAW;6BAlB6B,sBAAsB;2BAAtB,sBAAsB;+BAAtB,sBAAsB;2BADpD,gCAAgC;kCAAhC,gCAAgC;qCACF,sBAAsB;6BAFhE,QAAQ;6BA6BP,eAAe"}
+315
View File
@@ -0,0 +1,315 @@
/**
* @import {Program} from 'estree'
* @import {Acorn, AcornOptions} from 'micromark-util-events-to-acorn'
* @import {Effects, Point, State, TokenType, TokenizeContext} from 'micromark-util-types'
*/
/**
* @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 {MdxSignalNok | MdxSignalOk} MdxSignal
*/
import { factorySpace } from 'micromark-factory-space';
import { markdownLineEnding, markdownSpace } 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';
// Tab-size to eat has to be the same as what we serialize as.
// While in some places in markdown thats 4, in JS its more common as 2.
// Which is whats also in `mdast-util-mdx-jsx`:
// <https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/40b951b/lib/index.js#L52>
const indentSize = 2;
const trouble = 'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression';
const unexpectedEndOfFileHash = '#unexpected-end-of-file-in-expression-expected-a-corresponding-closing-brace-for-';
const unexpectedLazyHash = '#unexpected-lazy-line-in-expression-in-container-expected-line-to-be-prefixed';
const nonSpreadHash = '#unexpected-type-in-code-expected-an-object-spread-spread';
const spreadExtraHash = '#unexpected-extra-content-in-spread-only-a-single-spread-is-supported';
const acornHash = '#could-not-parse-expression-with-acorn';
/**
* @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 (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression (default: `false`).
* @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) {
if (lastCrash) throw lastCrash;
const error = new VFileMessage('Unexpected end of file in expression, expected a corresponding closing brace for `{`', {
place: self.now(),
ruleId: 'unexpected-eof',
source: 'micromark-extension-mdx-expression'
});
error.url = trouble + unexpectedEndOfFileHash;
throw error;
}
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, chunkType, 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]) {
const error = new VFileMessage('Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc', {
place: self.now(),
ruleId: 'unexpected-lazy',
source: 'micromark-extension-mdx-expression'
});
error.url = trouble + unexpectedLazyHash;
throw error;
}
// Note: `markdown-rs` uses `4`, but we use `2`.
//
// Idea: investigate if wed need to use more complex stripping.
// Take this example:
//
// ```markdown
// > aaa <b c={`
// > d
// > `} /> eee
// ```
//
// Currently, the “paragraph” starts at `> | aaa`, so for the next line
// here we split it into `>␠|␠␠|␠␠␠d` (prefix, this indent here,
// expression data).
if (markdownSpace(code)) {
return factorySpace(effects, before, "linePrefix", indentSize + 1)(code);
}
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 {TokenType} chunkType
* @param {number} eventStart
* @param {Point} pointStart
* @param {boolean} allowEmpty
* @param {boolean} spread
* @returns {MdxSignal}
*/
// eslint-disable-next-line max-params
function mdxExpressionParse(acorn, acornOptions, chunkType, eventStart, pointStart, allowEmpty, spread) {
// Gnostic mode: parse w/ acorn.
const result = eventsToAcorn(this.events.slice(eventStart), {
acorn,
tokenTypes: [chunkType],
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];
if (head.type !== 'ExpressionStatement' || head.expression.type !== 'ObjectExpression') {
const place = positionFromEstree(head);
const error = new VFileMessage('Unexpected `' + head.type + '` in code: expected an object spread (`{...spread}`)', {
place: place.start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
});
error.url = trouble + nonSpreadHash;
throw error;
}
if (head.expression.properties[1]) {
const place = positionFromEstree(head.expression.properties[1]);
const error = new VFileMessage('Unexpected extra content in spread: only a single spread is supported', {
place: place.start,
ruleId: 'spread-extra',
source: 'micromark-extension-mdx-expression'
});
error.url = trouble + spreadExtraHash;
throw error;
}
if (head.expression.properties[0] && head.expression.properties[0].type !== 'SpreadElement') {
const place = positionFromEstree(head.expression.properties[0]);
const error = new VFileMessage('Unexpected `' + head.expression.properties[0].type + '` in code: only spread elements are supported', {
place: place.start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
});
error.url = trouble + nonSpreadHash;
throw error;
}
}
if (result.error) {
const error = new VFileMessage('Could not parse expression with acorn', {
cause: result.error,
place: {
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
ruleId: 'acorn',
source: 'micromark-extension-mdx-expression'
});
error.url = trouble + acornHash;
return {
type: 'nok',
message: error
};
}
return {
type: 'ok',
estree
};
}
+22
View File
@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+64
View File
@@ -0,0 +1,64 @@
{
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"bugs": "https://github.com/micromark/micromark-extension-mdx-expression/issues",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"dependencies": {
"@types/estree": "^1.0.0",
"devlop": "^1.0.0",
"micromark-factory-space": "^2.0.0",
"micromark-util-character": "^2.0.0",
"micromark-util-events-to-acorn": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0",
"unist-util-position-from-estree": "^2.0.0",
"vfile-message": "^4.0.0"
},
"description": "micromark factory to parse MDX expressions (found in JSX attributes, flow, text)",
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"files": [
"dev/",
"index.d.ts.map",
"index.d.ts",
"index.js"
],
"funding": [
{
"type": "GitHub Sponsors",
"url": "https://github.com/sponsors/unifiedjs"
},
{
"type": "OpenCollective",
"url": "https://opencollective.com/unified"
}
],
"keywords": [
"expression",
"factory",
"mdx",
"micromark"
],
"license": "MIT",
"name": "micromark-factory-mdx-expression",
"repository": "https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-factory-mdx-expression",
"scripts": {
"build": "micromark-build"
},
"sideEffects": false,
"typeCoverage": {
"atLeast": 100,
"strict": true
},
"type": "module",
"version": "2.0.3",
"xo": {
"prettier": true,
"rules": {
"unicorn/no-this-assignment": "off"
}
}
}
+218
View File
@@ -0,0 +1,218 @@
# micromark-factory-mdx-expression
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][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@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@2?bundle'
</script>
```
## Use
```js
import {ok as assert} from 'devlop'
import {factoryMdxExpression} from 'micromark-factory-mdx-expression'
import {codes} from 'micromark-util-symbol'
// 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 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-factory-mdx-expression@^2`, compatible with Node.js 16.
This package works with `micromark` version `3` and later.
## 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 -->
[acorn]: https://github.com/acornjs/acorn
[acorn-options]: https://github.com/acornjs/acorn/blob/96c721dbf89d0ccc3a8c7f39e69ef2a6a3c04dfa/acorn/dist/acorn.d.ts#L16
[api-factory-mdx-expression]: #micromark-factory-mdx-expression
[author]: https://wooorm.com
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[build]: https://github.com/micromark/micromark-extension-mdx-expression/actions
[build-badge]: https://github.com/micromark/micromark-extension-mdx-expression/workflows/main/badge.svg
[chat]: https://github.com/micromark/micromark/discussions
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[coverage]: https://codecov.io/github/micromark/micromark-extension-mdx-expression
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-mdx-expression.svg
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
[downloads]: https://www.npmjs.com/package/micromark-factory-mdx-expression
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-mdx-expression.svg
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[health]: https://github.com/micromark/.github
[license]: https://github.com/micromark/micromark-extension-mdx-expression/blob/main/license
[micromark]: https://github.com/micromark/micromark
[npm]: https://docs.npmjs.com/cli/install
[opencollective]: https://opencollective.com/unified
[size]: https://bundlejs.com/?q=micromark-factory-mdx-expression
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-factory-mdx-expression
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[support]: https://github.com/micromark/.github/blob/main/support.md
[typescript]: https://www.typescriptlang.org