Skip to content

Commit

Permalink
Merge pull request #51 from imslepov/fix/ref-for-non-primitive-types
Browse files Browse the repository at this point in the history
fix: ref for non-primitive types
  • Loading branch information
yoyo930021 authored Apr 13, 2024
2 parents dac94dc + 9cd95d8 commit 28fa88b
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/plugins/vue-class-component/Data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ASTConverter, ASTResultKind, ReferenceKind } from '../types'
import type ts from 'typescript'
import { isPrimitiveType, copySyntheticComments, removeComments } from '../../utils'
import { copySyntheticComments, removeComments } from '../../utils'

export const convertData: ASTConverter<ts.PropertyDeclaration> = (node, options, program) => {

Check warning on line 5 in src/plugins/vue-class-component/Data.ts

View workflow job for this annotation

GitHub Actions / lint

'program' is defined but never used
if (!node.initializer) {
Expand All @@ -9,31 +9,20 @@ export const convertData: ASTConverter<ts.PropertyDeclaration> = (node, options,
const tsModule = options.typescript
const dataName = node.name.getText()

const checker = program.getTypeChecker()
const isRef = isPrimitiveType(tsModule, checker.getTypeAtLocation(node.initializer))

const tag = (isRef) ? 'Data-ref' : 'Data-reactive'
const named = (isRef) ? ['ref'] : ['reactive']
const callExpr = (isRef)
? tsModule.createCall(
tsModule.createIdentifier('ref'),
undefined,
[removeComments(tsModule, node.initializer)]
)
: tsModule.createCall(
tsModule.createIdentifier('reactive'),
undefined,
[removeComments(tsModule, node.initializer)]
)
const callExpr = tsModule.createCall(
tsModule.createIdentifier('ref'),
undefined,
[removeComments(tsModule, node.initializer)]
)

return {
tag,
tag: 'Data-ref',
kind: ASTResultKind.COMPOSITION,
imports: [{
named,
named: ['ref'],
external: (options.compatible) ? '@vue/composition-api' : 'vue'
}],
reference: (isRef) ? ReferenceKind.VARIABLE_VALUE : ReferenceKind.VARIABLE,
reference: ReferenceKind.VARIABLE_VALUE,
attributes: [dataName],
nodes: [
copySyntheticComments(
Expand Down

0 comments on commit 28fa88b

Please sign in to comment.