Skip to content

Commit d7331ac

Browse files
committed
make it compatible with Node.js v14
1 parent fe49694 commit d7331ac

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ function addUseTemplateRefImport(context, fixer) {
7575
)
7676

7777
if (vueDestructuredImport) {
78-
const importSpecifierLast = vueDestructuredImport.specifiers.at(-1)
78+
const importSpecifierLast = utils.getLastArrayElement(
79+
vueDestructuredImport.specifiers
80+
)
7981

8082
// @ts-ignore
8183
return fixer.insertTextAfter(importSpecifierLast, `,useTemplateRef`)
8284
}
8385

84-
const lastImport = imports.at(-1)
86+
const lastImport = utils.getLastArrayElement(imports)
8587

8688
const importStatement = "import {useTemplateRef} from 'vue';"
8789

lib/utils/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,16 @@ module.exports = {
22082208
(token, i) =>
22092209
token.type === tokensR[i].type && token.value === tokensR[i].value
22102210
)
2211+
},
2212+
2213+
/**
2214+
* TODO: replace usages with 'array.at(-1)' once the minimum supported Node.js version is at least 16.6.0
2215+
* @template T
2216+
* @param array {T[]}
2217+
* @returns {T | undefined}
2218+
* */
2219+
getLastArrayElement(array) {
2220+
return array[array.length - 1]
22112221
}
22122222
}
22132223

0 commit comments

Comments
 (0)