]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(ref-transform): not transform the prototype attributes. (#4503)
authorygj6 <7699524+ygj6@users.noreply.github.com>
Sun, 5 Sep 2021 21:35:13 +0000 (05:35 +0800)
committerGitHub <noreply@github.com>
Sun, 5 Sep 2021 21:35:13 +0000 (17:35 -0400)
fix #4502

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

index b4b3473741c74dcbd4e7975953a0610e48506096..1b9f3003bfbe58997f1a7b3eb6164851c49566a4 100644 (file)
@@ -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')
+  })
 })
index 7fae8562e0c2c3e9bd913da6e0e4a41ce05b02ef..bfed7311b84f21ac70980b2a2d80ded0f07db9e2 100644 (file)
@@ -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