@vue/language-core 3.1.4 → 3.1.6

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 (101) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +15 -20
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +10 -19
  28. package/lib/codegen/template/context.js +82 -94
  29. package/lib/codegen/template/element.js +174 -65
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.d.ts +1 -1
  32. package/lib/codegen/template/elementEvents.js +30 -35
  33. package/lib/codegen/template/elementProps.d.ts +3 -3
  34. package/lib/codegen/template/elementProps.js +64 -83
  35. package/lib/codegen/template/index.d.ts +11 -22
  36. package/lib/codegen/template/index.js +85 -80
  37. package/lib/codegen/template/interpolation.d.ts +3 -3
  38. package/lib/codegen/template/interpolation.js +108 -155
  39. package/lib/codegen/template/objectProperty.js +8 -4
  40. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  41. package/lib/codegen/template/propertyAccess.js +5 -7
  42. package/lib/codegen/template/slotOutlet.js +26 -14
  43. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  44. package/lib/codegen/template/styleScopedClasses.js +23 -149
  45. package/lib/codegen/template/templateChild.d.ts +0 -1
  46. package/lib/codegen/template/templateChild.js +11 -68
  47. package/lib/codegen/template/vFor.js +10 -13
  48. package/lib/codegen/template/vIf.js +5 -3
  49. package/lib/codegen/template/vSlot.js +20 -16
  50. package/lib/codegen/utils/boundary.d.ts +3 -0
  51. package/lib/codegen/utils/boundary.js +13 -0
  52. package/lib/codegen/utils/camelized.js +3 -3
  53. package/lib/codegen/utils/escaped.js +4 -2
  54. package/lib/codegen/utils/index.d.ts +3 -6
  55. package/lib/codegen/utils/index.js +41 -26
  56. package/lib/codegen/utils/merge.d.ts +2 -2
  57. package/lib/codegen/utils/merge.js +9 -9
  58. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  59. package/lib/codegen/utils/transform.d.ts +8 -0
  60. package/lib/codegen/utils/transform.js +27 -0
  61. package/lib/codegen/utils/unicode.js +4 -2
  62. package/lib/compilerOptions.js +4 -4
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +18 -25
  65. package/lib/plugins/vue-template-html.js +12 -9
  66. package/lib/plugins/vue-template-inline-css.js +8 -18
  67. package/lib/plugins/vue-template-inline-ts.js +12 -14
  68. package/lib/plugins/vue-tsx.d.ts +14 -23
  69. package/lib/plugins/vue-tsx.js +121 -69
  70. package/lib/plugins.js +1 -1
  71. package/lib/types.d.ts +5 -4
  72. package/lib/utils/parseSfc.js +10 -11
  73. package/lib/utils/shared.d.ts +1 -0
  74. package/lib/utils/shared.js +9 -0
  75. package/lib/utils/signals.d.ts +2 -2
  76. package/lib/utils/signals.js +8 -6
  77. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  78. package/lib/virtualCode/embeddedCodes.js +249 -0
  79. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  80. package/lib/virtualCode/index.js +81 -0
  81. package/lib/virtualCode/ir.d.ts +4 -0
  82. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
  83. package/lib/virtualCode/normalize.d.ts +2 -0
  84. package/lib/virtualCode/normalize.js +170 -0
  85. package/package.json +4 -4
  86. package/lib/codegen/style/classProperty.d.ts +0 -2
  87. package/lib/codegen/style/classProperty.js +0 -18
  88. package/lib/codegen/style/imports.d.ts +0 -2
  89. package/lib/codegen/style/imports.js +0 -27
  90. package/lib/codegen/template/elementChildren.d.ts +0 -5
  91. package/lib/codegen/template/elementChildren.js +0 -12
  92. package/lib/codegen/utils/wrapWith.d.ts +0 -3
  93. package/lib/codegen/utils/wrapWith.js +0 -24
  94. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  95. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  96. package/lib/virtualFile/computedSfc.d.ts +0 -6
  97. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  98. package/lib/virtualFile/computedVueSfc.js +0 -41
  99. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  100. package/lib/virtualFile/embeddedFile.js +0 -14
  101. package/lib/virtualFile/vueFile.js +0 -49
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeTemplateAST = normalizeTemplateAST;
4
+ const CompilerDOM = require("@vue/compiler-dom");
5
+ const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
6
+ // See https://github.com/vuejs/core/issues/3498
7
+ function normalizeTemplateAST(root) {
8
+ // @ts-ignore
9
+ const transformContext = {
10
+ onError: () => { },
11
+ helperString: str => str.toString(),
12
+ replaceNode: () => { },
13
+ cacheHandlers: false,
14
+ prefixIdentifiers: false,
15
+ scopes: {
16
+ vFor: 0,
17
+ vOnce: 0,
18
+ vPre: 0,
19
+ vSlot: 0,
20
+ },
21
+ expressionPlugins: ['typescript'],
22
+ };
23
+ for (const { children, codegenNode, props } of (0, forEachTemplateNode_1.forEachElementNode)(root)) {
24
+ for (let i = 0; i < children.length; i++) {
25
+ const child = children[i];
26
+ if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
27
+ continue;
28
+ }
29
+ const forNode = getVForNode(child, transformContext);
30
+ if (forNode) {
31
+ children[i] = forNode;
32
+ continue;
33
+ }
34
+ const ifNode = getVIfNode(child, transformContext);
35
+ if (ifNode) {
36
+ const normalized = normalizeIfBranch(ifNode, children, i);
37
+ children.splice(i, normalized.end - i + 1, normalized.node);
38
+ continue;
39
+ }
40
+ }
41
+ // #4539
42
+ if (codegenNode
43
+ && 'props' in codegenNode
44
+ && codegenNode.props
45
+ && 'properties' in codegenNode.props) {
46
+ for (const p of codegenNode.props.properties) {
47
+ if (p.key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
48
+ && p.key.content === 'key'
49
+ && !p.key.isHandlerKey
50
+ && !p.key.loc.source
51
+ && p.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
52
+ && p.value.constType === CompilerDOM.ConstantTypes.NOT_CONSTANT) {
53
+ const contentBeforeValue = root.loc.source.slice(0, p.value.loc.start.offset);
54
+ const argOffset = contentBeforeValue.lastIndexOf('key');
55
+ props.push({
56
+ type: CompilerDOM.NodeTypes.DIRECTIVE,
57
+ name: 'bind',
58
+ exp: p.value,
59
+ loc: p.loc,
60
+ arg: {
61
+ ...p.key,
62
+ loc: {
63
+ start: { line: -1, column: -1, offset: argOffset },
64
+ end: { line: -1, column: -1, offset: argOffset + 'key'.length },
65
+ source: 'key',
66
+ },
67
+ },
68
+ modifiers: [],
69
+ });
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ function normalizeIfBranch(ifNode, children, start) {
77
+ let end = start;
78
+ let comments = [];
79
+ for (let i = start + 1; i < children.length; i++) {
80
+ const sibling = children[i];
81
+ if (sibling.type === CompilerDOM.NodeTypes.COMMENT) {
82
+ comments.push(sibling);
83
+ continue;
84
+ }
85
+ if (sibling.type === CompilerDOM.NodeTypes.TEXT && !sibling.content.trim()) {
86
+ continue;
87
+ }
88
+ const elseBranch = getVElseDirective(sibling);
89
+ if (elseBranch) {
90
+ const branchNode = {
91
+ ...elseBranch.element,
92
+ props: elseBranch.element.props.filter(prop => prop !== elseBranch.directive),
93
+ };
94
+ const branch = createIfBranch(branchNode, elseBranch.directive);
95
+ if (comments.length) {
96
+ branch.children = [...comments, ...branch.children];
97
+ }
98
+ ifNode.branches.push(branch);
99
+ comments = [];
100
+ end = i;
101
+ continue;
102
+ }
103
+ break;
104
+ }
105
+ return { node: ifNode, end };
106
+ }
107
+ // source: https://github.com/vuejs/core/blob/25ebe3a42cd80ac0256355c2740a0258cdd7419d/packages/compiler-core/src/transforms/vIf.ts#L207
108
+ function createIfBranch(node, dir) {
109
+ const isTemplateIf = node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
110
+ return {
111
+ type: CompilerDOM.NodeTypes.IF_BRANCH,
112
+ loc: node.loc,
113
+ condition: dir.name === 'else' ? undefined : dir.exp,
114
+ children: isTemplateIf && !CompilerDOM.findDir(node, 'for') ? node.children : [node],
115
+ userKey: CompilerDOM.findProp(node, 'key'),
116
+ isTemplateIf,
117
+ };
118
+ }
119
+ function getVElseDirective(node) {
120
+ if (node.type !== CompilerDOM.NodeTypes.ELEMENT) {
121
+ return;
122
+ }
123
+ const directive = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
124
+ && (prop.name === 'else-if' || prop.name === 'else'));
125
+ if (directive) {
126
+ return {
127
+ element: node,
128
+ directive,
129
+ };
130
+ }
131
+ }
132
+ function getVForNode(node, transformContext) {
133
+ const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
134
+ && prop.name === 'for');
135
+ if (forDirective) {
136
+ let forNode;
137
+ CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
138
+ forNode = { ..._forNode };
139
+ return undefined;
140
+ });
141
+ if (forNode) {
142
+ forNode.children = [{
143
+ ...node,
144
+ props: node.props.filter(prop => prop !== forDirective),
145
+ }];
146
+ return forNode;
147
+ }
148
+ }
149
+ }
150
+ function getVIfNode(node, transformContext) {
151
+ const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
152
+ && prop.name === 'if');
153
+ if (ifDirective) {
154
+ let ifNode;
155
+ CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
156
+ ifNode = { ..._ifNode };
157
+ return undefined;
158
+ });
159
+ if (ifNode) {
160
+ for (const branch of ifNode.branches) {
161
+ branch.children = [{
162
+ ...node,
163
+ props: node.props.filter(prop => prop !== ifDirective),
164
+ }];
165
+ }
166
+ return ifNode;
167
+ }
168
+ }
169
+ }
170
+ //# sourceMappingURL=normalize.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.23",
16
+ "@volar/language-core": "2.4.26",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
18
  "@vue/shared": "^3.5.0",
19
19
  "alien-signals": "^3.0.0",
@@ -25,7 +25,7 @@
25
25
  "@types/node": "^22.10.4",
26
26
  "@types/path-browserify": "^1.0.1",
27
27
  "@types/picomatch": "^4.0.0",
28
- "@volar/typescript": "2.4.23",
28
+ "@volar/typescript": "2.4.26",
29
29
  "@vue/compiler-sfc": "^3.5.0"
30
30
  },
31
31
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "optional": true
37
37
  }
38
38
  },
39
- "gitHead": "9670176c727993d16f9224f48406077e20972353"
39
+ "gitHead": "341c06897f7f46606dddb8dd6d9e74e9c7844f02"
40
40
  }
@@ -1,2 +0,0 @@
1
- import type { Code } from '../../types';
2
- export declare function generateClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string): Generator<Code>;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateClassProperty = generateClassProperty;
4
- const codeFeatures_1 = require("../codeFeatures");
5
- const utils_1 = require("../utils");
6
- const wrapWith_1 = require("../utils/wrapWith");
7
- function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyType) {
8
- yield `${utils_1.newLine} & { `;
9
- yield* (0, wrapWith_1.wrapWith)(offset, offset + classNameWithDot.length, 'style_' + styleIndex, codeFeatures_1.codeFeatures.navigation, `'`, [
10
- classNameWithDot.slice(1),
11
- 'style_' + styleIndex,
12
- offset + 1,
13
- utils_1.combineLastMapping,
14
- ], `'`);
15
- yield `: ${propertyType}`;
16
- yield ` }`;
17
- }
18
- //# sourceMappingURL=classProperty.js.map
@@ -1,2 +0,0 @@
1
- import type { Code, Sfc } from '../../types';
2
- export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateStyleImports = generateStyleImports;
4
- const utils_1 = require("../utils");
5
- const wrapWith_1 = require("../utils/wrapWith");
6
- function* generateStyleImports(style) {
7
- const features = {
8
- navigation: true,
9
- verification: true,
10
- };
11
- if (typeof style.src === 'object') {
12
- yield `${utils_1.newLine} & typeof import(`;
13
- yield* (0, wrapWith_1.wrapWith)(style.src.offset, style.src.offset + style.src.text.length, 'main', features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
14
- yield `).default`;
15
- }
16
- for (const { text, offset } of style.imports) {
17
- yield `${utils_1.newLine} & typeof import('`;
18
- yield [
19
- text,
20
- style.name,
21
- offset,
22
- features,
23
- ];
24
- yield `').default`;
25
- }
26
- }
27
- //# sourceMappingURL=imports.js.map
@@ -1,5 +0,0 @@
1
- import type * as CompilerDOM from '@vue/compiler-dom';
2
- import type { Code } from '../../types';
3
- import type { TemplateCodegenContext } from './context';
4
- import type { TemplateCodegenOptions } from './index';
5
- export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, children: (CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode)[], enterNode?: boolean): Generator<Code>;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateElementChildren = generateElementChildren;
4
- const templateChild_1 = require("./templateChild");
5
- function* generateElementChildren(options, ctx, children, enterNode = true) {
6
- yield* ctx.generateAutoImportCompletion();
7
- for (const childNode of children) {
8
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, enterNode);
9
- }
10
- yield* ctx.generateAutoImportCompletion();
11
- }
12
- //# sourceMappingURL=elementChildren.js.map
@@ -1,3 +0,0 @@
1
- import type { Code, VueCodeInformation } from '../../types';
2
- export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
3
- export declare function wrapWith(startOffset: number, endOffset: number, source: string, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapWith = wrapWith;
4
- function* wrapWith(startOffset, endOffset, ...args) {
5
- let source = 'template';
6
- let features;
7
- let codes;
8
- if (typeof args[0] === 'string') {
9
- [source, features, ...codes] = args;
10
- }
11
- else {
12
- [features, ...codes] = args;
13
- }
14
- yield ['', source, startOffset, features];
15
- let offset = 1;
16
- for (const code of codes) {
17
- if (typeof code !== 'string') {
18
- offset++;
19
- }
20
- yield code;
21
- }
22
- yield ['', source, endOffset, { __combineOffset: offset }];
23
- }
24
- //# sourceMappingURL=wrapWith.js.map
@@ -1,4 +0,0 @@
1
- import type { VirtualCode } from '@volar/language-core';
2
- import type { Sfc, VueLanguagePluginReturn } from '../types';
3
- export declare function computedEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];
4
- export declare function resolveCommonLanguageId(lang: string): string;
@@ -1,262 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computedEmbeddedCodes = computedEmbeddedCodes;
4
- exports.resolveCommonLanguageId = resolveCommonLanguageId;
5
- const alien_signals_1 = require("alien-signals");
6
- const muggle_string_1 = require("muggle-string");
7
- const buildMappings_1 = require("../utils/buildMappings");
8
- const embeddedFile_1 = require("./embeddedFile");
9
- function computedEmbeddedCodes(plugins, fileName, sfc) {
10
- const getNameToBlockMap = (0, alien_signals_1.computed)(() => {
11
- const blocks = {};
12
- if (sfc.template) {
13
- blocks[sfc.template.name] = sfc.template;
14
- }
15
- if (sfc.script) {
16
- blocks[sfc.script.name] = sfc.script;
17
- }
18
- if (sfc.scriptSetup) {
19
- blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
20
- }
21
- for (const block of sfc.styles) {
22
- blocks[block.name] = block;
23
- }
24
- for (const block of sfc.customBlocks) {
25
- blocks[block.name] = block;
26
- }
27
- return blocks;
28
- });
29
- const getPluginsResult = plugins.map(plugin => computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, name => getNameToBlockMap()[name]));
30
- const getFlatResult = (0, alien_signals_1.computed)(() => getPluginsResult.map(r => r()).flat());
31
- const getStructuredResult = (0, alien_signals_1.computed)(() => {
32
- const embeddedCodes = [];
33
- let remain = [...getFlatResult()];
34
- while (remain.length) {
35
- const beforeLength = remain.length;
36
- consumeRemain();
37
- if (beforeLength === remain.length) {
38
- break;
39
- }
40
- }
41
- for (const { code } of remain) {
42
- console.error('Unable to resolve embedded: ' + code.parentCodeId + ' -> ' + code.id);
43
- }
44
- return embeddedCodes;
45
- function consumeRemain() {
46
- for (let i = remain.length - 1; i >= 0; i--) {
47
- const { code, snapshot, mappings } = remain[i];
48
- if (!code.parentCodeId) {
49
- embeddedCodes.push({
50
- id: code.id,
51
- languageId: resolveCommonLanguageId(code.lang),
52
- linkedCodeMappings: code.linkedCodeMappings,
53
- snapshot,
54
- mappings,
55
- embeddedCodes: [],
56
- });
57
- remain.splice(i, 1);
58
- }
59
- else {
60
- const parent = findParentStructure(code.parentCodeId, embeddedCodes);
61
- if (parent) {
62
- parent.embeddedCodes ??= [];
63
- parent.embeddedCodes.push({
64
- id: code.id,
65
- languageId: resolveCommonLanguageId(code.lang),
66
- linkedCodeMappings: code.linkedCodeMappings,
67
- snapshot,
68
- mappings,
69
- embeddedCodes: [],
70
- });
71
- remain.splice(i, 1);
72
- }
73
- }
74
- }
75
- }
76
- function findParentStructure(id, current) {
77
- for (const child of current) {
78
- if (child.id === id) {
79
- return child;
80
- }
81
- let parent = findParentStructure(id, child.embeddedCodes ?? []);
82
- if (parent) {
83
- return parent;
84
- }
85
- }
86
- }
87
- });
88
- return getStructuredResult;
89
- }
90
- function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByName) {
91
- const computeds = new Map();
92
- const getComputedKey = (code) => code.id + '__' + code.lang;
93
- const getCodes = (0, alien_signals_1.computed)(() => {
94
- try {
95
- if (!plugin.getEmbeddedCodes) {
96
- return [...computeds.values()];
97
- }
98
- const embeddedCodeInfos = plugin.getEmbeddedCodes(fileName, sfc);
99
- for (const oldId of computeds.keys()) {
100
- if (!embeddedCodeInfos.some(code => getComputedKey(code) === oldId)) {
101
- computeds.delete(oldId);
102
- }
103
- }
104
- for (const codeInfo of embeddedCodeInfos) {
105
- if (!computeds.has(getComputedKey(codeInfo))) {
106
- computeds.set(getComputedKey(codeInfo), (0, alien_signals_1.computed)(() => {
107
- const content = [];
108
- const code = new embeddedFile_1.VueEmbeddedCode(codeInfo.id, codeInfo.lang, content);
109
- for (const plugin of plugins) {
110
- if (!plugin.resolveEmbeddedCode) {
111
- continue;
112
- }
113
- try {
114
- plugin.resolveEmbeddedCode(fileName, sfc, code);
115
- }
116
- catch (e) {
117
- console.error(e);
118
- }
119
- }
120
- const newText = (0, muggle_string_1.toString)(code.content);
121
- const changeRanges = new Map();
122
- const snapshot = {
123
- getText: (start, end) => newText.slice(start, end),
124
- getLength: () => newText.length,
125
- getChangeRange(oldSnapshot) {
126
- if (!changeRanges.has(oldSnapshot)) {
127
- changeRanges.set(oldSnapshot, undefined);
128
- const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
129
- const changeRange = fullDiffTextChangeRange(oldText, newText);
130
- if (changeRange) {
131
- changeRanges.set(oldSnapshot, changeRange);
132
- }
133
- }
134
- return changeRanges.get(oldSnapshot);
135
- },
136
- };
137
- return {
138
- code,
139
- snapshot,
140
- };
141
- }));
142
- }
143
- }
144
- }
145
- catch (e) {
146
- console.error(e);
147
- }
148
- return [...computeds.values()];
149
- });
150
- return (0, alien_signals_1.computed)(() => {
151
- return getCodes().map(_file => {
152
- const { code, snapshot } = _file();
153
- const mappings = (0, buildMappings_1.buildMappings)(code.content.map(segment => {
154
- if (typeof segment === 'string') {
155
- return segment;
156
- }
157
- const source = segment[1];
158
- if (source === undefined) {
159
- return segment;
160
- }
161
- const block = getBlockByName(source);
162
- if (!block) {
163
- // console.warn('Unable to find block: ' + source);
164
- return segment;
165
- }
166
- return [
167
- segment[0],
168
- undefined,
169
- segment[2] + block.startTagEnd,
170
- segment[3],
171
- ];
172
- }));
173
- const newMappings = [];
174
- const tokenMappings = new Map();
175
- for (let i = 0; i < mappings.length; i++) {
176
- const mapping = mappings[i];
177
- if (mapping.data.__combineOffset !== undefined) {
178
- const offsetMapping = mappings[i - mapping.data.__combineOffset];
179
- if (typeof offsetMapping === 'string' || !offsetMapping) {
180
- throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: '
181
- + mapping.data.__combineOffset);
182
- }
183
- offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
184
- offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
185
- offsetMapping.lengths.push(...mapping.lengths);
186
- continue;
187
- }
188
- if (mapping.data.__linkedToken !== undefined) {
189
- const token = mapping.data.__linkedToken;
190
- if (tokenMappings.has(token)) {
191
- const prevMapping = tokenMappings.get(token);
192
- code.linkedCodeMappings.push({
193
- sourceOffsets: [prevMapping.generatedOffsets[0]],
194
- generatedOffsets: [mapping.generatedOffsets[0]],
195
- lengths: [Number(token.description)],
196
- data: undefined,
197
- });
198
- }
199
- else {
200
- tokenMappings.set(token, mapping);
201
- }
202
- continue;
203
- }
204
- newMappings.push(mapping);
205
- }
206
- return {
207
- code,
208
- snapshot,
209
- mappings: newMappings,
210
- };
211
- });
212
- });
213
- }
214
- function fullDiffTextChangeRange(oldText, newText) {
215
- for (let start = 0; start < oldText.length && start < newText.length; start++) {
216
- if (oldText[start] !== newText[start]) {
217
- let end = oldText.length;
218
- for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
219
- if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
220
- break;
221
- }
222
- end--;
223
- }
224
- let length = end - start;
225
- let newLength = length + (newText.length - oldText.length);
226
- if (newLength < 0) {
227
- length -= newLength;
228
- newLength = 0;
229
- }
230
- return {
231
- span: { start, length },
232
- newLength,
233
- };
234
- }
235
- }
236
- }
237
- function resolveCommonLanguageId(lang) {
238
- switch (lang) {
239
- case 'js':
240
- return 'javascript';
241
- case 'cjs':
242
- return 'javascript';
243
- case 'mjs':
244
- return 'javascript';
245
- case 'ts':
246
- return 'typescript';
247
- case 'cts':
248
- return 'typescript';
249
- case 'mts':
250
- return 'typescript';
251
- case 'jsx':
252
- return 'javascriptreact';
253
- case 'tsx':
254
- return 'typescriptreact';
255
- case 'pug':
256
- return 'jade';
257
- case 'md':
258
- return 'markdown';
259
- }
260
- return lang;
261
- }
262
- //# sourceMappingURL=computedEmbeddedCodes.js.map
@@ -1,6 +0,0 @@
1
- import type * as CompilerDOM from '@vue/compiler-dom';
2
- import type { SFCParseResult } from '@vue/compiler-sfc';
3
- import type * as ts from 'typescript';
4
- import type { Sfc, VueLanguagePluginReturn } from '../types';
5
- export declare const templateInlineTsAsts: WeakMap<CompilerDOM.RootNode, Map<string, ts.SourceFile>>;
6
- export declare function computedSfc(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseResult: () => SFCParseResult | undefined): Sfc;
@@ -1,4 +0,0 @@
1
- import type { SFCParseResult } from '@vue/compiler-sfc';
2
- import type * as ts from 'typescript';
3
- import type { VueLanguagePluginReturn } from '../types';
4
- export declare function computedVueSfc(plugins: VueLanguagePluginReturn[], fileName: string, languageId: string, getSnapshot: () => ts.IScriptSnapshot): () => SFCParseResult | undefined;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computedVueSfc = computedVueSfc;
4
- const alien_signals_1 = require("alien-signals");
5
- function computedVueSfc(plugins, fileName, languageId, getSnapshot) {
6
- let cache;
7
- return (0, alien_signals_1.computed)(() => {
8
- // incremental update
9
- if (cache?.plugin.updateSFC) {
10
- const change = getSnapshot().getChangeRange(cache.snapshot);
11
- if (change) {
12
- const newSfc = cache.plugin.updateSFC(cache.sfc, {
13
- start: change.span.start,
14
- end: change.span.start + change.span.length,
15
- newText: getSnapshot().getText(change.span.start, change.span.start + change.newLength),
16
- });
17
- if (newSfc) {
18
- cache.snapshot = getSnapshot();
19
- // force dirty
20
- cache.sfc = JSON.parse(JSON.stringify(newSfc));
21
- return cache.sfc;
22
- }
23
- }
24
- }
25
- for (const plugin of plugins) {
26
- const sfc = plugin.parseSFC?.(fileName, getSnapshot().getText(0, getSnapshot().getLength()))
27
- ?? plugin.parseSFC2?.(fileName, languageId, getSnapshot().getText(0, getSnapshot().getLength()));
28
- if (sfc) {
29
- if (!sfc.errors.length) {
30
- cache = {
31
- snapshot: getSnapshot(),
32
- sfc,
33
- plugin,
34
- };
35
- }
36
- return sfc;
37
- }
38
- }
39
- });
40
- }
41
- //# sourceMappingURL=computedVueSfc.js.map
@@ -1,11 +0,0 @@
1
- import type { Mapping } from '@volar/language-core';
2
- import type { Code } from '../types';
3
- export declare class VueEmbeddedCode {
4
- id: string;
5
- lang: string;
6
- content: Code[];
7
- parentCodeId?: string;
8
- linkedCodeMappings: Mapping[];
9
- embeddedCodes: VueEmbeddedCode[];
10
- constructor(id: string, lang: string, content: Code[]);
11
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VueEmbeddedCode = void 0;
4
- class VueEmbeddedCode {
5
- constructor(id, lang, content) {
6
- this.id = id;
7
- this.lang = lang;
8
- this.content = content;
9
- this.linkedCodeMappings = [];
10
- this.embeddedCodes = [];
11
- }
12
- }
13
- exports.VueEmbeddedCode = VueEmbeddedCode;
14
- //# sourceMappingURL=embeddedFile.js.map