fix(ref-transform): not transform the prototype attributes. (#4503)

fix #4502
This commit is contained in:
ygj6 2021-09-06 05:35:13 +08:00 committed by GitHub
parent 12acf5102c
commit 0178f4ed31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -395,4 +395,12 @@ describe('errors', () => {
`$computed can only be used as the initializer` `$computed can only be used as the initializer`
) )
}) })
test('not transform the prototype attributes', () => {
const { code } = transform(`
const hasOwnProperty = Object.prototype.hasOwnProperty
const hasOwn = (val, key) => hasOwnProperty.call(val, key)
`)
expect(code).not.toMatch('.value')
})
}) })

View File

@ -20,7 +20,7 @@ import {
walkFunctionParams walkFunctionParams
} from '@vue/compiler-core' } from '@vue/compiler-core'
import { parse, ParserPlugin } from '@babel/parser' import { parse, ParserPlugin } from '@babel/parser'
import { babelParserDefaultPlugins } from '@vue/shared' import { babelParserDefaultPlugins, hasOwn } from '@vue/shared'
const TO_VAR_SYMBOL = '$' const TO_VAR_SYMBOL = '$'
const TO_REF_SYMBOL = '$$' const TO_REF_SYMBOL = '$$'
@ -309,7 +309,7 @@ export function transformAST(
parent: Node, parent: Node,
parentStack: Node[] parentStack: Node[]
): boolean { ): boolean {
if (id.name in scope) { if (hasOwn(scope, id.name)) {
if (scope[id.name]) { if (scope[id.name]) {
if (isStaticProperty(parent) && parent.shorthand) { if (isStaticProperty(parent) && parent.shorthand) {
// let binding used in a property shorthand // let binding used in a property shorthand