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 60f4a5f commit 48e082c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 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
29 changes: 29 additions & 0 deletions dev/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export type {BackLabelTemplate, Options} from './lib/html.js'

export {gfmFootnote} from './lib/syntax.js'
export {gfmFootnoteHtml, defaultBackLabel} from './lib/html.js'

declare module 'micromark-util-types' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface TokenTypeMap {
gfmFootnoteCall: 'gfmFootnoteCall'
gfmFootnoteCallLabelMarker: 'gfmFootnoteCallLabelMarker'
gfmFootnoteCallMarker: 'gfmFootnoteCallMarker'
gfmFootnoteCallString: 'gfmFootnoteCallString'
gfmFootnoteDefinition: 'gfmFootnoteDefinition'
gfmFootnoteDefinitionIndent: 'gfmFootnoteDefinitionIndent'
gfmFootnoteDefinitionLabel: 'gfmFootnoteDefinitionLabel'
gfmFootnoteDefinitionLabelMarker: 'gfmFootnoteDefinitionLabelMarker'
gfmFootnoteDefinitionLabelString: 'gfmFootnoteDefinitionLabelString'
gfmFootnoteDefinitionMarker: 'gfmFootnoteDefinitionMarker'
gfmFootnoteDefinitionWhitespace: 'gfmFootnoteDefinitionWhitespace'
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface CompileData {
gfmFootnoteDefinitions?: Record<string, string>
gfmFootnoteDefinitionStack?: string[]
gfmFootnoteCallCounts?: Record<string, number>
gfmFootnoteCallOrder?: string[]
}
}
6 changes: 1 addition & 5 deletions dev/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @typedef {import('./lib/html.js').BackLabelTemplate} BackLabelTemplate
* @typedef {import('./lib/html.js').Options} HtmlOptions
*/

// Note: types are exported from `dev/index.d.ts`.
export {gfmFootnote} from './lib/syntax.js'
export {gfmFootnoteHtml, defaultBackLabel} from './lib/html.js'
23 changes: 7 additions & 16 deletions dev/lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function gfmFootnoteHtml(options) {
return {
enter: {
gfmFootnoteDefinition() {
const stack = /** @type {Array<boolean>} */ (this.getData('tightStack'))
const stack = this.getData('tightStack')
stack.push(false)
},
gfmFootnoteDefinitionLabelString() {
Expand All @@ -177,15 +177,10 @@ export function gfmFootnoteHtml(options) {
},
exit: {
gfmFootnoteDefinition() {
let definitions = /** @type {Record<string, string>} */ (
this.getData('gfmFootnoteDefinitions')
)
const footnoteStack = /** @type {Array<string>} */ (
this.getData('gfmFootnoteDefinitionStack')
)
const tightStack = /** @type {Array<boolean>} */ (
this.getData('tightStack')
)
let definitions = this.getData('gfmFootnoteDefinitions')
const footnoteStack = this.getData('gfmFootnoteDefinitionStack')
assert(footnoteStack, 'expected `footnoteStack`')
const tightStack = this.getData('tightStack')
const current = footnoteStack.pop()
const value = this.resume()

Expand Down Expand Up @@ -217,12 +212,8 @@ export function gfmFootnoteHtml(options) {
this.buffer() // Get ready for a value.
},
gfmFootnoteCallString(token) {
let calls = /** @type {Array<string>|undefined} */ (
this.getData('gfmFootnoteCallOrder')
)
let counts = /** @type {Record<string, number>|undefined} */ (
this.getData('gfmFootnoteCallCounts')
)
let calls = this.getData('gfmFootnoteCallOrder')
let counts = this.getData('gfmFootnoteCallCounts')
const id = normalizeIdentifier(this.sliceSerialize(token))
/** @type {number} */
let counter
Expand Down
4 changes: 4 additions & 0 deletions dev/lib/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ function resolveToPotentialGfmFootnoteCall(events, context) {
events[index + 3][1].type = 'gfmFootnoteCallLabelMarker'

// The whole (without `!`):
/** @type {Token} */
const call = {
type: 'gfmFootnoteCall',
start: Object.assign({}, events[index + 3][1].start),
end: Object.assign({}, events[events.length - 1][1].end)
}
// The `^` marker
/** @type {Token} */
const marker = {
type: 'gfmFootnoteCallMarker',
start: Object.assign({}, events[index + 3][1].end),
Expand All @@ -156,11 +158,13 @@ function resolveToPotentialGfmFootnoteCall(events, context) {
marker.end.column++
marker.end.offset++
marker.end._bufferIndex++
/** @type {Token} */
const string = {
type: 'gfmFootnoteCallString',
start: Object.assign({}, marker.end),
end: Object.assign({}, events[events.length - 1][1].start)
}
/** @type {Token} */
const chunk = {
type: types.chunkString,
contentType: 'string',
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 48e082c

Please sign in to comment.