@vue/language-core 3.3.5 → 3.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/lib/codegen/codeFeatures.d.ts +24 -84
- package/lib/codegen/codeFeatures.js +46 -4
- package/lib/codegen/names.d.ts +3 -4
- package/lib/codegen/names.js +3 -4
- package/lib/codegen/script/index.js +5 -5
- package/lib/codegen/script/scriptSetup.js +4 -4
- package/lib/codegen/style/common.js +7 -11
- package/lib/codegen/style/index.d.ts +55 -27
- package/lib/codegen/style/index.js +3 -3
- package/lib/codegen/template/context.d.ts +55 -124
- package/lib/codegen/template/context.js +187 -269
- package/lib/codegen/template/element.js +16 -15
- package/lib/codegen/template/elementDirectives.js +11 -11
- package/lib/codegen/template/elementEvents.js +45 -44
- package/lib/codegen/template/elementProps.js +12 -12
- package/lib/codegen/template/index.d.ts +55 -27
- package/lib/codegen/template/index.js +7 -7
- package/lib/codegen/template/interpolation.js +28 -28
- package/lib/codegen/template/objectProperty.js +5 -5
- package/lib/codegen/template/propertyAccess.js +1 -1
- package/lib/codegen/template/slotOutlet.js +8 -10
- package/lib/codegen/template/styleScopedClasses.js +4 -4
- package/lib/codegen/template/vFor.js +3 -3
- package/lib/codegen/template/vIf.js +4 -4
- package/lib/codegen/template/vSlot.js +9 -9
- package/lib/codegen/utils/boundary.d.ts +7 -2
- package/lib/codegen/utils/boundary.js +15 -9
- package/lib/codegen/utils/camelized.js +5 -13
- package/lib/codegen/utils/escaped.js +4 -9
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +3 -3
- package/lib/codegen/utils/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +1 -1
- package/lib/codegen/utils/unicode.js +4 -4
- package/lib/languagePlugin.js +2 -1
- package/lib/parsers/scriptRanges.d.ts +2 -2
- package/lib/parsers/scriptRanges.js +3 -10
- package/lib/parsers/scriptSetupRanges.d.ts +2 -2
- package/lib/parsers/scriptSetupRanges.js +3 -10
- package/lib/parsers/utils.d.ts +1 -0
- package/lib/parsers/utils.js +10 -0
- package/lib/parsers/vueCompilerOptions.js +2 -2
- package/lib/plugins/file-html.js +4 -4
- package/lib/plugins/file-md.js +15 -15
- package/lib/plugins/file-vue.js +2 -2
- package/lib/plugins/vue-root-tags.js +3 -3
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -4
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-style-css.js +86 -33
- package/lib/plugins/vue-template-html.js +3 -3
- package/lib/plugins/vue-template-inline-css.js +2 -7
- package/lib/plugins/vue-template-inline-ts.js +4 -5
- package/lib/plugins/vue-tsx.d.ts +61 -31
- package/lib/plugins/vue-tsx.js +26 -23
- package/lib/plugins.d.ts +0 -1
- package/lib/plugins.js +0 -15
- package/lib/utils/forEachTemplateNode.js +36 -43
- package/lib/virtualCode/index.js +2 -2
- package/package.json +2 -2
- package/types/template-helpers.d.ts +14 -24
- package/lib/plugins/shared.d.ts +0 -2
- package/lib/plugins/shared.js +0 -12
|
@@ -45,11 +45,11 @@ const templateChild_1 = require("./templateChild");
|
|
|
45
45
|
function* generateVFor(options, ctx, node) {
|
|
46
46
|
const { source } = node.parseResult;
|
|
47
47
|
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
48
|
-
const
|
|
48
|
+
const scope = ctx.scope();
|
|
49
49
|
yield `for (const [`;
|
|
50
50
|
if (leftExpressionRange && leftExpressionText) {
|
|
51
51
|
const collectAst = (0, utils_1.getTypeScriptAST)(options.typescript, options.template, `const [${leftExpressionText}]`);
|
|
52
|
-
|
|
52
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(options.typescript, collectAst, collectAst));
|
|
53
53
|
yield [
|
|
54
54
|
leftExpressionText,
|
|
55
55
|
'template',
|
|
@@ -73,7 +73,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
73
73
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, false, true);
|
|
74
74
|
}
|
|
75
75
|
ctx.inVFor = inVFor;
|
|
76
|
-
yield*
|
|
76
|
+
yield* scope.end();
|
|
77
77
|
yield `}${utils_1.newLine}`;
|
|
78
78
|
}
|
|
79
79
|
function parseVForNode(node) {
|
|
@@ -41,7 +41,7 @@ const utils_1 = require("../utils");
|
|
|
41
41
|
const interpolation_1 = require("./interpolation");
|
|
42
42
|
const templateChild_1 = require("./templateChild");
|
|
43
43
|
function* generateVIf(options, ctx, node) {
|
|
44
|
-
const originalBlockConditionsLength = ctx.
|
|
44
|
+
const originalBlockConditionsLength = ctx.conditions.length;
|
|
45
45
|
for (let i = 0; i < node.branches.length; i++) {
|
|
46
46
|
const branch = node.branches[i];
|
|
47
47
|
if (i === 0) {
|
|
@@ -57,7 +57,7 @@ function* generateVIf(options, ctx, node) {
|
|
|
57
57
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
58
58
|
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
|
|
59
59
|
yield* codes;
|
|
60
|
-
ctx.
|
|
60
|
+
ctx.conditions.push((0, muggle_string_1.toString)(codes));
|
|
61
61
|
addedBlockCondition = true;
|
|
62
62
|
yield ` `;
|
|
63
63
|
}
|
|
@@ -67,9 +67,9 @@ function* generateVIf(options, ctx, node) {
|
|
|
67
67
|
}
|
|
68
68
|
yield `}${utils_1.newLine}`;
|
|
69
69
|
if (addedBlockCondition) {
|
|
70
|
-
ctx.
|
|
70
|
+
ctx.conditions[ctx.conditions.length - 1] = `!${ctx.conditions[ctx.conditions.length - 1]}`;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
ctx.
|
|
73
|
+
ctx.conditions.length = originalBlockConditionsLength;
|
|
74
74
|
}
|
|
75
75
|
//# sourceMappingURL=vIf.js.map
|
|
@@ -53,29 +53,29 @@ function* generateVSlot(options, ctx, node, slotDir, ctxVar) {
|
|
|
53
53
|
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);
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
const
|
|
56
|
+
const boundary = yield* boundary_1.Boundary.start('template', slotDir.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
57
57
|
yield `default`;
|
|
58
|
-
yield
|
|
58
|
+
yield boundary.end(slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
yield `const { `;
|
|
63
63
|
// #932: reference for implicit default slot
|
|
64
|
-
const
|
|
64
|
+
const boundary = yield* boundary_1.Boundary.start('template', node.loc.start.offset, codeFeatures_1.codeFeatures.navigation);
|
|
65
65
|
yield `default`;
|
|
66
|
-
yield
|
|
66
|
+
yield boundary.end(node.loc.end.offset);
|
|
67
67
|
}
|
|
68
68
|
yield `: ${slotVar} } = ${ctxVar}.slots!${utils_1.endOfLine}`;
|
|
69
|
-
const
|
|
69
|
+
const scope = ctx.scope();
|
|
70
70
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
71
71
|
const slotAst = (0, utils_1.getTypeScriptAST)(options.typescript, options.template, `(${slotDir.exp.content}) => {}`);
|
|
72
72
|
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
73
|
-
|
|
73
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(options.typescript, slotAst, slotAst));
|
|
74
74
|
}
|
|
75
75
|
for (const child of node.children) {
|
|
76
76
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
77
77
|
}
|
|
78
|
-
yield*
|
|
78
|
+
yield* scope.end();
|
|
79
79
|
if (slotDir) {
|
|
80
80
|
let isStatic = true;
|
|
81
81
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -129,11 +129,11 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
129
129
|
yield `] = ${names_1.names.vSlot}(${slotVar}!`;
|
|
130
130
|
if (types.some(t => t)) {
|
|
131
131
|
yield `, `;
|
|
132
|
-
const
|
|
132
|
+
const boundary = yield* boundary_1.Boundary.start('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
133
133
|
yield `(`;
|
|
134
134
|
yield* types.flatMap(type => type ? [`_`, type, `, `] : `_, `);
|
|
135
135
|
yield `) => [] as any`;
|
|
136
|
-
yield
|
|
136
|
+
yield boundary.end(exp.loc.end.offset);
|
|
137
137
|
}
|
|
138
138
|
yield `)${utils_1.endOfLine}`;
|
|
139
139
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
-
export declare
|
|
3
|
-
|
|
2
|
+
export declare class Boundary {
|
|
3
|
+
source: string;
|
|
4
|
+
features: VueCodeInformation;
|
|
5
|
+
private constructor();
|
|
6
|
+
static start(source: string, offset: number, features: VueCodeInformation): Generator<Code, Boundary>;
|
|
7
|
+
end(offset: number): Code;
|
|
8
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
exports.Boundary = void 0;
|
|
4
|
+
class Boundary {
|
|
5
|
+
constructor(source, features) {
|
|
6
|
+
this.source = source;
|
|
7
|
+
this.features = features;
|
|
8
|
+
}
|
|
9
|
+
static *start(source, offset, features) {
|
|
10
|
+
features = { ...features, __combineToken: Symbol() };
|
|
11
|
+
yield [``, source, offset, features];
|
|
12
|
+
return new Boundary(source, features);
|
|
13
|
+
}
|
|
14
|
+
end(offset) {
|
|
15
|
+
return [``, this.source, offset, this.features];
|
|
16
|
+
}
|
|
12
17
|
}
|
|
18
|
+
exports.Boundary = Boundary;
|
|
13
19
|
//# sourceMappingURL=boundary.js.map
|
|
@@ -4,25 +4,17 @@ exports.generateCamelized = generateCamelized;
|
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
5
|
function* generateCamelized(code, source, offset, features) {
|
|
6
6
|
const parts = code.split('-');
|
|
7
|
-
|
|
7
|
+
if (!features.__combineToken) {
|
|
8
|
+
features = { ...features, __combineToken: Symbol() };
|
|
9
|
+
}
|
|
8
10
|
for (let i = 0; i < parts.length; i++) {
|
|
9
11
|
const part = parts[i];
|
|
10
12
|
if (part !== '') {
|
|
11
13
|
if (i === 0) {
|
|
12
|
-
yield [
|
|
13
|
-
part,
|
|
14
|
-
source,
|
|
15
|
-
offset,
|
|
16
|
-
{ ...features, __combineToken: combineToken },
|
|
17
|
-
];
|
|
14
|
+
yield [part, source, offset, features];
|
|
18
15
|
}
|
|
19
16
|
else {
|
|
20
|
-
yield [
|
|
21
|
-
(0, shared_1.capitalize)(part),
|
|
22
|
-
source,
|
|
23
|
-
offset,
|
|
24
|
-
{ __combineToken: combineToken },
|
|
25
|
-
];
|
|
17
|
+
yield [(0, shared_1.capitalize)(part), source, offset, features];
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
20
|
offset += part.length + 1;
|
|
@@ -3,21 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateEscaped = generateEscaped;
|
|
4
4
|
function* generateEscaped(text, source, offset, features, escapeTarget) {
|
|
5
5
|
const parts = text.split(escapeTarget);
|
|
6
|
-
|
|
6
|
+
if (!features.__combineToken) {
|
|
7
|
+
features = { ...features, __combineToken: Symbol() };
|
|
8
|
+
}
|
|
7
9
|
let isEscapeTarget = false;
|
|
8
10
|
for (let i = 0; i < parts.length; i++) {
|
|
9
11
|
const part = parts[i];
|
|
10
12
|
if (isEscapeTarget) {
|
|
11
13
|
yield `\\`;
|
|
12
14
|
}
|
|
13
|
-
yield [
|
|
14
|
-
part,
|
|
15
|
-
source,
|
|
16
|
-
offset,
|
|
17
|
-
i === 0
|
|
18
|
-
? { ...features, __combineToken: combineToken }
|
|
19
|
-
: { __combineToken: combineToken },
|
|
20
|
-
];
|
|
15
|
+
yield [part, source, offset, features];
|
|
21
16
|
offset += part.length;
|
|
22
17
|
isEscapeTarget = !isEscapeTarget;
|
|
23
18
|
}
|
|
@@ -2,7 +2,7 @@ import type * as ts from 'typescript';
|
|
|
2
2
|
import type { Code, IRBlock, IRScript, IRScriptSetup, VueCodeInformation } from '../../types';
|
|
3
3
|
export declare const newLine = "\n";
|
|
4
4
|
export declare const endOfLine = ";\n";
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const identifierRE: RegExp;
|
|
6
6
|
export declare function getTypeScriptAST(ts: typeof import('typescript'), block: IRBlock, text: string): ts.SourceFile;
|
|
7
7
|
export declare function generateSfcBlockSection(block: IRScript | IRScriptSetup, start: number, end: number, features: VueCodeInformation): Generator<Code>;
|
|
8
8
|
export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.identifierRE = exports.endOfLine = exports.newLine = void 0;
|
|
4
4
|
exports.getTypeScriptAST = getTypeScriptAST;
|
|
5
5
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
6
6
|
exports.forEachNode = forEachNode;
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
8
|
exports.newLine = `\n`;
|
|
9
9
|
exports.endOfLine = `;${exports.newLine}`;
|
|
10
|
-
exports.
|
|
11
|
-
const cacheMaps = new
|
|
10
|
+
exports.identifierRE = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
11
|
+
const cacheMaps = new WeakMap();
|
|
12
12
|
function getTypeScriptAST(ts, block, text) {
|
|
13
13
|
if (!cacheMaps.has(block)) {
|
|
14
14
|
cacheMaps.set(block, [block.content, new Map()]);
|
|
@@ -7,11 +7,11 @@ function* generateStringLiteralKey(code, offset, info) {
|
|
|
7
7
|
yield `'${code}'`;
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
const
|
|
10
|
+
const boundary = yield* boundary_1.Boundary.start('template', offset, info);
|
|
11
11
|
yield `'`;
|
|
12
|
-
yield [code, 'template', offset,
|
|
12
|
+
yield [code, 'template', offset, boundary.features];
|
|
13
13
|
yield `'`;
|
|
14
|
-
yield
|
|
14
|
+
yield boundary.end(offset + code.length);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=stringLiteralKey.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
-
export declare function generateUnicode(code: string, offset: number,
|
|
2
|
+
export declare function generateUnicode(code: string, offset: number, features: VueCodeInformation): Generator<Code>;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateUnicode = generateUnicode;
|
|
4
4
|
const boundary_1 = require("./boundary");
|
|
5
|
-
function* generateUnicode(code, offset,
|
|
5
|
+
function* generateUnicode(code, offset, features) {
|
|
6
6
|
if (needToUnicode(code)) {
|
|
7
|
-
const
|
|
7
|
+
const boundary = yield* boundary_1.Boundary.start('template', offset, features);
|
|
8
8
|
yield toUnicode(code);
|
|
9
|
-
yield
|
|
9
|
+
yield boundary.end(offset + code.length);
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
|
-
yield [code, 'template', offset,
|
|
12
|
+
yield [code, 'template', offset, features];
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function needToUnicode(str) {
|
package/lib/languagePlugin.js
CHANGED
|
@@ -40,6 +40,7 @@ const language_core_1 = require("@volar/language-core");
|
|
|
40
40
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
41
41
|
const LanguageCore = __importStar(require("../index"));
|
|
42
42
|
const plugins_1 = require("./plugins");
|
|
43
|
+
const vue_tsx_1 = require("./plugins/vue-tsx");
|
|
43
44
|
const virtualCode_1 = require("./virtualCode");
|
|
44
45
|
const fileRegistries = {};
|
|
45
46
|
function getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins) {
|
|
@@ -111,7 +112,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
111
112
|
})),
|
|
112
113
|
getServiceScript(root) {
|
|
113
114
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
|
|
114
|
-
if (
|
|
115
|
+
if (vue_tsx_1.serviceScriptRE.test(code.id)) {
|
|
115
116
|
const lang = code.id.slice('script_'.length);
|
|
116
117
|
return {
|
|
117
118
|
code,
|
|
@@ -3,6 +3,8 @@ import type { TextRange, VueCompilerOptions } from '../types';
|
|
|
3
3
|
export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
|
|
4
4
|
}
|
|
5
5
|
export declare function parseScriptRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
|
6
|
+
bindings: TextRange<ts.Node>[];
|
|
7
|
+
components: TextRange<ts.Node>[];
|
|
6
8
|
exportDefault: (TextRange<ts.Node> & {
|
|
7
9
|
expression: TextRange<ts.Expression>;
|
|
8
10
|
isObjectLiteral: boolean;
|
|
@@ -16,8 +18,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), sourc
|
|
|
16
18
|
inheritAttrs: string | undefined;
|
|
17
19
|
};
|
|
18
20
|
}) | undefined;
|
|
19
|
-
bindings: TextRange<ts.Node>[];
|
|
20
|
-
components: TextRange<ts.Node>[];
|
|
21
21
|
};
|
|
22
22
|
export declare function parseOptionsFromExtression(ts: typeof import('typescript'), exp: ts.Node, sourceFile: ts.SourceFile): {
|
|
23
23
|
isObjectLiteral: boolean;
|
|
@@ -6,7 +6,6 @@ const shared_1 = require("../utils/shared");
|
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
function parseScriptRanges(ts, sourceFile, vueCompilerOptions) {
|
|
8
8
|
let exportDefault;
|
|
9
|
-
const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions);
|
|
10
9
|
ts.forEachChild(sourceFile, child => {
|
|
11
10
|
if (ts.isExportAssignment(child)) {
|
|
12
11
|
exportDefault = {
|
|
@@ -22,16 +21,14 @@ function parseScriptRanges(ts, sourceFile, vueCompilerOptions) {
|
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
return {
|
|
24
|
+
...(0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions),
|
|
25
25
|
exportDefault,
|
|
26
|
-
bindings,
|
|
27
|
-
components,
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
function parseOptionsFromExtression(ts, exp, sourceFile) {
|
|
31
29
|
let obj;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
30
|
+
// #1882
|
|
31
|
+
exp = (0, utils_1.getUnwrappedExpression)(ts, exp);
|
|
35
32
|
if (ts.isObjectLiteralExpression(exp)) {
|
|
36
33
|
obj = exp;
|
|
37
34
|
}
|
|
@@ -83,8 +80,4 @@ function parseOptionsFromExtression(ts, exp, sourceFile) {
|
|
|
83
80
|
return (0, shared_1.getNodeText)(ts, node, sourceFile);
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
|
-
// isAsExpression is missing in tsc
|
|
87
|
-
function isAsExpression(ts, node) {
|
|
88
|
-
return node.kind === ts.SyntaxKind.AsExpression;
|
|
89
|
-
}
|
|
90
83
|
//# sourceMappingURL=scriptRanges.js.map
|
|
@@ -42,10 +42,10 @@ export interface UseTemplateRef extends CallExpressionRange {
|
|
|
42
42
|
export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
|
|
43
43
|
}
|
|
44
44
|
export declare function parseScriptSetupRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
|
45
|
-
leadingCommentEndOffset: number;
|
|
46
|
-
importSectionEndOffset: number;
|
|
47
45
|
bindings: TextRange<ts.Node>[];
|
|
48
46
|
components: TextRange<ts.Node>[];
|
|
47
|
+
leadingCommentEndOffset: number;
|
|
48
|
+
importSectionEndOffset: number;
|
|
49
49
|
defineModel: DefineModel[];
|
|
50
50
|
defineProps: DefineProps | undefined;
|
|
51
51
|
withDefaults: CallExpressionRange | undefined;
|
|
@@ -4,7 +4,7 @@ exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
|
|
4
4
|
const collectBindings_1 = require("../utils/collectBindings");
|
|
5
5
|
const shared_1 = require("../utils/shared");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
const
|
|
7
|
+
const tsCheckRE = /^\/\/\s*@ts-(?:no)?check(?:$|\s)/;
|
|
8
8
|
function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
|
|
9
9
|
const defineModel = [];
|
|
10
10
|
let defineProps;
|
|
@@ -19,8 +19,7 @@ function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
|
|
|
19
19
|
const useTemplateRef = [];
|
|
20
20
|
const text = sourceFile.text;
|
|
21
21
|
const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
|
|
22
|
-
const leadingCommentEndOffset = leadingCommentRanges.find(range =>
|
|
23
|
-
let { bindings, components } = (0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions);
|
|
22
|
+
const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckRE.test(text.slice(range.pos, range.end)))?.end ?? 0;
|
|
24
23
|
let foundNonImportExportNode = false;
|
|
25
24
|
let importSectionEndOffset = 0;
|
|
26
25
|
ts.forEachChild(sourceFile, node => {
|
|
@@ -47,16 +46,10 @@ function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
|
|
|
47
46
|
foundNonImportExportNode = true;
|
|
48
47
|
});
|
|
49
48
|
ts.forEachChild(sourceFile, node => visitNode(node, [sourceFile]));
|
|
50
|
-
const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
|
|
51
|
-
bindings = bindings.filter(range => {
|
|
52
|
-
const name = text.slice(range.start, range.end);
|
|
53
|
-
return !templateRefNames.has(name);
|
|
54
|
-
});
|
|
55
49
|
return {
|
|
50
|
+
...(0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions),
|
|
56
51
|
leadingCommentEndOffset,
|
|
57
52
|
importSectionEndOffset,
|
|
58
|
-
bindings,
|
|
59
|
-
components,
|
|
60
53
|
defineModel,
|
|
61
54
|
defineProps,
|
|
62
55
|
withDefaults,
|
package/lib/parsers/utils.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
|
|
|
5
5
|
components: TextRange<ts.Node>[];
|
|
6
6
|
};
|
|
7
7
|
export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): TextRange | undefined;
|
|
8
|
+
export declare function getUnwrappedExpression(ts: typeof import('typescript'), node: ts.Node): ts.Node;
|
package/lib/parsers/utils.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseBindingRanges = parseBindingRanges;
|
|
4
4
|
exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
|
|
5
|
+
exports.getUnwrappedExpression = getUnwrappedExpression;
|
|
5
6
|
const collectBindings_1 = require("../utils/collectBindings");
|
|
6
7
|
const shared_1 = require("../utils/shared");
|
|
7
8
|
function parseBindingRanges(ts, ast, componentExtsensions) {
|
|
@@ -91,4 +92,13 @@ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
}
|
|
95
|
+
function getUnwrappedExpression(ts, node) {
|
|
96
|
+
while (ts.isParenthesizedExpression(node)
|
|
97
|
+
|| ts.isAssertionExpression(node)
|
|
98
|
+
|| ts.isNonNullExpression(node)
|
|
99
|
+
|| ts.isSatisfiesExpression(node)) {
|
|
100
|
+
node = node.expression;
|
|
101
|
+
}
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
94
104
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseVueCompilerOptions = parseVueCompilerOptions;
|
|
4
|
-
const
|
|
4
|
+
const syntaxRE = /^\s*@(?<key>.+?)\s+(?<value>.+?)\s*$/m;
|
|
5
5
|
function parseVueCompilerOptions(comments) {
|
|
6
6
|
const entries = comments
|
|
7
7
|
.map(text => {
|
|
8
8
|
try {
|
|
9
|
-
const match = text.match(
|
|
9
|
+
const match = text.match(syntaxRE);
|
|
10
10
|
if (match) {
|
|
11
11
|
const { key, value } = match.groups ?? {};
|
|
12
12
|
return [key, JSON.parse(value)];
|
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
|
|
4
|
-
const
|
|
3
|
+
const sfcBlockRE = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
|
|
4
|
+
const langRE = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
|
|
5
5
|
const plugin = ({ vueCompilerOptions }) => {
|
|
6
6
|
return {
|
|
7
7
|
version: 2.2,
|
|
@@ -34,11 +34,11 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
34
34
|
errors: [],
|
|
35
35
|
};
|
|
36
36
|
let templateContent = content;
|
|
37
|
-
for (const match of content.matchAll(
|
|
37
|
+
for (const match of content.matchAll(sfcBlockRE)) {
|
|
38
38
|
const matchText = match[0];
|
|
39
39
|
const tag = match[1];
|
|
40
40
|
const attrs = match[2];
|
|
41
|
-
const lang = attrs.match(
|
|
41
|
+
const lang = attrs.match(langRE)?.[2];
|
|
42
42
|
const content = match[3];
|
|
43
43
|
const contentStart = match.index + matchText.indexOf(content);
|
|
44
44
|
if (tag === 'style') {
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -4,14 +4,14 @@ const language_core_1 = require("@volar/language-core");
|
|
|
4
4
|
const muggle_string_1 = require("muggle-string");
|
|
5
5
|
const buildMappings_1 = require("../utils/buildMappings");
|
|
6
6
|
const parseSfc_1 = require("../utils/parseSfc");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
7
|
+
const frontmatterRE = /^---[\s\S]*?\n---(?:\r?\n|$)/;
|
|
8
|
+
const codeblockRE = /(`{3}|\${2})[\s\S]+?\1/g;
|
|
9
|
+
const codeSnippetImportRE = /^\s*<<<\s*.+/gm;
|
|
10
|
+
const sfcBlockRE = /<(script|style)\b[^>]*>([\s\S]*?)<\/\1>/g;
|
|
11
|
+
const htmlTagRE = /(?<=<\/?)([a-z][a-z0-9-]*)\b[^>]*(?=>)/gi;
|
|
12
|
+
const interpolationRE = /(?<=\{\{)[\s\S]*?(?=\}\})/g;
|
|
13
|
+
const inlineCodeRE = /(`{1,2})[^`]+\1/g;
|
|
14
|
+
const angleBracketRE = /<[^\s:]*:\S*>/g;
|
|
15
15
|
const plugin = ({ vueCompilerOptions }) => {
|
|
16
16
|
return {
|
|
17
17
|
version: 2.2,
|
|
@@ -27,23 +27,23 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
27
27
|
if (languageId !== 'markdown') {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
for (const
|
|
31
|
-
content = content.replace(
|
|
30
|
+
for (const pattern of [frontmatterRE, codeblockRE, codeSnippetImportRE]) {
|
|
31
|
+
content = content.replace(pattern, match => ' '.repeat(match.length));
|
|
32
32
|
}
|
|
33
33
|
const codes = [];
|
|
34
|
-
for (const { 0: text, index } of content.matchAll(
|
|
34
|
+
for (const { 0: text, index } of content.matchAll(sfcBlockRE)) {
|
|
35
35
|
codes.push([text, undefined, index]);
|
|
36
36
|
codes.push('\n\n');
|
|
37
37
|
content = content.slice(0, index) + ' '.repeat(text.length) + content.slice(index + text.length);
|
|
38
38
|
}
|
|
39
39
|
const ranges = [];
|
|
40
|
-
for (const
|
|
41
|
-
for (const { 0: text, index } of content.matchAll(
|
|
40
|
+
for (const pattern of [htmlTagRE, interpolationRE]) {
|
|
41
|
+
for (const { 0: text, index } of content.matchAll(pattern)) {
|
|
42
42
|
ranges.push([index, index + text.length]);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
for (const
|
|
46
|
-
for (const { 0: text, index } of content.matchAll(
|
|
45
|
+
for (const pattern of [inlineCodeRE, angleBracketRE]) {
|
|
46
|
+
for (const { 0: text, index } of content.matchAll(pattern)) {
|
|
47
47
|
if (ranges.some(([start, end]) => index >= start && index < end)) {
|
|
48
48
|
continue;
|
|
49
49
|
}
|
package/lib/plugins/file-vue.js
CHANGED
|
@@ -50,8 +50,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
50
50
|
+ change.newText
|
|
51
51
|
+ hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
|
|
52
52
|
// #3449
|
|
53
|
-
const
|
|
54
|
-
const insertedEndTag =
|
|
53
|
+
const endTagRE = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
|
|
54
|
+
const insertedEndTag = endTagRE.test(oldContent) !== endTagRE.test(newContent);
|
|
55
55
|
if (insertedEndTag) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const muggle_string_1 = require("muggle-string");
|
|
4
|
-
const
|
|
4
|
+
const codeFeatures_1 = require("../codegen/codeFeatures");
|
|
5
5
|
const plugin = () => {
|
|
6
6
|
return {
|
|
7
7
|
version: 2.2,
|
|
@@ -13,7 +13,7 @@ const plugin = () => {
|
|
|
13
13
|
},
|
|
14
14
|
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
15
15
|
if (embeddedFile.id === 'root_tags') {
|
|
16
|
-
embeddedFile.content.push([ir.content, undefined, 0,
|
|
16
|
+
embeddedFile.content.push([ir.content, undefined, 0, codeFeatures_1.codeFeatures.full]);
|
|
17
17
|
for (const block of [
|
|
18
18
|
ir.template,
|
|
19
19
|
ir.script,
|
|
@@ -30,7 +30,7 @@ const plugin = () => {
|
|
|
30
30
|
'',
|
|
31
31
|
undefined,
|
|
32
32
|
block.startTagEnd + offset,
|
|
33
|
-
|
|
33
|
+
codeFeatures_1.codeFeatures.structure,
|
|
34
34
|
], ir.content.slice(block.startTagEnd + offset, block.endTagStart));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const codeFeatures_1 = require("../codegen/codeFeatures");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2.2,
|
|
@@ -18,7 +18,7 @@ const plugin = () => {
|
|
|
18
18
|
customBlock.content,
|
|
19
19
|
customBlock.name,
|
|
20
20
|
0,
|
|
21
|
-
|
|
21
|
+
codeFeatures_1.codeFeatures.full,
|
|
22
22
|
]);
|
|
23
23
|
}
|
|
24
24
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codeFeatures_1 = require("../codegen/codeFeatures");
|
|
3
4
|
const plugin = () => {
|
|
4
5
|
return {
|
|
5
6
|
version: 2.2,
|
|
@@ -24,10 +25,7 @@ const plugin = () => {
|
|
|
24
25
|
script.content,
|
|
25
26
|
script.name,
|
|
26
27
|
0,
|
|
27
|
-
|
|
28
|
-
structure: true,
|
|
29
|
-
format: true,
|
|
30
|
-
},
|
|
28
|
+
codeFeatures_1.codeFeatures.structureAndFormat,
|
|
31
29
|
]);
|
|
32
30
|
}
|
|
33
31
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const codeFeatures_1 = require("../codegen/codeFeatures");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2.2,
|
|
@@ -34,7 +34,7 @@ const plugin = () => {
|
|
|
34
34
|
binding.text,
|
|
35
35
|
style.name,
|
|
36
36
|
binding.offset,
|
|
37
|
-
|
|
37
|
+
codeFeatures_1.codeFeatures.full,
|
|
38
38
|
], ');\n');
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -43,7 +43,7 @@ const plugin = () => {
|
|
|
43
43
|
style.content,
|
|
44
44
|
style.name,
|
|
45
45
|
0,
|
|
46
|
-
|
|
46
|
+
codeFeatures_1.codeFeatures.full,
|
|
47
47
|
]);
|
|
48
48
|
}
|
|
49
49
|
}
|