@vue/language-core 2.0.17 → 2.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/script/globalTypes.js +7 -11
- package/lib/codegen/script/scriptSetup.js +0 -4
- package/lib/codegen/template/element.js +1 -2
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +38 -36
- package/lib/codegen/template/elementProps.js +51 -62
- package/lib/codegen/template/vFor.js +13 -3
- package/lib/plugins/file-md.js +1 -0
- package/lib/plugins/vue-script-js.d.ts +3 -0
- package/lib/plugins/vue-script-js.js +15 -0
- package/lib/plugins/vue-template-html.js +1 -1
- package/lib/plugins.d.ts +1 -0
- package/lib/plugins.js +2 -0
- package/lib/types.d.ts +1 -0
- package/lib/virtualFile/computedSfc.js +20 -2
- package/package.json +3 -3
|
@@ -7,16 +7,20 @@ function generateGlobalTypes(vueCompilerOptions) {
|
|
|
7
7
|
return `export const __VLS_globalTypesStart = {};
|
|
8
8
|
declare global {
|
|
9
9
|
// @ts-ignore
|
|
10
|
-
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('
|
|
10
|
+
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('${vueCompilerOptions.lib}/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
|
|
11
11
|
// @ts-ignore
|
|
12
|
-
type __VLS_Element = __VLS_PickNotAny<import('
|
|
12
|
+
type __VLS_Element = __VLS_PickNotAny<import('${vueCompilerOptions.lib}/jsx-runtime').JSX.Element, globalThis.JSX.Element>;
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
type __VLS_GlobalComponents = ${[
|
|
15
|
-
`__VLS_PickNotAny<import('
|
|
15
|
+
`__VLS_PickNotAny<import('${vueCompilerOptions.lib}').GlobalComponents, {}>`,
|
|
16
16
|
`__VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>`,
|
|
17
17
|
`__VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>`,
|
|
18
18
|
`Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`
|
|
19
19
|
].join(' & ')};
|
|
20
|
+
type __VLS_BuiltInPublicProps =
|
|
21
|
+
__VLS_PickNotAny<import('${vueCompilerOptions.lib}').VNodeProps, {}>
|
|
22
|
+
& __VLS_PickNotAny<import('${vueCompilerOptions.lib}').AllowedComponentProps, {}>
|
|
23
|
+
& __VLS_PickNotAny<import('${vueCompilerOptions.lib}').ComponentCustomProps, {}>;
|
|
20
24
|
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
21
25
|
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
22
26
|
|
|
@@ -67,8 +71,6 @@ declare global {
|
|
|
67
71
|
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
68
72
|
${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
|
|
69
73
|
|
|
70
|
-
type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
|
|
71
|
-
type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
|
|
72
74
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
73
75
|
T extends new (...args: any) => any
|
|
74
76
|
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
|
|
@@ -81,12 +83,6 @@ declare global {
|
|
|
81
83
|
: (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
82
84
|
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
|
|
83
85
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
|
|
84
|
-
function __VLS_pickEvent<E1, E2>(emitEvent: E1, propEvent: E2): __VLS_FillingEventArg<
|
|
85
|
-
__VLS_PickNotAny<
|
|
86
|
-
__VLS_AsFunctionOrAny<E2>,
|
|
87
|
-
__VLS_AsFunctionOrAny<E1>
|
|
88
|
-
>
|
|
89
|
-
> | undefined;
|
|
90
86
|
function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): __VLS_PickNotAny<
|
|
91
87
|
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
92
88
|
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
@@ -255,10 +255,6 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
255
255
|
yield `let __VLS_functionalComponentProps!: `;
|
|
256
256
|
yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
|
257
257
|
yield common_1.endOfLine;
|
|
258
|
-
yield `type __VLS_BuiltInPublicProps =${common_1.newLine}`
|
|
259
|
-
+ ` import('${options.vueCompilerOptions.lib}').VNodeProps${common_1.newLine}`
|
|
260
|
-
+ ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps${common_1.newLine}`
|
|
261
|
-
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps${common_1.endOfLine}`;
|
|
262
258
|
if (scriptSetupRanges.defineProp.length) {
|
|
263
259
|
yield `const __VLS_defaults = {${common_1.newLine}`;
|
|
264
260
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
@@ -32,7 +32,6 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
32
32
|
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
33
33
|
let props = node.props;
|
|
34
34
|
let dynamicTagInfo;
|
|
35
|
-
let usedComponentEventsVar = false;
|
|
36
35
|
if (isComponentTag) {
|
|
37
36
|
for (const prop of node.props) {
|
|
38
37
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.arg?.loc.source === 'is' && prop.exp) {
|
|
@@ -163,7 +162,7 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
163
162
|
}
|
|
164
163
|
yield* generateVScope(options, ctx, node, props);
|
|
165
164
|
ctx.usedComponentCtxVars.add(componentCtxVar);
|
|
166
|
-
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEmit, var_componentEvents
|
|
165
|
+
const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEmit, var_componentEvents);
|
|
167
166
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
168
167
|
if (slotDir) {
|
|
169
168
|
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
|
|
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
import type { Code } from '../../types';
|
|
4
4
|
import type { TemplateCodegenContext } from './context';
|
|
5
5
|
import type { TemplateCodegenOptions } from './index';
|
|
6
|
-
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, emitVar: string, eventsVar: string
|
|
7
|
-
export declare function generateEventArg(
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, emitVar: string, eventsVar: string): Generator<Code>;
|
|
7
|
+
export declare function generateEventArg(ctx: TemplateCodegenContext, arg: CompilerDOM.SimpleExpressionNode, enableHover: boolean): Generator<Code>;
|
|
8
8
|
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
9
|
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
@@ -7,33 +7,48 @@ const shared_2 = require("../../utils/shared");
|
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const camelized_1 = require("./camelized");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
function* generateElementEvents(options, ctx, node, componentVar, componentInstanceVar, emitVar, eventsVar) {
|
|
11
|
+
let usedComponentEventsVar = false;
|
|
12
|
+
let propsVar;
|
|
12
13
|
for (const prop of node.props) {
|
|
13
14
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
14
15
|
&& prop.name === 'on'
|
|
15
|
-
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
yield `
|
|
16
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
17
|
+
&& !prop.arg.loc.source.startsWith('[')
|
|
18
|
+
&& !prop.arg.loc.source.endsWith(']')) {
|
|
19
|
+
usedComponentEventsVar = true;
|
|
20
|
+
if (!propsVar) {
|
|
21
|
+
propsVar = ctx.getInternalVariable();
|
|
22
|
+
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>${common_1.endOfLine}`;
|
|
23
|
+
}
|
|
24
|
+
const originalPropName = (0, shared_1.camelize)('on-' + prop.arg.loc.source);
|
|
25
|
+
const originalPropNameObjectKey = common_1.variableNameRegex.test(originalPropName)
|
|
26
|
+
? originalPropName
|
|
27
|
+
: `'${originalPropName}'`;
|
|
28
|
+
yield `const ${ctx.getInternalVariable()}: `;
|
|
29
|
+
if (!options.vueCompilerOptions.strictTemplates) {
|
|
30
|
+
yield `Record<string, unknown> & `;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
yield `(`;
|
|
33
|
+
yield `__VLS_IsAny<__VLS_AsFunctionOrAny<typeof ${propsVar}['${originalPropName}']>> extends false${common_1.newLine}`;
|
|
34
|
+
yield `? typeof ${propsVar}${common_1.newLine}`;
|
|
35
|
+
yield `: __VLS_IsAny<typeof ${eventsVar}['${prop.arg.loc.source}']> extends false${common_1.newLine}`;
|
|
36
|
+
yield `? {${common_1.newLine}`;
|
|
37
|
+
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${common_1.newLine}`;
|
|
38
|
+
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${prop.arg.loc.source}']${common_1.newLine}`;
|
|
39
|
+
yield `}${common_1.newLine}`;
|
|
40
|
+
if (prop.arg.loc.source !== (0, shared_1.camelize)(prop.arg.loc.source)) {
|
|
41
|
+
yield `: __VLS_IsAny<typeof ${eventsVar}['${(0, shared_1.camelize)(prop.arg.loc.source)}']> extends false${common_1.newLine}`;
|
|
42
|
+
yield `? {${common_1.newLine}`;
|
|
43
|
+
yield `/**__VLS_emit,${emitVar},${(0, shared_1.camelize)(prop.arg.loc.source)}*/${common_1.newLine}`;
|
|
44
|
+
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${(0, shared_1.camelize)(prop.arg.loc.source)}']${common_1.newLine}`;
|
|
45
|
+
yield `}${common_1.newLine}`;
|
|
33
46
|
}
|
|
47
|
+
yield `: typeof ${propsVar}${common_1.newLine}`;
|
|
48
|
+
yield `) = {${common_1.newLine}`;
|
|
49
|
+
yield* generateEventArg(ctx, prop.arg, true);
|
|
34
50
|
yield `: `;
|
|
35
51
|
yield* generateEventExpression(options, ctx, prop);
|
|
36
|
-
yield common_1.newLine;
|
|
37
52
|
yield `}${common_1.endOfLine}`;
|
|
38
53
|
}
|
|
39
54
|
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -45,6 +60,7 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
|
|
|
45
60
|
yield common_1.endOfLine;
|
|
46
61
|
}
|
|
47
62
|
}
|
|
63
|
+
return usedComponentEventsVar;
|
|
48
64
|
}
|
|
49
65
|
exports.generateElementEvents = generateElementEvents;
|
|
50
66
|
const eventArgFeatures = {
|
|
@@ -63,34 +79,20 @@ const eventArgFeatures = {
|
|
|
63
79
|
},
|
|
64
80
|
},
|
|
65
81
|
};
|
|
66
|
-
function* generateEventArg(
|
|
82
|
+
function* generateEventArg(ctx, arg, enableHover) {
|
|
67
83
|
const features = enableHover
|
|
68
84
|
? {
|
|
69
85
|
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
70
86
|
...eventArgFeatures,
|
|
71
87
|
}
|
|
72
88
|
: eventArgFeatures;
|
|
73
|
-
if (
|
|
74
|
-
yield `[`;
|
|
75
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, arg.loc.source.slice(1, -1), arg.loc, arg.loc.start.offset + 1, ctx.codeFeatures.all, '', '');
|
|
76
|
-
yield `]`;
|
|
77
|
-
}
|
|
78
|
-
else if (common_1.variableNameRegex.test((0, shared_1.camelize)(arg.loc.source))) {
|
|
79
|
-
if (access) {
|
|
80
|
-
yield `.`;
|
|
81
|
-
}
|
|
89
|
+
if (common_1.variableNameRegex.test((0, shared_1.camelize)(arg.loc.source))) {
|
|
82
90
|
yield ['', 'template', arg.loc.start.offset, features];
|
|
83
91
|
yield `on`;
|
|
84
92
|
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping);
|
|
85
93
|
}
|
|
86
94
|
else {
|
|
87
|
-
if (access) {
|
|
88
|
-
yield `[`;
|
|
89
|
-
}
|
|
90
95
|
yield* (0, common_1.wrapWith)(arg.loc.start.offset, arg.loc.end.offset, features, `'`, ['', 'template', arg.loc.start.offset, common_1.combineLastMapping], 'on', ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping), `'`);
|
|
91
|
-
if (access) {
|
|
92
|
-
yield `]`;
|
|
93
|
-
}
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
exports.generateEventArg = generateEventArg;
|
|
@@ -12,86 +12,71 @@ const objectProperty_1 = require("./objectProperty");
|
|
|
12
12
|
const language_core_1 = require("@volar/language-core");
|
|
13
13
|
const elementEvents_1 = require("./elementEvents");
|
|
14
14
|
function* generateElementProps(options, ctx, node, props, enableCodeFeatures, propsFailedExps) {
|
|
15
|
-
let styleAttrNum = 0;
|
|
16
|
-
let classAttrNum = 0;
|
|
17
15
|
const isIntrinsicElement = node.tagType === CompilerDOM.ElementTypes.ELEMENT || node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
|
|
18
16
|
const canCamelize = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const prop of props) {
|
|
29
|
-
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
30
|
-
&& prop.name === 'on') {
|
|
31
|
-
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
32
|
-
yield* (0, elementEvents_1.generateEventArg)(options, ctx, prop.arg, false, true);
|
|
17
|
+
for (const prop of props) {
|
|
18
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
19
|
+
&& prop.name === 'on') {
|
|
20
|
+
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
21
|
+
&& !prop.arg.loc.source.startsWith('[')
|
|
22
|
+
&& !prop.arg.loc.source.endsWith(']')) {
|
|
23
|
+
if (isIntrinsicElement) {
|
|
24
|
+
yield `...{ `;
|
|
25
|
+
yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg, true);
|
|
33
26
|
yield `: `;
|
|
34
27
|
yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
|
|
35
|
-
yield
|
|
28
|
+
yield `}, `;
|
|
36
29
|
}
|
|
37
|
-
else
|
|
38
|
-
|
|
30
|
+
else {
|
|
31
|
+
yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any }, `;
|
|
39
32
|
}
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
47
|
-
&& prop.name === 'on'
|
|
48
|
-
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
49
|
-
if (prop.arg.loc.source.startsWith('[') && prop.arg.loc.source.endsWith(']')) {
|
|
50
|
-
continue;
|
|
34
|
+
else {
|
|
35
|
+
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
36
|
+
&& prop.arg.loc.source.startsWith('[')
|
|
37
|
+
&& prop.arg.loc.source.endsWith(']')) {
|
|
38
|
+
propsFailedExps?.push(prop.arg);
|
|
51
39
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
generatedEvent = true;
|
|
40
|
+
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
41
|
+
propsFailedExps?.push(prop.exp);
|
|
55
42
|
}
|
|
56
|
-
yield `'${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any, `;
|
|
57
43
|
}
|
|
58
44
|
}
|
|
59
|
-
if (generatedEvent) {
|
|
60
|
-
yield `}, `;
|
|
61
|
-
}
|
|
62
45
|
}
|
|
63
46
|
for (const prop of props) {
|
|
64
47
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
65
48
|
&& (prop.name === 'bind' || prop.name === 'model')
|
|
66
49
|
&& (prop.name === 'model' || prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)
|
|
67
50
|
&& (!prop.exp || prop.exp.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)) {
|
|
68
|
-
let propName
|
|
69
|
-
|
|
51
|
+
let propName;
|
|
52
|
+
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
53
|
+
propName = prop.arg.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY
|
|
70
54
|
? prop.arg.content
|
|
71
|
-
: prop.arg.loc.source
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
propName =
|
|
55
|
+
: prop.arg.loc.source;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
propName = getModelValuePropName(node, options.vueCompilerOptions.target, options.vueCompilerOptions);
|
|
75
59
|
}
|
|
76
60
|
if (propName === undefined
|
|
77
|
-
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))
|
|
78
|
-
|| (propName === 'style' && ++styleAttrNum >= 2)
|
|
79
|
-
|| (propName === 'class' && ++classAttrNum >= 2)
|
|
80
|
-
|| (propName === 'name' && node.tagType === CompilerDOM.ElementTypes.SLOT) // #2308
|
|
81
|
-
) {
|
|
61
|
+
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
|
|
82
62
|
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
83
63
|
propsFailedExps?.push(prop.exp);
|
|
84
64
|
}
|
|
85
65
|
continue;
|
|
86
66
|
}
|
|
67
|
+
if (prop.modifiers.some(m => m === 'prop' || m === 'attr')) {
|
|
68
|
+
propName = propName.substring(1);
|
|
69
|
+
}
|
|
70
|
+
const shouldSpread = propName === 'style' || propName === 'class';
|
|
87
71
|
const shouldCamelize = canCamelize
|
|
88
72
|
&& (!prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)) // isStatic
|
|
89
73
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
90
74
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
75
|
+
if (shouldSpread) {
|
|
76
|
+
yield `...{ `;
|
|
77
|
+
}
|
|
78
|
+
const codes = (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
79
|
+
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, {
|
|
95
80
|
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
96
81
|
navigation: ctx.codeFeatures.withoutHighlightAndCompletion.navigation
|
|
97
82
|
? {
|
|
@@ -99,33 +84,34 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
99
84
|
resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
|
|
100
85
|
}
|
|
101
86
|
: false,
|
|
102
|
-
}
|
|
103
|
-
:
|
|
87
|
+
}, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize)
|
|
88
|
+
: [propName]), `: (`, ...genereatePropExp(options, ctx, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
|
|
104
89
|
if (!enableCodeFeatures) {
|
|
105
90
|
yield (0, language_core_1.toString)([...codes]);
|
|
106
91
|
}
|
|
107
92
|
else {
|
|
108
93
|
yield* codes;
|
|
109
94
|
}
|
|
95
|
+
if (shouldSpread) {
|
|
96
|
+
yield ` }`;
|
|
97
|
+
}
|
|
110
98
|
yield `, `;
|
|
111
99
|
}
|
|
112
100
|
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
113
101
|
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
|
|
114
|
-
|| (prop.name === 'style' && ++styleAttrNum >= 2)
|
|
115
|
-
|| (prop.name === 'class' && ++classAttrNum >= 2)
|
|
116
|
-
|| (prop.name === 'name' && node.tagType === CompilerDOM.ElementTypes.SLOT) // #2308
|
|
117
|
-
) {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (options.vueCompilerOptions.target < 3
|
|
121
|
-
&& prop.name === 'persisted'
|
|
122
|
-
&& node.tag.toLowerCase() === 'transition') {
|
|
123
102
|
// Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom always adds it (#3881)
|
|
103
|
+
|| (options.vueCompilerOptions.target < 3
|
|
104
|
+
&& prop.name === 'persisted'
|
|
105
|
+
&& node.tag.toLowerCase() === 'transition')) {
|
|
124
106
|
continue;
|
|
125
107
|
}
|
|
108
|
+
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
126
109
|
const shouldCamelize = canCamelize
|
|
127
110
|
&& (0, shared_2.hyphenateAttr)(prop.name) === prop.name
|
|
128
111
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern));
|
|
112
|
+
if (shouldSpread) {
|
|
113
|
+
yield `...{ `;
|
|
114
|
+
}
|
|
129
115
|
const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, shouldCamelize
|
|
130
116
|
? {
|
|
131
117
|
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
@@ -145,6 +131,9 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
145
131
|
else {
|
|
146
132
|
yield* codes;
|
|
147
133
|
}
|
|
134
|
+
if (shouldSpread) {
|
|
135
|
+
yield ` }`;
|
|
136
|
+
}
|
|
148
137
|
yield `, `;
|
|
149
138
|
}
|
|
150
139
|
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -31,12 +31,22 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
31
31
|
yield `{} as any`;
|
|
32
32
|
}
|
|
33
33
|
yield `) {${common_1.newLine}`;
|
|
34
|
-
if ((0, index_1.isFragment)(node)) {
|
|
35
|
-
yield* ctx.resetDirectiveComments('end of v-for start');
|
|
36
|
-
}
|
|
37
34
|
for (const varName of forBlockVars) {
|
|
38
35
|
ctx.addLocalVariable(varName);
|
|
39
36
|
}
|
|
37
|
+
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
38
|
+
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
39
|
+
&& argument.returns.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
40
|
+
&& argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
|
41
|
+
for (const prop of argument.returns.props.properties) {
|
|
42
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.loc.source, prop.value.loc, prop.value.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
43
|
+
yield common_1.endOfLine;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if ((0, index_1.isFragment)(node)) {
|
|
48
|
+
yield* ctx.resetDirectiveComments('end of v-for start');
|
|
49
|
+
}
|
|
40
50
|
let prev;
|
|
41
51
|
for (const childNode of node.children) {
|
|
42
52
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -42,6 +42,7 @@ const plugin = () => {
|
|
|
42
42
|
const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
|
|
43
43
|
const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
|
|
44
44
|
if (sfc.descriptor.template) {
|
|
45
|
+
sfc.descriptor.template.lang = 'md';
|
|
45
46
|
transformRange(sfc.descriptor.template);
|
|
46
47
|
}
|
|
47
48
|
if (sfc.descriptor.script) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const plugin = ({ modules }) => {
|
|
4
|
+
return {
|
|
5
|
+
version: 2,
|
|
6
|
+
compileSFCScript(lang, script) {
|
|
7
|
+
if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
|
|
8
|
+
const ts = modules.typescript;
|
|
9
|
+
return ts.createSourceFile('test.' + lang, script, 99);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.default = plugin;
|
|
15
|
+
//# sourceMappingURL=vue-script-js.js.map
|
|
@@ -4,7 +4,7 @@ const plugin = ({ modules }) => {
|
|
|
4
4
|
return {
|
|
5
5
|
version: 2,
|
|
6
6
|
compileSFCTemplate(lang, template, options) {
|
|
7
|
-
if (lang === 'html') {
|
|
7
|
+
if (lang === 'html' || lang === 'md') {
|
|
8
8
|
const compiler = modules['@vue/compiler-dom'];
|
|
9
9
|
return compiler.compile(template, {
|
|
10
10
|
...options,
|
package/lib/plugins.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlug
|
|
|
12
12
|
newText: string;
|
|
13
13
|
}): import("@vue/compiler-sfc").SFCParseResult | undefined;
|
|
14
14
|
resolveTemplateCompilerOptions?(options: import("@vue/compiler-dom").CompilerOptions): import("@vue/compiler-dom").CompilerOptions;
|
|
15
|
+
compileSFCScript?(lang: string, script: string): import("typescript").SourceFile | undefined;
|
|
15
16
|
compileSFCTemplate?(lang: string, template: string, options: import("@vue/compiler-dom").CompilerOptions): import("@vue/compiler-dom").CodegenResult | undefined;
|
|
16
17
|
updateSFCTemplate?(oldResult: import("@vue/compiler-dom").CodegenResult, textChange: {
|
|
17
18
|
start: number;
|
package/lib/plugins.js
CHANGED
|
@@ -19,6 +19,7 @@ const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
|
|
|
19
19
|
const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
|
|
20
20
|
const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
|
|
21
21
|
const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
|
|
22
|
+
const vue_script_js_1 = require("./plugins/vue-script-js");
|
|
22
23
|
const vue_template_html_1 = require("./plugins/vue-template-html");
|
|
23
24
|
const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
|
|
24
25
|
const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
|
|
@@ -27,6 +28,7 @@ const types_1 = require("./types");
|
|
|
27
28
|
__exportStar(require("./plugins/shared"), exports);
|
|
28
29
|
function getBasePlugins(pluginContext) {
|
|
29
30
|
const plugins = [
|
|
31
|
+
vue_script_js_1.default,
|
|
30
32
|
vue_template_html_1.default,
|
|
31
33
|
vue_template_inline_css_1.default,
|
|
32
34
|
vue_template_inline_ts_1.default,
|
package/lib/types.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export type VueLanguagePlugin = (ctx: {
|
|
|
68
68
|
newText: string;
|
|
69
69
|
}): SFCParseResult | undefined;
|
|
70
70
|
resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
|
|
71
|
+
compileSFCScript?(lang: string, script: string): ts.SourceFile | undefined;
|
|
71
72
|
compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
|
|
72
73
|
updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
|
|
73
74
|
start: number;
|
|
@@ -25,7 +25,16 @@ function computedSfc(ts, plugins, fileName, snapshot, parsed) {
|
|
|
25
25
|
const _src = src();
|
|
26
26
|
return _src ? untrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_src) - base.startTagEnd : -1;
|
|
27
27
|
});
|
|
28
|
-
const ast = (0, computeds_1.computed)(() =>
|
|
28
|
+
const ast = (0, computeds_1.computed)(() => {
|
|
29
|
+
for (const plugin of plugins) {
|
|
30
|
+
const ast = plugin.compileSFCScript?.(base.lang, base.content);
|
|
31
|
+
if (ast) {
|
|
32
|
+
return ast;
|
|
33
|
+
;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
|
|
37
|
+
});
|
|
29
38
|
return mergeObject(base, {
|
|
30
39
|
get src() { return src(); },
|
|
31
40
|
get srcOffset() { return srcOffset(); },
|
|
@@ -41,7 +50,16 @@ function computedSfc(ts, plugins, fileName, snapshot, parsed) {
|
|
|
41
50
|
const _generic = generic();
|
|
42
51
|
return _generic !== undefined ? untrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_generic) - base.startTagEnd : -1;
|
|
43
52
|
});
|
|
44
|
-
const ast = (0, computeds_1.computed)(() =>
|
|
53
|
+
const ast = (0, computeds_1.computed)(() => {
|
|
54
|
+
for (const plugin of plugins) {
|
|
55
|
+
const ast = plugin.compileSFCScript?.(base.lang, base.content);
|
|
56
|
+
if (ast) {
|
|
57
|
+
return ast;
|
|
58
|
+
;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
|
|
62
|
+
});
|
|
45
63
|
return mergeObject(base, {
|
|
46
64
|
get generic() { return generic(); },
|
|
47
65
|
get genericOffset() { return genericOffset(); },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/language-core"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "~2.2.
|
|
15
|
+
"@volar/language-core": "~2.2.4",
|
|
16
16
|
"@vue/compiler-dom": "^3.4.0",
|
|
17
17
|
"@vue/shared": "^3.4.0",
|
|
18
18
|
"computeds": "^0.0.1",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "7aac2805f03b17e4c624335f509d502002bb75a8"
|
|
38
38
|
}
|