@vue/language-core 3.2.7 → 3.2.9

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 (48) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -23
  3. package/lib/codegen/names.d.ts +73 -26
  4. package/lib/codegen/names.js +75 -27
  5. package/lib/codegen/script/component.js +19 -58
  6. package/lib/codegen/script/index.js +12 -12
  7. package/lib/codegen/script/scriptSetup.js +48 -81
  8. package/lib/codegen/script/template.js +29 -63
  9. package/lib/codegen/style/modules.js +4 -37
  10. package/lib/codegen/style/scopedClasses.js +2 -1
  11. package/lib/codegen/template/element.d.ts +1 -0
  12. package/lib/codegen/template/element.js +45 -25
  13. package/lib/codegen/template/elementDirectives.js +4 -4
  14. package/lib/codegen/template/elementEvents.js +3 -2
  15. package/lib/codegen/template/elementProps.js +9 -9
  16. package/lib/codegen/template/index.js +16 -49
  17. package/lib/codegen/template/interpolation.js +3 -36
  18. package/lib/codegen/template/objectProperty.js +2 -1
  19. package/lib/codegen/template/slotOutlet.js +5 -5
  20. package/lib/codegen/template/styleScopedClasses.js +3 -2
  21. package/lib/codegen/template/templateChild.d.ts +1 -1
  22. package/lib/codegen/template/templateChild.js +14 -23
  23. package/lib/codegen/template/vFor.js +3 -20
  24. package/lib/codegen/template/vIf.js +1 -5
  25. package/lib/codegen/template/vSlot.js +2 -1
  26. package/lib/languagePlugin.js +2 -0
  27. package/lib/plugins/file-md.js +26 -30
  28. package/lib/plugins/vue-template-html.js +37 -12
  29. package/lib/plugins/vue-template-inline-ts.js +0 -4
  30. package/lib/plugins/vue-tsx.js +5 -22
  31. package/lib/template/compile.d.ts +2 -0
  32. package/lib/template/compile.js +31 -0
  33. package/lib/template/transforms/transformElement.d.ts +2 -0
  34. package/lib/template/transforms/transformElement.js +95 -0
  35. package/lib/template/transforms/transformText.d.ts +2 -0
  36. package/lib/template/transforms/transformText.js +35 -0
  37. package/lib/template/transforms/vFor.d.ts +1 -0
  38. package/lib/template/transforms/vFor.js +42 -0
  39. package/lib/template/transforms/vIf.d.ts +1 -0
  40. package/lib/template/transforms/vIf.js +92 -0
  41. package/lib/template/utils.d.ts +3 -0
  42. package/lib/template/utils.js +37 -0
  43. package/lib/types.d.ts +1 -0
  44. package/lib/utils/forEachTemplateNode.js +0 -3
  45. package/lib/virtualCode/ir.js +0 -39
  46. package/package.json +12 -6
  47. package/lib/virtualCode/normalize.d.ts +0 -2
  48. package/lib/virtualCode/normalize.js +0 -205
@@ -38,6 +38,7 @@ exports.parseVForNode = parseVForNode;
38
38
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
39
39
  const collectBindings_1 = require("../../utils/collectBindings");
40
40
  const codeFeatures_1 = require("../codeFeatures");
41
+ const names_1 = require("../names");
41
42
  const utils_1 = require("../utils");
42
43
  const interpolation_1 = require("./interpolation");
43
44
  const templateChild_1 = require("./templateChild");
@@ -58,7 +59,7 @@ function* generateVFor(options, ctx, node) {
58
59
  }
59
60
  yield `] of `;
60
61
  if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
61
- yield `__VLS_vFor(`;
62
+ yield `${names_1.names.vFor}(`;
62
63
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
63
64
  yield `!)`; // #3102
64
65
  }
@@ -66,28 +67,10 @@ function* generateVFor(options, ctx, node) {
66
67
  yield `{} as any`;
67
68
  }
68
69
  yield `) {${utils_1.newLine}`;
69
- let isFragment = true;
70
- for (const argument of node.codegenNode?.children.arguments ?? []) {
71
- if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
72
- && argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
73
- && argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
74
- if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
75
- isFragment = false;
76
- continue;
77
- }
78
- for (const prop of argument.returns.props.properties) {
79
- if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
80
- && !prop.value.isStatic) {
81
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
82
- yield utils_1.endOfLine;
83
- }
84
- }
85
- }
86
- }
87
70
  const { inVFor } = ctx;
88
71
  ctx.inVFor = true;
89
72
  for (const child of node.children) {
90
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, isFragment);
73
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, false, true);
91
74
  }
92
75
  ctx.inVFor = inVFor;
93
76
  yield* endScope();
@@ -42,10 +42,6 @@ const interpolation_1 = require("./interpolation");
42
42
  const templateChild_1 = require("./templateChild");
43
43
  function* generateVIf(options, ctx, node) {
44
44
  const originalBlockConditionsLength = ctx.blockConditions.length;
45
- const isFragment = node.codegenNode
46
- && 'consequent' in node.codegenNode
47
- && 'tag' in node.codegenNode.consequent
48
- && node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
49
45
  for (let i = 0; i < node.branches.length; i++) {
50
46
  const branch = node.branches[i];
51
47
  if (i === 0) {
@@ -67,7 +63,7 @@ function* generateVIf(options, ctx, node) {
67
63
  }
68
64
  yield `{${utils_1.newLine}`;
69
65
  for (const child of branch.children) {
70
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, i !== 0 || isFragment);
66
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, i !== 0, true);
71
67
  }
72
68
  yield `}${utils_1.newLine}`;
73
69
  if (addedBlockCondition) {
@@ -38,6 +38,7 @@ const CompilerDOM = __importStar(require("@vue/compiler-dom"));
38
38
  const muggle_string_1 = require("muggle-string");
39
39
  const collectBindings_1 = require("../../utils/collectBindings");
40
40
  const codeFeatures_1 = require("../codeFeatures");
41
+ const names_1 = require("../names");
41
42
  const utils_1 = require("../utils");
42
43
  const boundary_1 = require("../utils/boundary");
43
44
  const interpolation_1 = require("./interpolation");
@@ -125,7 +126,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
125
126
  }
126
127
  yield `const [`;
127
128
  yield* interpolation;
128
- yield `] = __VLS_vSlot(${slotVar}!`;
129
+ yield `] = ${names_1.names.vSlot}(${slotVar}!`;
129
130
  if (types.some(t => t)) {
130
131
  yield `, `;
131
132
  const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
@@ -38,6 +38,7 @@ exports.createVueLanguagePlugin = createVueLanguagePlugin;
38
38
  exports.getAllExtensions = getAllExtensions;
39
39
  const language_core_1 = require("@volar/language-core");
40
40
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
41
+ const LanguageCore = __importStar(require("../index"));
41
42
  const plugins_1 = require("./plugins");
42
43
  const virtualCode_1 = require("./virtualCode");
43
44
  const fileRegistries = {};
@@ -60,6 +61,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
60
61
  const pluginContext = {
61
62
  modules: {
62
63
  '@vue/compiler-dom': CompilerDOM,
64
+ '@vue/language-core': LanguageCore,
63
65
  typescript: ts,
64
66
  },
65
67
  compilerOptions,
@@ -5,14 +5,13 @@ const muggle_string_1 = require("muggle-string");
5
5
  const buildMappings_1 = require("../utils/buildMappings");
6
6
  const parseSfc_1 = require("../utils/parseSfc");
7
7
  const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
8
- const codeblockReg = /(`{3,})[\s\S]+?\1/g;
9
- const inlineCodeblockReg = /`[^\n`]+?`/g;
10
- const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
11
- const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
8
+ const codeblockReg = /(`{3}|\${2})[\s\S]+?\1/g;
12
9
  const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
13
- const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
14
- const angleBracketReg = /<\S*:\S*>/g;
15
- const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
10
+ const sfcBlockReg = /<(script|style)\b[^>]*>([\s\S]*?)<\/\1>/g;
11
+ const htmlTagReg = /(?<=<\/?)([a-z][a-z0-9-]*)\b[^>]*(?=>)/gi;
12
+ const interpolationReg = /(?<=\{\{)[\s\S]*?(?=\}\})/g;
13
+ const inlineCodeReg = /(`{1,2})[^`]+\1/g;
14
+ const angleBracketReg = /<[^\s:]*:\S*>/g;
16
15
  const plugin = ({ vueCompilerOptions }) => {
17
16
  return {
18
17
  version: 2.2,
@@ -28,32 +27,29 @@ const plugin = ({ vueCompilerOptions }) => {
28
27
  if (languageId !== 'markdown') {
29
28
  return;
30
29
  }
31
- content = content
32
- // frontmatter
33
- .replace(frontmatterReg, match => ' '.repeat(match.length))
34
- // code block
35
- .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
36
- // inline code block
37
- .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
38
- // latex block
39
- .replace(latexBlockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
40
- // # \<script setup>
41
- .replace(scriptSetupReg, match => ' '.repeat(match.length))
42
- // <<< https://vitepress.dev/guide/markdown#import-code-snippets
43
- .replace(codeSnippetImportReg, match => ' '.repeat(match.length));
30
+ for (const reg of [frontmatterReg, codeblockReg, codeSnippetImportReg]) {
31
+ content = content.replace(reg, match => ' '.repeat(match.length));
32
+ }
44
33
  const codes = [];
45
- for (const match of content.matchAll(sfcBlockReg)) {
46
- const matchText = match[0];
47
- codes.push([matchText, undefined, match.index]);
34
+ for (const { 0: text, index } of content.matchAll(sfcBlockReg)) {
35
+ codes.push([text, undefined, index]);
48
36
  codes.push('\n\n');
49
- content = content.slice(0, match.index) + ' '.repeat(matchText.length)
50
- + content.slice(match.index + matchText.length);
37
+ content = content.slice(0, index) + ' '.repeat(text.length) + content.slice(index + text.length);
38
+ }
39
+ const ranges = [];
40
+ for (const reg of [htmlTagReg, interpolationReg]) {
41
+ for (const { 0: text, index } of content.matchAll(reg)) {
42
+ ranges.push([index, index + text.length]);
43
+ }
44
+ }
45
+ for (const reg of [inlineCodeReg, angleBracketReg]) {
46
+ for (const { 0: text, index } of content.matchAll(reg)) {
47
+ if (ranges.some(([start, end]) => index >= start && index < end)) {
48
+ continue;
49
+ }
50
+ content = content.slice(0, index) + ' '.repeat(text.length) + content.slice(index + text.length);
51
+ }
51
52
  }
52
- content = content
53
- // angle bracket: <http://foo.com>
54
- .replace(angleBracketReg, match => ' '.repeat(match.length))
55
- // [foo](http://foo.com)
56
- .replace(linkReg, match => ' '.repeat(match.length));
57
53
  codes.push('<template>\n');
58
54
  codes.push([content, undefined, 0]);
59
55
  codes.push('\n</template>');
@@ -1,8 +1,42 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const CompilerDOM = __importStar(require("@vue/compiler-dom"));
37
+ const compile_1 = require("../template/compile");
3
38
  const shouldAddSuffix = /(?<=<[^>/]+)$/;
4
- const plugin = ({ modules }) => {
5
- const CompilerDOM = modules['@vue/compiler-dom'];
39
+ const plugin = () => {
6
40
  return {
7
41
  version: 2.2,
8
42
  compileSFCTemplate(lang, template, options) {
@@ -13,11 +47,7 @@ const plugin = ({ modules }) => {
13
47
  template += '>';
14
48
  addedSuffix = true;
15
49
  }
16
- const ast = CompilerDOM.parse(template, {
17
- ...options,
18
- comments: true,
19
- });
20
- CompilerDOM.transform(ast, options);
50
+ const ast = (0, compile_1.compileTemplate)(template, options);
21
51
  return {
22
52
  ast,
23
53
  code: '',
@@ -97,11 +127,6 @@ const plugin = ({ modules }) => {
97
127
  return false;
98
128
  }
99
129
  }
100
- else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
101
- if (!tryUpdateNode(node.content)) {
102
- return false;
103
- }
104
- }
105
130
  else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
106
131
  for (const childNode of node.children) {
107
132
  if (typeof childNode === 'object') {
@@ -178,10 +178,6 @@ const plugin = ({ modules: { typescript: ts } }) => {
178
178
  visit(child);
179
179
  }
180
180
  }
181
- else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
182
- // {{ var }}
183
- visit(node.content);
184
- }
185
181
  else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
186
182
  // {{ ... }} {{ ... }}
187
183
  for (const childNode of node.children) {
@@ -206,28 +206,11 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
206
206
  if (!allVars.size) {
207
207
  return allVars;
208
208
  }
209
- const exposedNames = new Set();
210
- const generatedTemplate = getGeneratedTemplate();
211
- const generatedStyle = getGeneratedStyle();
212
- for (const [name] of generatedTemplate?.componentAccessMap ?? []) {
213
- if (allVars.has(name)) {
214
- exposedNames.add(name);
215
- }
216
- }
217
- for (const [name] of generatedStyle?.componentAccessMap ?? []) {
218
- if (allVars.has(name)) {
219
- exposedNames.add(name);
220
- }
221
- }
222
- for (const component of sfc.template?.ast?.components ?? []) {
223
- const testNames = new Set([(0, shared_1.camelize)(component), (0, shared_1.capitalize)((0, shared_1.camelize)(component))]);
224
- for (const testName of testNames) {
225
- if (allVars.has(testName)) {
226
- exposedNames.add(testName);
227
- }
228
- }
229
- }
230
- return exposedNames;
209
+ return new Set([
210
+ ...getGeneratedTemplate()?.componentAccessMap.keys() ?? [],
211
+ ...getGeneratedStyle()?.componentAccessMap.keys() ?? [],
212
+ ...sfc.template?.ast?.components.flatMap(name => [(0, shared_1.camelize)(name), (0, shared_1.capitalize)((0, shared_1.camelize)(name))]) ?? [],
213
+ ].filter(name => allVars.has(name)));
231
214
  });
232
215
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
233
216
  return (0, script_1.generateScript)({
@@ -0,0 +1,2 @@
1
+ import { type CompilerOptions } from '@vue/compiler-dom';
2
+ export declare function compileTemplate(source: string, options: CompilerOptions): import("@vue/compiler-dom").RootNode;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileTemplate = compileTemplate;
4
+ const compiler_dom_1 = require("@vue/compiler-dom");
5
+ const transformElement_1 = require("./transforms/transformElement");
6
+ const transformText_1 = require("./transforms/transformText");
7
+ const vFor_1 = require("./transforms/vFor");
8
+ const vIf_1 = require("./transforms/vIf");
9
+ function compileTemplate(source, options) {
10
+ const [nodeTransforms, directiveTransforms] = (0, compiler_dom_1.getBaseTransformPreset)();
11
+ const resolvedOptions = {
12
+ ...options,
13
+ comments: true,
14
+ nodeTransforms: [
15
+ nodeTransforms[0], // transformVBindShorthand
16
+ vIf_1.transformIf,
17
+ vFor_1.transformFor,
18
+ transformElement_1.transformElement,
19
+ transformText_1.transformText,
20
+ ...options.nodeTransforms || [],
21
+ ],
22
+ directiveTransforms: {
23
+ ...directiveTransforms,
24
+ ...options.directiveTransforms,
25
+ },
26
+ };
27
+ const ast = (0, compiler_dom_1.parse)(source, resolvedOptions);
28
+ (0, compiler_dom_1.transform)(ast, resolvedOptions);
29
+ return ast;
30
+ }
31
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1,2 @@
1
+ import { type NodeTransform } from '@vue/compiler-dom';
2
+ export declare const transformElement: NodeTransform;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformElement = void 0;
4
+ const compiler_dom_1 = require("@vue/compiler-dom");
5
+ const shared_1 = require("@vue/shared");
6
+ const transformElement = (node, context) => {
7
+ return () => {
8
+ if (node.type !== compiler_dom_1.NodeTypes.ELEMENT || node.tagType === compiler_dom_1.ElementTypes.TEMPLATE) {
9
+ return;
10
+ }
11
+ const isComponent = node.tagType === compiler_dom_1.ElementTypes.COMPONENT;
12
+ const isSlotOutlet = node.tagType === compiler_dom_1.ElementTypes.SLOT;
13
+ for (const prop of node.props) {
14
+ if (prop.type !== compiler_dom_1.NodeTypes.DIRECTIVE) {
15
+ continue;
16
+ }
17
+ if (prop.name === 'slot') {
18
+ if (!isComponent) {
19
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_MISPLACED, prop.loc));
20
+ }
21
+ continue;
22
+ }
23
+ const isVBind = prop.name === 'bind';
24
+ const isVOn = prop.name === 'on';
25
+ if (!prop.arg && (isVBind || isVOn)) {
26
+ if (!prop.exp) {
27
+ context.onError((0, compiler_dom_1.createCompilerError)(isVBind
28
+ ? compiler_dom_1.ErrorCodes.X_V_BIND_NO_EXPRESSION
29
+ : compiler_dom_1.ErrorCodes.X_V_ON_NO_EXPRESSION, prop.loc));
30
+ }
31
+ continue;
32
+ }
33
+ const runtimeDirectives = [];
34
+ const directiveTransform = context.directiveTransforms[prop.name];
35
+ if (directiveTransform) {
36
+ const { needRuntime } = directiveTransform(prop, node, context);
37
+ if (needRuntime) {
38
+ runtimeDirectives.push(prop);
39
+ }
40
+ }
41
+ else if (!(0, shared_1.isBuiltInDirective)(prop.name)) {
42
+ runtimeDirectives.push(prop);
43
+ }
44
+ if (isSlotOutlet && runtimeDirectives.length) {
45
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET, prop.loc));
46
+ }
47
+ }
48
+ if (isComponent) {
49
+ let hasTemplateSlots = false;
50
+ let hasNamedDefaultSlot = false;
51
+ const implicitDefaultChildren = [];
52
+ const seenSlotNames = new Set();
53
+ const onComponentSlot = (0, compiler_dom_1.findDir)(node, 'slot', true);
54
+ for (const child of node.children) {
55
+ let slotDir;
56
+ if (!(0, compiler_dom_1.isTemplateNode)(child) || !(slotDir = (0, compiler_dom_1.findDir)(child, 'slot', true))) {
57
+ if (child.type !== compiler_dom_1.NodeTypes.COMMENT) {
58
+ implicitDefaultChildren.push(child);
59
+ }
60
+ continue;
61
+ }
62
+ if (onComponentSlot) {
63
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, slotDir.loc));
64
+ break;
65
+ }
66
+ if ((0, compiler_dom_1.findDir)(child, /^(?:if|else-if|else|for)$/, true)) {
67
+ continue;
68
+ }
69
+ hasTemplateSlots = true;
70
+ const staticSlotName = slotDir.arg
71
+ ? (0, compiler_dom_1.isStaticExp)(slotDir.arg)
72
+ ? slotDir.arg.content
73
+ : undefined
74
+ : 'default';
75
+ if (staticSlotName) {
76
+ if (seenSlotNames.has(staticSlotName)) {
77
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, slotDir.loc));
78
+ continue;
79
+ }
80
+ seenSlotNames.add(staticSlotName);
81
+ if (staticSlotName === 'default') {
82
+ hasNamedDefaultSlot = true;
83
+ }
84
+ }
85
+ }
86
+ if (hasTemplateSlots && hasNamedDefaultSlot
87
+ && implicitDefaultChildren.some(node => node.type !== compiler_dom_1.NodeTypes.TEXT || !!node.content.trim())) {
88
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN, implicitDefaultChildren[0].loc));
89
+ }
90
+ context.components.add(node.tag);
91
+ }
92
+ };
93
+ };
94
+ exports.transformElement = transformElement;
95
+ //# sourceMappingURL=transformElement.js.map
@@ -0,0 +1,2 @@
1
+ import { type NodeTransform } from '@vue/compiler-dom';
2
+ export declare const transformText: NodeTransform;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformText = void 0;
4
+ const compiler_dom_1 = require("@vue/compiler-dom");
5
+ const transformText = node => {
6
+ if (node.type === compiler_dom_1.NodeTypes.ROOT
7
+ || node.type === compiler_dom_1.NodeTypes.ELEMENT
8
+ || node.type === compiler_dom_1.NodeTypes.FOR
9
+ || node.type === compiler_dom_1.NodeTypes.IF_BRANCH) {
10
+ return () => {
11
+ const children = node.children;
12
+ let currentContainer = undefined;
13
+ for (let i = 0; i < children.length; i++) {
14
+ const child = children[i];
15
+ if ((0, compiler_dom_1.isText)(child)) {
16
+ for (let j = i + 1; j < children.length; j++) {
17
+ const next = children[j];
18
+ if ((0, compiler_dom_1.isText)(next)) {
19
+ currentContainer ??= children[i] = (0, compiler_dom_1.createCompoundExpression)([child], child.loc);
20
+ currentContainer.children.push(` + `, next);
21
+ children.splice(j, 1);
22
+ j--;
23
+ }
24
+ else {
25
+ currentContainer = undefined;
26
+ break;
27
+ }
28
+ }
29
+ }
30
+ }
31
+ };
32
+ }
33
+ };
34
+ exports.transformText = transformText;
35
+ //# sourceMappingURL=transformText.js.map
@@ -0,0 +1 @@
1
+ export declare const transformFor: import("@vue/compiler-dom").NodeTransform;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformFor = void 0;
4
+ const compiler_dom_1 = require("@vue/compiler-dom");
5
+ const utils_1 = require("../utils");
6
+ exports.transformFor = (0, utils_1.createStructuralDirectiveTransform)('for', (node, dir, context) => {
7
+ if (!dir.exp) {
8
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_FOR_NO_EXPRESSION, dir.loc));
9
+ return;
10
+ }
11
+ const parseResult = dir.forParseResult;
12
+ if (!parseResult) {
13
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, dir.loc));
14
+ return;
15
+ }
16
+ const { source, value, key, index } = parseResult;
17
+ const forNode = {
18
+ type: compiler_dom_1.NodeTypes.FOR,
19
+ loc: dir.loc,
20
+ source,
21
+ valueAlias: value,
22
+ keyAlias: key,
23
+ objectIndexAlias: index,
24
+ parseResult,
25
+ children: [node],
26
+ };
27
+ context.replaceNode(forNode);
28
+ return () => {
29
+ if ((0, compiler_dom_1.isTemplateNode)(node)) {
30
+ for (const child of node.children) {
31
+ if (child.type === compiler_dom_1.NodeTypes.ELEMENT) {
32
+ const key = (0, compiler_dom_1.findProp)(child, 'key');
33
+ if (key) {
34
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT, key.loc));
35
+ break;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ };
41
+ });
42
+ //# sourceMappingURL=vFor.js.map
@@ -0,0 +1 @@
1
+ export declare const transformIf: import("@vue/compiler-dom").NodeTransform;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformIf = void 0;
4
+ const compiler_dom_1 = require("@vue/compiler-dom");
5
+ const utils_1 = require("../utils");
6
+ exports.transformIf = (0, utils_1.createStructuralDirectiveTransform)(/^(?:if|else-if|else)$/, (node, dir, context) => {
7
+ if (dir.name !== 'else'
8
+ && (!dir.exp || !dir.exp.content.trim())) {
9
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc));
10
+ }
11
+ if (dir.name === 'if') {
12
+ const branch = createIfBranch(node, dir);
13
+ const ifNode = {
14
+ type: compiler_dom_1.NodeTypes.IF,
15
+ loc: (0, utils_1.cloneLoc)(node.loc),
16
+ branches: [branch],
17
+ };
18
+ context.replaceNode(ifNode);
19
+ }
20
+ else {
21
+ const siblings = context.parent.children;
22
+ const comments = [];
23
+ let i = siblings.indexOf(node);
24
+ while (i-- >= -1) {
25
+ const sibling = siblings[i];
26
+ if (sibling?.type === compiler_dom_1.NodeTypes.COMMENT) {
27
+ context.removeNode(sibling);
28
+ comments.unshift(sibling);
29
+ continue;
30
+ }
31
+ if (sibling?.type === compiler_dom_1.NodeTypes.TEXT && !sibling.content.trim().length) {
32
+ context.removeNode(sibling);
33
+ continue;
34
+ }
35
+ if (sibling?.type === compiler_dom_1.NodeTypes.IF) {
36
+ if (!sibling.branches.at(-1).condition) {
37
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, node.loc));
38
+ }
39
+ context.removeNode();
40
+ const branch = createIfBranch(node, dir);
41
+ if (comments.length) {
42
+ branch.children.unshift(...comments);
43
+ }
44
+ if (branch.userKey) {
45
+ for (const { userKey } of sibling.branches) {
46
+ if (isSameKey(userKey, branch.userKey)) {
47
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_IF_SAME_KEY, branch.userKey.loc));
48
+ }
49
+ }
50
+ }
51
+ sibling.branches.push(branch);
52
+ (0, compiler_dom_1.traverseNode)(branch, context);
53
+ context.currentNode = null;
54
+ }
55
+ else {
56
+ context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, node.loc));
57
+ }
58
+ break;
59
+ }
60
+ }
61
+ });
62
+ function createIfBranch(node, dir) {
63
+ return {
64
+ type: compiler_dom_1.NodeTypes.IF_BRANCH,
65
+ loc: node.loc,
66
+ condition: dir.name === 'else' ? undefined : dir.exp,
67
+ children: [node],
68
+ userKey: (0, compiler_dom_1.findProp)(node, 'key'),
69
+ };
70
+ }
71
+ function isSameKey(a, b) {
72
+ if (!a || a.type !== b.type) {
73
+ return false;
74
+ }
75
+ if (a.type === compiler_dom_1.NodeTypes.ATTRIBUTE) {
76
+ if (a.value.content !== b.value.content) {
77
+ return false;
78
+ }
79
+ }
80
+ else {
81
+ const exp = a.exp;
82
+ const branchExp = b.exp;
83
+ if (exp.type !== branchExp.type
84
+ || exp.type !== compiler_dom_1.NodeTypes.SIMPLE_EXPRESSION
85
+ || exp.isStatic !== branchExp.isStatic
86
+ || exp.content !== branchExp.content) {
87
+ return false;
88
+ }
89
+ }
90
+ return true;
91
+ }
92
+ //# sourceMappingURL=vIf.js.map
@@ -0,0 +1,3 @@
1
+ import { type NodeTransform, type SourceLocation, type StructuralDirectiveTransform } from '@vue/compiler-dom';
2
+ export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
3
+ export declare function cloneLoc(loc: SourceLocation): SourceLocation;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
4
+ exports.cloneLoc = cloneLoc;
5
+ const compiler_dom_1 = require("@vue/compiler-dom");
6
+ const shared_1 = require("@vue/shared");
7
+ function createStructuralDirectiveTransform(name, fn) {
8
+ const matches = (0, shared_1.isString)(name)
9
+ ? (n) => n === name
10
+ : (n) => name.test(n);
11
+ return (node, context) => {
12
+ if (node.type === compiler_dom_1.NodeTypes.ELEMENT) {
13
+ const { props } = node;
14
+ const exitFns = [];
15
+ for (let i = 0; i < props.length; i++) {
16
+ const prop = props[i];
17
+ if (prop.type === compiler_dom_1.NodeTypes.DIRECTIVE && matches(prop.name)) {
18
+ props.splice(i, 1);
19
+ i--;
20
+ const onExit = fn(node, prop, context);
21
+ if (onExit) {
22
+ exitFns.push(onExit);
23
+ }
24
+ }
25
+ }
26
+ return exitFns;
27
+ }
28
+ };
29
+ }
30
+ function cloneLoc(loc) {
31
+ return {
32
+ start: { ...loc.start },
33
+ end: { ...loc.end },
34
+ source: loc.source,
35
+ };
36
+ }
37
+ //# sourceMappingURL=utils.js.map