Skip to content

Commit b84dbc8

Browse files
committed
Refactor types to use CompileData interface
1 parent e4ba789 commit b84dbc8

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

index.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ export type {
77

88
export {directiveFromMarkdown, directiveToMarkdown} from './lib/index.js'
99

10+
// Add custom data tracked to turn markdown into a tree.
11+
declare module 'mdast-util-from-markdown' {
12+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
13+
interface CompileData {
14+
/**
15+
* Attributes for current directive.
16+
*/
17+
directiveAttributes?: Array<[string, string]> | undefined
18+
}
19+
}
20+
1021
declare module 'mdast-util-to-markdown' {
1122
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1223
interface ConstructNameMap {

lib/index.js

-12
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ function exitContainerLabel(token) {
164164
* @type {FromMarkdownHandle}
165165
*/
166166
function enterAttributes() {
167-
// @ts-expect-error: to do: register.
168167
this.setData('directiveAttributes', [])
169168
this.buffer() // Capture EOLs
170169
}
@@ -174,9 +173,7 @@ function enterAttributes() {
174173
* @type {FromMarkdownHandle}
175174
*/
176175
function exitAttributeIdValue(token) {
177-
// @ts-expect-error: to do: register.
178176
const list = /** @type {Array.<[string, string]>} */ (
179-
// @ts-expect-error: to do: register.
180177
this.getData('directiveAttributes')
181178
)
182179
list.push([
@@ -192,9 +189,7 @@ function exitAttributeIdValue(token) {
192189
* @type {FromMarkdownHandle}
193190
*/
194191
function exitAttributeClassValue(token) {
195-
// @ts-expect-error: to do: register.
196192
const list = /** @type {Array.<[string, string]>} */ (
197-
// @ts-expect-error: to do: register.
198193
this.getData('directiveAttributes')
199194
)
200195
list.push([
@@ -210,9 +205,7 @@ function exitAttributeClassValue(token) {
210205
* @type {FromMarkdownHandle}
211206
*/
212207
function exitAttributeValue(token) {
213-
// @ts-expect-error: to do: register.
214208
const list = /** @type {Array.<[string, string]>} */ (
215-
// @ts-expect-error: to do: register.
216209
this.getData('directiveAttributes')
217210
)
218211
list[list.length - 1][1] = parseEntities(this.sliceSerialize(token), {
@@ -225,9 +218,7 @@ function exitAttributeValue(token) {
225218
* @type {FromMarkdownHandle}
226219
*/
227220
function exitAttributeName(token) {
228-
// @ts-expect-error: to do: register.
229221
const list = /** @type {Array.<[string, string]>} */ (
230-
// @ts-expect-error: to do: register.
231222
this.getData('directiveAttributes')
232223
)
233224

@@ -241,9 +232,7 @@ function exitAttributeName(token) {
241232
* @type {FromMarkdownHandle}
242233
*/
243234
function exitAttributes() {
244-
// @ts-expect-error: to do: register.
245235
const list = /** @type {Array.<[string, string]>} */ (
246-
// @ts-expect-error: to do: register.
247236
this.getData('directiveAttributes')
248237
)
249238
/** @type {Record.<string, string>} */
@@ -260,7 +249,6 @@ function exitAttributes() {
260249
}
261250
}
262251

263-
// @ts-expect-error: to do: register.
264252
this.setData('directiveAttributes')
265253
this.resume() // Drop EOLs
266254
const node = /** @type {Directive} */ (this.stack[this.stack.length - 1])

0 commit comments

Comments
 (0)