@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
package/out/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- export * from './generators/template';
2
- export * from './languageModule';
3
- export * from './parsers/scriptSetupRanges';
4
- export * from './plugins';
5
- export * from './virtualFile/vueFile';
6
- export * from './types';
7
- export * from './utils/ts';
8
- export * from './utils/parseSfc';
9
- export * as scriptRanges from './parsers/scriptRanges';
10
- export * as sharedTypes from './utils/globalTypes';
11
- export * from './utils/shared';
12
- export { tsCodegen } from './plugins/vue-tsx';
13
- export * from '@volar/language-core';
14
- export * from '@volar/source-map';
15
- export type * as CompilerDOM from '@vue/compiler-dom';
16
- //# sourceMappingURL=index.d.ts.map
package/out/index.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.tsCodegen = exports.sharedTypes = exports.scriptRanges = void 0;
18
- __exportStar(require("./generators/template"), exports);
19
- __exportStar(require("./languageModule"), exports);
20
- __exportStar(require("./parsers/scriptSetupRanges"), exports);
21
- __exportStar(require("./plugins"), exports);
22
- __exportStar(require("./virtualFile/vueFile"), exports);
23
- __exportStar(require("./types"), exports);
24
- __exportStar(require("./utils/ts"), exports);
25
- __exportStar(require("./utils/parseSfc"), exports);
26
- exports.scriptRanges = require("./parsers/scriptRanges");
27
- exports.sharedTypes = require("./utils/globalTypes");
28
- __exportStar(require("./utils/shared"), exports);
29
- var vue_tsx_1 = require("./plugins/vue-tsx");
30
- Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
31
- __exportStar(require("@volar/language-core"), exports);
32
- __exportStar(require("@volar/source-map"), exports);
33
- //# sourceMappingURL=index.js.map
@@ -1,10 +0,0 @@
1
- import type { Language } from '@volar/language-core';
2
- import { VueFile } from './virtualFile/vueFile';
3
- import { VueCompilerOptions } from './types';
4
- import type * as ts from 'typescript/lib/tsserverlibrary';
5
- export declare function createVueLanguage(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Language<VueFile>;
6
- /**
7
- * @deprecated planed to remove in 2.0, please use createVueLanguage instead of
8
- */
9
- export declare function createLanguages(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions?: ts.CompilerOptions, vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Language[];
10
- //# sourceMappingURL=languageModule.d.ts.map
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLanguages = exports.createVueLanguage = void 0;
4
- const path = require("path-browserify");
5
- const plugins_1 = require("./plugins");
6
- const vueFile_1 = require("./virtualFile/vueFile");
7
- const sharedTypes = require("./utils/globalTypes");
8
- const ts_1 = require("./utils/ts");
9
- const fileRegistries = [];
10
- function getVueFileRegistry(key, plugins) {
11
- let fileRegistry = fileRegistries.find(r => r.key === key
12
- && r.plugins.length === plugins.length
13
- && r.plugins.every(plugin => plugins.includes(plugin)))?.files;
14
- if (!fileRegistry) {
15
- fileRegistry = new Map();
16
- fileRegistries.push({
17
- key: key,
18
- plugins: plugins,
19
- files: fileRegistry,
20
- });
21
- }
22
- return fileRegistry;
23
- }
24
- function createVueLanguage(ts, compilerOptions = {}, _vueCompilerOptions = {}, codegenStack = false) {
25
- const vueCompilerOptions = (0, ts_1.resolveVueCompilerOptions)(_vueCompilerOptions);
26
- const plugins = (0, plugins_1.getDefaultVueLanguagePlugins)(ts, compilerOptions, vueCompilerOptions, codegenStack);
27
- const keys = [
28
- ...Object.keys(vueCompilerOptions)
29
- .sort()
30
- .filter(key => key !== 'plugins')
31
- .map(key => [key, vueCompilerOptions[key]]),
32
- [...new Set(plugins.map(plugin => plugin.requiredCompilerOptions ?? []).flat())]
33
- .sort()
34
- .map(key => [key, compilerOptions[key]]),
35
- ];
36
- const fileRegistry = getVueFileRegistry(JSON.stringify(keys), _vueCompilerOptions.plugins ?? []);
37
- const allowLanguageIds = new Set(['vue']);
38
- if (vueCompilerOptions.extensions.includes('.md')) {
39
- allowLanguageIds.add('markdown');
40
- }
41
- if (vueCompilerOptions.extensions.includes('.html')) {
42
- allowLanguageIds.add('html');
43
- }
44
- return {
45
- createVirtualFile(fileName, snapshot, languageId) {
46
- if ((languageId && allowLanguageIds.has(languageId))
47
- || (!languageId && vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext)))) {
48
- if (fileRegistry.has(fileName)) {
49
- const reusedVueFile = fileRegistry.get(fileName);
50
- reusedVueFile.update(snapshot);
51
- return reusedVueFile;
52
- }
53
- const vueFile = new vueFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
54
- fileRegistry.set(fileName, vueFile);
55
- return vueFile;
56
- }
57
- },
58
- updateVirtualFile(sourceFile, snapshot) {
59
- sourceFile.update(snapshot);
60
- },
61
- resolveHost(host) {
62
- const sharedTypesSnapshot = ts.ScriptSnapshot.fromString(sharedTypes.getTypesCode(vueCompilerOptions));
63
- const sharedTypesFileName = path.join(host.rootPath, sharedTypes.baseName);
64
- return {
65
- ...host,
66
- resolveModuleName(moduleName, impliedNodeFormat) {
67
- if (impliedNodeFormat === ts.ModuleKind.ESNext && vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
68
- return `${moduleName}.js`;
69
- }
70
- return host.resolveModuleName?.(moduleName, impliedNodeFormat) ?? moduleName;
71
- },
72
- getScriptFileNames() {
73
- return [
74
- sharedTypesFileName,
75
- ...host.getScriptFileNames(),
76
- ];
77
- },
78
- getScriptSnapshot(fileName) {
79
- if (fileName === sharedTypesFileName) {
80
- return sharedTypesSnapshot;
81
- }
82
- return host.getScriptSnapshot(fileName);
83
- },
84
- };
85
- },
86
- };
87
- }
88
- exports.createVueLanguage = createVueLanguage;
89
- /**
90
- * @deprecated planed to remove in 2.0, please use createVueLanguage instead of
91
- */
92
- function createLanguages(ts, compilerOptions = {}, vueCompilerOptions = {}, codegenStack = false) {
93
- return [
94
- createVueLanguage(ts, compilerOptions, vueCompilerOptions, codegenStack),
95
- ...vueCompilerOptions.experimentalAdditionalLanguageModules?.map(module => require(module)) ?? [],
96
- ];
97
- }
98
- exports.createLanguages = createLanguages;
99
- //# sourceMappingURL=languageModule.js.map
@@ -1,16 +0,0 @@
1
- import type { TextRange } from '../types';
2
- import type * as ts from 'typescript/lib/tsserverlibrary';
3
- export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
4
- }
5
- export declare function parseScriptRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean): {
6
- exportDefault: (TextRange & {
7
- expression: TextRange;
8
- args: TextRange;
9
- argsNode: ts.ObjectLiteralExpression | undefined;
10
- componentsOption: TextRange | undefined;
11
- componentsOptionNode: ts.ObjectLiteralExpression | undefined;
12
- nameOption: TextRange | undefined;
13
- }) | undefined;
14
- bindings: TextRange[];
15
- };
16
- //# sourceMappingURL=scriptRanges.d.ts.map
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseScriptRanges = void 0;
4
- const scriptSetupRanges_1 = require("./scriptSetupRanges");
5
- function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
6
- let exportDefault;
7
- const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
8
- ast.forEachChild(raw => {
9
- if (ts.isExportAssignment(raw)) {
10
- let node = raw;
11
- while (ts.isAsExpression(node.expression) || ts.isParenthesizedExpression(node.expression)) { // fix https://github.com/vuejs/language-tools/issues/1882
12
- node = node.expression;
13
- }
14
- let obj;
15
- if (ts.isObjectLiteralExpression(node.expression)) {
16
- obj = node.expression;
17
- }
18
- else if (ts.isCallExpression(node.expression) && node.expression.arguments.length) {
19
- const arg0 = node.expression.arguments[0];
20
- if (ts.isObjectLiteralExpression(arg0)) {
21
- obj = arg0;
22
- }
23
- }
24
- if (obj) {
25
- let componentsOptionNode;
26
- let nameOptionNode;
27
- obj.forEachChild(node => {
28
- if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
29
- if (node.name.escapedText === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
30
- componentsOptionNode = node.initializer;
31
- }
32
- if (node.name.escapedText === 'name') {
33
- nameOptionNode = node.initializer;
34
- }
35
- }
36
- });
37
- exportDefault = {
38
- ..._getStartEnd(raw),
39
- expression: _getStartEnd(node.expression),
40
- args: _getStartEnd(obj),
41
- argsNode: withNode ? obj : undefined,
42
- componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
43
- componentsOptionNode: withNode ? componentsOptionNode : undefined,
44
- nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
45
- };
46
- }
47
- }
48
- });
49
- return {
50
- exportDefault,
51
- bindings,
52
- };
53
- function _getStartEnd(node) {
54
- return (0, scriptSetupRanges_1.getStartEnd)(node, ast);
55
- }
56
- }
57
- exports.parseScriptRanges = parseScriptRanges;
58
- //# sourceMappingURL=scriptRanges.js.map
@@ -1,49 +0,0 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import type { VueCompilerOptions, TextRange } from '../types';
3
- export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
4
- }
5
- export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
6
- leadingCommentEndOffset: number;
7
- importSectionEndOffset: number;
8
- bindings: TextRange[];
9
- props: {
10
- name?: string | undefined;
11
- define?: (TextRange & {
12
- statement: TextRange;
13
- arg?: TextRange | undefined;
14
- typeArg?: TextRange | undefined;
15
- }) | undefined;
16
- withDefaults?: (TextRange & {
17
- arg?: TextRange | undefined;
18
- }) | undefined;
19
- };
20
- slots: {
21
- name?: string | undefined;
22
- define?: TextRange | undefined;
23
- };
24
- emits: {
25
- name?: string | undefined;
26
- define?: TextRange | undefined;
27
- };
28
- expose: {
29
- name?: string | undefined;
30
- define?: (TextRange & {
31
- arg?: TextRange | undefined;
32
- typeArg?: TextRange | undefined;
33
- }) | undefined;
34
- };
35
- defineProp: {
36
- name: TextRange | undefined;
37
- nameIsString: boolean;
38
- type: TextRange | undefined;
39
- defaultValue: TextRange | undefined;
40
- required: boolean;
41
- }[];
42
- };
43
- export declare function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlibrary'), sourceFile: ts.SourceFile): TextRange[];
44
- export declare function findBindingVars(ts: typeof import('typescript/lib/tsserverlibrary'), left: ts.BindingName, sourceFile: ts.SourceFile): TextRange[];
45
- export declare function getStartEnd(node: ts.Node, sourceFile: ts.SourceFile): {
46
- start: number;
47
- end: number;
48
- };
49
- //# sourceMappingURL=scriptSetupRanges.d.ts.map
@@ -1,291 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStartEnd = exports.findBindingVars = exports.parseBindingRanges = exports.parseScriptSetupRanges = void 0;
4
- function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
5
- let foundNonImportExportNode = false;
6
- let importSectionEndOffset = 0;
7
- const props = {};
8
- const slots = {};
9
- const emits = {};
10
- const expose = {};
11
- const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
12
- const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
13
- const defineProp = [];
14
- const bindings = parseBindingRanges(ts, ast);
15
- const text = ast.getFullText();
16
- const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
17
- ast.forEachChild(node => {
18
- const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
19
- if (!foundNonImportExportNode
20
- && !ts.isImportDeclaration(node)
21
- && !isTypeExport
22
- && !ts.isEmptyStatement(node)
23
- // fix https://github.com/vuejs/language-tools/issues/1223
24
- && !ts.isImportEqualsDeclaration(node)) {
25
- const commentRanges = ts.getLeadingCommentRanges(text, node.getFullStart());
26
- if (commentRanges?.length) {
27
- const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
28
- importSectionEndOffset = commentRange.pos;
29
- }
30
- else {
31
- importSectionEndOffset = node.getStart(ast);
32
- }
33
- foundNonImportExportNode = true;
34
- }
35
- });
36
- ast.forEachChild(child => visitNode(child, [ast]));
37
- return {
38
- leadingCommentEndOffset,
39
- importSectionEndOffset,
40
- bindings,
41
- props,
42
- slots,
43
- emits,
44
- expose,
45
- defineProp,
46
- };
47
- function _getStartEnd(node) {
48
- return getStartEnd(node, ast);
49
- }
50
- function visitNode(node, parents) {
51
- const parent = parents[parents.length - 1];
52
- if (ts.isCallExpression(node)
53
- && ts.isIdentifier(node.expression)) {
54
- const callText = node.expression.getText(ast);
55
- if (vueCompilerOptions.macros.defineModel.includes(callText)) {
56
- let name;
57
- let options;
58
- if (node.arguments.length >= 2) {
59
- name = _getStartEnd(node.arguments[0]);
60
- options = node.arguments[1];
61
- }
62
- else if (node.arguments.length >= 1) {
63
- if (ts.isStringLiteral(node.arguments[0])) {
64
- name = _getStartEnd(node.arguments[0]);
65
- }
66
- else {
67
- options = node.arguments[0];
68
- }
69
- }
70
- let required = false;
71
- if (options && ts.isObjectLiteralExpression(options)) {
72
- for (const property of options.properties) {
73
- if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.getText(ast) === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
74
- required = true;
75
- break;
76
- }
77
- }
78
- }
79
- defineProp.push({
80
- name,
81
- nameIsString: true,
82
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
83
- defaultValue: undefined,
84
- required,
85
- });
86
- }
87
- else if (callText === 'defineProp') {
88
- if (definePropProposalA) {
89
- let required = false;
90
- if (node.arguments.length >= 2) {
91
- const secondArg = node.arguments[1];
92
- if (ts.isObjectLiteralExpression(secondArg)) {
93
- for (const property of secondArg.properties) {
94
- if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.getText(ast) === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
95
- required = true;
96
- break;
97
- }
98
- }
99
- }
100
- }
101
- if (node.arguments.length >= 1) {
102
- defineProp.push({
103
- name: _getStartEnd(node.arguments[0]),
104
- nameIsString: true,
105
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
106
- defaultValue: undefined,
107
- required,
108
- });
109
- }
110
- else if (ts.isVariableDeclaration(parent)) {
111
- defineProp.push({
112
- name: _getStartEnd(parent.name),
113
- nameIsString: false,
114
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
115
- defaultValue: undefined,
116
- required,
117
- });
118
- }
119
- }
120
- else if (definePropProposalB && ts.isVariableDeclaration(parent)) {
121
- defineProp.push({
122
- name: _getStartEnd(parent.name),
123
- nameIsString: false,
124
- defaultValue: node.arguments.length >= 1 ? _getStartEnd(node.arguments[0]) : undefined,
125
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
126
- required: node.arguments.length >= 2 && node.arguments[1].kind === ts.SyntaxKind.TrueKeyword,
127
- });
128
- }
129
- }
130
- else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
131
- slots.define = _getStartEnd(node);
132
- if (ts.isVariableDeclaration(parent)) {
133
- slots.name = parent.name.getText(ast);
134
- }
135
- }
136
- else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
137
- emits.define = _getStartEnd(node);
138
- if (ts.isVariableDeclaration(parent)) {
139
- emits.name = parent.name.getText(ast);
140
- }
141
- }
142
- else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
143
- expose.define = _getStartEnd(node);
144
- if (node.arguments.length) {
145
- expose.define.arg = _getStartEnd(node.arguments[0]);
146
- }
147
- if (node.typeArguments?.length) {
148
- expose.define.typeArg = _getStartEnd(node.typeArguments[0]);
149
- }
150
- }
151
- else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
152
- let statementRange;
153
- for (let i = parents.length - 1; i >= 0; i--) {
154
- if (ts.isStatement(parents[i])) {
155
- const statement = parents[i];
156
- statement.forEachChild(child => {
157
- const range = _getStartEnd(child);
158
- statementRange ??= range;
159
- statementRange.end = range.end;
160
- });
161
- break;
162
- }
163
- }
164
- if (!statementRange) {
165
- statementRange = _getStartEnd(node);
166
- }
167
- props.define = {
168
- ..._getStartEnd(node),
169
- statement: statementRange,
170
- };
171
- if (ts.isVariableDeclaration(parent)) {
172
- props.name = parent.name.getText(ast);
173
- }
174
- if (node.arguments.length) {
175
- props.define.arg = _getStartEnd(node.arguments[0]);
176
- }
177
- if (node.typeArguments?.length) {
178
- props.define.typeArg = _getStartEnd(node.typeArguments[0]);
179
- }
180
- }
181
- else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
182
- props.withDefaults = _getStartEnd(node);
183
- if (node.arguments.length >= 2) {
184
- const arg = node.arguments[1];
185
- props.withDefaults.arg = _getStartEnd(arg);
186
- }
187
- if (ts.isVariableDeclaration(parent)) {
188
- props.name = parent.name.getText(ast);
189
- }
190
- }
191
- }
192
- node.forEachChild(child => {
193
- parents.push(node);
194
- visitNode(child, parents);
195
- parents.pop();
196
- });
197
- }
198
- }
199
- exports.parseScriptSetupRanges = parseScriptSetupRanges;
200
- function parseBindingRanges(ts, sourceFile) {
201
- const bindings = [];
202
- sourceFile.forEachChild(node => {
203
- if (ts.isVariableStatement(node)) {
204
- for (const node_2 of node.declarationList.declarations) {
205
- const vars = _findBindingVars(node_2.name);
206
- for (const _var of vars) {
207
- bindings.push(_var);
208
- }
209
- }
210
- }
211
- else if (ts.isFunctionDeclaration(node)) {
212
- if (node.name && ts.isIdentifier(node.name)) {
213
- bindings.push(_getStartEnd(node.name));
214
- }
215
- }
216
- else if (ts.isClassDeclaration(node)) {
217
- if (node.name) {
218
- bindings.push(_getStartEnd(node.name));
219
- }
220
- }
221
- else if (ts.isEnumDeclaration(node)) {
222
- bindings.push(_getStartEnd(node.name));
223
- }
224
- if (ts.isImportDeclaration(node)) {
225
- if (node.importClause && !node.importClause.isTypeOnly) {
226
- if (node.importClause.name) {
227
- bindings.push(_getStartEnd(node.importClause.name));
228
- }
229
- if (node.importClause.namedBindings) {
230
- if (ts.isNamedImports(node.importClause.namedBindings)) {
231
- for (const element of node.importClause.namedBindings.elements) {
232
- bindings.push(_getStartEnd(element.name));
233
- }
234
- }
235
- else if (ts.isNamespaceImport(node.importClause.namedBindings)) {
236
- bindings.push(_getStartEnd(node.importClause.namedBindings.name));
237
- }
238
- }
239
- }
240
- }
241
- });
242
- return bindings;
243
- function _getStartEnd(node) {
244
- return getStartEnd(node, sourceFile);
245
- }
246
- function _findBindingVars(left) {
247
- return findBindingVars(ts, left, sourceFile);
248
- }
249
- }
250
- exports.parseBindingRanges = parseBindingRanges;
251
- function findBindingVars(ts, left, sourceFile) {
252
- const vars = [];
253
- worker(left);
254
- return vars;
255
- function worker(_node) {
256
- if (ts.isIdentifier(_node)) {
257
- vars.push(getStartEnd(_node, sourceFile));
258
- }
259
- // { ? } = ...
260
- // [ ? ] = ...
261
- else if (ts.isObjectBindingPattern(_node) || ts.isArrayBindingPattern(_node)) {
262
- for (const property of _node.elements) {
263
- if (ts.isBindingElement(property)) {
264
- worker(property.name);
265
- }
266
- }
267
- }
268
- // { foo: ? } = ...
269
- else if (ts.isPropertyAssignment(_node)) {
270
- worker(_node.initializer);
271
- }
272
- // { foo } = ...
273
- else if (ts.isShorthandPropertyAssignment(_node)) {
274
- vars.push(getStartEnd(_node.name, sourceFile));
275
- }
276
- // { ...? } = ...
277
- // [ ...? ] = ...
278
- else if (ts.isSpreadAssignment(_node) || ts.isSpreadElement(_node)) {
279
- worker(_node.expression);
280
- }
281
- }
282
- }
283
- exports.findBindingVars = findBindingVars;
284
- function getStartEnd(node, sourceFile) {
285
- return {
286
- start: node.getStart(sourceFile),
287
- end: node.getEnd(),
288
- };
289
- }
290
- exports.getStartEnd = getStartEnd;
291
- //# sourceMappingURL=scriptSetupRanges.js.map
@@ -1,4 +0,0 @@
1
- import { VueLanguagePlugin } from '../types';
2
- declare const plugin: VueLanguagePlugin;
3
- export default plugin;
4
- //# sourceMappingURL=file-html.d.ts.map
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sfcBlockReg = /\<(script|style)\b([\s\S]*?)\>([\s\S]*?)\<\/\1\>/g;
4
- const langReg = /\blang\s*=\s*(['\"]?)(\S*)\b\1/;
5
- const plugin = () => {
6
- return {
7
- version: 1,
8
- parseSFC(fileName, content) {
9
- if (fileName.endsWith('.html')) {
10
- let sfc = {
11
- descriptor: {
12
- filename: fileName,
13
- source: content,
14
- template: null,
15
- script: null,
16
- scriptSetup: null,
17
- styles: [],
18
- customBlocks: [],
19
- cssVars: [],
20
- shouldForceReload: () => false,
21
- slotted: false,
22
- },
23
- errors: [],
24
- };
25
- let templateContent = content;
26
- for (const match of content.matchAll(sfcBlockReg)) {
27
- const matchText = match[0];
28
- const tag = match[1];
29
- const attrs = match[2];
30
- const lang = attrs.match(langReg)?.[2];
31
- const content = match[3];
32
- const contentStart = match.index + matchText.indexOf(content);
33
- if (tag === 'style') {
34
- sfc.descriptor.styles.push({
35
- attrs: {},
36
- content,
37
- loc: {
38
- start: { column: -1, line: -1, offset: contentStart },
39
- end: { column: -1, line: -1, offset: contentStart + content.length },
40
- source: content,
41
- },
42
- type: 'style',
43
- lang,
44
- });
45
- }
46
- // ignore `<script src="...">`
47
- else if (tag === 'script' && attrs.indexOf('src=') === -1) {
48
- let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
49
- sfc.descriptor[type] = {
50
- attrs: {},
51
- content,
52
- loc: {
53
- start: { column: -1, line: -1, offset: contentStart },
54
- end: { column: -1, line: -1, offset: contentStart + content.length },
55
- source: content,
56
- },
57
- type: 'script',
58
- lang,
59
- };
60
- }
61
- templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
62
- }
63
- sfc.descriptor.template = {
64
- attrs: {},
65
- content: templateContent,
66
- loc: {
67
- start: { column: -1, line: -1, offset: 0 },
68
- end: { column: -1, line: -1, offset: templateContent.length },
69
- source: templateContent,
70
- },
71
- type: 'template',
72
- ast: {},
73
- };
74
- return sfc;
75
- }
76
- ;
77
- }
78
- };
79
- };
80
- exports.default = plugin;
81
- //# sourceMappingURL=file-html.js.map
@@ -1,4 +0,0 @@
1
- import { VueLanguagePlugin } from '../types';
2
- declare const plugin: VueLanguagePlugin;
3
- export default plugin;
4
- //# sourceMappingURL=file-md.d.ts.map