@vue/language-core 3.0.0-beta.3 → 3.0.0-beta.4
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 +9 -8
- package/lib/codegen/localTypes.js +21 -7
- package/lib/codegen/script/component.js +2 -1
- package/lib/codegen/script/scriptSetup.js +36 -18
- package/lib/codegen/template/context.d.ts +2 -1
- package/lib/codegen/template/context.js +3 -1
- package/lib/codegen/template/element.js +6 -4
- package/lib/codegen/template/elementEvents.js +1 -1
- package/lib/codegen/template/index.js +1 -1
- package/lib/codegen/template/interpolation.js +9 -12
- package/lib/codegen/template/slotOutlet.js +2 -1
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/template/templateChild.js +2 -1
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/codegen/template/vSlot.js +1 -1
- package/lib/codegen/utils/escaped.d.ts +1 -1
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +1 -2
- package/lib/codegen/utils/wrapWith.d.ts +1 -1
- package/lib/languagePlugin.js +6 -3
- package/lib/parsers/scriptSetupRanges.js +4 -8
- package/lib/parsers/vueCompilerOptions.js +0 -1
- package/lib/plugins/file-html.js +3 -3
- package/lib/plugins/file-md.js +2 -1
- package/lib/plugins/file-vue.js +3 -4
- package/lib/plugins/vue-sfc-scripts.js +4 -2
- package/lib/plugins/vue-template-html.js +3 -4
- package/lib/plugins/vue-template-inline-ts.js +3 -1
- package/lib/plugins/vue-tsx.d.ts +1 -0
- package/lib/plugins/vue-tsx.js +2 -1
- package/lib/utils/parseCssImports.js +1 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +22 -11
- package/lib/virtualFile/computedSfc.d.ts +2 -0
- package/lib/virtualFile/computedSfc.js +94 -32
- package/package.json +4 -4
|
@@ -28,15 +28,15 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
28
28
|
const __VLS_placeholder: any;
|
|
29
29
|
|
|
30
30
|
type __VLS_NativeElements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
|
|
31
|
-
type __VLS_IntrinsicElements = ${
|
|
31
|
+
type __VLS_IntrinsicElements = ${target >= 3.3
|
|
32
32
|
? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
|
|
33
|
-
: `globalThis.JSX.IntrinsicElements;`
|
|
34
|
-
type __VLS_Element = ${
|
|
33
|
+
: `globalThis.JSX.IntrinsicElements;`}
|
|
34
|
+
type __VLS_Element = ${target >= 3.3
|
|
35
35
|
? `import('${lib}/jsx-runtime').JSX.Element;`
|
|
36
|
-
: `globalThis.JSX.Element;`
|
|
37
|
-
type __VLS_GlobalComponents = ${
|
|
36
|
+
: `globalThis.JSX.Element;`}
|
|
37
|
+
type __VLS_GlobalComponents = ${target >= 3.5
|
|
38
38
|
? `import('${lib}').GlobalComponents;`
|
|
39
|
-
: `import('${lib}').GlobalComponents & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`
|
|
39
|
+
: `import('${lib}').GlobalComponents & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`}
|
|
40
40
|
type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
|
|
41
41
|
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
42
42
|
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
@@ -117,7 +117,9 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
117
117
|
type __VLS_ResolveEmits<
|
|
118
118
|
Comp,
|
|
119
119
|
Emits,
|
|
120
|
-
TypeEmits = ${target >= 3.6
|
|
120
|
+
TypeEmits = ${target >= 3.6
|
|
121
|
+
? `Comp extends { __typeEmits?: infer T } ? unknown extends T ? {} : import('${lib}').ShortEmitsToObject<T> : {}`
|
|
122
|
+
: `{}`},
|
|
121
123
|
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
|
|
122
124
|
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
|
|
123
125
|
type __VLS_ResolveDirectives<T> = {
|
|
@@ -160,5 +162,4 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
160
162
|
`;
|
|
161
163
|
return text;
|
|
162
164
|
}
|
|
163
|
-
;
|
|
164
165
|
//# sourceMappingURL=globalTypes.js.map
|
|
@@ -63,13 +63,27 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
63
63
|
getUsedNames() {
|
|
64
64
|
return used;
|
|
65
65
|
},
|
|
66
|
-
get PrettifyLocal() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
get
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
get
|
|
66
|
+
get PrettifyLocal() {
|
|
67
|
+
return PrettifyLocal.name;
|
|
68
|
+
},
|
|
69
|
+
get OmitKeepDiscriminatedUnion() {
|
|
70
|
+
return OmitKeepDiscriminatedUnion.name;
|
|
71
|
+
},
|
|
72
|
+
get WithDefaults() {
|
|
73
|
+
return WithDefaults.name;
|
|
74
|
+
},
|
|
75
|
+
get WithSlots() {
|
|
76
|
+
return WithSlots.name;
|
|
77
|
+
},
|
|
78
|
+
get PropsChildren() {
|
|
79
|
+
return PropsChildren.name;
|
|
80
|
+
},
|
|
81
|
+
get TypePropsToOption() {
|
|
82
|
+
return TypePropsToOption.name;
|
|
83
|
+
},
|
|
84
|
+
get OmitIndexSignature() {
|
|
85
|
+
return OmitIndexSignature.name;
|
|
86
|
+
},
|
|
73
87
|
};
|
|
74
88
|
function* generate(names) {
|
|
75
89
|
const generated = new Set();
|
|
@@ -7,7 +7,8 @@ exports.generatePropsOption = generatePropsOption;
|
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
10
|
-
if (options.sfc.script && options.scriptRanges?.exportDefault
|
|
10
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault
|
|
11
|
+
&& options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
|
|
11
12
|
// use defineComponent() from user space code if it exist
|
|
12
13
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, codeFeatures_1.codeFeatures.all);
|
|
13
14
|
yield `{${utils_1.newLine}`;
|
|
@@ -149,15 +149,17 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
149
149
|
callExp.start,
|
|
150
150
|
callExp.start,
|
|
151
151
|
], [
|
|
152
|
-
arg
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
152
|
+
arg
|
|
153
|
+
? [
|
|
154
|
+
` as Omit<__VLS_StyleModules, '$style'>[`,
|
|
155
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
156
|
+
`])`,
|
|
157
|
+
]
|
|
158
|
+
: [
|
|
159
|
+
` as __VLS_StyleModules[`,
|
|
160
|
+
...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
|
|
161
|
+
`])`,
|
|
162
|
+
],
|
|
161
163
|
callExp.end,
|
|
162
164
|
callExp.end,
|
|
163
165
|
]);
|
|
@@ -277,11 +279,15 @@ function* generateMacros(options, ctx) {
|
|
|
277
279
|
}
|
|
278
280
|
function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
|
|
279
281
|
if (typeArg) {
|
|
280
|
-
yield [
|
|
282
|
+
yield [
|
|
283
|
+
[
|
|
281
284
|
`type ${typeName} = `,
|
|
282
285
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
|
|
283
286
|
utils_1.endOfLine,
|
|
284
|
-
],
|
|
287
|
+
],
|
|
288
|
+
statement.start,
|
|
289
|
+
statement.start,
|
|
290
|
+
];
|
|
285
291
|
yield [[typeName], typeArg.start, typeArg.end];
|
|
286
292
|
}
|
|
287
293
|
if (!name) {
|
|
@@ -289,25 +295,37 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
|
|
|
289
295
|
yield [[`const ${defaultName} = `], callExp.start, callExp.start];
|
|
290
296
|
}
|
|
291
297
|
else if (typeArg) {
|
|
292
|
-
yield [
|
|
298
|
+
yield [
|
|
299
|
+
[
|
|
293
300
|
`const ${defaultName} = `,
|
|
294
301
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all),
|
|
295
|
-
],
|
|
296
|
-
|
|
302
|
+
],
|
|
303
|
+
statement.start,
|
|
304
|
+
typeArg.start,
|
|
305
|
+
];
|
|
306
|
+
yield [
|
|
307
|
+
[
|
|
297
308
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
298
309
|
utils_1.endOfLine,
|
|
299
310
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
300
311
|
defaultName,
|
|
301
|
-
],
|
|
312
|
+
],
|
|
313
|
+
typeArg.end,
|
|
314
|
+
callExp.end,
|
|
315
|
+
];
|
|
302
316
|
}
|
|
303
317
|
else {
|
|
304
|
-
yield [
|
|
318
|
+
yield [
|
|
319
|
+
[
|
|
305
320
|
`const ${defaultName} = `,
|
|
306
321
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
307
322
|
utils_1.endOfLine,
|
|
308
323
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
309
324
|
defaultName,
|
|
310
|
-
],
|
|
325
|
+
],
|
|
326
|
+
statement.start,
|
|
327
|
+
callExp.end,
|
|
328
|
+
];
|
|
311
329
|
}
|
|
312
330
|
}
|
|
313
331
|
}
|
|
@@ -415,7 +433,7 @@ function* generateDefineModelType(scriptSetup, propName, localName, defineModel)
|
|
|
415
433
|
yield getRangeText(scriptSetup, defineModel.type);
|
|
416
434
|
}
|
|
417
435
|
else if (defineModel.runtimeType && localName) {
|
|
418
|
-
// Infer from actual prop declaration code
|
|
436
|
+
// Infer from actual prop declaration code
|
|
419
437
|
yield `typeof ${localName}['value']`;
|
|
420
438
|
}
|
|
421
439
|
else if (defineModel.defaultValue && propName) {
|
|
@@ -100,7 +100,7 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
|
|
|
100
100
|
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
|
101
101
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
102
102
|
*/
|
|
103
|
-
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'
|
|
103
|
+
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'>, templateAst?: CompilerDOM.RootNode): {
|
|
104
104
|
readonly currentInfo: {
|
|
105
105
|
ignoreError?: boolean;
|
|
106
106
|
expectError?: {
|
|
@@ -132,6 +132,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
132
132
|
withoutSemantic: VueCodeInformation;
|
|
133
133
|
};
|
|
134
134
|
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
135
|
+
inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
|
|
135
136
|
inVFor: boolean;
|
|
136
137
|
slots: {
|
|
137
138
|
name: string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const computedSfc_1 = require("../../virtualFile/computedSfc");
|
|
5
6
|
const codeFeatures_1 = require("../codeFeatures");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
7
8
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
@@ -103,7 +104,7 @@ const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)
|
|
|
103
104
|
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
|
104
105
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
105
106
|
*/
|
|
106
|
-
function createTemplateCodegenContext(options) {
|
|
107
|
+
function createTemplateCodegenContext(options, templateAst) {
|
|
107
108
|
let variableId = 0;
|
|
108
109
|
function resolveCodeFeatures(features) {
|
|
109
110
|
if (features.verification && stack.length) {
|
|
@@ -160,6 +161,7 @@ function createTemplateCodegenContext(options) {
|
|
|
160
161
|
},
|
|
161
162
|
}),
|
|
162
163
|
resolveCodeFeatures,
|
|
164
|
+
inlineTsAsts: templateAst && computedSfc_1.templateInlineTsAsts.get(templateAst),
|
|
163
165
|
inVFor: false,
|
|
164
166
|
slots,
|
|
165
167
|
dynamicSlots,
|
|
@@ -161,7 +161,8 @@ function* generateComponent(options, ctx, node) {
|
|
|
161
161
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
162
162
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
163
163
|
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
164
|
-
const isRootNode = ctx.singleRootNodes.has(node)
|
|
164
|
+
const isRootNode = ctx.singleRootNodes.has(node)
|
|
165
|
+
&& !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
|
|
165
166
|
if (refName || isRootNode) {
|
|
166
167
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
167
168
|
ctx.currentComponent.used = true;
|
|
@@ -190,7 +191,8 @@ function* generateComponent(options, ctx, node) {
|
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
function* generateElement(options, ctx, node) {
|
|
193
|
-
const startTagOffset = node.loc.start.offset
|
|
194
|
+
const startTagOffset = node.loc.start.offset
|
|
195
|
+
+ options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
194
196
|
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
195
197
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
196
198
|
: undefined;
|
|
@@ -289,8 +291,8 @@ function* generateElementReference(options, ctx, node) {
|
|
|
289
291
|
return [];
|
|
290
292
|
}
|
|
291
293
|
function hasVBindAttrs(options, ctx, node) {
|
|
292
|
-
return options.vueCompilerOptions.fallthroughAttributes && ((options.inheritAttrs && ctx.singleRootNodes.has(node))
|
|
293
|
-
node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
294
|
+
return options.vueCompilerOptions.fallthroughAttributes && ((options.inheritAttrs && ctx.singleRootNodes.has(node))
|
|
295
|
+
|| node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
294
296
|
&& prop.name === 'bind'
|
|
295
297
|
&& prop.exp?.loc.source === '$attrs'));
|
|
296
298
|
}
|
|
@@ -86,7 +86,7 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
86
86
|
let prefix = `(`;
|
|
87
87
|
let suffix = `)`;
|
|
88
88
|
let isFirstMapping = true;
|
|
89
|
-
const ast = (0, utils_1.createTsAst)(options.ts,
|
|
89
|
+
const ast = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, prop.exp.content);
|
|
90
90
|
const isCompound = isCompoundExpression(options.ts, ast);
|
|
91
91
|
if (isCompound) {
|
|
92
92
|
ctx.addLocalVariable('$event');
|
|
@@ -10,7 +10,7 @@ const objectProperty_1 = require("./objectProperty");
|
|
|
10
10
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
11
11
|
const templateChild_1 = require("./templateChild");
|
|
12
12
|
function* generateTemplate(options) {
|
|
13
|
-
const ctx = (0, context_1.createTemplateCodegenContext)(options);
|
|
13
|
+
const ctx = (0, context_1.createTemplateCodegenContext)(options, options.template.ast);
|
|
14
14
|
if (options.slotsAssignName) {
|
|
15
15
|
ctx.addLocalVariable(options.slotsAssignName);
|
|
16
16
|
}
|
|
@@ -8,8 +8,7 @@ const utils_1 = require("../utils");
|
|
|
8
8
|
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
9
9
|
function* generateInterpolation(options, ctx, source, data, code, start, prefix = '', suffix = '') {
|
|
10
10
|
const { ts, destructuredPropNames, templateRefNames, } = options;
|
|
11
|
-
|
|
12
|
-
for (let [section, offset, type] of forEachInterpolationSegment(ts, template, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
|
|
11
|
+
for (let [section, offset, type] of forEachInterpolationSegment(ts, ctx.inlineTsAsts, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
|
|
13
12
|
if (offset === undefined) {
|
|
14
13
|
yield section;
|
|
15
14
|
}
|
|
@@ -36,7 +35,9 @@ function* generateInterpolation(options, ctx, source, data, code, start, prefix
|
|
|
36
35
|
start + offset,
|
|
37
36
|
type === 'errorMappingOnly'
|
|
38
37
|
? ctx.codeFeatures.verification
|
|
39
|
-
: typeof data === 'function'
|
|
38
|
+
: typeof data === 'function'
|
|
39
|
+
? data(start + offset)
|
|
40
|
+
: data,
|
|
40
41
|
];
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
@@ -47,8 +48,7 @@ function* generateInterpolation(options, ctx, source, data, code, start, prefix
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
function* forEachInterpolationSegment(ts, template, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
|
|
51
|
+
function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
|
|
52
52
|
const code = prefix + originalCode + suffix;
|
|
53
53
|
const offset = start !== undefined ? start - prefix.length : undefined;
|
|
54
54
|
let ctxVars = [];
|
|
@@ -59,7 +59,7 @@ function* forEachInterpolationSegment(ts, template, destructuredPropNames, templ
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
const ast = (0, utils_1.createTsAst)(ts,
|
|
62
|
+
const ast = (0, utils_1.createTsAst)(ts, inlineTsAsts, code);
|
|
63
63
|
const varCb = (id, isShorthand) => {
|
|
64
64
|
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
65
65
|
if (!shouldIdentifierSkipped(ctx, text, destructuredPropNames)) {
|
|
@@ -152,17 +152,14 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
|
|
|
152
152
|
walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars, false);
|
|
153
153
|
}
|
|
154
154
|
walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars, false);
|
|
155
|
-
}
|
|
156
|
-
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
155
|
+
} // fix https://github.com/vuejs/language-tools/issues/1156
|
|
157
156
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
158
157
|
walkIdentifiers(ts, prop, ast, cb, ctx, blockVars, false);
|
|
159
|
-
}
|
|
160
|
-
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
158
|
+
} // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
161
159
|
else if (ts.isSpreadAssignment(prop)) {
|
|
162
160
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
163
161
|
walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
|
|
164
|
-
}
|
|
165
|
-
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
162
|
+
} // fix https://github.com/vuejs/language-tools/issues/4604
|
|
166
163
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
167
164
|
processFunction(ts, prop, ast, cb, ctx);
|
|
168
165
|
}
|
|
@@ -10,7 +10,8 @@ const elementProps_1 = require("./elementProps");
|
|
|
10
10
|
const interpolation_1 = require("./interpolation");
|
|
11
11
|
const propertyAccess_1 = require("./propertyAccess");
|
|
12
12
|
function* generateSlotOutlet(options, ctx, node) {
|
|
13
|
-
const startTagOffset = node.loc.start.offset
|
|
13
|
+
const startTagOffset = node.loc.start.offset
|
|
14
|
+
+ options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
14
15
|
const startTagEndOffset = startTagOffset + node.tag.length;
|
|
15
16
|
const propsVar = ctx.getInternalVariable();
|
|
16
17
|
const nameProp = node.props.find(prop => {
|
|
@@ -67,8 +67,8 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
67
67
|
const ast = ts.createSourceFile('', content, 99);
|
|
68
68
|
const literals = [];
|
|
69
69
|
ts.forEachChild(ast, node => {
|
|
70
|
-
if (!ts.isExpressionStatement(node)
|
|
71
|
-
!isTemplateExpression(node.expression)) {
|
|
70
|
+
if (!ts.isExpressionStatement(node)
|
|
71
|
+
|| !isTemplateExpression(node.expression)) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
const expression = node.expression.templateSpans[0].expression;
|
|
@@ -173,7 +173,8 @@ function parseInterpolationNode(node, template) {
|
|
|
173
173
|
start--;
|
|
174
174
|
content = leftCharacter + content;
|
|
175
175
|
}
|
|
176
|
-
while ((rightCharacter = template.slice(start + content.length, start + content.length + 1)).trim() === ''
|
|
176
|
+
while ((rightCharacter = template.slice(start + content.length, start + content.length + 1)).trim() === ''
|
|
177
|
+
&& rightCharacter.length) {
|
|
177
178
|
content = content + rightCharacter;
|
|
178
179
|
}
|
|
179
180
|
return [
|
|
@@ -12,7 +12,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
12
12
|
const forBlockVars = [];
|
|
13
13
|
yield `for (const [`;
|
|
14
14
|
if (leftExpressionRange && leftExpressionText) {
|
|
15
|
-
const collectAst = (0, utils_1.createTsAst)(options.ts,
|
|
15
|
+
const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
|
|
16
16
|
(0, utils_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
|
|
17
17
|
yield [
|
|
18
18
|
leftExpressionText,
|
|
@@ -35,7 +35,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
35
35
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
36
36
|
}
|
|
37
37
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
38
|
-
const slotAst = (0, utils_1.createTsAst)(options.ts,
|
|
38
|
+
const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
|
|
39
39
|
(0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
40
40
|
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
41
41
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Code, VueCodeInformation } from
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
export declare function generateEscaped(text: string, source: string, offset: number, features: VueCodeInformation, escapeTarget: RegExp): Generator<Code>;
|
|
@@ -16,5 +16,5 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
|
|
|
16
16
|
initializer: ts.Expression | undefined;
|
|
17
17
|
}[];
|
|
18
18
|
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
19
|
-
export declare function createTsAst(ts: typeof import('typescript'),
|
|
19
|
+
export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
|
|
20
20
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
@@ -49,8 +49,7 @@ function normalizeAttributeValue(node) {
|
|
|
49
49
|
}
|
|
50
50
|
return [content, offset];
|
|
51
51
|
}
|
|
52
|
-
function createTsAst(ts,
|
|
53
|
-
const inlineTsAsts = templateAst?.__volar_inlineTsAsts;
|
|
52
|
+
function createTsAst(ts, inlineTsAsts, text) {
|
|
54
53
|
let ast = inlineTsAsts?.get(text);
|
|
55
54
|
if (!ast) {
|
|
56
55
|
ast = ts.createSourceFile('/a.ts', text, 99);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Code, VueCodeInformation } from
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
|
|
3
3
|
export declare function wrapWith(startOffset: number, endOffset: number, source: string, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
|
package/lib/languagePlugin.js
CHANGED
|
@@ -88,9 +88,12 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
88
88
|
return {
|
|
89
89
|
code,
|
|
90
90
|
extension: '.' + lang,
|
|
91
|
-
scriptKind: lang === 'js'
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
scriptKind: lang === 'js'
|
|
92
|
+
? ts.ScriptKind.JS
|
|
93
|
+
: lang === 'jsx'
|
|
94
|
+
? ts.ScriptKind.JSX
|
|
95
|
+
: lang === 'tsx'
|
|
96
|
+
? ts.ScriptKind.TSX
|
|
94
97
|
: ts.ScriptKind.TS,
|
|
95
98
|
};
|
|
96
99
|
}
|
|
@@ -343,8 +343,7 @@ function findBindingVars(ts, left, ast) {
|
|
|
343
343
|
function worker(node) {
|
|
344
344
|
if (ts.isIdentifier(node)) {
|
|
345
345
|
vars.push((0, shared_1.getStartEnd)(ts, node, ast));
|
|
346
|
-
}
|
|
347
|
-
// { ? } = ...
|
|
346
|
+
} // { ? } = ...
|
|
348
347
|
// [ ? ] = ...
|
|
349
348
|
else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
|
|
350
349
|
for (const property of node.elements) {
|
|
@@ -352,16 +351,13 @@ function findBindingVars(ts, left, ast) {
|
|
|
352
351
|
worker(property.name);
|
|
353
352
|
}
|
|
354
353
|
}
|
|
355
|
-
}
|
|
356
|
-
// { foo: ? } = ...
|
|
354
|
+
} // { foo: ? } = ...
|
|
357
355
|
else if (ts.isPropertyAssignment(node)) {
|
|
358
356
|
worker(node.initializer);
|
|
359
|
-
}
|
|
360
|
-
// { foo } = ...
|
|
357
|
+
} // { foo } = ...
|
|
361
358
|
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
362
359
|
vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
|
|
363
|
-
}
|
|
364
|
-
// { ...? } = ...
|
|
360
|
+
} // { ...? } = ...
|
|
365
361
|
// [ ...? ] = ...
|
|
366
362
|
else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
|
|
367
363
|
worker(node.expression);
|
package/lib/plugins/file-html.js
CHANGED
|
@@ -53,8 +53,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
53
53
|
type: 'style',
|
|
54
54
|
lang,
|
|
55
55
|
});
|
|
56
|
-
}
|
|
57
|
-
// ignore `<script src="...">`
|
|
56
|
+
} // ignore `<script src="...">`
|
|
58
57
|
else if (tag === 'script' && !attrs.includes('src=')) {
|
|
59
58
|
let type = attrs.includes('type=') ? 'scriptSetup' : 'script';
|
|
60
59
|
sfc.descriptor[type] = {
|
|
@@ -69,7 +68,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
69
68
|
lang,
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
|
-
templateContent = templateContent.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
71
|
+
templateContent = templateContent.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
72
|
+
+ templateContent.slice(match.index + matchText.length);
|
|
73
73
|
}
|
|
74
74
|
sfc.descriptor.template = {
|
|
75
75
|
attrs: {},
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -47,7 +47,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
47
47
|
const matchText = match[0];
|
|
48
48
|
codes.push([matchText, undefined, match.index]);
|
|
49
49
|
codes.push('\n\n');
|
|
50
|
-
content = content.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
50
|
+
content = content.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
51
|
+
+ content.slice(match.index + matchText.length);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
content = content
|
package/lib/plugins/file-vue.js
CHANGED
|
@@ -31,10 +31,9 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
const oldContent = hitBlock.content;
|
|
34
|
-
const newContent = hitBlock.content =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
+ hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
|
|
34
|
+
const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
|
|
35
|
+
+ change.newText
|
|
36
|
+
+ hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
|
|
38
37
|
// #3449
|
|
39
38
|
const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
|
|
40
39
|
const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
|
|
@@ -14,8 +14,10 @@ const plugin = () => {
|
|
|
14
14
|
return names;
|
|
15
15
|
},
|
|
16
16
|
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
17
|
-
const script = embeddedFile.id === 'script_raw'
|
|
18
|
-
|
|
17
|
+
const script = embeddedFile.id === 'script_raw'
|
|
18
|
+
? sfc.script
|
|
19
|
+
: embeddedFile.id === 'scriptsetup_raw'
|
|
20
|
+
? sfc.scriptSetup
|
|
19
21
|
: undefined;
|
|
20
22
|
if (script) {
|
|
21
23
|
embeddedFile.content.push([
|
|
@@ -171,10 +171,9 @@ const plugin = ({ modules }) => {
|
|
|
171
171
|
function tryUpdateNodeLoc(loc) {
|
|
172
172
|
delete loc.__endOffset;
|
|
173
173
|
if (withinChangeRange(loc)) {
|
|
174
|
-
loc.source =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
+ loc.source.slice(change.end - loc.start.offset);
|
|
174
|
+
loc.source = loc.source.slice(0, change.start - loc.start.offset)
|
|
175
|
+
+ change.newText
|
|
176
|
+
+ loc.source.slice(change.end - loc.start.offset);
|
|
178
177
|
loc.__endOffset = loc.end.offset;
|
|
179
178
|
loc.end.offset += lengthDiff;
|
|
180
179
|
return true;
|
|
@@ -5,6 +5,7 @@ const elementEvents_1 = require("../codegen/template/elementEvents");
|
|
|
5
5
|
const templateChild_1 = require("../codegen/template/templateChild");
|
|
6
6
|
const vFor_1 = require("../codegen/template/vFor");
|
|
7
7
|
const utils_1 = require("../codegen/utils");
|
|
8
|
+
const computedSfc_1 = require("../virtualFile/computedSfc");
|
|
8
9
|
const codeFeatures = {
|
|
9
10
|
format: true,
|
|
10
11
|
};
|
|
@@ -58,6 +59,7 @@ const plugin = ctx => {
|
|
|
58
59
|
return data;
|
|
59
60
|
}
|
|
60
61
|
const templateContent = sfc.template.content;
|
|
62
|
+
const inlineTsAsts = sfc.template.ast && computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
|
|
61
63
|
let i = 0;
|
|
62
64
|
sfc.template.ast.children.forEach(visit);
|
|
63
65
|
return data;
|
|
@@ -85,7 +87,7 @@ const plugin = ctx => {
|
|
|
85
87
|
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
|
86
88
|
) {
|
|
87
89
|
if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
88
|
-
const ast = (0, utils_1.createTsAst)(ctx.modules.typescript,
|
|
90
|
+
const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, inlineTsAsts, prop.exp.content);
|
|
89
91
|
if ((0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)) {
|
|
90
92
|
addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.event);
|
|
91
93
|
}
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -167,6 +167,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
167
167
|
withoutSemantic: import("../types").VueCodeInformation;
|
|
168
168
|
};
|
|
169
169
|
resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
|
|
170
|
+
inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
|
|
170
171
|
inVFor: boolean;
|
|
171
172
|
slots: {
|
|
172
173
|
name: string;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -129,7 +129,8 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
129
129
|
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
130
130
|
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
|
131
131
|
const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
132
|
-
const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
|
|
132
|
+
const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
|
|
133
|
+
?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
|
|
133
134
|
return value !== 'false';
|
|
134
135
|
});
|
|
135
136
|
const getComponentSelfName = (0, alien_signals_1.computed)(() => {
|
|
@@ -7,7 +7,7 @@ function* parseCssImports(css) {
|
|
|
7
7
|
for (const match of matches) {
|
|
8
8
|
let text = match[0];
|
|
9
9
|
let offset = match.index;
|
|
10
|
-
if (text.startsWith('
|
|
10
|
+
if (text.startsWith("'") || text.startsWith('"')) {
|
|
11
11
|
text = text.slice(1, -1);
|
|
12
12
|
offset += 1;
|
|
13
13
|
}
|
|
@@ -177,7 +177,8 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByN
|
|
|
177
177
|
if (mapping.data.__combineOffset !== undefined) {
|
|
178
178
|
const offsetMapping = mappings[i - mapping.data.__combineOffset];
|
|
179
179
|
if (typeof offsetMapping === 'string' || !offsetMapping) {
|
|
180
|
-
throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: '
|
|
180
|
+
throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: '
|
|
181
|
+
+ mapping.data.__combineOffset);
|
|
181
182
|
}
|
|
182
183
|
offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
|
|
183
184
|
offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
|
|
@@ -235,16 +236,26 @@ function fullDiffTextChangeRange(oldText, newText) {
|
|
|
235
236
|
}
|
|
236
237
|
function resolveCommonLanguageId(lang) {
|
|
237
238
|
switch (lang) {
|
|
238
|
-
case 'js':
|
|
239
|
-
|
|
240
|
-
case '
|
|
241
|
-
|
|
242
|
-
case '
|
|
243
|
-
|
|
244
|
-
case '
|
|
245
|
-
|
|
246
|
-
case '
|
|
247
|
-
|
|
239
|
+
case 'js':
|
|
240
|
+
return 'javascript';
|
|
241
|
+
case 'cjs':
|
|
242
|
+
return 'javascript';
|
|
243
|
+
case 'mjs':
|
|
244
|
+
return 'javascript';
|
|
245
|
+
case 'ts':
|
|
246
|
+
return 'typescript';
|
|
247
|
+
case 'cts':
|
|
248
|
+
return 'typescript';
|
|
249
|
+
case 'mts':
|
|
250
|
+
return 'typescript';
|
|
251
|
+
case 'jsx':
|
|
252
|
+
return 'javascriptreact';
|
|
253
|
+
case 'tsx':
|
|
254
|
+
return 'typescriptreact';
|
|
255
|
+
case 'pug':
|
|
256
|
+
return 'jade';
|
|
257
|
+
case 'md':
|
|
258
|
+
return 'markdown';
|
|
248
259
|
}
|
|
249
260
|
return lang;
|
|
250
261
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
1
2
|
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
2
3
|
import type * as ts from 'typescript';
|
|
3
4
|
import type { Sfc, VueLanguagePluginReturn } from '../types';
|
|
5
|
+
export declare const templateInlineTsAsts: WeakMap<CompilerDOM.RootNode, Map<string, ts.SourceFile>>;
|
|
4
6
|
export declare function computedSfc(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseResult: () => SFCParseResult | undefined): Sfc;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.templateInlineTsAsts = void 0;
|
|
3
4
|
exports.computedSfc = computedSfc;
|
|
4
5
|
const alien_signals_1 = require("alien-signals");
|
|
5
6
|
const parseCssClassNames_1 = require("../utils/parseCssClassNames");
|
|
6
7
|
const parseCssImports_1 = require("../utils/parseCssImports");
|
|
7
8
|
const parseCssVars_1 = require("../utils/parseCssVars");
|
|
8
9
|
const signals_1 = require("../utils/signals");
|
|
10
|
+
exports.templateInlineTsAsts = new WeakMap();
|
|
9
11
|
function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
10
12
|
const getUntrackedSnapshot = () => {
|
|
11
13
|
const pausedSub = (0, alien_signals_1.setCurrentSub)(undefined);
|
|
@@ -27,9 +29,15 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
27
29
|
const getTemplate = computedNullableSfcBlock('template', 'html', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.template ?? undefined), (_block, base) => {
|
|
28
30
|
const compiledAst = computedTemplateAst(base);
|
|
29
31
|
return mergeObject(base, {
|
|
30
|
-
get ast() {
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
get ast() {
|
|
33
|
+
return compiledAst()?.ast;
|
|
34
|
+
},
|
|
35
|
+
get errors() {
|
|
36
|
+
return compiledAst()?.errors;
|
|
37
|
+
},
|
|
38
|
+
get warnings() {
|
|
39
|
+
return compiledAst()?.warnings;
|
|
40
|
+
},
|
|
33
41
|
});
|
|
34
42
|
});
|
|
35
43
|
const getScript = computedNullableSfcBlock('script', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.script ?? undefined), (block, base) => {
|
|
@@ -44,8 +52,12 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
44
52
|
return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
|
|
45
53
|
});
|
|
46
54
|
return mergeObject(base, {
|
|
47
|
-
get src() {
|
|
48
|
-
|
|
55
|
+
get src() {
|
|
56
|
+
return getSrc();
|
|
57
|
+
},
|
|
58
|
+
get ast() {
|
|
59
|
+
return getAst();
|
|
60
|
+
},
|
|
49
61
|
});
|
|
50
62
|
});
|
|
51
63
|
const getOriginalScriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.scriptSetup ?? undefined), (block, base) => {
|
|
@@ -60,15 +72,19 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
60
72
|
return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
|
|
61
73
|
});
|
|
62
74
|
return mergeObject(base, {
|
|
63
|
-
get generic() {
|
|
64
|
-
|
|
75
|
+
get generic() {
|
|
76
|
+
return getGeneric();
|
|
77
|
+
},
|
|
78
|
+
get ast() {
|
|
79
|
+
return getAst();
|
|
80
|
+
},
|
|
65
81
|
});
|
|
66
82
|
});
|
|
67
83
|
const hasScript = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.script);
|
|
68
84
|
const hasScriptSetup = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.scriptSetup);
|
|
69
85
|
const getScriptSetup = (0, alien_signals_1.computed)(() => {
|
|
70
86
|
if (!hasScript() && !hasScriptSetup()) {
|
|
71
|
-
|
|
87
|
+
// #region monkey fix: https://github.com/vuejs/language-tools/pull/2113
|
|
72
88
|
return {
|
|
73
89
|
content: '',
|
|
74
90
|
lang: 'ts',
|
|
@@ -94,36 +110,67 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
94
110
|
const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
95
111
|
const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
96
112
|
return () => mergeObject(base, {
|
|
97
|
-
get src() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
get
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
get src() {
|
|
114
|
+
return getSrc();
|
|
115
|
+
},
|
|
116
|
+
get module() {
|
|
117
|
+
return getModule();
|
|
118
|
+
},
|
|
119
|
+
get scoped() {
|
|
120
|
+
return getScoped();
|
|
121
|
+
},
|
|
122
|
+
get imports() {
|
|
123
|
+
return getImports();
|
|
124
|
+
},
|
|
125
|
+
get cssVars() {
|
|
126
|
+
return getCssVars();
|
|
127
|
+
},
|
|
128
|
+
get classNames() {
|
|
129
|
+
return getClassNames();
|
|
130
|
+
},
|
|
103
131
|
});
|
|
104
132
|
});
|
|
105
133
|
const customBlocks = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.customBlocks ?? []), (getBlock, i) => {
|
|
106
134
|
const base = computedSfcBlock('custom_block_' + i, 'txt', getBlock);
|
|
107
135
|
const getType = (0, alien_signals_1.computed)(() => getBlock().type);
|
|
108
136
|
return () => mergeObject(base, {
|
|
109
|
-
get type() {
|
|
137
|
+
get type() {
|
|
138
|
+
return getType();
|
|
139
|
+
},
|
|
110
140
|
});
|
|
111
141
|
});
|
|
112
142
|
return {
|
|
113
|
-
get content() {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
get
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
get
|
|
143
|
+
get content() {
|
|
144
|
+
return getContent();
|
|
145
|
+
},
|
|
146
|
+
get comments() {
|
|
147
|
+
return getComments();
|
|
148
|
+
},
|
|
149
|
+
get template() {
|
|
150
|
+
return getTemplate();
|
|
151
|
+
},
|
|
152
|
+
get script() {
|
|
153
|
+
return getScript();
|
|
154
|
+
},
|
|
155
|
+
get scriptSetup() {
|
|
156
|
+
return getScriptSetup();
|
|
157
|
+
},
|
|
158
|
+
get styles() {
|
|
159
|
+
return styles;
|
|
160
|
+
},
|
|
161
|
+
get customBlocks() {
|
|
162
|
+
return customBlocks;
|
|
163
|
+
},
|
|
120
164
|
};
|
|
121
165
|
function computedTemplateAst(base) {
|
|
122
166
|
let cache;
|
|
123
167
|
let inlineTsAsts;
|
|
124
168
|
function updateInlineTsAsts(newAst, oldAst) {
|
|
125
|
-
|
|
126
|
-
|
|
169
|
+
let newTsAsts = exports.templateInlineTsAsts.get(newAst);
|
|
170
|
+
if (!newTsAsts) {
|
|
171
|
+
exports.templateInlineTsAsts.set(newAst, newTsAsts = new Map());
|
|
172
|
+
}
|
|
173
|
+
const oldTsAsts = oldAst && exports.templateInlineTsAsts.get(oldAst) || inlineTsAsts;
|
|
127
174
|
if (oldTsAsts) {
|
|
128
175
|
for (const [text, ast] of oldTsAsts) {
|
|
129
176
|
if (!ast.__volar_used) {
|
|
@@ -238,16 +285,31 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
238
285
|
const getStartTagEnd = (0, alien_signals_1.computed)(() => getBlock().loc.start.offset);
|
|
239
286
|
const getEndTagStart = (0, alien_signals_1.computed)(() => getBlock().loc.end.offset);
|
|
240
287
|
const getStart = (0, alien_signals_1.computed)(() => getUntrackedSnapshot().getText(0, getStartTagEnd()).lastIndexOf('<' + getBlock().type));
|
|
241
|
-
const getEnd = (0, alien_signals_1.computed)(() => getEndTagStart()
|
|
288
|
+
const getEnd = (0, alien_signals_1.computed)(() => getEndTagStart()
|
|
289
|
+
+ getUntrackedSnapshot().getText(getEndTagStart(), getUntrackedSnapshot().getLength()).indexOf('>') + 1);
|
|
242
290
|
return {
|
|
243
291
|
name,
|
|
244
|
-
get lang() {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
get
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
get
|
|
292
|
+
get lang() {
|
|
293
|
+
return getLang();
|
|
294
|
+
},
|
|
295
|
+
get attrs() {
|
|
296
|
+
return getAttrs();
|
|
297
|
+
},
|
|
298
|
+
get content() {
|
|
299
|
+
return getContent();
|
|
300
|
+
},
|
|
301
|
+
get startTagEnd() {
|
|
302
|
+
return getStartTagEnd();
|
|
303
|
+
},
|
|
304
|
+
get endTagStart() {
|
|
305
|
+
return getEndTagStart();
|
|
306
|
+
},
|
|
307
|
+
get start() {
|
|
308
|
+
return getStart();
|
|
309
|
+
},
|
|
310
|
+
get end() {
|
|
311
|
+
return getEnd();
|
|
312
|
+
},
|
|
251
313
|
};
|
|
252
314
|
}
|
|
253
315
|
function computedAttrValue(key, base, getBlock) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
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.15",
|
|
17
17
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
19
|
"alien-signals": "^2.0.5",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^22.10.4",
|
|
26
26
|
"@types/path-browserify": "^1.0.1",
|
|
27
|
-
"@volar/typescript": "2.4.
|
|
27
|
+
"@volar/typescript": "2.4.15",
|
|
28
28
|
"@vue/compiler-sfc": "^3.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"optional": true
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "5cb41faacbfe2d9e2d64637c6c1ae8769d9cba3f"
|
|
39
39
|
}
|