@vue/language-core 3.2.8 → 3.3.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 (67) hide show
  1. package/README.md +1 -0
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/lib/codegen/names.d.ts +1 -0
  5. package/lib/codegen/names.js +1 -0
  6. package/lib/codegen/script/component.d.ts +2 -2
  7. package/lib/codegen/script/component.js +64 -58
  8. package/lib/codegen/script/index.d.ts +3 -3
  9. package/lib/codegen/script/scriptSetup.d.ts +4 -4
  10. package/lib/codegen/script/template.js +9 -9
  11. package/lib/codegen/style/common.d.ts +2 -2
  12. package/lib/codegen/style/index.d.ts +2 -2
  13. package/lib/codegen/template/element.d.ts +1 -0
  14. package/lib/codegen/template/element.js +46 -24
  15. package/lib/codegen/template/elementProps.d.ts +2 -2
  16. package/lib/codegen/template/elementProps.js +17 -16
  17. package/lib/codegen/template/index.d.ts +2 -2
  18. package/lib/codegen/template/index.js +6 -3
  19. package/lib/codegen/template/interpolation.d.ts +2 -2
  20. package/lib/codegen/template/styleScopedClasses.d.ts +3 -3
  21. package/lib/codegen/template/templateChild.d.ts +1 -1
  22. package/lib/codegen/template/templateChild.js +20 -25
  23. package/lib/codegen/template/vFor.js +1 -19
  24. package/lib/codegen/template/vIf.js +1 -5
  25. package/lib/codegen/utils/index.d.ts +3 -3
  26. package/lib/codegen/utils/merge.d.ts +2 -2
  27. package/lib/codegen/utils/merge.js +9 -9
  28. package/lib/compilerOptions.js +1 -0
  29. package/lib/languagePlugin.js +2 -0
  30. package/lib/plugins/file-md.js +26 -30
  31. package/lib/plugins/vue-root-tags.js +9 -9
  32. package/lib/plugins/vue-sfc-customblocks.js +4 -4
  33. package/lib/plugins/vue-sfc-scripts.js +8 -8
  34. package/lib/plugins/vue-sfc-styles.js +5 -5
  35. package/lib/plugins/vue-sfc-template.js +7 -7
  36. package/lib/plugins/vue-template-html.js +37 -12
  37. package/lib/plugins/vue-template-inline-css.js +6 -6
  38. package/lib/plugins/vue-template-inline-ts.js +12 -16
  39. package/lib/plugins/vue-tsx.d.ts +2 -2
  40. package/lib/plugins/vue-tsx.js +35 -35
  41. package/lib/template/compile.d.ts +2 -0
  42. package/lib/template/compile.js +31 -0
  43. package/lib/template/transforms/transformElement.d.ts +2 -0
  44. package/lib/template/transforms/transformElement.js +95 -0
  45. package/lib/template/transforms/transformText.d.ts +2 -0
  46. package/lib/template/transforms/transformText.js +35 -0
  47. package/lib/template/transforms/vFor.d.ts +1 -0
  48. package/lib/template/transforms/vFor.js +42 -0
  49. package/lib/template/transforms/vIf.d.ts +1 -0
  50. package/lib/template/transforms/vIf.js +92 -0
  51. package/lib/template/utils.d.ts +3 -0
  52. package/lib/template/utils.js +37 -0
  53. package/lib/types.d.ts +55 -48
  54. package/lib/utils/forEachTemplateNode.js +0 -3
  55. package/lib/utils/parseSfc.js +0 -1
  56. package/lib/utils/shared.d.ts +2 -2
  57. package/lib/virtualCode/embeddedCodes.d.ts +2 -2
  58. package/lib/virtualCode/embeddedCodes.js +11 -11
  59. package/lib/virtualCode/index.d.ts +4 -2
  60. package/lib/virtualCode/index.js +4 -0
  61. package/lib/virtualCode/ir.d.ts +2 -2
  62. package/lib/virtualCode/ir.js +0 -39
  63. package/package.json +9 -6
  64. package/types/template-helpers.d.ts +1 -0
  65. package/lib/virtualCode/normalize.d.ts +0 -2
  66. package/lib/virtualCode/normalize.js +0 -205
  67. package/scripts/generate-names.js +0 -41
package/lib/types.d.ts CHANGED
@@ -16,6 +16,7 @@ export type RawPlugin = string | (Record<string, any> & {
16
16
  });
17
17
  export interface VueCodeInformation extends CodeInformation {
18
18
  __importCompletion?: boolean;
19
+ __propsCompletion?: boolean;
19
20
  __shorthandExpression?: 'html' | 'js';
20
21
  __combineToken?: symbol;
21
22
  __linkedToken?: symbol;
@@ -43,6 +44,7 @@ export interface VueCompilerOptions {
43
44
  inferTemplateDollarSlots: boolean;
44
45
  skipTemplateCodegen: boolean;
45
46
  fallthroughAttributes: boolean;
47
+ checkRequiredFallthroughAttributes: boolean;
46
48
  resolveStyleImports: boolean;
47
49
  resolveStyleClassNames: boolean | 'scoped';
48
50
  fallthroughComponentNames: string[];
@@ -85,28 +87,42 @@ export interface VueLanguagePluginReturn {
85
87
  resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
86
88
  compileSFCScript?(lang: string, script: string): ts.SourceFile | undefined;
87
89
  compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
88
- compileSFCStyle?(lang: string, style: string): Pick<Sfc['styles'][number], 'imports' | 'bindings' | 'classNames'> | undefined;
90
+ compileSFCStyle?(lang: string, style: string): Pick<IRStyle, 'imports' | 'bindings' | 'classNames'> | undefined;
89
91
  updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
90
92
  start: number;
91
93
  end: number;
92
94
  newText: string;
93
95
  }): CompilerDOM.CodegenResult | undefined;
94
- getEmbeddedCodes?(fileName: string, sfc: Sfc): {
96
+ getEmbeddedCodes?(fileName: string, ir: IR): {
95
97
  id: string;
96
98
  lang: string;
97
99
  }[];
98
- resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void;
100
+ resolveEmbeddedCode?(fileName: string, ir: IR, embeddedFile: VueEmbeddedCode): void;
99
101
  }
100
102
  export type VueLanguagePlugin<T extends Record<string, any> = {}> = (ctx: {
101
103
  modules: {
102
104
  typescript: typeof ts;
103
105
  '@vue/compiler-dom': typeof CompilerDOM;
106
+ '@vue/language-core': typeof import('../index');
104
107
  };
105
108
  compilerOptions: ts.CompilerOptions;
106
109
  vueCompilerOptions: VueCompilerOptions;
107
110
  config: T;
108
111
  }) => VueLanguagePluginReturn | VueLanguagePluginReturn[];
109
- export interface SfcBlock {
112
+ export interface IR {
113
+ content: string;
114
+ comments: string[];
115
+ template: IRTemplate | undefined;
116
+ script: IRScript | undefined;
117
+ scriptSetup: IRScriptSetup | undefined;
118
+ styles: readonly IRStyle[];
119
+ customBlocks: readonly IRCustomBlock[];
120
+ }
121
+ export type IRAttr = true | {
122
+ text: string;
123
+ offset: number;
124
+ };
125
+ export interface IRBlock {
110
126
  name: string;
111
127
  start: number;
112
128
  end: number;
@@ -116,57 +132,48 @@ export interface SfcBlock {
116
132
  content: string;
117
133
  attrs: Record<string, string | true>;
118
134
  }
119
- export type SfcBlockAttr = true | {
120
- text: string;
121
- offset: number;
122
- quotes: boolean;
123
- };
124
- export interface Sfc {
125
- content: string;
126
- comments: string[];
127
- template: (SfcBlock & {
128
- ast: CompilerDOM.RootNode | undefined;
129
- errors: CompilerDOM.CompilerError[];
130
- warnings: CompilerDOM.CompilerError[];
131
- }) | undefined;
132
- script: (SfcBlock & {
133
- src: SfcBlockAttr | undefined;
134
- ast: ts.SourceFile;
135
- }) | undefined;
136
- scriptSetup: (SfcBlock & {
137
- generic: SfcBlockAttr | undefined;
138
- ast: ts.SourceFile;
139
- }) | undefined;
140
- styles: readonly (SfcBlock & {
141
- src: SfcBlockAttr | undefined;
142
- module: SfcBlockAttr | undefined;
143
- scoped: boolean;
144
- imports: {
145
- text: string;
146
- offset: number;
147
- }[];
148
- bindings: {
149
- text: string;
150
- offset: number;
151
- }[];
152
- classNames: {
153
- text: string;
154
- offset: number;
155
- }[];
156
- })[];
157
- customBlocks: readonly (SfcBlock & {
158
- type: string;
159
- })[];
135
+ export interface IRTemplate extends IRBlock {
136
+ ast: CompilerDOM.RootNode | undefined;
137
+ errors: CompilerDOM.CompilerError[];
138
+ warnings: CompilerDOM.CompilerError[];
139
+ }
140
+ export interface IRScript extends IRBlock {
141
+ src: IRAttr | undefined;
142
+ ast: ts.SourceFile;
143
+ }
144
+ export interface IRScriptSetup extends IRBlock {
145
+ generic: IRAttr | undefined;
146
+ ast: ts.SourceFile;
147
+ }
148
+ export interface IRStyle extends IRBlock {
149
+ src: IRAttr | undefined;
150
+ module: IRAttr | undefined;
151
+ scoped: boolean;
152
+ imports: {
153
+ text: string;
154
+ offset: number;
155
+ }[];
156
+ bindings: {
157
+ text: string;
158
+ offset: number;
159
+ }[];
160
+ classNames: {
161
+ text: string;
162
+ offset: number;
163
+ }[];
164
+ }
165
+ export interface IRCustomBlock extends IRBlock {
166
+ type: string;
160
167
  }
161
168
  declare module '@vue/compiler-sfc' {
162
169
  interface SFCBlock {
163
- __src?: SfcBlockAttr;
170
+ __src?: IRAttr;
164
171
  }
165
172
  interface SFCScriptBlock {
166
- __generic?: SfcBlockAttr;
173
+ __generic?: IRAttr;
167
174
  }
168
175
  interface SFCStyleBlock {
169
- __module?: SfcBlockAttr;
176
+ __module?: IRAttr;
170
177
  }
171
178
  }
172
179
  export interface TextRange<Node extends ts.Node = ts.Node> {
@@ -72,9 +72,6 @@ function* forEachInterpolationNode(node) {
72
72
  yield* forEachInterpolationNode(child);
73
73
  }
74
74
  }
75
- else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
76
- yield* forEachInterpolationNode(node.content);
77
- }
78
75
  else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
79
76
  for (const child of node.children) {
80
77
  if (typeof child === 'object') {
@@ -179,7 +179,6 @@ function parseAttr(p, node) {
179
179
  return {
180
180
  text: content,
181
181
  offset: offset - node.loc.start.offset,
182
- quotes: offset > p.value.loc.start.offset,
183
182
  };
184
183
  }
185
184
  //# sourceMappingURL=parseSfc.js.map
@@ -1,9 +1,9 @@
1
1
  import type * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type * as ts from 'typescript';
3
- import type { Sfc, TextRange } from '../types';
3
+ import type { IRTemplate, TextRange } from '../types';
4
4
  export { hyphenate as hyphenateTag } from '@vue/shared';
5
5
  export declare function hyphenateAttr(str: string): string;
6
6
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number];
7
- export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
7
+ export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: IRTemplate): [number] | [number, number];
8
8
  export declare function getStartEnd<T extends ts.Node>(ts: typeof import('typescript'), node: T, ast: ts.SourceFile): TextRange<T>;
9
9
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -1,5 +1,5 @@
1
1
  import type { Mapping, VirtualCode } from '@volar/language-core';
2
- import type { Code, Sfc, VueLanguagePluginReturn } from '../types';
2
+ import type { Code, IR, VueLanguagePluginReturn } from '../types';
3
3
  export declare class VueEmbeddedCode {
4
4
  id: string;
5
5
  lang: string;
@@ -9,4 +9,4 @@ export declare class VueEmbeddedCode {
9
9
  embeddedCodes: VueEmbeddedCode[];
10
10
  constructor(id: string, lang: string, content: Code[]);
11
11
  }
12
- export declare function useEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];
12
+ export declare function useEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, ir: IR): () => VirtualCode[];
@@ -15,22 +15,22 @@ class VueEmbeddedCode {
15
15
  }
16
16
  }
17
17
  exports.VueEmbeddedCode = VueEmbeddedCode;
18
- function useEmbeddedCodes(plugins, fileName, sfc) {
18
+ function useEmbeddedCodes(plugins, fileName, ir) {
19
19
  const getNameToBlockMap = (0, alien_signals_1.computed)(() => {
20
20
  const blocks = {};
21
- if (sfc.template) {
22
- blocks[sfc.template.name] = sfc.template;
21
+ if (ir.template) {
22
+ blocks[ir.template.name] = ir.template;
23
23
  }
24
- if (sfc.script) {
25
- blocks[sfc.script.name] = sfc.script;
24
+ if (ir.script) {
25
+ blocks[ir.script.name] = ir.script;
26
26
  }
27
- if (sfc.scriptSetup) {
28
- blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
27
+ if (ir.scriptSetup) {
28
+ blocks[ir.scriptSetup.name] = ir.scriptSetup;
29
29
  }
30
- for (const block of sfc.styles) {
30
+ for (const block of ir.styles) {
31
31
  blocks[block.name] = block;
32
32
  }
33
- for (const block of sfc.customBlocks) {
33
+ for (const block of ir.customBlocks) {
34
34
  blocks[block.name] = block;
35
35
  }
36
36
  return blocks;
@@ -75,7 +75,7 @@ function useEmbeddedCodes(plugins, fileName, sfc) {
75
75
  if (!plugin.getEmbeddedCodes) {
76
76
  return new Map();
77
77
  }
78
- const newCodeList = plugin.getEmbeddedCodes(fileName, sfc);
78
+ const newCodeList = plugin.getEmbeddedCodes(fileName, ir);
79
79
  const map = new Map();
80
80
  for (const { id, lang } of newCodeList) {
81
81
  const key = id + '__' + lang;
@@ -110,7 +110,7 @@ function useEmbeddedCodes(plugins, fileName, sfc) {
110
110
  continue;
111
111
  }
112
112
  try {
113
- plugin.resolveEmbeddedCode(fileName, sfc, code);
113
+ plugin.resolveEmbeddedCode(fileName, ir, code);
114
114
  }
115
115
  catch (e) {
116
116
  console.error(e);
@@ -1,7 +1,7 @@
1
1
  import type { CodeMapping, VirtualCode } from '@volar/language-core';
2
2
  import type { SFCParseResult } from '@vue/compiler-sfc';
3
3
  import type * as ts from 'typescript';
4
- import type { Sfc, VueCompilerOptions, VueLanguagePluginReturn } from '../types';
4
+ import type { IR, VueCompilerOptions, VueLanguagePluginReturn } from '../types';
5
5
  export declare class VueVirtualCode implements VirtualCode {
6
6
  fileName: string;
7
7
  languageId: string;
@@ -15,7 +15,9 @@ export declare class VueVirtualCode implements VirtualCode {
15
15
  private _mappings;
16
16
  get snapshot(): ts.IScriptSnapshot;
17
17
  get vueSfc(): SFCParseResult | undefined;
18
- get sfc(): Sfc;
18
+ get ir(): IR;
19
+ /** @deprecated use `ir` instead */
20
+ get sfc(): IR;
19
21
  get embeddedCodes(): VirtualCode[];
20
22
  get mappings(): CodeMapping[];
21
23
  constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: VueLanguagePluginReturn[], ts: typeof import('typescript'));
@@ -12,6 +12,10 @@ class VueVirtualCode {
12
12
  get vueSfc() {
13
13
  return this._parsedSfcResult()?.result;
14
14
  }
15
+ get ir() {
16
+ return this._ir;
17
+ }
18
+ /** @deprecated use `ir` instead */
15
19
  get sfc() {
16
20
  return this._ir;
17
21
  }
@@ -1,4 +1,4 @@
1
1
  import type { SFCParseResult } from '@vue/compiler-sfc';
2
2
  import type * as ts from 'typescript';
3
- import type { Sfc, VueLanguagePluginReturn } from '../types';
4
- export declare function useIR(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseSfcResult: () => SFCParseResult | undefined): Sfc;
3
+ import type { IR, VueLanguagePluginReturn } from '../types';
4
+ export declare function useIR(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseSfcResult: () => SFCParseResult | undefined): IR;
@@ -1,43 +1,8 @@
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
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.useIR = useIR;
37
- const CompilerDOM = __importStar(require("@vue/compiler-dom"));
38
4
  const alien_signals_1 = require("alien-signals");
39
5
  const signals_1 = require("../utils/signals");
40
- const normalize_1 = require("./normalize");
41
6
  function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
42
7
  const getUntrackedSnapshot = () => {
43
8
  const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
@@ -229,13 +194,10 @@ function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
229
194
  }
230
195
  const errors = [];
231
196
  const warnings = [];
232
- const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset();
233
197
  let options = {
234
198
  onError: err => errors.push(err),
235
199
  onWarn: err => warnings.push(err),
236
200
  expressionPlugins: ['typescript'],
237
- nodeTransforms,
238
- directiveTransforms,
239
201
  };
240
202
  for (const plugin of plugins) {
241
203
  if (plugin.resolveTemplateCompilerOptions) {
@@ -246,7 +208,6 @@ function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
246
208
  try {
247
209
  const result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
248
210
  if (result) {
249
- (0, normalize_1.normalizeTemplateAST)(result.ast);
250
211
  return {
251
212
  snapshot: getUntrackedSnapshot(),
252
213
  template: base.content,
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.2.8",
3
+ "version": "3.3.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
- "**/*.js",
7
- "**/*.d.ts"
6
+ "index.d.ts",
7
+ "index.js",
8
+ "lib/**/*.d.ts",
9
+ "lib/**/*.js",
10
+ "types"
8
11
  ],
9
12
  "sideEffects": false,
10
13
  "repository": {
@@ -19,17 +22,17 @@
19
22
  "@volar/language-core": "2.4.28",
20
23
  "@vue/compiler-dom": "^3.5.0",
21
24
  "@vue/shared": "^3.5.0",
22
- "alien-signals": "^3.1.2",
25
+ "alien-signals": "^3.2.0",
23
26
  "muggle-string": "^0.4.1",
24
27
  "path-browserify": "^1.0.1",
25
28
  "picomatch": "^4.0.4"
26
29
  },
27
30
  "devDependencies": {
28
- "@types/node": "^22.10.4",
31
+ "@types/node": "^24.1.0",
29
32
  "@types/path-browserify": "^1.0.3",
30
33
  "@types/picomatch": "^4.0.3",
31
34
  "@volar/typescript": "2.4.28",
32
35
  "@vue/compiler-sfc": "^3.5.0"
33
36
  },
34
- "gitHead": "618bd6bfb19729726787df7b52fccda72c888c95"
37
+ "gitHead": "1088dce8ae6b937f7525fae4982e3b3ea99d3c64"
35
38
  }
@@ -143,6 +143,7 @@ declare global {
143
143
  function __VLS_asFunctionalElement0<T>(tag: T, endTag?: T): (attrs: T) => void;
144
144
  function __VLS_asFunctionalElement1<T>(tag: T, endTag?: T): (attrs: T & Record<string, unknown>) => void;
145
145
  function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
146
+ function __VLS_omit<T, K>(target: T, props: K): Omit<T, keyof K>;
146
147
  function __VLS_tryAsConstant<const T>(t: T): T;
147
148
  }
148
149
 
@@ -1,2 +0,0 @@
1
- import * as CompilerDOM from '@vue/compiler-dom';
2
- export declare function normalizeTemplateAST(root: CompilerDOM.RootNode): void;
@@ -1,205 +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 __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
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.normalizeTemplateAST = normalizeTemplateAST;
37
- const CompilerDOM = __importStar(require("@vue/compiler-dom"));
38
- const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
39
- // See https://github.com/vuejs/core/issues/3498
40
- function normalizeTemplateAST(root) {
41
- // @ts-ignore
42
- const transformContext = {
43
- onError: () => { },
44
- helperString: str => str.toString(),
45
- replaceNode: () => { },
46
- cacheHandlers: false,
47
- prefixIdentifiers: false,
48
- scopes: {
49
- vFor: 0,
50
- vOnce: 0,
51
- vPre: 0,
52
- vSlot: 0,
53
- },
54
- expressionPlugins: ['typescript'],
55
- };
56
- for (const { children, codegenNode, props } of (0, forEachTemplateNode_1.forEachElementNode)(root)) {
57
- for (let i = 0; i < children.length; i++) {
58
- const child = children[i];
59
- if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
60
- continue;
61
- }
62
- const forNode = getVForNode(child, transformContext);
63
- if (forNode) {
64
- children[i] = forNode;
65
- continue;
66
- }
67
- const ifNode = getVIfNode(child, transformContext);
68
- if (ifNode) {
69
- const normalized = normalizeIfBranch(ifNode, children, i);
70
- children.splice(i, normalized.end - i + 1, normalized.node);
71
- continue;
72
- }
73
- }
74
- // #4539
75
- if (codegenNode
76
- && 'props' in codegenNode
77
- && codegenNode.props
78
- && 'properties' in codegenNode.props) {
79
- for (const p of codegenNode.props.properties) {
80
- if (p.key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
81
- && p.key.content === 'key'
82
- && !p.key.isHandlerKey
83
- && !p.key.loc.source
84
- && p.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
85
- && p.value.constType === CompilerDOM.ConstantTypes.NOT_CONSTANT) {
86
- const contentBeforeValue = root.loc.source.slice(0, p.value.loc.start.offset);
87
- const argOffset = contentBeforeValue.lastIndexOf('key');
88
- props.push({
89
- type: CompilerDOM.NodeTypes.DIRECTIVE,
90
- name: 'bind',
91
- exp: p.value,
92
- loc: p.loc,
93
- arg: {
94
- ...p.key,
95
- loc: {
96
- start: { line: -1, column: -1, offset: argOffset },
97
- end: { line: -1, column: -1, offset: argOffset + 'key'.length },
98
- source: 'key',
99
- },
100
- },
101
- modifiers: [],
102
- });
103
- break;
104
- }
105
- }
106
- }
107
- }
108
- }
109
- function normalizeIfBranch(ifNode, children, start) {
110
- let end = start;
111
- let comments = [];
112
- for (let i = start + 1; i < children.length; i++) {
113
- const sibling = children[i];
114
- if (sibling.type === CompilerDOM.NodeTypes.COMMENT) {
115
- comments.push(sibling);
116
- continue;
117
- }
118
- if (sibling.type === CompilerDOM.NodeTypes.TEXT && !sibling.content.trim()) {
119
- continue;
120
- }
121
- const elseBranch = getVElseDirective(sibling);
122
- if (elseBranch) {
123
- const branchNode = {
124
- ...elseBranch.element,
125
- props: elseBranch.element.props.filter(prop => prop !== elseBranch.directive),
126
- };
127
- const branch = createIfBranch(branchNode, elseBranch.directive);
128
- if (comments.length) {
129
- branch.children = [...comments, ...branch.children];
130
- }
131
- ifNode.branches.push(branch);
132
- comments = [];
133
- end = i;
134
- continue;
135
- }
136
- break;
137
- }
138
- return { node: ifNode, end };
139
- }
140
- // source: https://github.com/vuejs/core/blob/25ebe3a42cd80ac0256355c2740a0258cdd7419d/packages/compiler-core/src/transforms/vIf.ts#L207
141
- function createIfBranch(node, dir) {
142
- const isTemplateIf = node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
143
- return {
144
- type: CompilerDOM.NodeTypes.IF_BRANCH,
145
- loc: node.loc,
146
- condition: dir.name === 'else' ? undefined : dir.exp,
147
- children: isTemplateIf && !CompilerDOM.findDir(node, 'for') && !CompilerDOM.findDir(node, 'slot')
148
- ? node.children
149
- : [node],
150
- userKey: CompilerDOM.findProp(node, 'key'),
151
- isTemplateIf,
152
- };
153
- }
154
- function getVElseDirective(node) {
155
- if (node.type !== CompilerDOM.NodeTypes.ELEMENT) {
156
- return;
157
- }
158
- const directive = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
159
- && (prop.name === 'else-if' || prop.name === 'else'));
160
- if (directive) {
161
- return {
162
- element: node,
163
- directive,
164
- };
165
- }
166
- }
167
- function getVForNode(node, transformContext) {
168
- const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
169
- && prop.name === 'for');
170
- if (forDirective) {
171
- let forNode;
172
- CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
173
- forNode = { ..._forNode };
174
- return undefined;
175
- });
176
- if (forNode) {
177
- forNode.children = [{
178
- ...node,
179
- props: node.props.filter(prop => prop !== forDirective),
180
- }];
181
- return forNode;
182
- }
183
- }
184
- }
185
- function getVIfNode(node, transformContext) {
186
- const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
187
- && prop.name === 'if');
188
- if (ifDirective) {
189
- let ifNode;
190
- CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
191
- ifNode = { ..._ifNode };
192
- return undefined;
193
- });
194
- if (ifNode) {
195
- for (const branch of ifNode.branches) {
196
- branch.children = [{
197
- ...node,
198
- props: node.props.filter(prop => prop !== ifDirective),
199
- }];
200
- }
201
- return ifNode;
202
- }
203
- }
204
- }
205
- //# sourceMappingURL=normalize.js.map
@@ -1,41 +0,0 @@
1
- // @ts-check
2
- const { readFile, writeFile } = require('node:fs/promises');
3
- const { join } = require('node:path');
4
-
5
- generateNames();
6
-
7
- async function generateNames() {
8
- const typePath = join(__dirname, '../types/template-helpers.d.ts');
9
- const typeText = await readFile(typePath, 'utf-8');
10
-
11
- /** @type {Set<string>} */
12
- const pascalNames = new Set();
13
- /** @type {Set<string>} */
14
- const camelNames = new Set();
15
-
16
- const declReg = /(?<=const\s+)\w*?(?=:)|(?<=type\s+)\w*?(?=\s*=|<)|(?<=function\s+)\w*?(?=\(|<)/g;
17
- const prefix = '__VLS_';
18
-
19
- for (const match of typeText.matchAll(declReg)) {
20
- const name = match[0].slice(prefix.length);
21
- if (name[0]?.toUpperCase() === name[0]) {
22
- pascalNames.add(name);
23
- }
24
- else {
25
- camelNames.add(name);
26
- }
27
- }
28
-
29
- const namesPath = join(__dirname, '../lib/codegen/names.ts');
30
- const namesText = await readFile(namesPath, 'utf-8');
31
-
32
- await writeFile(
33
- namesPath,
34
- namesText.replace(
35
- /(?<=\/\/ #region .*\n).*?(?=\t\/\/ #endregion)/ms,
36
- [...camelNames].sort().map(name => `\t${name}: '',\n`).join('')
37
- + '\n'
38
- + [...pascalNames].sort().map(name => `\t${name}: '',\n`).join(''),
39
- ),
40
- );
41
- }