@vue/language-core 2.1.10 → 2.2.2
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 +0 -1
- package/index.js +1 -2
- package/lib/codeFeatures.d.ts +1 -0
- package/lib/codeFeatures.js +3 -0
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +39 -14
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +7 -7
- package/lib/codegen/script/binding.d.ts +4 -0
- package/lib/codegen/script/binding.js +41 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +44 -44
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +14 -14
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +6 -11
- package/lib/codegen/script/index.js +21 -63
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +236 -205
- package/lib/codegen/script/src.js +8 -8
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +7 -7
- package/lib/codegen/script/template.d.ts +2 -2
- package/lib/codegen/script/template.js +81 -114
- package/lib/codegen/template/context.d.ts +29 -15
- package/lib/codegen/template/context.js +51 -96
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +124 -317
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +10 -11
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +43 -30
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +5 -3
- package/lib/codegen/template/elementProps.js +116 -123
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +67 -69
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +30 -27
- package/lib/codegen/template/objectProperty.js +8 -8
- package/lib/codegen/template/propertyAccess.js +4 -4
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +47 -25
- package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
- package/lib/codegen/template/styleScopedClasses.js +152 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +39 -20
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +11 -11
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +6 -6
- package/lib/codegen/template/vSlot.d.ts +5 -0
- package/lib/codegen/template/vSlot.js +80 -0
- package/lib/codegen/utils/camelized.d.ts +2 -0
- package/lib/codegen/utils/camelized.js +31 -0
- package/lib/codegen/utils/index.d.ts +21 -0
- package/lib/codegen/utils/index.js +79 -0
- package/lib/codegen/utils/src.d.ts +2 -0
- package/lib/codegen/utils/src.js +19 -0
- package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +2 -0
- package/lib/codegen/utils/unicode.js +25 -0
- package/lib/languagePlugin.js +1 -1
- package/lib/parsers/scriptRanges.d.ts +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +69 -83
- package/lib/parsers/scriptSetupRanges.js +194 -171
- package/lib/parsers/vueCompilerOptions.d.ts +2 -0
- package/lib/parsers/vueCompilerOptions.js +23 -0
- package/lib/plugins/file-html.js +4 -3
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +4 -4
- package/lib/plugins/vue-root-tags.js +2 -2
- package/lib/plugins/vue-style-class-names.d.ts +5 -0
- package/lib/plugins/vue-style-class-names.js +32 -0
- package/lib/plugins/vue-style-reference-link.d.ts +1 -0
- package/lib/plugins/vue-style-reference-link.js +3 -0
- package/lib/plugins/vue-style-reference-links.d.ts +3 -0
- package/lib/plugins/vue-style-reference-links.js +26 -0
- package/lib/plugins/vue-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +66 -17
- package/lib/plugins/vue-tsx.d.ts +126 -92
- package/lib/plugins/vue-tsx.js +114 -97
- package/lib/plugins/vue-vine.d.ts +3 -0
- package/lib/plugins/vue-vine.js +35 -0
- package/lib/types.d.ts +25 -12
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +11 -5
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +134 -91
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +87 -79
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +5 -5
- package/lib/virtualFile/vueFile.js +6 -6
- package/package.json +6 -6
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsCodegen = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
4
5
|
const alien_signals_1 = require("alien-signals");
|
|
6
|
+
const path = require("path-browserify");
|
|
5
7
|
const script_1 = require("../codegen/script");
|
|
6
8
|
const template_1 = require("../codegen/template");
|
|
7
9
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
8
10
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
11
|
+
const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
12
|
+
const signals_1 = require("../utils/signals");
|
|
13
|
+
const ts_1 = require("../utils/ts");
|
|
9
14
|
exports.tsCodegen = new WeakMap();
|
|
10
15
|
const fileEditTimes = new Map();
|
|
11
16
|
const plugin = ctx => {
|
|
@@ -17,26 +22,25 @@ const plugin = ctx => {
|
|
|
17
22
|
'exactOptionalPropertyTypes',
|
|
18
23
|
],
|
|
19
24
|
getEmbeddedCodes(fileName, sfc) {
|
|
20
|
-
const
|
|
25
|
+
const codegen = useCodegen(fileName, sfc);
|
|
21
26
|
const files = [];
|
|
22
|
-
if (['js', 'ts', 'jsx', 'tsx'].includes(
|
|
23
|
-
files.push({ id: 'script_' +
|
|
27
|
+
if (['js', 'ts', 'jsx', 'tsx'].includes(codegen.getLang())) {
|
|
28
|
+
files.push({ id: 'script_' + codegen.getLang(), lang: codegen.getLang() });
|
|
24
29
|
}
|
|
25
30
|
return files;
|
|
26
31
|
},
|
|
27
32
|
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
28
|
-
const _tsx = useTsx(fileName, sfc);
|
|
29
33
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
30
|
-
const
|
|
34
|
+
const codegen = useCodegen(fileName, sfc);
|
|
35
|
+
const tsx = codegen.getGeneratedScript();
|
|
31
36
|
if (tsx) {
|
|
32
|
-
|
|
33
|
-
embeddedFile.content = content;
|
|
37
|
+
embeddedFile.content = [...tsx.codes];
|
|
34
38
|
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
};
|
|
39
|
-
function
|
|
43
|
+
function useCodegen(fileName, sfc) {
|
|
40
44
|
if (!exports.tsCodegen.has(sfc)) {
|
|
41
45
|
let appendGlobalTypes = false;
|
|
42
46
|
if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
|
|
@@ -51,37 +55,106 @@ const plugin = ctx => {
|
|
|
51
55
|
exports.default = plugin;
|
|
52
56
|
function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
53
57
|
const ts = ctx.modules.typescript;
|
|
54
|
-
const
|
|
58
|
+
const getLang = (0, alien_signals_1.computed)(() => {
|
|
55
59
|
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
|
56
60
|
: _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
|
|
57
61
|
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
58
62
|
: 'js';
|
|
59
63
|
});
|
|
60
|
-
const
|
|
64
|
+
const getResolvedOptions = (0, alien_signals_1.computed)(() => {
|
|
65
|
+
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(_sfc.comments);
|
|
66
|
+
if (options) {
|
|
67
|
+
const resolver = new ts_1.CompilerOptionsResolver();
|
|
68
|
+
resolver.addConfig(options, path.dirname(fileName));
|
|
69
|
+
return resolver.build(ctx.vueCompilerOptions);
|
|
70
|
+
}
|
|
71
|
+
return ctx.vueCompilerOptions;
|
|
72
|
+
});
|
|
73
|
+
const getScriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
|
|
61
74
|
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
|
|
62
75
|
: undefined);
|
|
63
|
-
const
|
|
64
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast,
|
|
76
|
+
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
|
|
77
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, getResolvedOptions())
|
|
65
78
|
: undefined);
|
|
66
|
-
const
|
|
67
|
-
|
|
79
|
+
const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
80
|
+
const newNames = new Set();
|
|
81
|
+
const bindings = getScriptSetupRanges()?.bindings;
|
|
82
|
+
if (_sfc.scriptSetup && bindings) {
|
|
83
|
+
for (const { range } of bindings) {
|
|
84
|
+
newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return newNames;
|
|
88
|
+
}));
|
|
89
|
+
const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
90
|
+
const newNames = new Set();
|
|
91
|
+
const bindings = getScriptSetupRanges()?.bindings;
|
|
92
|
+
if (_sfc.scriptSetup && bindings) {
|
|
93
|
+
for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
|
|
94
|
+
if (moduleName
|
|
95
|
+
&& isDefaultImport
|
|
96
|
+
&& !isNamespace
|
|
97
|
+
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
98
|
+
newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return newNames;
|
|
103
|
+
}));
|
|
104
|
+
const getSetupDestructuredPropNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
105
|
+
const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
|
|
106
|
+
const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
|
|
107
|
+
if (rest) {
|
|
108
|
+
newNames.add(rest);
|
|
109
|
+
}
|
|
110
|
+
return newNames;
|
|
111
|
+
}));
|
|
112
|
+
const getSetupTemplateRefNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
113
|
+
const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
|
|
114
|
+
.map(({ name }) => name)
|
|
115
|
+
.filter(name => name !== undefined));
|
|
116
|
+
return newNames;
|
|
117
|
+
}));
|
|
118
|
+
const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
|
|
119
|
+
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
120
|
+
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
|
121
|
+
const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
122
|
+
const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs ?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
|
|
123
|
+
return value !== 'false';
|
|
124
|
+
});
|
|
125
|
+
const getComponentSelfName = (0, alien_signals_1.computed)(() => {
|
|
126
|
+
const { exportDefault } = getScriptRanges() ?? {};
|
|
127
|
+
if (_sfc.script && exportDefault?.nameOption) {
|
|
128
|
+
const { nameOption } = exportDefault;
|
|
129
|
+
return _sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
|
|
130
|
+
}
|
|
131
|
+
const { defineOptions } = getScriptSetupRanges() ?? {};
|
|
132
|
+
if (_sfc.scriptSetup && defineOptions?.name) {
|
|
133
|
+
return defineOptions.name;
|
|
134
|
+
}
|
|
135
|
+
const baseName = path.basename(fileName);
|
|
136
|
+
return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
|
|
137
|
+
});
|
|
138
|
+
const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
|
|
139
|
+
if (getResolvedOptions().skipTemplateCodegen || !_sfc.template) {
|
|
68
140
|
return;
|
|
69
141
|
}
|
|
70
142
|
const codes = [];
|
|
71
143
|
const codegen = (0, template_1.generateTemplate)({
|
|
72
144
|
ts,
|
|
73
145
|
compilerOptions: ctx.compilerOptions,
|
|
74
|
-
vueCompilerOptions:
|
|
146
|
+
vueCompilerOptions: getResolvedOptions(),
|
|
75
147
|
template: _sfc.template,
|
|
76
|
-
edited:
|
|
77
|
-
scriptSetupBindingNames:
|
|
78
|
-
scriptSetupImportComponentNames:
|
|
79
|
-
destructuredPropNames:
|
|
80
|
-
templateRefNames:
|
|
81
|
-
hasDefineSlots:
|
|
82
|
-
slotsAssignName:
|
|
83
|
-
propsAssignName:
|
|
84
|
-
inheritAttrs:
|
|
148
|
+
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
149
|
+
scriptSetupBindingNames: getSetupBindingNames(),
|
|
150
|
+
scriptSetupImportComponentNames: getSetupImportComponentNames(),
|
|
151
|
+
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
152
|
+
templateRefNames: getSetupTemplateRefNames(),
|
|
153
|
+
hasDefineSlots: setupHasDefineSlots(),
|
|
154
|
+
slotsAssignName: getSetupSlotsAssignName(),
|
|
155
|
+
propsAssignName: getSetupPropsAssignName(),
|
|
156
|
+
inheritAttrs: getSetupInheritAttrs(),
|
|
157
|
+
selfComponentName: getComponentSelfName(),
|
|
85
158
|
});
|
|
86
159
|
let current = codegen.next();
|
|
87
160
|
while (!current.done) {
|
|
@@ -91,71 +164,26 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
91
164
|
}
|
|
92
165
|
return {
|
|
93
166
|
...current.value,
|
|
94
|
-
codes
|
|
167
|
+
codes,
|
|
95
168
|
};
|
|
96
169
|
});
|
|
97
|
-
const
|
|
98
|
-
const newNames = new Set();
|
|
99
|
-
const bindings = scriptSetupRanges.get()?.bindings;
|
|
100
|
-
if (_sfc.scriptSetup && bindings) {
|
|
101
|
-
for (const binding of bindings) {
|
|
102
|
-
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
106
|
-
return oldNames;
|
|
107
|
-
}
|
|
108
|
-
return newNames;
|
|
109
|
-
});
|
|
110
|
-
const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
|
|
111
|
-
const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
|
|
112
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
113
|
-
return oldNames;
|
|
114
|
-
}
|
|
115
|
-
return newNames;
|
|
116
|
-
});
|
|
117
|
-
const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
|
|
118
|
-
const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
|
|
119
|
-
const rest = scriptSetupRanges.get()?.props.destructuredRest;
|
|
120
|
-
if (rest) {
|
|
121
|
-
newNames.add(rest);
|
|
122
|
-
}
|
|
123
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
124
|
-
return oldNames;
|
|
125
|
-
}
|
|
126
|
-
return newNames;
|
|
127
|
-
});
|
|
128
|
-
const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
|
|
129
|
-
const newNames = new Set(scriptSetupRanges.get()?.templateRefs
|
|
130
|
-
.map(({ name }) => name)
|
|
131
|
-
.filter(name => name !== undefined));
|
|
132
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
133
|
-
return oldNames;
|
|
134
|
-
}
|
|
135
|
-
return newNames;
|
|
136
|
-
});
|
|
137
|
-
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
|
|
138
|
-
const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
|
|
139
|
-
const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
|
|
140
|
-
const inheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
141
|
-
const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
|
|
142
|
-
return value !== 'false';
|
|
143
|
-
});
|
|
144
|
-
const generatedScript = (0, alien_signals_1.computed)(() => {
|
|
170
|
+
const getGeneratedScript = (0, alien_signals_1.computed)(() => {
|
|
145
171
|
const codes = [];
|
|
146
172
|
const linkedCodeMappings = [];
|
|
147
173
|
let generatedLength = 0;
|
|
148
174
|
const codegen = (0, script_1.generateScript)({
|
|
149
175
|
ts,
|
|
150
|
-
fileName,
|
|
151
|
-
sfc: _sfc,
|
|
152
|
-
lang: lang.get(),
|
|
153
|
-
scriptRanges: scriptRanges.get(),
|
|
154
|
-
scriptSetupRanges: scriptSetupRanges.get(),
|
|
155
|
-
templateCodegen: generatedTemplate.get(),
|
|
156
176
|
compilerOptions: ctx.compilerOptions,
|
|
157
|
-
vueCompilerOptions:
|
|
158
|
-
|
|
177
|
+
vueCompilerOptions: getResolvedOptions(),
|
|
178
|
+
sfc: _sfc,
|
|
179
|
+
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
180
|
+
fileName,
|
|
181
|
+
lang: getLang(),
|
|
182
|
+
scriptRanges: getScriptRanges(),
|
|
183
|
+
scriptSetupRanges: getScriptSetupRanges(),
|
|
184
|
+
templateCodegen: getGeneratedTemplate(),
|
|
185
|
+
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
186
|
+
templateRefNames: getSetupTemplateRefNames(),
|
|
159
187
|
getGeneratedLength: () => generatedLength,
|
|
160
188
|
linkedCodeMappings,
|
|
161
189
|
appendGlobalTypes,
|
|
@@ -177,22 +205,11 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
177
205
|
};
|
|
178
206
|
});
|
|
179
207
|
return {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
208
|
+
getScriptRanges,
|
|
209
|
+
getScriptSetupRanges,
|
|
210
|
+
getLang,
|
|
211
|
+
getGeneratedScript,
|
|
212
|
+
getGeneratedTemplate,
|
|
185
213
|
};
|
|
186
214
|
}
|
|
187
|
-
function twoSetsEqual(a, b) {
|
|
188
|
-
if (a.size !== b.size) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
for (const file of a) {
|
|
192
|
-
if (!b.has(file)) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
215
|
//# sourceMappingURL=vue-tsx.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("./shared");
|
|
4
|
+
const plugin = () => {
|
|
5
|
+
return {
|
|
6
|
+
version: 2.1,
|
|
7
|
+
getEmbeddedCodes(_fileName, sfc) {
|
|
8
|
+
const result = [];
|
|
9
|
+
for (let i = 0; i < sfc.customBlocks.length; i++) {
|
|
10
|
+
const block = sfc.customBlocks[i];
|
|
11
|
+
if (block.type === 'vine') {
|
|
12
|
+
result.push({
|
|
13
|
+
id: 'vine_' + i,
|
|
14
|
+
lang: block.lang,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
},
|
|
20
|
+
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
21
|
+
if (embeddedFile.id.startsWith('vine_')) {
|
|
22
|
+
const index = parseInt(embeddedFile.id.slice('vine_'.length));
|
|
23
|
+
const block = sfc.customBlocks[index];
|
|
24
|
+
embeddedFile.content.push([
|
|
25
|
+
block.content,
|
|
26
|
+
block.name,
|
|
27
|
+
0,
|
|
28
|
+
shared_1.allCodeFeatures,
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.default = plugin;
|
|
35
|
+
//# sourceMappingURL=vue-vine.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
|
|
|
7
7
|
export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
8
8
|
export { VueEmbeddedCode };
|
|
9
9
|
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
|
10
|
-
|
|
10
|
+
strictTemplates?: boolean;
|
|
11
|
+
target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 99 | number;
|
|
11
12
|
plugins?: string[];
|
|
12
13
|
};
|
|
13
14
|
export interface VueCodeInformation extends CodeInformation {
|
|
@@ -22,7 +23,10 @@ export interface VueCompilerOptions {
|
|
|
22
23
|
vitePressExtensions: string[];
|
|
23
24
|
petiteVueExtensions: string[];
|
|
24
25
|
jsxSlots: boolean;
|
|
25
|
-
|
|
26
|
+
checkUnknownProps: boolean;
|
|
27
|
+
checkUnknownEvents: boolean;
|
|
28
|
+
checkUnknownDirectives: boolean;
|
|
29
|
+
checkUnknownComponents: boolean;
|
|
26
30
|
skipTemplateCodegen: boolean;
|
|
27
31
|
fallthroughAttributes: boolean;
|
|
28
32
|
dataAttributes: string[];
|
|
@@ -37,8 +41,10 @@ export interface VueCompilerOptions {
|
|
|
37
41
|
defineOptions: string[];
|
|
38
42
|
withDefaults: string[];
|
|
39
43
|
};
|
|
40
|
-
|
|
44
|
+
composables: {
|
|
45
|
+
useAttrs: string[];
|
|
41
46
|
useCssModule: string[];
|
|
47
|
+
useSlots: string[];
|
|
42
48
|
useTemplateRef: string[];
|
|
43
49
|
};
|
|
44
50
|
plugins: VueLanguagePlugin[];
|
|
@@ -81,8 +87,8 @@ export type VueLanguagePluginReturn = {
|
|
|
81
87
|
};
|
|
82
88
|
export type VueLanguagePlugin = (ctx: {
|
|
83
89
|
modules: {
|
|
84
|
-
typescript: typeof
|
|
85
|
-
'@vue/compiler-dom': typeof
|
|
90
|
+
typescript: typeof ts;
|
|
91
|
+
'@vue/compiler-dom': typeof CompilerDOM;
|
|
86
92
|
};
|
|
87
93
|
compilerOptions: ts.CompilerOptions;
|
|
88
94
|
vueCompilerOptions: VueCompilerOptions;
|
|
@@ -97,14 +103,9 @@ export interface SfcBlock {
|
|
|
97
103
|
content: string;
|
|
98
104
|
attrs: Record<string, string | true>;
|
|
99
105
|
}
|
|
100
|
-
export interface SFCStyleOverride {
|
|
101
|
-
module?: {
|
|
102
|
-
name: string;
|
|
103
|
-
offset?: number;
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
106
|
export interface Sfc {
|
|
107
107
|
content: string;
|
|
108
|
+
comments: string[];
|
|
108
109
|
template: SfcBlock & {
|
|
109
110
|
ast: CompilerDOM.RootNode | undefined;
|
|
110
111
|
errors: CompilerDOM.CompilerError[];
|
|
@@ -120,8 +121,12 @@ export interface Sfc {
|
|
|
120
121
|
genericOffset: number;
|
|
121
122
|
ast: ts.SourceFile;
|
|
122
123
|
} | undefined;
|
|
123
|
-
styles: readonly (SfcBlock &
|
|
124
|
+
styles: readonly (SfcBlock & {
|
|
124
125
|
scoped: boolean;
|
|
126
|
+
module?: {
|
|
127
|
+
name: string;
|
|
128
|
+
offset?: number;
|
|
129
|
+
};
|
|
125
130
|
cssVars: {
|
|
126
131
|
text: string;
|
|
127
132
|
offset: number;
|
|
@@ -135,6 +140,14 @@ export interface Sfc {
|
|
|
135
140
|
type: string;
|
|
136
141
|
})[];
|
|
137
142
|
}
|
|
143
|
+
declare module '@vue/compiler-sfc' {
|
|
144
|
+
interface SFCStyleBlock {
|
|
145
|
+
__module?: {
|
|
146
|
+
name: string;
|
|
147
|
+
offset?: number;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
138
151
|
export interface TextRange {
|
|
139
152
|
start: number;
|
|
140
153
|
end: number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCssImports = parseCssImports;
|
|
4
|
+
const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
|
|
5
|
+
function* parseCssImports(css) {
|
|
6
|
+
const matches = css.matchAll(cssImportReg);
|
|
7
|
+
for (const match of matches) {
|
|
8
|
+
let text = match[0];
|
|
9
|
+
let offset = match.index;
|
|
10
|
+
if (text.startsWith('\'') || text.startsWith('"')) {
|
|
11
|
+
text = text.slice(1, -1);
|
|
12
|
+
offset += 1;
|
|
13
|
+
}
|
|
14
|
+
if (text) {
|
|
15
|
+
yield { text, offset };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parseCssImports.js.map
|
package/lib/utils/parseSfc.d.ts
CHANGED
package/lib/utils/parseSfc.js
CHANGED
|
@@ -18,6 +18,7 @@ function parse(source) {
|
|
|
18
18
|
const descriptor = {
|
|
19
19
|
filename: 'anonymous.vue',
|
|
20
20
|
source,
|
|
21
|
+
comments: [],
|
|
21
22
|
template: null,
|
|
22
23
|
script: null,
|
|
23
24
|
scriptSetup: null,
|
|
@@ -28,7 +29,11 @@ function parse(source) {
|
|
|
28
29
|
shouldForceReload: () => false,
|
|
29
30
|
};
|
|
30
31
|
ast.children.forEach(node => {
|
|
31
|
-
if (node.type
|
|
32
|
+
if (node.type === compiler.NodeTypes.COMMENT) {
|
|
33
|
+
descriptor.comments.push(node.content);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
else if (node.type !== compiler.NodeTypes.ELEMENT) {
|
|
32
37
|
return;
|
|
33
38
|
}
|
|
34
39
|
switch (node.tag) {
|
|
@@ -37,7 +42,7 @@ function parse(source) {
|
|
|
37
42
|
break;
|
|
38
43
|
case 'script':
|
|
39
44
|
const scriptBlock = createBlock(node, source);
|
|
40
|
-
const isSetup = !!scriptBlock.
|
|
45
|
+
const isSetup = !!scriptBlock.setup;
|
|
41
46
|
if (isSetup && !descriptor.scriptSetup) {
|
|
42
47
|
descriptor.scriptSetup = scriptBlock;
|
|
43
48
|
break;
|
|
@@ -107,14 +112,15 @@ function createBlock(node, source) {
|
|
|
107
112
|
block.scoped = true;
|
|
108
113
|
}
|
|
109
114
|
else if (p.name === 'module') {
|
|
110
|
-
block.
|
|
115
|
+
block.__module = {
|
|
111
116
|
name: p.value?.content ?? '$style',
|
|
112
117
|
offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
|
|
113
118
|
};
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
|
-
else if (type === 'script'
|
|
117
|
-
|
|
121
|
+
else if (type === 'script'
|
|
122
|
+
&& (p.name === 'setup' || p.name === 'vapor')) {
|
|
123
|
+
block.setup = attrs[p.name];
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedArray = computedArray;
|
|
4
|
+
exports.computedSet = computedSet;
|
|
5
|
+
const alien_signals_1 = require("alien-signals");
|
|
6
|
+
function computedArray(arr, getGetter) {
|
|
7
|
+
const length = (0, alien_signals_1.computed)(() => arr().length);
|
|
8
|
+
const keys = (0, alien_signals_1.computed)(() => {
|
|
9
|
+
const keys = [];
|
|
10
|
+
for (let i = 0; i < length(); i++) {
|
|
11
|
+
keys.push(String(i));
|
|
12
|
+
}
|
|
13
|
+
return keys;
|
|
14
|
+
});
|
|
15
|
+
const items = (0, alien_signals_1.computed)(array => {
|
|
16
|
+
array ??= [];
|
|
17
|
+
while (array.length < length()) {
|
|
18
|
+
const index = array.length;
|
|
19
|
+
const item = (0, alien_signals_1.computed)(() => arr()[index]);
|
|
20
|
+
array.push((0, alien_signals_1.computed)(getGetter(item, index)));
|
|
21
|
+
}
|
|
22
|
+
if (array.length > length()) {
|
|
23
|
+
array.length = length();
|
|
24
|
+
}
|
|
25
|
+
return array;
|
|
26
|
+
});
|
|
27
|
+
return new Proxy({}, {
|
|
28
|
+
get(_, p, receiver) {
|
|
29
|
+
if (p === 'length') {
|
|
30
|
+
return length();
|
|
31
|
+
}
|
|
32
|
+
if (typeof p === 'string' && !isNaN(Number(p))) {
|
|
33
|
+
return items()[Number(p)]?.();
|
|
34
|
+
}
|
|
35
|
+
return Reflect.get(items(), p, receiver);
|
|
36
|
+
},
|
|
37
|
+
has(_, p) {
|
|
38
|
+
return Reflect.has(items(), p);
|
|
39
|
+
},
|
|
40
|
+
ownKeys() {
|
|
41
|
+
return keys();
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function computedSet(source) {
|
|
46
|
+
return (0, alien_signals_1.computed)(oldValue => {
|
|
47
|
+
const newValue = source();
|
|
48
|
+
if (oldValue?.size === newValue.size && [...oldValue].every(c => newValue.has(c))) {
|
|
49
|
+
return oldValue;
|
|
50
|
+
}
|
|
51
|
+
return newValue;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=signals.js.map
|
package/lib/utils/ts.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type { VueCompilerOptions } from '../types';
|
|
2
|
+
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';
|
|
3
3
|
export type ParsedCommandLine = ts.ParsedCommandLine & {
|
|
4
4
|
vueOptions: VueCompilerOptions;
|
|
5
5
|
};
|
|
@@ -7,7 +7,19 @@ export declare function createParsedCommandLineByJson(ts: typeof import('typescr
|
|
|
7
7
|
writeFile?(path: string, data: string): void;
|
|
8
8
|
}, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
|
|
9
9
|
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
|
|
10
|
-
export declare
|
|
10
|
+
export declare class CompilerOptionsResolver {
|
|
11
|
+
options: Omit<RawVueCompilerOptions, 'target' | 'plugin'>;
|
|
12
|
+
fallbackTarget: number | undefined;
|
|
13
|
+
target: number | undefined;
|
|
14
|
+
plugins: VueLanguagePlugin[];
|
|
15
|
+
addConfig(options: RawVueCompilerOptions, rootDir: string): void;
|
|
16
|
+
build(defaults?: VueCompilerOptions): VueCompilerOptions;
|
|
17
|
+
}
|
|
18
|
+
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use `getDefaultCompilerOptions` instead
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>): VueCompilerOptions;
|
|
11
23
|
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
|
|
12
24
|
fileExists(path: string): boolean;
|
|
13
25
|
writeFile?(path: string, data: string): void;
|