Movatterモバイル変換


[0]ホーム

URL:


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

Commitebff8d9

Browse files
committed
refactor: generate Map
1 parent3f4795c commitebff8d9

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

‎lib/rules/prefer-use-template-ref.js‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const utils = require('../utils')
88

99
/**
1010
*@typedef ScriptRef
11-
*@type {{node: Expression, ref: string}}
11+
*@type {[string, CallExpression]}
1212
*/
1313

1414
/**
@@ -26,10 +26,7 @@ function getScriptRefsFromSetupFunction(body) {
2626
declarator.id.type==='Identifier'&&
2727
['ref','shallowRef'].includes(declarator.init.callee.name)
2828
)
29-
return{
30-
node:declarator.init,
31-
ref:declarator.id.name
32-
}
29+
return[[declarator.id.name,declarator.init]]
3330
}
3431

3532
return[]
@@ -86,21 +83,21 @@ module.exports = {
8683
}),
8784
{
8885
'Program:exit'(){
86+
constscriptRefsMap=newMap(scriptRefs)
87+
8988
for(consttemplateRefoftemplateRefs){
90-
constscriptRef=scriptRefs.find(
91-
(scriptRef)=>scriptRef.ref===templateRef
92-
)
89+
constscriptRef=scriptRefsMap.get(templateRef)
9390

9491
if(!scriptRef){
9592
continue
9693
}
9794

9895
context.report({
99-
node:scriptRef.node,
96+
node:scriptRef,
10097
messageId:'preferUseTemplateRef',
10198
data:{
102-
//@ts-ignore
103-
name:scriptRef.node?.callee?.name
99+
//@ts-expect-error `scriptRef.callee` is `Identifier`
100+
name:scriptRef.callee.name
104101
}
105102
})
106103
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp