Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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