Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@volar/vue-code-gen

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@volar/vue-code-gen - npm Package Compare versions

Comparing version 0.34.13 to 0.34.15

2

out/generators/script.d.ts

@@ -12,3 +12,3 @@ import { CodeGen } from '@volar/code-gen';

content: string;
}, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, getHtmlGen: () => ReturnType<typeof templateGen['generate']> | undefined, getStyleBindTexts: () => string[], vueLibName: string, shimComponentOptions: boolean): {
}, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, getHtmlGen: () => ReturnType<typeof templateGen['generate']> | undefined, getStyleBindTexts: () => string[], vueLibName: string, shimComponentOptions: boolean, downgradePropsAndEmitsToSetupReturnOnScriptSetup: boolean): {
codeGen: CodeGen<EmbeddedFileMappingData>;

@@ -15,0 +15,0 @@ teleports: SourceMaps.Mapping<TeleportMappingData>[];

@@ -8,3 +8,3 @@ "use strict";

const path = require("path");
function generate(lsType, fileName, script, scriptSetup, scriptRanges, scriptSetupRanges, getHtmlGen, getStyleBindTexts, vueLibName, shimComponentOptions) {
function generate(lsType, fileName, script, scriptSetup, scriptRanges, scriptSetupRanges, getHtmlGen, getStyleBindTexts, vueLibName, shimComponentOptions, downgradePropsAndEmitsToSetupReturnOnScriptSetup) {
const codeGen = new code_gen_1.CodeGen();

@@ -204,3 +204,3 @@ const teleports = [];

});
if (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg) {
if (scriptSetupRanges.propsTypeArg && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg)) {
// fix https://github.com/johnsoncodehk/volar/issues/1187

@@ -220,35 +220,37 @@ codeGen.addText(`const __VLS_withDefaultsArg = (<T>(t: T) => t)(`);

if (scriptSetup && scriptSetupRanges) {
if (scriptSetupRanges.propsRuntimeArg || scriptSetupRanges.propsTypeArg) {
codeGen.addText(`props: (`);
if (scriptSetupRanges.propsTypeArg) {
usedTypes.DefinePropsToOptions = true;
codeGen.addText(`{} as `);
if (scriptSetupRanges.withDefaultsArg) {
usedTypes.mergePropDefaults = true;
codeGen.addText(`__VLS_WithDefaults<`);
}
codeGen.addText(`__VLS_TypePropsToRuntimeProps<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
codeGen.addText(`>`);
if (scriptSetupRanges.withDefaultsArg) {
codeGen.addText(`, typeof __VLS_withDefaultsArg`);
if (!downgradePropsAndEmitsToSetupReturnOnScriptSetup) {
if (scriptSetupRanges.propsRuntimeArg || scriptSetupRanges.propsTypeArg) {
codeGen.addText(`props: (`);
if (scriptSetupRanges.propsTypeArg) {
usedTypes.DefinePropsToOptions = true;
codeGen.addText(`{} as `);
if (scriptSetupRanges.withDefaultsArg) {
usedTypes.mergePropDefaults = true;
codeGen.addText(`__VLS_WithDefaults<`);
}
codeGen.addText(`__VLS_TypePropsToRuntimeProps<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
codeGen.addText(`>`);
if (scriptSetupRanges.withDefaultsArg) {
codeGen.addText(`, typeof __VLS_withDefaultsArg`);
codeGen.addText(`>`);
}
}
else if (scriptSetupRanges.propsRuntimeArg) {
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
}
codeGen.addText(`),\n`);
}
else if (scriptSetupRanges.propsRuntimeArg) {
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
if (scriptSetupRanges.emitsTypeArg) {
usedTypes.ConstructorOverloads = true;
codeGen.addText(`emits: ({} as __VLS_UnionToIntersection<__VLS_ConstructorOverloads<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end);
codeGen.addText(`>>),\n`);
}
codeGen.addText(`),\n`);
else if (scriptSetupRanges.emitsRuntimeArg) {
codeGen.addText(`emits: (`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsRuntimeArg.start, scriptSetupRanges.emitsRuntimeArg.end);
codeGen.addText(`),\n`);
}
}
if (scriptSetupRanges.emitsTypeArg) {
usedTypes.ConstructorOverloads = true;
codeGen.addText(`emits: ({} as __VLS_UnionToIntersection<__VLS_ConstructorOverloads<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end);
codeGen.addText(`>>),\n`);
}
else if (scriptSetupRanges.emitsRuntimeArg) {
codeGen.addText(`emits: (`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsRuntimeArg.start, scriptSetupRanges.emitsRuntimeArg.end);
codeGen.addText(`),\n`);
}
const bindingsArr = [];

@@ -278,19 +280,65 @@ if (scriptSetupRanges) {

codeGen.addText(`};\n`);
if (scriptSetupRanges.exposeTypeArg) {
codeGen.addText(`return { } as `);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.exposeTypeArg.start, scriptSetupRanges.exposeTypeArg.end);
codeGen.addText(`;\n`);
}
codeGen.addText(`return {\n`);
if (downgradePropsAndEmitsToSetupReturnOnScriptSetup) {
// fill $props
if (scriptSetupRanges.propsTypeArg) {
// NOTE: defineProps is inaccurate for $props
codeGen.addText(`$props: defineProps<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
codeGen.addText(`>(),\n`);
}
else if (scriptSetupRanges.exposeRuntimeArg) {
codeGen.addText(`return `);
else if (scriptSetupRanges.propsRuntimeArg) {
// NOTE: defineProps is inaccurate for $props
codeGen.addText(`$props: defineProps(`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
codeGen.addText(`),\n`);
}
// fill $emit
if (scriptSetupRanges.emitsAssignName) {
codeGen.addText(`$emit: ${scriptSetupRanges.emitsAssignName},\n`);
}
else if (scriptSetupRanges.emitsTypeArg) {
codeGen.addText(`$emit: defineEmits<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end);
codeGen.addText(`>(),\n`);
}
else if (scriptSetupRanges.emitsRuntimeArg) {
codeGen.addText(`$emit: defineEmits(`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsRuntimeArg.start, scriptSetupRanges.emitsRuntimeArg.end);
codeGen.addText(`),\n`);
}
}
if (lsType === 'script') {
if (scriptSetupRanges.exposeRuntimeArg) {
codeGen.addText(`...(`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.exposeRuntimeArg.start, scriptSetupRanges.exposeRuntimeArg.end);
codeGen.addText(`;\n`);
codeGen.addText(`),\n`);
}
else {
codeGen.addText(`return { };\n`);
if (scriptSetupRanges.exposeTypeArg) {
codeGen.addText(`...({} as `);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.exposeTypeArg.start, scriptSetupRanges.exposeTypeArg.end);
codeGen.addText(`),\n`);
}
;
}
if (lsType === 'template') {
codeGen.addText(`return {\n`);
// fill ctx from props
if (downgradePropsAndEmitsToSetupReturnOnScriptSetup) {
if (scriptSetupRanges.propsAssignName) {
codeGen.addText(`...${scriptSetupRanges.propsAssignName},\n`);
}
else if (scriptSetupRanges.withDefaultsArg && scriptSetupRanges.propsTypeArg) {
codeGen.addText(`...withDefaults(defineProps<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
codeGen.addText(`>(), `);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.withDefaultsArg.start, scriptSetupRanges.withDefaultsArg.end);
codeGen.addText(`),\n`);
}
else if (scriptSetupRanges.propsRuntimeArg) {
codeGen.addText(`...defineProps(`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
codeGen.addText(`),\n`);
}
}
// bindings
for (const { bindings, content } of bindingsArr) {

@@ -326,4 +374,4 @@ for (const expose of bindings) {

}
codeGen.addText(`};\n`);
}
codeGen.addText(`};\n`);
codeGen.addText(`},\n`);

@@ -330,0 +378,0 @@ }

@@ -9,3 +9,3 @@ import * as CompilerDOM from '@vue/compiler-dom';

*/
export declare function generateSFCScriptTypeCheckCode(ts: typeof import('typescript/lib/tsserverlibrary'), scriptLang: 'js' | 'jsx' | 'ts' | 'tsx', scriptCode: string | undefined, scriptSetupCode: string | undefined, shimComponentOptions: boolean, templateAst?: CompilerDOM.RootNode, cssVars?: string[], vueLibName?: string): {
export declare function generateSFCScriptTypeCheckCode(ts: typeof import('typescript/lib/tsserverlibrary'), scriptLang: 'js' | 'jsx' | 'ts' | 'tsx', scriptCode: string | undefined, scriptSetupCode: string | undefined, shimComponentOptions: boolean, downgradePropsAndEmitsToSetupReturnOnScriptSetup: boolean, templateAst?: CompilerDOM.RootNode, cssVars?: string[], vueLibName?: string): {
code: string;

@@ -12,0 +12,0 @@ scriptMappings: {

@@ -30,6 +30,6 @@ "use strict";

*/
function generateSFCScriptTypeCheckCode(ts, scriptLang, scriptCode, scriptSetupCode, shimComponentOptions, templateAst, cssVars, vueLibName = 'vue') {
function generateSFCScriptTypeCheckCode(ts, scriptLang, scriptCode, scriptSetupCode, shimComponentOptions, downgradePropsAndEmitsToSetupReturnOnScriptSetup, templateAst, cssVars, vueLibName = 'vue') {
const generated = (0, script_1.generate)('script', '', scriptCode !== undefined ? { content: scriptCode } : undefined, scriptSetupCode !== undefined ? { content: scriptSetupCode } : undefined, scriptCode !== undefined ? (0, scriptRanges_1.parseScriptRanges)(ts, ts.createSourceFile('dummy.' + scriptLang, scriptCode, ts.ScriptTarget.ESNext), scriptSetupCode !== undefined, false, false) : undefined, scriptSetupCode !== undefined ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, ts.createSourceFile('dummy.' + scriptLang, scriptSetupCode, ts.ScriptTarget.ESNext)) : undefined, () => undefined, // TODO
// () => templateAst ? generateTemplateScript(templateAst) : undefined,
() => cssVars !== null && cssVars !== void 0 ? cssVars : [], vueLibName, shimComponentOptions);
() => cssVars !== null && cssVars !== void 0 ? cssVars : [], vueLibName, shimComponentOptions, downgradePropsAndEmitsToSetupReturnOnScriptSetup);
return {

@@ -36,0 +36,0 @@ code: generated.codeGen.getText(),

@@ -11,4 +11,6 @@ import type * as ts from 'typescript/lib/tsserverlibrary';

withDefaultsArg: TextRange | undefined;
propsAssignName: string | undefined;
propsRuntimeArg: TextRange | undefined;
propsTypeArg: TextRange | undefined;
emitsAssignName: string | undefined;
emitsRuntimeArg: TextRange | undefined;

@@ -15,0 +17,0 @@ emitsTypeArg: TextRange | undefined;

@@ -9,4 +9,6 @@ "use strict";

let withDefaultsArg;
let propsAssignName;
let propsRuntimeArg;
let propsTypeArg;
let emitsAssignName;
let emitsRuntimeArg;

@@ -35,3 +37,3 @@ let emitsTypeArg;

});
ast.forEachChild(visitNode);
ast.forEachChild(child => visitNode(child, ast));
return {

@@ -43,4 +45,6 @@ importSectionEndOffset,

withDefaultsArg,
propsAssignName,
propsRuntimeArg,
propsTypeArg,
emitsAssignName,
emitsRuntimeArg,

@@ -55,3 +59,3 @@ emitsTypeArg,

}
function visitNode(node) {
function visitNode(node, parent) {
var _a;

@@ -66,5 +70,11 @@ if (ts.isCallExpression(node)

propsRuntimeArg = _getStartEnd(runtimeArg);
if (ts.isVariableDeclaration(parent)) {
propsAssignName = parent.name.getText(ast);
}
}
else if (callText === 'defineEmits') {
emitsRuntimeArg = _getStartEnd(runtimeArg);
if (ts.isVariableDeclaration(parent)) {
emitsAssignName = parent.name.getText(ast);
}
}

@@ -79,2 +89,5 @@ else if (callText === 'defineExpose') {

propsTypeArg = _getStartEnd(typeArg);
if (ts.isVariableDeclaration(parent)) {
propsAssignName = parent.name.getText(ast);
}
}

@@ -86,2 +99,5 @@ else if (callText === 'defineEmits') {

}
if (ts.isVariableDeclaration(parent)) {
emitsAssignName = parent.name.getText(ast);
}
}

@@ -98,5 +114,8 @@ else if (callText === 'defineExpose') {

}
if (ts.isVariableDeclaration(parent)) {
propsAssignName = parent.name.getText(ast);
}
}
}
node.forEachChild(child => visitNode(child));
node.forEachChild(child => visitNode(child, node));
}

@@ -103,0 +122,0 @@ }

{
"name": "@volar/vue-code-gen",
"version": "0.34.13",
"version": "0.34.15",
"main": "out/index.js",

@@ -19,4 +19,4 @@ "license": "MIT",

"dependencies": {
"@volar/code-gen": "0.34.13",
"@volar/source-map": "0.34.13",
"@volar/code-gen": "0.34.15",
"@volar/source-map": "0.34.15",
"@vue/compiler-core": "^3.2.31",

@@ -26,3 +26,3 @@ "@vue/compiler-dom": "^3.2.31",

},
"gitHead": "9fea59dea83915be69b79b34537be47734bce0c0"
"gitHead": "5b2db858bb30dcff1b659eaa08d9ad965e6255a4"
}

Sorry, the diff of this file is too big to display

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