Skip to content

Commit

Permalink
Refactor to use @imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 5, 2024
1 parent 7ac2291 commit 00ce6d3
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 65 deletions.
34 changes: 31 additions & 3 deletions dev/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
import type {Program} from 'estree'
import type {Acorn, AcornOptions} from 'micromark-factory-mdx-expression'

export {mdxJsx, type Options} from './lib/syntax.js'
export {mdxJsx} from './lib/syntax.js'

/**
* Configuration (optional).
*/
export interface Options {
/**
* Acorn parser to use (optional).
*/
acorn?: Acorn | null | undefined
/**
* Configuration for acorn (default: `{ecmaVersion: 2024, 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
* (default: `false`).
*/
addResult?: boolean | null | undefined
}

/**
* Augment types.
*/
declare module 'micromark-util-types' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
/**
* Token fields.
*/
interface Token {
estree?: Program
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
/**
* Token types.
*/
interface TokenTypeMap {
esWhitespace: 'esWhitespace'

Expand Down
15 changes: 5 additions & 10 deletions dev/lib/factory-tag.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* @typedef {import('micromark-factory-mdx-expression').Acorn} Acorn
* @typedef {import('micromark-factory-mdx-expression').AcornOptions} AcornOptions
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').TokenType} TokenType
* @import {Acorn, AcornOptions} from 'micromark-factory-mdx-expression'
* @import {Code, Effects, State, TokenizeContext, TokenType} from 'micromark-util-types'
*/

import {ok as assert} from 'devlop'
Expand All @@ -27,9 +22,9 @@ const trouble = 'https://github.com/micromark/micromark-extension-mdx-jsx'
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {Acorn | undefined} acorn
* @param {AcornOptions | undefined} acornOptions
* @param {boolean | undefined} addResult
* @param {Acorn | null | undefined} acorn
* @param {AcornOptions | null | undefined} acornOptions
* @param {boolean | null | undefined} addResult
* @param {boolean | undefined} allowLazy
* @param {TokenType} tagType
* @param {TokenType} tagMarkerType
Expand Down
18 changes: 3 additions & 15 deletions dev/lib/jsx-flow.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
/**
* @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
*/

/**
* @typedef Options
* Configuration.
* @property {AcornOptions | undefined} acornOptions
* Acorn options.
* @property {boolean | undefined} addResult
* Whether to add `estree` fields to tokens with results from acorn.
* @import {Options} from 'micromark-extension-mdx-jsx'
* @import {Acorn, AcornOptions} from 'micromark-factory-mdx-expression'
* @import {Construct, State, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/

import {ok as assert} from 'devlop'
Expand Down
17 changes: 3 additions & 14 deletions dev/lib/jsx-text.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
/**
* @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
*/

/**
* @typedef Options
* Configuration.
* @property {AcornOptions | undefined} acornOptions
* Acorn options.
* @property {boolean | undefined} addResult
* Whether to add `estree` fields to tokens with results from acorn.
* @import {Options} from 'micromark-extension-mdx-jsx'
* @import {Acorn} from 'micromark-factory-mdx-expression'
* @import {Construct, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/

import {factoryTag} from './factory-tag.js'
Expand Down
19 changes: 3 additions & 16 deletions dev/lib/syntax.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
/**
* @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: 2024, 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
* (default: `false`).
* @import {Options} from 'micromark-extension-mdx-jsx'
* @import {AcornOptions} from 'micromark-factory-mdx-expression'
* @import {Extension} from 'micromark-util-types'
*/

import {codes} from 'micromark-util-symbol'
Expand Down
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.d.ts"
],
"rules": {
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true
}
],
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
]
}
}
],
"prettier": true,
"rules": {
"unicorn/no-this-assignment": "off"
Expand Down
7 changes: 5 additions & 2 deletions script/grammar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/**
* @typedef {import('mdast').Root} Root
* @import {Root} from 'mdast'
*/

import fs from 'node:fs/promises'
import {zone} from 'mdast-zone'

const syntax = await fs.readFile(new URL('grammar.html', import.meta.url))
const syntax = await fs.readFile(
new URL('grammar.html', import.meta.url),
'utf8'
)

export default function grammar() {
/**
Expand Down
7 changes: 2 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/**
* @typedef {import('estree').Node} Node
* @typedef {import('estree').Program} Program
* @typedef {import('micromark-util-types').CompileContext} CompileContext
* @typedef {import('micromark-util-types').Handle} Handle
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
* @import {Node, Program} from 'estree'
* @import {CompileContext, Handle, HtmlExtension} from 'micromark-util-types'
*/

import assert from 'node:assert/strict'
Expand Down

0 comments on commit 00ce6d3

Please sign in to comment.