@vue/language-core 3.3.4 → 3.3.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 (66) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/codegen/codeFeatures.d.ts +24 -84
  4. package/lib/codegen/codeFeatures.js +46 -4
  5. package/lib/codegen/names.d.ts +4 -5
  6. package/lib/codegen/names.js +4 -5
  7. package/lib/codegen/script/index.js +5 -5
  8. package/lib/codegen/script/scriptSetup.js +4 -4
  9. package/lib/codegen/style/common.js +7 -11
  10. package/lib/codegen/style/index.d.ts +55 -27
  11. package/lib/codegen/style/index.js +3 -3
  12. package/lib/codegen/template/context.d.ts +55 -124
  13. package/lib/codegen/template/context.js +187 -269
  14. package/lib/codegen/template/element.js +16 -15
  15. package/lib/codegen/template/elementDirectives.js +11 -11
  16. package/lib/codegen/template/elementEvents.js +76 -73
  17. package/lib/codegen/template/elementProps.js +12 -12
  18. package/lib/codegen/template/index.d.ts +55 -27
  19. package/lib/codegen/template/index.js +7 -7
  20. package/lib/codegen/template/interpolation.js +28 -28
  21. package/lib/codegen/template/objectProperty.js +5 -5
  22. package/lib/codegen/template/propertyAccess.js +1 -1
  23. package/lib/codegen/template/slotOutlet.js +8 -10
  24. package/lib/codegen/template/styleScopedClasses.js +4 -4
  25. package/lib/codegen/template/vFor.js +3 -3
  26. package/lib/codegen/template/vIf.js +4 -4
  27. package/lib/codegen/template/vSlot.js +9 -9
  28. package/lib/codegen/utils/boundary.d.ts +7 -2
  29. package/lib/codegen/utils/boundary.js +15 -9
  30. package/lib/codegen/utils/camelized.js +5 -13
  31. package/lib/codegen/utils/escaped.js +4 -9
  32. package/lib/codegen/utils/index.d.ts +1 -1
  33. package/lib/codegen/utils/index.js +3 -3
  34. package/lib/codegen/utils/stringLiteralKey.js +3 -3
  35. package/lib/codegen/utils/unicode.d.ts +1 -1
  36. package/lib/codegen/utils/unicode.js +4 -4
  37. package/lib/languagePlugin.js +2 -1
  38. package/lib/parsers/scriptRanges.d.ts +2 -2
  39. package/lib/parsers/scriptRanges.js +3 -10
  40. package/lib/parsers/scriptSetupRanges.d.ts +2 -2
  41. package/lib/parsers/scriptSetupRanges.js +3 -10
  42. package/lib/parsers/utils.d.ts +1 -0
  43. package/lib/parsers/utils.js +10 -0
  44. package/lib/parsers/vueCompilerOptions.js +2 -2
  45. package/lib/plugins/file-html.js +4 -4
  46. package/lib/plugins/file-md.js +15 -15
  47. package/lib/plugins/file-vue.js +2 -2
  48. package/lib/plugins/vue-root-tags.js +3 -3
  49. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  50. package/lib/plugins/vue-sfc-scripts.js +2 -4
  51. package/lib/plugins/vue-sfc-styles.js +3 -3
  52. package/lib/plugins/vue-sfc-template.js +2 -2
  53. package/lib/plugins/vue-style-css.js +86 -33
  54. package/lib/plugins/vue-template-html.js +3 -3
  55. package/lib/plugins/vue-template-inline-css.js +2 -7
  56. package/lib/plugins/vue-template-inline-ts.js +4 -5
  57. package/lib/plugins/vue-tsx.d.ts +61 -31
  58. package/lib/plugins/vue-tsx.js +26 -23
  59. package/lib/plugins.d.ts +0 -1
  60. package/lib/plugins.js +0 -15
  61. package/lib/utils/forEachTemplateNode.js +36 -43
  62. package/lib/virtualCode/index.js +2 -2
  63. package/package.json +2 -2
  64. package/types/template-helpers.d.ts +15 -25
  65. package/lib/plugins/shared.d.ts +0 -2
  66. package/lib/plugins/shared.js +0 -12
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const muggle_string_1 = require("muggle-string");
4
- const shared_1 = require("./shared");
4
+ const codeFeatures_1 = require("../codegen/codeFeatures");
5
5
  const plugin = () => {
6
6
  return {
7
7
  version: 2.2,
@@ -13,7 +13,7 @@ const plugin = () => {
13
13
  },
14
14
  resolveEmbeddedCode(_fileName, ir, embeddedFile) {
15
15
  if (embeddedFile.id === 'root_tags') {
16
- embeddedFile.content.push([ir.content, undefined, 0, shared_1.allCodeFeatures]);
16
+ embeddedFile.content.push([ir.content, undefined, 0, codeFeatures_1.codeFeatures.full]);
17
17
  for (const block of [
18
18
  ir.template,
19
19
  ir.script,
@@ -30,7 +30,7 @@ const plugin = () => {
30
30
  '',
31
31
  undefined,
32
32
  block.startTagEnd + offset,
33
- { structure: true },
33
+ codeFeatures_1.codeFeatures.structure,
34
34
  ], ir.content.slice(block.startTagEnd + offset, block.endTagStart));
35
35
  }
36
36
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const shared_1 = require("./shared");
3
+ const codeFeatures_1 = require("../codegen/codeFeatures");
4
4
  const plugin = () => {
5
5
  return {
6
6
  version: 2.2,
@@ -18,7 +18,7 @@ const plugin = () => {
18
18
  customBlock.content,
19
19
  customBlock.name,
20
20
  0,
21
- shared_1.allCodeFeatures,
21
+ codeFeatures_1.codeFeatures.full,
22
22
  ]);
23
23
  }
24
24
  },
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const codeFeatures_1 = require("../codegen/codeFeatures");
3
4
  const plugin = () => {
4
5
  return {
5
6
  version: 2.2,
@@ -24,10 +25,7 @@ const plugin = () => {
24
25
  script.content,
25
26
  script.name,
26
27
  0,
27
- {
28
- structure: true,
29
- format: true,
30
- },
28
+ codeFeatures_1.codeFeatures.structureAndFormat,
31
29
  ]);
32
30
  }
33
31
  },
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const shared_1 = require("./shared");
3
+ const codeFeatures_1 = require("../codegen/codeFeatures");
4
4
  const plugin = () => {
5
5
  return {
6
6
  version: 2.2,
@@ -34,7 +34,7 @@ const plugin = () => {
34
34
  binding.text,
35
35
  style.name,
36
36
  binding.offset,
37
- shared_1.allCodeFeatures,
37
+ codeFeatures_1.codeFeatures.full,
38
38
  ], ');\n');
39
39
  }
40
40
  }
@@ -43,7 +43,7 @@ const plugin = () => {
43
43
  style.content,
44
44
  style.name,
45
45
  0,
46
- shared_1.allCodeFeatures,
46
+ codeFeatures_1.codeFeatures.full,
47
47
  ]);
48
48
  }
49
49
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const shared_1 = require("./shared");
3
+ const codeFeatures_1 = require("../codegen/codeFeatures");
4
4
  const plugin = () => {
5
5
  return {
6
6
  version: 2.2,
@@ -19,7 +19,7 @@ const plugin = () => {
19
19
  ir.template.content,
20
20
  ir.template.name,
21
21
  0,
22
- shared_1.allCodeFeatures,
22
+ codeFeatures_1.codeFeatures.full,
23
23
  ]);
24
24
  }
25
25
  },
@@ -13,50 +13,103 @@ const plugin = () => {
13
13
  };
14
14
  };
15
15
  exports.default = plugin;
16
- const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
17
- const cssBindingReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
18
- const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
19
- const commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
20
- const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
16
+ const cssImportRE = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
17
+ const cssBindingRE = /\bv-bind\s*\(/g;
18
+ const cssClassNameRE = /\.[a-z_][-\w]*(?=[\s.,+~>:#)[{])/gi;
19
+ const commentRE = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
20
+ const fragmentRE = /(?<={)[^{]*(?=(?<!\\);)/g;
21
21
  function* parseCssImports(css) {
22
- const matches = css.matchAll(cssImportReg);
23
- for (const match of matches) {
24
- let text = match[0];
25
- let offset = match.index;
26
- if (text.startsWith("'") || text.startsWith('"')) {
27
- text = text.slice(1, -1);
28
- offset += 1;
29
- }
30
- if (text) {
31
- yield { text, offset };
32
- }
22
+ for (const match of css.matchAll(cssImportRE)) {
23
+ yield trimQuotes(match[0], match.index);
33
24
  }
34
25
  }
35
26
  function* parseCssBindings(css) {
36
- css = fillBlank(css, commentReg);
37
- const matchs = css.matchAll(cssBindingReg);
38
- for (const match of matchs) {
39
- const matchText = match.slice(1).find(t => t);
40
- if (matchText) {
41
- const offset = match.index + css.slice(match.index).indexOf(matchText);
42
- yield { offset, text: matchText };
27
+ css = fillBlank(css, commentRE);
28
+ for (const match of css.matchAll(cssBindingRE)) {
29
+ const start = match.index + match[0].length;
30
+ const end = lexBinding(css, start);
31
+ if (end !== null) {
32
+ yield trimQuotes(css.slice(start, end), start, false);
43
33
  }
44
34
  }
45
35
  }
46
- function* parseCssClassNames(css) {
47
- css = fillBlank(css, commentReg, fragmentReg);
48
- const matches = css.matchAll(cssClassNameReg);
49
- for (const match of matches) {
50
- const matchText = match[1];
51
- if (matchText) {
52
- yield { offset: match.index, text: matchText };
36
+ var LexerState;
37
+ (function (LexerState) {
38
+ LexerState[LexerState["inParens"] = 0] = "inParens";
39
+ LexerState[LexerState["inSingleQuoteString"] = 1] = "inSingleQuoteString";
40
+ LexerState[LexerState["inDoubleQuoteString"] = 2] = "inDoubleQuoteString";
41
+ })(LexerState || (LexerState = {}));
42
+ // https://github.com/vuejs/core/blob/c0606e91798c8dca4f33d101e1dd836d672592c1/packages/compiler-sfc/src/style/cssVars.ts#L93
43
+ function lexBinding(content, start) {
44
+ let state = LexerState.inParens;
45
+ let parenDepth = 0;
46
+ for (let i = start; i < content.length; i++) {
47
+ const char = content.charAt(i);
48
+ switch (state) {
49
+ case LexerState.inParens:
50
+ if (char === `'`) {
51
+ state = LexerState.inSingleQuoteString;
52
+ }
53
+ else if (char === `"`) {
54
+ state = LexerState.inDoubleQuoteString;
55
+ }
56
+ else if (char === `(`) {
57
+ parenDepth++;
58
+ }
59
+ else if (char === `)`) {
60
+ if (parenDepth > 0) {
61
+ parenDepth--;
62
+ }
63
+ else {
64
+ return i;
65
+ }
66
+ }
67
+ break;
68
+ case LexerState.inSingleQuoteString:
69
+ if (char === `'`) {
70
+ state = LexerState.inParens;
71
+ }
72
+ break;
73
+ case LexerState.inDoubleQuoteString:
74
+ if (char === `"`) {
75
+ state = LexerState.inParens;
76
+ }
77
+ break;
53
78
  }
54
79
  }
80
+ return null;
55
81
  }
56
- function fillBlank(css, ...regs) {
57
- for (const reg of regs) {
58
- css = css.replace(reg, match => ' '.repeat(match.length));
82
+ function* parseCssClassNames(css) {
83
+ css = fillBlank(css, commentRE, fragmentRE);
84
+ for (const match of css.matchAll(cssClassNameRE)) {
85
+ yield { text: match[0], offset: match.index };
86
+ }
87
+ }
88
+ function fillBlank(css, ...patterns) {
89
+ for (const pattern of patterns) {
90
+ css = css.replace(pattern, match => ' '.repeat(match.length));
59
91
  }
60
92
  return css;
61
93
  }
94
+ function trimQuotes(text, offset, trim = true) {
95
+ let start = 0;
96
+ let end = text.length;
97
+ if (trim || text.includes('"') || text.includes("'")) {
98
+ while (start < text.length && !text[start]?.trim()) {
99
+ start++;
100
+ }
101
+ while (end >= 0 && !text[end - 1]?.trim()) {
102
+ end--;
103
+ }
104
+ }
105
+ if (text[start] === '"' && text[end - 1] === '"'
106
+ || text[start] === "'" && text[end - 1] === "'") {
107
+ start++;
108
+ end--;
109
+ }
110
+ return {
111
+ text: text.slice(start, end),
112
+ offset: offset + start,
113
+ };
114
+ }
62
115
  //# sourceMappingURL=vue-style-css.js.map
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
37
37
  const compile_1 = require("../template/compile");
38
- const shouldAddSuffix = /(?<=<[^>/]+)$/;
38
+ const shouldAddSuffixRE = /(?<=<[^>/]+)$/;
39
39
  const plugin = () => {
40
40
  return {
41
41
  version: 2.2,
@@ -43,7 +43,7 @@ const plugin = () => {
43
43
  if (lang === 'html' || lang === 'md') {
44
44
  let addedSuffix = false;
45
45
  // #4583
46
- if (shouldAddSuffix.test(template)) {
46
+ if (shouldAddSuffixRE.test(template)) {
47
47
  template += '>';
48
48
  addedSuffix = true;
49
49
  }
@@ -63,7 +63,7 @@ const plugin = () => {
63
63
  // @ts-expect-error
64
64
  if (oldResult.__addedSuffix) {
65
65
  const originalTemplate = newSource.slice(0, -1); // remove added '>'
66
- if (!shouldAddSuffix.test(originalTemplate)) {
66
+ if (!shouldAddSuffixRE.test(originalTemplate)) {
67
67
  return undefined;
68
68
  }
69
69
  }
@@ -34,14 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
37
+ const codeFeatures_1 = require("../codegen/codeFeatures");
37
38
  const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
38
39
  const shared_1 = require("../utils/shared");
39
- const shared_2 = require("./shared");
40
- const codeFeatures = {
41
- ...shared_2.allCodeFeatures,
42
- format: false,
43
- structure: false,
44
- };
45
40
  const plugin = () => {
46
41
  return {
47
42
  version: 2.2,
@@ -69,7 +64,7 @@ function* generate(templateAst) {
69
64
  && prop.value) {
70
65
  yield `x { `;
71
66
  const [content, offset] = (0, shared_1.normalizeAttributeValue)(prop.value);
72
- yield [content, 'template', offset, codeFeatures];
67
+ yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
73
68
  yield ` }\n`;
74
69
  }
75
70
  }
@@ -34,13 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
37
+ const codeFeatures_1 = require("../codegen/codeFeatures");
37
38
  const elementEvents_1 = require("../codegen/template/elementEvents");
38
39
  const templateChild_1 = require("../codegen/template/templateChild");
39
40
  const vFor_1 = require("../codegen/template/vFor");
40
41
  const utils_1 = require("../codegen/utils");
41
- const codeFeatures = {
42
- format: true,
43
- };
44
42
  const formatBrackets = {
45
43
  normal: ['`${', '}`;'],
46
44
  if: ['if (', ') { }'],
@@ -53,6 +51,7 @@ const formatBrackets = {
53
51
  event: ['() => ', ';'],
54
52
  generic: ['<', '>() => {};'],
55
53
  };
54
+ const genericCommentRE = /^<!--\s*@vue-generic\s*\{(?<content>[\s\S]*)\}\s*-->$/;
56
55
  const plugin = ({ modules: { typescript: ts } }) => {
57
56
  const parseds = new WeakMap();
58
57
  return {
@@ -96,7 +95,7 @@ const plugin = ({ modules: { typescript: ts } }) => {
96
95
  return result;
97
96
  function visit(node) {
98
97
  if (node.type === CompilerDOM.NodeTypes.COMMENT) {
99
- const match = node.loc.source.match(/^<!--\s*@vue-generic\s*\{(?<content>[\s\S]*)\}\s*-->$/);
98
+ const match = node.loc.source.match(genericCommentRE);
100
99
  if (match) {
101
100
  const { content } = match.groups;
102
101
  addFormatCodes(content, node.loc.start.offset + node.loc.source.indexOf('{') + 1, formatBrackets.generic);
@@ -221,7 +220,7 @@ const plugin = ({ modules: { typescript: ts } }) => {
221
220
  code,
222
221
  'template',
223
222
  offset,
224
- codeFeatures,
223
+ codeFeatures_1.codeFeatures.format,
225
224
  ],
226
225
  wrapper[1],
227
226
  ]);
@@ -1,6 +1,9 @@
1
1
  import type { IR, VueLanguagePlugin } from '../types';
2
+ export declare const serviceScriptRE: RegExp;
2
3
  export declare const tsCodegen: WeakMap<IR, {
3
4
  getScriptRanges: () => {
5
+ bindings: import("../types").TextRange<import("typescript").Node>[];
6
+ components: import("../types").TextRange<import("typescript").Node>[];
4
7
  exportDefault: (import("../types").TextRange<import("typescript").Node> & {
5
8
  expression: import("../types").TextRange<import("typescript").Expression>;
6
9
  isObjectLiteral: boolean;
@@ -14,14 +17,12 @@ export declare const tsCodegen: WeakMap<IR, {
14
17
  inheritAttrs: string | undefined;
15
18
  };
16
19
  }) | undefined;
17
- bindings: import("../types").TextRange<import("typescript").Node>[];
18
- components: import("../types").TextRange<import("typescript").Node>[];
19
20
  } | undefined;
20
21
  getScriptSetupRanges: () => {
21
- leadingCommentEndOffset: number;
22
- importSectionEndOffset: number;
23
22
  bindings: import("../types").TextRange<import("typescript").Node>[];
24
23
  components: import("../types").TextRange<import("typescript").Node>[];
24
+ leadingCommentEndOffset: number;
25
+ importSectionEndOffset: number;
25
26
  defineModel: import("../parsers/scriptSetupRanges").DefineModel[];
26
27
  defineProps: import("../parsers/scriptSetupRanges").DefineProps | undefined;
27
28
  withDefaults: import("../parsers/scriptSetupRanges").CallExpressionRange | undefined;
@@ -49,8 +50,7 @@ export declare const tsCodegen: WeakMap<IR, {
49
50
  codes: import("../types").Code[];
50
51
  };
51
52
  getGeneratedTemplate: () => {
52
- generatedTypes: Set<string>;
53
- currentInfo: {
53
+ getCommentInfo: () => {
54
54
  ignoreError?: boolean;
55
55
  expectError?: {
56
56
  token: number;
@@ -61,45 +61,75 @@ export declare const tsCodegen: WeakMap<IR, {
61
61
  offset: number;
62
62
  };
63
63
  };
64
+ enter: (node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode) => boolean;
65
+ exit: () => Generator<import("../types").Code>;
64
66
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
65
- inVFor: boolean;
67
+ getInternalVariable: () => string;
68
+ scopes: {
69
+ add(value: string): /*elided*/ any;
70
+ declare(...variables: string[]): void;
71
+ end(): Generator<import("../types").Code, any, any>;
72
+ clear(): void;
73
+ delete(value: string): boolean;
74
+ forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
75
+ has(value: string): boolean;
76
+ readonly size: number;
77
+ [Symbol.iterator](): SetIterator<string>;
78
+ entries(): SetIterator<[string, string]>;
79
+ keys(): SetIterator<string>;
80
+ values(): SetIterator<string>;
81
+ readonly [Symbol.toStringTag]: string;
82
+ }[];
83
+ scope: () => {
84
+ add(value: string): any;
85
+ declare(...variables: string[]): void;
86
+ end(): Generator<import("../types").Code, any, any>;
87
+ clear(): void;
88
+ delete(value: string): boolean;
89
+ forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
90
+ has(value: string): boolean;
91
+ readonly size: number;
92
+ [Symbol.iterator](): SetIterator<string>;
93
+ entries(): SetIterator<[string, string]>;
94
+ keys(): SetIterator<string>;
95
+ values(): SetIterator<string>;
96
+ readonly [Symbol.toStringTag]: string;
97
+ };
98
+ contextAccesses: Map<string, Map<string, Set<number>>>;
99
+ accessVariable: (source: string, name: string, offset?: number) => void;
100
+ generateAutoImport: () => Generator<import("../types").Code>;
101
+ conditions: string[];
102
+ generateConditionGuards: () => Generator<string, void, unknown>;
103
+ hoistVars: Map<string, string>;
104
+ getHoistVariable: (originalVar: string) => string;
105
+ generateHoistVariables: () => Generator<string, void, unknown>;
106
+ templateRefs: Map<string, {
107
+ typeExp: string;
108
+ offset: number;
109
+ }[]>;
110
+ addTemplateRef: (name: string, typeExp: string, offset: number) => void;
111
+ components: (() => string)[];
112
+ dollarVars: Set<string>;
113
+ inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
114
+ generatedTypes: Set<string>;
115
+ inheritedAttrVars: Set<string>;
116
+ singleRootElTypes: Set<string>;
117
+ singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
66
118
  slots: {
67
119
  name: string;
68
120
  offset?: number;
69
121
  tagRange: [number, number];
70
- nodeLoc: any;
71
122
  propsVar: string;
72
123
  }[];
73
124
  dynamicSlots: {
74
125
  expVar: string;
75
126
  propsVar: string;
76
127
  }[];
77
- dollarVars: Set<string>;
78
- componentAccessMap: Map<string, Map<string, Set<number>>>;
79
- blockConditions: string[];
80
- inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
81
- inheritedAttrVars: Set<string>;
82
- templateRefs: Map<string, {
83
- typeExp: string;
84
- offset: number;
85
- }[]>;
86
- singleRootElTypes: Set<string>;
87
- singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
88
- addTemplateRef(name: string, typeExp: string, offset: number): void;
89
- recordComponentAccess(source: string, name: string, offset?: number): void;
90
- scopes: Set<string>[];
91
- components: (() => string)[];
92
- declare(...varNames: string[]): void;
93
- startScope(): () => Generator<import("../types").Code, any, any>;
94
- getInternalVariable(): string;
95
- getHoistVariable(originalVar: string): string;
96
- generateHoistVariables(): Generator<string, void, unknown>;
97
- generateConditionGuards(): Generator<string, void, unknown>;
98
- enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
99
- exit(): Generator<import("../types").Code>;
128
+ inVFor: boolean;
100
129
  codes: import("../types").Code[];
101
130
  } | undefined;
102
131
  getImportedComponents: () => Set<string>;
132
+ getSetupBindings: () => Set<string>;
103
133
  getSetupExposed: () => Set<string>;
104
134
  }>;
105
135
  declare const plugin: VueLanguagePlugin;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.tsCodegen = void 0;
36
+ exports.tsCodegen = exports.serviceScriptRE = void 0;
37
37
  const shared_1 = require("@vue/shared");
38
38
  const alien_signals_1 = require("alien-signals");
39
39
  const path = __importStar(require("path-browserify"));
@@ -45,6 +45,7 @@ const scriptRanges_1 = require("../parsers/scriptRanges");
45
45
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
46
46
  const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
47
47
  const signals_1 = require("../utils/signals");
48
+ exports.serviceScriptRE = /^script_(?:js|jsx|ts|tsx)$/;
48
49
  exports.tsCodegen = new WeakMap();
49
50
  const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
50
51
  const plugin = ({ modules: { typescript: ts }, vueCompilerOptions, }) => {
@@ -55,7 +56,7 @@ const plugin = ({ modules: { typescript: ts }, vueCompilerOptions, }) => {
55
56
  return [{ lang, id: 'script_' + lang }];
56
57
  },
57
58
  resolveEmbeddedCode(fileName, ir, embeddedFile) {
58
- if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
59
+ if (exports.serviceScriptRE.test(embeddedFile.id)) {
59
60
  let codegen = exports.tsCodegen.get(ir);
60
61
  if (!codegen) {
61
62
  exports.tsCodegen.set(ir, codegen = useCodegen(ts, vueCompilerOptions, fileName, ir));
@@ -114,6 +115,22 @@ function useCodegen(ts, vueCompilerOptions, fileName, ir) {
114
115
  }
115
116
  return names;
116
117
  });
118
+ const getSetupBindings = (0, signals_1.computedSet)(() => {
119
+ const names = new Set();
120
+ const scriptSetupRanges = getScriptSetupRanges();
121
+ if (ir.scriptSetup && scriptSetupRanges) {
122
+ for (const range of scriptSetupRanges.bindings) {
123
+ names.add(ir.scriptSetup.content.slice(range.start, range.end));
124
+ }
125
+ const scriptRanges = getScriptRanges();
126
+ if (ir.script && scriptRanges) {
127
+ for (const range of scriptRanges.bindings) {
128
+ names.add(ir.script.content.slice(range.start, range.end));
129
+ }
130
+ }
131
+ }
132
+ return names;
133
+ });
117
134
  const getSetupConsts = (0, signals_1.computedSet)(() => {
118
135
  const scriptSetupRanges = getScriptSetupRanges();
119
136
  const names = new Set([
@@ -187,30 +204,15 @@ function useCodegen(ts, vueCompilerOptions, fileName, ir) {
187
204
  });
188
205
  });
189
206
  const getSetupExposed = (0, signals_1.computedSet)(() => {
190
- const allVars = new Set();
191
- const scriptSetupRanges = getScriptSetupRanges();
192
- if (!ir.scriptSetup || !scriptSetupRanges) {
193
- return allVars;
194
- }
195
- for (const range of scriptSetupRanges.bindings) {
196
- const name = ir.scriptSetup.content.slice(range.start, range.end);
197
- allVars.add(name);
198
- }
199
- const scriptRanges = getScriptRanges();
200
- if (ir.script && scriptRanges) {
201
- for (const range of scriptRanges.bindings) {
202
- const name = ir.script.content.slice(range.start, range.end);
203
- allVars.add(name);
204
- }
205
- }
206
- if (!allVars.size) {
207
- return allVars;
207
+ const bindings = getSetupBindings();
208
+ if (!bindings.size) {
209
+ return bindings;
208
210
  }
209
211
  return new Set([
210
- ...getGeneratedTemplate()?.componentAccessMap.keys() ?? [],
211
- ...getGeneratedStyle()?.componentAccessMap.keys() ?? [],
212
+ ...getGeneratedTemplate()?.contextAccesses.keys() ?? [],
213
+ ...getGeneratedStyle()?.contextAccesses.keys() ?? [],
212
214
  ...ir.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)));
215
+ ].filter(name => bindings.has(name)));
214
216
  });
215
217
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
216
218
  return (0, script_1.generateScript)({
@@ -237,6 +239,7 @@ function useCodegen(ts, vueCompilerOptions, fileName, ir) {
237
239
  getGeneratedScript,
238
240
  getGeneratedTemplate,
239
241
  getImportedComponents,
242
+ getSetupBindings,
240
243
  getSetupExposed,
241
244
  };
242
245
  }
package/lib/plugins.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { type VueLanguagePlugin } from './types';
2
- export * from './plugins/shared';
3
2
  export declare function createPlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): import("./types").VueLanguagePluginReturn[];
package/lib/plugins.js CHANGED
@@ -1,18 +1,4 @@
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 __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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
4
  };
@@ -33,7 +19,6 @@ const vue_template_inline_css_1 = __importDefault(require("./plugins/vue-templat
33
19
  const vue_template_inline_ts_1 = __importDefault(require("./plugins/vue-template-inline-ts"));
34
20
  const vue_tsx_1 = __importDefault(require("./plugins/vue-tsx"));
35
21
  const types_1 = require("./types");
36
- __exportStar(require("./plugins/shared"), exports);
37
22
  function createPlugins(pluginContext) {
38
23
  const plugins = [
39
24
  file_vue_1.default,