WEB-47204 Vue 3: support arrow function setup() master
authorPiotr Tomiak <piotr.tomiak@jetbrains.com>
Mon, 26 Oct 2020 16:54:26 +0000 (17:54 +0100)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 26 Oct 2020 17:15:04 +0000 (17:15 +0000)
GitOrigin-RevId: 543f8fbe8e33f7ae26f2e35e13f2e0948200cbbf

vuejs/src/org/jetbrains/vuejs/model/source/VueCompositionInfoProvider.kt
vuejs/vuejs-tests/src/org/jetbrains/vuejs/lang/VueHighlightingTest.kt
vuejs/vuejs-tests/testData/highlighting/asyncSetup.vue [new file with mode: 0644]

index 9c7b3d0e79ab533d84b6930e76f48e9fd64ba62a..952475600447f5e80c3e63b5995040213ddeac94 100644 (file)
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiElement
 import com.intellij.psi.util.CachedValueProvider
 import com.intellij.psi.util.CachedValuesManager
 import com.intellij.util.castSafelyTo
+import org.jetbrains.vuejs.codeInsight.resolveElementTo
 import org.jetbrains.vuejs.codeInsight.resolveSymbolFromNodeModule
 import org.jetbrains.vuejs.index.COMPOSITION_API_MODULE
 import org.jetbrains.vuejs.index.VUE_MODULE
@@ -43,8 +44,8 @@ class VueCompositionInfoProvider : VueContainerInfoProvider {
                             initializer, "$COMPOSITION_API_MODULE/dist/reactivity/ref",
                             "UnwrapRef", TypeScriptTypeAlias::class.java)
           CachedValueProvider.Result.create(
-            initializer.findProperty(SETUP_METHOD)
-              ?.castSafelyTo<JSFunctionProperty>()
+            resolveElementTo(initializer.findProperty(SETUP_METHOD), JSFunction::class)
+              ?.castSafelyTo<JSFunction>()
               ?.returnType
               ?.let { returnType ->
                 (returnType as? JSAsyncReturnType)
index dd029f01aec40751f15ade6e844ddf0aa83a228a..c03eb0df4d2a6f6b8d7f0930bf2750d73a61a0c6 100644 (file)
@@ -1554,6 +1554,13 @@ var <info descr="global variable">i</info>:<info descr="exported class">SpaceInt
     myFixture.checkHighlighting()
   }
 
+  fun testAsyncSetup() {
+    myFixture.configureDependencies(VueTestModule.VUE_3_0_0)
+    myFixture.enableInspections(VueInspectionsProvider())
+    myFixture.configureByFile("asyncSetup.vue")
+    myFixture.checkHighlighting()
+  }
+
 }
 
 fun createTwoClassComponents(fixture: CodeInsightTestFixture, tsLang: Boolean = false) {
diff --git a/vuejs/vuejs-tests/testData/highlighting/asyncSetup.vue b/vuejs/vuejs-tests/testData/highlighting/asyncSetup.vue
new file mode 100644 (file)
index 0000000..ec6e789
--- /dev/null
@@ -0,0 +1,26 @@
+<template>
+  <div>
+    <p>{{ stories }}</p>
+    <p>{{ <weak_warning descr="Element is not exported">fooBar</weak_warning> }}</p>
+    <div @input="getFoo()" />
+  </div>
+</template>
+
+<script lang="ts">
+import { defineComponent } from "vue";
+
+function foo() {
+  return {
+    fooBar: 12
+  }
+}
+
+export default defineComponent({
+  setup: () => ({
+    stories: 12,
+    getFoo() {
+      return 1;
+    }
+  })
+});
+</script>