Skip to content

Commit 0178f4e

Browse files
authored
fix(ref-transform): not transform the prototype attributes. (#4503)
fix #4502
1 parent 12acf51 commit 0178f4e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/ref-transform/__tests__/refTransform.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,12 @@ describe('errors', () => {
395395
`$computed can only be used as the initializer`
396396
)
397397
})
398+
399+
test('not transform the prototype attributes', () => {
400+
const { code } = transform(`
401+
const hasOwnProperty = Object.prototype.hasOwnProperty
402+
const hasOwn = (val, key) => hasOwnProperty.call(val, key)
403+
`)
404+
expect(code).not.toMatch('.value')
405+
})
398406
})

packages/ref-transform/src/refTransform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
walkFunctionParams
2121
} from '@vue/compiler-core'
2222
import { parse, ParserPlugin } from '@babel/parser'
23-
import { babelParserDefaultPlugins } from '@vue/shared'
23+
import { babelParserDefaultPlugins, hasOwn } from '@vue/shared'
2424

2525
const TO_VAR_SYMBOL = '$'
2626
const TO_REF_SYMBOL = '$$'
@@ -309,7 +309,7 @@ export function transformAST(
309309
parent: Node,
310310
parentStack: Node[]
311311
): boolean {
312-
if (id.name in scope) {
312+
if (hasOwn(scope, id.name)) {
313313
if (scope[id.name]) {
314314
if (isStaticProperty(parent) && parent.shorthand) {
315315
// let binding used in a property shorthand

0 commit comments

Comments
 (0)