Kaynağa Gözat

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

fix #4502
ygj6 4 yıl önce
ebeveyn
işleme
0178f4ed31

+ 8 - 0
packages/ref-transform/__tests__/refTransform.spec.ts

@@ -395,4 +395,12 @@ describe('errors', () => {
       `$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')
+  })
 })

+ 2 - 2
packages/ref-transform/src/refTransform.ts

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