@vue/language-core 3.3.5 → 3.3.7
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 +4 -4
- package/lib/codegen/style/modules.d.ts +1 -1
- package/lib/codegen/style/modules.js +1 -1
- package/lib/codegen/style/scopedClasses.d.ts +2 -1
- package/lib/codegen/style/scopedClasses.js +5 -4
- package/lib/codegen/template/context.d.ts +55 -124
- package/lib/codegen/template/context.js +187 -269
- package/lib/codegen/template/element.js +18 -103
- package/lib/codegen/template/elementDirectives.js +11 -11
- package/lib/codegen/template/elementEvents.js +50 -45
- 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.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +126 -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/types.d.ts +1 -1
- package/lib/utils/forEachTemplateNode.js +36 -43
- package/lib/virtualCode/index.js +2 -2
- package/package.json +4 -4
- package/types/template-helpers.d.ts +14 -24
- package/lib/plugins/shared.d.ts +0 -2
- package/lib/plugins/shared.js +0 -12
|
@@ -21,14 +21,14 @@ function generate(options) {
|
|
|
21
21
|
return { ...ctx, codes };
|
|
22
22
|
}
|
|
23
23
|
function* generateWorker(options, ctx) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const scope = ctx.scope();
|
|
25
|
+
scope.declare(...options.setupConsts);
|
|
26
26
|
const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
|
|
27
27
|
if (slotsAssignName) {
|
|
28
|
-
|
|
28
|
+
scope.declare(slotsAssignName);
|
|
29
29
|
}
|
|
30
30
|
if (propsAssignName) {
|
|
31
|
-
|
|
31
|
+
scope.declare(propsAssignName);
|
|
32
32
|
}
|
|
33
33
|
if (vueCompilerOptions.inferTemplateDollarSlots) {
|
|
34
34
|
ctx.dollarVars.add('$slots');
|
|
@@ -73,7 +73,7 @@ function* generateWorker(options, ctx) {
|
|
|
73
73
|
}
|
|
74
74
|
yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
75
75
|
}
|
|
76
|
-
yield*
|
|
76
|
+
yield* scope.end();
|
|
77
77
|
}
|
|
78
78
|
function* generateSlotsType(options, ctx) {
|
|
79
79
|
if (options.hasDefineSlots) {
|
|
@@ -94,9 +94,9 @@ function* generateSlotsType(options, ctx) {
|
|
|
94
94
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
|
-
const
|
|
97
|
+
const boundary = yield* boundary_1.Boundary.start('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
|
|
98
98
|
yield `default`;
|
|
99
|
-
yield
|
|
99
|
+
yield boundary.end(slot.tagRange[1]);
|
|
100
100
|
}
|
|
101
101
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
102
102
|
}
|
|
@@ -45,12 +45,12 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
// #1205, #1264
|
|
48
|
-
const
|
|
48
|
+
const boundary = yield* boundary_1.Boundary.start(block.name, start + offset, codeFeatures_1.codeFeatures.verification);
|
|
49
49
|
if (ctx.dollarVars.has(name)) {
|
|
50
50
|
yield names_1.names.dollars;
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
ctx.
|
|
53
|
+
ctx.accessVariable(block.name, name, start + offset);
|
|
54
54
|
yield names_1.names.ctx;
|
|
55
55
|
}
|
|
56
56
|
yield `.`;
|
|
@@ -62,7 +62,7 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
62
62
|
? { ...data, __shorthandExpression: 'js' }
|
|
63
63
|
: data,
|
|
64
64
|
];
|
|
65
|
-
yield
|
|
65
|
+
yield boundary.end(start + offset + name.length);
|
|
66
66
|
}
|
|
67
67
|
prevEnd = offset + name.length;
|
|
68
68
|
}
|
|
@@ -79,22 +79,22 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function* forEachIdentifiers(ts, ctx, block, code, prefix, suffix) {
|
|
82
|
-
if (utils_1.
|
|
82
|
+
if (utils_1.identifierRE.test(code) && !shouldIdentifierSkipped(ctx, code)) {
|
|
83
83
|
yield [code, 0, false];
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
const
|
|
86
|
+
const scope = ctx.scope();
|
|
87
87
|
const ast = (0, utils_1.getTypeScriptAST)(ts, block, prefix + code + suffix);
|
|
88
|
-
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx)) {
|
|
88
|
+
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx, scope)) {
|
|
89
89
|
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
90
90
|
if (shouldIdentifierSkipped(ctx, text)) {
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start - prefix.length, isShorthand];
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
scope.end();
|
|
96
96
|
}
|
|
97
|
-
function* forEachDeclarations(ts, node, ast, ctx) {
|
|
97
|
+
function* forEachDeclarations(ts, node, ast, ctx, scope) {
|
|
98
98
|
if (ts.isIdentifier(node)) {
|
|
99
99
|
yield [node, false];
|
|
100
100
|
}
|
|
@@ -102,16 +102,16 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
102
102
|
yield [node.name, true];
|
|
103
103
|
}
|
|
104
104
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
105
|
-
yield* forEachDeclarations(ts, node.expression, ast, ctx);
|
|
105
|
+
yield* forEachDeclarations(ts, node.expression, ast, ctx, scope);
|
|
106
106
|
}
|
|
107
107
|
else if (ts.isVariableDeclaration(node)) {
|
|
108
|
-
|
|
109
|
-
yield* forEachDeclarationsInBinding(ts, node, ast, ctx);
|
|
108
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(ts, node.name, ast));
|
|
109
|
+
yield* forEachDeclarationsInBinding(ts, node, ast, ctx, scope);
|
|
110
110
|
}
|
|
111
111
|
else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
|
|
112
112
|
for (const element of node.elements) {
|
|
113
113
|
if (ts.isBindingElement(element)) {
|
|
114
|
-
yield* forEachDeclarationsInBinding(ts, element, ast, ctx);
|
|
114
|
+
yield* forEachDeclarationsInBinding(ts, element, ast, ctx, scope);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -123,18 +123,18 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
123
123
|
if (ts.isPropertyAssignment(prop)) {
|
|
124
124
|
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
125
125
|
if (ts.isComputedPropertyName(prop.name)) {
|
|
126
|
-
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx);
|
|
126
|
+
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx, scope);
|
|
127
127
|
}
|
|
128
|
-
yield* forEachDeclarations(ts, prop.initializer, ast, ctx);
|
|
128
|
+
yield* forEachDeclarations(ts, prop.initializer, ast, ctx, scope);
|
|
129
129
|
}
|
|
130
130
|
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
131
131
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
132
|
-
yield* forEachDeclarations(ts, prop, ast, ctx);
|
|
132
|
+
yield* forEachDeclarations(ts, prop, ast, ctx, scope);
|
|
133
133
|
}
|
|
134
134
|
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
135
135
|
else if (ts.isSpreadAssignment(prop)) {
|
|
136
136
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
137
|
-
yield* forEachDeclarations(ts, prop.expression, ast, ctx);
|
|
137
|
+
yield* forEachDeclarations(ts, prop.expression, ast, ctx, scope);
|
|
138
138
|
}
|
|
139
139
|
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
140
140
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
@@ -147,39 +147,39 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
147
147
|
yield* forEachDeclarationsInTypeNode(ts, node);
|
|
148
148
|
}
|
|
149
149
|
else if (ts.isBlock(node)) {
|
|
150
|
-
const
|
|
150
|
+
const scope = ctx.scope();
|
|
151
151
|
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
152
|
-
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
152
|
+
yield* forEachDeclarations(ts, child, ast, ctx, scope);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
scope.end();
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
158
|
-
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
158
|
+
yield* forEachDeclarations(ts, child, ast, ctx, scope);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function* forEachDeclarationsInBinding(ts, node, ast, ctx) {
|
|
162
|
+
function* forEachDeclarationsInBinding(ts, node, ast, ctx, scope) {
|
|
163
163
|
if ('type' in node && node.type) {
|
|
164
164
|
yield* forEachDeclarationsInTypeNode(ts, node.type);
|
|
165
165
|
}
|
|
166
166
|
if (!ts.isIdentifier(node.name)) {
|
|
167
|
-
yield* forEachDeclarations(ts, node.name, ast, ctx);
|
|
167
|
+
yield* forEachDeclarations(ts, node.name, ast, ctx, scope);
|
|
168
168
|
}
|
|
169
169
|
if (node.initializer) {
|
|
170
|
-
yield* forEachDeclarations(ts, node.initializer, ast, ctx);
|
|
170
|
+
yield* forEachDeclarations(ts, node.initializer, ast, ctx, scope);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
function* forEachDeclarationsInFunction(ts, node, ast, ctx) {
|
|
174
|
-
const
|
|
174
|
+
const scope = ctx.scope();
|
|
175
175
|
for (const param of node.parameters) {
|
|
176
|
-
|
|
177
|
-
yield* forEachDeclarationsInBinding(ts, param, ast, ctx);
|
|
176
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
|
|
177
|
+
yield* forEachDeclarationsInBinding(ts, param, ast, ctx, scope);
|
|
178
178
|
}
|
|
179
179
|
if (node.body) {
|
|
180
|
-
yield* forEachDeclarations(ts, node.body, ast, ctx);
|
|
180
|
+
yield* forEachDeclarations(ts, node.body, ast, ctx, scope);
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
scope.end();
|
|
183
183
|
}
|
|
184
184
|
function* forEachDeclarationsInTypeNode(ts, node) {
|
|
185
185
|
if (ts.isTypeQueryNode(node)) {
|
|
@@ -18,19 +18,19 @@ function* generateObjectProperty(options, ctx, code, offset, features, shouldCam
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
else if (shouldCamelize) {
|
|
21
|
-
if (utils_1.
|
|
21
|
+
if (utils_1.identifierRE.test((0, shared_1.camelize)(code))) {
|
|
22
22
|
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, features);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
const
|
|
25
|
+
const boundary = yield* boundary_1.Boundary.start('template', offset, features);
|
|
26
26
|
yield `'`;
|
|
27
|
-
yield* (0, camelized_1.generateCamelized)(code, 'template', offset,
|
|
27
|
+
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, boundary.features);
|
|
28
28
|
yield `'`;
|
|
29
|
-
yield
|
|
29
|
+
yield boundary.end(offset + code.length);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
if (utils_1.
|
|
33
|
+
if (utils_1.identifierRE.test(code)) {
|
|
34
34
|
yield [code, 'template', offset, features];
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
@@ -8,7 +8,7 @@ function* generatePropertyAccess(options, ctx, code, offset, features) {
|
|
|
8
8
|
if (code.startsWith('[') && code.endsWith(']')) {
|
|
9
9
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code, offset);
|
|
10
10
|
}
|
|
11
|
-
else if (utils_1.
|
|
11
|
+
else if (utils_1.identifierRE.test(code)) {
|
|
12
12
|
yield `.`;
|
|
13
13
|
yield [code, 'template', offset, features];
|
|
14
14
|
}
|
|
@@ -77,26 +77,26 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
77
77
|
else {
|
|
78
78
|
codes = [`['default']`];
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const boundary = yield* boundary_1.Boundary.start('template', nameProp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
81
81
|
yield options.slotsAssignName ?? names_1.names.slots;
|
|
82
82
|
yield* codes;
|
|
83
|
-
yield
|
|
83
|
+
yield boundary.end(nameProp.loc.end.offset);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
const
|
|
86
|
+
const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
87
87
|
yield `${options.slotsAssignName ?? names_1.names.slots}[`;
|
|
88
|
-
const
|
|
88
|
+
const boundary2 = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
89
89
|
yield `'default'`;
|
|
90
|
-
yield
|
|
90
|
+
yield boundary2.end(startTagEndOffset);
|
|
91
91
|
yield `]`;
|
|
92
|
-
yield
|
|
92
|
+
yield boundary.end(startTagEndOffset);
|
|
93
93
|
}
|
|
94
94
|
yield `)(`;
|
|
95
|
-
const
|
|
95
|
+
const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
96
96
|
yield `{${utils_1.newLine}`;
|
|
97
97
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
98
98
|
yield `}`;
|
|
99
|
-
yield
|
|
99
|
+
yield boundary.end(startTagEndOffset);
|
|
100
100
|
yield `)${utils_1.endOfLine}`;
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
@@ -109,7 +109,6 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
109
109
|
name: nameProp.value.content,
|
|
110
110
|
offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
111
111
|
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
112
|
-
nodeLoc: node.loc,
|
|
113
112
|
propsVar: ctx.getHoistVariable(propsVar),
|
|
114
113
|
});
|
|
115
114
|
}
|
|
@@ -134,7 +133,6 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
134
133
|
ctx.slots.push({
|
|
135
134
|
name: 'default',
|
|
136
135
|
tagRange: [startTagOffset, startTagEndOffset],
|
|
137
|
-
nodeLoc: node.loc,
|
|
138
136
|
propsVar: ctx.getHoistVariable(propsVar),
|
|
139
137
|
});
|
|
140
138
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
1
2
|
import type { Code, IRBlock } from '../../types';
|
|
3
|
+
import type { TemplateCodegenOptions } from './index';
|
|
2
4
|
export declare const references: WeakMap<IRBlock, [version: string, [className: string, offset: number][]]>;
|
|
5
|
+
export declare function generateStyleScopedClassReferences({ template, typescript: ts }: TemplateCodegenOptions, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
3
6
|
export declare function generateStyleScopedClassReference(block: IRBlock, className: string, offset: number, fullStart?: number): Generator<Code>;
|
|
@@ -1,15 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.references = void 0;
|
|
37
|
+
exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
|
|
4
38
|
exports.generateStyleScopedClassReference = generateStyleScopedClassReference;
|
|
39
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
40
|
+
const shared_1 = require("../../utils/shared");
|
|
5
41
|
const codeFeatures_1 = require("../codeFeatures");
|
|
6
42
|
const names_1 = require("../names");
|
|
7
43
|
const utils_1 = require("../utils");
|
|
8
44
|
const boundary_1 = require("../utils/boundary");
|
|
9
45
|
const escaped_1 = require("../utils/escaped");
|
|
10
|
-
const
|
|
46
|
+
const classNameEscapeRE = /([\\'])/;
|
|
11
47
|
// For language-service/lib/plugins/vue-scoped-class-links.ts usage
|
|
12
48
|
exports.references = new WeakMap();
|
|
49
|
+
function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
|
|
50
|
+
for (const prop of node.props) {
|
|
51
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
52
|
+
&& prop.name === 'class'
|
|
53
|
+
&& prop.value) {
|
|
54
|
+
const [text, start] = (0, shared_1.normalizeAttributeValue)(prop.value);
|
|
55
|
+
for (const [className, offset] of forEachClassName(text)) {
|
|
56
|
+
yield* generateStyleScopedClassReference(template, className, start + offset);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
60
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
61
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
62
|
+
&& prop.arg.content === 'class') {
|
|
63
|
+
const content = '(' + prop.exp.content + ')';
|
|
64
|
+
const startOffset = prop.exp.loc.start.offset - 1;
|
|
65
|
+
const ast = (0, utils_1.getTypeScriptAST)(ts, template, content);
|
|
66
|
+
const literals = [];
|
|
67
|
+
for (const node of (0, utils_1.forEachNode)(ts, ast)) {
|
|
68
|
+
if (!ts.isExpressionStatement(node)
|
|
69
|
+
|| !ts.isParenthesizedExpression(node.expression)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const { expression } = node.expression;
|
|
73
|
+
if (ts.isStringLiteralLike(expression)) {
|
|
74
|
+
literals.push(expression);
|
|
75
|
+
}
|
|
76
|
+
else if (ts.isArrayLiteralExpression(expression)) {
|
|
77
|
+
yield* walkArrayLiteral(expression);
|
|
78
|
+
}
|
|
79
|
+
else if (ts.isObjectLiteralExpression(expression)) {
|
|
80
|
+
yield* walkObjectLiteral(expression);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const literal of literals) {
|
|
84
|
+
const start = literal.end - literal.text.length - 1 + startOffset;
|
|
85
|
+
for (const [className, offset] of forEachClassName(literal.text)) {
|
|
86
|
+
yield* generateStyleScopedClassReference(template, className, start + offset);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function* walkArrayLiteral(node) {
|
|
90
|
+
const { elements } = node;
|
|
91
|
+
for (const element of elements) {
|
|
92
|
+
if (ts.isStringLiteralLike(element)) {
|
|
93
|
+
literals.push(element);
|
|
94
|
+
}
|
|
95
|
+
else if (ts.isObjectLiteralExpression(element)) {
|
|
96
|
+
yield* walkObjectLiteral(element);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function* walkObjectLiteral(node) {
|
|
101
|
+
const { properties } = node;
|
|
102
|
+
for (const property of properties) {
|
|
103
|
+
if (ts.isPropertyAssignment(property)) {
|
|
104
|
+
const { name } = property;
|
|
105
|
+
if (ts.isIdentifier(name)) {
|
|
106
|
+
const text = (0, shared_1.getNodeText)(ts, name, ast);
|
|
107
|
+
yield* generateStyleScopedClassReference(template, text, name.end - text.length + startOffset);
|
|
108
|
+
}
|
|
109
|
+
else if (ts.isStringLiteral(name)) {
|
|
110
|
+
literals.push(name);
|
|
111
|
+
}
|
|
112
|
+
else if (ts.isComputedPropertyName(name)) {
|
|
113
|
+
const { expression } = name;
|
|
114
|
+
if (ts.isStringLiteralLike(expression)) {
|
|
115
|
+
literals.push(expression);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (ts.isShorthandPropertyAssignment(property)) {
|
|
120
|
+
const text = (0, shared_1.getNodeText)(ts, property.name, ast);
|
|
121
|
+
yield* generateStyleScopedClassReference(template, text, property.name.end - text.length + startOffset);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function* forEachClassName(content) {
|
|
129
|
+
let offset = 0;
|
|
130
|
+
for (const className of content.split(' ')) {
|
|
131
|
+
yield [className, offset];
|
|
132
|
+
offset += className.length + 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
13
135
|
function* generateStyleScopedClassReference(block, className, offset, fullStart = offset) {
|
|
14
136
|
if (!className) {
|
|
15
137
|
yield `/** @type {${names_1.names.StyleScopedClasses}['`;
|
|
@@ -27,11 +149,11 @@ function* generateStyleScopedClassReference(block, className, offset, fullStart
|
|
|
27
149
|
cache[1].push([className, offset]);
|
|
28
150
|
}
|
|
29
151
|
yield `/** @type {${names_1.names.StyleScopedClasses}[`;
|
|
30
|
-
const
|
|
152
|
+
const boundary = yield* boundary_1.Boundary.start(block.name, fullStart, codeFeatures_1.codeFeatures.navigationAndCompletion);
|
|
31
153
|
yield `'`;
|
|
32
|
-
yield* (0, escaped_1.generateEscaped)(className, block.name, offset,
|
|
154
|
+
yield* (0, escaped_1.generateEscaped)(className, block.name, offset, boundary.features, classNameEscapeRE);
|
|
33
155
|
yield `'`;
|
|
34
|
-
yield
|
|
156
|
+
yield boundary.end(offset + className.length);
|
|
35
157
|
yield `]} */${utils_1.endOfLine}`;
|
|
36
158
|
}
|
|
37
159
|
//# sourceMappingURL=styleScopedClasses.js.map
|
|
@@ -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>;
|