Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e8e1e8

Browse files
authored
perf: remove unnecessary second filter for type narrowing (#2417)
1 parent 02e6bbf commit 8e8e1e8

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

‎lib/rules/enforce-style-attribute.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ module.exports = {
9292
return {}
9393
}
9494

95-
const topLevelElements = documentFragment.children.filter(isVElement)
96-
consttopLevelStyleTags=topLevelElements.filter(
97-
(element) => element.rawName === 'style'
95+
const topLevelStyleTags = documentFragment.children.filter(
96+
/** @returns {element is VElement} */
97+
(element) => isVElement(element)&&element.rawName === 'style'
9898
)
9999

100100
if (topLevelStyleTags.length === 0) {

‎lib/rules/require-explicit-slots.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ module.exports = {
5959
if (!documentFragment) {
6060
return {}
6161
}
62-
const scripts = documentFragment.children
63-
.filter(utils.isVElement)
64-
.filter((element) => element.name === 'script')
62+
const scripts = documentFragment.children.filter(
63+
/** @returns {element is VElement} */
64+
(element) => utils.isVElement(element) && element.name === 'script'
65+
)
6566
if (scripts.every((script) => !utils.hasAttribute(script, 'lang', 'ts'))) {
6667
return {}
6768
}

‎lib/utils/index.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,9 +2643,10 @@ function getScriptSetupElement(context) {
26432643
if (!df) {
26442644
return null
26452645
}
2646-
const scripts = df.children
2647-
.filter(isVElement)
2648-
.filter((e) => e.name === 'script')
2646+
const scripts = df.children.filter(
2647+
/** @returns {e is VElement} */
2648+
(e) => isVElement(e) && e.name === 'script'
2649+
)
26492650
if (scripts.length === 2) {
26502651
return scripts.find((e) => hasAttribute(e, 'setup')) || null
26512652
} else {

‎lib/utils/selector.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,10 @@ function buildPseudoNthVElementMatcher(testIndex) {
580580
*/
581581
function buildPseudoNthOfTypeVElementMatcher(testIndex) {
582582
return (element) => {
583-
const elements = element.parent.children
584-
.filter(isVElement)
585-
.filter((e) => e.rawName === element.rawName)
583+
const elements = element.parent.children.filter(
584+
/** @returns {e is VElement} */
585+
(e) => isVElement(e) && e.rawName === element.rawName
586+
)
586587
return testIndex(elements.indexOf(element), elements.length)
587588
}
588589
}

‎lib/utils/style-variables/index.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ function getStyleVariablesContext(context) {
4747
if (!df) {
4848
return null
4949
}
50-
const styles = df.children
51-
.filter(isVElement)
52-
.filter((e) => e.name === 'style')
50+
const styles = df.children.filter(
51+
/** @returns {e is VElement} */
52+
(e) => isVElement(e) && e.name === 'style'
53+
)
5354
if (styles.length === 0) {
5455
return null
5556
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /