Skip to content

Commit

Permalink
fix: <script setup> variables declared with destructure
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Nov 19, 2020
1 parent 5bae813 commit fd96f89
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/vscode-vue-languageservice/src/sourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export function createSourceFile(initialDocument: TextDocument, globalEls: Ref<C
const virtualTemplateGen = useTemplateScript(
untrack(() => vueDoc.value),
computed(() => descriptor.template),
computed(() => descriptor.scriptSetup),
templateScriptData, virtualStyles.textDocuments,
virtualStyles.sourceMaps,
pugData,
Expand Down
8 changes: 8 additions & 0 deletions packages/vscode-vue-languageservice/src/virtuals/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,14 @@ function getScriptSetupData(sourceCode: string) {
end: node_2.name.getStart(scriptAst) + node_2.name.getWidth(scriptAst),
});
}
else if (ts.isObjectBindingPattern(node_2.name) || ts.isArrayBindingPattern(node_2.name)) {
for (const element of node_2.name.elements) {
exposeVarNames.push({
start: element.getStart(scriptAst),
end: element.getStart(scriptAst) + element.getWidth(scriptAst),
});
}
}
}
}
else if (ts.isFunctionDeclaration(node)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useScriptSetupFormat(
const vueDoc = getUnreactiveDoc();
const lang = getValidScriptSyntax(scriptSetup.value.lang);
const uri = `${vueDoc.uri}.scriptSetup.raw.${lang}`;
return TextDocument.create(uri, syntaxToLanguageId(lang), version++, scriptSetup.value.content);
return TextDocument.create(uri, syntaxToLanguageId(lang), version++, scriptSetup.value.content + '\n\nexport {}');
}
});
const sourceMap = computed(() => {
Expand Down
3 changes: 1 addition & 2 deletions packages/vscode-vue-languageservice/src/virtuals/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import * as vueDom from '@vue/compiler-dom';
export function useTemplateScript(
getUnreactiveDoc: () => TextDocument,
template: Ref<IDescriptor['template']>,
scriptSetup: Ref<IDescriptor['scriptSetup']>,
templateScriptData: ITemplateScriptData,
styleDocuments: Ref<{
textDocument: TextDocument;
Expand Down Expand Up @@ -55,7 +54,7 @@ export function useTemplateScript(
`import { VNodeProps as __VLS_Vue_VNodeProps } from '@vue/runtime-dom'`,
`import { AllowedComponentProps as __VLS_Vue_AllowedComponentProps } from '@vue/runtime-dom'`,
`import __VLS_VM from './${upath.basename(vueFileName)}';`,
(scriptSetup.value
(templateScriptData.scriptSetupExports.length
? `import * as __VLS_setups from './${upath.basename(vueFileName)}.scriptSetup.raw';`
: `// no setups`),
`const __VLS_Options = __VLS_VM.__VLS_options`,
Expand Down

0 comments on commit fd96f89

Please sign in to comment.