New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vue-macros/volar

Package Overview
Dependencies
Maintainers
1
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue-macros/volar - npm Package Compare versions

Comparing version 0.21.1 to 0.22.0

dist/boolean-prop.js

47

dist/define-emit.js
// src/define-emit.ts
var import_common = require("@vue-macros/common");
var import_language_core2 = require("@vue/language-core");
// src/common.ts
var import_language_core = require("@vue/language-core");
var REGEX_DEFINE_COMPONENT = /(?<=\(await import\(\S+\)\)\.defineComponent\({\n)/g;
function addEmits(codes, decl) {
var REGEX_DEFINE_COMPONENT = /(?<=(?:__VLS_|\(await import\(\S+\)\)\.)defineComponent\({\n)/g;
function addEmits(codes, decl, vueLibName) {
if (!decl.length) return;
const index = codes.indexOf("const __VLS_modelEmitsType = ");
if (codes[index + 1] === "{}") {
codes[index + 1] = `(await import('${vueLibName}')).defineEmits<{
${decl.join(",\n")}
}>()`;
} else {
codes.splice(index + 2, 0, `
${decl.join(",\n")}
`);
}
if (codes.some((code) => code.includes("emits: ({} as __VLS_NormalizeEmits<")))
return;
(0, import_language_core.replaceAll)(codes, REGEX_DEFINE_COMPONENT, "emits: ({} as ", ...decl, "),\n");
(0, import_language_core.replaceAll)(
codes,
REGEX_DEFINE_COMPONENT,
"emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType>),\n"
);
return true;

@@ -23,13 +37,2 @@ }

// src/define-emit.ts
function transformDefineModels(options) {
const { codes, emitStrings, vueLibName } = options;
(0, import_language_core2.replace)(
codes,
/(?<=let __VLS_modelEmitsType!: {})/,
` & ReturnType<typeof import('${vueLibName}').defineEmits<{
${emitStrings.join(",\n")}
}>>`
);
addEmits(codes, ["__VLS_NormalizeEmits<typeof __VLS_modelEmitsType>"]);
}
function getEmitStrings(options) {

@@ -41,4 +44,3 @@ const { ts, sfc } = options;

const name = node.arguments.length && ts.isStringLiteral(node.arguments[0]) ? node.arguments[0].text : defaultName;
if (!name)
return;
if (!name) return;
const type = node.typeArguments?.length === 1 ? ts.isFunctionTypeNode(node.typeArguments[0]) ? `Parameters<${getText(node.typeArguments[0], options)}>` : getText(node.typeArguments[0], options) : "[]";

@@ -73,12 +75,5 @@ emitStrings.push(`'${name}': ${type}`);

const emitStrings = getEmitStrings({ ts, sfc });
if (!emitStrings.length)
return;
if (!emitStrings.length) return;
const vueLibName = vueCompilerOptions.lib;
transformDefineModels({
codes: embeddedFile.content,
sfc,
emitStrings,
vueLibName,
ts
});
addEmits(embeddedFile.content, emitStrings, vueLibName);
}

@@ -85,0 +80,0 @@ };

// src/define-models.ts
var import_common = require("@vue-macros/common");
var import_language_core2 = require("@vue/language-core");
// src/common.ts
var import_language_core = require("@vue/language-core");
var REGEX_DEFINE_COMPONENT = /(?<=\(await import\(\S+\)\)\.defineComponent\({\n)/g;
var REGEX_DEFINE_COMPONENT = /(?<=(?:__VLS_|\(await import\(\S+\)\)\.)defineComponent\({\n)/g;
function addProps(codes, decl, vueLibName) {
if (codes.includes("__VLS_TypePropsToOption<"))
return;
(0, import_language_core.replaceAll)(codes, REGEX_DEFINE_COMPONENT, "props: ({} as ", ...decl, "),\n");
if (!decl.length) return;
(0, import_language_core.replace)(
codes,
/(?<=type __VLS_PublicProps = )/,
`{
${decl.join(",\n")}
} & `
);
if (codes.includes("__VLS_TypePropsToOption<")) return;
(0, import_language_core.replaceAll)(
codes,
REGEX_DEFINE_COMPONENT,
" props: ({} as __VLS_TypePropsToOption<__VLS_PublicProps>),\n"
);
codes.push(

@@ -20,6 +30,21 @@ `type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;

}
function addEmits(codes, decl) {
function addEmits(codes, decl, vueLibName) {
if (!decl.length) return;
const index = codes.indexOf("const __VLS_modelEmitsType = ");
if (codes[index + 1] === "{}") {
codes[index + 1] = `(await import('${vueLibName}')).defineEmits<{
${decl.join(",\n")}
}>()`;
} else {
codes.splice(index + 2, 0, `
${decl.join(",\n")}
`);
}
if (codes.some((code) => code.includes("emits: ({} as __VLS_NormalizeEmits<")))
return;
(0, import_language_core.replaceAll)(codes, REGEX_DEFINE_COMPONENT, "emits: ({} as ", ...decl, "),\n");
(0, import_language_core.replaceAll)(
codes,
REGEX_DEFINE_COMPONENT,
"emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType>),\n"
);
return true;

@@ -58,20 +83,4 @@ }

}
if (propStrings.length) {
(0, import_language_core2.replace)(
codes,
/(?<=type __VLS_PublicProps = )/,
`{
${propStrings.join(",\n")}} & `
);
addProps(codes, ["__VLS_TypePropsToOption<__VLS_PublicProps>"], vueLibName);
}
if (emitStrings.length) {
(0, import_language_core2.replace)(
codes,
/(?<=let __VLS_modelEmitsType!: {})/,
` & ReturnType<typeof import('${vueLibName}').defineEmits<{
${emitStrings.join(",\n")}}>>`
);
addEmits(codes, ["__VLS_NormalizeEmits<typeof __VLS_modelEmitsType>"]);
}
addProps(codes, propStrings, vueLibName);
addEmits(codes, emitStrings, vueLibName);
}

@@ -92,4 +101,3 @@ function getTypeArg(ts, sfc) {

return ts.forEachChild(node.declarationList, (decl) => {
if (!ts.isVariableDeclaration(decl) || !decl.initializer)
return;
if (!ts.isVariableDeclaration(decl) || !decl.initializer) return;
return getCallArg(decl.initializer);

@@ -111,4 +119,3 @@ });

const typeArg = getTypeArg(ts, sfc);
if (!typeArg)
return;
if (!typeArg) return;
const vueVersion = vueCompilerOptions.target;

@@ -115,0 +122,0 @@ const vueLibName = vueCompilerOptions.lib;

@@ -25,4 +25,3 @@ // src/define-options.ts

return ts.forEachChild(node.declarationList, (decl) => {
if (!ts.isVariableDeclaration(decl) || !decl.initializer)
return;
if (!ts.isVariableDeclaration(decl) || !decl.initializer) return;
return getCallArg(decl.initializer);

@@ -38,7 +37,5 @@ });

resolveEmbeddedCode(fileName, sfc, embeddedFile) {
if (!sfc.scriptSetup || !sfc.scriptSetup.ast)
return;
if (!sfc.scriptSetup || !sfc.scriptSetup.ast) return;
const arg = getArg(ts, sfc);
if (!arg)
return;
if (!arg) return;
transformDefineOptions({

@@ -45,0 +42,0 @@ codes: embeddedFile.content,

// src/define-prop.ts
var import_common = require("@vue-macros/common");
var import_language_core2 = require("@vue/language-core");
// src/common.ts
var import_language_core = require("@vue/language-core");
var REGEX_DEFINE_COMPONENT = /(?<=\(await import\(\S+\)\)\.defineComponent\({\n)/g;
var REGEX_DEFINE_COMPONENT = /(?<=(?:__VLS_|\(await import\(\S+\)\)\.)defineComponent\({\n)/g;
function addProps(codes, decl, vueLibName) {
if (codes.includes("__VLS_TypePropsToOption<"))
return;
(0, import_language_core.replaceAll)(codes, REGEX_DEFINE_COMPONENT, "props: ({} as ", ...decl, "),\n");
if (!decl.length) return;
(0, import_language_core.replace)(
codes,
/(?<=type __VLS_PublicProps = )/,
`{
${decl.join(",\n")}
} & `
);
if (codes.includes("__VLS_TypePropsToOption<")) return;
(0, import_language_core.replaceAll)(
codes,
REGEX_DEFINE_COMPONENT,
" props: ({} as __VLS_TypePropsToOption<__VLS_PublicProps>),\n"
);
codes.push(

@@ -35,12 +45,10 @@ `type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;

}) {
(0, import_language_core2.replace)(
addProps(
codes,
/(?<=type __VLS_PublicProps = )/,
"{\n",
...defineProps.flatMap((defineProp) => {
const result = [defineProp.name ?? "modelValue"];
defineProps.map((defineProp) => {
let result = defineProp.name ?? "modelValue";
if (!defineProp.required) {
result.push("?");
result += "?";
}
result.push(": ");
result += ": ";
let type = "any";

@@ -52,9 +60,7 @@ if (defineProp.type) {

}
result.push(type, `,
`);
result += type;
return result;
}),
"} & "
vueLibName
);
addProps(codes, ["__VLS_TypePropsToOption<__VLS_PublicProps>"], vueLibName);
if (vueCompilerOptions.experimentalDefinePropProposal === "kevinEdition") {

@@ -156,4 +162,3 @@ codes.push(`

ts.forEachChild(node.declarationList, (decl) => {
if (!ts.isVariableDeclaration(decl) || !decl.initializer)
return;
if (!ts.isVariableDeclaration(decl) || !decl.initializer) return;
if (ts.isCallExpression(decl.initializer) && ts.isIdentifier(decl.initializer.expression) && decl.initializer.expression.escapedText === "$" && decl.initializer.arguments.length > 0) {

@@ -180,4 +185,3 @@ visitNode(decl.initializer.arguments[0], decl, true);

const defineProps = getDefineProp(ts, sfc, vueCompilerOptions);
if (defineProps.length === 0)
return;
if (defineProps.length === 0) return;
const vueLibName = vueCompilerOptions.lib;

@@ -184,0 +188,0 @@ transformDefineProp({

@@ -56,4 +56,3 @@ // src/define-slots.ts

const typeArg = getTypeArg(ts, sfc);
if (!typeArg)
return;
if (!typeArg) return;
transform({

@@ -60,0 +59,0 @@ codes: embeddedFile.content,

@@ -27,4 +27,3 @@ // src/export-expose.ts

);
if (!filter(fileName))
return;
if (!filter(fileName)) return;
const exposed = /* @__PURE__ */ Object.create(null);

@@ -38,4 +37,3 @@ for (const stmt of sfc.scriptSetup.ast.statements) {

stmt.exportClause.elements.forEach((element) => {
if (element.isTypeOnly)
return;
if (element.isTypeOnly) return;
const name = element.name;

@@ -74,3 +72,3 @@ const propertyName = element.propertyName || name;

end,
`(({`,
`;(({`,
...Array.from(exportMap.entries()).flatMap(

@@ -97,9 +95,7 @@ ([name, value]) => name[0] === value[0] ? [value, ","] : [name, ":", value, ","]

);
if (!exportModifier)
continue;
if (!exportModifier) continue;
const exposedValues = [];
if (ts.isVariableStatement(stmt)) {
for (const decl of stmt.declarationList.declarations) {
if (!decl.name)
continue;
if (!decl.name) continue;
if (ts.isIdentifier(decl.name)) {

@@ -110,4 +106,3 @@ const name = decl.name.escapedText;

decl.name.elements.forEach((element) => {
if (!ts.isIdentifier(element.name))
return;
if (!ts.isIdentifier(element.name)) return;
exposedValues.push(element.name.escapedText);

@@ -131,4 +126,3 @@ exposed[element.name.escapedText] = element.propertyName && ts.isIdentifier(element.propertyName) ? element.propertyName.escapedText : element.name.escapedText;

}
if (Object.keys(exposed).length === 0)
return;
if (Object.keys(exposed).length === 0) return;
const exposedStrings = Object.entries(exposed).flatMap(([key, value]) => [

@@ -164,4 +158,3 @@ `${key}: `,

resolveEmbeddedCode(fileName, sfc, embeddedFile) {
if (!sfc.scriptSetup || !sfc.scriptSetup.ast)
return;
if (!sfc.scriptSetup || !sfc.scriptSetup.ast) return;
transform({

@@ -168,0 +161,0 @@ fileName,

@@ -7,7 +7,18 @@ // src/export-props.ts

var import_language_core = require("@vue/language-core");
var REGEX_DEFINE_COMPONENT = /(?<=\(await import\(\S+\)\)\.defineComponent\({\n)/g;
var REGEX_DEFINE_COMPONENT = /(?<=(?:__VLS_|\(await import\(\S+\)\)\.)defineComponent\({\n)/g;
function addProps(codes, decl, vueLibName) {
if (codes.includes("__VLS_TypePropsToOption<"))
return;
(0, import_language_core.replaceAll)(codes, REGEX_DEFINE_COMPONENT, "props: ({} as ", ...decl, "),\n");
if (!decl.length) return;
(0, import_language_core.replace)(
codes,
/(?<=type __VLS_PublicProps = )/,
`{
${decl.join(",\n")}
} & `
);
if (codes.includes("__VLS_TypePropsToOption<")) return;
(0, import_language_core.replaceAll)(
codes,
REGEX_DEFINE_COMPONENT,
" props: ({} as __VLS_TypePropsToOption<__VLS_PublicProps>),\n"
);
codes.push(

@@ -35,14 +46,11 @@ `type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;

);
if (!filter(fileName))
return;
if (!filter(fileName)) return;
const props = /* @__PURE__ */ Object.create(null);
let changed = false;
for (const stmt of sfc.scriptSetup.ast.statements) {
if (!ts.isVariableStatement(stmt))
continue;
if (!ts.isVariableStatement(stmt)) continue;
const exportModifier = stmt.modifiers?.find(
(m) => m.kind === ts.SyntaxKind.ExportKeyword
);
if (!exportModifier)
continue;
if (!exportModifier) continue;
(0, import_language_core2.replaceSourceRange)(

@@ -56,4 +64,3 @@ codes,

for (const decl of stmt.declarationList.declarations) {
if (!ts.isIdentifier(decl.name))
continue;
if (!ts.isIdentifier(decl.name)) continue;
props[decl.name.escapedText] = !!decl.initializer;

@@ -65,7 +72,5 @@ }

codes,
[
`__VLS_TypePropsToOption<{
${Object.entries(props).map(([prop, optional]) => ` ${prop}${optional ? "?" : ""}: typeof ${prop}`).join(",\n")}
}>`
],
Object.entries(props).map(
([prop, optional]) => `${prop}${optional ? "?" : ""}: typeof ${prop}`
),
vueLibName

@@ -83,4 +88,3 @@ );

resolveEmbeddedCode(fileName, sfc, embeddedFile) {
if (!sfc.scriptSetup || !sfc.scriptSetup.ast)
return;
if (!sfc.scriptSetup || !sfc.scriptSetup.ast) return;
const vueLibName = vueCompilerOptions.lib;

@@ -87,0 +91,0 @@ transform({

@@ -21,7 +21,5 @@ // src/export-render.ts

);
if (!filter(fileName))
return;
if (!filter(fileName)) return;
for (const stmt of sfc.scriptSetup.ast.statements) {
if (!ts.isExportAssignment(stmt))
continue;
if (!ts.isExportAssignment(stmt)) continue;
(0, import_language_core2.replaceSourceRange)(

@@ -51,4 +49,3 @@ codes,

resolveEmbeddedCode(fileName, sfc, embeddedFile) {
if (!sfc.scriptSetup || !sfc.scriptSetup.ast)
return;
if (!sfc.scriptSetup || !sfc.scriptSetup.ast) return;
transform({

@@ -55,0 +52,0 @@ fileName,

@@ -106,4 +106,3 @@ // src/common.ts

function transformVSlot(nodeMap, ctxMap, options) {
if (nodeMap.size === 0)
return;
if (nodeMap.size === 0) return;
const { codes, ts, sfc, source } = options;

@@ -115,4 +114,3 @@ nodeMap.forEach(({ attributeMap, vSlotAttribute }, node) => {

([attribute, { children, vIfAttribute, vForAttribute }], index) => {
if (!attribute)
return;
if (!attribute) return;
let vIfAttributeName;

@@ -235,4 +233,3 @@ if (vIfAttribute && (vIfAttributeName = getText(vIfAttribute.name, options))) {

nodes.forEach(({ node, attribute, parent }, index) => {
if (!ts.isIdentifier(attribute.name))
return;
if (!ts.isIdentifier(attribute.name)) return;
if (["v-if", "v-else-if"].includes(getText(attribute.name, options)) && isJsxExpression(attribute.initializer) && attribute.initializer.expression) {

@@ -351,4 +348,3 @@ const hasScope = parent && attribute.name.escapedText === "v-if";

}
if (!firstNamespacedNode)
return;
if (!firstNamespacedNode) return;
const { attribute, node } = firstNamespacedNode;

@@ -369,4 +365,3 @@ getModelsType(codes);

function getModelsType(codes) {
if (codes.toString().includes("type __VLS_GetModels"))
return;
if (codes.toString().includes("type __VLS_GetModels")) return;
codes.push(`

@@ -411,4 +406,3 @@ type __VLS_NormalizeProps<T> = T extends object

function transformVOn(nodes, ctxMap, { codes, source }) {
if (nodes.length === 0)
return;
if (nodes.length === 0) return;
for (const { node, attribute } of nodes) {

@@ -430,3 +424,3 @@ (0, import_language_core6.replaceSourceRange)(

const end = attribute.name.end;
(0, import_language_core6.replaceSourceRange)(codes, source, start, end, [
(0, import_language_core6.replaceSourceRange)(codes, source, start, end, "{...{", [
attributeName,

@@ -437,4 +431,14 @@ source,

]);
if (!attribute.initializer)
(0, import_language_core6.replaceSourceRange)(codes, source, end, end, "={() => {}}");
if (!attribute.initializer) {
(0, import_language_core6.replaceSourceRange)(codes, source, end, end, ": () => {}}}");
} else if (isJsxExpression(attribute.initializer) && attribute.initializer.expression) {
(0, import_language_core6.replaceSourceRange)(
codes,
source,
end,
getStart(attribute.initializer.expression, options),
": "
);
(0, import_language_core6.replaceSourceRange)(codes, source, attribute.end, attribute.end, "}");
}
}

@@ -447,4 +451,3 @@ }

function transformVBind(nodes, options) {
if (nodes.length === 0)
return;
if (nodes.length === 0) return;
const { codes, ts, source } = options;

@@ -505,11 +508,8 @@ for (const { attribute } of nodes) {

const openingElement = getOpeningElement(node, options);
if (!openingElement)
return "";
if (!openingElement) return "";
let props = "";
for (const prop of openingElement.attributes.properties) {
if (!ts.isJsxAttribute(prop))
continue;
if (!ts.isJsxAttribute(prop)) continue;
const name = getText(prop.name, options);
if (name.startsWith("v-"))
continue;
if (name.startsWith("v-")) continue;
const value = isJsxExpression(prop.initializer) ? getText(prop.initializer.expression, options) : "true";

@@ -555,4 +555,3 @@ props += `'${name}': ${value},`;

for (const attribute of properties?.attributes.properties || []) {
if (!ts.isJsxAttribute(attribute))
continue;
if (!ts.isJsxAttribute(attribute)) continue;
const attributeName = getText(attribute.name, options);

@@ -602,4 +601,3 @@ if (["v-if", "v-else-if", "v-else"].includes(attributeName)) {

const slotNode = tagName === "template" ? parent : node;
if (!slotNode)
return;
if (!slotNode) return;
ctxNodeSet.add(slotNode);

@@ -619,4 +617,3 @@ const attributeMap = vSlotMap.get(slotNode)?.attributeMap || vSlotMap.set(slotNode, {

children.push(node);
if (attributeMap.get(null))
return;
if (attributeMap.get(null)) return;
for (const child of parent.children) {

@@ -661,4 +658,3 @@ if (getTagName(child, options) === "template" || ts.isJsxText(child) && !getText(child, options).trim())

const openingElement = getOpeningElement(node, options);
if (!openingElement)
return "";
if (!openingElement) return "";
let types = "";

@@ -680,7 +676,5 @@ if (options.withTypes && openingElement.typeArguments?.length) {

resolveEmbeddedCode(fileName, sfc, embeddedFile) {
if (!["jsx", "tsx"].includes(embeddedFile.lang))
return;
if (!["jsx", "tsx"].includes(embeddedFile.lang)) return;
for (const source of ["script", "scriptSetup"]) {
if (!sfc[source]?.ast)
continue;
if (!sfc[source]?.ast) continue;
transformJsxDirective({

@@ -687,0 +681,0 @@ codes: embeddedFile.content,

// src/setup-jsdoc.ts
var import_language_core = require("@vue/language-core");
function hasJSDocNodes(node) {
if (!node)
return false;
if (!node) return false;
const { jsDoc } = node;

@@ -19,6 +18,4 @@ return !!jsDoc && jsDoc.length > 0;

for (const stmt of sfc.scriptSetup.ast.statements) {
if (!ts.isExportAssignment(stmt))
continue;
if (hasJSDocNodes(stmt))
jsDoc ??= stmt.jsDoc.at(-1);
if (!ts.isExportAssignment(stmt)) continue;
if (hasJSDocNodes(stmt)) jsDoc ??= stmt.jsDoc.at(-1);
}

@@ -39,4 +36,3 @@ if (jsDoc) {

resolveEmbeddedCode(fileName, sfc, embeddedFile) {
if (!sfc.scriptSetup || !sfc.scriptSetup.ast)
return;
if (!sfc.scriptSetup || !sfc.scriptSetup.ast) return;
transform({

@@ -43,0 +39,0 @@ codes: embeddedFile.content,

{
"name": "@vue-macros/volar",
"version": "0.21.1",
"version": "0.22.0",
"description": "Volar plugin for Vue Macros.",

@@ -34,2 +34,3 @@ "keywords": [

"./*": {
"dev": "./src/*.ts",
"require": "./dist/*.js"

@@ -48,7 +49,8 @@ }

"@rollup/pluginutils": "^5.1.0",
"@vue/language-core": "2.0.19",
"@vue/language-core": "2.0.21",
"@vue/shared": "^3.4.27",
"@vue-macros/boolean-prop": "0.4.0",
"@vue-macros/common": "1.10.4",
"@vue-macros/define-props": "2.0.6",
"@vue-macros/short-bind": "0.2.5",
"@vue-macros/define-props": "2.0.6",
"@vue-macros/short-vmodel": "1.4.5"

@@ -59,3 +61,3 @@ },

"typescript": "~5.4.5",
"vue-tsc": "2.0.19"
"vue-tsc": "2.0.21"
},

@@ -62,0 +64,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc