@vue-macros/volar
Advanced tools
Comparing version 0.18.13 to 0.18.14
@@ -25,22 +25,111 @@ // src/export-expose.ts | ||
return; | ||
const exposed = /* @__PURE__ */ Object.create( | ||
null | ||
); | ||
const exposed = /* @__PURE__ */ Object.create(null); | ||
for (const stmt of sfc.scriptSetup.ast.statements) { | ||
if (!ts.isVariableStatement(stmt)) | ||
continue; | ||
const exportModifier = stmt.modifiers?.find( | ||
(m) => m.kind === ts.SyntaxKind.ExportKeyword | ||
); | ||
if (!exportModifier) | ||
continue; | ||
const start = exportModifier.getStart(sfc.scriptSetup?.ast); | ||
const end = exportModifier.getEnd(); | ||
(0, import_language_core2.replaceSourceRange)(file.content, "scriptSetup", start, end); | ||
for (const decl of stmt.declarationList.declarations) { | ||
if (!ts.isIdentifier(decl.name)) | ||
if (ts.isExportDeclaration(stmt) && stmt.exportClause) { | ||
if (ts.isNamedExports(stmt.exportClause)) { | ||
const exportMap = /* @__PURE__ */ new Map(); | ||
stmt.exportClause.elements.forEach((element) => { | ||
if (element.isTypeOnly) | ||
return; | ||
const name = element.name; | ||
const propertyName = element.propertyName || name; | ||
exportMap.set( | ||
[ | ||
propertyName.text, | ||
"scriptSetup", | ||
propertyName.getStart(sfc.scriptSetup?.ast), | ||
import_language_core2.FileRangeCapabilities.full | ||
], | ||
[ | ||
name.text, | ||
"scriptSetup", | ||
name.getStart(sfc.scriptSetup?.ast), | ||
import_language_core2.FileRangeCapabilities.full | ||
] | ||
); | ||
exposed[name.text] = propertyName.text; | ||
}); | ||
if (stmt.moduleSpecifier) { | ||
const start = stmt.getStart(sfc.scriptSetup?.ast); | ||
const end = stmt.getEnd(); | ||
(0, import_language_core2.replaceSourceRange)( | ||
file.content, | ||
"scriptSetup", | ||
start, | ||
start + 6, | ||
"import" | ||
); | ||
(0, import_language_core2.replaceSourceRange)( | ||
file.content, | ||
"scriptSetup", | ||
end, | ||
end, | ||
`;[${Array.from(exportMap.values()).map(([name]) => name)}];` | ||
); | ||
} else { | ||
(0, import_language_core2.replaceSourceRange)( | ||
file.content, | ||
"scriptSetup", | ||
stmt.getStart(sfc.scriptSetup?.ast), | ||
stmt.getEnd(), | ||
`(({`, | ||
...Array.from(exportMap.entries()).flatMap( | ||
([name, value]) => name[0] === value[0] ? [value, ","] : [name, ":", value, ","] | ||
), | ||
`})=>{${Array.from(exportMap.values()).map(([name]) => name)}`, | ||
`})({${Array.from(exportMap.keys()).map(([name]) => name)}})` | ||
); | ||
} | ||
} else if (ts.isNamespaceExport(stmt.exportClause)) { | ||
const start = stmt.getStart(sfc.scriptSetup?.ast); | ||
const end = stmt.getEnd(); | ||
(0, import_language_core2.replaceSourceRange)( | ||
file.content, | ||
"scriptSetup", | ||
start, | ||
start + 6, | ||
"import" | ||
); | ||
(0, import_language_core2.replaceSourceRange)( | ||
file.content, | ||
"scriptSetup", | ||
end, | ||
end, | ||
`;[${stmt.exportClause.name.text}];` | ||
); | ||
} | ||
} else if (ts.isVariableStatement(stmt) || ts.isFunctionDeclaration(stmt) || ts.isClassDeclaration(stmt)) { | ||
const exportModifier = stmt.modifiers?.find( | ||
(m) => m.kind === ts.SyntaxKind.ExportKeyword | ||
); | ||
if (!exportModifier) | ||
continue; | ||
const name = decl.name.text; | ||
const start2 = decl.name.getStart(sfc.scriptSetup?.ast); | ||
exposed[name] = [name, "scriptSetup", start2, import_language_core2.FileRangeCapabilities.full]; | ||
const exposedValues = []; | ||
if (ts.isVariableStatement(stmt)) { | ||
for (const decl of stmt.declarationList.declarations) { | ||
if (!decl.name) | ||
continue; | ||
if (ts.isIdentifier(decl.name)) { | ||
const name = decl.name.text; | ||
exposed[name] = name; | ||
} else if (ts.isObjectBindingPattern(decl.name)) { | ||
decl.name.elements.forEach((element) => { | ||
if (!ts.isIdentifier(element.name)) | ||
return; | ||
exposedValues.push(element.name.text); | ||
exposed[element.name.text] = element.propertyName && ts.isIdentifier(element.propertyName) ? element.propertyName.text : element.name.text; | ||
}); | ||
} | ||
} | ||
} else if (stmt.name && ts.isIdentifier(stmt.name)) { | ||
const name = stmt.name.text; | ||
exposed[name] = name; | ||
} | ||
(0, import_language_core2.replaceSourceRange)( | ||
file.content, | ||
"scriptSetup", | ||
exportModifier.getStart(sfc.scriptSetup?.ast), | ||
exportModifier.getEnd(), | ||
exposedValues.length > 0 ? `[${exposedValues}];` : "" | ||
); | ||
} | ||
@@ -47,0 +136,0 @@ } |
{ | ||
"name": "@vue-macros/volar", | ||
"version": "0.18.13", | ||
"version": "0.18.14", | ||
"packageManager": "pnpm@8.15.5", | ||
@@ -51,4 +51,4 @@ "description": "Volar plugin for Vue Macros.", | ||
"@vue-macros/common": "1.10.1", | ||
"@vue-macros/short-bind": "0.2.2", | ||
"@vue-macros/define-props": "2.0.3", | ||
"@vue-macros/short-bind": "0.2.2", | ||
"@vue-macros/short-vmodel": "1.4.2" | ||
@@ -55,0 +55,0 @@ }, |
45641
1368