vuejs / vue-eslint-parser

The ESLint custom parser for `.vue` files.
MIT License
443 stars 74 forks source link

Version ^9 throws error using 'no-obj-calls' rule when JSON is used in template #151

Closed iamrgroot closed 2 years ago

iamrgroot commented 2 years ago

See reproduction at: https://github.com/IAmRGroot/reproduction-vue. I'm using Vue 2 with Composition API + Script Setup.

Steps:

Error:

Oops! Something went wrong! :(

ESLint: 8.15.0

TypeError: Cannot read properties of undefined (reading 'parent')
Occurred while linting /app/src/App.vue:9
Rule: "no-obj-calls"
    at isPassThrough (/app/node_modules/eslint-utils/index.js:1461:25)
    at ReferenceTracker._iteratePropertyReferences (/app/node_modules/eslint-utils/index.js:1676:16)
    at _iteratePropertyReferences.next (<anonymous>)
    at ReferenceTracker._iterateVariableReferences (/app/node_modules/eslint-utils/index.js:1659:29)
    at _iterateVariableReferences.next (<anonymous>)
    at ReferenceTracker.iterateGlobalReferences (/app/node_modules/eslint-utils/index.js:1517:25)
    at iterateGlobalReferences.next (<anonymous>)
    at Program (/app/node_modules/eslint/lib/rules/no-obj-calls.js:74:41)
    at ruleErrorHandler (/app/node_modules/eslint/lib/linter/linter.js:1114:28)
    at /app/node_modules/eslint/lib/linter/safe-emitter.js:45:58

Reverting to vue-eslint-parser@^8 or moving the JSON call to the script prevents the error:

<template>
    <div>
        {{ json }}
    </div>
</template>

<script lang="ts" setup>
import { computed } from '@vue/composition-api';

const json = computed(() => JSON.stringify({ test: 'test'}))
</script>
ota-meshi commented 2 years ago

Thank you for posting this issue. I fixed and released it.