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