Skip to content

Script Capability Matrix

Macro Capabilities

MacroStatusDescription
definePropsSupportedSupports runtime declaration and TS type extraction
defineEmitsSupportedSupports event signature extraction and call conversion
defineSlotsSupportedSupports slot type extraction
defineOptionsPartially SupportedMainly processes analyzable fields (e.g., name)

API Adaptation Capabilities (Complete List)

Reactive State API

Vue APIAdaptation TargetCategoryDescription
refuseVRefSide EffectCreates a reactive reference
reactiveuseReactiveSide EffectCreates a reactive object
computeduseComputedSide EffectCreates a computed property
readonlyuseReadonlySide EffectCreates a readonly reactive object
shallowRefuseShallowRefSide EffectCreates a shallow reactive reference
shallowReactiveuseShallowReactiveSide EffectCreates a shallow reactive object
shallowReadonlyuseShallowReadonlySide EffectCreates a shallow readonly reactive object
toRefuseToVRefSide EffectConverts a reactive object's property to a ref
toRefsuseToVRefsSide EffectConverts all properties of a reactive object to refs
toRawuseToRawSide EffectGets the raw object of a reactive object
isRefisRefPure FunctionChecks if a value is a ref
isProxyisProxyPure FunctionChecks if a value is a proxy
isReactiveisReactivePure FunctionChecks if a value is a reactive object

Lifecycle API

Vue APIAdaptation TargetCategoryDescription
onMounteduseMountedPure FunctionExecuted after component mounting
onUnmounteduseUnmountedPure FunctionExecuted after component unmounting
onBeforeMountuseBeforeMountPure FunctionExecuted before component mounting
onBeforeUnmountuseBeforeUnMountPure FunctionExecuted before component unmounting
onBeforeUpdateuseBeforeUpdatePure FunctionExecuted before component update
onUpdateduseUpdatedPure FunctionExecuted after component update
useActiveduseActivedPure FunctionExecuted when KeepAlive component is activated
useDeactivateduseDeactivatedPure FunctionExecuted when KeepAlive component is deactivated

Watcher API

Vue APIAdaptation TargetCategoryDescription
watchuseWatchSide EffectWatches for changes in reactive data sources
watchEffectuseWatchEffectPure FunctionAuto-tracking reactive watcher
watchPostEffectuseWatchPostEffectPure FunctionWatcher executed after DOM update
watchSyncEffectuseWatchSyncEffectPure FunctionSynchronously executed watcher

Dependency Injection API

Vue APIAdaptation TargetCategoryDescription
provideProviderContext ComponentProvides values for dependency injection
injectuseInjectSide EffectInjects values from dependency injection

Template Ref API

Vue APIAdaptation TargetCategoryDescription
useTemplateRefuseRefPure FunctionTemplate ref (converted to React useRef)
Vue Router-style APIAdaptation TargetCategoryDescription
useRouteuseRouteSide EffectAccesses current route information
useRouteruseRouterSide EffectAccesses router instance
useLinkuseLinkSide EffectCustom routing link
onBeforeRouteLeaveuseBeforeRouteLeavePure FunctionRoute guard before leaving the route
onBeforeRouteUpdateuseBeforeRouteUpdatePure FunctionRoute guard before updating the route
onBeforeRouteEnteruseBeforeRouteEnterPure FunctionRoute guard before entering the route
createRoutercreateRouterPure FunctionCreates router instance

Utility Function API

Vue APIAdaptation TargetCategoryDescription
nextTicknextTickPure FunctionExecuted after the next DOM update cycle

Key Conversion Behaviors

  1. emit('change', payload) will be converted to props.onChange(payload)
  2. Top-level arrow functions with trackable internal state will automatically have useCallback and dependency arrays added
  3. defineAsyncComponent will use the React.lazy path
  4. The watchEffect series of APIs will automatically analyze dependencies and add dependency array parameters
  5. Lifecycle hooks will be automatically converted to corresponding React Hook forms

Hard Constraints (Mandatory)

  1. Macros can only be defined at the top level of SFCs
  2. use* APIs converted to Hooks (e.g., ref/watchEffect, etc.) can only be called at the top level or in top-level functions
  3. defineAsyncComponent only supports ESM import('...') syntax

Partial Support and Risks

ScenarioStatusRisk
Traditional scriptPartially SupportedCompilable but less stable than <script setup>
Complex dynamic expressionsPartially SupportedMay trigger warnings, removal, or degradation
Unanalyzable dependency chainsPartially SupportedDependency injection may not behave as expected
Code not processed by the compilerPartially SupportedUnknown APIs, etc., will be carried over to React as-is
  • Use <script setup lang="ts">
  • Enforce checks for Hook top-level rules in code reviews
  • Include compilation warnings as CI failure conditions
  • For complex reactive logic, prioritize useReactive over multiple refs
  • Avoid using other Vue APIs or related libraries outside the compiler's recognition scope; if absolutely necessary, temporarily write React platform code

Released under the MIT License