Skip to content

Commit

Permalink
feat: support As expression for script setup
Browse files Browse the repository at this point in the history
close #1882
  • Loading branch information
johnsoncodehk committed Oct 9, 2022
1 parent 4e750f8 commit a750a0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -386,7 +386,11 @@ export function generate(

codeGen.push(`};\n`);
codeGen.push(`return await __VLS_setup();\n`);
codeGen.push(`})();`);
codeGen.push(`})()`);
if (sfc.script && scriptRanges?.exportDefault?.args) {
addVirtualCode('script', scriptRanges.exportDefault.expression.end, scriptRanges.exportDefault.end);
}
codeGen.push(`;`);
// fix https://github.com/johnsoncodehk/volar/issues/1127
codeGen.push([
'',
Expand Down
11 changes: 9 additions & 2 deletions vue-language-tools/vue-language-core/src/parsers/scriptRanges.ts
Expand Up @@ -17,8 +17,15 @@ export function parseScriptRanges(ts: typeof import('typescript/lib/tsserverlibr

const bindings = hasScriptSetup ? parseBindingRanges(ts, ast, false) : [];

ast.forEachChild(node => {
if (ts.isExportAssignment(node)) {
ast.forEachChild(raw => {

if (ts.isExportAssignment(raw)) {

let node: ts.AsExpression | ts.ExportAssignment = raw;
if (ts.isAsExpression(node.expression)) { // fix https://github.com/johnsoncodehk/volar/issues/1882
node = node.expression;
}

let obj: ts.ObjectLiteralExpression | undefined;
if (ts.isObjectLiteralExpression(node.expression)) {
obj = node.expression;
Expand Down

0 comments on commit a750a0b

Please sign in to comment.