🎉 initiate project *astro_rewrite*

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

View file

@ -0,0 +1,80 @@
/**
* @this {TokenizeContext}
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {Acorn | undefined} acorn
* @param {AcornOptions | undefined} acornOptions
* @param {boolean | undefined} addResult
* @param {boolean | undefined} allowLazy
* @param {TokenType} tagType
* @param {TokenType} tagMarkerType
* @param {TokenType} tagClosingMarkerType
* @param {TokenType} tagSelfClosingMarker
* @param {TokenType} tagNameType
* @param {TokenType} tagNamePrimaryType
* @param {TokenType} tagNameMemberMarkerType
* @param {TokenType} tagNameMemberType
* @param {TokenType} tagNamePrefixMarkerType
* @param {TokenType} tagNameLocalType
* @param {TokenType} tagExpressionAttributeType
* @param {TokenType} tagExpressionAttributeMarkerType
* @param {TokenType} tagExpressionAttributeValueType
* @param {TokenType} tagAttributeType
* @param {TokenType} tagAttributeNameType
* @param {TokenType} tagAttributeNamePrimaryType
* @param {TokenType} tagAttributeNamePrefixMarkerType
* @param {TokenType} tagAttributeNameLocalType
* @param {TokenType} tagAttributeInitializerMarkerType
* @param {TokenType} tagAttributeValueLiteralType
* @param {TokenType} tagAttributeValueLiteralMarkerType
* @param {TokenType} tagAttributeValueLiteralValueType
* @param {TokenType} tagAttributeValueExpressionType
* @param {TokenType} tagAttributeValueExpressionMarkerType
* @param {TokenType} tagAttributeValueExpressionValueType
*/
export function factoryTag(
this: import('micromark-util-types').TokenizeContext,
effects: Effects,
ok: State,
nok: State,
acorn: Acorn | undefined,
acornOptions: AcornOptions | undefined,
addResult: boolean | undefined,
allowLazy: boolean | undefined,
tagType: TokenType,
tagMarkerType: TokenType,
tagClosingMarkerType: TokenType,
tagSelfClosingMarker: TokenType,
tagNameType: TokenType,
tagNamePrimaryType: TokenType,
tagNameMemberMarkerType: TokenType,
tagNameMemberType: TokenType,
tagNamePrefixMarkerType: TokenType,
tagNameLocalType: TokenType,
tagExpressionAttributeType: TokenType,
tagExpressionAttributeMarkerType: TokenType,
tagExpressionAttributeValueType: TokenType,
tagAttributeType: TokenType,
tagAttributeNameType: TokenType,
tagAttributeNamePrimaryType: TokenType,
tagAttributeNamePrefixMarkerType: TokenType,
tagAttributeNameLocalType: TokenType,
tagAttributeInitializerMarkerType: TokenType,
tagAttributeValueLiteralType: TokenType,
tagAttributeValueLiteralMarkerType: TokenType,
tagAttributeValueLiteralValueType: TokenType,
tagAttributeValueExpressionType: TokenType,
tagAttributeValueExpressionMarkerType: TokenType,
tagAttributeValueExpressionValueType: TokenType
): (
code: import('micromark-util-types').Code
) => void | import('micromark-util-types').State
export type Acorn = import('micromark-factory-mdx-expression').Acorn
export type AcornOptions =
import('micromark-factory-mdx-expression').AcornOptions
export type Code = import('micromark-util-types').Code
export type Effects = import('micromark-util-types').Effects
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type TokenType = import('micromark-util-types').TokenType

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,24 @@
/**
* Parse JSX (flow).
*
* @param {Acorn | undefined} acorn
* Acorn parser to use (optional).
* @param {AcornOptions | undefined} acornOptions
* Configuration for acorn.
* @param {boolean | undefined} addResult
* Whether to add `estree` fields to tokens with results from acorn.
* @returns {Construct}
* Construct.
*/
export function jsxFlow(
acorn: Acorn | undefined,
acornOptions: AcornOptions | undefined,
addResult: boolean | undefined
): Construct
export type Acorn = import('micromark-factory-mdx-expression').Acorn
export type AcornOptions =
import('micromark-factory-mdx-expression').AcornOptions
export type Construct = import('micromark-util-types').Construct
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer

View file

@ -0,0 +1,148 @@
/**
* @typedef {import('micromark-factory-mdx-expression').Acorn} Acorn
* @typedef {import('micromark-factory-mdx-expression').AcornOptions} AcornOptions
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
*/
import {markdownLineEnding, markdownSpace} from 'micromark-util-character'
import {factorySpace} from 'micromark-factory-space'
import {codes} from 'micromark-util-symbol/codes.js'
import {types} from 'micromark-util-symbol/types.js'
import {ok as assert} from 'uvu/assert'
import {factoryTag} from './factory-tag.js'
/**
* Parse JSX (flow).
*
* @param {Acorn | undefined} acorn
* Acorn parser to use (optional).
* @param {AcornOptions | undefined} acornOptions
* Configuration for acorn.
* @param {boolean | undefined} addResult
* Whether to add `estree` fields to tokens with results from acorn.
* @returns {Construct}
* Construct.
*/
export function jsxFlow(acorn, acornOptions, addResult) {
return {tokenize: tokenizeJsxFlow, concrete: true}
/**
* MDX JSX (flow).
*
* ```markdown
* > | <A />
* ^^^^^
* ```
*
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeJsxFlow(effects, ok, nok) {
const self = this
return start
/**
* Start of MDX: JSX (flow).
*
* ```markdown
* > | <A />
* ^
* ```
*
* @type {State}
*/
function start(code) {
// To do: in `markdown-rs`, constructs need to parse the indent themselves.
// This should also be introduced in `micromark-js`.
assert(code === codes.lessThan, 'expected `<`')
return before(code)
}
/**
* After optional whitespace, before of MDX JSX (flow).
*
* ```markdown
* > | <A />
* ^
* ```
*
* @type {State}
*/
function before(code) {
return factoryTag.call(
self,
effects,
after,
nok,
acorn,
acornOptions,
addResult,
false,
'mdxJsxFlowTag',
'mdxJsxFlowTagMarker',
'mdxJsxFlowTagClosingMarker',
'mdxJsxFlowTagSelfClosingMarker',
'mdxJsxFlowTagName',
'mdxJsxFlowTagNamePrimary',
'mdxJsxFlowTagNameMemberMarker',
'mdxJsxFlowTagNameMember',
'mdxJsxFlowTagNamePrefixMarker',
'mdxJsxFlowTagNameLocal',
'mdxJsxFlowTagExpressionAttribute',
'mdxJsxFlowTagExpressionAttributeMarker',
'mdxJsxFlowTagExpressionAttributeValue',
'mdxJsxFlowTagAttribute',
'mdxJsxFlowTagAttributeName',
'mdxJsxFlowTagAttributeNamePrimary',
'mdxJsxFlowTagAttributeNamePrefixMarker',
'mdxJsxFlowTagAttributeNameLocal',
'mdxJsxFlowTagAttributeInitializerMarker',
'mdxJsxFlowTagAttributeValueLiteral',
'mdxJsxFlowTagAttributeValueLiteralMarker',
'mdxJsxFlowTagAttributeValueLiteralValue',
'mdxJsxFlowTagAttributeValueExpression',
'mdxJsxFlowTagAttributeValueExpressionMarker',
'mdxJsxFlowTagAttributeValueExpressionValue'
)(code)
}
/**
* After an MDX JSX (flow) tag.
*
* ```markdown
* > | <A>
* ^
* ```
*
* @type {State}
*/
function after(code) {
return markdownSpace(code)
? factorySpace(effects, end, types.whitespace)(code)
: end(code)
}
/**
* After an MDX JSX (flow) tag, after optional whitespace.
*
* ```markdown
* > | <A> <B>
* ^
* ```
*
* @type {State}
*/
function end(code) {
// Another tag.
return code === codes.lessThan
? start(code)
: code === codes.eof || markdownLineEnding(code)
? ok(code)
: nok(code)
}
}
}

View file

@ -0,0 +1,23 @@
/**
* Parse JSX (text).
*
* @param {Acorn | undefined} acorn
* Acorn parser to use (optional).
* @param {AcornOptions | undefined} acornOptions
* Configuration for acorn.
* @param {boolean | undefined} addResult
* Whether to add `estree` fields to tokens with results from acorn.
* @returns {Construct}
* Construct.
*/
export function jsxText(
acorn: Acorn | undefined,
acornOptions: AcornOptions | undefined,
addResult: boolean | undefined
): Construct
export type Acorn = import('micromark-factory-mdx-expression').Acorn
export type AcornOptions =
import('micromark-factory-mdx-expression').AcornOptions
export type Construct = import('micromark-util-types').Construct
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer

View file

@ -0,0 +1,74 @@
/**
* @typedef {import('micromark-factory-mdx-expression').Acorn} Acorn
* @typedef {import('micromark-factory-mdx-expression').AcornOptions} AcornOptions
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
*/
import {factoryTag} from './factory-tag.js'
/**
* Parse JSX (text).
*
* @param {Acorn | undefined} acorn
* Acorn parser to use (optional).
* @param {AcornOptions | undefined} acornOptions
* Configuration for acorn.
* @param {boolean | undefined} addResult
* Whether to add `estree` fields to tokens with results from acorn.
* @returns {Construct}
* Construct.
*/
export function jsxText(acorn, acornOptions, addResult) {
return {tokenize: tokenizeJsxText}
/**
* MDX JSX (text).
*
* ```markdown
* > | a <b />.
* ^^^^^
* ```
*
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeJsxText(effects, ok, nok) {
return factoryTag.call(
this,
effects,
ok,
nok,
acorn,
acornOptions,
addResult,
true,
'mdxJsxTextTag',
'mdxJsxTextTagMarker',
'mdxJsxTextTagClosingMarker',
'mdxJsxTextTagSelfClosingMarker',
'mdxJsxTextTagName',
'mdxJsxTextTagNamePrimary',
'mdxJsxTextTagNameMemberMarker',
'mdxJsxTextTagNameMember',
'mdxJsxTextTagNamePrefixMarker',
'mdxJsxTextTagNameLocal',
'mdxJsxTextTagExpressionAttribute',
'mdxJsxTextTagExpressionAttributeMarker',
'mdxJsxTextTagExpressionAttributeValue',
'mdxJsxTextTagAttribute',
'mdxJsxTextTagAttributeName',
'mdxJsxTextTagAttributeNamePrimary',
'mdxJsxTextTagAttributeNamePrefixMarker',
'mdxJsxTextTagAttributeNameLocal',
'mdxJsxTextTagAttributeInitializerMarker',
'mdxJsxTextTagAttributeValueLiteral',
'mdxJsxTextTagAttributeValueLiteralMarker',
'mdxJsxTextTagAttributeValueLiteralValue',
'mdxJsxTextTagAttributeValueExpression',
'mdxJsxTextTagAttributeValueExpressionMarker',
'mdxJsxTextTagAttributeValueExpressionValue'
)
}
}

View file

@ -0,0 +1,34 @@
/**
* Create an extension for `micromark` to enable MDX JSX syntax.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable MDX
* JSX syntax.
*/
export function mdxJsx(options?: Options | null | undefined): Extension
export type Extension = import('micromark-util-types').Extension
export type Acorn = import('micromark-factory-mdx-expression').Acorn
export type AcornOptions =
import('micromark-factory-mdx-expression').AcornOptions
/**
* Configuration (optional).
*/
export type Options = {
/**
* Acorn parser to use (optional).
*/
acorn?: Acorn | null | undefined
/**
* Configuration for acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`).
*
* All fields except `locations` can be set.
*/
acornOptions?: AcornOptions | null | undefined
/**
* Whether to add `estree` fields to tokens with results from acorn.
*/
addResult?: boolean | null | undefined
}

View file

@ -0,0 +1,72 @@
/**
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('micromark-factory-mdx-expression').Acorn} Acorn
* @typedef {import('micromark-factory-mdx-expression').AcornOptions} AcornOptions
*/
/**
* @typedef Options
* Configuration (optional).
* @property {Acorn | null | undefined} [acorn]
* Acorn parser to use (optional).
* @property {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`).
*
* All fields except `locations` can be set.
* @property {boolean | null | undefined} [addResult=false]
* Whether to add `estree` fields to tokens with results from acorn.
*/
import {codes} from 'micromark-util-symbol/codes.js'
import {jsxText} from './jsx-text.js'
import {jsxFlow} from './jsx-flow.js'
/**
* Create an extension for `micromark` to enable MDX JSX syntax.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable MDX
* JSX syntax.
*/
export function mdxJsx(options) {
const settings = options || {}
const acorn = settings.acorn
/** @type {AcornOptions | undefined} */
let acornOptions
if (acorn) {
if (!acorn.parse || !acorn.parseExpressionAt) {
throw new Error(
'Expected a proper `acorn` instance passed in as `options.acorn`'
)
}
acornOptions = Object.assign(
{ecmaVersion: 2020, sourceType: 'module'},
settings.acornOptions,
{locations: true}
)
} else if (settings.acornOptions || settings.addResult) {
throw new Error('Expected an `acorn` instance passed in as `options.acorn`')
}
return {
flow: {
[codes.lessThan]: jsxFlow(
acorn || undefined,
acornOptions,
settings.addResult || false
)
},
text: {
[codes.lessThan]: jsxText(
acorn || undefined,
acornOptions,
settings.addResult || false
)
}
}
}