Skip to content

Commit

Permalink
make it compatible with Node.js v14
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasan1999 committed Nov 30, 2024
1 parent fe49694 commit d7331ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rules/prefer-use-template-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ function addUseTemplateRefImport(context, fixer) {
)

if (vueDestructuredImport) {
const importSpecifierLast = vueDestructuredImport.specifiers.at(-1)
const importSpecifierLast = utils.getLastArrayElement(
vueDestructuredImport.specifiers
)

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

const lastImport = imports.at(-1)
const lastImport = utils.getLastArrayElement(imports)

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

Expand Down
10 changes: 10 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,16 @@ module.exports = {
(token, i) =>
token.type === tokensR[i].type && token.value === tokensR[i].value
)
},

/**
* TODO: replace usages with 'array.at(-1)' once the minimum supported Node.js version is at least 16.6.0
* @template T
* @param array {T[]}
* @returns {T | undefined}
* */
getLastArrayElement(array) {
return array[array.length - 1]
}
}

Expand Down

0 comments on commit d7331ac

Please sign in to comment.