@vue/language-core 3.1.4 → 3.1.5
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 +4 -3
- package/lib/codegen/script/component.js +1 -1
- package/lib/codegen/script/index.js +1 -1
- package/lib/codegen/script/scriptSetup.js +2 -2
- package/lib/codegen/script/src.js +1 -1
- package/lib/codegen/style/classProperty.js +1 -1
- package/lib/codegen/style/imports.js +1 -1
- package/lib/codegen/template/context.d.ts +3 -3
- package/lib/codegen/template/context.js +2 -2
- package/lib/codegen/template/element.js +30 -17
- package/lib/codegen/template/elementDirectives.js +5 -5
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +4 -8
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +38 -83
- package/lib/codegen/template/index.d.ts +3 -3
- package/lib/codegen/template/index.js +2 -2
- package/lib/codegen/template/interpolation.js +38 -39
- package/lib/codegen/template/objectProperty.js +1 -1
- package/lib/codegen/template/slotOutlet.js +5 -10
- package/lib/codegen/template/styleScopedClasses.js +8 -8
- package/lib/codegen/template/vSlot.js +3 -4
- package/lib/codegen/utils/index.d.ts +0 -2
- package/lib/codegen/utils/index.js +0 -11
- package/lib/codegen/utils/stringLiteralKey.js +1 -1
- package/lib/codegen/utils/unicode.js +1 -1
- package/lib/codegen/utils/wrapWith.d.ts +1 -2
- package/lib/codegen/utils/wrapWith.js +1 -10
- package/lib/compilerOptions.d.ts +2 -5
- package/lib/compilerOptions.js +43 -66
- package/lib/languagePlugin.js +16 -23
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +8 -14
- package/lib/plugins/vue-tsx.d.ts +3 -3
- package/lib/plugins/vue-tsx.js +0 -1
- package/lib/utils/parseSfc.js +5 -10
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +8 -0
- package/lib/virtualFile/computedSfc.d.ts +1 -1
- package/lib/virtualFile/computedSfc.js +6 -2
- package/package.json +2 -2
|
@@ -10,44 +10,43 @@ const utils_1 = require("../utils");
|
|
|
10
10
|
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
11
11
|
function* generateInterpolation(options, ctx, source, data, code, start, prefix = '', suffix = '') {
|
|
12
12
|
const { ts, destructuredPropNames, templateRefNames, } = options;
|
|
13
|
-
for (
|
|
14
|
-
if (
|
|
15
|
-
yield
|
|
13
|
+
for (const segment of forEachInterpolationSegment(ts, ctx.inlineTsAsts, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
|
|
14
|
+
if (typeof segment === 'string') {
|
|
15
|
+
yield segment;
|
|
16
|
+
continue;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
let [section, offset, type] = segment;
|
|
19
|
+
offset -= prefix.length;
|
|
20
|
+
let addSuffix = '';
|
|
21
|
+
const overLength = offset + section.length - code.length;
|
|
22
|
+
if (overLength > 0) {
|
|
23
|
+
addSuffix = section.slice(section.length - overLength);
|
|
24
|
+
section = section.slice(0, -overLength);
|
|
25
|
+
}
|
|
26
|
+
if (offset < 0) {
|
|
27
|
+
yield section.slice(0, -offset);
|
|
28
|
+
section = section.slice(-offset);
|
|
29
|
+
offset = 0;
|
|
30
|
+
}
|
|
31
|
+
const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
|
|
32
|
+
if (!shouldSkip) {
|
|
33
|
+
if (start !== undefined && data) {
|
|
34
|
+
yield [
|
|
35
|
+
section,
|
|
36
|
+
source,
|
|
37
|
+
start + offset,
|
|
38
|
+
type === 'errorMappingOnly'
|
|
39
|
+
? codeFeatures_1.codeFeatures.verification
|
|
40
|
+
: typeof data === 'function'
|
|
41
|
+
? data(start + offset)
|
|
42
|
+
: data,
|
|
43
|
+
];
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (start !== undefined
|
|
33
|
-
&& data) {
|
|
34
|
-
yield [
|
|
35
|
-
section,
|
|
36
|
-
source,
|
|
37
|
-
start + offset,
|
|
38
|
-
type === 'errorMappingOnly'
|
|
39
|
-
? codeFeatures_1.codeFeatures.verification
|
|
40
|
-
: typeof data === 'function'
|
|
41
|
-
? data(start + offset)
|
|
42
|
-
: data,
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
yield section;
|
|
47
|
-
}
|
|
45
|
+
else {
|
|
46
|
+
yield section;
|
|
48
47
|
}
|
|
49
|
-
yield addSuffix;
|
|
50
48
|
}
|
|
49
|
+
yield addSuffix;
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
|
|
@@ -82,7 +81,7 @@ function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, t
|
|
|
82
81
|
const lastVarEnd = lastVar ? lastVar.offset + lastVar.text.length : 0;
|
|
83
82
|
if (curVar.isShorthand) {
|
|
84
83
|
yield [code.slice(lastVarEnd, curVar.offset + curVar.text.length), lastVarEnd];
|
|
85
|
-
yield
|
|
84
|
+
yield `: `;
|
|
86
85
|
}
|
|
87
86
|
else {
|
|
88
87
|
yield [code.slice(lastVarEnd, curVar.offset), lastVarEnd, i ? undefined : 'startText'];
|
|
@@ -104,9 +103,9 @@ function* generateVar(templateRefNames, ctx, code, offset, curVar) {
|
|
|
104
103
|
yield ['', curVar.offset, 'errorMappingOnly'];
|
|
105
104
|
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
106
105
|
if (isTemplateRef) {
|
|
107
|
-
yield
|
|
106
|
+
yield `__VLS_unref(`;
|
|
108
107
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
109
|
-
yield
|
|
108
|
+
yield `)`;
|
|
110
109
|
}
|
|
111
110
|
else {
|
|
112
111
|
if (offset !== undefined) {
|
|
@@ -116,10 +115,10 @@ function* generateVar(templateRefNames, ctx, code, offset, curVar) {
|
|
|
116
115
|
ctx.accessExternalVariable(curVar.text);
|
|
117
116
|
}
|
|
118
117
|
if (ctx.dollarVars.has(curVar.text)) {
|
|
119
|
-
yield
|
|
118
|
+
yield `__VLS_dollars.`;
|
|
120
119
|
}
|
|
121
120
|
else {
|
|
122
|
-
yield
|
|
121
|
+
yield `__VLS_ctx.`;
|
|
123
122
|
}
|
|
124
123
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
125
124
|
}
|
|
@@ -21,7 +21,7 @@ function* generateObjectProperty(options, ctx, code, offset, features, shouldCam
|
|
|
21
21
|
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, features);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, features, `'`, ...(0, camelized_1.generateCamelized)(code, 'template', offset, utils_1.combineLastMapping), `'`);
|
|
24
|
+
yield* (0, wrapWith_1.wrapWith)('template', offset, offset + code.length, features, `'`, ...(0, camelized_1.generateCamelized)(code, 'template', offset, utils_1.combineLastMapping), `'`);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
@@ -29,12 +29,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
29
29
|
if (nameProp) {
|
|
30
30
|
let codes;
|
|
31
31
|
if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
|
|
32
|
-
|
|
33
|
-
if (source.startsWith('"') || source.startsWith("'")) {
|
|
34
|
-
source = source.slice(1, -1);
|
|
35
|
-
offset++;
|
|
36
|
-
}
|
|
37
|
-
codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, codeFeatures_1.codeFeatures.navigationAndVerification);
|
|
32
|
+
codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, nameProp.value.content, (0, shared_1.getAttributeValueOffset)(nameProp.value), codeFeatures_1.codeFeatures.navigationAndVerification);
|
|
38
33
|
}
|
|
39
34
|
else if (nameProp.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
40
35
|
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -47,18 +42,18 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
47
42
|
else {
|
|
48
43
|
codes = [`['default']`];
|
|
49
44
|
}
|
|
50
|
-
yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, options.slotsAssignName ?? '__VLS_slots', ...codes);
|
|
45
|
+
yield* (0, wrapWith_1.wrapWith)('template', nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, options.slotsAssignName ?? '__VLS_slots', ...codes);
|
|
51
46
|
}
|
|
52
47
|
else {
|
|
53
|
-
yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
|
|
48
|
+
yield* (0, wrapWith_1.wrapWith)('template', startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)('template', startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
|
|
54
49
|
}
|
|
55
50
|
yield `)(`;
|
|
56
|
-
yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true
|
|
51
|
+
yield* (0, wrapWith_1.wrapWith)('template', startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
|
|
57
52
|
yield `)${utils_1.endOfLine}`;
|
|
58
53
|
}
|
|
59
54
|
else {
|
|
60
55
|
yield `var ${propsVar} = {${utils_1.newLine}`;
|
|
61
|
-
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.checkUnknownProps
|
|
56
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.checkUnknownProps);
|
|
62
57
|
yield `}${utils_1.endOfLine}`;
|
|
63
58
|
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
64
59
|
&& nameProp.value) {
|
|
@@ -22,7 +22,7 @@ function* generateStyleScopedClassReferences(ctx, withDot = false) {
|
|
|
22
22
|
}
|
|
23
23
|
for (const { source, className, offset } of ctx.scopedClasses) {
|
|
24
24
|
yield `/** @type {__VLS_StyleScopedClasses[`;
|
|
25
|
-
yield* (0, wrapWith_1.wrapWith)(offset - (withDot ? 1 : 0), offset + className.length,
|
|
25
|
+
yield* (0, wrapWith_1.wrapWith)(source, offset - (withDot ? 1 : 0), offset + className.length, codeFeatures_1.codeFeatures.navigation, `'`, ...(0, escaped_1.generateEscaped)(className, source, offset, codeFeatures_1.codeFeatures.navigationAndAdditionalCompletion, classNameEscapeRegex), `'`);
|
|
26
26
|
yield `]} */${utils_1.endOfLine}`;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -34,26 +34,26 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
34
34
|
if (options.template.lang === 'pug') {
|
|
35
35
|
const getClassOffset = Reflect.get(prop.value.loc.start, 'getClassOffset');
|
|
36
36
|
const content = prop.value.loc.source.slice(1, -1);
|
|
37
|
-
let
|
|
37
|
+
let offset = 1;
|
|
38
38
|
for (const className of content.split(' ')) {
|
|
39
39
|
if (className) {
|
|
40
40
|
ctx.scopedClasses.push({
|
|
41
41
|
source: 'template',
|
|
42
42
|
className,
|
|
43
|
-
offset: getClassOffset(
|
|
43
|
+
offset: getClassOffset(offset),
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
offset += className.length + 1;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
const
|
|
51
|
-
if (content) {
|
|
52
|
-
const classes = collectClasses(content,
|
|
50
|
+
const offset = (0, shared_1.getAttributeValueOffset)(prop.value);
|
|
51
|
+
if (prop.value.content) {
|
|
52
|
+
const classes = collectClasses(prop.value.content, offset);
|
|
53
53
|
ctx.scopedClasses.push(...classes);
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
ctx.emptyClassOffsets.push(
|
|
56
|
+
ctx.emptyClassOffsets.push(offset);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -20,19 +20,18 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
20
20
|
yield `{${utils_1.newLine}`;
|
|
21
21
|
}
|
|
22
22
|
if (slotDir || node.children.length) {
|
|
23
|
-
ctx.currentComponent.used = true;
|
|
24
23
|
yield `const { `;
|
|
25
24
|
if (slotDir) {
|
|
26
25
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
27
26
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
29
|
+
yield* (0, wrapWith_1.wrapWith)('template', slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
33
|
// #932: reference for implicit default slot
|
|
35
|
-
yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.navigation, `default`);
|
|
34
|
+
yield* (0, wrapWith_1.wrapWith)('template', node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.navigation, `default`);
|
|
36
35
|
}
|
|
37
36
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
38
37
|
}
|
|
@@ -101,7 +100,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
101
100
|
yield `] = __VLS_getSlotParameters(${slotVar}!`;
|
|
102
101
|
if (types.some(t => t)) {
|
|
103
102
|
yield `, `;
|
|
104
|
-
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_`, type, `, `] : `_, `), `) => [] as any`);
|
|
103
|
+
yield* (0, wrapWith_1.wrapWith)('template', exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_`, type, `, `] : `_, `), `) => [] as any`);
|
|
105
104
|
}
|
|
106
105
|
yield `)${utils_1.endOfLine}`;
|
|
107
106
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
2
1
|
import type * as ts from 'typescript';
|
|
3
2
|
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
4
3
|
export declare const newLine = "\n";
|
|
5
4
|
export declare const endOfLine = ";\n";
|
|
6
5
|
export declare const combineLastMapping: VueCodeInformation;
|
|
7
6
|
export declare const identifierRegex: RegExp;
|
|
8
|
-
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number];
|
|
9
7
|
export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
|
|
10
8
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
11
9
|
export declare function generatePartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
-
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
5
4
|
exports.createTsAst = createTsAst;
|
|
6
5
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
7
6
|
exports.generatePartiallyEnding = generatePartiallyEnding;
|
|
@@ -10,16 +9,6 @@ exports.newLine = `\n`;
|
|
|
10
9
|
exports.endOfLine = `;${exports.newLine}`;
|
|
11
10
|
exports.combineLastMapping = { __combineOffset: 1 };
|
|
12
11
|
exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
13
|
-
function normalizeAttributeValue(node) {
|
|
14
|
-
let offset = node.loc.start.offset;
|
|
15
|
-
let content = node.loc.source;
|
|
16
|
-
if ((content.startsWith(`'`) && content.endsWith(`'`))
|
|
17
|
-
|| (content.startsWith(`"`) && content.endsWith(`"`))) {
|
|
18
|
-
offset++;
|
|
19
|
-
content = content.slice(1, -1);
|
|
20
|
-
}
|
|
21
|
-
return [content, offset];
|
|
22
|
-
}
|
|
23
12
|
function createTsAst(ts, inlineTsAsts, text) {
|
|
24
13
|
let ast = inlineTsAsts?.get(text);
|
|
25
14
|
if (!ast) {
|
|
@@ -8,7 +8,7 @@ function* generateStringLiteralKey(code, offset, info) {
|
|
|
8
8
|
yield `'${code}'`;
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, info, `'`, [code, 'template', offset, index_1.combineLastMapping], `'`);
|
|
11
|
+
yield* (0, wrapWith_1.wrapWith)('template', offset, offset + code.length, info, `'`, [code, 'template', offset, index_1.combineLastMapping], `'`);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=stringLiteralKey.js.map
|
|
@@ -4,7 +4,7 @@ exports.generateUnicode = generateUnicode;
|
|
|
4
4
|
const wrapWith_1 = require("./wrapWith");
|
|
5
5
|
function* generateUnicode(code, offset, info) {
|
|
6
6
|
if (needToUnicode(code)) {
|
|
7
|
-
yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, info, toUnicode(code));
|
|
7
|
+
yield* (0, wrapWith_1.wrapWith)('template', offset, offset + code.length, info, toUnicode(code));
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
10
|
yield [code, 'template', offset, info];
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
-
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
|
|
3
|
-
export declare function wrapWith(startOffset: number, endOffset: number, source: string, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
|
|
2
|
+
export declare function wrapWith(source: string, startOffset: number, endOffset: number, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wrapWith = wrapWith;
|
|
4
|
-
function* wrapWith(startOffset, endOffset, ...
|
|
5
|
-
let source = 'template';
|
|
6
|
-
let features;
|
|
7
|
-
let codes;
|
|
8
|
-
if (typeof args[0] === 'string') {
|
|
9
|
-
[source, features, ...codes] = args;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
[features, ...codes] = args;
|
|
13
|
-
}
|
|
4
|
+
function* wrapWith(source, startOffset, endOffset, features, ...codes) {
|
|
14
5
|
yield ['', source, startOffset, features];
|
|
15
6
|
let offset = 1;
|
|
16
7
|
for (const code of codes) {
|
package/lib/compilerOptions.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from './types';
|
|
3
|
-
interface ParseConfigHost extends Omit<ts.ParseConfigHost, 'readDirectory'> {
|
|
4
|
-
}
|
|
5
3
|
export interface ParsedCommandLine extends Omit<ts.ParsedCommandLine, 'fileNames'> {
|
|
6
4
|
vueOptions: VueCompilerOptions;
|
|
7
5
|
}
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
6
|
+
export declare const createParsedCommandLineByJson: (ts: typeof import("typescript"), host: Omit<ts.ParseConfigHost, "readDirectory">, rootDir: string, json: any, configFileName?: string | undefined) => ParsedCommandLine;
|
|
7
|
+
export declare const createParsedCommandLine: (ts: typeof import("typescript"), host: Omit<ts.ParseConfigHost, "readDirectory">, configFileName: string) => ParsedCommandLine;
|
|
10
8
|
export declare class CompilerOptionsResolver {
|
|
11
9
|
fileExists?: ((path: string) => boolean) | undefined;
|
|
12
10
|
options: Omit<RawVueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>;
|
|
@@ -24,4 +22,3 @@ export declare function createGlobalTypesWriter(vueOptions: VueCompilerOptions,
|
|
|
24
22
|
* @deprecated use `createGlobalTypesWriter` instead
|
|
25
23
|
*/
|
|
26
24
|
export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
|
|
27
|
-
export {};
|
package/lib/compilerOptions.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompilerOptionsResolver = void 0;
|
|
4
|
-
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
|
-
exports.createParsedCommandLine = createParsedCommandLine;
|
|
3
|
+
exports.CompilerOptionsResolver = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
|
|
6
4
|
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
5
|
exports.createGlobalTypesWriter = createGlobalTypesWriter;
|
|
8
6
|
exports.writeGlobalTypes = writeGlobalTypes;
|
|
@@ -10,75 +8,54 @@ const shared_1 = require("@vue/shared");
|
|
|
10
8
|
const path_browserify_1 = require("path-browserify");
|
|
11
9
|
const globalTypes_1 = require("./codegen/globalTypes");
|
|
12
10
|
const shared_2 = require("./utils/shared");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
const parsed = ts.parseJsonConfigFileContent(json, proxyHost, rootDir, {}, configFileName);
|
|
28
|
-
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
29
|
-
for (const extendPath of [...extendedPaths].reverse()) {
|
|
11
|
+
exports.createParsedCommandLineByJson = create((ts, host, rootDir, json, configFileName) => {
|
|
12
|
+
// `parseJsonConfigFileContent` is missing in tsc
|
|
13
|
+
return 'parseJsonConfigFileContent' in ts
|
|
14
|
+
? ts.parseJsonConfigFileContent(json, host, rootDir, {}, configFileName)
|
|
15
|
+
: ts.parseJsonSourceFileConfigFileContent(ts.parseJsonText(configFileName ?? 'tsconfig.json', JSON.stringify(json)), host, rootDir, {}, configFileName);
|
|
16
|
+
});
|
|
17
|
+
exports.createParsedCommandLine = create((ts, host, configFileName) => {
|
|
18
|
+
const config = ts.readJsonConfigFile(configFileName, host.readFile);
|
|
19
|
+
return ts.parseJsonSourceFileConfigFileContent(config, host, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
|
|
20
|
+
});
|
|
21
|
+
function create(getParsedCommandLine) {
|
|
22
|
+
return (ts, host, ...args) => {
|
|
30
23
|
try {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
extendedPaths.add(fileName);
|
|
24
|
+
const extendedPaths = new Set();
|
|
25
|
+
const proxyHost = {
|
|
26
|
+
...host,
|
|
27
|
+
readFile(fileName) {
|
|
28
|
+
if (!fileName.endsWith('/package.json')) {
|
|
29
|
+
extendedPaths.add(fileName);
|
|
30
|
+
}
|
|
31
|
+
return host.readFile(fileName);
|
|
32
|
+
},
|
|
33
|
+
readDirectory() {
|
|
34
|
+
return [];
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const parsed = getParsedCommandLine(ts, proxyHost, ...args);
|
|
38
|
+
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
39
|
+
for (const extendPath of [...extendedPaths].reverse()) {
|
|
40
|
+
try {
|
|
41
|
+
const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
|
|
42
|
+
const obj = ts.convertToObject(configFile, []);
|
|
43
|
+
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
44
|
+
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
readDirectory() {
|
|
57
|
-
return [];
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
|
|
61
|
-
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
|
|
62
|
-
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
63
|
-
for (const extendPath of [...extendedPaths].reverse()) {
|
|
64
|
-
try {
|
|
65
|
-
const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
|
|
66
|
-
const obj = ts.convertToObject(configFile, []);
|
|
67
|
-
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
68
|
-
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
46
|
+
catch { }
|
|
69
47
|
}
|
|
70
|
-
|
|
48
|
+
return {
|
|
49
|
+
...parsed,
|
|
50
|
+
vueOptions: resolver.build(),
|
|
51
|
+
};
|
|
71
52
|
}
|
|
53
|
+
catch { }
|
|
72
54
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
options: {},
|
|
56
|
+
errors: [],
|
|
57
|
+
vueOptions: getDefaultCompilerOptions(),
|
|
75
58
|
};
|
|
76
|
-
}
|
|
77
|
-
catch { }
|
|
78
|
-
return {
|
|
79
|
-
options: {},
|
|
80
|
-
errors: [],
|
|
81
|
-
vueOptions: getDefaultCompilerOptions(),
|
|
82
59
|
};
|
|
83
60
|
}
|
|
84
61
|
class CompilerOptionsResolver {
|
package/lib/languagePlugin.js
CHANGED
|
@@ -7,32 +7,21 @@ const language_core_1 = require("@volar/language-core");
|
|
|
7
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
8
|
const plugins_1 = require("./plugins");
|
|
9
9
|
const vueFile_1 = require("./virtualFile/vueFile");
|
|
10
|
-
const fileRegistries =
|
|
11
|
-
function getVueFileRegistry(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fileRegistry = new Map();
|
|
17
|
-
fileRegistries.push({
|
|
18
|
-
key: key,
|
|
19
|
-
plugins: plugins,
|
|
20
|
-
files: fileRegistry,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return fileRegistry;
|
|
24
|
-
}
|
|
25
|
-
function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
|
26
|
-
const values = [
|
|
10
|
+
const fileRegistries = {};
|
|
11
|
+
function getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins) {
|
|
12
|
+
const key = JSON.stringify([
|
|
13
|
+
...plugins.map(plugin => plugin.name)
|
|
14
|
+
.filter(name => typeof name === 'string')
|
|
15
|
+
.sort(),
|
|
27
16
|
...Object.keys(vueCompilerOptions)
|
|
28
|
-
.sort()
|
|
29
17
|
.filter(key => key !== 'plugins')
|
|
18
|
+
.sort()
|
|
30
19
|
.map(key => [key, vueCompilerOptions[key]]),
|
|
31
|
-
[...new Set(plugins.
|
|
20
|
+
...[...new Set(plugins.flatMap(plugin => plugin.requiredCompilerOptions ?? []))]
|
|
32
21
|
.sort()
|
|
33
22
|
.map(key => [key, compilerOptions[key]]),
|
|
34
|
-
];
|
|
35
|
-
return
|
|
23
|
+
]);
|
|
24
|
+
return fileRegistries[key] ??= new Map();
|
|
36
25
|
}
|
|
37
26
|
function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
|
|
38
27
|
const pluginContext = {
|
|
@@ -44,7 +33,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
44
33
|
vueCompilerOptions,
|
|
45
34
|
};
|
|
46
35
|
const plugins = (0, plugins_1.createPlugins)(pluginContext);
|
|
47
|
-
const fileRegistry = getVueFileRegistry(
|
|
36
|
+
const fileRegistry = getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins);
|
|
48
37
|
return {
|
|
49
38
|
getLanguageId(scriptId) {
|
|
50
39
|
const fileName = asFileName(scriptId);
|
|
@@ -70,10 +59,14 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
70
59
|
}
|
|
71
60
|
}
|
|
72
61
|
},
|
|
73
|
-
updateVirtualCode(
|
|
62
|
+
updateVirtualCode(_scriptId, code, snapshot) {
|
|
74
63
|
code.update(snapshot);
|
|
75
64
|
return code;
|
|
76
65
|
},
|
|
66
|
+
disposeVirtualCode(scriptId) {
|
|
67
|
+
const fileName = asFileName(scriptId);
|
|
68
|
+
fileRegistry.delete(fileName);
|
|
69
|
+
},
|
|
77
70
|
typescript: {
|
|
78
71
|
extraFileExtensions: getAllExtensions(vueCompilerOptions)
|
|
79
72
|
.map(ext => ({
|
|
@@ -2,38 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const shouldAddSuffix = /(?<=<[^>/]+)$/;
|
|
4
4
|
const plugin = ({ modules }) => {
|
|
5
|
+
const CompilerDOM = modules['@vue/compiler-dom'];
|
|
5
6
|
return {
|
|
6
7
|
version: 2.2,
|
|
7
8
|
compileSFCTemplate(lang, template, options) {
|
|
8
9
|
if (lang === 'html' || lang === 'md') {
|
|
9
|
-
const compiler = modules['@vue/compiler-dom'];
|
|
10
10
|
let addedSuffix = false;
|
|
11
11
|
// #4583
|
|
12
12
|
if (shouldAddSuffix.test(template)) {
|
|
13
13
|
template += '>';
|
|
14
14
|
addedSuffix = true;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const ast = CompilerDOM.parse(template, {
|
|
17
17
|
...options,
|
|
18
18
|
comments: true,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
CompilerDOM.transform(ast, options);
|
|
21
|
+
return {
|
|
22
|
+
ast,
|
|
23
|
+
code: '',
|
|
24
|
+
preamble: '',
|
|
25
|
+
__addedSuffix: addedSuffix,
|
|
26
|
+
};
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
updateSFCTemplate(oldResult, change) {
|
|
26
|
-
|
|
30
|
+
const newSource = oldResult.ast.source.slice(0, change.start)
|
|
27
31
|
+ change.newText
|
|
28
|
-
+ oldResult.
|
|
32
|
+
+ oldResult.ast.source.slice(change.end);
|
|
29
33
|
// @ts-expect-error
|
|
30
34
|
if (oldResult.__addedSuffix) {
|
|
31
|
-
const originalTemplate =
|
|
35
|
+
const originalTemplate = newSource.slice(0, -1); // remove added '>'
|
|
32
36
|
if (!shouldAddSuffix.test(originalTemplate)) {
|
|
33
37
|
return undefined;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
|
-
const CompilerDOM = modules['@vue/compiler-dom'];
|
|
37
40
|
const lengthDiff = change.newText.length - (change.end - change.start);
|
|
38
41
|
let hitNodes = [];
|
|
39
42
|
if (tryUpdateNode(oldResult.ast) && hitNodes.length) {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
4
|
const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
|
|
5
|
-
const shared_1 = require("
|
|
5
|
+
const shared_1 = require("../utils/shared");
|
|
6
|
+
const shared_2 = require("./shared");
|
|
6
7
|
const codeFeatures = {
|
|
7
|
-
...
|
|
8
|
+
...shared_2.allCodeFeatures,
|
|
8
9
|
format: false,
|
|
9
10
|
structure: false,
|
|
10
11
|
};
|
|
@@ -30,21 +31,14 @@ exports.default = plugin;
|
|
|
30
31
|
function* generate(templateAst) {
|
|
31
32
|
for (const node of (0, forEachTemplateNode_1.forEachElementNode)(templateAst)) {
|
|
32
33
|
for (const prop of node.props) {
|
|
33
|
-
if (prop.type === CompilerDOM.NodeTypes.
|
|
34
|
-
&& prop.name === '
|
|
35
|
-
&& prop.
|
|
36
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
37
|
-
&& prop.arg.content === 'style'
|
|
38
|
-
&& prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
39
|
-
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
|
|
40
|
-
const start = prop.arg.loc.source.indexOf(endCrt) + 1;
|
|
41
|
-
const end = prop.arg.loc.source.lastIndexOf(endCrt);
|
|
42
|
-
const content = prop.arg.loc.source.slice(start, end);
|
|
34
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
35
|
+
&& prop.name === 'style'
|
|
36
|
+
&& prop.value) {
|
|
43
37
|
yield `x { `;
|
|
44
38
|
yield [
|
|
45
|
-
content,
|
|
39
|
+
prop.value.content,
|
|
46
40
|
'template',
|
|
47
|
-
prop.
|
|
41
|
+
(0, shared_1.getAttributeValueOffset)(prop.value),
|
|
48
42
|
codeFeatures,
|
|
49
43
|
];
|
|
50
44
|
yield ` }\n`;
|