Skip to content

Commit

Permalink
Refactor to use @imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 11, 2024
1 parent bb9649b commit 3b28c25
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 58 deletions.
10 changes: 3 additions & 7 deletions lib/attribute.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* @typedef {import('css-selector-parser').AstAttribute} AstAttribute
*
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
*
* @typedef {import('property-information').Info} Info
* @typedef {import('property-information').Schema} Schema
* @import {AstAttribute} from 'css-selector-parser'
* @import {Element, Properties} from 'hast'
* @import {Info, Schema} from 'property-information'
*/

import {stringify as commas} from 'comma-separated-tokens'
Expand Down
4 changes: 2 additions & 2 deletions lib/class-name.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('css-selector-parser').AstClassName} AstClassName
* @typedef {import('hast').Element} Element
* @import {AstClassName} from 'css-selector-parser'
* @import {Element} from 'hast'
*/

/** @type {Array<never>} */
Expand Down
12 changes: 4 additions & 8 deletions lib/enter-state.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Nodes} Nodes
*
* @typedef {import('unist-util-visit').Visitor<ElementContent>} Visitor
*
* @typedef {import('./index.js').Direction} Direction
* @typedef {import('./index.js').State} State
* @import {Visitor} from 'unist-util-visit'
* @import {ElementContent, Nodes} from 'hast'
* @import {Direction, State} from './index.js'
*/

import {direction} from 'direction'
Expand Down Expand Up @@ -112,7 +108,7 @@ export function enterState(state, node) {
state.editableOrEditingHost = editableOrEditingHost
}

/** @type {Visitor} */
/** @type {Visitor<ElementContent>} */
function inferDirectionality(child) {
if (child.type === 'text') {
directionInferred = directionBidi(child.value)
Expand Down
8 changes: 2 additions & 6 deletions lib/id.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* @typedef {import('css-selector-parser').AstId} AstId
*
* @typedef {import('hast').Element} Element
* @import {AstId} from 'css-selector-parser'
* @import {Element} from 'hast'
*/

// Workaround to show references to above types in VS Code.
''

/**
* Check whether an element has an ID.
*
Expand Down
10 changes: 3 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* @typedef {import('css-selector-parser').AstSelector} AstSelector
*
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Nodes} Nodes
* @typedef {import('hast').RootContent} RootContent
*
* @typedef {import('property-information').Schema} Schema
* @import {AstSelector} from 'css-selector-parser'
* @import {Element, Nodes, RootContent} from 'hast'
* @import {Schema} from 'property-information'
*/

/**
Expand Down
8 changes: 2 additions & 6 deletions lib/name.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* @typedef {import('css-selector-parser').AstTagName} AstTagName
*
* @typedef {import('hast').Element} Element
* @import {AstTagName} from 'css-selector-parser'
* @import {Element} from 'hast'
*/

// Workaround to show references to above types in VS Code.
''

/**
* Check whether an element has a tag name.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('css-selector-parser').AstSelector} AstSelector
* @import {AstSelector} from 'css-selector-parser'
*/

import {createParser} from 'css-selector-parser'
Expand Down
13 changes: 5 additions & 8 deletions lib/pseudo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/**
* @typedef {import('css-selector-parser').AstPseudoClass} AstPseudoClass
*
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Parents} Parents
*
* @typedef {import('./index.js').State} State
* @import {AstPseudoClass} from 'css-selector-parser'
* @import {default as NthCheck} from 'nth-check'
* @import {ElementContent, Element, Parents} from 'hast'
* @import {State} from './index.js'
*/

import {extendedFilter} from 'bcp-47-match'
Expand All @@ -17,7 +14,7 @@ import fauxEsmNthCheck from 'nth-check'
import {zwitch} from 'zwitch'
import {walk} from './walk.js'

/** @type {import('nth-check').default} */
/** @type {NthCheck} */
// @ts-expect-error: types are broken.
const nthCheck = fauxEsmNthCheck.default || fauxEsmNthCheck

Expand Down
9 changes: 3 additions & 6 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* @typedef {import('css-selector-parser').AstRule} AstRule
*
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Parents} Parents
*
* @typedef {import('./index.js').State} State
* @import {AstRule} from 'css-selector-parser'
* @import {Element, Parents} from 'hast'
* @import {State} from './index.js'
*/

import {attribute} from './attribute.js'
Expand Down
10 changes: 3 additions & 7 deletions lib/walk.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* @typedef {import('css-selector-parser').AstRule} AstRule
*
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Nodes} Nodes
* @typedef {import('hast').Parents} Parents
*
* @typedef {import('./index.js').State} State
* @import {AstRule} from 'css-selector-parser'
* @import {Element, Nodes, Parents} from 'hast'
* @import {State} from './index.js'
*/

/**
Expand Down

0 comments on commit 3b28c25

Please sign in to comment.