Skip to content

Commit

Permalink
feat: add support for :outdated pseudo selector (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf authored Sep 20, 2022
1 parent b30604e commit 34ea05a
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ const fixupPaths = astNode => {
astNode.nodes.length = 0
}

const fixupOutdated = astNode => {
if (astNode.nodes.length) {
astNode.outdatedKind = String(astNode.nodes[0])
astNode.nodes.length = 0
}
}

// a few of the supported ast nodes need to be tweaked in order to properly be
// interpreted as proper arborist query selectors, namely semver ranges from
// both ids and :semver pseudo-class selectors need to be translated from what
Expand Down Expand Up @@ -196,6 +203,8 @@ const transformAst = selector => {
return fixupSemverSpecs(nextAstNode)
case ':type':
return fixupTypes(nextAstNode)
case ':outdated':
return fixupOutdated(nextAstNode)
}
})
}
Expand Down
137 changes: 137 additions & 0 deletions tap-snapshots/test/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7492,6 +7492,143 @@ exports[`test/index.js TAP > :not(:not(:link)) 1`] = `
}
`

exports[`test/index.js TAP > :outdated 1`] = `
&ref_2 Root {
"_error": Function (message, errorOptions),
"indexes": Object {},
"lastEach": 1,
"nodes": Array [
&ref_1 Selector {
"indexes": Object {},
"lastEach": 1,
"nodes": Array [
Pseudo {
"nodes": Array [],
"parent": <*ref_1>,
"source": Object {
"end": Object {
"column": 9,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"sourceIndex": 0,
"spaces": Object {
"after": "",
"before": "",
},
"type": "pseudo",
"value": ":outdated",
},
],
"parent": <*ref_2>,
"source": Object {
"end": Object {
"column": 9,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"spaces": Object {
"after": "",
"before": "",
},
"type": "selector",
},
],
"source": Object {
"end": Object {
"column": 9,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"spaces": Object {
"after": "",
"before": "",
},
"type": "root",
}
`

exports[`test/index.js TAP > :outdated(any) 1`] = `
&ref_2 Root {
"_error": Function (message, errorOptions),
"indexes": Object {},
"lastEach": 1,
"nodes": Array [
&ref_1 Selector {
"indexes": Object {},
"lastEach": 1,
"nodes": Array [
Pseudo {
"nodes": Array [],
"outdatedKind": "any",
"parent": <*ref_1>,
"source": Object {
"end": Object {
"column": 14,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"sourceIndex": 0,
"spaces": Object {
"after": "",
"before": "",
},
"type": "pseudo",
"value": ":outdated",
},
],
"parent": <*ref_2>,
"source": Object {
"end": Object {
"column": 14,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"spaces": Object {
"after": "",
"before": "",
},
"type": "selector",
},
],
"source": Object {
"end": Object {
"column": 14,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"spaces": Object {
"after": "",
"before": "",
},
"type": "root",
}
`

exports[`test/index.js TAP > :path() 1`] = `
&ref_2 Root {
"_error": Function (message, errorOptions),
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ const checks = [
[':attr(funding, :attr([type=GitHub i]))'],
[':attr(arbitrary, foo, :attr(funding, [type=GH]))'],

// :outdated pseudo
[':outdated'],
[':outdated(any)'],

// attribute matchers
['[name]'],
['[name=a]'],
Expand Down

0 comments on commit 34ea05a

Please sign in to comment.