Skip to content

Commit

Permalink
component
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed May 8, 2024
1 parent 6590f0c commit ba6ef44
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/language-core/lib/utils/parseBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { TextRange, VueCompilerOptions } from '../types';
import { injectTscApiShim } from './tscApiShim';

export enum BindingTypes {
NoUnref,
NeedUnref,
DirectAccess,
NoUnref = 2 << 0,
NeedUnref = 2 << 1,
DirectAccess = 2 << 2,
Component = 2 << 3,
}

export function parseBindings(
Expand All @@ -27,7 +28,7 @@ export function parseBindings(

ts.forEachChild(sourceFile, node => {
// TODO: User may use package name alias then the import specifier may not be `vue`
if (ts.isImportDeclaration(node) && _getNodeText(node.moduleSpecifier) === 'vue') {
if (ts.isImportDeclaration(node) && _getNodeText(node.moduleSpecifier) === vueCompilerOptions?.lib) {
const namedBindings = node.importClause?.namedBindings;
if (namedBindings && ts.isNamedImports(namedBindings)) {
for (const element of namedBindings.elements) {
Expand Down Expand Up @@ -148,8 +149,8 @@ export function parseBindings(
if (node.importClause.name) {
const name = _getNodeText(node.importClause.name);
bindingRanges.push(_getStartEnd(node.importClause.name));
if (ts.isStringLiteral(node.moduleSpecifier) && _getNodeText(node.moduleSpecifier).endsWith('.vue')) {
bindingTypes.set(name, BindingTypes.NoUnref);
if (ts.isStringLiteral(node.moduleSpecifier) && vueCompilerOptions?.extensions.some(ext => _getNodeText(node.moduleSpecifier).endsWith(ext))) {
bindingTypes.set(name, BindingTypes.NoUnref | BindingTypes.Component);
}
else {
bindingTypes.set(name, BindingTypes.NeedUnref);
Expand Down

0 comments on commit ba6ef44

Please sign in to comment.