diff --git a/.gitignore b/.gitignore index b957bb5..a136532 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules/ /lib/ /index.js yarn.lock +!dev/index.d.ts diff --git a/dev/index.d.ts b/dev/index.d.ts new file mode 100644 index 0000000..a578824 --- /dev/null +++ b/dev/index.d.ts @@ -0,0 +1,12 @@ +export {gfmStrikethroughHtml} from './lib/html.js' +export {gfmStrikethrough} from './lib/syntax.js' + +declare module 'micromark-util-types' { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions + interface TokenTypeMap { + strikethroughSequence: 'strikethroughSequence' + strikethroughSequenceTemporary: 'strikethroughSequenceTemporary' + strikethrough: 'strikethrough' + strikethroughText: 'strikethroughText' + } +} diff --git a/dev/lib/syntax.js b/dev/lib/syntax.js index c3c6332..082adab 100644 --- a/dev/lib/syntax.js +++ b/dev/lib/syntax.js @@ -1,7 +1,9 @@ /** + * @typedef {import('micromark-util-types').Event} Event * @typedef {import('micromark-util-types').Extension} Extension * @typedef {import('micromark-util-types').Resolver} Resolver * @typedef {import('micromark-util-types').State} State + * @typedef {import('micromark-util-types').Token} Token * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext * @typedef {import('micromark-util-types').Tokenizer} Tokenizer * @@ -81,12 +83,14 @@ export function gfmStrikethrough(options) { events[index][1].type = 'strikethroughSequence' events[open][1].type = 'strikethroughSequence' + /** @type {Token} */ const strikethrough = { type: 'strikethrough', start: Object.assign({}, events[open][1].start), end: Object.assign({}, events[index][1].end) } + /** @type {Token} */ const text = { type: 'strikethroughText', start: Object.assign({}, events[open][1].end), @@ -94,6 +98,7 @@ export function gfmStrikethrough(options) { } // Opening. + /** @type {Array} */ const nextEvents = [ ['enter', strikethrough, context], ['enter', events[open][1], context], @@ -109,7 +114,6 @@ export function gfmStrikethrough(options) { nextEvents, nextEvents.length, 0, - // @ts-expect-error: to do: update `mdast-util-types` to allow explicit `undefined`s. resolveAll(insideSpan, events.slice(open + 1, index), context) ) } diff --git a/tsconfig.json b/tsconfig.json index 397ca4a..bbc8fb2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["**/*.js"], + "include": ["**/*.js", "dev/index.d.ts"], "exclude": ["coverage/", "lib/", "node_modules/", "index.js"], "compilerOptions": { "customConditions": ["development"],