@vue/language-core 3.0.0-alpha.2 → 3.0.0-alpha.6
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/globalTypes.js +45 -26
- package/lib/codegen/localTypes.d.ts +2 -3
- package/lib/codegen/localTypes.js +4 -13
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +1 -1
- package/lib/codegen/script/index.d.ts +1 -1
- package/lib/codegen/script/src.js +4 -3
- package/lib/codegen/script/template.js +3 -5
- package/lib/codegen/template/context.d.ts +2 -1
- package/lib/codegen/template/element.js +9 -3
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementDirectives.js +2 -4
- package/lib/codegen/template/elementEvents.d.ts +3 -3
- package/lib/codegen/template/elementEvents.js +25 -17
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +6 -9
- package/lib/codegen/template/index.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +1 -1
- package/lib/codegen/template/vSlot.js +31 -1
- package/lib/codegen/utils/index.d.ts +2 -3
- package/lib/codegen/utils/index.js +0 -16
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/plugins/vue-style-css.d.ts +3 -0
- package/lib/plugins/vue-style-css.js +18 -0
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +5 -2
- package/lib/plugins/vue-tsx.d.ts +1 -0
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/utils/signals.d.ts +1 -0
- package/lib/utils/signals.js +11 -0
- package/lib/utils/ts.js +1 -0
- package/lib/virtualFile/computedSfc.js +2 -2
- package/package.json +4 -4
- package/lib/codegen/script/styleModulesType.d.ts +0 -4
- package/lib/codegen/script/styleModulesType.js +0 -34
- package/lib/codegen/utils/objectProperty.d.ts +0 -3
- package/lib/codegen/utils/objectProperty.js +0 -41
- package/lib/utils/forEachElementNode.d.ts +0 -1
- package/lib/utils/forEachElementNode.js +0 -3
|
@@ -13,7 +13,7 @@ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEv
|
|
|
13
13
|
].map(v => (typeof v === 'boolean' ? Number(v) : v)).join('_') + '.d.ts';
|
|
14
14
|
}
|
|
15
15
|
function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
16
|
-
const fnPropsType = `(
|
|
16
|
+
const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
|
|
17
17
|
let text = ``;
|
|
18
18
|
if (target < 3.5) {
|
|
19
19
|
text += `
|
|
@@ -51,10 +51,31 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
51
51
|
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
52
52
|
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
53
53
|
${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
|
|
55
|
+
? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
|
|
56
|
+
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
57
|
+
>;
|
|
58
|
+
type __VLS_FunctionalComponentProps<T, K> = '__ctx' extends keyof __VLS_PickNotAny<K, {}>
|
|
59
|
+
? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
60
|
+
: T extends (props: infer P, ...args: any) => any ? P
|
|
61
|
+
: {};
|
|
62
|
+
type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
63
|
+
__ctx?: {
|
|
64
|
+
attrs?: any,
|
|
65
|
+
slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>,
|
|
66
|
+
emit?: T extends { $emit: infer Emit } ? Emit : {},
|
|
67
|
+
props?: ${fnPropsType},
|
|
68
|
+
expose?: (exposed: T) => void,
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
type __VLS_NormalizeSlotReturns<S, R = NonNullable<S> extends (...args: any) => infer K ? K : any> = R extends any[] ? {
|
|
72
|
+
[K in keyof R]: R[K] extends infer V
|
|
73
|
+
? V extends Element ? V
|
|
74
|
+
: V extends new (...args: any) => infer R ? ReturnType<__VLS_FunctionalComponent<R>>
|
|
75
|
+
: V extends (...args: any) => infer R ? R
|
|
76
|
+
: any
|
|
77
|
+
: never
|
|
78
|
+
} : R;
|
|
58
79
|
type __VLS_IsFunction<T, K> = K extends keyof T
|
|
59
80
|
? __VLS_IsAny<T[K]> extends false
|
|
60
81
|
? unknown extends T[K]
|
|
@@ -62,13 +83,13 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
62
83
|
: true
|
|
63
84
|
: false
|
|
64
85
|
: false;
|
|
65
|
-
type __VLS_NormalizeComponentEvent<Props,
|
|
86
|
+
type __VLS_NormalizeComponentEvent<Props, Emits, onEvent extends keyof Props, Event extends keyof Emits, CamelizedEvent extends keyof Emits> = (
|
|
66
87
|
__VLS_IsFunction<Props, onEvent> extends true
|
|
67
88
|
? Props
|
|
68
|
-
: __VLS_IsFunction<
|
|
69
|
-
? { [K in onEvent]?:
|
|
70
|
-
: __VLS_IsFunction<
|
|
71
|
-
? { [K in onEvent]?:
|
|
89
|
+
: __VLS_IsFunction<Emits, Event> extends true
|
|
90
|
+
? { [K in onEvent]?: Emits[Event] }
|
|
91
|
+
: __VLS_IsFunction<Emits, CamelizedEvent> extends true
|
|
92
|
+
? { [K in onEvent]?: Emits[CamelizedEvent] }
|
|
72
93
|
: Props
|
|
73
94
|
)${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
|
|
74
95
|
// fix https://github.com/vuejs/language-tools/issues/926
|
|
@@ -94,11 +115,16 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
94
115
|
}
|
|
95
116
|
>
|
|
96
117
|
>;
|
|
118
|
+
type __VLS_ResolveEmits<
|
|
119
|
+
Comp,
|
|
120
|
+
Emits,
|
|
121
|
+
TypeEmits = ${target >= 3.6 ? `Comp extends { __typeEmits?: infer T } ? unknown extends T ? {} : import('${lib}').ShortEmitsToObject<T> : {}` : `{}`},
|
|
122
|
+
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
|
|
123
|
+
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
|
|
124
|
+
type __VLS_ResolveDirectives<T> = {
|
|
125
|
+
[K in Exclude<keyof T, keyof __VLS_GlobalDirectives> & string as \`v\${Capitalize<K>}\`]: T[K];
|
|
126
|
+
};
|
|
97
127
|
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
98
|
-
type __VLS_PickFunctionalComponentCtx<T, K> = NonNullable<__VLS_PickNotAny<
|
|
99
|
-
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
100
|
-
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
101
|
-
>>;
|
|
102
128
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
103
129
|
|
|
104
130
|
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
@@ -123,19 +149,12 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
123
149
|
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
|
|
124
150
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
125
151
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
126
|
-
T extends new (...args: any) => any
|
|
127
|
-
? (props:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any;
|
|
131
|
-
emit?: K extends { $emit: infer Emit } ? Emit : any;
|
|
132
|
-
expose?(exposed: K): void;
|
|
133
|
-
props?: ${fnPropsType};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
152
|
+
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
|
|
153
|
+
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${(target === 2.7
|
|
154
|
+
? `: T extends import('${lib}').AsyncComponent ? (props: {}, ctx?: any) => any`
|
|
155
|
+
: ``)}
|
|
137
156
|
: T extends (...args: any) => any ? T
|
|
138
|
-
:
|
|
157
|
+
: __VLS_FunctionalComponent<{}>;
|
|
139
158
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
140
159
|
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
141
160
|
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
export declare function getLocalTypesGenerator(compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): {
|
|
1
|
+
import type { VueCompilerOptions } from '../types';
|
|
2
|
+
export declare function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions): {
|
|
4
3
|
generate: (names: string[]) => Generator<string, void, unknown>;
|
|
5
4
|
getUsedNames(): Set<string>;
|
|
6
5
|
readonly PrettifyLocal: string;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
|
4
4
|
const shared_1 = require("../utils/shared");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
-
function getLocalTypesGenerator(
|
|
6
|
+
function getLocalTypesGenerator(vueCompilerOptions) {
|
|
7
7
|
const used = new Set();
|
|
8
8
|
const OmitKeepDiscriminatedUnion = defineHelper(`__VLS_OmitKeepDiscriminatedUnion`, () => `
|
|
9
9
|
type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
|
@@ -13,7 +13,7 @@ type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
|
|
13
13
|
const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
|
|
14
14
|
type __VLS_WithDefaults<P, D> = {
|
|
15
15
|
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
|
16
|
-
? ${PrettifyLocal.name}<P[K] & { default: D[K]}>
|
|
16
|
+
? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
|
|
17
17
|
: P[K]
|
|
18
18
|
};
|
|
19
19
|
`.trimStart());
|
|
@@ -41,19 +41,10 @@ type __VLS_PropsChildren<S> = {
|
|
|
41
41
|
)]?: S;
|
|
42
42
|
};
|
|
43
43
|
`.trimStart());
|
|
44
|
-
const TypePropsToOption = defineHelper(`__VLS_TypePropsToOption`, () =>
|
|
45
|
-
`
|
|
44
|
+
const TypePropsToOption = defineHelper(`__VLS_TypePropsToOption`, () => `
|
|
46
45
|
type __VLS_TypePropsToOption<T> = {
|
|
47
46
|
[K in keyof T]-?: {} extends Pick<T, K>
|
|
48
|
-
? { type: import('${vueCompilerOptions.lib}').PropType<T[K]> }
|
|
49
|
-
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
50
|
-
};
|
|
51
|
-
`.trimStart() :
|
|
52
|
-
`
|
|
53
|
-
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
54
|
-
type __VLS_TypePropsToOption<T> = {
|
|
55
|
-
[K in keyof T]-?: {} extends Pick<T, K>
|
|
56
|
-
? { type: import('${vueCompilerOptions.lib}').PropType<__VLS_NonUndefinedable<T[K]>> }
|
|
47
|
+
? { type: import('${vueCompilerOptions.lib}').PropType<Required<T>[K]> }
|
|
57
48
|
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
58
49
|
};
|
|
59
50
|
`.trimStart());
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createScriptCodegenContext = createScriptCodegenContext;
|
|
4
4
|
const localTypes_1 = require("../localTypes");
|
|
5
5
|
function createScriptCodegenContext(options) {
|
|
6
|
-
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.
|
|
6
|
+
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.vueCompilerOptions);
|
|
7
7
|
const inlayHints = [];
|
|
8
8
|
return {
|
|
9
9
|
generatedTemplate: false,
|
|
@@ -3,7 +3,7 @@ import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
|
3
3
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
4
4
|
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
5
5
|
import type { TemplateCodegenContext } from '../template/context';
|
|
6
|
-
import { ScriptCodegenContext } from './context';
|
|
6
|
+
import { type ScriptCodegenContext } from './context';
|
|
7
7
|
export interface ScriptCodegenOptions {
|
|
8
8
|
ts: typeof ts;
|
|
9
9
|
compilerOptions: ts.CompilerOptions;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateSrc = generateSrc;
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
6
7
|
function* generateSrc(src) {
|
|
7
8
|
if (src === true) {
|
|
8
9
|
return;
|
|
@@ -21,10 +22,10 @@ function* generateSrc(src) {
|
|
|
21
22
|
text = text + '.js';
|
|
22
23
|
}
|
|
23
24
|
yield `export * from `;
|
|
24
|
-
yield* (0,
|
|
25
|
+
yield* (0, wrapWith_1.wrapWith)(src.offset, src.offset + src.text.length, 'main', {
|
|
25
26
|
...codeFeatures_1.codeFeatures.all,
|
|
26
|
-
...text
|
|
27
|
-
});
|
|
27
|
+
...text !== src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
|
|
28
|
+
}, `'`, [text.slice(0, src.text.length), 'main', src.offset, utils_1.combineLastMapping], text.slice(src.text.length), `'`);
|
|
28
29
|
yield utils_1.endOfLine;
|
|
29
30
|
yield `export { default } from '${text}'${utils_1.endOfLine}`;
|
|
30
31
|
}
|
|
@@ -51,7 +51,7 @@ function* generateTemplateElements() {
|
|
|
51
51
|
yield `let __VLS_elements!: __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
52
52
|
}
|
|
53
53
|
function* generateTemplateComponents(options) {
|
|
54
|
-
const types = [];
|
|
54
|
+
const types = [`typeof __VLS_ctx`];
|
|
55
55
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
|
|
56
56
|
const { componentsOption } = options.scriptRanges.exportDefault;
|
|
57
57
|
yield `const __VLS_componentsOption = `;
|
|
@@ -64,7 +64,6 @@ function* generateTemplateComponents(options) {
|
|
|
64
64
|
yield utils_1.endOfLine;
|
|
65
65
|
types.push(`typeof __VLS_componentsOption`);
|
|
66
66
|
}
|
|
67
|
-
types.push(`typeof __VLS_ctx`);
|
|
68
67
|
yield `type __VLS_LocalComponents =`;
|
|
69
68
|
for (const type of types) {
|
|
70
69
|
yield ` & `;
|
|
@@ -74,7 +73,7 @@ function* generateTemplateComponents(options) {
|
|
|
74
73
|
yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
|
|
75
74
|
}
|
|
76
75
|
function* generateTemplateDirectives(options) {
|
|
77
|
-
const types = [];
|
|
76
|
+
const types = [`typeof __VLS_ctx`];
|
|
78
77
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
|
|
79
78
|
const { directivesOption } = options.scriptRanges.exportDefault;
|
|
80
79
|
yield `const __VLS_directivesOption = `;
|
|
@@ -85,9 +84,8 @@ function* generateTemplateDirectives(options) {
|
|
|
85
84
|
codeFeatures_1.codeFeatures.navigation,
|
|
86
85
|
];
|
|
87
86
|
yield utils_1.endOfLine;
|
|
88
|
-
types.push(`typeof __VLS_directivesOption
|
|
87
|
+
types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
|
|
89
88
|
}
|
|
90
|
-
types.push(`typeof __VLS_ctx`);
|
|
91
89
|
yield `type __VLS_LocalDirectives =`;
|
|
92
90
|
for (const type of types) {
|
|
93
91
|
yield ` & `;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type { Code, VueCodeInformation } from '../../types';
|
|
3
|
-
import { InlayHintInfo } from '../inlayHints';
|
|
3
|
+
import type { InlayHintInfo } from '../inlayHints';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
|
|
6
6
|
/**
|
|
@@ -161,6 +161,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
161
161
|
}[]>;
|
|
162
162
|
currentComponent: {
|
|
163
163
|
ctxVar: string;
|
|
164
|
+
childTypes: string[];
|
|
164
165
|
used: boolean;
|
|
165
166
|
} | undefined;
|
|
166
167
|
singleRootElTypes: string[];
|
|
@@ -35,9 +35,11 @@ function* generateComponent(options, ctx, node) {
|
|
|
35
35
|
const componentVNodeVar = ctx.getInternalVariable();
|
|
36
36
|
const componentCtxVar = ctx.getInternalVariable();
|
|
37
37
|
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
38
|
+
ctx.currentComponent?.childTypes.push(`typeof ${componentVNodeVar}`);
|
|
38
39
|
ctx.currentComponent = {
|
|
39
40
|
ctxVar: componentCtxVar,
|
|
40
|
-
|
|
41
|
+
childTypes: [],
|
|
42
|
+
used: false,
|
|
41
43
|
};
|
|
42
44
|
let props = node.props;
|
|
43
45
|
let dynamicTagInfo;
|
|
@@ -159,7 +161,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
159
161
|
yield* (0, wrapWith_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
|
|
160
162
|
yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
|
|
161
163
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
162
|
-
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
164
|
+
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
163
165
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
164
166
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
165
167
|
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
@@ -188,7 +190,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
188
190
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
189
191
|
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
190
192
|
if (ctx.currentComponent.used) {
|
|
191
|
-
yield `var ${componentCtxVar}!:
|
|
193
|
+
yield `var ${componentCtxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
function* generateElement(options, ctx, node) {
|
|
@@ -197,6 +199,7 @@ function* generateElement(options, ctx, node) {
|
|
|
197
199
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
198
200
|
: undefined;
|
|
199
201
|
const failedPropExps = [];
|
|
202
|
+
ctx.currentComponent?.childTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
200
203
|
yield `__VLS_asFunctionalElement(__VLS_elements`;
|
|
201
204
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
202
205
|
if (endTagOffset !== undefined) {
|
|
@@ -223,7 +226,10 @@ function* generateElement(options, ctx, node) {
|
|
|
223
226
|
ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
|
|
224
227
|
}
|
|
225
228
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
229
|
+
const { currentComponent } = ctx;
|
|
230
|
+
ctx.currentComponent = undefined;
|
|
226
231
|
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
232
|
+
ctx.currentComponent = currentComponent;
|
|
227
233
|
}
|
|
228
234
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
229
235
|
for (const failedExp of failedPropExps) {
|
|
@@ -26,9 +26,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
26
26
|
|| prop.name === 'slot'
|
|
27
27
|
|| prop.name === 'on'
|
|
28
28
|
|| prop.name === 'model'
|
|
29
|
-
|| prop.name === 'bind'
|
|
30
|
-
|| prop.name === 'scope'
|
|
31
|
-
|| prop.name === 'data') {
|
|
29
|
+
|| prop.name === 'bind') {
|
|
32
30
|
continue;
|
|
33
31
|
}
|
|
34
32
|
ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
|
|
@@ -81,6 +79,6 @@ function* generateValue(options, ctx, prop) {
|
|
|
81
79
|
}
|
|
82
80
|
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
|
|
83
81
|
yield `: `;
|
|
84
|
-
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp
|
|
82
|
+
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
|
|
85
83
|
}
|
|
86
84
|
//# sourceMappingURL=elementDirectives.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { Code } from '../../types';
|
|
3
|
+
import type { Code, VueCodeInformation } 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, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
|
-
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
|
+
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
|
|
8
8
|
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
9
|
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
10
10
|
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
@@ -11,9 +11,8 @@ const utils_1 = require("../utils");
|
|
|
11
11
|
const camelized_1 = require("../utils/camelized");
|
|
12
12
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
13
13
|
const interpolation_1 = require("./interpolation");
|
|
14
|
-
function* generateElementEvents(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
|
|
15
|
-
let
|
|
16
|
-
let eventsVar;
|
|
14
|
+
function* generateElementEvents(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
|
|
15
|
+
let emitsVar;
|
|
17
16
|
let propsVar;
|
|
18
17
|
for (const prop of node.props) {
|
|
19
18
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -23,12 +22,10 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
23
22
|
&& prop.name === 'model'
|
|
24
23
|
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
25
24
|
ctx.currentComponent.used = true;
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
eventsVar = ctx.getInternalVariable();
|
|
25
|
+
if (!emitsVar) {
|
|
26
|
+
emitsVar = ctx.getInternalVariable();
|
|
29
27
|
propsVar = ctx.getInternalVariable();
|
|
30
|
-
yield `let ${
|
|
31
|
-
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
28
|
+
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${componentCtxVar}.emit>${utils_1.endOfLine}`;
|
|
32
29
|
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
33
30
|
}
|
|
34
31
|
let source = prop.arg?.loc.source ?? 'model-value';
|
|
@@ -45,32 +42,43 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
45
42
|
propPrefix = 'onVnode-';
|
|
46
43
|
emitPrefix = 'vnode-';
|
|
47
44
|
}
|
|
48
|
-
|
|
45
|
+
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
46
|
+
const emitName = emitPrefix + source;
|
|
47
|
+
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
48
|
+
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> => (${utils_1.newLine}`;
|
|
49
|
+
if (prop.name === 'on') {
|
|
50
|
+
yield `{ `;
|
|
51
|
+
yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
|
|
52
|
+
yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
|
|
53
|
+
}
|
|
54
|
+
yield `{ `;
|
|
49
55
|
if (prop.name === 'on') {
|
|
50
56
|
yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
|
|
51
57
|
yield `: `;
|
|
52
58
|
yield* generateEventExpression(options, ctx, prop);
|
|
53
59
|
}
|
|
54
60
|
else {
|
|
55
|
-
yield `'${
|
|
61
|
+
yield `'${propName}': `;
|
|
56
62
|
yield* generateModelEventExpression(options, ctx, prop);
|
|
57
63
|
}
|
|
58
64
|
yield `})${utils_1.endOfLine}`;
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
|
-
function* generateEventArg(ctx, name, start, directive = 'on'
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
function* generateEventArg(ctx, name, start, directive = 'on', features = {
|
|
69
|
+
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
70
|
+
...ctx.codeFeatures.navigationWithoutRename,
|
|
71
|
+
}) {
|
|
72
|
+
if (directive.length) {
|
|
73
|
+
name = (0, shared_1.capitalize)(name);
|
|
74
|
+
}
|
|
67
75
|
if (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
|
|
68
76
|
yield ['', 'template', start, features];
|
|
69
77
|
yield directive;
|
|
70
|
-
yield* (0, camelized_1.generateCamelized)(
|
|
78
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping);
|
|
71
79
|
}
|
|
72
80
|
else {
|
|
73
|
-
yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(
|
|
81
|
+
yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping), `'`);
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
function* generateEventExpression(options, ctx, prop) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
-
import type { Code
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export interface FailedPropExpression {
|
|
@@ -8,4 +8,4 @@ export interface FailedPropExpression {
|
|
|
8
8
|
suffix: string;
|
|
9
9
|
}
|
|
10
10
|
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
|
|
11
|
-
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined,
|
|
11
|
+
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, enableCodeFeatures?: boolean): Generator<Code>;
|
|
@@ -83,7 +83,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
83
83
|
}
|
|
84
84
|
const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
85
85
|
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
|
|
86
|
-
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp,
|
|
86
|
+
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures)))];
|
|
87
87
|
if (enableCodeFeatures) {
|
|
88
88
|
yield* codes;
|
|
89
89
|
}
|
|
@@ -148,7 +148,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
|
-
const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp,
|
|
151
|
+
const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures))];
|
|
152
152
|
if (enableCodeFeatures) {
|
|
153
153
|
yield* codes;
|
|
154
154
|
}
|
|
@@ -160,14 +160,11 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
function* generatePropExp(options, ctx, prop, exp,
|
|
163
|
+
function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
|
|
164
164
|
const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
completion: undefined,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
165
|
+
const features = isShorthand
|
|
166
|
+
? ctx.codeFeatures.withoutHighlightAndCompletion
|
|
167
|
+
: ctx.codeFeatures.all;
|
|
171
168
|
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
|
172
169
|
if (!isShorthand) { // vue 3.4+
|
|
173
170
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, `(`, `)`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
4
|
-
import { TemplateCodegenContext } from './context';
|
|
4
|
+
import { type TemplateCodegenContext } from './context';
|
|
5
5
|
export interface TemplateCodegenOptions {
|
|
6
6
|
ts: typeof ts;
|
|
7
7
|
compilerOptions: ts.CompilerOptions;
|
|
@@ -39,7 +39,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
39
39
|
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
40
40
|
codes = [
|
|
41
41
|
`[`,
|
|
42
|
-
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp
|
|
42
|
+
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp),
|
|
43
43
|
`]`
|
|
44
44
|
];
|
|
45
45
|
}
|
|
@@ -28,7 +28,9 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
|
|
31
|
+
// #932: reference for implicit default slot
|
|
32
|
+
const { start, end } = getElementInnerLoc(options, node);
|
|
33
|
+
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.navigation, `default`);
|
|
32
34
|
}
|
|
33
35
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
34
36
|
}
|
|
@@ -44,6 +46,12 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
44
46
|
for (const varName of slotBlockVars) {
|
|
45
47
|
ctx.removeLocalVariable(varName);
|
|
46
48
|
}
|
|
49
|
+
if (options.vueCompilerOptions.strictSlotChildren && node.children.length) {
|
|
50
|
+
const { start, end } = getElementInnerLoc(options, node);
|
|
51
|
+
yield `(): __VLS_NormalizeSlotReturns<typeof ${slotVar}> => (`;
|
|
52
|
+
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.verification, `{} as [`, ...ctx.currentComponent.childTypes.map(name => `${name}, `), `]`);
|
|
53
|
+
yield `)${utils_1.endOfLine}`;
|
|
54
|
+
}
|
|
47
55
|
if (slotDir) {
|
|
48
56
|
let isStatic = true;
|
|
49
57
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -112,4 +120,26 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
112
120
|
];
|
|
113
121
|
}
|
|
114
122
|
}
|
|
123
|
+
function getElementInnerLoc(options, node) {
|
|
124
|
+
if (node.children.length) {
|
|
125
|
+
let start = node.children[0].loc.start.offset;
|
|
126
|
+
let end = node.children.at(-1).loc.end.offset;
|
|
127
|
+
while (options.template.content[start - 1] !== '>') {
|
|
128
|
+
start--;
|
|
129
|
+
}
|
|
130
|
+
while (options.template.content[end] !== '<' && end < node.loc.end.offset) {
|
|
131
|
+
end++;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
start,
|
|
135
|
+
end,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return {
|
|
140
|
+
start: node.loc.start.offset,
|
|
141
|
+
end: node.loc.end.offset,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
115
145
|
//# sourceMappingURL=vSlot.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as CompilerDOM from '@vue/compiler-dom';
|
|
1
|
+
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { Code, SfcBlock,
|
|
3
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
4
4
|
export declare const newLine = "\n";
|
|
5
5
|
export declare const endOfLine = ";\n";
|
|
6
6
|
export declare const combineLastMapping: VueCodeInformation;
|
|
@@ -18,4 +18,3 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
|
|
|
18
18
|
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
19
19
|
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
20
20
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
21
|
-
export declare function generateSfcBlockAttrValue(src: SfcBlockAttr & object, text: string, features: VueCodeInformation): Generator<Code>;
|
|
@@ -6,7 +6,6 @@ exports.collectIdentifiers = collectIdentifiers;
|
|
|
6
6
|
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
7
7
|
exports.createTsAst = createTsAst;
|
|
8
8
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
9
|
-
exports.generateSfcBlockAttrValue = generateSfcBlockAttrValue;
|
|
10
9
|
const shared_1 = require("../../utils/shared");
|
|
11
10
|
exports.newLine = `\n`;
|
|
12
11
|
exports.endOfLine = `;${exports.newLine}`;
|
|
@@ -65,19 +64,4 @@ function generateSfcBlockSection(block, start, end, features) {
|
|
|
65
64
|
features,
|
|
66
65
|
];
|
|
67
66
|
}
|
|
68
|
-
function* generateSfcBlockAttrValue(src, text, features) {
|
|
69
|
-
const { offset, quotes } = src;
|
|
70
|
-
if (!quotes) {
|
|
71
|
-
yield [``, 'main', offset, { verification: true }];
|
|
72
|
-
}
|
|
73
|
-
yield [
|
|
74
|
-
`'${text}'`,
|
|
75
|
-
'main',
|
|
76
|
-
quotes ? offset - 1 : offset,
|
|
77
|
-
features
|
|
78
|
-
];
|
|
79
|
-
if (!quotes) {
|
|
80
|
-
yield [``, 'main', offset + text.length, { __combineOffset: 2 }];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
67
|
//# sourceMappingURL=index.js.map
|
package/lib/languagePlugin.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const css = require("css-tree");
|
|
4
|
+
const plugin = () => {
|
|
5
|
+
return {
|
|
6
|
+
version: 2.1,
|
|
7
|
+
compileSFCStyle(lang, style) {
|
|
8
|
+
if (lang === 'css' || lang === 'scss' || lang === 'sass' || lang === 'less') {
|
|
9
|
+
return css.parse(style, {
|
|
10
|
+
filename: 'test.' + lang,
|
|
11
|
+
positions: true,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.default = plugin;
|
|
18
|
+
//# sourceMappingURL=vue-style-css.js.map
|
|
@@ -21,7 +21,7 @@ const plugin = () => {
|
|
|
21
21
|
if (embeddedFile.id !== 'template_inline_css' || !sfc.template?.ast) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
embeddedFile.parentCodeId = 'template';
|
|
24
|
+
embeddedFile.parentCodeId = sfc.template.lang === 'md' ? 'root_tags' : 'template';
|
|
25
25
|
embeddedFile.content.push(...generate(sfc.template.ast));
|
|
26
26
|
},
|
|
27
27
|
};
|
|
@@ -37,14 +37,17 @@ const plugin = ctx => {
|
|
|
37
37
|
return result;
|
|
38
38
|
},
|
|
39
39
|
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
40
|
+
if (!embeddedFile.id.startsWith('template_inline_ts_')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
// access template content to watch change
|
|
41
|
-
|
|
44
|
+
void sfc.template?.content;
|
|
42
45
|
const parsed = parseds.get(sfc);
|
|
43
46
|
if (parsed) {
|
|
44
47
|
const codes = parsed.get(embeddedFile.id);
|
|
45
48
|
if (codes) {
|
|
46
49
|
embeddedFile.content.push(...codes);
|
|
47
|
-
embeddedFile.parentCodeId = 'template';
|
|
50
|
+
embeddedFile.parentCodeId = sfc.template?.lang === 'md' ? 'root_tags' : 'template';
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
},
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
package/lib/plugins.d.ts
CHANGED
package/lib/types.d.ts
CHANGED
package/lib/utils/signals.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function computedArray<I, O>(arr: () => I[], getGetter: (item: () => I, index: number) => () => O): readonly Readonly<O>[];
|
|
2
2
|
export declare function computedSet<T>(source: () => Set<T>): () => Set<T>;
|
|
3
|
+
export declare function computedItems<T>(source: () => T[], compareFn: (oldItem: T, newItem: T) => boolean): () => T[];
|
package/lib/utils/signals.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.computedArray = computedArray;
|
|
4
4
|
exports.computedSet = computedSet;
|
|
5
|
+
exports.computedItems = computedItems;
|
|
5
6
|
const alien_signals_1 = require("alien-signals");
|
|
6
7
|
function computedArray(arr, getGetter) {
|
|
7
8
|
const length = (0, alien_signals_1.computed)(() => arr().length);
|
|
@@ -51,4 +52,14 @@ function computedSet(source) {
|
|
|
51
52
|
return newValue;
|
|
52
53
|
});
|
|
53
54
|
}
|
|
55
|
+
function computedItems(source, compareFn) {
|
|
56
|
+
return (0, alien_signals_1.computed)(oldArr => {
|
|
57
|
+
oldArr ??= [];
|
|
58
|
+
const newArr = source();
|
|
59
|
+
if (oldArr.length === newArr.length && oldArr.every((item, index) => compareFn(item, newArr[index]))) {
|
|
60
|
+
return oldArr;
|
|
61
|
+
}
|
|
62
|
+
return newArr;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
54
65
|
//# sourceMappingURL=signals.js.map
|
package/lib/utils/ts.js
CHANGED
|
@@ -217,6 +217,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
217
217
|
vitePressExtensions: [],
|
|
218
218
|
petiteVueExtensions: [],
|
|
219
219
|
jsxSlots: false,
|
|
220
|
+
strictSlotChildren: strictTemplates,
|
|
220
221
|
strictVModel: strictTemplates,
|
|
221
222
|
checkUnknownProps: strictTemplates,
|
|
222
223
|
checkUnknownEvents: strictTemplates,
|
|
@@ -88,8 +88,8 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
88
88
|
const base = computedSfcBlock('style_' + i, 'css', getBlock);
|
|
89
89
|
const getModule = computedAttrValue('__module', base, getBlock);
|
|
90
90
|
const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
|
|
91
|
-
const getCssVars = (0,
|
|
92
|
-
const getClassNames = (0,
|
|
91
|
+
const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
92
|
+
const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
93
93
|
return () => mergeObject(base, {
|
|
94
94
|
get module() { return getModule(); },
|
|
95
95
|
get scoped() { return getScoped(); },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "~2.4.
|
|
16
|
+
"@volar/language-core": "~2.4.13",
|
|
17
17
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
18
|
"@vue/compiler-vue2": "^2.7.16",
|
|
19
19
|
"@vue/shared": "^3.5.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/minimatch": "^5.1.2",
|
|
27
27
|
"@types/node": "^22.10.4",
|
|
28
28
|
"@types/path-browserify": "^1.0.1",
|
|
29
|
-
"@volar/typescript": "~2.4.
|
|
29
|
+
"@volar/typescript": "~2.4.13",
|
|
30
30
|
"@vue/compiler-sfc": "^3.5.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"optional": true
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "a7b5649ab4957cd2228f4bbc9205b2008bff58a2"
|
|
41
41
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Code } from '../../types';
|
|
2
|
-
import type { ScriptCodegenContext } from './context';
|
|
3
|
-
import type { ScriptCodegenOptions } from './index';
|
|
4
|
-
export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateStyleModulesType = generateStyleModulesType;
|
|
4
|
-
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const template_1 = require("./template");
|
|
7
|
-
function* generateStyleModulesType(options, ctx) {
|
|
8
|
-
const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
|
|
9
|
-
if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
yield `type __VLS_StyleModules = {${utils_1.newLine}`;
|
|
13
|
-
for (const [style, i] of styles) {
|
|
14
|
-
const { name, offset } = style.module;
|
|
15
|
-
if (offset) {
|
|
16
|
-
yield [
|
|
17
|
-
name,
|
|
18
|
-
'main',
|
|
19
|
-
offset + 1,
|
|
20
|
-
codeFeatures_1.codeFeatures.all
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
yield name;
|
|
25
|
-
}
|
|
26
|
-
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
|
27
|
-
for (const className of style.classNames) {
|
|
28
|
-
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
|
29
|
-
}
|
|
30
|
-
yield `>${utils_1.endOfLine}`;
|
|
31
|
-
}
|
|
32
|
-
yield `}${utils_1.endOfLine}`;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=styleModulesType.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
-
export declare function getObjectProperty(code: string): string;
|
|
3
|
-
export declare function generateObjectProperty(code: string, source: string, offset: number, features: VueCodeInformation, hasQuotes?: boolean, shouldCamelize?: boolean): Generator<Code>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getObjectProperty = getObjectProperty;
|
|
4
|
-
exports.generateObjectProperty = generateObjectProperty;
|
|
5
|
-
const shared_1 = require("@vue/shared");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const camelized_1 = require("../utils/camelized");
|
|
8
|
-
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
9
|
-
function getObjectProperty(code) {
|
|
10
|
-
if (utils_1.identifierRegex.test(code)) {
|
|
11
|
-
return code;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return `'${code}'`;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function* generateObjectProperty(code, source, offset, features, hasQuotes = false, shouldCamelize = false) {
|
|
18
|
-
const start = offset;
|
|
19
|
-
const end = offset + code.length;
|
|
20
|
-
if (hasQuotes) {
|
|
21
|
-
code = code.slice(1, -1);
|
|
22
|
-
offset++;
|
|
23
|
-
}
|
|
24
|
-
if (shouldCamelize) {
|
|
25
|
-
if (utils_1.identifierRegex.test((0, shared_1.camelize)(code))) {
|
|
26
|
-
yield* (0, camelized_1.generateCamelized)(code, source, offset, features);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
yield* (0, utils_1.wrapWith)(start, end, source, features, `'`, ...(0, camelized_1.generateCamelized)(code, source, offset, features), `'`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (utils_1.identifierRegex.test(code)) {
|
|
34
|
-
yield [code, source, offset, features];
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, source, offset, features);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=objectProperty.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|