@vue/language-core 1.9.0-alpha.3 → 2.0.0

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.
Files changed (63) hide show
  1. package/package.json +6 -9
  2. package/out/generators/script.d.ts +0 -15
  3. package/out/generators/script.js +0 -887
  4. package/out/generators/template.d.ts +0 -21
  5. package/out/generators/template.js +0 -1506
  6. package/out/index.d.ts +0 -16
  7. package/out/index.js +0 -33
  8. package/out/languageModule.d.ts +0 -10
  9. package/out/languageModule.js +0 -99
  10. package/out/parsers/scriptRanges.d.ts +0 -16
  11. package/out/parsers/scriptRanges.js +0 -58
  12. package/out/parsers/scriptSetupRanges.d.ts +0 -49
  13. package/out/parsers/scriptSetupRanges.js +0 -291
  14. package/out/plugins/file-html.d.ts +0 -4
  15. package/out/plugins/file-html.js +0 -81
  16. package/out/plugins/file-md.d.ts +0 -4
  17. package/out/plugins/file-md.js +0 -71
  18. package/out/plugins/file-vue.d.ts +0 -4
  19. package/out/plugins/file-vue.js +0 -40
  20. package/out/plugins/vue-sfc-customblocks.d.ts +0 -4
  21. package/out/plugins/vue-sfc-customblocks.js +0 -33
  22. package/out/plugins/vue-sfc-scripts.d.ts +0 -4
  23. package/out/plugins/vue-sfc-scripts.js +0 -42
  24. package/out/plugins/vue-sfc-styles.d.ts +0 -4
  25. package/out/plugins/vue-sfc-styles.js +0 -33
  26. package/out/plugins/vue-sfc-template.d.ts +0 -4
  27. package/out/plugins/vue-sfc-template.js +0 -29
  28. package/out/plugins/vue-template-html.d.ts +0 -4
  29. package/out/plugins/vue-template-html.js +0 -169
  30. package/out/plugins/vue-tsx.d.ts +0 -73
  31. package/out/plugins/vue-tsx.js +0 -159
  32. package/out/plugins.d.ts +0 -25
  33. package/out/plugins.js +0 -58
  34. package/out/types.d.ts +0 -125
  35. package/out/types.js +0 -3
  36. package/out/utils/globalTypes.d.ts +0 -4
  37. package/out/utils/globalTypes.js +0 -135
  38. package/out/utils/parseCssClassNames.d.ts +0 -5
  39. package/out/utils/parseCssClassNames.js +0 -19
  40. package/out/utils/parseCssVars.d.ts +0 -6
  41. package/out/utils/parseCssVars.js +0 -28
  42. package/out/utils/parseSfc.d.ts +0 -3
  43. package/out/utils/parseSfc.js +0 -135
  44. package/out/utils/shared.d.ts +0 -4
  45. package/out/utils/shared.js +0 -20
  46. package/out/utils/transform.d.ts +0 -9
  47. package/out/utils/transform.js +0 -195
  48. package/out/utils/ts.d.ts +0 -9
  49. package/out/utils/ts.js +0 -237
  50. package/out/utils/vue2TemplateCompiler.d.ts +0 -3
  51. package/out/utils/vue2TemplateCompiler.js +0 -86
  52. package/out/virtualFile/computedFiles.d.ts +0 -4
  53. package/out/virtualFile/computedFiles.js +0 -204
  54. package/out/virtualFile/computedMappings.d.ts +0 -6
  55. package/out/virtualFile/computedMappings.js +0 -39
  56. package/out/virtualFile/computedSfc.d.ts +0 -5
  57. package/out/virtualFile/computedSfc.js +0 -197
  58. package/out/virtualFile/computedVueSfc.d.ts +0 -5
  59. package/out/virtualFile/computedVueSfc.js +0 -41
  60. package/out/virtualFile/embeddedFile.d.ts +0 -13
  61. package/out/virtualFile/embeddedFile.js +0 -16
  62. package/out/virtualFile/vueFile.d.ts +0 -28
  63. package/out/virtualFile/vueFile.js +0 -53
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = void 0;
4
- const compiler = require("@vue/compiler-dom");
5
- function parse(source) {
6
- const errors = [];
7
- const ast = compiler.parse(source, {
8
- // there are no components at SFC parsing level
9
- isNativeTag: () => true,
10
- // preserve all whitespaces
11
- isPreTag: () => true,
12
- getTextMode: ({ tag, props }, parent) => {
13
- if ((!parent && tag !== 'template')
14
- || (tag === 'template'
15
- && props.some(p => p.type === 6 /* compiler.NodeTypes.ATTRIBUTE */ &&
16
- p.name === 'lang' &&
17
- p.value &&
18
- p.value.content &&
19
- p.value.content !== 'html'))) {
20
- return 2 /* compiler.TextModes.RAWTEXT */;
21
- }
22
- else {
23
- return 0 /* compiler.TextModes.DATA */;
24
- }
25
- },
26
- onError: e => {
27
- errors.push(e);
28
- },
29
- comments: true,
30
- });
31
- const descriptor = {
32
- filename: 'anonymous.vue',
33
- source,
34
- template: null,
35
- script: null,
36
- scriptSetup: null,
37
- styles: [],
38
- customBlocks: [],
39
- cssVars: [],
40
- slotted: false,
41
- shouldForceReload: () => false,
42
- };
43
- ast.children.forEach(node => {
44
- if (node.type !== 1 /* compiler.NodeTypes.ELEMENT */) {
45
- return;
46
- }
47
- switch (node.tag) {
48
- case 'template':
49
- const templateBlock = (descriptor.template = createBlock(node, source));
50
- templateBlock.ast = node;
51
- break;
52
- case 'script':
53
- const scriptBlock = createBlock(node, source);
54
- const isSetup = !!scriptBlock.attrs.setup;
55
- if (isSetup && !descriptor.scriptSetup) {
56
- descriptor.scriptSetup = scriptBlock;
57
- break;
58
- }
59
- if (!isSetup && !descriptor.script) {
60
- descriptor.script = scriptBlock;
61
- break;
62
- }
63
- break;
64
- case 'style':
65
- const styleBlock = createBlock(node, source);
66
- descriptor.styles.push(styleBlock);
67
- break;
68
- default:
69
- descriptor.customBlocks.push(createBlock(node, source));
70
- break;
71
- }
72
- });
73
- return {
74
- descriptor,
75
- errors,
76
- };
77
- }
78
- exports.parse = parse;
79
- function createBlock(node, source) {
80
- const type = node.tag;
81
- let { start, end } = node.loc;
82
- let content = '';
83
- if (node.children.length) {
84
- start = node.children[0].loc.start;
85
- end = node.children[node.children.length - 1].loc.end;
86
- content = source.slice(start.offset, end.offset);
87
- }
88
- else {
89
- const offset = node.loc.source.indexOf(`</`);
90
- if (offset > -1) {
91
- start = {
92
- line: start.line,
93
- column: start.column + offset,
94
- offset: start.offset + offset
95
- };
96
- }
97
- end = Object.assign({}, start);
98
- }
99
- const loc = {
100
- source: content,
101
- start,
102
- end
103
- };
104
- const attrs = {};
105
- const block = {
106
- type,
107
- content,
108
- loc,
109
- attrs
110
- };
111
- node.props.forEach(p => {
112
- if (p.type === 6 /* compiler.NodeTypes.ATTRIBUTE */) {
113
- attrs[p.name] = p.value ? p.value.content || true : true;
114
- if (p.name === 'lang') {
115
- block.lang = p.value && p.value.content;
116
- }
117
- else if (p.name === 'src') {
118
- block.src = p.value && p.value.content;
119
- }
120
- else if (type === 'style') {
121
- if (p.name === 'scoped') {
122
- block.scoped = true;
123
- }
124
- else if (p.name === 'module') {
125
- block.module = attrs[p.name];
126
- }
127
- }
128
- else if (type === 'script' && p.name === 'setup') {
129
- block.setup = attrs.setup;
130
- }
131
- }
132
- });
133
- return block;
134
- }
135
- //# sourceMappingURL=parseSfc.js.map
@@ -1,4 +0,0 @@
1
- export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
2
- export { hyphenate as hyphenateTag } from '@vue/shared';
3
- export declare function hyphenateAttr(str: string): string;
4
- //# sourceMappingURL=shared.d.ts.map
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hyphenateAttr = exports.hyphenateTag = exports.getSlotsPropertyName = void 0;
4
- const shared_1 = require("@vue/shared");
5
- function getSlotsPropertyName(vueVersion) {
6
- return vueVersion < 3 ? '$scopedSlots' : '$slots';
7
- }
8
- exports.getSlotsPropertyName = getSlotsPropertyName;
9
- var shared_2 = require("@vue/shared");
10
- Object.defineProperty(exports, "hyphenateTag", { enumerable: true, get: function () { return shared_2.hyphenate; } });
11
- function hyphenateAttr(str) {
12
- let hyphencase = (0, shared_1.hyphenate)(str);
13
- // fix https://github.com/vuejs/core/issues/8811
14
- if (str.length && str[0] !== str[0].toLowerCase()) {
15
- hyphencase = '-' + hyphencase;
16
- }
17
- return hyphencase;
18
- }
19
- exports.hyphenateAttr = hyphenateAttr;
20
- //# sourceMappingURL=shared.js.map
@@ -1,9 +0,0 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import { VueCompilerOptions } from '../types';
3
- export declare function walkInterpolationFragment(ts: typeof import('typescript/lib/tsserverlibrary'), code: string, ast: ts.SourceFile, cb: (fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean) => void, localVars: Map<string, number>, identifiers: Set<string>, vueOptions: VueCompilerOptions): {
4
- text: string;
5
- isShorthand: boolean;
6
- offset: number;
7
- }[];
8
- export declare function collectVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void;
9
- //# sourceMappingURL=transform.d.ts.map
@@ -1,195 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectVars = exports.walkInterpolationFragment = void 0;
4
- const shared_1 = require("@vue/shared");
5
- function walkInterpolationFragment(ts, code, ast, cb, localVars, identifiers, vueOptions) {
6
- let ctxVars = [];
7
- const varCb = (id, isShorthand) => {
8
- if (localVars.get(id.text) ||
9
- // https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
10
- (0, shared_1.isGloballyWhitelisted)(id.text) ||
11
- id.text === 'require' ||
12
- id.text.startsWith('__VLS_')) {
13
- // localVarOffsets.push(localVar.getStart(ast));
14
- }
15
- else {
16
- ctxVars.push({
17
- text: id.text,
18
- isShorthand: isShorthand,
19
- offset: id.getStart(ast),
20
- });
21
- identifiers.add(id.text);
22
- }
23
- };
24
- ast.forEachChild(node => walkIdentifiers(ts, node, varCb, localVars));
25
- ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
26
- if (ctxVars.length) {
27
- if (ctxVars[0].isShorthand) {
28
- cb(code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0);
29
- cb(': ', undefined);
30
- }
31
- else {
32
- cb(code.substring(0, ctxVars[0].offset), 0);
33
- }
34
- for (let i = 0; i < ctxVars.length - 1; i++) {
35
- // fix https://github.com/vuejs/language-tools/issues/1205
36
- // fix https://github.com/vuejs/language-tools/issues/1264
37
- cb('', ctxVars[i + 1].offset, true);
38
- if (vueOptions.experimentalUseElementAccessInTemplate) {
39
- const varStart = ctxVars[i].offset;
40
- const varEnd = ctxVars[i].offset + ctxVars[i].text.length;
41
- cb('__VLS_ctx[', undefined);
42
- cb('', varStart, true);
43
- cb("'", undefined);
44
- cb(code.substring(varStart, varEnd), varStart);
45
- cb("'", undefined);
46
- cb('', varEnd, true);
47
- cb(']', undefined);
48
- if (ctxVars[i + 1].isShorthand) {
49
- cb(code.substring(varEnd, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), varEnd);
50
- cb(': ', undefined);
51
- }
52
- else {
53
- cb(code.substring(varEnd, ctxVars[i + 1].offset), varEnd);
54
- }
55
- }
56
- else {
57
- cb('__VLS_ctx.', undefined);
58
- if (ctxVars[i + 1].isShorthand) {
59
- cb(code.substring(ctxVars[i].offset, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), ctxVars[i].offset);
60
- cb(': ', undefined);
61
- }
62
- else {
63
- cb(code.substring(ctxVars[i].offset, ctxVars[i + 1].offset), ctxVars[i].offset);
64
- }
65
- }
66
- }
67
- if (vueOptions.experimentalUseElementAccessInTemplate) {
68
- const varStart = ctxVars[ctxVars.length - 1].offset;
69
- const varEnd = ctxVars[ctxVars.length - 1].offset + ctxVars[ctxVars.length - 1].text.length;
70
- cb('__VLS_ctx[', undefined);
71
- cb('', varStart, true);
72
- cb("'", undefined);
73
- cb(code.substring(varStart, varEnd), varStart);
74
- cb("'", undefined);
75
- cb('', varEnd, true);
76
- cb(']', undefined);
77
- cb(code.substring(varEnd), varEnd);
78
- }
79
- else {
80
- cb('', ctxVars[ctxVars.length - 1].offset, true);
81
- cb('__VLS_ctx.', undefined);
82
- cb(code.substring(ctxVars[ctxVars.length - 1].offset), ctxVars[ctxVars.length - 1].offset);
83
- }
84
- }
85
- else {
86
- cb(code, 0);
87
- }
88
- return ctxVars;
89
- }
90
- exports.walkInterpolationFragment = walkInterpolationFragment;
91
- function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true) {
92
- if (ts.isIdentifier(node)) {
93
- cb(node, false);
94
- }
95
- else if (ts.isShorthandPropertyAssignment(node)) {
96
- cb(node.name, true);
97
- }
98
- else if (ts.isPropertyAccessExpression(node)) {
99
- walkIdentifiers(ts, node.expression, cb, localVars, blockVars, false);
100
- }
101
- else if (ts.isVariableDeclaration(node)) {
102
- collectVars(ts, node.name, blockVars);
103
- for (const varName of blockVars) {
104
- localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
105
- }
106
- if (node.initializer)
107
- walkIdentifiers(ts, node.initializer, cb, localVars, blockVars, false);
108
- }
109
- else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
110
- const functionArgs = [];
111
- for (const param of node.parameters) {
112
- collectVars(ts, param.name, functionArgs);
113
- if (param.type) {
114
- walkIdentifiers(ts, param.type, cb, localVars, blockVars, false);
115
- }
116
- }
117
- for (const varName of functionArgs)
118
- localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
119
- walkIdentifiers(ts, node.body, cb, localVars, blockVars, false);
120
- for (const varName of functionArgs)
121
- localVars.set(varName, localVars.get(varName) - 1);
122
- }
123
- else if (ts.isObjectLiteralExpression(node)) {
124
- for (const prop of node.properties) {
125
- if (ts.isPropertyAssignment(prop)) {
126
- // fix https://github.com/vuejs/language-tools/issues/1176
127
- if (ts.isComputedPropertyName(prop.name)) {
128
- walkIdentifiers(ts, prop.name.expression, cb, localVars, blockVars, false);
129
- }
130
- walkIdentifiers(ts, prop.initializer, cb, localVars, blockVars, false);
131
- }
132
- // fix https://github.com/vuejs/language-tools/issues/1156
133
- else if (ts.isShorthandPropertyAssignment(prop)) {
134
- walkIdentifiers(ts, prop, cb, localVars, blockVars, false);
135
- }
136
- // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
137
- else if (ts.isSpreadAssignment(prop)) {
138
- // TODO: cannot report "Spread types may only be created from object types.ts(2698)"
139
- walkIdentifiers(ts, prop.expression, cb, localVars, blockVars, false);
140
- }
141
- }
142
- }
143
- else if (ts.isTypeReferenceNode(node)) {
144
- // fix https://github.com/vuejs/language-tools/issues/1422
145
- node.forEachChild(node => walkIdentifiersInTypeReference(ts, node, cb));
146
- }
147
- else {
148
- const _blockVars = blockVars;
149
- if (ts.isBlock(node)) {
150
- blockVars = [];
151
- }
152
- node.forEachChild(node => walkIdentifiers(ts, node, cb, localVars, blockVars, false));
153
- if (ts.isBlock(node)) {
154
- for (const varName of blockVars) {
155
- localVars.set(varName, localVars.get(varName) - 1);
156
- }
157
- }
158
- blockVars = _blockVars;
159
- }
160
- if (isRoot) {
161
- for (const varName of blockVars) {
162
- localVars.set(varName, localVars.get(varName) - 1);
163
- }
164
- }
165
- }
166
- function walkIdentifiersInTypeReference(ts, node, cb) {
167
- if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
168
- cb(node.exprName, false);
169
- }
170
- else {
171
- node.forEachChild(node => walkIdentifiersInTypeReference(ts, node, cb));
172
- }
173
- }
174
- function collectVars(ts, node, result) {
175
- if (ts.isIdentifier(node)) {
176
- result.push(node.text);
177
- }
178
- else if (ts.isObjectBindingPattern(node)) {
179
- for (const el of node.elements) {
180
- collectVars(ts, el.name, result);
181
- }
182
- }
183
- else if (ts.isArrayBindingPattern(node)) {
184
- for (const el of node.elements) {
185
- if (ts.isBindingElement(el)) {
186
- collectVars(ts, el.name, result);
187
- }
188
- }
189
- }
190
- else {
191
- node.forEachChild(node => collectVars(ts, node, result));
192
- }
193
- }
194
- exports.collectVars = collectVars;
195
- //# sourceMappingURL=transform.js.map
package/out/utils/ts.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import type { VueCompilerOptions } from '../types';
3
- export type ParsedCommandLine = ts.ParsedCommandLine & {
4
- vueOptions: Partial<VueCompilerOptions>;
5
- };
6
- export declare function createParsedCommandLineByJson(ts: typeof import('typescript/lib/tsserverlibrary'), parseConfigHost: ts.ParseConfigHost, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
7
- export declare function createParsedCommandLine(ts: typeof import('typescript/lib/tsserverlibrary'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
8
- export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
9
- //# sourceMappingURL=ts.d.ts.map
package/out/utils/ts.js DELETED
@@ -1,237 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVueCompilerOptions = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
4
- const path = require("path-browserify");
5
- function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
6
- const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
7
- ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
8
- let vueOptions = {};
9
- for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
10
- try {
11
- vueOptions = {
12
- ...vueOptions,
13
- ...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
14
- };
15
- }
16
- catch (err) { }
17
- }
18
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (vueOptions.extensions ?? ['.vue']).map(extension => ({
19
- extension: extension.slice(1),
20
- isMixedContent: true,
21
- scriptKind: ts.ScriptKind.Deferred,
22
- })));
23
- // fix https://github.com/vuejs/language-tools/issues/1786
24
- // https://github.com/microsoft/TypeScript/issues/30457
25
- // patching ts server broke with outDir + rootDir + composite/incremental
26
- parsed.options.outDir = undefined;
27
- return {
28
- ...parsed,
29
- vueOptions,
30
- };
31
- }
32
- exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
33
- function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
34
- try {
35
- const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
36
- const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
37
- ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath);
38
- let vueOptions = {};
39
- for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
40
- try {
41
- vueOptions = {
42
- ...vueOptions,
43
- ...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
44
- };
45
- }
46
- catch (err) { }
47
- }
48
- const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, (vueOptions.extensions ?? ['.vue']).map(extension => ({
49
- extension: extension.slice(1),
50
- isMixedContent: true,
51
- scriptKind: ts.ScriptKind.Deferred,
52
- })));
53
- // fix https://github.com/vuejs/language-tools/issues/1786
54
- // https://github.com/microsoft/TypeScript/issues/30457
55
- // patching ts server broke with outDir + rootDir + composite/incremental
56
- parsed.options.outDir = undefined;
57
- return {
58
- ...parsed,
59
- vueOptions,
60
- };
61
- }
62
- catch (err) {
63
- // console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
64
- return {
65
- fileNames: [],
66
- options: {},
67
- vueOptions: resolveVueCompilerOptions({}),
68
- errors: [],
69
- };
70
- }
71
- }
72
- exports.createParsedCommandLine = createParsedCommandLine;
73
- function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
74
- const extendConfigPaths = [];
75
- const host = new Proxy(parseConfigHost, {
76
- get(target, key) {
77
- if (key === 'readFile') {
78
- return (fileName) => {
79
- if (!fileName.endsWith('/package.json') && !extendConfigPaths.includes(fileName)) {
80
- extendConfigPaths.push(fileName);
81
- }
82
- return target.readFile(fileName);
83
- };
84
- }
85
- return target[key];
86
- }
87
- });
88
- return {
89
- host,
90
- extendConfigPaths,
91
- };
92
- }
93
- function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
94
- const folder = path.dirname(tsConfigSourceFile.fileName);
95
- const obj = ts.convertToObject(tsConfigSourceFile, []);
96
- const rawOptions = obj?.vueCompilerOptions ?? {};
97
- const result = {
98
- ...rawOptions,
99
- };
100
- const target = rawOptions.target ?? 'auto';
101
- if (target === 'auto') {
102
- const resolvedPath = resolvePath('vue/package.json');
103
- if (resolvedPath) {
104
- const vuePackageJson = require(resolvedPath);
105
- const versionNumbers = vuePackageJson.version.split('.');
106
- result.target = Number(versionNumbers[0] + '.' + versionNumbers[1]);
107
- }
108
- else {
109
- // console.warn('Load vue/package.json failed from', folder);
110
- }
111
- }
112
- else {
113
- result.target = target;
114
- }
115
- if (rawOptions.plugins) {
116
- const plugins = rawOptions.plugins
117
- .map((pluginPath) => {
118
- try {
119
- const resolvedPath = resolvePath(pluginPath);
120
- if (resolvedPath) {
121
- return require(resolvedPath);
122
- }
123
- else {
124
- console.warn('Load plugin failed:', pluginPath);
125
- }
126
- }
127
- catch (error) {
128
- console.warn('Load plugin failed:', pluginPath, error);
129
- }
130
- return [];
131
- })
132
- .flat(Infinity);
133
- result.plugins = plugins;
134
- }
135
- if (rawOptions.hooks) {
136
- result.hooks = rawOptions.hooks
137
- .map(resolvePath)
138
- .filter((hook) => !!hook);
139
- }
140
- if (rawOptions.experimentalAdditionalLanguageModules) {
141
- result.experimentalAdditionalLanguageModules = rawOptions.experimentalAdditionalLanguageModules
142
- .map(resolvePath)
143
- .filter((module) => !!module);
144
- }
145
- return result;
146
- function resolvePath(scriptPath) {
147
- try {
148
- if (require?.resolve) {
149
- return require.resolve(scriptPath, { paths: [folder] });
150
- }
151
- else {
152
- // console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
153
- }
154
- }
155
- catch (error) {
156
- // console.warn(error);
157
- }
158
- }
159
- }
160
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
161
- const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
162
- 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
163
- 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
164
- 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
165
- 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
166
- 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
167
- 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
168
- 'option,output,progress,select,textarea,details,dialog,menu,' +
169
- 'summary,template,blockquote,iframe,tfoot';
170
- // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
171
- const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
172
- 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
173
- 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
174
- 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
175
- 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
176
- 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
177
- 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
178
- 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
179
- 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
180
- 'text,textPath,title,tspan,unknown,use,view';
181
- function resolveVueCompilerOptions(vueOptions) {
182
- const target = vueOptions.target ?? 3.3;
183
- const lib = vueOptions.lib || (target < 2.7 ? '@vue/runtime-dom' : 'vue');
184
- return {
185
- ...vueOptions,
186
- target,
187
- extensions: vueOptions.extensions ?? ['.vue'],
188
- lib,
189
- jsxSlots: vueOptions.jsxSlots ?? false,
190
- strictTemplates: vueOptions.strictTemplates ?? false,
191
- skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
192
- nativeTags: vueOptions.nativeTags ?? [...new Set([
193
- ...HTML_TAGS.split(','),
194
- ...SVG_TAGS.split(','),
195
- // fix https://github.com/johnsoncodehk/volar/issues/1340
196
- 'hgroup',
197
- 'slot',
198
- 'component',
199
- ])],
200
- dataAttributes: vueOptions.dataAttributes ?? [],
201
- htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
202
- optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
203
- ? [`(await import('${lib}')).defineComponent(`, `)`]
204
- : [`(await import('vue')).default.extend(`, `)`]),
205
- macros: {
206
- defineProps: ['defineProps'],
207
- defineSlots: ['defineSlots'],
208
- defineEmits: ['defineEmits'],
209
- defineExpose: ['defineExpose'],
210
- defineModel: ['defineModel'],
211
- defineOptions: ['defineOptions'],
212
- withDefaults: ['withDefaults'],
213
- ...vueOptions.macros,
214
- },
215
- plugins: vueOptions.plugins ?? [],
216
- hooks: vueOptions.hooks ?? [],
217
- // experimental
218
- experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false,
219
- experimentalAdditionalLanguageModules: vueOptions.experimentalAdditionalLanguageModules ?? [],
220
- experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
221
- // https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
222
- // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
223
- experimentalModelPropName: vueOptions.experimentalModelPropName ?? {
224
- '': {
225
- input: true
226
- },
227
- value: {
228
- input: { type: 'text' },
229
- textarea: true,
230
- select: true
231
- }
232
- },
233
- experimentalUseElementAccessInTemplate: vueOptions.experimentalUseElementAccessInTemplate ?? false,
234
- };
235
- }
236
- exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
237
- //# sourceMappingURL=ts.js.map
@@ -1,3 +0,0 @@
1
- import * as CompilerDOM from '@vue/compiler-dom';
2
- export declare function compile(template: string, options?: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult;
3
- //# sourceMappingURL=vue2TemplateCompiler.d.ts.map