This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,107 @@
/**
* Parse a list of micromark events with acorn.
*
* @param {Array<Event>} events
* Events.
* @param {Options} options
* Configuration (required).
* @returns {Result}
* Result.
*/
export function eventsToAcorn(events: Array<import("micromark-util-types").Event>, options: Options): Result;
export type Comment = import('acorn').Comment;
export type AcornNode = import('acorn').Node;
export type AcornOptions = import('acorn').Options;
export type Token = import('acorn').Token;
export type EstreeNode = import('estree').Node;
export type Program = import('estree').Program;
export type Chunk = import('micromark-util-types').Chunk;
export type Event = import('micromark-util-types').Event;
export type MicromarkPoint = import('micromark-util-types').Point;
export type TokenType = import('micromark-util-types').TokenType;
export type UnistPoint = import('unist').Point;
/**
* Acorn-like interface.
*/
export type Acorn = {
/**
* Parse a program.
*/
parse: typeof import("acorn").parse;
/**
* Parse an expression.
*/
parseExpressionAt: typeof import("acorn").parseExpressionAt;
};
export type AcornLoc = {
line: number;
column: number;
};
export type AcornErrorFields = {
raisedAt: number;
pos: number;
loc: AcornLoc;
};
export type AcornError = Error & AcornErrorFields;
/**
* Configuration.
*/
export type Options = {
/**
* Typically `acorn`, object with `parse` and `parseExpressionAt` fields (required).
*/
acorn: Acorn;
/**
* Names of (void) tokens to consider as data; `'lineEnding'` is always
* included (required).
*/
tokenTypes: Array<TokenType>;
/**
* Configuration for `acorn` (optional).
*/
acornOptions?: AcornOptions | null | undefined;
/**
* Place where events start (optional, required if `allowEmpty`).
*/
start?: MicromarkPoint | null | undefined;
/**
* Text to place before events (default: `''`).
*/
prefix?: string | null | undefined;
/**
* Text to place after events (default: `''`).
*/
suffix?: string | null | undefined;
/**
* Whether this is a program or expression (default: `false`).
*/
expression?: boolean | null | undefined;
/**
* Whether an empty expression is allowed (programs are always allowed to
* be empty) (default: `false`).
*/
allowEmpty?: boolean | null | undefined;
};
/**
* Result.
*/
export type Result = {
/**
* Program.
*/
estree: Program | undefined;
/**
* Error if unparseable
*/
error: AcornError | undefined;
/**
* Whether the error, if there is one, can be swallowed and more JavaScript
* could be valid.
*/
swallow: boolean;
};
export type Stop = [number, MicromarkPoint];
export type Collection = {
value: string;
stops: Array<Stop>;
};

View File

@@ -0,0 +1,470 @@
/**
* @typedef {import('acorn').Comment} Comment
* @typedef {import('acorn').Node} AcornNode
* @typedef {import('acorn').Options} AcornOptions
* @typedef {import('acorn').Token} Token
* @typedef {import('estree').Node} EstreeNode
* @typedef {import('estree').Program} Program
* @typedef {import('micromark-util-types').Chunk} Chunk
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').Point} MicromarkPoint
* @typedef {import('micromark-util-types').TokenType} TokenType
* @typedef {import('unist').Point} UnistPoint
*/
/**
* @typedef Acorn
* Acorn-like interface.
* @property {import('acorn').parse} parse
* Parse a program.
* @property {import('acorn').parseExpressionAt} parseExpressionAt
* Parse an expression.
*
* @typedef AcornLoc
* @property {number} line
* @property {number} column
*
* @typedef AcornErrorFields
* @property {number} raisedAt
* @property {number} pos
* @property {AcornLoc} loc
*
* @typedef {Error & AcornErrorFields} AcornError
*
* @typedef Options
* Configuration.
* @property {Acorn} acorn
* Typically `acorn`, object with `parse` and `parseExpressionAt` fields (required).
* @property {Array<TokenType>} tokenTypes
* Names of (void) tokens to consider as data; `'lineEnding'` is always
* included (required).
* @property {AcornOptions | null | undefined} [acornOptions]
* Configuration for `acorn` (optional).
* @property {MicromarkPoint | null | undefined} [start]
* Place where events start (optional, required if `allowEmpty`).
* @property {string | null | undefined} [prefix='']
* Text to place before events (default: `''`).
* @property {string | null | undefined} [suffix='']
* Text to place after events (default: `''`).
* @property {boolean | null | undefined} [expression=false]
* Whether this is a program or expression (default: `false`).
* @property {boolean | null | undefined} [allowEmpty=false]
* Whether an empty expression is allowed (programs are always allowed to
* be empty) (default: `false`).
*
* @typedef Result
* Result.
* @property {Program | undefined} estree
* Program.
* @property {AcornError | undefined} error
* Error if unparseable
* @property {boolean} swallow
* Whether the error, if there is one, can be swallowed and more JavaScript
* could be valid.
*
* @typedef {[number, MicromarkPoint]} Stop
*
* @typedef Collection
* @property {string} value
* @property {Array<Stop>} stops
*/
import {ok as assert} from 'devlop'
import {visit} from 'estree-util-visit'
import {codes, types, values} from 'micromark-util-symbol'
import {VFileMessage} from 'vfile-message'
/**
* Parse a list of micromark events with acorn.
*
* @param {Array<Event>} events
* Events.
* @param {Options} options
* Configuration (required).
* @returns {Result}
* Result.
*/
// eslint-disable-next-line complexity
export function eventsToAcorn(events, options) {
const prefix = options.prefix || ''
const suffix = options.suffix || ''
const acornOptions = Object.assign({}, options.acornOptions)
/** @type {Array<Comment>} */
const comments = []
/** @type {Array<Token>} */
const tokens = []
const onComment = acornOptions.onComment
const onToken = acornOptions.onToken
let swallow = false
/** @type {AcornNode | undefined} */
let estree
/** @type {AcornError | undefined} */
let exception
/** @type {AcornOptions} */
const acornConfig = Object.assign({}, acornOptions, {
onComment: comments,
preserveParens: true
})
if (onToken) {
acornConfig.onToken = tokens
}
const collection = collect(events, options.tokenTypes)
const source = collection.value
const value = prefix + source + suffix
const isEmptyExpression = options.expression && empty(source)
if (isEmptyExpression && !options.allowEmpty) {
throw new VFileMessage('Unexpected empty expression', {
place: parseOffsetToUnistPoint(0),
ruleId: 'unexpected-empty-expression',
source: 'micromark-extension-mdx-expression'
})
}
try {
estree =
options.expression && !isEmptyExpression
? options.acorn.parseExpressionAt(value, 0, acornConfig)
: options.acorn.parse(value, acornConfig)
} catch (error_) {
const error = /** @type {AcornError} */ (error_)
const point = parseOffsetToUnistPoint(error.pos)
error.message = String(error.message).replace(/ \(\d+:\d+\)$/, '')
// Always defined in our unist points that come from micromark.
assert(point.offset !== undefined, 'expected `offset`')
error.pos = point.offset
error.loc = {line: point.line, column: point.column - 1}
exception = error
swallow =
error.raisedAt >= prefix.length + source.length ||
// Broken comments are raised at their start, not their end.
error.message === 'Unterminated comment'
}
if (estree && options.expression && !isEmptyExpression) {
if (empty(value.slice(estree.end, value.length - suffix.length))) {
estree = {
type: 'Program',
start: 0,
end: prefix.length + source.length,
// @ts-expect-error: Its good.
body: [
{
type: 'ExpressionStatement',
expression: estree,
start: 0,
end: prefix.length + source.length
}
],
sourceType: 'module',
comments: []
}
} else {
const point = parseOffsetToUnistPoint(estree.end)
const error = /** @type {AcornError} */ (
new Error('Unexpected content after expression')
)
// Always defined in our unist points that come from micromark.
assert(point.offset !== undefined, 'expected `offset`')
error.pos = point.offset
error.loc = {line: point.line, column: point.column - 1}
exception = error
estree = undefined
}
}
if (estree) {
// @ts-expect-error: acorn *does* allow comments
estree.comments = comments
// @ts-expect-error: acorn looks enough like estree.
visit(estree, function (esnode, field, index, parents) {
let context = /** @type {AcornNode | Array<AcornNode>} */ (
parents[parents.length - 1]
)
/** @type {number | string | undefined} */
let prop = field
// Remove non-standard `ParenthesizedExpression`.
// @ts-expect-error: included in acorn.
if (esnode.type === 'ParenthesizedExpression' && context && prop) {
/* c8 ignore next 5 */
if (typeof index === 'number') {
// @ts-expect-error: indexable.
context = context[prop]
prop = index
}
// @ts-expect-error: indexable.
context[prop] = esnode.expression
}
fixPosition(esnode)
})
// Comment positions are fixed by `visit` because theyre in the tree.
if (Array.isArray(onComment)) {
onComment.push(...comments)
} else if (typeof onComment === 'function') {
for (const comment of comments) {
assert(comment.loc, 'expected `loc` on comment')
onComment(
comment.type === 'Block',
comment.value,
comment.start,
comment.end,
comment.loc.start,
comment.loc.end
)
}
}
for (const token of tokens) {
// Ignore tokens that ends in prefix or start in suffix:
if (
token.end <= prefix.length ||
token.start - prefix.length >= source.length
) {
continue
}
fixPosition(token)
if (Array.isArray(onToken)) {
onToken.push(token)
} else {
// `tokens` are not added if `onToken` is not defined, so it must be a
// function.
assert(typeof onToken === 'function', 'expected function')
onToken(token)
}
}
}
// @ts-expect-error: Its a program now.
return {estree, error: exception, swallow}
/**
* Update the position of a node.
*
* @param {AcornNode | EstreeNode | Token} nodeOrToken
* @returns {undefined}
*/
function fixPosition(nodeOrToken) {
assert(
'start' in nodeOrToken,
'expected `start` in node or token from acorn'
)
assert('end' in nodeOrToken, 'expected `end` in node or token from acorn')
const pointStart = parseOffsetToUnistPoint(nodeOrToken.start)
const pointEnd = parseOffsetToUnistPoint(nodeOrToken.end)
// Always defined in our unist points that come from micromark.
assert(pointStart.offset !== undefined, 'expected `offset`')
assert(pointEnd.offset !== undefined, 'expected `offset`')
nodeOrToken.start = pointStart.offset
nodeOrToken.end = pointEnd.offset
nodeOrToken.loc = {
start: {
line: pointStart.line,
column: pointStart.column - 1,
offset: pointStart.offset
},
end: {
line: pointEnd.line,
column: pointEnd.column - 1,
offset: pointEnd.offset
}
}
nodeOrToken.range = [nodeOrToken.start, nodeOrToken.end]
}
/**
* Turn an arbitrary offset into the parsed value, into a point in the source
* value.
*
* @param {number} acornOffset
* @returns {UnistPoint}
*/
function parseOffsetToUnistPoint(acornOffset) {
let sourceOffset = acornOffset - prefix.length
if (sourceOffset < 0) {
sourceOffset = 0
} else if (sourceOffset > source.length) {
sourceOffset = source.length
}
let point = relativeToPoint(collection.stops, sourceOffset)
if (!point) {
assert(
options.start,
'empty expressions are need `options.start` being passed'
)
point = {
line: options.start.line,
column: options.start.column,
offset: options.start.offset
}
}
return point
}
}
/**
* @param {string} value
* @returns {boolean}
*/
function empty(value) {
return /^\s*$/.test(
value
// Multiline comments.
.replace(/\/\*[\s\S]*?\*\//g, '')
// Line comments.
// EOF instead of EOL is specifically not allowed, because that would
// mean the closing brace is on the commented-out line
.replace(/\/\/[^\r\n]*(\r\n|\n|\r)/g, '')
)
}
// Port from <https://github.com/wooorm/markdown-rs/blob/e692ab0/src/util/mdx_collect.rs#L15>.
/**
* @param {Array<Event>} events
* @param {Array<TokenType>} tokenTypes
* @returns {Collection}
*/
function collect(events, tokenTypes) {
/** @type {Collection} */
const result = {value: '', stops: []}
let index = -1
while (++index < events.length) {
const event = events[index]
// Assume void.
if (event[0] === 'enter') {
const type = event[1].type
if (type === types.lineEnding || tokenTypes.includes(type)) {
const chunks = event[2].sliceStream(event[1])
// Drop virtual spaces.
while (chunks.length > 0 && chunks[0] === codes.virtualSpace) {
chunks.shift()
}
const value = serializeChunks(chunks)
result.stops.push([result.value.length, event[1].start])
result.value += value
result.stops.push([result.value.length, event[1].end])
}
}
}
return result
}
// Port from <https://github.com/wooorm/markdown-rs/blob/e692ab0/src/util/location.rs#L91>.
/**
* Turn a relative offset into an absolute offset.
*
* @param {Array<Stop>} stops
* @param {number} relative
* @returns {UnistPoint | undefined}
*/
function relativeToPoint(stops, relative) {
let index = 0
while (index < stops.length && stops[index][0] <= relative) {
index += 1
}
// There are no points: that only occurs if there was an empty string.
if (index === 0) {
return undefined
}
const [stopRelative, stopAbsolute] = stops[index - 1]
const rest = relative - stopRelative
return {
line: stopAbsolute.line,
column: stopAbsolute.column + rest,
offset: stopAbsolute.offset + rest
}
}
// Copy from <https://github.com/micromark/micromark/blob/ce3593a/packages/micromark/dev/lib/create-tokenizer.js#L595>
// To do: expose that?
/**
* Get the string value of a slice of chunks.
*
* @param {Array<Chunk>} chunks
* @returns {string}
*/
function serializeChunks(chunks) {
let index = -1
/** @type {Array<string>} */
const result = []
/** @type {boolean | undefined} */
let atTab
while (++index < chunks.length) {
const chunk = chunks[index]
/** @type {string} */
let value
if (typeof chunk === 'string') {
value = chunk
} else
switch (chunk) {
case codes.carriageReturn: {
value = values.cr
break
}
case codes.lineFeed: {
value = values.lf
break
}
case codes.carriageReturnLineFeed: {
value = values.cr + values.lf
break
}
case codes.horizontalTab: {
value = values.ht
break
}
/* c8 ignore next 6 */
case codes.virtualSpace: {
if (atTab) continue
value = values.space
break
}
default: {
assert(typeof chunk === 'number', 'expected number')
// Currently only replacement character.
// eslint-disable-next-line unicorn/prefer-code-point
value = String.fromCharCode(chunk)
}
}
atTab = chunk === codes.horizontalTab
result.push(value)
}
return result.join('')
}

107
node_modules/micromark-util-events-to-acorn/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,107 @@
/**
* Parse a list of micromark events with acorn.
*
* @param {Array<Event>} events
* Events.
* @param {Options} options
* Configuration (required).
* @returns {Result}
* Result.
*/
export function eventsToAcorn(events: Array<import("micromark-util-types").Event>, options: Options): Result;
export type Comment = import('acorn').Comment;
export type AcornNode = import('acorn').Node;
export type AcornOptions = import('acorn').Options;
export type Token = import('acorn').Token;
export type EstreeNode = import('estree').Node;
export type Program = import('estree').Program;
export type Chunk = import('micromark-util-types').Chunk;
export type Event = import('micromark-util-types').Event;
export type MicromarkPoint = import('micromark-util-types').Point;
export type TokenType = import('micromark-util-types').TokenType;
export type UnistPoint = import('unist').Point;
/**
* Acorn-like interface.
*/
export type Acorn = {
/**
* Parse a program.
*/
parse: typeof import("acorn").parse;
/**
* Parse an expression.
*/
parseExpressionAt: typeof import("acorn").parseExpressionAt;
};
export type AcornLoc = {
line: number;
column: number;
};
export type AcornErrorFields = {
raisedAt: number;
pos: number;
loc: AcornLoc;
};
export type AcornError = Error & AcornErrorFields;
/**
* Configuration.
*/
export type Options = {
/**
* Typically `acorn`, object with `parse` and `parseExpressionAt` fields (required).
*/
acorn: Acorn;
/**
* Names of (void) tokens to consider as data; `'lineEnding'` is always
* included (required).
*/
tokenTypes: Array<TokenType>;
/**
* Configuration for `acorn` (optional).
*/
acornOptions?: AcornOptions | null | undefined;
/**
* Place where events start (optional, required if `allowEmpty`).
*/
start?: MicromarkPoint | null | undefined;
/**
* Text to place before events (default: `''`).
*/
prefix?: string | null | undefined;
/**
* Text to place after events (default: `''`).
*/
suffix?: string | null | undefined;
/**
* Whether this is a program or expression (default: `false`).
*/
expression?: boolean | null | undefined;
/**
* Whether an empty expression is allowed (programs are always allowed to
* be empty) (default: `false`).
*/
allowEmpty?: boolean | null | undefined;
};
/**
* Result.
*/
export type Result = {
/**
* Program.
*/
estree: Program | undefined;
/**
* Error if unparseable
*/
error: AcornError | undefined;
/**
* Whether the error, if there is one, can be swallowed and more JavaScript
* could be valid.
*/
swallow: boolean;
};
export type Stop = [number, MicromarkPoint];
export type Collection = {
value: string;
stops: Array<Stop>;
};

419
node_modules/micromark-util-events-to-acorn/index.js generated vendored Normal file
View File

@@ -0,0 +1,419 @@
/**
* @typedef {import('acorn').Comment} Comment
* @typedef {import('acorn').Node} AcornNode
* @typedef {import('acorn').Options} AcornOptions
* @typedef {import('acorn').Token} Token
* @typedef {import('estree').Node} EstreeNode
* @typedef {import('estree').Program} Program
* @typedef {import('micromark-util-types').Chunk} Chunk
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').Point} MicromarkPoint
* @typedef {import('micromark-util-types').TokenType} TokenType
* @typedef {import('unist').Point} UnistPoint
*/
/**
* @typedef Acorn
* Acorn-like interface.
* @property {import('acorn').parse} parse
* Parse a program.
* @property {import('acorn').parseExpressionAt} parseExpressionAt
* Parse an expression.
*
* @typedef AcornLoc
* @property {number} line
* @property {number} column
*
* @typedef AcornErrorFields
* @property {number} raisedAt
* @property {number} pos
* @property {AcornLoc} loc
*
* @typedef {Error & AcornErrorFields} AcornError
*
* @typedef Options
* Configuration.
* @property {Acorn} acorn
* Typically `acorn`, object with `parse` and `parseExpressionAt` fields (required).
* @property {Array<TokenType>} tokenTypes
* Names of (void) tokens to consider as data; `'lineEnding'` is always
* included (required).
* @property {AcornOptions | null | undefined} [acornOptions]
* Configuration for `acorn` (optional).
* @property {MicromarkPoint | null | undefined} [start]
* Place where events start (optional, required if `allowEmpty`).
* @property {string | null | undefined} [prefix='']
* Text to place before events (default: `''`).
* @property {string | null | undefined} [suffix='']
* Text to place after events (default: `''`).
* @property {boolean | null | undefined} [expression=false]
* Whether this is a program or expression (default: `false`).
* @property {boolean | null | undefined} [allowEmpty=false]
* Whether an empty expression is allowed (programs are always allowed to
* be empty) (default: `false`).
*
* @typedef Result
* Result.
* @property {Program | undefined} estree
* Program.
* @property {AcornError | undefined} error
* Error if unparseable
* @property {boolean} swallow
* Whether the error, if there is one, can be swallowed and more JavaScript
* could be valid.
*
* @typedef {[number, MicromarkPoint]} Stop
*
* @typedef Collection
* @property {string} value
* @property {Array<Stop>} stops
*/
import { visit } from 'estree-util-visit';
import { VFileMessage } from 'vfile-message';
/**
* Parse a list of micromark events with acorn.
*
* @param {Array<Event>} events
* Events.
* @param {Options} options
* Configuration (required).
* @returns {Result}
* Result.
*/
// eslint-disable-next-line complexity
export function eventsToAcorn(events, options) {
const prefix = options.prefix || '';
const suffix = options.suffix || '';
const acornOptions = Object.assign({}, options.acornOptions);
/** @type {Array<Comment>} */
const comments = [];
/** @type {Array<Token>} */
const tokens = [];
const onComment = acornOptions.onComment;
const onToken = acornOptions.onToken;
let swallow = false;
/** @type {AcornNode | undefined} */
let estree;
/** @type {AcornError | undefined} */
let exception;
/** @type {AcornOptions} */
const acornConfig = Object.assign({}, acornOptions, {
onComment: comments,
preserveParens: true
});
if (onToken) {
acornConfig.onToken = tokens;
}
const collection = collect(events, options.tokenTypes);
const source = collection.value;
const value = prefix + source + suffix;
const isEmptyExpression = options.expression && empty(source);
if (isEmptyExpression && !options.allowEmpty) {
throw new VFileMessage('Unexpected empty expression', {
place: parseOffsetToUnistPoint(0),
ruleId: 'unexpected-empty-expression',
source: 'micromark-extension-mdx-expression'
});
}
try {
estree = options.expression && !isEmptyExpression ? options.acorn.parseExpressionAt(value, 0, acornConfig) : options.acorn.parse(value, acornConfig);
} catch (error_) {
const error = /** @type {AcornError} */error_;
const point = parseOffsetToUnistPoint(error.pos);
error.message = String(error.message).replace(/ \(\d+:\d+\)$/, '');
// Always defined in our unist points that come from micromark.
error.pos = point.offset;
error.loc = {
line: point.line,
column: point.column - 1
};
exception = error;
swallow = error.raisedAt >= prefix.length + source.length ||
// Broken comments are raised at their start, not their end.
error.message === 'Unterminated comment';
}
if (estree && options.expression && !isEmptyExpression) {
if (empty(value.slice(estree.end, value.length - suffix.length))) {
estree = {
type: 'Program',
start: 0,
end: prefix.length + source.length,
// @ts-expect-error: Its good.
body: [{
type: 'ExpressionStatement',
expression: estree,
start: 0,
end: prefix.length + source.length
}],
sourceType: 'module',
comments: []
};
} else {
const point = parseOffsetToUnistPoint(estree.end);
const error = /** @type {AcornError} */
new Error('Unexpected content after expression');
// Always defined in our unist points that come from micromark.
error.pos = point.offset;
error.loc = {
line: point.line,
column: point.column - 1
};
exception = error;
estree = undefined;
}
}
if (estree) {
// @ts-expect-error: acorn *does* allow comments
estree.comments = comments;
// @ts-expect-error: acorn looks enough like estree.
visit(estree, function (esnode, field, index, parents) {
let context = /** @type {AcornNode | Array<AcornNode>} */
parents[parents.length - 1];
/** @type {number | string | undefined} */
let prop = field;
// Remove non-standard `ParenthesizedExpression`.
// @ts-expect-error: included in acorn.
if (esnode.type === 'ParenthesizedExpression' && context && prop) {
/* c8 ignore next 5 */
if (typeof index === 'number') {
// @ts-expect-error: indexable.
context = context[prop];
prop = index;
}
// @ts-expect-error: indexable.
context[prop] = esnode.expression;
}
fixPosition(esnode);
});
// Comment positions are fixed by `visit` because theyre in the tree.
if (Array.isArray(onComment)) {
onComment.push(...comments);
} else if (typeof onComment === 'function') {
for (const comment of comments) {
onComment(comment.type === 'Block', comment.value, comment.start, comment.end, comment.loc.start, comment.loc.end);
}
}
for (const token of tokens) {
// Ignore tokens that ends in prefix or start in suffix:
if (token.end <= prefix.length || token.start - prefix.length >= source.length) {
continue;
}
fixPosition(token);
if (Array.isArray(onToken)) {
onToken.push(token);
} else {
// `tokens` are not added if `onToken` is not defined, so it must be a
// function.
onToken(token);
}
}
}
// @ts-expect-error: Its a program now.
return {
estree,
error: exception,
swallow
};
/**
* Update the position of a node.
*
* @param {AcornNode | EstreeNode | Token} nodeOrToken
* @returns {undefined}
*/
function fixPosition(nodeOrToken) {
const pointStart = parseOffsetToUnistPoint(nodeOrToken.start);
const pointEnd = parseOffsetToUnistPoint(nodeOrToken.end);
// Always defined in our unist points that come from micromark.
nodeOrToken.start = pointStart.offset;
nodeOrToken.end = pointEnd.offset;
nodeOrToken.loc = {
start: {
line: pointStart.line,
column: pointStart.column - 1,
offset: pointStart.offset
},
end: {
line: pointEnd.line,
column: pointEnd.column - 1,
offset: pointEnd.offset
}
};
nodeOrToken.range = [nodeOrToken.start, nodeOrToken.end];
}
/**
* Turn an arbitrary offset into the parsed value, into a point in the source
* value.
*
* @param {number} acornOffset
* @returns {UnistPoint}
*/
function parseOffsetToUnistPoint(acornOffset) {
let sourceOffset = acornOffset - prefix.length;
if (sourceOffset < 0) {
sourceOffset = 0;
} else if (sourceOffset > source.length) {
sourceOffset = source.length;
}
let point = relativeToPoint(collection.stops, sourceOffset);
if (!point) {
point = {
line: options.start.line,
column: options.start.column,
offset: options.start.offset
};
}
return point;
}
}
/**
* @param {string} value
* @returns {boolean}
*/
function empty(value) {
return /^\s*$/.test(value
// Multiline comments.
.replace(/\/\*[\s\S]*?\*\//g, '')
// Line comments.
// EOF instead of EOL is specifically not allowed, because that would
// mean the closing brace is on the commented-out line
.replace(/\/\/[^\r\n]*(\r\n|\n|\r)/g, ''));
}
// Port from <https://github.com/wooorm/markdown-rs/blob/e692ab0/src/util/mdx_collect.rs#L15>.
/**
* @param {Array<Event>} events
* @param {Array<TokenType>} tokenTypes
* @returns {Collection}
*/
function collect(events, tokenTypes) {
/** @type {Collection} */
const result = {
value: '',
stops: []
};
let index = -1;
while (++index < events.length) {
const event = events[index];
// Assume void.
if (event[0] === 'enter') {
const type = event[1].type;
if (type === "lineEnding" || tokenTypes.includes(type)) {
const chunks = event[2].sliceStream(event[1]);
// Drop virtual spaces.
while (chunks.length > 0 && chunks[0] === -1) {
chunks.shift();
}
const value = serializeChunks(chunks);
result.stops.push([result.value.length, event[1].start]);
result.value += value;
result.stops.push([result.value.length, event[1].end]);
}
}
}
return result;
}
// Port from <https://github.com/wooorm/markdown-rs/blob/e692ab0/src/util/location.rs#L91>.
/**
* Turn a relative offset into an absolute offset.
*
* @param {Array<Stop>} stops
* @param {number} relative
* @returns {UnistPoint | undefined}
*/
function relativeToPoint(stops, relative) {
let index = 0;
while (index < stops.length && stops[index][0] <= relative) {
index += 1;
}
// There are no points: that only occurs if there was an empty string.
if (index === 0) {
return undefined;
}
const [stopRelative, stopAbsolute] = stops[index - 1];
const rest = relative - stopRelative;
return {
line: stopAbsolute.line,
column: stopAbsolute.column + rest,
offset: stopAbsolute.offset + rest
};
}
// Copy from <https://github.com/micromark/micromark/blob/ce3593a/packages/micromark/dev/lib/create-tokenizer.js#L595>
// To do: expose that?
/**
* Get the string value of a slice of chunks.
*
* @param {Array<Chunk>} chunks
* @returns {string}
*/
function serializeChunks(chunks) {
let index = -1;
/** @type {Array<string>} */
const result = [];
/** @type {boolean | undefined} */
let atTab;
while (++index < chunks.length) {
const chunk = chunks[index];
/** @type {string} */
let value;
if (typeof chunk === 'string') {
value = chunk;
} else switch (chunk) {
case -5:
{
value = "\r";
break;
}
case -4:
{
value = "\n";
break;
}
case -3:
{
value = "\r" + "\n";
break;
}
case -2:
{
value = "\t";
break;
}
/* c8 ignore next 6 */
case -1:
{
if (atTab) continue;
value = " ";
break;
}
default:
{
// Currently only replacement character.
// eslint-disable-next-line unicorn/prefer-code-point
value = String.fromCharCode(chunk);
}
}
atTab = chunk === -2;
result.push(value);
}
return result.join('');
}

View File

@@ -0,0 +1,138 @@
export namespace codes {
let carriageReturn: -5
let lineFeed: -4
let carriageReturnLineFeed: -3
let horizontalTab: -2
let virtualSpace: -1
let eof: null
let nul: 0
let soh: 1
let stx: 2
let etx: 3
let eot: 4
let enq: 5
let ack: 6
let bel: 7
let bs: 8
let ht: 9
let lf: 10
let vt: 11
let ff: 12
let cr: 13
let so: 14
let si: 15
let dle: 16
let dc1: 17
let dc2: 18
let dc3: 19
let dc4: 20
let nak: 21
let syn: 22
let etb: 23
let can: 24
let em: 25
let sub: 26
let esc: 27
let fs: 28
let gs: 29
let rs: 30
let us: 31
let space: 32
let exclamationMark: 33
let quotationMark: 34
let numberSign: 35
let dollarSign: 36
let percentSign: 37
let ampersand: 38
let apostrophe: 39
let leftParenthesis: 40
let rightParenthesis: 41
let asterisk: 42
let plusSign: 43
let comma: 44
let dash: 45
let dot: 46
let slash: 47
let digit0: 48
let digit1: 49
let digit2: 50
let digit3: 51
let digit4: 52
let digit5: 53
let digit6: 54
let digit7: 55
let digit8: 56
let digit9: 57
let colon: 58
let semicolon: 59
let lessThan: 60
let equalsTo: 61
let greaterThan: 62
let questionMark: 63
let atSign: 64
let uppercaseA: 65
let uppercaseB: 66
let uppercaseC: 67
let uppercaseD: 68
let uppercaseE: 69
let uppercaseF: 70
let uppercaseG: 71
let uppercaseH: 72
let uppercaseI: 73
let uppercaseJ: 74
let uppercaseK: 75
let uppercaseL: 76
let uppercaseM: 77
let uppercaseN: 78
let uppercaseO: 79
let uppercaseP: 80
let uppercaseQ: 81
let uppercaseR: 82
let uppercaseS: 83
let uppercaseT: 84
let uppercaseU: 85
let uppercaseV: 86
let uppercaseW: 87
let uppercaseX: 88
let uppercaseY: 89
let uppercaseZ: 90
let leftSquareBracket: 91
let backslash: 92
let rightSquareBracket: 93
let caret: 94
let underscore: 95
let graveAccent: 96
let lowercaseA: 97
let lowercaseB: 98
let lowercaseC: 99
let lowercaseD: 100
let lowercaseE: 101
let lowercaseF: 102
let lowercaseG: 103
let lowercaseH: 104
let lowercaseI: 105
let lowercaseJ: 106
let lowercaseK: 107
let lowercaseL: 108
let lowercaseM: 109
let lowercaseN: 110
let lowercaseO: 111
let lowercaseP: 112
let lowercaseQ: 113
let lowercaseR: 114
let lowercaseS: 115
let lowercaseT: 116
let lowercaseU: 117
let lowercaseV: 118
let lowercaseW: 119
let lowercaseX: 120
let lowercaseY: 121
let lowercaseZ: 122
let leftCurlyBrace: 123
let verticalBar: 124
let rightCurlyBrace: 125
let tilde: 126
let del: 127
let byteOrderMarker: 65279
let replacementCharacter: 65533
}

View File

@@ -0,0 +1,158 @@
/**
* Character codes.
*
* This module is compiled away!
*
* micromark works based on character codes.
* This module contains constants for the ASCII block and the replacement
* character.
* A couple of them are handled in a special way, such as the line endings
* (CR, LF, and CR+LF, commonly known as end-of-line: EOLs), the tab (horizontal
* tab) and its expansion based on what column its at (virtual space),
* and the end-of-file (eof) character.
* As values are preprocessed before handling them, the actual characters LF,
* CR, HT, and NUL (which is present as the replacement character), are
* guaranteed to not exist.
*
* Unicode basic latin block.
*/
export const codes = /** @type {const} */ ({
carriageReturn: -5,
lineFeed: -4,
carriageReturnLineFeed: -3,
horizontalTab: -2,
virtualSpace: -1,
eof: null,
nul: 0,
soh: 1,
stx: 2,
etx: 3,
eot: 4,
enq: 5,
ack: 6,
bel: 7,
bs: 8,
ht: 9, // `\t`
lf: 10, // `\n`
vt: 11, // `\v`
ff: 12, // `\f`
cr: 13, // `\r`
so: 14,
si: 15,
dle: 16,
dc1: 17,
dc2: 18,
dc3: 19,
dc4: 20,
nak: 21,
syn: 22,
etb: 23,
can: 24,
em: 25,
sub: 26,
esc: 27,
fs: 28,
gs: 29,
rs: 30,
us: 31,
space: 32,
exclamationMark: 33, // `!`
quotationMark: 34, // `"`
numberSign: 35, // `#`
dollarSign: 36, // `$`
percentSign: 37, // `%`
ampersand: 38, // `&`
apostrophe: 39, // `'`
leftParenthesis: 40, // `(`
rightParenthesis: 41, // `)`
asterisk: 42, // `*`
plusSign: 43, // `+`
comma: 44, // `,`
dash: 45, // `-`
dot: 46, // `.`
slash: 47, // `/`
digit0: 48, // `0`
digit1: 49, // `1`
digit2: 50, // `2`
digit3: 51, // `3`
digit4: 52, // `4`
digit5: 53, // `5`
digit6: 54, // `6`
digit7: 55, // `7`
digit8: 56, // `8`
digit9: 57, // `9`
colon: 58, // `:`
semicolon: 59, // `;`
lessThan: 60, // `<`
equalsTo: 61, // `=`
greaterThan: 62, // `>`
questionMark: 63, // `?`
atSign: 64, // `@`
uppercaseA: 65, // `A`
uppercaseB: 66, // `B`
uppercaseC: 67, // `C`
uppercaseD: 68, // `D`
uppercaseE: 69, // `E`
uppercaseF: 70, // `F`
uppercaseG: 71, // `G`
uppercaseH: 72, // `H`
uppercaseI: 73, // `I`
uppercaseJ: 74, // `J`
uppercaseK: 75, // `K`
uppercaseL: 76, // `L`
uppercaseM: 77, // `M`
uppercaseN: 78, // `N`
uppercaseO: 79, // `O`
uppercaseP: 80, // `P`
uppercaseQ: 81, // `Q`
uppercaseR: 82, // `R`
uppercaseS: 83, // `S`
uppercaseT: 84, // `T`
uppercaseU: 85, // `U`
uppercaseV: 86, // `V`
uppercaseW: 87, // `W`
uppercaseX: 88, // `X`
uppercaseY: 89, // `Y`
uppercaseZ: 90, // `Z`
leftSquareBracket: 91, // `[`
backslash: 92, // `\`
rightSquareBracket: 93, // `]`
caret: 94, // `^`
underscore: 95, // `_`
graveAccent: 96, // `` ` ``
lowercaseA: 97, // `a`
lowercaseB: 98, // `b`
lowercaseC: 99, // `c`
lowercaseD: 100, // `d`
lowercaseE: 101, // `e`
lowercaseF: 102, // `f`
lowercaseG: 103, // `g`
lowercaseH: 104, // `h`
lowercaseI: 105, // `i`
lowercaseJ: 106, // `j`
lowercaseK: 107, // `k`
lowercaseL: 108, // `l`
lowercaseM: 109, // `m`
lowercaseN: 110, // `n`
lowercaseO: 111, // `o`
lowercaseP: 112, // `p`
lowercaseQ: 113, // `q`
lowercaseR: 114, // `r`
lowercaseS: 115, // `s`
lowercaseT: 116, // `t`
lowercaseU: 117, // `u`
lowercaseV: 118, // `v`
lowercaseW: 119, // `w`
lowercaseX: 120, // `x`
lowercaseY: 121, // `y`
lowercaseZ: 122, // `z`
leftCurlyBrace: 123, // `{`
verticalBar: 124, // `|`
rightCurlyBrace: 125, // `}`
tilde: 126, // `~`
del: 127,
// Unicode Specials block.
byteOrderMarker: 65279,
// Unicode Specials block.
replacementCharacter: 65533 // `<60>`
})

View File

@@ -0,0 +1,36 @@
export namespace constants {
let attentionSideBefore: 1
let attentionSideAfter: 2
let atxHeadingOpeningFenceSizeMax: 6
let autolinkDomainSizeMax: 63
let autolinkSchemeSizeMax: 32
let cdataOpeningString: 'CDATA['
let characterGroupWhitespace: 1
let characterGroupPunctuation: 2
let characterReferenceDecimalSizeMax: 7
let characterReferenceHexadecimalSizeMax: 6
let characterReferenceNamedSizeMax: 31
let codeFencedSequenceSizeMin: 3
let contentTypeDocument: 'document'
let contentTypeFlow: 'flow'
let contentTypeContent: 'content'
let contentTypeString: 'string'
let contentTypeText: 'text'
let hardBreakPrefixSizeMin: 2
let htmlRaw: 1
let htmlComment: 2
let htmlInstruction: 3
let htmlDeclaration: 4
let htmlCdata: 5
let htmlBasic: 6
let htmlComplete: 7
let htmlRawSizeMax: 8
let linkResourceDestinationBalanceMax: 32
let linkReferenceSizeMax: 999
let listItemValueSizeMax: 10
let numericBaseDecimal: 10
let numericBaseHexadecimal: 16
let tabSize: 4
let thematicBreakMarkerCountMin: 3
let v8MaxSafeChunkSize: 10000
}

View File

@@ -0,0 +1,44 @@
/**
* This module is compiled away!
*
* Parsing markdown comes with a couple of constants, such as minimum or maximum
* sizes of certain sequences.
* Additionally, there are a couple symbols used inside micromark.
* These are all defined here, but compiled away by scripts.
*/
export const constants = /** @type {const} */ ({
attentionSideBefore: 1, // Symbol to mark an attention sequence as before content: `*a`
attentionSideAfter: 2, // Symbol to mark an attention sequence as after content: `a*`
atxHeadingOpeningFenceSizeMax: 6, // 6 number signs is fine, 7 isnt.
autolinkDomainSizeMax: 63, // 63 characters is fine, 64 is too many.
autolinkSchemeSizeMax: 32, // 32 characters is fine, 33 is too many.
cdataOpeningString: 'CDATA[', // And preceded by `<![`.
characterGroupWhitespace: 1, // Symbol used to indicate a character is whitespace
characterGroupPunctuation: 2, // Symbol used to indicate a character is punctuation
characterReferenceDecimalSizeMax: 7, // `&#9999999;`.
characterReferenceHexadecimalSizeMax: 6, // `&#xff9999;`.
characterReferenceNamedSizeMax: 31, // `&CounterClockwiseContourIntegral;`.
codeFencedSequenceSizeMin: 3, // At least 3 ticks or tildes are needed.
contentTypeDocument: 'document',
contentTypeFlow: 'flow',
contentTypeContent: 'content',
contentTypeString: 'string',
contentTypeText: 'text',
hardBreakPrefixSizeMin: 2, // At least 2 trailing spaces are needed.
htmlRaw: 1, // Symbol for `<script>`
htmlComment: 2, // Symbol for `<!---->`
htmlInstruction: 3, // Symbol for `<?php?>`
htmlDeclaration: 4, // Symbol for `<!doctype>`
htmlCdata: 5, // Symbol for `<![CDATA[]]>`
htmlBasic: 6, // Symbol for `<div`
htmlComplete: 7, // Symbol for `<x>`
htmlRawSizeMax: 8, // Length of `textarea`.
linkResourceDestinationBalanceMax: 32, // See: <https://spec.commonmark.org/0.30/#link-destination>, <https://github.com/remarkjs/react-markdown/issues/658#issuecomment-984345577>
linkReferenceSizeMax: 999, // See: <https://spec.commonmark.org/0.30/#link-label>
listItemValueSizeMax: 10, // See: <https://spec.commonmark.org/0.30/#ordered-list-marker>
numericBaseDecimal: 10,
numericBaseHexadecimal: 0x10,
tabSize: 4, // Tabs have a hard-coded size of 4, per CommonMark.
thematicBreakMarkerCountMin: 3, // At least 3 asterisks, dashes, or underscores are needed.
v8MaxSafeChunkSize: 10000 // V8 (and potentially others) have problems injecting giant arrays into other arrays, hence we operate in chunks.
})

View File

@@ -0,0 +1,4 @@
export {codes} from './codes.js'
export {constants} from './constants.js'
export {types} from './types.js'
export {values} from './values.js'

View File

@@ -0,0 +1,4 @@
export {codes} from './codes.js'
export {constants} from './constants.js'
export {types} from './types.js'
export {values} from './values.js'

View File

@@ -0,0 +1,105 @@
export namespace types {
let data: 'data'
let whitespace: 'whitespace'
let lineEnding: 'lineEnding'
let lineEndingBlank: 'lineEndingBlank'
let linePrefix: 'linePrefix'
let lineSuffix: 'lineSuffix'
let atxHeading: 'atxHeading'
let atxHeadingSequence: 'atxHeadingSequence'
let atxHeadingText: 'atxHeadingText'
let autolink: 'autolink'
let autolinkEmail: 'autolinkEmail'
let autolinkMarker: 'autolinkMarker'
let autolinkProtocol: 'autolinkProtocol'
let characterEscape: 'characterEscape'
let characterEscapeValue: 'characterEscapeValue'
let characterReference: 'characterReference'
let characterReferenceMarker: 'characterReferenceMarker'
let characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric'
let characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal'
let characterReferenceValue: 'characterReferenceValue'
let codeFenced: 'codeFenced'
let codeFencedFence: 'codeFencedFence'
let codeFencedFenceSequence: 'codeFencedFenceSequence'
let codeFencedFenceInfo: 'codeFencedFenceInfo'
let codeFencedFenceMeta: 'codeFencedFenceMeta'
let codeFlowValue: 'codeFlowValue'
let codeIndented: 'codeIndented'
let codeText: 'codeText'
let codeTextData: 'codeTextData'
let codeTextPadding: 'codeTextPadding'
let codeTextSequence: 'codeTextSequence'
let content: 'content'
let definition: 'definition'
let definitionDestination: 'definitionDestination'
let definitionDestinationLiteral: 'definitionDestinationLiteral'
let definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker'
let definitionDestinationRaw: 'definitionDestinationRaw'
let definitionDestinationString: 'definitionDestinationString'
let definitionLabel: 'definitionLabel'
let definitionLabelMarker: 'definitionLabelMarker'
let definitionLabelString: 'definitionLabelString'
let definitionMarker: 'definitionMarker'
let definitionTitle: 'definitionTitle'
let definitionTitleMarker: 'definitionTitleMarker'
let definitionTitleString: 'definitionTitleString'
let emphasis: 'emphasis'
let emphasisSequence: 'emphasisSequence'
let emphasisText: 'emphasisText'
let escapeMarker: 'escapeMarker'
let hardBreakEscape: 'hardBreakEscape'
let hardBreakTrailing: 'hardBreakTrailing'
let htmlFlow: 'htmlFlow'
let htmlFlowData: 'htmlFlowData'
let htmlText: 'htmlText'
let htmlTextData: 'htmlTextData'
let image: 'image'
let label: 'label'
let labelText: 'labelText'
let labelLink: 'labelLink'
let labelImage: 'labelImage'
let labelMarker: 'labelMarker'
let labelImageMarker: 'labelImageMarker'
let labelEnd: 'labelEnd'
let link: 'link'
let paragraph: 'paragraph'
let reference: 'reference'
let referenceMarker: 'referenceMarker'
let referenceString: 'referenceString'
let resource: 'resource'
let resourceDestination: 'resourceDestination'
let resourceDestinationLiteral: 'resourceDestinationLiteral'
let resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker'
let resourceDestinationRaw: 'resourceDestinationRaw'
let resourceDestinationString: 'resourceDestinationString'
let resourceMarker: 'resourceMarker'
let resourceTitle: 'resourceTitle'
let resourceTitleMarker: 'resourceTitleMarker'
let resourceTitleString: 'resourceTitleString'
let setextHeading: 'setextHeading'
let setextHeadingText: 'setextHeadingText'
let setextHeadingLine: 'setextHeadingLine'
let setextHeadingLineSequence: 'setextHeadingLineSequence'
let strong: 'strong'
let strongSequence: 'strongSequence'
let strongText: 'strongText'
let thematicBreak: 'thematicBreak'
let thematicBreakSequence: 'thematicBreakSequence'
let blockQuote: 'blockQuote'
let blockQuotePrefix: 'blockQuotePrefix'
let blockQuoteMarker: 'blockQuoteMarker'
let blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace'
let listOrdered: 'listOrdered'
let listUnordered: 'listUnordered'
let listItemIndent: 'listItemIndent'
let listItemMarker: 'listItemMarker'
let listItemPrefix: 'listItemPrefix'
let listItemPrefixWhitespace: 'listItemPrefixWhitespace'
let listItemValue: 'listItemValue'
let chunkDocument: 'chunkDocument'
let chunkContent: 'chunkContent'
let chunkFlow: 'chunkFlow'
let chunkText: 'chunkText'
let chunkString: 'chunkString'
}

View File

@@ -0,0 +1,453 @@
/**
* This module is compiled away!
*
* Here is the list of all types of tokens exposed by micromark, with a short
* explanation of what they include and where they are found.
* In picking names, generally, the rule is to be as explicit as possible
* instead of reusing names.
* For example, there is a `definitionDestination` and a `resourceDestination`,
* instead of one shared name.
*/
// Note: when changing the next record, you must also change `TokenTypeMap`
// in `micromark-util-types/index.d.ts`.
export const types = /** @type {const} */ ({
// Generic type for data, such as in a title, a destination, etc.
data: 'data',
// Generic type for syntactic whitespace (tabs, virtual spaces, spaces).
// Such as, between a fenced code fence and an info string.
whitespace: 'whitespace',
// Generic type for line endings (line feed, carriage return, carriage return +
// line feed).
lineEnding: 'lineEnding',
// A line ending, but ending a blank line.
lineEndingBlank: 'lineEndingBlank',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the start of a
// line.
linePrefix: 'linePrefix',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the end of a
// line.
lineSuffix: 'lineSuffix',
// Whole ATX heading:
//
// ```markdown
// #
// ## Alpha
// ### Bravo ###
// ```
//
// Includes `atxHeadingSequence`, `whitespace`, `atxHeadingText`.
atxHeading: 'atxHeading',
// Sequence of number signs in an ATX heading (`###`).
atxHeadingSequence: 'atxHeadingSequence',
// Content in an ATX heading (`alpha`).
// Includes text.
atxHeadingText: 'atxHeadingText',
// Whole autolink (`<https://example.com>` or `<admin@example.com>`)
// Includes `autolinkMarker` and `autolinkProtocol` or `autolinkEmail`.
autolink: 'autolink',
// Email autolink w/o markers (`admin@example.com`)
autolinkEmail: 'autolinkEmail',
// Marker around an `autolinkProtocol` or `autolinkEmail` (`<` or `>`).
autolinkMarker: 'autolinkMarker',
// Protocol autolink w/o markers (`https://example.com`)
autolinkProtocol: 'autolinkProtocol',
// A whole character escape (`\-`).
// Includes `escapeMarker` and `characterEscapeValue`.
characterEscape: 'characterEscape',
// The escaped character (`-`).
characterEscapeValue: 'characterEscapeValue',
// A whole character reference (`&amp;`, `&#8800;`, or `&#x1D306;`).
// Includes `characterReferenceMarker`, an optional
// `characterReferenceMarkerNumeric`, in which case an optional
// `characterReferenceMarkerHexadecimal`, and a `characterReferenceValue`.
characterReference: 'characterReference',
// The start or end marker (`&` or `;`).
characterReferenceMarker: 'characterReferenceMarker',
// Mark reference as numeric (`#`).
characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric',
// Mark reference as numeric (`x` or `X`).
characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal',
// Value of character reference w/o markers (`amp`, `8800`, or `1D306`).
characterReferenceValue: 'characterReferenceValue',
// Whole fenced code:
//
// ````markdown
// ```js
// alert(1)
// ```
// ````
codeFenced: 'codeFenced',
// A fenced code fence, including whitespace, sequence, info, and meta
// (` ```js `).
codeFencedFence: 'codeFencedFence',
// Sequence of grave accent or tilde characters (` ``` `) in a fence.
codeFencedFenceSequence: 'codeFencedFenceSequence',
// Info word (`js`) in a fence.
// Includes string.
codeFencedFenceInfo: 'codeFencedFenceInfo',
// Meta words (`highlight="1"`) in a fence.
// Includes string.
codeFencedFenceMeta: 'codeFencedFenceMeta',
// A line of code.
codeFlowValue: 'codeFlowValue',
// Whole indented code:
//
// ```markdown
// alert(1)
// ```
//
// Includes `lineEnding`, `linePrefix`, and `codeFlowValue`.
codeIndented: 'codeIndented',
// A text code (``` `alpha` ```).
// Includes `codeTextSequence`, `codeTextData`, `lineEnding`, and can include
// `codeTextPadding`.
codeText: 'codeText',
codeTextData: 'codeTextData',
// A space or line ending right after or before a tick.
codeTextPadding: 'codeTextPadding',
// A text code fence (` `` `).
codeTextSequence: 'codeTextSequence',
// Whole content:
//
// ```markdown
// [a]: b
// c
// =
// d
// ```
//
// Includes `paragraph` and `definition`.
content: 'content',
// Whole definition:
//
// ```markdown
// [micromark]: https://github.com/micromark/micromark
// ```
//
// Includes `definitionLabel`, `definitionMarker`, `whitespace`,
// `definitionDestination`, and optionally `lineEnding` and `definitionTitle`.
definition: 'definition',
// Destination of a definition (`https://github.com/micromark/micromark` or
// `<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteral` or `definitionDestinationRaw`.
definitionDestination: 'definitionDestination',
// Enclosed destination of a definition
// (`<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteralMarker` and optionally
// `definitionDestinationString`.
definitionDestinationLiteral: 'definitionDestinationLiteral',
// Markers of an enclosed definition destination (`<` or `>`).
definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker',
// Unenclosed destination of a definition
// (`https://github.com/micromark/micromark`).
// Includes `definitionDestinationString`.
definitionDestinationRaw: 'definitionDestinationRaw',
// Text in an destination (`https://github.com/micromark/micromark`).
// Includes string.
definitionDestinationString: 'definitionDestinationString',
// Label of a definition (`[micromark]`).
// Includes `definitionLabelMarker` and `definitionLabelString`.
definitionLabel: 'definitionLabel',
// Markers of a definition label (`[` or `]`).
definitionLabelMarker: 'definitionLabelMarker',
// Value of a definition label (`micromark`).
// Includes string.
definitionLabelString: 'definitionLabelString',
// Marker between a label and a destination (`:`).
definitionMarker: 'definitionMarker',
// Title of a definition (`"x"`, `'y'`, or `(z)`).
// Includes `definitionTitleMarker` and optionally `definitionTitleString`.
definitionTitle: 'definitionTitle',
// Marker around a title of a definition (`"`, `'`, `(`, or `)`).
definitionTitleMarker: 'definitionTitleMarker',
// Data without markers in a title (`z`).
// Includes string.
definitionTitleString: 'definitionTitleString',
// Emphasis (`*alpha*`).
// Includes `emphasisSequence` and `emphasisText`.
emphasis: 'emphasis',
// Sequence of emphasis markers (`*` or `_`).
emphasisSequence: 'emphasisSequence',
// Emphasis text (`alpha`).
// Includes text.
emphasisText: 'emphasisText',
// The character escape marker (`\`).
escapeMarker: 'escapeMarker',
// A hard break created with a backslash (`\\n`).
// Note: does not include the line ending.
hardBreakEscape: 'hardBreakEscape',
// A hard break created with trailing spaces (` \n`).
// Does not include the line ending.
hardBreakTrailing: 'hardBreakTrailing',
// Flow HTML:
//
// ```markdown
// <div
// ```
//
// Inlcudes `lineEnding`, `htmlFlowData`.
htmlFlow: 'htmlFlow',
htmlFlowData: 'htmlFlowData',
// HTML in text (the tag in `a <i> b`).
// Includes `lineEnding`, `htmlTextData`.
htmlText: 'htmlText',
htmlTextData: 'htmlTextData',
// Whole image (`![alpha](bravo)`, `![alpha][bravo]`, `![alpha][]`, or
// `![alpha]`).
// Includes `label` and an optional `resource` or `reference`.
image: 'image',
// Whole link label (`[*alpha*]`).
// Includes `labelLink` or `labelImage`, `labelText`, and `labelEnd`.
label: 'label',
// Text in an label (`*alpha*`).
// Includes text.
labelText: 'labelText',
// Start a link label (`[`).
// Includes a `labelMarker`.
labelLink: 'labelLink',
// Start an image label (`![`).
// Includes `labelImageMarker` and `labelMarker`.
labelImage: 'labelImage',
// Marker of a label (`[` or `]`).
labelMarker: 'labelMarker',
// Marker to start an image (`!`).
labelImageMarker: 'labelImageMarker',
// End a label (`]`).
// Includes `labelMarker`.
labelEnd: 'labelEnd',
// Whole link (`[alpha](bravo)`, `[alpha][bravo]`, `[alpha][]`, or `[alpha]`).
// Includes `label` and an optional `resource` or `reference`.
link: 'link',
// Whole paragraph:
//
// ```markdown
// alpha
// bravo.
// ```
//
// Includes text.
paragraph: 'paragraph',
// A reference (`[alpha]` or `[]`).
// Includes `referenceMarker` and an optional `referenceString`.
reference: 'reference',
// A reference marker (`[` or `]`).
referenceMarker: 'referenceMarker',
// Reference text (`alpha`).
// Includes string.
referenceString: 'referenceString',
// A resource (`(https://example.com "alpha")`).
// Includes `resourceMarker`, an optional `resourceDestination` with an optional
// `whitespace` and `resourceTitle`.
resource: 'resource',
// A resource destination (`https://example.com`).
// Includes `resourceDestinationLiteral` or `resourceDestinationRaw`.
resourceDestination: 'resourceDestination',
// A literal resource destination (`<https://example.com>`).
// Includes `resourceDestinationLiteralMarker` and optionally
// `resourceDestinationString`.
resourceDestinationLiteral: 'resourceDestinationLiteral',
// A resource destination marker (`<` or `>`).
resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker',
// A raw resource destination (`https://example.com`).
// Includes `resourceDestinationString`.
resourceDestinationRaw: 'resourceDestinationRaw',
// Resource destination text (`https://example.com`).
// Includes string.
resourceDestinationString: 'resourceDestinationString',
// A resource marker (`(` or `)`).
resourceMarker: 'resourceMarker',
// A resource title (`"alpha"`, `'alpha'`, or `(alpha)`).
// Includes `resourceTitleMarker` and optionally `resourceTitleString`.
resourceTitle: 'resourceTitle',
// A resource title marker (`"`, `'`, `(`, or `)`).
resourceTitleMarker: 'resourceTitleMarker',
// Resource destination title (`alpha`).
// Includes string.
resourceTitleString: 'resourceTitleString',
// Whole setext heading:
//
// ```markdown
// alpha
// bravo
// =====
// ```
//
// Includes `setextHeadingText`, `lineEnding`, `linePrefix`, and
// `setextHeadingLine`.
setextHeading: 'setextHeading',
// Content in a setext heading (`alpha\nbravo`).
// Includes text.
setextHeadingText: 'setextHeadingText',
// Underline in a setext heading, including whitespace suffix (`==`).
// Includes `setextHeadingLineSequence`.
setextHeadingLine: 'setextHeadingLine',
// Sequence of equals or dash characters in underline in a setext heading (`-`).
setextHeadingLineSequence: 'setextHeadingLineSequence',
// Strong (`**alpha**`).
// Includes `strongSequence` and `strongText`.
strong: 'strong',
// Sequence of strong markers (`**` or `__`).
strongSequence: 'strongSequence',
// Strong text (`alpha`).
// Includes text.
strongText: 'strongText',
// Whole thematic break:
//
// ```markdown
// * * *
// ```
//
// Includes `thematicBreakSequence` and `whitespace`.
thematicBreak: 'thematicBreak',
// A sequence of one or more thematic break markers (`***`).
thematicBreakSequence: 'thematicBreakSequence',
// Whole block quote:
//
// ```markdown
// > a
// >
// > b
// ```
//
// Includes `blockQuotePrefix` and flow.
blockQuote: 'blockQuote',
// The `>` or `> ` of a block quote.
blockQuotePrefix: 'blockQuotePrefix',
// The `>` of a block quote prefix.
blockQuoteMarker: 'blockQuoteMarker',
// The optional ` ` of a block quote prefix.
blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace',
// Whole unordered list:
//
// ```markdown
// - a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listOrdered: 'listOrdered',
// Whole ordered list:
//
// ```markdown
// 1. a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listUnordered: 'listUnordered',
// The indent of further list item lines.
listItemIndent: 'listItemIndent',
// A marker, as in, `*`, `+`, `-`, `.`, or `)`.
listItemMarker: 'listItemMarker',
// The thing that starts a list item, such as `1. `.
// Includes `listItemValue` if ordered, `listItemMarker`, and
// `listItemPrefixWhitespace` (unless followed by a line ending).
listItemPrefix: 'listItemPrefix',
// The whitespace after a marker.
listItemPrefixWhitespace: 'listItemPrefixWhitespace',
// The numerical value of an ordered item.
listItemValue: 'listItemValue',
// Internal types used for subtokenizers, compiled away
chunkDocument: 'chunkDocument',
chunkContent: 'chunkContent',
chunkFlow: 'chunkFlow',
chunkText: 'chunkText',
chunkString: 'chunkString'
})

View File

@@ -0,0 +1,101 @@
export namespace values {
let ht: '\t'
let lf: '\n'
let cr: '\r'
let space: ' '
let exclamationMark: '!'
let quotationMark: '"'
let numberSign: '#'
let dollarSign: '$'
let percentSign: '%'
let ampersand: '&'
let apostrophe: "'"
let leftParenthesis: '('
let rightParenthesis: ')'
let asterisk: '*'
let plusSign: '+'
let comma: ','
let dash: '-'
let dot: '.'
let slash: '/'
let digit0: '0'
let digit1: '1'
let digit2: '2'
let digit3: '3'
let digit4: '4'
let digit5: '5'
let digit6: '6'
let digit7: '7'
let digit8: '8'
let digit9: '9'
let colon: ':'
let semicolon: ';'
let lessThan: '<'
let equalsTo: '='
let greaterThan: '>'
let questionMark: '?'
let atSign: '@'
let uppercaseA: 'A'
let uppercaseB: 'B'
let uppercaseC: 'C'
let uppercaseD: 'D'
let uppercaseE: 'E'
let uppercaseF: 'F'
let uppercaseG: 'G'
let uppercaseH: 'H'
let uppercaseI: 'I'
let uppercaseJ: 'J'
let uppercaseK: 'K'
let uppercaseL: 'L'
let uppercaseM: 'M'
let uppercaseN: 'N'
let uppercaseO: 'O'
let uppercaseP: 'P'
let uppercaseQ: 'Q'
let uppercaseR: 'R'
let uppercaseS: 'S'
let uppercaseT: 'T'
let uppercaseU: 'U'
let uppercaseV: 'V'
let uppercaseW: 'W'
let uppercaseX: 'X'
let uppercaseY: 'Y'
let uppercaseZ: 'Z'
let leftSquareBracket: '['
let backslash: '\\'
let rightSquareBracket: ']'
let caret: '^'
let underscore: '_'
let graveAccent: '`'
let lowercaseA: 'a'
let lowercaseB: 'b'
let lowercaseC: 'c'
let lowercaseD: 'd'
let lowercaseE: 'e'
let lowercaseF: 'f'
let lowercaseG: 'g'
let lowercaseH: 'h'
let lowercaseI: 'i'
let lowercaseJ: 'j'
let lowercaseK: 'k'
let lowercaseL: 'l'
let lowercaseM: 'm'
let lowercaseN: 'n'
let lowercaseO: 'o'
let lowercaseP: 'p'
let lowercaseQ: 'q'
let lowercaseR: 'r'
let lowercaseS: 's'
let lowercaseT: 't'
let lowercaseU: 'u'
let lowercaseV: 'v'
let lowercaseW: 'w'
let lowercaseX: 'x'
let lowercaseY: 'y'
let lowercaseZ: 'z'
let leftCurlyBrace: '{'
let verticalBar: '|'
let rightCurlyBrace: '}'
let tilde: '~'
let replacementCharacter: '<27>'
}

View File

@@ -0,0 +1,109 @@
/**
* This module is compiled away!
*
* While micromark works based on character codes, this module includes the
* string versions of em.
* The C0 block, except for LF, CR, HT, and w/ the replacement character added,
* are available here.
*/
export const values = /** @type {const} */ ({
ht: '\t',
lf: '\n',
cr: '\r',
space: ' ',
exclamationMark: '!',
quotationMark: '"',
numberSign: '#',
dollarSign: '$',
percentSign: '%',
ampersand: '&',
apostrophe: "'",
leftParenthesis: '(',
rightParenthesis: ')',
asterisk: '*',
plusSign: '+',
comma: ',',
dash: '-',
dot: '.',
slash: '/',
digit0: '0',
digit1: '1',
digit2: '2',
digit3: '3',
digit4: '4',
digit5: '5',
digit6: '6',
digit7: '7',
digit8: '8',
digit9: '9',
colon: ':',
semicolon: ';',
lessThan: '<',
equalsTo: '=',
greaterThan: '>',
questionMark: '?',
atSign: '@',
uppercaseA: 'A',
uppercaseB: 'B',
uppercaseC: 'C',
uppercaseD: 'D',
uppercaseE: 'E',
uppercaseF: 'F',
uppercaseG: 'G',
uppercaseH: 'H',
uppercaseI: 'I',
uppercaseJ: 'J',
uppercaseK: 'K',
uppercaseL: 'L',
uppercaseM: 'M',
uppercaseN: 'N',
uppercaseO: 'O',
uppercaseP: 'P',
uppercaseQ: 'Q',
uppercaseR: 'R',
uppercaseS: 'S',
uppercaseT: 'T',
uppercaseU: 'U',
uppercaseV: 'V',
uppercaseW: 'W',
uppercaseX: 'X',
uppercaseY: 'Y',
uppercaseZ: 'Z',
leftSquareBracket: '[',
backslash: '\\',
rightSquareBracket: ']',
caret: '^',
underscore: '_',
graveAccent: '`',
lowercaseA: 'a',
lowercaseB: 'b',
lowercaseC: 'c',
lowercaseD: 'd',
lowercaseE: 'e',
lowercaseF: 'f',
lowercaseG: 'g',
lowercaseH: 'h',
lowercaseI: 'i',
lowercaseJ: 'j',
lowercaseK: 'k',
lowercaseL: 'l',
lowercaseM: 'm',
lowercaseN: 'n',
lowercaseO: 'o',
lowercaseP: 'p',
lowercaseQ: 'q',
lowercaseR: 'r',
lowercaseS: 's',
lowercaseT: 't',
lowercaseU: 'u',
lowercaseV: 'v',
lowercaseW: 'w',
lowercaseX: 'x',
lowercaseY: 'y',
lowercaseZ: 'z',
leftCurlyBrace: '{',
verticalBar: '|',
rightCurlyBrace: '}',
tilde: '~',
replacementCharacter: '<27>'
})

View File

@@ -0,0 +1,35 @@
{
"name": "micromark-util-symbol",
"version": "2.0.0",
"description": "micromark utility with symbols",
"license": "MIT",
"keywords": [
"micromark",
"util",
"utility",
"symbol"
],
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-symbol",
"bugs": "https://github.com/micromark/micromark/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",
"files": [
"lib/"
],
"exports": "./lib/default.js",
"xo": false
}

View File

@@ -0,0 +1,168 @@
# micromark-util-symbol
[![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][] utility with symbols.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package exposes constants used throughout the micromark ecosystem.
## When should I use this?
This package is useful when you are making your own micromark extensions.
Its useful to reference these constants by name instead of value while
developing.
[`micromark-build`][micromark-build] compiles them away for production code.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install micromark-util-symbol
```
In Deno with [`esm.sh`][esmsh]:
```js
import * as symbol from 'https://esm.sh/micromark-util-symbol@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import * as symbol from 'https://esm.sh/micromark-util-symbol@1?bundle'
</script>
```
## Use
```js
import {codes, constants, types, values} from 'micromark-util-symbol'
console.log(codes.atSign) // 64
console.log(constants.characterReferenceNamedSizeMax) // 31
console.log(types.definitionDestinationRaw) // 'definitionDestinationRaw'
console.log(values.atSign) // '@'
```
## API
This package exports the identifiers `codes`, `constants`, `types`, and
`values`.
There is no default export.
Each identifier is an object mapping strings to values.
See the code for the exposed data.
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## 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-symbol@^2`, compatible with Node.js 16.
This package works with `micromark@^3`.
## Security
This package is safe.
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## 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/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-symbol.svg
[downloads]: https://www.npmjs.com/package/micromark-util-symbol
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-symbol
[bundle-size]: https://bundlejs.com/?q=micromark-util-symbol
[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
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[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/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
[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
[typescript]: https://www.typescriptlang.org
[micromark]: https://github.com/micromark/micromark
[micromark-build]: https://github.com/micromark/micromark/tree/main/packages/micromark-build

View File

@@ -0,0 +1,65 @@
{
"name": "micromark-util-events-to-acorn",
"version": "2.0.2",
"description": "micromark utility to try and parse events w/ acorn",
"license": "MIT",
"keywords": [
"micromark",
"factory",
"mdx",
"expression"
],
"repository": "https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-util-events-to-acorn",
"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",
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"files": [
"dev/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/acorn": "^4.0.0",
"@types/estree": "^1.0.0",
"@types/unist": "^3.0.0",
"devlop": "^1.0.0",
"estree-util-visit": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0",
"vfile-message": "^4.0.0"
},
"scripts": {
"build": "micromark-build"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"unicorn/prefer-at": "off",
"unicorn/prefer-string-replace-all": "off"
}
}
}

241
node_modules/micromark-util-events-to-acorn/readme.md generated vendored Normal file
View File

@@ -0,0 +1,241 @@
# micromark-util-events-to-acorn
[![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][] utility to try and parse events with acorn.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`eventsToAcorn(events, options)`](#eventstoacornevents-options)
* [`Options`](#options)
* [`Result`](#result)
* [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-util-events-to-acorn
```
In Deno with [`esm.sh`][esmsh]:
```js
import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@2?bundle'
</script>
```
## Use
```js
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`][api-events-to-acorn].
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.
### `eventsToAcorn(events, options)`
###### Parameters
* `events` (`Array<Event>`)
— events
* `options` ([`Options`][api-options])
— configuration (required)
###### Returns
Result ([`Result`][api-result]).
### `Options`
Configuration (TypeScript type).
###### Fields
* `acorn` ([`Acorn`][acorn], required)
— 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 if `allowEmpty`)
— 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
* `estree` ([`Program`][program] or `undefined`)
— Program
* `error` (`Error` or `undefined`)
— 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 types [`Acorn`][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
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-util-events-to-acorn.svg
[downloads]: https://www.npmjs.com/package/micromark-util-events-to-acorn
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-events-to-acorn
[size]: https://bundlejs.com/?q=micromark-util-events-to-acorn
[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
[program]: https://github.com/estree/estree/blob/master/es2015.md#programs
[api-events-to-acorn]: #eventstoacornevents-options
[api-options]: #options
[api-result]: #result