@vue/language-core 2.2.0 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +0 -1
- package/index.js +1 -2
- 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 +45 -37
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +4 -4
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +15 -11
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +2 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +1 -8
- package/lib/codegen/script/index.js +19 -45
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +78 -79
- package/lib/codegen/script/src.d.ts +2 -2
- package/lib/codegen/script/src.js +37 -38
- package/lib/codegen/script/template.d.ts +2 -3
- package/lib/codegen/script/template.js +12 -79
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +31 -0
- package/lib/codegen/style/modules.d.ts +3 -0
- package/lib/codegen/{script/styleModulesType.js → style/modules.js} +15 -15
- package/lib/codegen/style/scopedClasses.d.ts +4 -0
- package/lib/codegen/style/scopedClasses.js +32 -0
- package/lib/codegen/template/context.d.ts +122 -17
- package/lib/codegen/template/context.js +162 -92
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +86 -330
- package/lib/codegen/template/elementChildren.js +0 -13
- package/lib/codegen/template/elementDirectives.js +20 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +15 -11
- package/lib/codegen/template/elementProps.d.ts +2 -1
- package/lib/codegen/template/elementProps.js +31 -33
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +53 -33
- package/lib/codegen/template/interpolation.js +13 -9
- package/lib/codegen/template/slotOutlet.js +44 -21
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +146 -9
- package/lib/codegen/template/templateChild.js +69 -30
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/codegen/template/vIf.js +3 -3
- package/lib/codegen/template/vSlot.d.ts +6 -0
- package/lib/codegen/template/vSlot.js +92 -0
- package/lib/codegen/utils/index.d.ts +13 -2
- package/lib/codegen/utils/index.js +33 -6
- package/lib/parsers/scriptSetupRanges.d.ts +5 -3
- package/lib/parsers/scriptSetupRanges.js +24 -35
- package/lib/parsers/vueCompilerOptions.d.ts +2 -2
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-template-inline-ts.js +56 -15
- package/lib/plugins/vue-tsx.d.ts +43 -32
- package/lib/plugins/vue-tsx.js +88 -68
- package/lib/types.d.ts +29 -16
- package/lib/utils/parseSfc.js +41 -16
- 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 -88
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +14 -24
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +86 -96
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +8 -11
- package/lib/virtualFile/vueFile.js +15 -9
- package/package.json +4 -4
- package/lib/codegen/script/styleModulesType.d.ts +0 -4
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
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");
|
|
9
11
|
const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
12
|
+
const signals_1 = require("../utils/signals");
|
|
10
13
|
const ts_1 = require("../utils/ts");
|
|
11
14
|
exports.tsCodegen = new WeakMap();
|
|
12
15
|
const fileEditTimes = new Map();
|
|
@@ -19,17 +22,17 @@ const plugin = ctx => {
|
|
|
19
22
|
'exactOptionalPropertyTypes',
|
|
20
23
|
],
|
|
21
24
|
getEmbeddedCodes(fileName, sfc) {
|
|
22
|
-
const
|
|
25
|
+
const codegen = useCodegen(fileName, sfc);
|
|
23
26
|
const files = [];
|
|
24
|
-
if (['js', 'ts', 'jsx', 'tsx'].includes(
|
|
25
|
-
files.push({ id: 'script_' +
|
|
27
|
+
if (['js', 'ts', 'jsx', 'tsx'].includes(codegen.getLang())) {
|
|
28
|
+
files.push({ id: 'script_' + codegen.getLang(), lang: codegen.getLang() });
|
|
26
29
|
}
|
|
27
30
|
return files;
|
|
28
31
|
},
|
|
29
32
|
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
30
|
-
const _tsx = useTsx(fileName, sfc);
|
|
31
33
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
32
|
-
const
|
|
34
|
+
const codegen = useCodegen(fileName, sfc);
|
|
35
|
+
const tsx = codegen.getGeneratedScript();
|
|
33
36
|
if (tsx) {
|
|
34
37
|
embeddedFile.content = [...tsx.codes];
|
|
35
38
|
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
|
|
@@ -37,7 +40,7 @@ const plugin = ctx => {
|
|
|
37
40
|
}
|
|
38
41
|
},
|
|
39
42
|
};
|
|
40
|
-
function
|
|
43
|
+
function useCodegen(fileName, sfc) {
|
|
41
44
|
if (!exports.tsCodegen.has(sfc)) {
|
|
42
45
|
let appendGlobalTypes = false;
|
|
43
46
|
if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
|
|
@@ -50,91 +53,108 @@ const plugin = ctx => {
|
|
|
50
53
|
}
|
|
51
54
|
};
|
|
52
55
|
exports.default = plugin;
|
|
53
|
-
function createTsx(fileName,
|
|
56
|
+
function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
54
57
|
const ts = ctx.modules.typescript;
|
|
55
|
-
const
|
|
56
|
-
return !
|
|
57
|
-
:
|
|
58
|
-
:
|
|
58
|
+
const getLang = (0, alien_signals_1.computed)(() => {
|
|
59
|
+
return !sfc.script && !sfc.scriptSetup ? 'ts'
|
|
60
|
+
: sfc.scriptSetup && sfc.scriptSetup.lang !== 'js' ? sfc.scriptSetup.lang
|
|
61
|
+
: sfc.script && sfc.script.lang !== 'js' ? sfc.script.lang
|
|
59
62
|
: 'js';
|
|
60
63
|
});
|
|
61
|
-
const
|
|
62
|
-
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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;
|
|
66
72
|
});
|
|
67
|
-
const
|
|
68
|
-
? (0, scriptRanges_1.parseScriptRanges)(ts,
|
|
73
|
+
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
|
|
74
|
+
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
|
|
69
75
|
: undefined);
|
|
70
|
-
const
|
|
71
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts,
|
|
76
|
+
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
|
|
77
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
|
|
72
78
|
: undefined);
|
|
73
|
-
const
|
|
79
|
+
const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
74
80
|
const newNames = new Set();
|
|
75
|
-
const bindings =
|
|
76
|
-
if (
|
|
81
|
+
const bindings = getScriptSetupRanges()?.bindings;
|
|
82
|
+
if (sfc.scriptSetup && bindings) {
|
|
77
83
|
for (const { range } of bindings) {
|
|
78
|
-
newNames.add(
|
|
84
|
+
newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
return newNames;
|
|
82
88
|
}));
|
|
83
|
-
const
|
|
89
|
+
const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
84
90
|
const newNames = new Set();
|
|
85
|
-
const bindings =
|
|
86
|
-
if (
|
|
91
|
+
const bindings = getScriptSetupRanges()?.bindings;
|
|
92
|
+
if (sfc.scriptSetup && bindings) {
|
|
87
93
|
for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
|
|
88
94
|
if (moduleName
|
|
89
95
|
&& isDefaultImport
|
|
90
96
|
&& !isNamespace
|
|
91
97
|
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
92
|
-
newNames.add(
|
|
98
|
+
newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
}
|
|
96
102
|
return newNames;
|
|
97
103
|
}));
|
|
98
|
-
const
|
|
99
|
-
const newNames = new Set(
|
|
100
|
-
const rest =
|
|
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;
|
|
101
107
|
if (rest) {
|
|
102
108
|
newNames.add(rest);
|
|
103
109
|
}
|
|
104
110
|
return newNames;
|
|
105
111
|
}));
|
|
106
|
-
const
|
|
107
|
-
const newNames = new Set(
|
|
112
|
+
const getSetupTemplateRefNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
|
|
113
|
+
const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
|
|
108
114
|
.map(({ name }) => name)
|
|
109
115
|
.filter(name => name !== undefined));
|
|
110
116
|
return newNames;
|
|
111
117
|
}));
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const value =
|
|
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;
|
|
117
123
|
return value !== 'false';
|
|
118
124
|
});
|
|
119
|
-
const
|
|
120
|
-
|
|
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) {
|
|
121
140
|
return;
|
|
122
141
|
}
|
|
123
142
|
const codes = [];
|
|
124
143
|
const codegen = (0, template_1.generateTemplate)({
|
|
125
144
|
ts,
|
|
126
145
|
compilerOptions: ctx.compilerOptions,
|
|
127
|
-
vueCompilerOptions:
|
|
128
|
-
template:
|
|
129
|
-
edited:
|
|
130
|
-
scriptSetupBindingNames:
|
|
131
|
-
scriptSetupImportComponentNames:
|
|
132
|
-
destructuredPropNames:
|
|
133
|
-
templateRefNames:
|
|
134
|
-
hasDefineSlots:
|
|
135
|
-
slotsAssignName:
|
|
136
|
-
propsAssignName:
|
|
137
|
-
inheritAttrs:
|
|
146
|
+
vueCompilerOptions: getResolvedOptions(),
|
|
147
|
+
template: sfc.template,
|
|
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(),
|
|
138
158
|
});
|
|
139
159
|
let current = codegen.next();
|
|
140
160
|
while (!current.done) {
|
|
@@ -144,26 +164,26 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
144
164
|
}
|
|
145
165
|
return {
|
|
146
166
|
...current.value,
|
|
147
|
-
codes
|
|
167
|
+
codes,
|
|
148
168
|
};
|
|
149
169
|
});
|
|
150
|
-
const
|
|
151
|
-
const codes = [];
|
|
170
|
+
const getGeneratedScript = (0, alien_signals_1.computed)(() => {
|
|
152
171
|
const linkedCodeMappings = [];
|
|
153
172
|
let generatedLength = 0;
|
|
173
|
+
const codes = [];
|
|
154
174
|
const codegen = (0, script_1.generateScript)({
|
|
155
175
|
ts,
|
|
156
176
|
compilerOptions: ctx.compilerOptions,
|
|
157
|
-
vueCompilerOptions:
|
|
158
|
-
sfc:
|
|
159
|
-
edited:
|
|
177
|
+
vueCompilerOptions: getResolvedOptions(),
|
|
178
|
+
sfc: sfc,
|
|
179
|
+
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
160
180
|
fileName,
|
|
161
|
-
lang:
|
|
162
|
-
scriptRanges:
|
|
163
|
-
scriptSetupRanges:
|
|
164
|
-
templateCodegen:
|
|
165
|
-
destructuredPropNames:
|
|
166
|
-
templateRefNames:
|
|
181
|
+
lang: getLang(),
|
|
182
|
+
scriptRanges: getScriptRanges(),
|
|
183
|
+
scriptSetupRanges: getScriptSetupRanges(),
|
|
184
|
+
templateCodegen: getGeneratedTemplate(),
|
|
185
|
+
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
186
|
+
templateRefNames: getSetupTemplateRefNames(),
|
|
167
187
|
getGeneratedLength: () => generatedLength,
|
|
168
188
|
linkedCodeMappings,
|
|
169
189
|
appendGlobalTypes,
|
|
@@ -185,11 +205,11 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
185
205
|
};
|
|
186
206
|
});
|
|
187
207
|
return {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
208
|
+
getScriptRanges,
|
|
209
|
+
getScriptSetupRanges,
|
|
210
|
+
getLang,
|
|
211
|
+
getGeneratedScript,
|
|
212
|
+
getGeneratedTemplate,
|
|
193
213
|
};
|
|
194
214
|
}
|
|
195
215
|
//# sourceMappingURL=vue-tsx.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ 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 {
|
|
14
|
-
|
|
15
|
-
__combineOffsetMapping?: number;
|
|
15
|
+
__combineOffset?: number;
|
|
16
16
|
}
|
|
17
17
|
export type Code = Segment<VueCodeInformation>;
|
|
18
18
|
export interface VueCompilerOptions {
|
|
@@ -22,9 +22,19 @@ export interface VueCompilerOptions {
|
|
|
22
22
|
vitePressExtensions: string[];
|
|
23
23
|
petiteVueExtensions: string[];
|
|
24
24
|
jsxSlots: boolean;
|
|
25
|
-
|
|
25
|
+
checkUnknownProps: boolean;
|
|
26
|
+
checkUnknownEvents: boolean;
|
|
27
|
+
checkUnknownDirectives: boolean;
|
|
28
|
+
checkUnknownComponents: boolean;
|
|
29
|
+
inferComponentDollarEl: boolean;
|
|
30
|
+
inferComponentDollarRefs: boolean;
|
|
31
|
+
inferTemplateDollarAttrs: boolean;
|
|
32
|
+
inferTemplateDollarEl: boolean;
|
|
33
|
+
inferTemplateDollarRefs: boolean;
|
|
34
|
+
inferTemplateDollarSlots: boolean;
|
|
26
35
|
skipTemplateCodegen: boolean;
|
|
27
36
|
fallthroughAttributes: boolean;
|
|
37
|
+
fallthroughComponentNames: string[];
|
|
28
38
|
dataAttributes: string[];
|
|
29
39
|
htmlAttributes: string[];
|
|
30
40
|
optionsWrapper: [string, string] | [];
|
|
@@ -99,6 +109,11 @@ export interface SfcBlock {
|
|
|
99
109
|
content: string;
|
|
100
110
|
attrs: Record<string, string | true>;
|
|
101
111
|
}
|
|
112
|
+
export type SfcBlockAttr = true | {
|
|
113
|
+
text: string;
|
|
114
|
+
offset: number;
|
|
115
|
+
quotes: boolean;
|
|
116
|
+
};
|
|
102
117
|
export interface Sfc {
|
|
103
118
|
content: string;
|
|
104
119
|
comments: string[];
|
|
@@ -108,21 +123,16 @@ export interface Sfc {
|
|
|
108
123
|
warnings: CompilerDOM.CompilerError[];
|
|
109
124
|
} | undefined;
|
|
110
125
|
script: (SfcBlock & {
|
|
111
|
-
src:
|
|
112
|
-
srcOffset: number;
|
|
126
|
+
src: SfcBlockAttr | undefined;
|
|
113
127
|
ast: ts.SourceFile;
|
|
114
128
|
}) | undefined;
|
|
115
129
|
scriptSetup: SfcBlock & {
|
|
116
|
-
generic:
|
|
117
|
-
genericOffset: number;
|
|
130
|
+
generic: SfcBlockAttr | undefined;
|
|
118
131
|
ast: ts.SourceFile;
|
|
119
132
|
} | undefined;
|
|
120
133
|
styles: readonly (SfcBlock & {
|
|
121
134
|
scoped: boolean;
|
|
122
|
-
module?:
|
|
123
|
-
name: string;
|
|
124
|
-
offset?: number;
|
|
125
|
-
};
|
|
135
|
+
module?: SfcBlockAttr | undefined;
|
|
126
136
|
cssVars: {
|
|
127
137
|
text: string;
|
|
128
138
|
offset: number;
|
|
@@ -137,11 +147,14 @@ export interface Sfc {
|
|
|
137
147
|
})[];
|
|
138
148
|
}
|
|
139
149
|
declare module '@vue/compiler-sfc' {
|
|
150
|
+
interface SFCBlock {
|
|
151
|
+
__src?: SfcBlockAttr;
|
|
152
|
+
}
|
|
153
|
+
interface SFCScriptBlock {
|
|
154
|
+
__generic?: SfcBlockAttr;
|
|
155
|
+
}
|
|
140
156
|
interface SFCStyleBlock {
|
|
141
|
-
__module?:
|
|
142
|
-
name: string;
|
|
143
|
-
offset?: number;
|
|
144
|
-
};
|
|
157
|
+
__module?: SfcBlockAttr;
|
|
145
158
|
}
|
|
146
159
|
}
|
|
147
160
|
export interface TextRange {
|
package/lib/utils/parseSfc.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = parse;
|
|
4
|
-
const
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
function parse(source) {
|
|
6
6
|
const errors = [];
|
|
7
|
-
const ast =
|
|
7
|
+
const ast = CompilerDOM.parse(source, {
|
|
8
8
|
// there are no components at SFC parsing level
|
|
9
9
|
isNativeTag: () => true,
|
|
10
10
|
// preserve all whitespaces
|
|
@@ -29,11 +29,11 @@ function parse(source) {
|
|
|
29
29
|
shouldForceReload: () => false,
|
|
30
30
|
};
|
|
31
31
|
ast.children.forEach(node => {
|
|
32
|
-
if (node.type ===
|
|
32
|
+
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
33
33
|
descriptor.comments.push(node.content);
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
else if (node.type !==
|
|
36
|
+
else if (node.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
switch (node.tag) {
|
|
@@ -42,7 +42,7 @@ function parse(source) {
|
|
|
42
42
|
break;
|
|
43
43
|
case 'script':
|
|
44
44
|
const scriptBlock = createBlock(node, source);
|
|
45
|
-
const isSetup = !!scriptBlock.
|
|
45
|
+
const isSetup = !!scriptBlock.setup;
|
|
46
46
|
if (isSetup && !descriptor.scriptSetup) {
|
|
47
47
|
descriptor.scriptSetup = scriptBlock;
|
|
48
48
|
break;
|
|
@@ -99,30 +99,55 @@ function createBlock(node, source) {
|
|
|
99
99
|
attrs
|
|
100
100
|
};
|
|
101
101
|
node.props.forEach(p => {
|
|
102
|
-
if (p.type ===
|
|
102
|
+
if (p.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
103
103
|
attrs[p.name] = p.value ? p.value.content || true : true;
|
|
104
104
|
if (p.name === 'lang') {
|
|
105
|
-
block.lang = p.value
|
|
105
|
+
block.lang = p.value?.content;
|
|
106
106
|
}
|
|
107
107
|
else if (p.name === 'src') {
|
|
108
|
-
block.
|
|
108
|
+
block.__src = parseAttr(p, node);
|
|
109
109
|
}
|
|
110
|
-
else if (
|
|
110
|
+
else if (isScriptBlock(block)) {
|
|
111
|
+
if (p.name === 'setup' || p.name === 'vapor') {
|
|
112
|
+
block.setup = attrs[p.name];
|
|
113
|
+
}
|
|
114
|
+
else if (p.name === 'generic') {
|
|
115
|
+
block.__generic = parseAttr(p, node);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (isStyleBlock(block)) {
|
|
111
119
|
if (p.name === 'scoped') {
|
|
112
120
|
block.scoped = true;
|
|
113
121
|
}
|
|
114
122
|
else if (p.name === 'module') {
|
|
115
|
-
block.__module =
|
|
116
|
-
name: p.value?.content ?? '$style',
|
|
117
|
-
offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
|
|
118
|
-
};
|
|
123
|
+
block.__module = parseAttr(p, node);
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
|
-
else if (type === 'script' && p.name === 'setup') {
|
|
122
|
-
block.setup = attrs.setup;
|
|
123
|
-
}
|
|
124
126
|
}
|
|
125
127
|
});
|
|
126
128
|
return block;
|
|
127
129
|
}
|
|
130
|
+
function isScriptBlock(block) {
|
|
131
|
+
return block.type === 'script';
|
|
132
|
+
}
|
|
133
|
+
function isStyleBlock(block) {
|
|
134
|
+
return block.type === 'style';
|
|
135
|
+
}
|
|
136
|
+
function parseAttr(p, node) {
|
|
137
|
+
if (!p.value) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
const text = p.value.content;
|
|
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
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
text,
|
|
149
|
+
offset,
|
|
150
|
+
quotes,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
128
153
|
//# sourceMappingURL=parseSfc.js.map
|
|
@@ -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;
|