@vue/language-core 3.0.0-beta.2 → 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/codeFeatures.d.ts +5 -1
- package/lib/codegen/codeFeatures.js +3 -1
- package/lib/codegen/globalTypes.js +10 -9
- package/lib/codegen/localTypes.js +22 -8
- package/lib/codegen/script/component.js +2 -1
- package/lib/codegen/script/scriptSetup.js +53 -35
- package/lib/codegen/script/template.js +0 -1
- package/lib/codegen/style/classProperty.js +1 -1
- package/lib/codegen/style/imports.js +2 -2
- package/lib/codegen/style/scopedClasses.js +1 -1
- package/lib/codegen/template/context.d.ts +3 -2
- package/lib/codegen/template/context.js +4 -2
- package/lib/codegen/template/element.js +12 -12
- package/lib/codegen/template/elementDirectives.js +1 -1
- package/lib/codegen/template/elementEvents.js +9 -9
- package/lib/codegen/template/elementProps.js +4 -4
- package/lib/codegen/template/index.js +4 -4
- package/lib/codegen/template/interpolation.d.ts +3 -6
- package/lib/codegen/template/interpolation.js +11 -12
- package/lib/codegen/template/objectProperty.d.ts +1 -1
- package/lib/codegen/template/objectProperty.js +4 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +2 -2
- package/lib/codegen/template/slotOutlet.js +4 -3
- package/lib/codegen/template/styleScopedClasses.js +4 -4
- package/lib/codegen/template/templateChild.js +3 -2
- package/lib/codegen/template/vFor.js +3 -3
- package/lib/codegen/template/vIf.js +1 -1
- package/lib/codegen/template/vSlot.js +2 -2
- package/lib/codegen/utils/escaped.d.ts +1 -1
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +7 -5
- package/lib/codegen/utils/wrapWith.d.ts +1 -1
- package/lib/languagePlugin.js +6 -3
- package/lib/parsers/scriptSetupRanges.js +14 -18
- package/lib/parsers/vueCompilerOptions.js +0 -1
- package/lib/plugins/file-html.js +6 -6
- package/lib/plugins/file-md.js +6 -5
- 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 +4 -2
- package/lib/plugins/vue-tsx.d.ts +2 -1
- package/lib/plugins/vue-tsx.js +2 -1
- package/lib/utils/parseCssImports.js +1 -1
- package/lib/utils/parseSfc.js +3 -3
- package/lib/utils/ts.js +9 -9
- package/lib/virtualFile/computedEmbeddedCodes.js +22 -11
- package/lib/virtualFile/computedSfc.d.ts +2 -0
- package/lib/virtualFile/computedSfc.js +114 -31
- package/package.json +4 -4
|
@@ -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
|
}
|
|
@@ -38,7 +38,7 @@ function* generateTemplate(options) {
|
|
|
38
38
|
['$slots', yield* generateSlots(options, ctx)],
|
|
39
39
|
['$attrs', yield* generateInheritedAttrs(options, ctx)],
|
|
40
40
|
['$refs', yield* generateTemplateRefs(options, ctx)],
|
|
41
|
-
['$el', yield* generateRootEl(ctx)]
|
|
41
|
+
['$el', yield* generateRootEl(ctx)],
|
|
42
42
|
];
|
|
43
43
|
yield `var __VLS_dollars!: {${utils_1.newLine}`;
|
|
44
44
|
for (const [name, type] of speicalTypes) {
|
|
@@ -56,7 +56,7 @@ function* generateSlots(options, ctx) {
|
|
|
56
56
|
for (const slot of ctx.slots) {
|
|
57
57
|
yield `${utils_1.newLine}& { `;
|
|
58
58
|
if (slot.name && slot.offset !== undefined) {
|
|
59
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion
|
|
59
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
@@ -81,7 +81,7 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
81
81
|
loc.source,
|
|
82
82
|
'template',
|
|
83
83
|
loc.start.offset,
|
|
84
|
-
ctx.codeFeatures.all
|
|
84
|
+
ctx.codeFeatures.all,
|
|
85
85
|
];
|
|
86
86
|
yield `,`;
|
|
87
87
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { ScriptCodegenOptions } from '../script';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
destructuredPropNames: Set<string> | undefined;
|
|
7
|
-
templateRefNames: Set<string> | undefined;
|
|
8
|
-
}, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, code: string, start: number | undefined, astHolder?: any, prefix?: string, suffix?: string): Generator<Code>;
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateInterpolation(options: TemplateCodegenOptions | ScriptCodegenOptions, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, code: string, start: number | undefined, prefix?: string, suffix?: string): Generator<Code>;
|
|
@@ -6,8 +6,9 @@ const shared_2 = require("../../utils/shared");
|
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
|
8
8
|
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
9
|
-
function* generateInterpolation(options, ctx, source, data, code, start,
|
|
10
|
-
|
|
9
|
+
function* generateInterpolation(options, ctx, source, data, code, start, prefix = '', suffix = '') {
|
|
10
|
+
const { ts, destructuredPropNames, templateRefNames, } = options;
|
|
11
|
+
for (let [section, offset, type] of forEachInterpolationSegment(ts, ctx.inlineTsAsts, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
|
|
11
12
|
if (offset === undefined) {
|
|
12
13
|
yield section;
|
|
13
14
|
}
|
|
@@ -34,7 +35,9 @@ function* generateInterpolation(options, ctx, source, data, code, start, astHold
|
|
|
34
35
|
start + offset,
|
|
35
36
|
type === 'errorMappingOnly'
|
|
36
37
|
? ctx.codeFeatures.verification
|
|
37
|
-
: typeof data === 'function'
|
|
38
|
+
: typeof data === 'function'
|
|
39
|
+
? data(start + offset)
|
|
40
|
+
: data,
|
|
38
41
|
];
|
|
39
42
|
}
|
|
40
43
|
else {
|
|
@@ -45,8 +48,7 @@ function* generateInterpolation(options, ctx, source, data, code, start, astHold
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, originalCode, start, astHolder, prefix, suffix) {
|
|
51
|
+
function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
|
|
50
52
|
const code = prefix + originalCode + suffix;
|
|
51
53
|
const offset = start !== undefined ? start - prefix.length : undefined;
|
|
52
54
|
let ctxVars = [];
|
|
@@ -57,7 +59,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
60
|
-
const ast = (0, utils_1.createTsAst)(ts,
|
|
62
|
+
const ast = (0, utils_1.createTsAst)(ts, inlineTsAsts, code);
|
|
61
63
|
const varCb = (id, isShorthand) => {
|
|
62
64
|
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
63
65
|
if (!shouldIdentifierSkipped(ctx, text, destructuredPropNames)) {
|
|
@@ -150,17 +152,14 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
|
|
|
150
152
|
walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars, false);
|
|
151
153
|
}
|
|
152
154
|
walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars, false);
|
|
153
|
-
}
|
|
154
|
-
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
155
|
+
} // fix https://github.com/vuejs/language-tools/issues/1156
|
|
155
156
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
156
157
|
walkIdentifiers(ts, prop, ast, cb, ctx, blockVars, false);
|
|
157
|
-
}
|
|
158
|
-
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
158
|
+
} // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
159
159
|
else if (ts.isSpreadAssignment(prop)) {
|
|
160
160
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
161
161
|
walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
|
|
162
|
-
}
|
|
163
|
-
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
162
|
+
} // fix https://github.com/vuejs/language-tools/issues/4604
|
|
164
163
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
165
164
|
processFunction(ts, prop, ast, cb, ctx);
|
|
166
165
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from './context';
|
|
3
3
|
import type { TemplateCodegenOptions } from './index';
|
|
4
|
-
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation,
|
|
4
|
+
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, shouldCamelize?: boolean, shouldBeConstant?: boolean): Generator<Code>;
|
|
@@ -7,13 +7,13 @@ const camelized_1 = require("../utils/camelized");
|
|
|
7
7
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
8
8
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
|
-
function* generateObjectProperty(options, ctx, code, offset, features,
|
|
11
|
-
if (code.startsWith('[') && code.endsWith(']')
|
|
10
|
+
function* generateObjectProperty(options, ctx, code, offset, features, shouldCamelize = false, shouldBeConstant = false) {
|
|
11
|
+
if (code.startsWith('[') && code.endsWith(']')) {
|
|
12
12
|
if (shouldBeConstant) {
|
|
13
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code.slice(1, -1), offset + 1,
|
|
13
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code.slice(1, -1), offset + 1, `[__VLS_tryAsConstant(`, `)]`);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset
|
|
16
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
else if (shouldCamelize) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from './context';
|
|
3
3
|
import type { TemplateCodegenOptions } from './index';
|
|
4
|
-
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation
|
|
4
|
+
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation): Generator<Code>;
|
|
@@ -4,7 +4,7 @@ exports.generatePropertyAccess = generatePropertyAccess;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
6
6
|
const interpolation_1 = require("./interpolation");
|
|
7
|
-
function* generatePropertyAccess(options, ctx, code, offset, features
|
|
7
|
+
function* generatePropertyAccess(options, ctx, code, offset, features) {
|
|
8
8
|
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && utils_1.identifierRegex.test(code)) {
|
|
9
9
|
yield `.`;
|
|
10
10
|
yield offset !== undefined && features
|
|
@@ -12,7 +12,7 @@ function* generatePropertyAccess(options, ctx, code, offset, features, astHolder
|
|
|
12
12
|
: code;
|
|
13
13
|
}
|
|
14
14
|
else if (code.startsWith('[') && code.endsWith(']')) {
|
|
15
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset
|
|
15
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
yield `[`;
|
|
@@ -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 => {
|
|
@@ -40,7 +41,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
40
41
|
codes = [
|
|
41
42
|
`[`,
|
|
42
43
|
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp),
|
|
43
|
-
`]
|
|
44
|
+
`]`,
|
|
44
45
|
];
|
|
45
46
|
}
|
|
46
47
|
else {
|
|
@@ -77,7 +78,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
77
78
|
}
|
|
78
79
|
const expVar = ctx.getInternalVariable();
|
|
79
80
|
yield `var ${expVar} = __VLS_tryAsConstant(`;
|
|
80
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset
|
|
81
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
|
|
81
82
|
yield `)${utils_1.endOfLine}`;
|
|
82
83
|
ctx.dynamicSlots.push({
|
|
83
84
|
expVar: ctx.getHoistVariable(expVar),
|
|
@@ -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;
|
|
@@ -130,7 +130,7 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
130
130
|
ctx.scopedClasses.push({
|
|
131
131
|
source: 'template',
|
|
132
132
|
className: text,
|
|
133
|
-
offset: node.end - text.length + startOffset
|
|
133
|
+
offset: node.end - text.length + startOffset,
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -146,7 +146,7 @@ function collectClasses(content, startOffset = 0) {
|
|
|
146
146
|
classes.push({
|
|
147
147
|
source: 'template',
|
|
148
148
|
className: currentClassName,
|
|
149
|
-
offset: offset + startOffset
|
|
149
|
+
offset: offset + startOffset,
|
|
150
150
|
});
|
|
151
151
|
offset += currentClassName.length;
|
|
152
152
|
currentClassName = '';
|
|
@@ -83,7 +83,7 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
83
83
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
84
84
|
// {{ ... }}
|
|
85
85
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
86
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start,
|
|
86
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
|
|
87
87
|
}
|
|
88
88
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
89
89
|
// v-if / v-else-if / v-else
|
|
@@ -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,
|
|
@@ -24,7 +24,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
24
24
|
yield `] of `;
|
|
25
25
|
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
26
|
yield `__VLS_getVForSourceType(`;
|
|
27
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset,
|
|
27
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
|
|
28
28
|
yield `!)`; // #3102
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -46,7 +46,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
46
46
|
for (const prop of argument.returns.props.properties) {
|
|
47
47
|
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
48
48
|
&& !prop.value.isStatic) {
|
|
49
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset,
|
|
49
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
|
|
50
50
|
yield utils_1.endOfLine;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -21,7 +21,7 @@ function* generateVIf(options, ctx, node) {
|
|
|
21
21
|
}
|
|
22
22
|
let addedBlockCondition = false;
|
|
23
23
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
24
|
-
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset,
|
|
24
|
+
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
|
|
25
25
|
yield* codes;
|
|
26
26
|
ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
|
|
27
27
|
addedBlockCondition = true;
|
|
@@ -21,7 +21,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
21
21
|
yield `const { `;
|
|
22
22
|
if (slotDir) {
|
|
23
23
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
24
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all,
|
|
24
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, false, true);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
@@ -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,12 +49,14 @@ function normalizeAttributeValue(node) {
|
|
|
49
49
|
}
|
|
50
50
|
return [content, offset];
|
|
51
51
|
}
|
|
52
|
-
function createTsAst(ts,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
function createTsAst(ts, inlineTsAsts, text) {
|
|
53
|
+
let ast = inlineTsAsts?.get(text);
|
|
54
|
+
if (!ast) {
|
|
55
|
+
ast = ts.createSourceFile('/a.ts', text, 99);
|
|
56
|
+
inlineTsAsts?.set(text, ast);
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
ast.__volar_used = true;
|
|
59
|
+
return ast;
|
|
58
60
|
}
|
|
59
61
|
function generateSfcBlockSection(block, start, end, features) {
|
|
60
62
|
return [
|
|
@@ -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
|
}
|
|
@@ -143,7 +143,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
143
143
|
defineProps = {
|
|
144
144
|
...parseCallExpressionAssignment(node, parent),
|
|
145
145
|
statement: getStatementRange(ts, parents, node, ast),
|
|
146
|
-
argNode: node.arguments[0]
|
|
146
|
+
argNode: node.arguments[0],
|
|
147
147
|
};
|
|
148
148
|
if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
|
|
149
149
|
defineProps.destructured = new Map();
|
|
@@ -172,13 +172,13 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
172
172
|
callExp: _getStartEnd(node),
|
|
173
173
|
exp: _getStartEnd(node.expression),
|
|
174
174
|
arg: arg ? _getStartEnd(arg) : undefined,
|
|
175
|
-
argNode: arg
|
|
175
|
+
argNode: arg,
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
179
179
|
defineEmits = {
|
|
180
180
|
...parseCallExpressionAssignment(node, parent),
|
|
181
|
-
statement: getStatementRange(ts, parents, node, ast)
|
|
181
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
182
182
|
};
|
|
183
183
|
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
|
|
184
184
|
for (const member of node.typeArguments[0].members) {
|
|
@@ -195,7 +195,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
195
195
|
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
196
196
|
defineSlots = {
|
|
197
197
|
...parseCallExpressionAssignment(node, parent),
|
|
198
|
-
statement: getStatementRange(ts, parents, node, ast)
|
|
198
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
@@ -274,20 +274,20 @@ function parseBindingRanges(ts, ast) {
|
|
|
274
274
|
else if (ts.isFunctionDeclaration(node)) {
|
|
275
275
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
276
276
|
bindings.push({
|
|
277
|
-
range: _getStartEnd(node.name)
|
|
277
|
+
range: _getStartEnd(node.name),
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
else if (ts.isClassDeclaration(node)) {
|
|
282
282
|
if (node.name) {
|
|
283
283
|
bindings.push({
|
|
284
|
-
range: _getStartEnd(node.name)
|
|
284
|
+
range: _getStartEnd(node.name),
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
else if (ts.isEnumDeclaration(node)) {
|
|
289
289
|
bindings.push({
|
|
290
|
-
range: _getStartEnd(node.name)
|
|
290
|
+
range: _getStartEnd(node.name),
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
if (ts.isImportDeclaration(node)) {
|
|
@@ -298,7 +298,7 @@ function parseBindingRanges(ts, ast) {
|
|
|
298
298
|
bindings.push({
|
|
299
299
|
range: _getStartEnd(name),
|
|
300
300
|
moduleName,
|
|
301
|
-
isDefaultImport: true
|
|
301
|
+
isDefaultImport: true,
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
304
|
if (namedBindings) {
|
|
@@ -310,7 +310,7 @@ function parseBindingRanges(ts, ast) {
|
|
|
310
310
|
bindings.push({
|
|
311
311
|
range: _getStartEnd(element.name),
|
|
312
312
|
moduleName,
|
|
313
|
-
isDefaultImport: element.propertyName?.text === 'default'
|
|
313
|
+
isDefaultImport: element.propertyName?.text === 'default',
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -318,7 +318,7 @@ function parseBindingRanges(ts, ast) {
|
|
|
318
318
|
bindings.push({
|
|
319
319
|
range: _getStartEnd(namedBindings.name),
|
|
320
320
|
moduleName,
|
|
321
|
-
isNamespace: true
|
|
321
|
+
isNamespace: true,
|
|
322
322
|
});
|
|
323
323
|
}
|
|
324
324
|
}
|
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const sfcBlockReg =
|
|
4
|
-
const langReg = /\blang\s*=\s*(['
|
|
3
|
+
const sfcBlockReg = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
|
|
4
|
+
const langReg = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
|
|
5
5
|
const plugin = ({ vueCompilerOptions }) => {
|
|
6
6
|
return {
|
|
7
7
|
version: 2.1,
|
|
@@ -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: {},
|
|
@@ -83,7 +83,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
83
83
|
ast: {},
|
|
84
84
|
};
|
|
85
85
|
return sfc;
|
|
86
|
-
}
|
|
86
|
+
},
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
89
|
exports.default = plugin;
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -8,9 +8,9 @@ const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
|
|
|
8
8
|
const codeblockReg = /(`{3,})[\s\S]+?\1/g;
|
|
9
9
|
const inlineCodeblockReg = /`[^\n`]+?`/g;
|
|
10
10
|
const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
|
|
11
|
-
const scriptSetupReg =
|
|
12
|
-
const sfcBlockReg =
|
|
13
|
-
const angleBracketReg =
|
|
11
|
+
const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
|
|
12
|
+
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
13
|
+
const angleBracketReg = /<\S*:\S*>/g;
|
|
14
14
|
const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
|
|
15
15
|
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
16
16
|
const plugin = ({ vueCompilerOptions }) => {
|
|
@@ -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
|
|
@@ -92,7 +93,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
92
93
|
break;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
}
|
|
96
|
+
},
|
|
96
97
|
};
|
|
97
98
|
};
|
|
98
99
|
exports.default = plugin;
|
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
|
}
|
|
@@ -179,7 +181,7 @@ const plugin = ctx => {
|
|
|
179
181
|
else {
|
|
180
182
|
addFormatCodes(content, start, [
|
|
181
183
|
firstLineEmpty ? '(' : '(0 +',
|
|
182
|
-
lastLineEmpty ? ');' : '+ 0);'
|
|
184
|
+
lastLineEmpty ? ');' : '+ 0);',
|
|
183
185
|
]);
|
|
184
186
|
}
|
|
185
187
|
}
|