diff --git a/graph/test/javascript/expected/70-single-file-component-scripts.diag b/graph/test/javascript/expected/70-single-file-component-scripts.diag index f5093dfa5..f01b3a103 100644 --- a/graph/test/javascript/expected/70-single-file-component-scripts.diag +++ b/graph/test/javascript/expected/70-single-file-component-scripts.diag @@ -4,6 +4,7 @@ import_cause main.js:2:10 vue not_staged package_entry single-file-component-scripts . [] DEFAULT_INDEX index.js MISSING_FILE -> - unresolved components/Legacy.vue:7:26 METHOD_CALL $emit member_absent unresolved components/List.svelte:5:3 FUNCTION_CALL onMount callee_untyped +unresolved components/Price.vue:1:50 FUNCTION_CALL onlyInMarkup callee_untyped unresolved components/Price.vue:6:15 FUNCTION_CALL defineProps callee_untyped unresolved components/Price.vue:7:15 FUNCTION_CALL computed callee_untyped unresolved components/Price.vue:8:22 METHOD_CALL log no_target diff --git a/graph/test/javascript/expected/70-single-file-component-scripts.edges b/graph/test/javascript/expected/70-single-file-component-scripts.edges index 10564fe80..0bb4c4cbb 100644 --- a/graph/test/javascript/expected/70-single-file-component-scripts.edges +++ b/graph/test/javascript/expected/70-single-file-component-scripts.edges @@ -5,6 +5,8 @@ components/List.svelte:5:3 FUNCTION_CALL onMount -> ambiguous_unknown - components/List.svelte:5:3 FUNCTION_CALL onMount -> callback_registered components/List.svelte:5:11 components/List.svelte:5:39 FUNCTION_CALL fetchProducts -> known_edge lib/format.js:5:1 fetchProducts components/List.svelte:6:29 FUNCTION_CALL formatPrice -> known_edge lib/format.js:3:1 formatPrice +components/Price.vue:1:25 FUNCTION_CALL onClick -> known_edge components/Price.vue:8:1 onClick +components/Price.vue:1:50 FUNCTION_CALL onlyInMarkup -> ambiguous_unknown - components/Price.vue:6:15 FUNCTION_CALL defineProps -> ambiguous_unknown - components/Price.vue:7:15 FUNCTION_CALL computed -> ambiguous_unknown - components/Price.vue:7:15 FUNCTION_CALL computed -> callback_registered components/Price.vue:7:24 diff --git a/parser/src/utils/vue-sfc.ts b/parser/src/utils/vue-sfc.ts index 151e09f35..1cf8fd5c6 100644 --- a/parser/src/utils/vue-sfc.ts +++ b/parser/src/utils/vue-sfc.ts @@ -3,6 +3,8 @@ import * as path from 'path'; import * as ts from 'typescript'; +import { isJsComponentFile, sfcScriptText } from '@/utils/javascript'; + /** * A Vue single-file component read as the script it compiles to. * @@ -120,18 +122,47 @@ export function vueComponentLanguage(file: string): VueScriptLanguage | undefine } /** - * A source file's text as a script parser reads it, and how it parses: a `.vue` - * component becomes its virtual script; every other file is itself. + * A source file's text as a script parser reads it, and how it parses. The one + * place a single-file component becomes a script, for every analyzer: + * + * - a `.vue` component becomes its virtual script (script bodies plus template + * references, see above); `language` says which analyzer it belongs to; + * - a `.svelte` / `.astro` component keeps only its JavaScript `