From 9cd95d8a4ebbca17a09c12a5e69ad308f903d9f9 Mon Sep 17 00:00:00 2001 From: Daniel Slepov <danil.slepov@gmail.com> Date: Sat, 13 Apr 2024 10:27:18 +0500 Subject: [PATCH] fix: ref for non-primitive types --- src/plugins/vue-class-component/Data.ts | 29 ++++++++----------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/plugins/vue-class-component/Data.ts b/src/plugins/vue-class-component/Data.ts index 58ae92f..55d0138 100644 --- a/src/plugins/vue-class-component/Data.ts +++ b/src/plugins/vue-class-component/Data.ts @@ -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) => { if (!node.initializer) { @@ -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(