Fix types for TS 4.9
This commit is contained in:
parent
6b8f4d4a8b
commit
108af2192b
5 changed files with 112 additions and 27 deletions
|
@ -3,6 +3,7 @@
|
||||||
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
||||||
* @typedef {import('micromark-util-types').State} State
|
* @typedef {import('micromark-util-types').State} State
|
||||||
* @typedef {import('micromark-util-types').Token} Token
|
* @typedef {import('micromark-util-types').Token} Token
|
||||||
|
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ok as assert} from 'uvu/assert'
|
import {ok as assert} from 'uvu/assert'
|
||||||
|
@ -25,7 +26,10 @@ const label = {tokenize: tokenizeLabel, partial: true}
|
||||||
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
||||||
const nonLazyLine = {tokenize: tokenizeNonLazyLine, partial: true}
|
const nonLazyLine = {tokenize: tokenizeNonLazyLine, partial: true}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeDirectiveContainer(effects, ok, nok) {
|
function tokenizeDirectiveContainer(effects, ok, nok) {
|
||||||
const self = this
|
const self = this
|
||||||
const tail = self.events[self.events.length - 1]
|
const tail = self.events[self.events.length - 1]
|
||||||
|
@ -193,7 +197,10 @@ function tokenizeDirectiveContainer(effects, ok, nok) {
|
||||||
return ok(code)
|
return ok(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeClosingFence(effects, ok, nok) {
|
function tokenizeClosingFence(effects, ok, nok) {
|
||||||
let size = 0
|
let size = 0
|
||||||
|
|
||||||
|
@ -236,7 +243,10 @@ function tokenizeDirectiveContainer(effects, ok, nok) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeLabel(effects, ok, nok) {
|
function tokenizeLabel(effects, ok, nok) {
|
||||||
// Always a `[`
|
// Always a `[`
|
||||||
return factoryLabel(
|
return factoryLabel(
|
||||||
|
@ -250,7 +260,10 @@ function tokenizeLabel(effects, ok, nok) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeAttributes(effects, ok, nok) {
|
function tokenizeAttributes(effects, ok, nok) {
|
||||||
// Always a `{`
|
// Always a `{`
|
||||||
return factoryAttributes(
|
return factoryAttributes(
|
||||||
|
@ -272,7 +285,10 @@ function tokenizeAttributes(effects, ok, nok) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeNonLazyLine(effects, ok, nok) {
|
function tokenizeNonLazyLine(effects, ok, nok) {
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* @typedef {import('micromark-util-types').Construct} Construct
|
* @typedef {import('micromark-util-types').Construct} Construct
|
||||||
|
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
|
||||||
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
||||||
* @typedef {import('micromark-util-types').State} State
|
* @typedef {import('micromark-util-types').State} State
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +20,10 @@ export const directiveLeaf = {tokenize: tokenizeDirectiveLeaf}
|
||||||
const label = {tokenize: tokenizeLabel, partial: true}
|
const label = {tokenize: tokenizeLabel, partial: true}
|
||||||
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeDirectiveLeaf(effects, ok, nok) {
|
function tokenizeDirectiveLeaf(effects, ok, nok) {
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
|
@ -81,7 +85,10 @@ function tokenizeDirectiveLeaf(effects, ok, nok) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeLabel(effects, ok, nok) {
|
function tokenizeLabel(effects, ok, nok) {
|
||||||
// Always a `[`
|
// Always a `[`
|
||||||
return factoryLabel(
|
return factoryLabel(
|
||||||
|
@ -95,7 +102,10 @@ function tokenizeLabel(effects, ok, nok) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeAttributes(effects, ok, nok) {
|
function tokenizeAttributes(effects, ok, nok) {
|
||||||
// Always a `{`
|
// Always a `{`
|
||||||
return factoryAttributes(
|
return factoryAttributes(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* @typedef {import('micromark-util-types').Construct} Construct
|
* @typedef {import('micromark-util-types').Construct} Construct
|
||||||
|
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
|
||||||
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
||||||
* @typedef {import('micromark-util-types').Previous} Previous
|
* @typedef {import('micromark-util-types').Previous} Previous
|
||||||
* @typedef {import('micromark-util-types').State} State
|
* @typedef {import('micromark-util-types').State} State
|
||||||
|
@ -21,7 +22,10 @@ export const directiveText = {
|
||||||
const label = {tokenize: tokenizeLabel, partial: true}
|
const label = {tokenize: tokenizeLabel, partial: true}
|
||||||
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
||||||
|
|
||||||
/** @type {Previous} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Previous}
|
||||||
|
*/
|
||||||
function previous(code) {
|
function previous(code) {
|
||||||
// If there is a previous code, there will always be a tail.
|
// If there is a previous code, there will always be a tail.
|
||||||
return (
|
return (
|
||||||
|
@ -30,7 +34,10 @@ function previous(code) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeDirectiveText(effects, ok, nok) {
|
function tokenizeDirectiveText(effects, ok, nok) {
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
|
@ -70,7 +77,10 @@ function tokenizeDirectiveText(effects, ok, nok) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeLabel(effects, ok, nok) {
|
function tokenizeLabel(effects, ok, nok) {
|
||||||
// Always a `[`
|
// Always a `[`
|
||||||
return factoryLabel(
|
return factoryLabel(
|
||||||
|
@ -83,7 +93,10 @@ function tokenizeLabel(effects, ok, nok) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/**
|
||||||
|
* @this {TokenizeContext}
|
||||||
|
* @type {Tokenizer}
|
||||||
|
*/
|
||||||
function tokenizeAttributes(effects, ok, nok) {
|
function tokenizeAttributes(effects, ok, nok) {
|
||||||
// Always a `{`
|
// Always a `{`
|
||||||
return factoryAttributes(
|
return factoryAttributes(
|
||||||
|
|
|
@ -98,7 +98,10 @@ export function directiveHtml(options = {}) {
|
||||||
stack.push({type, name: ''})
|
stack.push({type, name: ''})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitName(token) {
|
function exitName(token) {
|
||||||
/** @type {Directive[]} */
|
/** @type {Directive[]} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -106,12 +109,18 @@ export function directiveHtml(options = {}) {
|
||||||
stack[stack.length - 1].name = this.sliceSerialize(token)
|
stack[stack.length - 1].name = this.sliceSerialize(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function enterLabel() {
|
function enterLabel() {
|
||||||
this.buffer()
|
this.buffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitLabel() {
|
function exitLabel() {
|
||||||
const data = this.resume()
|
const data = this.resume()
|
||||||
/** @type {Directive[]} */
|
/** @type {Directive[]} */
|
||||||
|
@ -120,13 +129,19 @@ export function directiveHtml(options = {}) {
|
||||||
stack[stack.length - 1].label = data
|
stack[stack.length - 1].label = data
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function enterAttributes() {
|
function enterAttributes() {
|
||||||
this.buffer()
|
this.buffer()
|
||||||
this.setData('directiveAttributes', [])
|
this.setData('directiveAttributes', [])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitAttributeIdValue(token) {
|
function exitAttributeIdValue(token) {
|
||||||
/** @type {Attribute[]} */
|
/** @type {Attribute[]} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -139,7 +154,10 @@ export function directiveHtml(options = {}) {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitAttributeClassValue(token) {
|
function exitAttributeClassValue(token) {
|
||||||
/** @type {Attribute[]} */
|
/** @type {Attribute[]} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -153,7 +171,10 @@ export function directiveHtml(options = {}) {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitAttributeName(token) {
|
function exitAttributeName(token) {
|
||||||
// Attribute names in CommonMark are significantly limited, so character
|
// Attribute names in CommonMark are significantly limited, so character
|
||||||
// references can’t exist.
|
// references can’t exist.
|
||||||
|
@ -164,7 +185,10 @@ export function directiveHtml(options = {}) {
|
||||||
attributes.push([this.sliceSerialize(token), ''])
|
attributes.push([this.sliceSerialize(token), ''])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitAttributeValue(token) {
|
function exitAttributeValue(token) {
|
||||||
/** @type {Attribute[]} */
|
/** @type {Attribute[]} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -175,7 +199,10 @@ export function directiveHtml(options = {}) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitAttributes() {
|
function exitAttributes() {
|
||||||
/** @type {Directive[]} */
|
/** @type {Directive[]} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -204,7 +231,10 @@ export function directiveHtml(options = {}) {
|
||||||
stack[stack.length - 1].attributes = cleaned
|
stack[stack.length - 1].attributes = cleaned
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitContainerContent() {
|
function exitContainerContent() {
|
||||||
const data = this.resume()
|
const data = this.resume()
|
||||||
/** @type {Directive[]} */
|
/** @type {Directive[]} */
|
||||||
|
@ -213,7 +243,10 @@ export function directiveHtml(options = {}) {
|
||||||
stack[stack.length - 1].content = data
|
stack[stack.length - 1].content = data
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exitContainerFence() {
|
function exitContainerFence() {
|
||||||
/** @type {Directive[]} */
|
/** @type {Directive[]} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -224,7 +257,10 @@ export function directiveHtml(options = {}) {
|
||||||
if (directive._fenceCount === 1) this.setData('slurpOneLineEnding', true)
|
if (directive._fenceCount === 1) this.setData('slurpOneLineEnding', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {_Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {_Handle}
|
||||||
|
*/
|
||||||
function exit() {
|
function exit() {
|
||||||
/** @type {Directive} */
|
/** @type {Directive} */
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/**
|
/**
|
||||||
|
* @typedef {import('micromark-util-types').CompileContext} CompileContext
|
||||||
* @typedef {import('../dev/index.js').HtmlOptions} HtmlOptions
|
* @typedef {import('../dev/index.js').HtmlOptions} HtmlOptions
|
||||||
* @typedef {import('../dev/index.js').Handle} Handle
|
* @typedef {import('../dev/index.js').Handle} Handle
|
||||||
*/
|
*/
|
||||||
|
@ -1476,7 +1477,10 @@ test('content', (t) => {
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
/** @type {Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {Handle}
|
||||||
|
*/
|
||||||
function abbr(d) {
|
function abbr(d) {
|
||||||
if (d.type !== 'textDirective') return false
|
if (d.type !== 'textDirective') return false
|
||||||
|
|
||||||
|
@ -1491,7 +1495,10 @@ function abbr(d) {
|
||||||
this.tag('</abbr>')
|
this.tag('</abbr>')
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {Handle}
|
||||||
|
*/
|
||||||
function youtube(d) {
|
function youtube(d) {
|
||||||
const attrs = d.attributes || {}
|
const attrs = d.attributes || {}
|
||||||
const v = attrs.v
|
const v = attrs.v
|
||||||
|
@ -1526,7 +1533,10 @@ function youtube(d) {
|
||||||
this.tag('</iframe>')
|
this.tag('</iframe>')
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Handle} */
|
/**
|
||||||
|
* @this {CompileContext}
|
||||||
|
* @type {Handle}
|
||||||
|
*/
|
||||||
function h(d) {
|
function h(d) {
|
||||||
const content = d.content || d.label
|
const content = d.content || d.label
|
||||||
const attrs = d.attributes || {}
|
const attrs = d.attributes || {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue