Skip to content

Commit

Permalink
Merge branch 'main' into remove-not-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm authored Oct 11, 2024
2 parents 25b86ae + b906f0c commit f22db43
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 227 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bb.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: bb
on:
issues:
types: [opened, reopened, edited, closed, labeled, unlabeled]
types: [closed, edited, labeled, opened, reopened, unlabeled]
pull_request_target:
types: [opened, reopened, edited, closed, labeled, unlabeled]
types: [closed, edited, labeled, opened, reopened, unlabeled]
jobs:
main:
runs-on: ubuntu-latest
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: main
on:
- pull_request
- push
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
strategy:
matrix:
node:
- lts/gallium
- lts/hydrogen
- node
name: main
on:
- pull_request
- push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
*.d.ts
*.log
*.tsbuildinfo
coverage/
node_modules/
yarn.lock
38 changes: 19 additions & 19 deletions lib/enter-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export function enterState(state, node) {
const currentDirection = state.direction
const editableOrEditingHost = state.editableOrEditingHost
/** @type {Direction | undefined} */
let dirInferred
let directionInferred

if (node.type === 'element') {
const lang = node.properties.xmlLang || node.properties.lang
const type = node.properties.type || 'text'
const dir = dirProperty(node)
const direction = directionProperty(node)

if (lang !== null && lang !== undefined) {
state.language = String(lang)
Expand All @@ -56,22 +56,22 @@ export function enterState(state, node) {

// See: <https://html.spec.whatwg.org/#the-directionality>.
// Explicit `[dir=rtl]`.
if (dir === 'rtl') {
dirInferred = dir
if (direction === 'rtl') {
directionInferred = direction
} else if (
// Explicit `[dir=ltr]`.
dir === 'ltr' ||
direction === 'ltr' ||
// HTML with an invalid or no `[dir]`.
(dir !== 'auto' && node.tagName === 'html') ||
(direction !== 'auto' && node.tagName === 'html') ||
// `input[type=tel]` with an invalid or no `[dir]`.
(dir !== 'auto' && node.tagName === 'input' && type === 'tel')
(direction !== 'auto' && node.tagName === 'input' && type === 'tel')
) {
dirInferred = 'ltr'
directionInferred = 'ltr'
// `[dir=auto]` or `bdi` with an invalid or no `[dir]`.
} else if (dir === 'auto' || node.tagName === 'bdi') {
} else if (direction === 'auto' || node.tagName === 'bdi') {
if (node.tagName === 'textarea') {
// Check contents of `<textarea>`.
dirInferred = dirBidi(toString(node))
directionInferred = directionBidi(toString(node))
} else if (
node.tagName === 'input' &&
(type === 'email' ||
Expand All @@ -80,17 +80,17 @@ export function enterState(state, node) {
type === 'text')
) {
// Check value of `<input>`.
dirInferred = node.properties.value
? dirBidi(String(node.properties.value))
directionInferred = node.properties.value
? directionBidi(String(node.properties.value))
: 'ltr'
} else {
// Check text nodes in `node`.
visit(node, inferDirectionality)
}
}

if (dirInferred) {
state.direction = dirInferred
if (directionInferred) {
state.direction = directionInferred
}
}
// Turn off editing mode in non-HTML spaces.
Expand All @@ -115,8 +115,8 @@ export function enterState(state, node) {
/** @type {Visitor} */
function inferDirectionality(child) {
if (child.type === 'text') {
dirInferred = dirBidi(child.value)
return dirInferred ? EXIT : undefined
directionInferred = directionBidi(child.value)
return directionInferred ? EXIT : undefined
}

if (
Expand All @@ -126,7 +126,7 @@ export function enterState(state, node) {
child.tagName === 'script' ||
child.tagName === 'style' ||
child.tagName === 'textare' ||
dirProperty(child))
directionProperty(child))
) {
return SKIP
}
Expand All @@ -141,7 +141,7 @@ export function enterState(state, node) {
* @returns {Exclude<Direction, 'auto'> | undefined}
* Directionality.
*/
function dirBidi(value) {
function directionBidi(value) {
const result = direction(value)
return result === 'neutral' ? undefined : result
}
Expand All @@ -152,7 +152,7 @@ function dirBidi(value) {
* @returns {Direction | undefined}
* Directionality.
*/
function dirProperty(node) {
function directionProperty(node) {
const value =
node.type === 'element' && typeof node.properties.dir === 'string'
? node.properties.dir.toLowerCase()
Expand Down
29 changes: 16 additions & 13 deletions lib/pseudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function checked(_, element) {
* @returns {boolean}
* Whether `element` matches `query`.
*/
// eslint-disable-next-line unicorn/prevent-abbreviations
function dir(query, _1, _2, _3, state) {
assert(query.argument, 'expected `argument`')
assert(query.argument.type === 'String', 'expected plain text')
Expand Down Expand Up @@ -270,9 +271,9 @@ function firstOfType(query, _1, _2, _3, state) {
function getCachedNthCheck(query) {
/** @type {(value: number) => boolean} */
// @ts-expect-error: cache.
let fn = query._cachedFn
let cachedFunction = query._cachedFn

if (!fn) {
if (!cachedFunction) {
const value = query.argument
assert(value, 'expected `argument`')

Expand All @@ -282,12 +283,12 @@ function getCachedNthCheck(query) {
)
}

fn = nthCheck(value.a + 'n+' + value.b)
cachedFunction = nthCheck(value.a + 'n+' + value.b)
// @ts-expect-error: cache.
query._cachedFn = fn
query._cachedFn = cachedFunction
}

return fn
return cachedFunction
}

/**
Expand Down Expand Up @@ -484,9 +485,11 @@ function not(query, element, index, parent, state) {
* Whether `element` matches `query`.
*/
function nthChild(query, _1, _2, _3, state) {
const fn = getCachedNthCheck(query)
const cachedFunction = getCachedNthCheck(query)
assertDeep(state, query)
return typeof state.elementIndex === 'number' && fn(state.elementIndex)
return (
typeof state.elementIndex === 'number' && cachedFunction(state.elementIndex)
)
}

/**
Expand All @@ -506,12 +509,12 @@ function nthChild(query, _1, _2, _3, state) {
* Whether `element` matches `query`.
*/
function nthLastChild(query, _1, _2, _3, state) {
const fn = getCachedNthCheck(query)
const cachedFunction = getCachedNthCheck(query)
assertDeep(state, query)
return Boolean(
typeof state.elementCount === 'number' &&
typeof state.elementIndex === 'number' &&
fn(state.elementCount - state.elementIndex - 1)
cachedFunction(state.elementCount - state.elementIndex - 1)
)
}

Expand All @@ -532,12 +535,12 @@ function nthLastChild(query, _1, _2, _3, state) {
* Whether `element` matches `query`.
*/
function nthLastOfType(query, _1, _2, _3, state) {
const fn = getCachedNthCheck(query)
const cachedFunction = getCachedNthCheck(query)
assertDeep(state, query)
return (
typeof state.typeCount === 'number' &&
typeof state.typeIndex === 'number' &&
fn(state.typeCount - 1 - state.typeIndex)
cachedFunction(state.typeCount - 1 - state.typeIndex)
)
}

Expand All @@ -558,9 +561,9 @@ function nthLastOfType(query, _1, _2, _3, state) {
* Whether `element` matches `query`.
*/
function nthOfType(query, _1, _2, _3, state) {
const fn = getCachedNthCheck(query)
const cachedFunction = getCachedNthCheck(query)
assertDeep(state, query)
return typeof state.typeIndex === 'number' && fn(state.typeIndex)
return typeof state.typeIndex === 'number' && cachedFunction(state.typeIndex)
}

/**
Expand Down
16 changes: 8 additions & 8 deletions lib/walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ function applySelectors(state, rules, node, index, parent) {
nest.combinator === '+'
? 'adjacentSibling'
: nest.combinator === '~'
? 'generalSibling'
: nest.combinator === '>'
? 'directChild'
: 'descendant'
? 'generalSibling'
: nest.combinator === '>'
? 'directChild'
: 'descendant'
add(nestResult, label, nest)
} else {
// We have a match!
Expand Down Expand Up @@ -237,10 +237,10 @@ function combine(left, right) {
return left && right && left.length > 0 && right.length > 0
? [...left, ...right]
: left && left.length > 0
? left
: right && right.length > 0
? right
: empty
? left
: right && right.length > 0
? right
: empty
}

/**
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@
"zwitch": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"@types/node": "^22.0.0",
"c8": "^10.0.0",
"hastscript": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.56.0"
"xo": "^0.59.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
Expand Down Expand Up @@ -107,6 +107,7 @@
],
"prettier": true,
"rules": {
"logical-assignment-operators": "off",
"max-params": "off",
"unicorn/prefer-at": "off"
}
Expand Down
Loading

0 comments on commit f22db43

Please sign in to comment.