Skip to content

Commit

Permalink
resolve e6 property for component targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed Feb 25, 2024
1 parent 1044c9f commit 2c9e4b8
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/main/java/de/espend/idea/vuejs/utils/VueJsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import com.intellij.lang.ecmascript6.psi.ES6FromClause;
import com.intellij.lang.ecmascript6.psi.ES6ImportDeclaration;
import com.intellij.lang.ecmascript6.psi.ES6ImportedBinding;
import com.intellij.lang.ecmascript6.psi.ES6Property;
import com.intellij.lang.ecmascript6.resolve.JSFileReferencesUtil;
import com.intellij.lang.javascript.psi.JSExpression;
import com.intellij.lang.javascript.psi.JSReferenceExpression;
import com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl;
import com.intellij.lang.javascript.psi.util.JSStubBasedPsiTreeUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -51,22 +56,38 @@ public static Map<String, String> getLocalFileScopeComponents(@NotNull PsiFile c
public boolean visitComponent(@NotNull String name, @NotNull VueComponent component, @NotNull VueModelVisitor.Proximity proximity) {
PsiElement source = component.getSource();
if (source instanceof ES6ImportedBinding es6ImportedBinding) {
ES6ImportDeclaration declaration = es6ImportedBinding.getDeclaration();
if (declaration != null) {
ES6FromClause fromClause = declaration.getFromClause();
if (fromClause != null) {
String referenceText1 = fromClause.getReferenceText();
if (referenceText1 != null) {
String referenceText = StringUtil.unquoteString(referenceText1);
components.putIfAbsent(name, referenceText);
components.put(VueJsUtil.convertToKebabCase(name), referenceText);
visitES6ImportedBinding(name, es6ImportedBinding);
} else if (source instanceof ES6Property es6Property) {
JSExpression value1 = es6Property.getValue();
if (value1 instanceof JSReferenceExpression jsReferenceExpression) {
String referenceName = JSReferenceExpressionImpl.getReferenceName(jsReferenceExpression.getNode());
if (referenceName != null) {
for (PsiElement resolveLocallyWithMergedResult : JSStubBasedPsiTreeUtil.resolveLocallyWithMergedResults(referenceName, jsReferenceExpression)) {
if (resolveLocallyWithMergedResult instanceof ES6ImportedBinding es6ImportedBinding) {
visitES6ImportedBinding(name, es6ImportedBinding);
}
}
}
}
}

return super.visitComponent(name, component, proximity);
}

private void visitES6ImportedBinding(@NotNull String name, ES6ImportedBinding es6ImportedBinding) {
ES6ImportDeclaration declaration = es6ImportedBinding.getDeclaration();
if (declaration != null) {
ES6FromClause fromClause = declaration.getFromClause();
if (fromClause != null) {
String referenceText1 = fromClause.getReferenceText();
if (referenceText1 != null) {
String referenceText = StringUtil.unquoteString(referenceText1);
components.putIfAbsent(name, referenceText);
components.put(VueJsUtil.convertToKebabCase(name), referenceText);
}
}
}
}
}, VueModelVisitor.Proximity.GLOBAL);


Expand Down

0 comments on commit 2c9e4b8

Please sign in to comment.