Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/mocker/src/node/esmWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,13 @@ export function esmWalker(
identifiers.forEach(([node, stack]) => {
if (!isInScope(node.name, stack)) {
const parent = stack[0]
const grandparent = stack[1]
const hasBindingShortcut
= isStaticProperty(parent)
&& parent.shorthand
&& (!isNodeInPattern(parent)
|| isInDestructuringAssignment(parent, parentStack))

const classDeclaration
= (parent.type === 'PropertyDefinition'
&& grandparent?.type === 'ClassBody')
|| (parent.type === 'ClassDeclaration' && node === parent.superClass)
const classDeclaration = (parent.type === 'ClassDeclaration' && node === parent.superClass)

const classExpression
= parent.type === 'ClassExpression' && node === parent.id
Expand Down Expand Up @@ -311,6 +307,12 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
return false
}

// class property
if (parent.type === 'PropertyDefinition' && !parent.computed) {
// Default values can still reference identifiers
return id === parent.value
}

// property key
if (isStaticPropertyKey(id, parent)) {
return false
Expand Down
18 changes: 14 additions & 4 deletions test/core/test/injector-mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,12 +746,18 @@ const obj = {
expect(
hoistSimpleCodeWithoutMocks(
`
import { remove, add } from 'vue'
import { remove, add, update, del, call } from 'vue'

class A {
remove = 1
add = null
update = update
del = () => del()
call = call(4)
}

remove(2);
add(4);
`,
),
).toMatchInlineSnapshot(`
Expand All @@ -761,12 +767,16 @@ class A {



const add = __vi_import_0__.add;
const remove = __vi_import_0__.remove;
class A {
remove = 1
add = null
}"
update = __vi_import_0__.update
del = () => __vi_import_0__.del()
call = __vi_import_0__.call(4)
}

__vi_import_0__.remove(2);
__vi_import_0__.add(4);"
`)
})

Expand Down
Loading