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,33 @@
/**
* Create smart processors to handle different formats.
*
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Configuration (optional).
* @return {FormatAwareProcessors}
* Smart processor.
*/
export function createFormatAwareProcessors(compileOptions?: Readonly<CompileOptions> | null | undefined): FormatAwareProcessors;
export type Program = import('estree-jsx').Program;
export type Root = import('mdast').Root;
export type Processor = import('unified').Processor<Root, Program, Program, Program, string>;
export type Compatible = import('vfile').Compatible;
export type VFile = import('vfile').VFile;
export type CompileOptions = import('../compile.js').CompileOptions;
/**
* Result.
*/
export type FormatAwareProcessors = {
/**
* Extensions to use.
*/
extnames: ReadonlyArray<string>;
/**
* Smart processor, async.
*/
process: Process;
};
/**
* Smart processor.
*/
export type Process = (vfileCompatible: Compatible) => Promise<VFile>;
//# sourceMappingURL=create-format-aware-processors.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"create-format-aware-processors.d.ts","sourceRoot":"","sources":["create-format-aware-processors.js"],"names":[],"mappings":"AA6BA;;;;;;;GAOG;AACH,6DALW,SAAS,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,GAE1C,qBAAqB,CAsDhC;sBAvFY,OAAO,YAAY,EAAE,OAAO;mBAC5B,OAAO,OAAO,EAAE,IAAI;wBACpB,OAAO,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;yBACpE,OAAO,OAAO,EAAE,UAAU;oBAC1B,OAAO,OAAO,EAAE,KAAK;6BACrB,OAAO,eAAe,EAAE,cAAc;;;;;;;;cAMrC,cAAc,MAAM,CAAC;;;;aAErB,OAAO;;;;;wCAKV,UAAU,KAET,QAAQ,KAAK,CAAC"}

View File

@@ -0,0 +1,89 @@
/**
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('mdast').Root} Root
* @typedef {import('unified').Processor<Root, Program, Program, Program, string>} Processor
* @typedef {import('vfile').Compatible} Compatible
* @typedef {import('vfile').VFile} VFile
* @typedef {import('../compile.js').CompileOptions} CompileOptions
*/
/**
* @typedef FormatAwareProcessors
* Result.
* @property {ReadonlyArray<string>} extnames
* Extensions to use.
* @property {Process} process
* Smart processor, async.
*
* @callback Process
* Smart processor.
* @param {Compatible} vfileCompatible
* MDX or markdown document.
* @return {Promise<VFile>}
* File.
*/
import {createProcessor} from '../core.js'
import {md, mdx} from './extnames.js'
import {resolveFileAndOptions} from './resolve-file-and-options.js'
/**
* Create smart processors to handle different formats.
*
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Configuration (optional).
* @return {FormatAwareProcessors}
* Smart processor.
*/
export function createFormatAwareProcessors(compileOptions) {
const compileOptions_ = compileOptions || {}
const mdExtensions = compileOptions_.mdExtensions || md
const mdxExtensions = compileOptions_.mdxExtensions || mdx
/** @type {Processor} */
let cachedMarkdown
/** @type {Processor} */
let cachedMdx
return {
extnames:
compileOptions_.format === 'md'
? mdExtensions
: compileOptions_.format === 'mdx'
? mdxExtensions
: [...mdExtensions, ...mdxExtensions],
process
}
/**
* Smart processor.
*
* @type {Process}
*/
function process(vfileCompatible) {
const {file, processor} = split(vfileCompatible)
return processor.process(file)
}
/**
* Make a full vfile from whats given, and figure out which processor
* should be used for it.
* This caches processors (one for markdown and one for MDX) so that they do
* not have to be reconstructed for each file.
*
* @param {Compatible} vfileCompatible
* MDX or markdown document.
* @return {{file: VFile, processor: Processor}}
* File and corresponding processor.
*/
function split(vfileCompatible) {
const {file, options} = resolveFileAndOptions(
vfileCompatible,
compileOptions_
)
const processor =
options.format === 'md'
? cachedMarkdown || (cachedMarkdown = createProcessor(options))
: cachedMdx || (cachedMdx = createProcessor(options))
return {file, processor}
}
}

View File

@@ -0,0 +1,11 @@
/**
* @param {Readonly<Node>} from
* Node to take from.
* @param {Node} to
* Node to add to.
* @returns {undefined}
* Nothing.
*/
export function create(from: Readonly<Node>, to: Node): undefined;
export type Node = import('estree-jsx').Node;
//# sourceMappingURL=estree-util-create.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-create.d.ts","sourceRoot":"","sources":["estree-util-create.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,6BAPW,SAAS,IAAI,CAAC,MAEd,IAAI,GAEF,SAAS,CAiBrB;mBA5BY,OAAO,YAAY,EAAE,IAAI"}

View File

@@ -0,0 +1,30 @@
/**
* @typedef {import('estree-jsx').Node} Node
*/
// Fix to show references to above types in VS Code.
''
/**
* @param {Readonly<Node>} from
* Node to take from.
* @param {Node} to
* Node to add to.
* @returns {undefined}
* Nothing.
*/
export function create(from, to) {
/** @type {Array<keyof Node>} */
// @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields.
const fields = ['start', 'end', 'loc', 'range', 'comments']
let index = -1
while (++index < fields.length) {
const field = fields[index]
if (field in from) {
// @ts-expect-error: assume theyre settable.
to[field] = from[field]
}
}
}

View File

@@ -0,0 +1,18 @@
/**
* Turn a declaration into an expression.
*
* Doesnt work for variable declarations, but thats fine for our use case
* because currently were using this utility for export default declarations,
* which cant contain variable declarations.
*
* @param {Readonly<Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration>} declaration
* Declaration.
* @returns {Expression}
* Expression.
*/
export function declarationToExpression(declaration: Readonly<Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration>): Expression;
export type Declaration = import('estree-jsx').Declaration;
export type Expression = import('estree-jsx').Expression;
export type MaybeNamedClassDeclaration = import('estree-jsx').MaybeNamedClassDeclaration;
export type MaybeNamedFunctionDeclaration = import('estree-jsx').MaybeNamedFunctionDeclaration;
//# sourceMappingURL=estree-util-declaration-to-expression.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-declaration-to-expression.d.ts","sourceRoot":"","sources":["estree-util-declaration-to-expression.js"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,qDALW,SAAS,WAAW,GAAG,0BAA0B,GAAG,6BAA6B,CAAC,GAEhF,UAAU,CAYtB;0BA7BY,OAAO,YAAY,EAAE,WAAW;yBAChC,OAAO,YAAY,EAAE,UAAU;yCAC/B,OAAO,YAAY,EAAE,0BAA0B;4CAC/C,OAAO,YAAY,EAAE,6BAA6B"}

View File

@@ -0,0 +1,31 @@
/**
* @typedef {import('estree-jsx').Declaration} Declaration
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').MaybeNamedClassDeclaration} MaybeNamedClassDeclaration
* @typedef {import('estree-jsx').MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration
*/
import {ok as assert} from 'devlop'
/**
* Turn a declaration into an expression.
*
* Doesnt work for variable declarations, but thats fine for our use case
* because currently were using this utility for export default declarations,
* which cant contain variable declarations.
*
* @param {Readonly<Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration>} declaration
* Declaration.
* @returns {Expression}
* Expression.
*/
export function declarationToExpression(declaration) {
if (declaration.type === 'FunctionDeclaration') {
return {...declaration, type: 'FunctionExpression'}
}
// This is currently an internal utility so the next shouldnt happen or a
// maintainer is making a mistake.
assert(declaration.type === 'ClassDeclaration', 'unexpected node type')
return {...declaration, type: 'ClassExpression'}
}

View File

@@ -0,0 +1,14 @@
/**
* Check if `node` is a declaration.
*
* @param {Readonly<MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration | Node>} node
* Node to check.
* @returns {node is Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration}
* Whether `node` is a declaration.
*/
export function isDeclaration(node: Readonly<MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration | Node>): node is import("estree").MaybeNamedClassDeclaration | import("estree").MaybeNamedFunctionDeclaration | import("estree").Declaration;
export type Declaration = import('estree-jsx').Declaration;
export type MaybeNamedClassDeclaration = import('estree-jsx').MaybeNamedClassDeclaration;
export type MaybeNamedFunctionDeclaration = import('estree-jsx').MaybeNamedFunctionDeclaration;
export type Node = import('estree-jsx').Node;
//# sourceMappingURL=estree-util-is-declaration.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-is-declaration.d.ts","sourceRoot":"","sources":["estree-util-is-declaration.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,oCALW,SAAS,0BAA0B,GAAG,6BAA6B,GAAG,IAAI,CAAC,uIAWrF;0BAvBY,OAAO,YAAY,EAAE,WAAW;yCAChC,OAAO,YAAY,EAAE,0BAA0B;4CAC/C,OAAO,YAAY,EAAE,6BAA6B;mBAClD,OAAO,YAAY,EAAE,IAAI"}

View File

@@ -0,0 +1,25 @@
/**
* @typedef {import('estree-jsx').Declaration} Declaration
* @typedef {import('estree-jsx').MaybeNamedClassDeclaration} MaybeNamedClassDeclaration
* @typedef {import('estree-jsx').MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration
* @typedef {import('estree-jsx').Node} Node
*/
// Fix to show references to above types in VS Code.
''
/**
* Check if `node` is a declaration.
*
* @param {Readonly<MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration | Node>} node
* Node to check.
* @returns {node is Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration}
* Whether `node` is a declaration.
*/
export function isDeclaration(node) {
return Boolean(
node.type === 'FunctionDeclaration' ||
node.type === 'ClassDeclaration' ||
node.type === 'VariableDeclaration'
)
}

View File

@@ -0,0 +1,18 @@
/**
* @param {ReadonlyArray<Readonly<ExportSpecifier> | Readonly<ImportDefaultSpecifier> | Readonly<ImportNamespaceSpecifier> | Readonly<ImportSpecifier>>} specifiers
* Specifiers.
* @param {Readonly<Expression>} init
* Initializer.
* @returns {Array<VariableDeclarator>}
* Declarations.
*/
export function specifiersToDeclarations(specifiers: ReadonlyArray<Readonly<ExportSpecifier> | Readonly<ImportDefaultSpecifier> | Readonly<ImportNamespaceSpecifier> | Readonly<ImportSpecifier>>, init: Readonly<Expression>): Array<VariableDeclarator>;
export type AssignmentProperty = import('estree-jsx').AssignmentProperty;
export type ExportSpecifier = import('estree-jsx').ExportSpecifier;
export type Expression = import('estree-jsx').Expression;
export type Identifier = import('estree-jsx').Identifier;
export type ImportDefaultSpecifier = import('estree-jsx').ImportDefaultSpecifier;
export type ImportNamespaceSpecifier = import('estree-jsx').ImportNamespaceSpecifier;
export type ImportSpecifier = import('estree-jsx').ImportSpecifier;
export type VariableDeclarator = import('estree-jsx').VariableDeclarator;
//# sourceMappingURL=estree-util-specifiers-to-declarations.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-specifiers-to-declarations.d.ts","sourceRoot":"","sources":["estree-util-specifiers-to-declarations.js"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,qDAPW,cAAc,SAAS,eAAe,CAAC,GAAG,SAAS,sBAAsB,CAAC,GAAG,SAAS,wBAAwB,CAAC,GAAG,SAAS,eAAe,CAAC,CAAC,QAE5I,SAAS,UAAU,CAAC,GAElB,MAAM,kBAAkB,CAAC,CA0ErC;iCA3FY,OAAO,YAAY,EAAE,kBAAkB;8BACvC,OAAO,YAAY,EAAE,eAAe;yBACpC,OAAO,YAAY,EAAE,UAAU;yBAC/B,OAAO,YAAY,EAAE,UAAU;qCAC/B,OAAO,YAAY,EAAE,sBAAsB;uCAC3C,OAAO,YAAY,EAAE,wBAAwB;8BAC7C,OAAO,YAAY,EAAE,eAAe;iCACpC,OAAO,YAAY,EAAE,kBAAkB"}

View File

@@ -0,0 +1,93 @@
/**
* @typedef {import('estree-jsx').AssignmentProperty} AssignmentProperty
* @typedef {import('estree-jsx').ExportSpecifier} ExportSpecifier
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').ImportDefaultSpecifier} ImportDefaultSpecifier
* @typedef {import('estree-jsx').ImportNamespaceSpecifier} ImportNamespaceSpecifier
* @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier
* @typedef {import('estree-jsx').VariableDeclarator} VariableDeclarator
*/
import {create} from './estree-util-create.js'
/**
* @param {ReadonlyArray<Readonly<ExportSpecifier> | Readonly<ImportDefaultSpecifier> | Readonly<ImportNamespaceSpecifier> | Readonly<ImportSpecifier>>} specifiers
* Specifiers.
* @param {Readonly<Expression>} init
* Initializer.
* @returns {Array<VariableDeclarator>}
* Declarations.
*/
export function specifiersToDeclarations(specifiers, init) {
let index = -1
/** @type {Array<VariableDeclarator>} */
const declarations = []
/** @type {Array<ExportSpecifier | ImportDefaultSpecifier | ImportSpecifier>} */
const otherSpecifiers = []
// Can only be one according to JS syntax.
/** @type {ImportNamespaceSpecifier | undefined} */
let importNamespaceSpecifier
while (++index < specifiers.length) {
const specifier = specifiers[index]
if (specifier.type === 'ImportNamespaceSpecifier') {
importNamespaceSpecifier = specifier
} else {
otherSpecifiers.push(specifier)
}
}
if (importNamespaceSpecifier) {
/** @type {VariableDeclarator} */
const declarator = {
type: 'VariableDeclarator',
id: importNamespaceSpecifier.local,
init
}
create(importNamespaceSpecifier, declarator)
declarations.push(declarator)
}
declarations.push({
type: 'VariableDeclarator',
id: {
type: 'ObjectPattern',
properties: otherSpecifiers.map(function (specifier) {
/** @type {Identifier} */
let key =
specifier.type === 'ImportSpecifier'
? specifier.imported
: specifier.type === 'ExportSpecifier'
? specifier.exported
: {type: 'Identifier', name: 'default'}
let value = specifier.local
// Switch them around if were exporting.
if (specifier.type === 'ExportSpecifier') {
value = key
key = specifier.local
}
/** @type {AssignmentProperty} */
const property = {
type: 'Property',
kind: 'init',
shorthand: key.name === value.name,
method: false,
computed: false,
key,
value
}
create(specifier, property)
return property
})
},
init: importNamespaceSpecifier
? {type: 'Identifier', name: importNamespaceSpecifier.local.name}
: init
})
return declarations
}

View File

@@ -0,0 +1,9 @@
/**
* @param {ReadonlyArray<Expression>} expressions
* Expressions.
* @returns {Expression}
* Addition.
*/
export function toBinaryAddition(expressions: ReadonlyArray<Expression>): Expression;
export type Expression = import('estree-jsx').Expression;
//# sourceMappingURL=estree-util-to-binary-addition.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-to-binary-addition.d.ts","sourceRoot":"","sources":["estree-util-to-binary-addition.js"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,8CALW,cAAc,UAAU,CAAC,GAEvB,UAAU,CAetB;yBAvBY,OAAO,YAAY,EAAE,UAAU"}

View File

@@ -0,0 +1,25 @@
/**
* @typedef {import('estree-jsx').Expression} Expression
*/
import {ok as assert} from 'devlop'
/**
* @param {ReadonlyArray<Expression>} expressions
* Expressions.
* @returns {Expression}
* Addition.
*/
export function toBinaryAddition(expressions) {
let index = -1
/** @type {Expression | undefined} */
let left
while (++index < expressions.length) {
const right = expressions[index]
left = left ? {type: 'BinaryExpression', left, operator: '+', right} : right
}
assert(left, 'expected non-empty `expressions` to be passed')
return left
}

View File

@@ -0,0 +1,20 @@
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {Identifier | MemberExpression}
* Identifier or member expression.
*/
export function toIdOrMemberExpression(ids: ReadonlyArray<number | string>): Identifier | MemberExpression;
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {JSXIdentifier | JSXMemberExpression}
* Identifier or member expression.
*/
export function toJsxIdOrMemberExpression(ids: ReadonlyArray<number | string>): JSXIdentifier | JSXMemberExpression;
export type Identifier = import('estree-jsx').Identifier;
export type JSXIdentifier = import('estree-jsx').JSXIdentifier;
export type JSXMemberExpression = import('estree-jsx').JSXMemberExpression;
export type Literal = import('estree-jsx').Literal;
export type MemberExpression = import('estree-jsx').MemberExpression;
//# sourceMappingURL=estree-util-to-id-or-member-expression.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-to-id-or-member-expression.d.ts","sourceRoot":"","sources":["estree-util-to-id-or-member-expression.js"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,4CALW,cAAc,MAAM,GAAG,MAAM,CAAC,GAE5B,UAAU,GAAG,gBAAgB,CA6BzC;AAED;;;;;GAKG;AACH,+CALW,cAAc,MAAM,GAAG,MAAM,CAAC,GAE5B,aAAa,GAAG,mBAAmB,CAsB/C;yBArEY,OAAO,YAAY,EAAE,UAAU;4BAC/B,OAAO,YAAY,EAAE,aAAa;kCAClC,OAAO,YAAY,EAAE,mBAAmB;sBACxC,OAAO,YAAY,EAAE,OAAO;+BAC5B,OAAO,YAAY,EAAE,gBAAgB"}

View File

@@ -0,0 +1,71 @@
/**
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').JSXIdentifier} JSXIdentifier
* @typedef {import('estree-jsx').JSXMemberExpression} JSXMemberExpression
* @typedef {import('estree-jsx').Literal} Literal
* @typedef {import('estree-jsx').MemberExpression} MemberExpression
*/
import {ok as assert} from 'devlop'
import {name as isIdentifierName} from 'estree-util-is-identifier-name'
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {Identifier | MemberExpression}
* Identifier or member expression.
*/
export function toIdOrMemberExpression(ids) {
let index = -1
/** @type {Identifier | Literal | MemberExpression | undefined} */
let object
while (++index < ids.length) {
const name = ids[index]
/** @type {Identifier | Literal} */
const id =
typeof name === 'string' && isIdentifierName(name)
? {type: 'Identifier', name}
: {type: 'Literal', value: name}
object = object
? {
type: 'MemberExpression',
object,
property: id,
computed: id.type === 'Literal',
optional: false
}
: id
}
assert(object, 'expected non-empty `ids` to be passed')
assert(object.type !== 'Literal', 'expected identifier as left-most value')
return object
}
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {JSXIdentifier | JSXMemberExpression}
* Identifier or member expression.
*/
export function toJsxIdOrMemberExpression(ids) {
let index = -1
/** @type {JSXIdentifier | JSXMemberExpression | undefined} */
let object
while (++index < ids.length) {
const name = ids[index]
assert(
typeof name === 'string' && isIdentifierName(name, {jsx: true}),
'expected valid jsx identifier, not `' + name + '`'
)
/** @type {JSXIdentifier} */
const id = {type: 'JSXIdentifier', name}
object = object ? {type: 'JSXMemberExpression', object, property: id} : id
}
assert(object, 'expected non-empty `ids` to be passed')
return object
}

View File

@@ -0,0 +1,10 @@
/**
* Turn a list of extnames (*with* dots) into an expression.
*
* @param {ReadonlyArray<string>} extnames
* List of extnames.
* @returns {RegExp}
* Regex matching them.
*/
export function extnamesToRegex(extnames: ReadonlyArray<string>): RegExp;
//# sourceMappingURL=extnames-to-regex.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extnames-to-regex.d.ts","sourceRoot":"","sources":["extnames-to-regex.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,0CALW,cAAc,MAAM,CAAC,GAEnB,MAAM,CAalB"}

19
node_modules/@mdx-js/mdx/lib/util/extnames-to-regex.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
/**
* Turn a list of extnames (*with* dots) into an expression.
*
* @param {ReadonlyArray<string>} extnames
* List of extnames.
* @returns {RegExp}
* Regex matching them.
*/
export function extnamesToRegex(extnames) {
return new RegExp(
'\\.(' +
extnames
.map(function (d) {
return d.slice(1)
})
.join('|') +
')([?#]|$)'
)
}

3
node_modules/@mdx-js/mdx/lib/util/extnames.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export const md: string[];
export const mdx: string[];
//# sourceMappingURL=extnames.d.ts.map

1
node_modules/@mdx-js/mdx/lib/util/extnames.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"extnames.d.ts","sourceRoot":"","sources":["extnames.js"],"names":[],"mappings":"AAEA,0BAEE;AACF,2BAA2B"}

6
node_modules/@mdx-js/mdx/lib/util/extnames.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import markdownExtensions from 'markdown-extensions'
export const md = markdownExtensions.map(function (d) {
return '.' + d
})
export const mdx = ['.mdx']

View File

@@ -0,0 +1,71 @@
/**
* Split compiletime options from runtime options.
*
* @param {Readonly<EvaluateOptions> | null | undefined} options
* Configuration.
* @returns {{compiletime: CompileOptions, runtime: RunOptions}}
* Split options.
*/
export function resolveEvaluateOptions(options: Readonly<EvaluateOptions> | null | undefined): {
compiletime: CompileOptions;
runtime: RunOptions;
};
export type Fragment = import('hast-util-to-jsx-runtime').Fragment;
export type Jsx = import('hast-util-to-jsx-runtime').Jsx;
export type JsxDev = import('hast-util-to-jsx-runtime').JsxDev;
export type Components = import('mdx/types.js').MDXComponents;
export type CompileOptions = import('../compile.js').CompileOptions;
/**
* Configuration for `evaluate`.
*/
export type EvaluateOptions = EvaluateProcessorOptions & RunOptions;
/**
* Compile configuration without JSX options for evaluation.
*/
export type EvaluateProcessorOptions = Omit<CompileOptions, 'baseUrl' | 'jsx' | 'jsxImportSource' | 'jsxRuntime' | 'outputFormat' | 'pragma' | 'pragmaFrag' | 'pragmaImportSource' | 'providerImportSource'>;
/**
* Configuration to run compiled code.
*
* `Fragment`, `jsx`, and `jsxs` are used when the code is compiled in
* production mode (`development: false`).
* `Fragment` and `jsxDEV` are used when compiled in development mode
* (`development: true`).
* `useMDXComponents` is used when the code is compiled with
* `providerImportSource: '#'` (the exact value of this compile option
* doesnt matter).
*/
export type RunOptions = {
/**
* Use this URL as `import.meta.url` and resolve `import` and `export … from`
* relative to it (optional, example: `import.meta.url`);
* this option can also be given at compile time in `CompileOptions`;
* you should pass this (likely at runtime), as you might get runtime errors
* when using `import.meta.url` / `import` / `export … from ` otherwise.
*/
baseUrl?: URL | string | null | undefined;
/**
* Symbol to use for fragments (**required**).
*/
Fragment: Fragment;
/**
* Function to generate an element with static children in production mode.
*/
jsx?: Jsx | null | undefined;
/**
* Function to generate an element in development mode.
*/
jsxDEV?: JsxDev | null | undefined;
/**
* Function to generate an element with dynamic children in production mode.
*/
jsxs?: Jsx | null | undefined;
/**
* Function to get components from context.
*/
useMDXComponents?: UseMdxComponents | null | undefined;
};
/**
* Get components from context.
*/
export type UseMdxComponents = () => Components;
//# sourceMappingURL=resolve-evaluate-options.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolve-evaluate-options.d.ts","sourceRoot":"","sources":["resolve-evaluate-options.js"],"names":[],"mappings":"AAmDA;;;;;;;GAOG;AACH,gDALW,SAAS,eAAe,CAAC,GAAG,IAAI,GAAG,SAAS,GAE1C;IAAC,WAAW,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAC,CAgC9D;uBAvFY,OAAO,0BAA0B,EAAE,QAAQ;kBAC3C,OAAO,0BAA0B,EAAE,GAAG;qBACtC,OAAO,0BAA0B,EAAE,MAAM;yBACzC,OAAO,cAAc,EAAE,aAAa;6BACpC,OAAO,eAAe,EAAE,cAAc;;;;8BAItC,wBAAwB,GAAG,UAAU;;;;uCAGrC,KAAK,cAAc,EAAE,SAAS,GAAG,KAAK,GAAG,iBAAiB,GAAG,YAAY,GAAG,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;cAapK,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;cAM/B,QAAQ;;;;UAER,GAAG,GAAG,IAAI,GAAG,SAAS;;;;aAEtB,MAAM,GAAG,IAAI,GAAG,SAAS;;;;WAEzB,GAAG,GAAG,IAAI,GAAG,SAAS;;;;uBAEtB,gBAAgB,GAAG,IAAI,GAAG,SAAS;;;;;qCAKpC,UAAU"}

View File

@@ -0,0 +1,89 @@
/**
* @typedef {import('hast-util-to-jsx-runtime').Fragment} Fragment
* @typedef {import('hast-util-to-jsx-runtime').Jsx} Jsx
* @typedef {import('hast-util-to-jsx-runtime').JsxDev} JsxDev
* @typedef {import('mdx/types.js').MDXComponents} Components
* @typedef {import('../compile.js').CompileOptions} CompileOptions
*/
/**
* @typedef {EvaluateProcessorOptions & RunOptions} EvaluateOptions
* Configuration for `evaluate`.
*
* @typedef {Omit<CompileOptions, 'baseUrl' | 'jsx' | 'jsxImportSource' | 'jsxRuntime' | 'outputFormat' | 'pragma' | 'pragmaFrag' | 'pragmaImportSource' | 'providerImportSource'> } EvaluateProcessorOptions
* Compile configuration without JSX options for evaluation.
*
* @typedef RunOptions
* Configuration to run compiled code.
*
* `Fragment`, `jsx`, and `jsxs` are used when the code is compiled in
* production mode (`development: false`).
* `Fragment` and `jsxDEV` are used when compiled in development mode
* (`development: true`).
* `useMDXComponents` is used when the code is compiled with
* `providerImportSource: '#'` (the exact value of this compile option
* doesnt matter).
* @property {URL | string | null | undefined} [baseUrl]
* Use this URL as `import.meta.url` and resolve `import` and `export … from`
* relative to it (optional, example: `import.meta.url`);
* this option can also be given at compile time in `CompileOptions`;
* you should pass this (likely at runtime), as you might get runtime errors
* when using `import.meta.url` / `import` / `export … from ` otherwise.
* @property {Fragment} Fragment
* Symbol to use for fragments (**required**).
* @property {Jsx | null | undefined} [jsx]
* Function to generate an element with static children in production mode.
* @property {JsxDev | null | undefined} [jsxDEV]
* Function to generate an element in development mode.
* @property {Jsx | null | undefined} [jsxs]
* Function to generate an element with dynamic children in production mode.
* @property {UseMdxComponents | null | undefined} [useMDXComponents]
* Function to get components from context.
*
* @callback UseMdxComponents
* Get components from context.
* @returns {Components}
* Current components.
*/
// Fix to show references to above types in VS Code.
''
/**
* Split compiletime options from runtime options.
*
* @param {Readonly<EvaluateOptions> | null | undefined} options
* Configuration.
* @returns {{compiletime: CompileOptions, runtime: RunOptions}}
* Split options.
*/
export function resolveEvaluateOptions(options) {
const {
Fragment,
baseUrl,
development,
jsx,
jsxDEV,
jsxs,
useMDXComponents,
...rest
} = options || {}
if (!Fragment) throw new Error('Expected `Fragment` given to `evaluate`')
if (development) {
if (!jsxDEV) throw new Error('Expected `jsxDEV` given to `evaluate`')
} else {
if (!jsx) throw new Error('Expected `jsx` given to `evaluate`')
if (!jsxs) throw new Error('Expected `jsxs` given to `evaluate`')
}
return {
compiletime: {
...rest,
development,
outputFormat: 'function-body',
providerImportSource: useMDXComponents ? '#' : undefined
},
runtime: {Fragment, baseUrl, jsx, jsxDEV, jsxs, useMDXComponents}
}
}

View File

@@ -0,0 +1,20 @@
/**
* Create a file and options from a given `vfileCompatible` and options that
* might contain `format: 'detect'`.
*
* @param {Readonly<Compatible>} vfileCompatible
* File.
* @param {Readonly<CompileOptions> | null | undefined} [options]
* Configuration (optional).
* @returns {{file: VFile, options: ProcessorOptions}}
* File and options.
*/
export function resolveFileAndOptions(vfileCompatible: Readonly<Compatible>, options?: Readonly<CompileOptions> | null | undefined): {
file: VFile;
options: ProcessorOptions;
};
export type Compatible = import('vfile').Compatible;
export type CompileOptions = import('../compile.js').CompileOptions;
export type ProcessorOptions = import('../core.js').ProcessorOptions;
import { VFile } from 'vfile';
//# sourceMappingURL=resolve-file-and-options.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolve-file-and-options.d.ts","sourceRoot":"","sources":["resolve-file-and-options.js"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,uDAPW,SAAS,UAAU,CAAC,YAEpB,SAAS,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS;UAElC,KAAK;aAAW,gBAAgB;EAoBnD;yBApCY,OAAO,OAAO,EAAE,UAAU;6BAC1B,OAAO,eAAe,EAAE,cAAc;+BACtC,OAAO,YAAY,EAAE,gBAAgB;sBAG9B,OAAO"}

View File

@@ -0,0 +1,53 @@
/**
* @typedef {import('vfile').Compatible} Compatible
* @typedef {import('../compile.js').CompileOptions} CompileOptions
* @typedef {import('../core.js').ProcessorOptions} ProcessorOptions
*/
import {VFile} from 'vfile'
import {md} from './extnames.js'
/**
* Create a file and options from a given `vfileCompatible` and options that
* might contain `format: 'detect'`.
*
* @param {Readonly<Compatible>} vfileCompatible
* File.
* @param {Readonly<CompileOptions> | null | undefined} [options]
* Configuration (optional).
* @returns {{file: VFile, options: ProcessorOptions}}
* File and options.
*/
export function resolveFileAndOptions(vfileCompatible, options) {
const file = looksLikeAVFile(vfileCompatible)
? vfileCompatible
: new VFile(vfileCompatible)
const {format, ...rest} = options || {}
return {
file,
options: {
format:
format === 'md' || format === 'mdx'
? format
: file.extname && (rest.mdExtensions || md).includes(file.extname)
? 'md'
: 'mdx',
...rest
}
}
}
/**
* @param {Readonly<Compatible> | null | undefined} [value]
* Thing.
* @returns {value is VFile}
* Check.
*/
function looksLikeAVFile(value) {
return Boolean(
value &&
typeof value === 'object' &&
'message' in value &&
'messages' in value
)
}