@vue/language-core 3.0.7-alpha.1 → 3.0.8
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/lib/codegen/script/componentSelf.js +1 -1
- package/lib/codegen/script/index.js +2 -6
- package/lib/codegen/script/scriptSetup.js +2 -2
- package/lib/codegen/template/element.js +3 -3
- package/lib/codegen/template/elementProps.js +4 -5
- package/lib/codegen/template/index.js +2 -3
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +1 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/codegen/template/vSlot.js +1 -1
- package/lib/compilerOptions.js +2 -5
- package/lib/parsers/scriptRanges.js +1 -1
- package/lib/parsers/scriptSetupRanges.js +2 -2
- package/lib/plugins/vue-template-inline-ts.js +2 -3
- package/lib/plugins/vue-tsx.js +1 -3
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/vue2TemplateCompiler.js +2 -2
- package/lib/virtualFile/computedSfc.js +4 -4
- package/lib/virtualFile/vueFile.d.ts +5 -10
- package/lib/virtualFile/vueFile.js +3 -10
- package/package.json +2 -2
- package/lib/utils/ts.js +0 -296
|
@@ -32,7 +32,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
32
32
|
yield `${varName},${utils_1.newLine}`;
|
|
33
33
|
}
|
|
34
34
|
yield `}),${utils_1.newLine}`;
|
|
35
|
-
if (
|
|
35
|
+
if (!ctx.bypassDefineComponent) {
|
|
36
36
|
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
|
37
37
|
yield* emitOptionCodes;
|
|
38
38
|
yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
|
|
@@ -47,9 +47,7 @@ function* generateScript(options, ctx) {
|
|
|
47
47
|
blockName: options.sfc.script.name,
|
|
48
48
|
offset: exportDefault.expression.start,
|
|
49
49
|
setting: 'vue.inlayHints.optionsWrapper',
|
|
50
|
-
label: options.vueCompilerOptions.optionsWrapper
|
|
51
|
-
? options.vueCompilerOptions.optionsWrapper[0]
|
|
52
|
-
: '[Missing optionsWrapper[0]]',
|
|
50
|
+
label: options.vueCompilerOptions.optionsWrapper[0],
|
|
53
51
|
tooltip: [
|
|
54
52
|
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
|
55
53
|
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
@@ -58,9 +56,7 @@ function* generateScript(options, ctx) {
|
|
|
58
56
|
blockName: options.sfc.script.name,
|
|
59
57
|
offset: exportDefault.expression.end,
|
|
60
58
|
setting: 'vue.inlayHints.optionsWrapper',
|
|
61
|
-
label: options.vueCompilerOptions.optionsWrapper
|
|
62
|
-
? options.vueCompilerOptions.optionsWrapper[1]
|
|
63
|
-
: '[Missing optionsWrapper[1]]',
|
|
59
|
+
label: options.vueCompilerOptions.optionsWrapper[1],
|
|
64
60
|
});
|
|
65
61
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
|
|
66
62
|
yield options.vueCompilerOptions.optionsWrapper[0];
|
|
@@ -97,7 +97,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
97
97
|
[
|
|
98
98
|
`let __VLS_exposed!: `,
|
|
99
99
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
|
|
100
|
-
|
|
100
|
+
utils_1.endOfLine,
|
|
101
101
|
],
|
|
102
102
|
callExp.start,
|
|
103
103
|
callExp.start,
|
|
@@ -112,7 +112,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
112
112
|
[
|
|
113
113
|
`const __VLS_exposed = `,
|
|
114
114
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
115
|
-
|
|
115
|
+
utils_1.endOfLine,
|
|
116
116
|
],
|
|
117
117
|
callExp.start,
|
|
118
118
|
callExp.start,
|
|
@@ -110,7 +110,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
110
110
|
? codeFeatures_1.codeFeatures.verification
|
|
111
111
|
: codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
|
|
112
112
|
});
|
|
113
|
-
yield
|
|
113
|
+
yield utils_1.endOfLine;
|
|
114
114
|
const camelizedTag = (0, shared_1.camelize)(node.tag);
|
|
115
115
|
if (utils_1.identifierRegex.test(camelizedTag)) {
|
|
116
116
|
// navigation support
|
|
@@ -131,7 +131,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
131
131
|
onlyImport: true,
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
|
-
yield
|
|
134
|
+
yield utils_1.endOfLine;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
@@ -159,7 +159,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
159
159
|
if (ctx.inVFor) {
|
|
160
160
|
yield `[]`;
|
|
161
161
|
}
|
|
162
|
-
yield
|
|
162
|
+
yield utils_1.endOfLine;
|
|
163
163
|
if (refName && offset) {
|
|
164
164
|
ctx.addTemplateRef(refName, `typeof ${ctx.getHoistVariable(componentInstanceVar)}`, offset);
|
|
165
165
|
}
|
|
@@ -138,8 +138,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
138
138
|
}
|
|
139
139
|
yield `,${utils_1.newLine}`;
|
|
140
140
|
}
|
|
141
|
-
else if (prop.
|
|
142
|
-
&& prop.name === 'bind'
|
|
141
|
+
else if (prop.name === 'bind'
|
|
143
142
|
&& !prop.arg
|
|
144
143
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
145
144
|
if (prop.exp.loc.source === '$attrs') {
|
|
@@ -172,8 +171,8 @@ function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
|
|
|
172
171
|
else {
|
|
173
172
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
174
173
|
if (utils_1.identifierRegex.test(propVariableName)) {
|
|
175
|
-
const isDestructuredProp = options.destructuredPropNames
|
|
176
|
-
const isTemplateRef = options.templateRefNames
|
|
174
|
+
const isDestructuredProp = options.destructuredPropNames.has(propVariableName);
|
|
175
|
+
const isTemplateRef = options.templateRefNames.has(propVariableName);
|
|
177
176
|
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, features);
|
|
178
177
|
if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
|
|
179
178
|
yield* codes;
|
|
@@ -216,7 +215,7 @@ function* generateAttrValue(attrNode, features) {
|
|
|
216
215
|
function getShouldCamelize(options, prop, propName) {
|
|
217
216
|
return (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
|
218
217
|
|| !prop.arg
|
|
219
|
-
|| (prop.arg
|
|
218
|
+
|| (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
|
|
220
219
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
221
220
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
|
|
222
221
|
}
|
|
@@ -79,7 +79,7 @@ function* generateSlots(options, ctx) {
|
|
|
79
79
|
}
|
|
80
80
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
81
81
|
}
|
|
82
|
-
yield
|
|
82
|
+
yield utils_1.endOfLine;
|
|
83
83
|
}
|
|
84
84
|
return `__VLS_Slots`;
|
|
85
85
|
}
|
|
@@ -160,8 +160,7 @@ function* forEachElementNode(node) {
|
|
|
160
160
|
}
|
|
161
161
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
162
162
|
// v-if / v-else-if / v-else
|
|
163
|
-
for (
|
|
164
|
-
const branch = node.branches[i];
|
|
163
|
+
for (const branch of node.branches) {
|
|
165
164
|
for (const childNode of branch.children) {
|
|
166
165
|
yield* forEachElementNode(childNode);
|
|
167
166
|
}
|
|
@@ -19,8 +19,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
19
19
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
20
20
|
return prop.name === 'name';
|
|
21
21
|
}
|
|
22
|
-
if (prop.
|
|
23
|
-
&& prop.name === 'bind'
|
|
22
|
+
if (prop.name === 'bind'
|
|
24
23
|
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
25
24
|
return prop.arg.content === 'name';
|
|
26
25
|
}
|
|
@@ -48,7 +47,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
48
47
|
else {
|
|
49
48
|
codes = [`['default']`];
|
|
50
49
|
}
|
|
51
|
-
yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification,
|
|
50
|
+
yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, options.slotsAssignName ?? '__VLS_slots', ...codes);
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
54
53
|
yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
|
|
@@ -47,10 +47,9 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
let isWrapped = false;
|
|
51
50
|
const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
52
51
|
if (content) {
|
|
53
|
-
const classes = collectClasses(content, startOffset
|
|
52
|
+
const classes = collectClasses(content, startOffset);
|
|
54
53
|
ctx.scopedClasses.push(...classes);
|
|
55
54
|
}
|
|
56
55
|
else {
|
|
@@ -40,7 +40,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
40
40
|
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
41
41
|
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
42
42
|
&& argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
43
|
-
&& argument.returns
|
|
43
|
+
&& argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
|
44
44
|
if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
|
|
45
45
|
isFragment = false;
|
|
46
46
|
continue;
|
|
@@ -73,7 +73,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
73
73
|
function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
74
74
|
const { ts } = options;
|
|
75
75
|
const statement = ast.statements[0];
|
|
76
|
-
if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
76
|
+
if (!statement || !ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
const { expression } = statement;
|
package/lib/compilerOptions.js
CHANGED
|
@@ -277,13 +277,10 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
279
|
function writeGlobalTypes(vueOptions, writeFile) {
|
|
280
|
-
const originalFn = vueOptions.globalTypesPath;
|
|
281
|
-
if (!originalFn) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
280
|
const writed = new Set();
|
|
281
|
+
const { globalTypesPath } = vueOptions;
|
|
285
282
|
vueOptions.globalTypesPath = (fileName) => {
|
|
286
|
-
const result =
|
|
283
|
+
const result = globalTypesPath(fileName);
|
|
287
284
|
if (result && !writed.has(result)) {
|
|
288
285
|
writed.add(result);
|
|
289
286
|
writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
|
|
@@ -60,7 +60,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
|
60
60
|
}
|
|
61
61
|
if (ts.isClassDeclaration(raw)
|
|
62
62
|
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
|
|
63
|
-
&& raw.modifiers
|
|
63
|
+
&& raw.modifiers.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
64
64
|
classBlockEnd = raw.end - 1;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
@@ -335,8 +335,8 @@ function parseBindingRanges(ts, ast) {
|
|
|
335
335
|
function getStatementRange(ts, parents, node, ast) {
|
|
336
336
|
let statementRange;
|
|
337
337
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
const statement = parents[i];
|
|
339
|
+
if (ts.isStatement(statement)) {
|
|
340
340
|
ts.forEachChild(statement, child => {
|
|
341
341
|
const range = (0, shared_1.getStartEnd)(ts, child, ast);
|
|
342
342
|
statementRange ??= range;
|
|
@@ -59,7 +59,7 @@ const plugin = ctx => {
|
|
|
59
59
|
return data;
|
|
60
60
|
}
|
|
61
61
|
const templateContent = sfc.template.content;
|
|
62
|
-
const inlineTsAsts =
|
|
62
|
+
const inlineTsAsts = computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
|
|
63
63
|
let i = 0;
|
|
64
64
|
sfc.template.ast.children.forEach(visit);
|
|
65
65
|
return data;
|
|
@@ -120,8 +120,7 @@ const plugin = ctx => {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
123
|
-
for (
|
|
124
|
-
const branch = node.branches[i];
|
|
123
|
+
for (const branch of node.branches) {
|
|
125
124
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
126
125
|
addFormatCodes(branch.condition.loc.source, branch.condition.loc.start.offset, formatBrackets.if);
|
|
127
126
|
}
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -31,9 +31,7 @@ const plugin = ctx => {
|
|
|
31
31
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
32
32
|
const codegen = useCodegen(fileName, sfc);
|
|
33
33
|
const tsx = codegen.getGeneratedScript();
|
|
34
|
-
|
|
35
|
-
embeddedFile.content = [...tsx.codes];
|
|
36
|
-
}
|
|
34
|
+
embeddedFile.content = [...tsx.codes];
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
37
|
};
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ 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
6
|
export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
|
|
7
|
-
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): number[];
|
|
7
|
+
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
|
|
8
8
|
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
9
9
|
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
|
@@ -31,7 +31,7 @@ const compile = (template, options = {}) => {
|
|
|
31
31
|
loc: {
|
|
32
32
|
source: '',
|
|
33
33
|
start: { column: -1, line: -1, offset: error.start },
|
|
34
|
-
end: { column: -1, line: -1, offset: error.end
|
|
34
|
+
end: { column: -1, line: -1, offset: error.end },
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ const compile = (template, options = {}) => {
|
|
|
43
43
|
loc: {
|
|
44
44
|
source: '',
|
|
45
45
|
start: { column: -1, line: -1, offset: error.start },
|
|
46
|
-
end: { column: -1, line: -1, offset: error.end
|
|
46
|
+
end: { column: -1, line: -1, offset: error.end },
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -18,7 +18,7 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
18
18
|
const getComments = (0, alien_signals_1.computed)(oldValue => {
|
|
19
19
|
const newValue = getParseResult()?.descriptor.comments ?? [];
|
|
20
20
|
if (oldValue?.length === newValue.length
|
|
21
|
-
&& oldValue
|
|
21
|
+
&& oldValue.every((v, i) => v === newValue[i])) {
|
|
22
22
|
return oldValue;
|
|
23
23
|
}
|
|
24
24
|
return newValue;
|
|
@@ -27,13 +27,13 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
27
27
|
const compiledAst = computedTemplateAst(base);
|
|
28
28
|
return mergeObject(base, {
|
|
29
29
|
get ast() {
|
|
30
|
-
return compiledAst()
|
|
30
|
+
return compiledAst().ast;
|
|
31
31
|
},
|
|
32
32
|
get errors() {
|
|
33
|
-
return compiledAst()
|
|
33
|
+
return compiledAst().errors;
|
|
34
34
|
},
|
|
35
35
|
get warnings() {
|
|
36
|
-
return compiledAst()
|
|
36
|
+
return compiledAst().warnings;
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
39
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { VirtualCode } from '@volar/language-core';
|
|
1
|
+
import type { CodeInformation, Mapping, VirtualCode } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { VueCompilerOptions, VueLanguagePluginReturn } from '../types';
|
|
4
|
+
import { computedSfc } from './computedSfc';
|
|
4
5
|
export declare class VueVirtualCode implements VirtualCode {
|
|
5
6
|
fileName: string;
|
|
6
7
|
languageId: string;
|
|
@@ -8,22 +9,16 @@ export declare class VueVirtualCode implements VirtualCode {
|
|
|
8
9
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
10
|
plugins: VueLanguagePluginReturn[];
|
|
10
11
|
ts: typeof import('typescript');
|
|
11
|
-
id
|
|
12
|
+
readonly id = "main";
|
|
13
|
+
readonly sfc: ReturnType<typeof computedSfc>;
|
|
12
14
|
private _snapshot;
|
|
13
15
|
private _vueSfc;
|
|
14
|
-
private _sfc;
|
|
15
16
|
private _embeddedCodes;
|
|
16
17
|
private _mappings;
|
|
17
18
|
get snapshot(): ts.IScriptSnapshot;
|
|
18
19
|
get vueSfc(): import("@vue/compiler-sfc").SFCParseResult | undefined;
|
|
19
|
-
get sfc(): import("../types").Sfc;
|
|
20
20
|
get embeddedCodes(): VirtualCode[];
|
|
21
|
-
get mappings():
|
|
22
|
-
sourceOffsets: number[];
|
|
23
|
-
generatedOffsets: number[];
|
|
24
|
-
lengths: number[];
|
|
25
|
-
data: import("@volar/language-core").CodeInformation;
|
|
26
|
-
}[];
|
|
21
|
+
get mappings(): Mapping<CodeInformation>[];
|
|
27
22
|
constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: VueLanguagePluginReturn[], ts: typeof import('typescript'));
|
|
28
23
|
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
29
24
|
}
|
|
@@ -7,16 +7,12 @@ const computedEmbeddedCodes_1 = require("./computedEmbeddedCodes");
|
|
|
7
7
|
const computedSfc_1 = require("./computedSfc");
|
|
8
8
|
const computedVueSfc_1 = require("./computedVueSfc");
|
|
9
9
|
class VueVirtualCode {
|
|
10
|
-
// others
|
|
11
10
|
get snapshot() {
|
|
12
11
|
return this._snapshot();
|
|
13
12
|
}
|
|
14
13
|
get vueSfc() {
|
|
15
14
|
return this._vueSfc();
|
|
16
15
|
}
|
|
17
|
-
get sfc() {
|
|
18
|
-
return this._sfc;
|
|
19
|
-
}
|
|
20
16
|
get embeddedCodes() {
|
|
21
17
|
return this._embeddedCodes();
|
|
22
18
|
}
|
|
@@ -30,13 +26,11 @@ class VueVirtualCode {
|
|
|
30
26
|
this.vueCompilerOptions = vueCompilerOptions;
|
|
31
27
|
this.plugins = plugins;
|
|
32
28
|
this.ts = ts;
|
|
33
|
-
// sources
|
|
34
29
|
this.id = 'main';
|
|
35
|
-
this._snapshot = (0, alien_signals_1.signal)(
|
|
36
|
-
// computeds
|
|
30
|
+
this._snapshot = (0, alien_signals_1.signal)(initSnapshot);
|
|
37
31
|
this._vueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, this.languageId, this._snapshot);
|
|
38
|
-
this.
|
|
39
|
-
this._embeddedCodes = (0, computedEmbeddedCodes_1.computedEmbeddedCodes)(this.plugins, this.fileName, this.
|
|
32
|
+
this.sfc = (0, computedSfc_1.computedSfc)(this.ts, this.plugins, this.fileName, this._snapshot, this._vueSfc);
|
|
33
|
+
this._embeddedCodes = (0, computedEmbeddedCodes_1.computedEmbeddedCodes)(this.plugins, this.fileName, this.sfc);
|
|
40
34
|
this._mappings = (0, alien_signals_1.computed)(() => {
|
|
41
35
|
const snapshot = this._snapshot();
|
|
42
36
|
return [{
|
|
@@ -46,7 +40,6 @@ class VueVirtualCode {
|
|
|
46
40
|
data: plugins_1.allCodeFeatures,
|
|
47
41
|
}];
|
|
48
42
|
});
|
|
49
|
-
this._snapshot(initSnapshot);
|
|
50
43
|
}
|
|
51
44
|
update(newSnapshot) {
|
|
52
45
|
this._snapshot(newSnapshot);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"optional": true
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f7bdeaa7bb476df1fc8ff46c504d75c1869b0be9"
|
|
41
41
|
}
|
package/lib/utils/ts.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompilerOptionsResolver = void 0;
|
|
4
|
-
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
|
-
exports.createParsedCommandLine = createParsedCommandLine;
|
|
6
|
-
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
|
-
exports.writeGlobalTypes = writeGlobalTypes;
|
|
8
|
-
const shared_1 = require("@vue/shared");
|
|
9
|
-
const path_browserify_1 = require("path-browserify");
|
|
10
|
-
const globalTypes_1 = require("../codegen/globalTypes");
|
|
11
|
-
const shared_2 = require("./shared");
|
|
12
|
-
function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName) {
|
|
13
|
-
const extendedPaths = new Set();
|
|
14
|
-
const proxyHost = {
|
|
15
|
-
...host,
|
|
16
|
-
readFile(fileName) {
|
|
17
|
-
if (!fileName.endsWith('/package.json')) {
|
|
18
|
-
extendedPaths.add(fileName);
|
|
19
|
-
}
|
|
20
|
-
return host.readFile(fileName);
|
|
21
|
-
},
|
|
22
|
-
readDirectory() {
|
|
23
|
-
return [];
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
const parsed = ts.parseJsonConfigFileContent(json, proxyHost, rootDir, {}, configFileName);
|
|
27
|
-
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
28
|
-
for (const extendPath of [...extendedPaths].reverse()) {
|
|
29
|
-
try {
|
|
30
|
-
const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
|
|
31
|
-
const obj = ts.convertToObject(configFile, []);
|
|
32
|
-
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
33
|
-
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
34
|
-
}
|
|
35
|
-
catch { }
|
|
36
|
-
}
|
|
37
|
-
// ensure the rootDir is added to the config roots
|
|
38
|
-
resolver.addConfig({}, rootDir);
|
|
39
|
-
return {
|
|
40
|
-
...parsed,
|
|
41
|
-
vueOptions: resolver.build(),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function createParsedCommandLine(ts, host, configFileName) {
|
|
45
|
-
try {
|
|
46
|
-
const extendedPaths = new Set();
|
|
47
|
-
const proxyHost = {
|
|
48
|
-
...host,
|
|
49
|
-
readFile(fileName) {
|
|
50
|
-
if (!fileName.endsWith('/package.json')) {
|
|
51
|
-
extendedPaths.add(fileName);
|
|
52
|
-
}
|
|
53
|
-
return host.readFile(fileName);
|
|
54
|
-
},
|
|
55
|
-
readDirectory() {
|
|
56
|
-
return [];
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
|
|
60
|
-
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
|
|
61
|
-
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
62
|
-
for (const extendPath of [...extendedPaths].reverse()) {
|
|
63
|
-
try {
|
|
64
|
-
const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
|
|
65
|
-
const obj = ts.convertToObject(configFile, []);
|
|
66
|
-
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
67
|
-
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
68
|
-
}
|
|
69
|
-
catch { }
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
...parsed,
|
|
73
|
-
vueOptions: resolver.build(),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
catch { }
|
|
77
|
-
return {
|
|
78
|
-
options: {},
|
|
79
|
-
errors: [],
|
|
80
|
-
vueOptions: getDefaultCompilerOptions(),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
class CompilerOptionsResolver {
|
|
84
|
-
constructor(fileExists) {
|
|
85
|
-
this.fileExists = fileExists;
|
|
86
|
-
this.configRoots = new Set();
|
|
87
|
-
this.options = {};
|
|
88
|
-
this.plugins = [];
|
|
89
|
-
}
|
|
90
|
-
addConfig(options, rootDir) {
|
|
91
|
-
this.configRoots.add(rootDir);
|
|
92
|
-
for (const key in options) {
|
|
93
|
-
switch (key) {
|
|
94
|
-
case 'target':
|
|
95
|
-
if (options[key] === 'auto') {
|
|
96
|
-
this.target = findVueVersion(rootDir);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.target = options[key];
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
case 'globalTypesPath':
|
|
103
|
-
if (options[key] !== undefined) {
|
|
104
|
-
this.globalTypesPath = path_browserify_1.posix.join(rootDir, options[key]);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
case 'plugins':
|
|
108
|
-
this.plugins = (options.plugins ?? [])
|
|
109
|
-
.flatMap((pluginPath) => {
|
|
110
|
-
try {
|
|
111
|
-
const resolvedPath = resolvePath(pluginPath, rootDir);
|
|
112
|
-
if (resolvedPath) {
|
|
113
|
-
const plugin = require(resolvedPath);
|
|
114
|
-
plugin.__moduleName = pluginPath;
|
|
115
|
-
return plugin;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
console.warn('[Vue] Load plugin failed:', pluginPath);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
|
|
123
|
-
}
|
|
124
|
-
return [];
|
|
125
|
-
});
|
|
126
|
-
break;
|
|
127
|
-
default:
|
|
128
|
-
// @ts-expect-error
|
|
129
|
-
this.options[key] = options[key];
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (options.target === undefined) {
|
|
134
|
-
this.target ??= findVueVersion(rootDir);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
build(defaults) {
|
|
138
|
-
defaults ??= getDefaultCompilerOptions(this.target, this.options.lib, this.options.strictTemplates);
|
|
139
|
-
const resolvedOptions = {
|
|
140
|
-
...defaults,
|
|
141
|
-
...this.options,
|
|
142
|
-
plugins: this.plugins,
|
|
143
|
-
macros: {
|
|
144
|
-
...defaults.macros,
|
|
145
|
-
...this.options.macros,
|
|
146
|
-
},
|
|
147
|
-
composables: {
|
|
148
|
-
...defaults.composables,
|
|
149
|
-
...this.options.composables,
|
|
150
|
-
},
|
|
151
|
-
fallthroughComponentNames: [
|
|
152
|
-
...defaults.fallthroughComponentNames,
|
|
153
|
-
...this.options.fallthroughComponentNames ?? [],
|
|
154
|
-
].map(shared_2.hyphenateTag),
|
|
155
|
-
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
156
|
-
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
157
|
-
experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
|
|
158
|
-
};
|
|
159
|
-
if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
|
|
160
|
-
if (this.fileExists && this.globalTypesPath === undefined) {
|
|
161
|
-
const fileDirToGlobalTypesPath = new Map();
|
|
162
|
-
resolvedOptions.globalTypesPath = fileName => {
|
|
163
|
-
const fileDir = path_browserify_1.posix.dirname(fileName);
|
|
164
|
-
if (fileDirToGlobalTypesPath.has(fileDir)) {
|
|
165
|
-
return fileDirToGlobalTypesPath.get(fileDir);
|
|
166
|
-
}
|
|
167
|
-
const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
|
|
168
|
-
const result = root
|
|
169
|
-
? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
|
|
170
|
-
: undefined;
|
|
171
|
-
fileDirToGlobalTypesPath.set(fileDir, result);
|
|
172
|
-
return result;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
resolvedOptions.globalTypesPath = () => this.globalTypesPath;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return resolvedOptions;
|
|
180
|
-
}
|
|
181
|
-
findNodeModulesRoot(dir, lib) {
|
|
182
|
-
while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', lib, 'package.json'))) {
|
|
183
|
-
const parentDir = path_browserify_1.posix.dirname(dir);
|
|
184
|
-
if (dir === parentDir) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
dir = parentDir;
|
|
188
|
-
}
|
|
189
|
-
return dir;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
exports.CompilerOptionsResolver = CompilerOptionsResolver;
|
|
193
|
-
function findVueVersion(rootDir) {
|
|
194
|
-
const resolvedPath = resolvePath('vue/package.json', rootDir);
|
|
195
|
-
if (resolvedPath) {
|
|
196
|
-
const vuePackageJson = require(resolvedPath);
|
|
197
|
-
const versionNumbers = vuePackageJson.version.split('.');
|
|
198
|
-
return Number(versionNumbers[0] + '.' + versionNumbers[1]);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// console.warn('Load vue/package.json failed from', folder);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function resolvePath(scriptPath, root) {
|
|
205
|
-
try {
|
|
206
|
-
if (require?.resolve) {
|
|
207
|
-
return require.resolve(scriptPath, { paths: [root] });
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
// console.warn(error);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = false) {
|
|
218
|
-
return {
|
|
219
|
-
target,
|
|
220
|
-
lib,
|
|
221
|
-
globalTypesPath: shared_1.NOOP,
|
|
222
|
-
extensions: ['.vue'],
|
|
223
|
-
vitePressExtensions: [],
|
|
224
|
-
petiteVueExtensions: [],
|
|
225
|
-
jsxSlots: false,
|
|
226
|
-
strictVModel: strictTemplates,
|
|
227
|
-
strictCssModules: false,
|
|
228
|
-
checkUnknownProps: strictTemplates,
|
|
229
|
-
checkUnknownEvents: strictTemplates,
|
|
230
|
-
checkUnknownDirectives: strictTemplates,
|
|
231
|
-
checkUnknownComponents: strictTemplates,
|
|
232
|
-
inferComponentDollarEl: false,
|
|
233
|
-
inferComponentDollarRefs: false,
|
|
234
|
-
inferTemplateDollarAttrs: false,
|
|
235
|
-
inferTemplateDollarEl: false,
|
|
236
|
-
inferTemplateDollarRefs: false,
|
|
237
|
-
inferTemplateDollarSlots: false,
|
|
238
|
-
skipTemplateCodegen: false,
|
|
239
|
-
fallthroughAttributes: false,
|
|
240
|
-
resolveStyleImports: false,
|
|
241
|
-
resolveStyleClassNames: 'scoped',
|
|
242
|
-
fallthroughComponentNames: [
|
|
243
|
-
'Transition',
|
|
244
|
-
'KeepAlive',
|
|
245
|
-
'Teleport',
|
|
246
|
-
'Suspense',
|
|
247
|
-
],
|
|
248
|
-
dataAttributes: [],
|
|
249
|
-
htmlAttributes: ['aria-*'],
|
|
250
|
-
optionsWrapper: target >= 2.7
|
|
251
|
-
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
252
|
-
: [`(await import('${lib}')).default.extend(`, `)`],
|
|
253
|
-
macros: {
|
|
254
|
-
defineProps: ['defineProps'],
|
|
255
|
-
defineSlots: ['defineSlots'],
|
|
256
|
-
defineEmits: ['defineEmits'],
|
|
257
|
-
defineExpose: ['defineExpose'],
|
|
258
|
-
defineModel: ['defineModel'],
|
|
259
|
-
defineOptions: ['defineOptions'],
|
|
260
|
-
withDefaults: ['withDefaults'],
|
|
261
|
-
},
|
|
262
|
-
composables: {
|
|
263
|
-
useAttrs: ['useAttrs'],
|
|
264
|
-
useCssModule: ['useCssModule'],
|
|
265
|
-
useSlots: ['useSlots'],
|
|
266
|
-
useTemplateRef: ['useTemplateRef', 'templateRef'],
|
|
267
|
-
},
|
|
268
|
-
plugins: [],
|
|
269
|
-
experimentalModelPropName: {
|
|
270
|
-
'': {
|
|
271
|
-
input: true,
|
|
272
|
-
},
|
|
273
|
-
value: {
|
|
274
|
-
input: { type: 'text' },
|
|
275
|
-
textarea: true,
|
|
276
|
-
select: true,
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function writeGlobalTypes(vueOptions, writeFile) {
|
|
282
|
-
const originalFn = vueOptions.globalTypesPath;
|
|
283
|
-
if (!originalFn) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
const writed = new Set();
|
|
287
|
-
vueOptions.globalTypesPath = (fileName) => {
|
|
288
|
-
const result = originalFn(fileName);
|
|
289
|
-
if (result && !writed.has(result)) {
|
|
290
|
-
writed.add(result);
|
|
291
|
-
writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
|
|
292
|
-
}
|
|
293
|
-
return result;
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
//# sourceMappingURL=ts.js.map
|