Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(ref-transform): not transform the prototype attributes. (#4503)
fix #4502
  • Loading branch information
ygj6 committed Sep 5, 2021
1 parent 12acf51 commit 0178f4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/ref-transform/__tests__/refTransform.spec.ts
Expand Up @@ -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')
})
})
4 changes: 2 additions & 2 deletions packages/ref-transform/src/refTransform.ts
Expand Up @@ -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 = '$$'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0178f4e

Please sign in to comment.