@vue/language-core 3.1.4 → 3.1.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 +2 -1
- package/index.js +3 -2
- package/lib/codegen/codeFeatures.d.ts +5 -9
- package/lib/codegen/codeFeatures.js +5 -5
- package/lib/codegen/globalTypes.js +15 -20
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +6 -6
- package/lib/codegen/names.d.ts +30 -0
- package/lib/codegen/names.js +34 -0
- package/lib/codegen/script/component.js +45 -54
- package/lib/codegen/script/context.d.ts +2 -5
- package/lib/codegen/script/context.js +1 -7
- package/lib/codegen/script/index.d.ts +10 -12
- package/lib/codegen/script/index.js +74 -73
- package/lib/codegen/script/scriptSetup.d.ts +3 -2
- package/lib/codegen/script/scriptSetup.js +209 -283
- package/lib/codegen/script/src.js +9 -3
- package/lib/codegen/script/template.js +64 -108
- package/lib/codegen/style/common.d.ts +3 -0
- package/lib/codegen/style/common.js +43 -0
- package/lib/codegen/style/index.d.ts +63 -0
- package/lib/codegen/style/index.js +38 -0
- package/lib/codegen/style/modules.d.ts +3 -2
- package/lib/codegen/style/modules.js +12 -11
- package/lib/codegen/style/scopedClasses.d.ts +2 -3
- package/lib/codegen/style/scopedClasses.js +23 -21
- package/lib/codegen/template/context.d.ts +10 -19
- package/lib/codegen/template/context.js +82 -94
- package/lib/codegen/template/element.js +174 -65
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +30 -35
- package/lib/codegen/template/elementProps.d.ts +3 -3
- package/lib/codegen/template/elementProps.js +64 -83
- package/lib/codegen/template/index.d.ts +11 -22
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +108 -155
- package/lib/codegen/template/objectProperty.js +8 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +5 -7
- package/lib/codegen/template/slotOutlet.js +26 -14
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
- package/lib/codegen/template/styleScopedClasses.js +23 -149
- package/lib/codegen/template/templateChild.d.ts +0 -1
- package/lib/codegen/template/templateChild.js +11 -68
- package/lib/codegen/template/vFor.js +10 -13
- package/lib/codegen/template/vIf.js +5 -3
- package/lib/codegen/template/vSlot.js +20 -16
- package/lib/codegen/utils/boundary.d.ts +3 -0
- package/lib/codegen/utils/boundary.js +13 -0
- package/lib/codegen/utils/camelized.js +3 -3
- package/lib/codegen/utils/escaped.js +4 -2
- package/lib/codegen/utils/index.d.ts +3 -6
- package/lib/codegen/utils/index.js +41 -26
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/codegen/utils/stringLiteralKey.js +6 -3
- package/lib/codegen/utils/transform.d.ts +8 -0
- package/lib/codegen/utils/transform.js +27 -0
- package/lib/codegen/utils/unicode.js +4 -2
- package/lib/compilerOptions.js +4 -4
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +18 -25
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +8 -18
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -23
- package/lib/plugins/vue-tsx.js +121 -69
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +10 -11
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +9 -0
- package/lib/utils/signals.d.ts +2 -2
- package/lib/utils/signals.js +8 -6
- package/lib/virtualCode/embeddedCodes.d.ts +12 -0
- package/lib/virtualCode/embeddedCodes.js +249 -0
- package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
- package/lib/virtualCode/index.js +81 -0
- package/lib/virtualCode/ir.d.ts +4 -0
- package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
- package/lib/virtualCode/normalize.d.ts +2 -0
- package/lib/virtualCode/normalize.js +170 -0
- package/package.json +4 -4
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -3
- package/lib/codegen/utils/wrapWith.js +0 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.js +0 -49
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -5,6 +5,7 @@ const shared_1 = require("@vue/shared");
|
|
|
5
5
|
const alien_signals_1 = require("alien-signals");
|
|
6
6
|
const path = require("path-browserify");
|
|
7
7
|
const script_1 = require("../codegen/script");
|
|
8
|
+
const style_1 = require("../codegen/style");
|
|
8
9
|
const template_1 = require("../codegen/template");
|
|
9
10
|
const compilerOptions_1 = require("../compilerOptions");
|
|
10
11
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
@@ -16,53 +17,40 @@ const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
|
|
|
16
17
|
const plugin = ctx => {
|
|
17
18
|
return {
|
|
18
19
|
version: 2.2,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
22
|
-
],
|
|
23
|
-
getEmbeddedCodes(fileName, sfc) {
|
|
24
|
-
const codegen = useCodegen(fileName, sfc);
|
|
25
|
-
return [{
|
|
26
|
-
id: 'script_' + codegen.getLang(),
|
|
27
|
-
lang: codegen.getLang(),
|
|
28
|
-
}];
|
|
20
|
+
getEmbeddedCodes(_fileName, sfc) {
|
|
21
|
+
const lang = computeLang(sfc);
|
|
22
|
+
return [{ lang, id: 'script_' + lang }];
|
|
29
23
|
},
|
|
30
24
|
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
31
25
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
let codegen = exports.tsCodegen.get(sfc);
|
|
27
|
+
if (!codegen) {
|
|
28
|
+
exports.tsCodegen.set(sfc, codegen = useCodegen(fileName, sfc, ctx));
|
|
29
|
+
}
|
|
30
|
+
const generatedScript = codegen.getGeneratedScript();
|
|
31
|
+
embeddedFile.content = [...generatedScript.codes];
|
|
35
32
|
}
|
|
36
33
|
},
|
|
37
34
|
};
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx));
|
|
41
|
-
}
|
|
42
|
-
return exports.tsCodegen.get(sfc);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
exports.default = plugin;
|
|
46
|
-
function createTsx(fileName, sfc, ctx) {
|
|
47
|
-
const ts = ctx.modules.typescript;
|
|
48
|
-
const getRawLang = (0, alien_signals_1.computed)(() => {
|
|
35
|
+
function computeLang(sfc) {
|
|
36
|
+
let lang = sfc.scriptSetup?.lang ?? sfc.script?.lang;
|
|
49
37
|
if (sfc.script && sfc.scriptSetup) {
|
|
50
38
|
if (sfc.scriptSetup.lang !== 'js') {
|
|
51
|
-
|
|
39
|
+
lang = sfc.scriptSetup.lang;
|
|
52
40
|
}
|
|
53
41
|
else {
|
|
54
|
-
|
|
42
|
+
lang = sfc.script.lang;
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const getLang = (0, alien_signals_1.computed)(() => {
|
|
60
|
-
const rawLang = getRawLang();
|
|
61
|
-
if (rawLang && validLangs.has(rawLang)) {
|
|
62
|
-
return rawLang;
|
|
45
|
+
if (lang && validLangs.has(lang)) {
|
|
46
|
+
return lang;
|
|
63
47
|
}
|
|
64
48
|
return 'ts';
|
|
65
|
-
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.default = plugin;
|
|
52
|
+
function useCodegen(fileName, sfc, ctx) {
|
|
53
|
+
const ts = ctx.modules.typescript;
|
|
66
54
|
const getResolvedOptions = (0, alien_signals_1.computed)(() => {
|
|
67
55
|
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
|
|
68
56
|
if (options) {
|
|
@@ -78,46 +66,51 @@ function createTsx(fileName, sfc, ctx) {
|
|
|
78
66
|
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
|
|
79
67
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
|
|
80
68
|
: undefined);
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
if (sfc.scriptSetup &&
|
|
85
|
-
for (const { range } of bindings) {
|
|
86
|
-
newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return newNames;
|
|
90
|
-
});
|
|
91
|
-
const getSetupImportComponentNames = (0, signals_1.computedSet)(() => {
|
|
92
|
-
const newNames = new Set();
|
|
93
|
-
const bindings = getScriptSetupRanges()?.bindings;
|
|
94
|
-
if (sfc.scriptSetup && bindings) {
|
|
95
|
-
for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
|
|
69
|
+
const getImportComponentNames = (0, signals_1.computedSet)(() => {
|
|
70
|
+
const names = new Set();
|
|
71
|
+
const scriptSetupRanges = getScriptSetupRanges();
|
|
72
|
+
if (sfc.scriptSetup && scriptSetupRanges) {
|
|
73
|
+
for (const { range, moduleName, isDefaultImport, isNamespace } of scriptSetupRanges.bindings) {
|
|
96
74
|
if (moduleName
|
|
97
75
|
&& isDefaultImport
|
|
98
76
|
&& !isNamespace
|
|
99
77
|
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
100
|
-
|
|
78
|
+
names.add(sfc.scriptSetup.content.slice(range.start, range.end));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const scriptRange = getScriptRanges();
|
|
82
|
+
if (sfc.script && scriptRange) {
|
|
83
|
+
for (const { range, moduleName, isDefaultImport, isNamespace } of scriptRange.bindings) {
|
|
84
|
+
if (moduleName
|
|
85
|
+
&& isDefaultImport
|
|
86
|
+
&& !isNamespace
|
|
87
|
+
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
88
|
+
names.add(sfc.script.content.slice(range.start, range.end));
|
|
89
|
+
}
|
|
101
90
|
}
|
|
102
91
|
}
|
|
103
92
|
}
|
|
104
|
-
return
|
|
93
|
+
return names;
|
|
105
94
|
});
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
const
|
|
95
|
+
const getSetupConsts = (0, signals_1.computedSet)(() => {
|
|
96
|
+
const scriptSetupRanges = getScriptSetupRanges();
|
|
97
|
+
const names = new Set([
|
|
98
|
+
...scriptSetupRanges?.defineProps?.destructured?.keys() ?? [],
|
|
99
|
+
...getImportComponentNames(),
|
|
100
|
+
]);
|
|
101
|
+
const rest = scriptSetupRanges?.defineProps?.destructuredRest;
|
|
109
102
|
if (rest) {
|
|
110
|
-
|
|
103
|
+
names.add(rest);
|
|
111
104
|
}
|
|
112
|
-
return
|
|
105
|
+
return names;
|
|
113
106
|
});
|
|
114
|
-
const
|
|
107
|
+
const getSetupRefs = (0, signals_1.computedSet)(() => {
|
|
115
108
|
const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
|
|
116
109
|
.map(({ name }) => name)
|
|
117
110
|
.filter(name => name !== undefined));
|
|
118
111
|
return newNames;
|
|
119
112
|
});
|
|
120
|
-
const
|
|
113
|
+
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
|
|
121
114
|
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
|
122
115
|
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
123
116
|
const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
@@ -149,42 +142,101 @@ function createTsx(fileName, sfc, ctx) {
|
|
|
149
142
|
}
|
|
150
143
|
return (0, template_1.generateTemplate)({
|
|
151
144
|
ts,
|
|
152
|
-
compilerOptions: ctx.compilerOptions,
|
|
153
145
|
vueCompilerOptions: getResolvedOptions(),
|
|
154
146
|
template: sfc.template,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
templateRefNames: getSetupTemplateRefNames(),
|
|
159
|
-
hasDefineSlots: setupHasDefineSlots(),
|
|
147
|
+
setupConsts: getSetupConsts(),
|
|
148
|
+
setupRefs: getSetupRefs(),
|
|
149
|
+
hasDefineSlots: hasDefineSlots(),
|
|
160
150
|
propsAssignName: getSetupPropsAssignName(),
|
|
161
151
|
slotsAssignName: getSetupSlotsAssignName(),
|
|
162
152
|
inheritAttrs: getSetupInheritAttrs(),
|
|
163
153
|
selfComponentName: getComponentSelfName(),
|
|
164
154
|
});
|
|
165
155
|
});
|
|
156
|
+
const getGeneratedStyle = (0, alien_signals_1.computed)(() => {
|
|
157
|
+
if (!sfc.styles.length) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
return (0, style_1.generateStyle)({
|
|
161
|
+
ts,
|
|
162
|
+
vueCompilerOptions: getResolvedOptions(),
|
|
163
|
+
styles: sfc.styles,
|
|
164
|
+
setupConsts: getSetupConsts(),
|
|
165
|
+
setupRefs: getSetupRefs(),
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
const getTemplateStartTagOffset = (0, alien_signals_1.computed)(() => {
|
|
169
|
+
if (sfc.template) {
|
|
170
|
+
return sfc.template.start - sfc.template.startTagEnd;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const getSetupExposed = (0, signals_1.computedSet)(() => {
|
|
174
|
+
const allVars = new Set();
|
|
175
|
+
const scriptSetupRanges = getScriptSetupRanges();
|
|
176
|
+
if (!sfc.scriptSetup || !scriptSetupRanges) {
|
|
177
|
+
return allVars;
|
|
178
|
+
}
|
|
179
|
+
for (const { range } of scriptSetupRanges.bindings) {
|
|
180
|
+
const name = sfc.scriptSetup.content.slice(range.start, range.end);
|
|
181
|
+
allVars.add(name);
|
|
182
|
+
}
|
|
183
|
+
const scriptRanges = getScriptRanges();
|
|
184
|
+
if (sfc.script && scriptRanges) {
|
|
185
|
+
for (const { range } of scriptRanges.bindings) {
|
|
186
|
+
const name = sfc.script.content.slice(range.start, range.end);
|
|
187
|
+
allVars.add(name);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!allVars.size) {
|
|
191
|
+
return allVars;
|
|
192
|
+
}
|
|
193
|
+
const exposedNames = new Set();
|
|
194
|
+
const generatedTemplate = getGeneratedTemplate();
|
|
195
|
+
const generatedStyle = getGeneratedStyle();
|
|
196
|
+
for (const [name] of generatedTemplate?.componentAccessMap ?? []) {
|
|
197
|
+
if (allVars.has(name)) {
|
|
198
|
+
exposedNames.add(name);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const [name] of generatedStyle?.componentAccessMap ?? []) {
|
|
202
|
+
if (allVars.has(name)) {
|
|
203
|
+
exposedNames.add(name);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const component of sfc.template?.ast?.components ?? []) {
|
|
207
|
+
const testNames = new Set([(0, shared_1.camelize)(component), (0, shared_1.capitalize)((0, shared_1.camelize)(component))]);
|
|
208
|
+
for (const testName of testNames) {
|
|
209
|
+
if (allVars.has(testName)) {
|
|
210
|
+
exposedNames.add(testName);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return exposedNames;
|
|
215
|
+
});
|
|
166
216
|
const getGeneratedScript = (0, alien_signals_1.computed)(() => {
|
|
167
217
|
return (0, script_1.generateScript)({
|
|
168
218
|
ts,
|
|
169
|
-
compilerOptions: ctx.compilerOptions,
|
|
170
219
|
vueCompilerOptions: getResolvedOptions(),
|
|
171
|
-
sfc,
|
|
220
|
+
script: sfc.script,
|
|
221
|
+
scriptSetup: sfc.scriptSetup,
|
|
222
|
+
setupExposed: getSetupExposed(),
|
|
172
223
|
fileName,
|
|
173
|
-
lang: getLang(),
|
|
174
224
|
scriptRanges: getScriptRanges(),
|
|
175
225
|
scriptSetupRanges: getScriptSetupRanges(),
|
|
176
226
|
templateCodegen: getGeneratedTemplate(),
|
|
177
|
-
|
|
178
|
-
|
|
227
|
+
templateStartTagOffset: getTemplateStartTagOffset(),
|
|
228
|
+
styleCodegen: getGeneratedStyle(),
|
|
179
229
|
});
|
|
180
230
|
});
|
|
181
231
|
return {
|
|
182
|
-
getLang,
|
|
183
232
|
getScriptRanges,
|
|
184
233
|
getScriptSetupRanges,
|
|
185
234
|
getSetupSlotsAssignName,
|
|
186
235
|
getGeneratedScript,
|
|
187
236
|
getGeneratedTemplate,
|
|
237
|
+
getImportComponentNames,
|
|
238
|
+
getSetupExposed,
|
|
239
|
+
getSetupConsts,
|
|
188
240
|
};
|
|
189
241
|
}
|
|
190
242
|
//# sourceMappingURL=vue-tsx.js.map
|
package/lib/plugins.js
CHANGED
|
@@ -37,6 +37,7 @@ function createPlugins(pluginContext) {
|
|
|
37
37
|
file_md_1.default,
|
|
38
38
|
file_html_1.default,
|
|
39
39
|
vue_root_tags_1.default,
|
|
40
|
+
vue_tsx_1.default,
|
|
40
41
|
vue_script_js_1.default,
|
|
41
42
|
vue_style_css_1.default,
|
|
42
43
|
vue_template_html_1.default,
|
|
@@ -46,7 +47,6 @@ function createPlugins(pluginContext) {
|
|
|
46
47
|
vue_sfc_customblocks_1.default,
|
|
47
48
|
vue_sfc_scripts_1.default,
|
|
48
49
|
vue_sfc_template_1.default,
|
|
49
|
-
vue_tsx_1.default,
|
|
50
50
|
...pluginContext.vueCompilerOptions.plugins,
|
|
51
51
|
];
|
|
52
52
|
const pluginInstances = plugins
|
package/lib/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type * as CompilerDOM from '@vue/compiler-dom';
|
|
|
3
3
|
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
4
4
|
import type { Segment } from 'muggle-string';
|
|
5
5
|
import type * as ts from 'typescript';
|
|
6
|
-
import type { VueEmbeddedCode } from './
|
|
6
|
+
import type { VueEmbeddedCode } from './virtualCode/embeddedCodes';
|
|
7
7
|
export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
8
8
|
export { VueEmbeddedCode };
|
|
9
9
|
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>> & {
|
|
@@ -13,7 +13,8 @@ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' |
|
|
|
13
13
|
plugins?: string[];
|
|
14
14
|
};
|
|
15
15
|
export interface VueCodeInformation extends CodeInformation {
|
|
16
|
-
|
|
16
|
+
__importCompletion?: boolean;
|
|
17
|
+
__combineToken?: symbol;
|
|
17
18
|
__linkedToken?: symbol;
|
|
18
19
|
}
|
|
19
20
|
export type Code = Segment<VueCodeInformation>;
|
|
@@ -64,7 +65,7 @@ export interface VueCompilerOptions {
|
|
|
64
65
|
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
|
65
66
|
}
|
|
66
67
|
export declare const validVersions: readonly [2, 2.1, 2.2];
|
|
67
|
-
export
|
|
68
|
+
export interface VueLanguagePluginReturn {
|
|
68
69
|
version: typeof validVersions[number];
|
|
69
70
|
name?: string;
|
|
70
71
|
order?: number;
|
|
@@ -92,7 +93,7 @@ export type VueLanguagePluginReturn = {
|
|
|
92
93
|
lang: string;
|
|
93
94
|
}[];
|
|
94
95
|
resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void;
|
|
95
|
-
}
|
|
96
|
+
}
|
|
96
97
|
export type VueLanguagePlugin = (ctx: {
|
|
97
98
|
modules: {
|
|
98
99
|
typescript: typeof ts;
|
package/lib/utils/parseSfc.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = parse;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
5
6
|
function parse(source) {
|
|
6
7
|
const errors = [];
|
|
7
8
|
const ast = CompilerDOM.parse(source, {
|
|
@@ -108,7 +109,11 @@ function createBlock(node, source) {
|
|
|
108
109
|
block.__src = parseAttr(p, node);
|
|
109
110
|
}
|
|
110
111
|
else if (isScriptBlock(block)) {
|
|
111
|
-
if (p.name === '
|
|
112
|
+
if (p.name === 'vapor') {
|
|
113
|
+
block.setup ??= attrs[p.name];
|
|
114
|
+
block.__generic ??= true;
|
|
115
|
+
}
|
|
116
|
+
else if (p.name === 'setup') {
|
|
112
117
|
block.setup = attrs[p.name];
|
|
113
118
|
}
|
|
114
119
|
else if (p.name === 'generic') {
|
|
@@ -137,17 +142,11 @@ function parseAttr(p, node) {
|
|
|
137
142
|
if (!p.value) {
|
|
138
143
|
return true;
|
|
139
144
|
}
|
|
140
|
-
const
|
|
141
|
-
const source = p.value.loc.source;
|
|
142
|
-
let offset = p.value.loc.start.offset - node.loc.start.offset;
|
|
143
|
-
const quotes = source.startsWith('"') || source.startsWith("'");
|
|
144
|
-
if (quotes) {
|
|
145
|
-
offset++;
|
|
146
|
-
}
|
|
145
|
+
const [content, offset] = (0, shared_1.normalizeAttributeValue)(p.value);
|
|
147
146
|
return {
|
|
148
|
-
text,
|
|
149
|
-
offset,
|
|
150
|
-
quotes,
|
|
147
|
+
text: content,
|
|
148
|
+
offset: offset - node.loc.start.offset,
|
|
149
|
+
quotes: offset > p.value.loc.start.offset,
|
|
151
150
|
};
|
|
152
151
|
}
|
|
153
152
|
//# sourceMappingURL=parseSfc.js.map
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
import type { Sfc, TextRange } from '../types';
|
|
4
4
|
export { hyphenate as hyphenateTag } from '@vue/shared';
|
|
5
5
|
export declare function hyphenateAttr(str: string): string;
|
|
6
|
+
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number];
|
|
6
7
|
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
|
|
7
8
|
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
8
9
|
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
package/lib/utils/shared.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hyphenateTag = void 0;
|
|
4
4
|
exports.hyphenateAttr = hyphenateAttr;
|
|
5
|
+
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
5
6
|
exports.getElementTagOffsets = getElementTagOffsets;
|
|
6
7
|
exports.getStartEnd = getStartEnd;
|
|
7
8
|
exports.getNodeText = getNodeText;
|
|
@@ -16,6 +17,14 @@ function hyphenateAttr(str) {
|
|
|
16
17
|
}
|
|
17
18
|
return hyphencase;
|
|
18
19
|
}
|
|
20
|
+
function normalizeAttributeValue(node) {
|
|
21
|
+
const { source, start } = node.loc;
|
|
22
|
+
if ((source.startsWith('"') && source.endsWith('"'))
|
|
23
|
+
|| (source.startsWith("'") && source.endsWith("'"))) {
|
|
24
|
+
return [source.slice(1, -1), start.offset + 1];
|
|
25
|
+
}
|
|
26
|
+
return [source, start.offset];
|
|
27
|
+
}
|
|
19
28
|
function getElementTagOffsets(node, template) {
|
|
20
29
|
const tagOffsets = [
|
|
21
30
|
template.content.indexOf(node.tag, node.loc.start.offset),
|
package/lib/utils/signals.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function reactiveArray<I, O>(getArr: () => I[], getGetter: (item: () => I, index: number) => () => O): readonly Readonly<O>[];
|
|
2
2
|
export declare function computedSet<T>(source: () => Set<T>): () => Set<T>;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function computedArray<T>(source: () => T[], compareFn?: (oldItem: T, newItem: T) => boolean): () => T[];
|
package/lib/utils/signals.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.reactiveArray = reactiveArray;
|
|
4
4
|
exports.computedSet = computedSet;
|
|
5
|
-
exports.
|
|
5
|
+
exports.computedArray = computedArray;
|
|
6
6
|
const alien_signals_1 = require("alien-signals");
|
|
7
|
-
function
|
|
7
|
+
function reactiveArray(getArr, getGetter) {
|
|
8
|
+
const arr = (0, alien_signals_1.computed)(getArr);
|
|
8
9
|
const length = (0, alien_signals_1.computed)(() => arr().length);
|
|
9
10
|
const keys = (0, alien_signals_1.computed)(() => {
|
|
10
|
-
const
|
|
11
|
-
|
|
11
|
+
const l = length();
|
|
12
|
+
const keys = new Array(l);
|
|
13
|
+
for (let i = 0; i < l; i++) {
|
|
12
14
|
keys.push(String(i));
|
|
13
15
|
}
|
|
14
16
|
return keys;
|
|
@@ -52,7 +54,7 @@ function computedSet(source) {
|
|
|
52
54
|
return newValue;
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
|
-
function
|
|
57
|
+
function computedArray(source, compareFn = (oldItem, newItem) => oldItem === newItem) {
|
|
56
58
|
return (0, alien_signals_1.computed)(oldArr => {
|
|
57
59
|
oldArr ??= [];
|
|
58
60
|
const newArr = source();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Mapping, VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type { Code, Sfc, VueLanguagePluginReturn } from '../types';
|
|
3
|
+
export declare class VueEmbeddedCode {
|
|
4
|
+
id: string;
|
|
5
|
+
lang: string;
|
|
6
|
+
content: Code[];
|
|
7
|
+
parentCodeId?: string;
|
|
8
|
+
linkedCodeMappings: Mapping[];
|
|
9
|
+
embeddedCodes: VueEmbeddedCode[];
|
|
10
|
+
constructor(id: string, lang: string, content: Code[]);
|
|
11
|
+
}
|
|
12
|
+
export declare function useEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];
|