( from: 'script' | 'scriptSetup', node: Declaration, bindings: Record<string, BindingTypes>, userImportAliases: Record<string, string>, hoistStatic: boolean, isPropsDestructureEnabled = false, )
| 1127 | } |
| 1128 | |
| 1129 | function walkDeclaration( |
| 1130 | from: 'script' | 'scriptSetup', |
| 1131 | node: Declaration, |
| 1132 | bindings: Record<string, BindingTypes>, |
| 1133 | userImportAliases: Record<string, string>, |
| 1134 | hoistStatic: boolean, |
| 1135 | isPropsDestructureEnabled = false, |
| 1136 | ): boolean { |
| 1137 | let isAllLiteral = false |
| 1138 | |
| 1139 | if (node.type === 'VariableDeclaration') { |
| 1140 | const isConst = node.kind === 'const' |
| 1141 | isAllLiteral = |
| 1142 | isConst && |
| 1143 | node.declarations.every( |
| 1144 | decl => decl.id.type === 'Identifier' && isStaticNode(decl.init!), |
| 1145 | ) |
| 1146 | |
| 1147 | // export const foo = ... |
| 1148 | for (const { id, init: _init } of node.declarations) { |
| 1149 | const init = _init && unwrapTSNode(_init) |
| 1150 | const isConstMacroCall = |
| 1151 | isConst && |
| 1152 | isCallOf( |
| 1153 | init, |
| 1154 | c => |
| 1155 | c === DEFINE_PROPS || |
| 1156 | c === DEFINE_EMITS || |
| 1157 | c === WITH_DEFAULTS || |
| 1158 | c === DEFINE_SLOTS, |
| 1159 | ) |
| 1160 | if (id.type === 'Identifier') { |
| 1161 | let bindingType |
| 1162 | const userReactiveBinding = userImportAliases['reactive'] |
| 1163 | if ( |
| 1164 | (hoistStatic || from === 'script') && |
| 1165 | (isAllLiteral || (isConst && isStaticNode(init!))) |
| 1166 | ) { |
| 1167 | bindingType = BindingTypes.LITERAL_CONST |
| 1168 | } else if (isCallOf(init, userReactiveBinding)) { |
| 1169 | // treat reactive() calls as let since it's meant to be mutable |
| 1170 | bindingType = isConst |
| 1171 | ? BindingTypes.SETUP_REACTIVE_CONST |
| 1172 | : BindingTypes.SETUP_LET |
| 1173 | } else if ( |
| 1174 | // if a declaration is a const literal, we can mark it so that |
| 1175 | // the generated render fn code doesn't need to unref() it |
| 1176 | isConstMacroCall || |
| 1177 | (isConst && canNeverBeRef(init!, userReactiveBinding)) |
| 1178 | ) { |
| 1179 | bindingType = isCallOf(init, DEFINE_PROPS) |
| 1180 | ? BindingTypes.SETUP_REACTIVE_CONST |
| 1181 | : BindingTypes.SETUP_CONST |
| 1182 | } else if (isConst) { |
| 1183 | if ( |
| 1184 | isCallOf( |
| 1185 | init, |
| 1186 | m => |
no test coverage detected