Skip to content

Commit

Permalink
Update types for changes in micromark-util-types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 30, 2023
1 parent 53a493c commit 36a6b6d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules/
/lib/
/index.js
yarn.lock
!dev/index.d.ts
12 changes: 12 additions & 0 deletions dev/index.d.ts
Original file line number Diff line number Diff line change
@@ -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'
}
}
6 changes: 5 additions & 1 deletion dev/lib/syntax.js
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -81,19 +83,22 @@ 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),
end: Object.assign({}, events[index][1].start)
}

// Opening.
/** @type {Array<Event>} */
const nextEvents = [
['enter', strikethrough, context],
['enter', events[open][1], context],
Expand All @@ -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)
)
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["**/*.js"],
"include": ["**/*.js", "dev/index.d.ts"],
"exclude": ["coverage/", "lib/", "node_modules/", "index.js"],
"compilerOptions": {
"customConditions": ["development"],
Expand Down

0 comments on commit 36a6b6d

Please sign in to comment.