Skip to content

Commit

Permalink
refactor: revert reactivity transform
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Mar 28, 2023
1 parent 2704d80 commit 9a7bf74
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,6 @@ const props = defineProps<{msg: string; ids?: string[]}>()
let ids = _ref([])"
`;
exports[`should support module string names syntax 1`] = `
"
let a = (ref(0));
console.log((a))
"
`;
exports[`using ref binding in property shorthand 1`] = `
"import { ref as _ref } from 'vue'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,22 +460,6 @@ test('macro import alias and removal', () => {
assertCode(code)
})

test('should support module string names syntax', () => {
const { code } = transform(
`
import { "$" as fromRefs, "$$" as escapeRefs } from 'vue/macros'
let a = fromRefs(ref(0));
console.log(escapeRefs(a))
`
)
// should remove imports
expect(code).not.toMatch(`from 'vue/macros'`)
expect(code).toMatch(`let a = (ref(0))`)
expect(code).toMatch(`console.log((a))`)
assertCode(code)
})

// #6838
test('should not overwrite importing', () => {
const { code } = transform(
Expand Down
7 changes: 5 additions & 2 deletions packages/reactivity-transform/src/reactivityTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import MagicString, { SourceMap } from 'magic-string'
import { walk } from 'estree-walker'
import {
extractIdentifiers,
getImportedName,
isFunctionType,
isInDestructureAssignment,
isReferencedIdentifier,
Expand Down Expand Up @@ -199,7 +198,11 @@ export function transformAST(

for (const specifier of node.specifiers) {
const local = specifier.local.name
const imported = getImportedName(specifier)
const imported =
(specifier.type === 'ImportSpecifier' &&
specifier.imported.type === 'Identifier' &&
specifier.imported.name) ||
'default'
userImports[local] = {
source,
local,
Expand Down

0 comments on commit 9a7bf74

Please sign in to comment.