@vue/language-core 2.1.10 → 2.2.2

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 (109) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codeFeatures.d.ts +1 -0
  4. package/lib/codeFeatures.js +3 -0
  5. package/lib/codegen/codeFeatures.d.ts +83 -0
  6. package/lib/codegen/codeFeatures.js +71 -0
  7. package/lib/codegen/globalTypes.d.ts +3 -1
  8. package/lib/codegen/globalTypes.js +39 -14
  9. package/lib/codegen/localTypes.d.ts +1 -1
  10. package/lib/codegen/localTypes.js +7 -7
  11. package/lib/codegen/script/binding.d.ts +4 -0
  12. package/lib/codegen/script/binding.js +41 -0
  13. package/lib/codegen/script/component.d.ts +1 -1
  14. package/lib/codegen/script/component.js +44 -44
  15. package/lib/codegen/script/componentSelf.d.ts +1 -1
  16. package/lib/codegen/script/componentSelf.js +14 -14
  17. package/lib/codegen/script/context.d.ts +1 -1
  18. package/lib/codegen/script/context.js +2 -2
  19. package/lib/codegen/script/index.d.ts +6 -11
  20. package/lib/codegen/script/index.js +21 -63
  21. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  22. package/lib/codegen/script/scriptSetup.js +236 -205
  23. package/lib/codegen/script/src.js +8 -8
  24. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  25. package/lib/codegen/script/styleModulesType.js +7 -7
  26. package/lib/codegen/script/template.d.ts +2 -2
  27. package/lib/codegen/script/template.js +81 -114
  28. package/lib/codegen/template/context.d.ts +29 -15
  29. package/lib/codegen/template/context.js +51 -96
  30. package/lib/codegen/template/element.d.ts +2 -4
  31. package/lib/codegen/template/element.js +124 -317
  32. package/lib/codegen/template/elementChildren.d.ts +1 -1
  33. package/lib/codegen/template/elementChildren.js +10 -11
  34. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  35. package/lib/codegen/template/elementDirectives.js +43 -30
  36. package/lib/codegen/template/elementEvents.d.ts +2 -2
  37. package/lib/codegen/template/elementEvents.js +32 -65
  38. package/lib/codegen/template/elementProps.d.ts +5 -3
  39. package/lib/codegen/template/elementProps.js +116 -123
  40. package/lib/codegen/template/index.d.ts +1 -0
  41. package/lib/codegen/template/index.js +67 -69
  42. package/lib/codegen/template/interpolation.d.ts +5 -3
  43. package/lib/codegen/template/interpolation.js +30 -27
  44. package/lib/codegen/template/objectProperty.js +8 -8
  45. package/lib/codegen/template/propertyAccess.js +4 -4
  46. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  47. package/lib/codegen/template/slotOutlet.js +47 -25
  48. package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
  49. package/lib/codegen/template/styleScopedClasses.js +152 -8
  50. package/lib/codegen/template/templateChild.d.ts +1 -1
  51. package/lib/codegen/template/templateChild.js +39 -20
  52. package/lib/codegen/template/vFor.d.ts +1 -1
  53. package/lib/codegen/template/vFor.js +11 -11
  54. package/lib/codegen/template/vIf.d.ts +1 -1
  55. package/lib/codegen/template/vIf.js +6 -6
  56. package/lib/codegen/template/vSlot.d.ts +5 -0
  57. package/lib/codegen/template/vSlot.js +80 -0
  58. package/lib/codegen/utils/camelized.d.ts +2 -0
  59. package/lib/codegen/utils/camelized.js +31 -0
  60. package/lib/codegen/utils/index.d.ts +21 -0
  61. package/lib/codegen/utils/index.js +79 -0
  62. package/lib/codegen/utils/src.d.ts +2 -0
  63. package/lib/codegen/utils/src.js +19 -0
  64. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  65. package/lib/codegen/utils/unicode.d.ts +2 -0
  66. package/lib/codegen/utils/unicode.js +25 -0
  67. package/lib/languagePlugin.js +1 -1
  68. package/lib/parsers/scriptRanges.d.ts +7 -2
  69. package/lib/parsers/scriptSetupRanges.d.ts +69 -83
  70. package/lib/parsers/scriptSetupRanges.js +194 -171
  71. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  72. package/lib/parsers/vueCompilerOptions.js +23 -0
  73. package/lib/plugins/file-html.js +4 -3
  74. package/lib/plugins/file-md.js +1 -1
  75. package/lib/plugins/file-vue.js +4 -4
  76. package/lib/plugins/vue-root-tags.js +2 -2
  77. package/lib/plugins/vue-style-class-names.d.ts +5 -0
  78. package/lib/plugins/vue-style-class-names.js +32 -0
  79. package/lib/plugins/vue-style-reference-link.d.ts +1 -0
  80. package/lib/plugins/vue-style-reference-link.js +3 -0
  81. package/lib/plugins/vue-style-reference-links.d.ts +3 -0
  82. package/lib/plugins/vue-style-reference-links.js +26 -0
  83. package/lib/plugins/vue-template-html.js +6 -2
  84. package/lib/plugins/vue-template-inline-css.js +1 -1
  85. package/lib/plugins/vue-template-inline-ts.js +66 -17
  86. package/lib/plugins/vue-tsx.d.ts +126 -92
  87. package/lib/plugins/vue-tsx.js +114 -97
  88. package/lib/plugins/vue-vine.d.ts +3 -0
  89. package/lib/plugins/vue-vine.js +35 -0
  90. package/lib/types.d.ts +25 -12
  91. package/lib/utils/buildMappings.d.ts +1 -1
  92. package/lib/utils/parseCssImports.d.ts +4 -0
  93. package/lib/utils/parseCssImports.js +19 -0
  94. package/lib/utils/parseSfc.d.ts +5 -0
  95. package/lib/utils/parseSfc.js +11 -5
  96. package/lib/utils/signals.d.ts +2 -0
  97. package/lib/utils/signals.js +54 -0
  98. package/lib/utils/ts.d.ts +14 -2
  99. package/lib/utils/ts.js +134 -91
  100. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  101. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  102. package/lib/virtualFile/computedSfc.d.ts +1 -2
  103. package/lib/virtualFile/computedSfc.js +87 -79
  104. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  105. package/lib/virtualFile/computedVueSfc.js +7 -7
  106. package/lib/virtualFile/vueFile.d.ts +5 -5
  107. package/lib/virtualFile/vueFile.js +6 -6
  108. package/package.json +6 -6
  109. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateInterpolation = generateInterpolation;
4
- exports.forEachInterpolationSegment = forEachInterpolationSegment;
5
4
  const shared_1 = require("@vue/shared");
6
5
  const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
7
- const common_1 = require("../common");
8
- function* generateInterpolation(options, ctx, _code, astHolder, start, data, prefix, suffix) {
6
+ const utils_1 = require("../utils");
7
+ function* generateInterpolation(options, ctx, source, data, _code, start, astHolder = {}, prefix = '', suffix = '') {
9
8
  const code = prefix + _code + suffix;
10
- const ast = (0, common_1.createTsAst)(options.ts, astHolder, code);
9
+ const ast = (0, utils_1.createTsAst)(options.ts, astHolder, code);
11
10
  for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
12
11
  if (offset === undefined) {
13
12
  yield section;
@@ -17,12 +16,12 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
17
16
  let addSuffix = '';
18
17
  const overLength = offset + section.length - _code.length;
19
18
  if (overLength > 0) {
20
- addSuffix = section.substring(section.length - overLength);
21
- section = section.substring(0, section.length - overLength);
19
+ addSuffix = section.slice(section.length - overLength);
20
+ section = section.slice(0, -overLength);
22
21
  }
23
22
  if (offset < 0) {
24
- yield section.substring(0, -offset);
25
- section = section.substring(-offset);
23
+ yield section.slice(0, -offset);
24
+ section = section.slice(-offset);
26
25
  offset = 0;
27
26
  }
28
27
  const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
@@ -31,7 +30,7 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
31
30
  && data) {
32
31
  yield [
33
32
  section,
34
- 'template',
33
+ source,
35
34
  start + offset,
36
35
  type === 'errorMappingOnly'
37
36
  ? ctx.codeFeatures.verification
@@ -46,15 +45,16 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
46
45
  }
47
46
  }
48
47
  }
48
+ ;
49
49
  function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
50
50
  let ctxVars = [];
51
51
  const varCb = (id, isShorthand) => {
52
52
  const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
53
- if (ctx.hasLocalVariable(text) ||
53
+ if (ctx.hasLocalVariable(text)
54
54
  // https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
55
- (0, shared_1.isGloballyWhitelisted)(text) ||
56
- text === 'require' ||
57
- text.startsWith('__VLS_')) {
55
+ || (0, shared_1.isGloballyAllowed)(text)
56
+ || text === 'require'
57
+ || text.startsWith('__VLS_')) {
58
58
  // localVarOffsets.push(localVar.getStart(ast));
59
59
  }
60
60
  else {
@@ -78,50 +78,53 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
78
78
  ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
79
79
  if (ctxVars.length) {
80
80
  if (ctxVars[0].isShorthand) {
81
- yield [code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
81
+ yield [code.slice(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
82
82
  yield [': ', undefined];
83
83
  }
84
84
  else if (ctxVars[0].offset > 0) {
85
- yield [code.substring(0, ctxVars[0].offset), 0, 'startText'];
85
+ yield [code.slice(0, ctxVars[0].offset), 0, 'startText'];
86
86
  }
87
87
  for (let i = 0; i < ctxVars.length - 1; i++) {
88
88
  const curVar = ctxVars[i];
89
89
  const nextVar = ctxVars[i + 1];
90
- yield* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar);
90
+ yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, curVar);
91
91
  if (nextVar.isShorthand) {
92
- yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
92
+ yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
93
93
  yield [': ', undefined];
94
94
  }
95
95
  else {
96
- yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset), curVar.offset + curVar.text.length];
96
+ yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset), curVar.offset + curVar.text.length];
97
97
  }
98
98
  }
99
99
  const lastVar = ctxVars.at(-1);
100
- yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
100
+ yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, lastVar);
101
101
  if (lastVar.offset + lastVar.text.length < code.length) {
102
- yield [code.substring(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
102
+ yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
103
103
  }
104
104
  }
105
105
  else {
106
106
  yield [code, 0];
107
107
  }
108
108
  }
109
- function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar = curVar) {
109
+ function* generateVar(code, specialVars, destructuredPropNames, templateRefNames, curVar) {
110
110
  // fix https://github.com/vuejs/language-tools/issues/1205
111
111
  // fix https://github.com/vuejs/language-tools/issues/1264
112
- yield ['', nextVar.offset, 'errorMappingOnly'];
112
+ yield ['', curVar.offset, 'errorMappingOnly'];
113
113
  const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
114
114
  const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
115
115
  if (isTemplateRef) {
116
116
  yield [`__VLS_unref(`, undefined];
117
- yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
117
+ yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
118
118
  yield [`)`, undefined];
119
119
  }
120
120
  else {
121
- if (!isDestructuredProp) {
121
+ if (specialVars.has(curVar.text)) {
122
+ yield [`__VLS_special.`, undefined];
123
+ }
124
+ else if (!isDestructuredProp) {
122
125
  yield [`__VLS_ctx.`, undefined];
123
126
  }
124
- yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
127
+ yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
125
128
  }
126
129
  }
127
130
  function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true) {
@@ -135,7 +138,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
135
138
  walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars, false);
136
139
  }
137
140
  else if (ts.isVariableDeclaration(node)) {
138
- (0, common_1.collectVars)(ts, node.name, ast, blockVars);
141
+ (0, utils_1.collectVars)(ts, node.name, ast, blockVars);
139
142
  for (const varName of blockVars) {
140
143
  ctx.addLocalVariable(varName);
141
144
  }
@@ -196,7 +199,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
196
199
  function processFunction(ts, node, ast, cb, ctx) {
197
200
  const functionArgs = [];
198
201
  for (const param of node.parameters) {
199
- (0, common_1.collectVars)(ts, param.name, ast, functionArgs);
202
+ (0, utils_1.collectVars)(ts, param.name, ast, functionArgs);
200
203
  if (param.type) {
201
204
  walkIdentifiers(ts, param.type, ast, cb, ctx);
202
205
  }
@@ -2,29 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateObjectProperty = generateObjectProperty;
4
4
  const shared_1 = require("@vue/shared");
5
- const common_1 = require("../common");
6
- const camelized_1 = require("./camelized");
5
+ const utils_1 = require("../utils");
6
+ const camelized_1 = require("../utils/camelized");
7
+ const stringLiteralKey_1 = require("../utils/stringLiteralKey");
7
8
  const interpolation_1 = require("./interpolation");
8
- const stringLiteralKey_1 = require("./stringLiteralKey");
9
9
  function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false, shouldBeConstant = false) {
10
10
  if (code.startsWith('[') && code.endsWith(']') && astHolder) {
11
11
  if (shouldBeConstant) {
12
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, code.slice(1, -1), astHolder, offset + 1, features, `[__VLS_tryAsConstant(`, `)]`);
12
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code.slice(1, -1), offset + 1, astHolder, `[__VLS_tryAsConstant(`, `)]`);
13
13
  }
14
14
  else {
15
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
15
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset, astHolder);
16
16
  }
17
17
  }
18
18
  else if (shouldCamelize) {
19
- if (common_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
19
+ if (utils_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
20
20
  yield* (0, camelized_1.generateCamelized)(code, offset, features);
21
21
  }
22
22
  else {
23
- yield* (0, common_1.wrapWith)(offset, offset + code.length, features, `"`, ...(0, camelized_1.generateCamelized)(code, offset, common_1.combineLastMapping), `"`);
23
+ yield* (0, utils_1.wrapWith)(offset, offset + code.length, features, `'`, ...(0, camelized_1.generateCamelized)(code, offset, utils_1.combineLastMapping), `'`);
24
24
  }
25
25
  }
26
26
  else {
27
- if (common_1.variableNameRegex.test(code)) {
27
+ if (utils_1.variableNameRegex.test(code)) {
28
28
  yield [code, 'template', offset, features];
29
29
  }
30
30
  else {
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generatePropertyAccess = generatePropertyAccess;
4
- const common_1 = require("../common");
4
+ const utils_1 = require("../utils");
5
+ const stringLiteralKey_1 = require("../utils/stringLiteralKey");
5
6
  const interpolation_1 = require("./interpolation");
6
- const stringLiteralKey_1 = require("./stringLiteralKey");
7
7
  function* generatePropertyAccess(options, ctx, code, offset, features, astHolder) {
8
- if (!options.compilerOptions.noPropertyAccessFromIndexSignature && common_1.variableNameRegex.test(code)) {
8
+ if (!options.compilerOptions.noPropertyAccessFromIndexSignature && utils_1.variableNameRegex.test(code)) {
9
9
  yield `.`;
10
10
  yield offset !== undefined && features
11
11
  ? [code, 'template', offset, features]
12
12
  : code;
13
13
  }
14
14
  else if (code.startsWith('[') && code.endsWith(']')) {
15
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
15
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset, astHolder);
16
16
  }
17
17
  else {
18
18
  yield `[`;
@@ -2,4 +2,4 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
5
+ export declare function generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode): Generator<Code>;
@@ -2,14 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSlotOutlet = generateSlotOutlet;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
- const common_1 = require("../common");
5
+ const inlayHints_1 = require("../inlayHints");
6
+ const utils_1 = require("../utils");
6
7
  const elementChildren_1 = require("./elementChildren");
7
8
  const elementProps_1 = require("./elementProps");
8
9
  const interpolation_1 = require("./interpolation");
9
- const inlayHints_1 = require("../inlayHints");
10
- function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxVar) {
11
- const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
12
- const varSlot = ctx.getInternalVariable();
10
+ const propertyAccess_1 = require("./propertyAccess");
11
+ function* generateSlotOutlet(options, ctx, node) {
12
+ const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
13
+ const propsVar = ctx.getInternalVariable();
13
14
  const nameProp = node.props.find(prop => {
14
15
  if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
15
16
  return prop.name === 'name';
@@ -22,27 +23,48 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
22
23
  });
23
24
  if (options.hasDefineSlots) {
24
25
  yield `__VLS_normalizeSlot(`;
25
- yield* (0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value
26
- ? `'${nameProp.value.content}'`
27
- : nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
28
- ? nameProp.exp.content
29
- : `('default' as const)`), `]`);
26
+ if (nameProp) {
27
+ let codes;
28
+ if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
29
+ let { source, start: { offset } } = nameProp.value.loc;
30
+ if (source.startsWith('"') || source.startsWith("'")) {
31
+ source = source.slice(1, -1);
32
+ offset++;
33
+ }
34
+ codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, ctx.codeFeatures.navigationAndVerification);
35
+ }
36
+ else if (nameProp.type === CompilerDOM.NodeTypes.DIRECTIVE
37
+ && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
38
+ codes = [
39
+ `[`,
40
+ ...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp, ctx.codeFeatures.all, true),
41
+ `]`
42
+ ];
43
+ }
44
+ else {
45
+ codes = [`['default']`];
46
+ }
47
+ yield* (0, utils_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
48
+ }
49
+ else {
50
+ yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}['default']`);
51
+ }
30
52
  yield `)?.(`;
31
- yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${common_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
32
- yield `)${common_1.endOfLine}`;
53
+ yield* (0, utils_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
54
+ yield `)${utils_1.endOfLine}`;
33
55
  }
34
56
  else {
35
- yield `var ${varSlot} = {${common_1.newLine}`;
36
- yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
37
- yield `}${common_1.endOfLine}`;
57
+ yield `var ${propsVar} = {${utils_1.newLine}`;
58
+ yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.checkUnknownProps, true);
59
+ yield `}${utils_1.endOfLine}`;
38
60
  if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
39
61
  && nameProp.value) {
40
62
  ctx.slots.push({
41
63
  name: nameProp.value.content,
42
- loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
64
+ offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
43
65
  tagRange: [startTagOffset, startTagOffset + node.tag.length],
44
- varName: varSlot,
45
66
  nodeLoc: node.loc,
67
+ propsVar,
46
68
  });
47
69
  }
48
70
  else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -51,25 +73,25 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
51
73
  if (isShortHand) {
52
74
  ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(nameProp.exp.loc, 'name'));
53
75
  }
54
- const slotExpVar = ctx.getInternalVariable();
55
- yield `var ${slotExpVar} = `;
56
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
57
- yield ` as const${common_1.endOfLine}`;
76
+ const expVar = ctx.getInternalVariable();
77
+ yield `var ${expVar} = __VLS_tryAsConstant(`;
78
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset, nameProp.exp);
79
+ yield `)${utils_1.endOfLine}`;
58
80
  ctx.dynamicSlots.push({
59
- expVar: slotExpVar,
60
- varName: varSlot,
81
+ expVar,
82
+ propsVar,
61
83
  });
62
84
  }
63
85
  else {
64
86
  ctx.slots.push({
65
87
  name: 'default',
66
88
  tagRange: [startTagOffset, startTagOffset + node.tag.length],
67
- varName: varSlot,
68
89
  nodeLoc: node.loc,
90
+ propsVar,
69
91
  });
70
92
  }
71
93
  }
72
94
  yield* ctx.generateAutoImportCompletion();
73
- yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
95
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
74
96
  }
75
97
  //# sourceMappingURL=slotOutlet.js.map
@@ -1,3 +1,6 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
1
2
  import type { Code } from '../../types';
2
3
  import type { TemplateCodegenContext } from './context';
3
- export declare function generateStyleScopedClasses(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
4
+ import type { TemplateCodegenOptions } from './index';
5
+ export declare function generateStyleScopedClassReferences(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
6
+ export declare function collectStyleScopedClassReferences(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): void;
@@ -1,20 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateStyleScopedClasses = generateStyleScopedClasses;
4
- const common_1 = require("../common");
5
- function* generateStyleScopedClasses(ctx, withDot = false) {
3
+ exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
4
+ exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
5
+ const CompilerDOM = require("@vue/compiler-dom");
6
+ const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
7
+ const utils_1 = require("../utils");
8
+ function* generateStyleScopedClassReferences(ctx, withDot = false) {
9
+ if (!ctx.emptyClassOffsets.length && !ctx.scopedClasses.length) {
10
+ return;
11
+ }
12
+ yield `[`;
6
13
  for (const offset of ctx.emptyClassOffsets) {
7
- yield `__VLS_styleScopedClasses['`;
14
+ yield `'`;
8
15
  yield [
9
16
  '',
10
17
  'template',
11
18
  offset,
12
19
  ctx.codeFeatures.additionalCompletion,
13
20
  ];
14
- yield `']${common_1.endOfLine}`;
21
+ yield `', `;
15
22
  }
16
23
  for (const { source, className, offset } of ctx.scopedClasses) {
17
- yield `__VLS_styleScopedClasses[`;
18
24
  yield [
19
25
  '',
20
26
  source,
@@ -31,9 +37,9 @@ function* generateStyleScopedClasses(ctx, withDot = false) {
31
37
  offset + className.length,
32
38
  ctx.codeFeatures.navigationWithoutRename,
33
39
  ];
34
- yield `]${common_1.endOfLine}`;
40
+ yield `, `;
35
41
  }
36
- yield common_1.newLine;
42
+ yield `] as (keyof __VLS_StyleScopedClasses)[]${utils_1.endOfLine}`;
37
43
  function* escapeString(source, className, offset, escapeTargets) {
38
44
  let count = 0;
39
45
  const currentEscapeTargets = [...escapeTargets];
@@ -69,4 +75,142 @@ function* generateStyleScopedClasses(ctx, withDot = false) {
69
75
  }
70
76
  }
71
77
  }
78
+ function collectStyleScopedClassReferences(options, ctx, node) {
79
+ for (const prop of node.props) {
80
+ if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
81
+ && prop.name === 'class'
82
+ && prop.value) {
83
+ if (options.template.lang === 'pug') {
84
+ const getClassOffset = Reflect.get(prop.value.loc.start, 'getClassOffset');
85
+ const content = prop.value.loc.source.slice(1, -1);
86
+ let startOffset = 1;
87
+ for (const className of content.split(' ')) {
88
+ if (className) {
89
+ ctx.scopedClasses.push({
90
+ source: 'template',
91
+ className,
92
+ offset: getClassOffset(startOffset),
93
+ });
94
+ }
95
+ startOffset += className.length + 1;
96
+ }
97
+ }
98
+ else {
99
+ let isWrapped = false;
100
+ const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
101
+ if (content) {
102
+ const classes = collectClasses(content, startOffset + (isWrapped ? 1 : 0));
103
+ ctx.scopedClasses.push(...classes);
104
+ }
105
+ else {
106
+ ctx.emptyClassOffsets.push(startOffset);
107
+ }
108
+ }
109
+ }
110
+ else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
111
+ && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
112
+ && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
113
+ && prop.arg.content === 'class') {
114
+ const content = '`${' + prop.exp.content + '}`';
115
+ const startOffset = prop.exp.loc.start.offset - 3;
116
+ const { ts } = options;
117
+ const ast = ts.createSourceFile('', content, 99);
118
+ const literals = [];
119
+ ts.forEachChild(ast, node => {
120
+ if (!ts.isExpressionStatement(node) ||
121
+ !isTemplateExpression(node.expression)) {
122
+ return;
123
+ }
124
+ const expression = node.expression.templateSpans[0].expression;
125
+ if (ts.isStringLiteralLike(expression)) {
126
+ literals.push(expression);
127
+ }
128
+ if (ts.isArrayLiteralExpression(expression)) {
129
+ walkArrayLiteral(expression);
130
+ }
131
+ if (ts.isObjectLiteralExpression(expression)) {
132
+ walkObjectLiteral(expression);
133
+ }
134
+ });
135
+ for (const literal of literals) {
136
+ if (literal.text) {
137
+ const classes = collectClasses(literal.text, literal.end - literal.text.length - 1 + startOffset);
138
+ ctx.scopedClasses.push(...classes);
139
+ }
140
+ else {
141
+ ctx.emptyClassOffsets.push(literal.end - 1 + startOffset);
142
+ }
143
+ }
144
+ function walkArrayLiteral(node) {
145
+ const { elements } = node;
146
+ for (const element of elements) {
147
+ if (ts.isStringLiteralLike(element)) {
148
+ literals.push(element);
149
+ }
150
+ else if (ts.isObjectLiteralExpression(element)) {
151
+ walkObjectLiteral(element);
152
+ }
153
+ }
154
+ }
155
+ function walkObjectLiteral(node) {
156
+ const { properties } = node;
157
+ for (const property of properties) {
158
+ if (ts.isPropertyAssignment(property)) {
159
+ const { name } = property;
160
+ if (ts.isIdentifier(name)) {
161
+ walkIdentifier(name);
162
+ }
163
+ else if (ts.isStringLiteral(name)) {
164
+ literals.push(name);
165
+ }
166
+ else if (ts.isComputedPropertyName(name)) {
167
+ const { expression } = name;
168
+ if (ts.isStringLiteralLike(expression)) {
169
+ literals.push(expression);
170
+ }
171
+ }
172
+ }
173
+ else if (ts.isShorthandPropertyAssignment(property)) {
174
+ walkIdentifier(property.name);
175
+ }
176
+ }
177
+ }
178
+ function walkIdentifier(node) {
179
+ const text = (0, scriptSetupRanges_1.getNodeText)(ts, node, ast);
180
+ ctx.scopedClasses.push({
181
+ source: 'template',
182
+ className: text,
183
+ offset: node.end - text.length + startOffset
184
+ });
185
+ }
186
+ }
187
+ }
188
+ }
189
+ function collectClasses(content, startOffset = 0) {
190
+ const classes = [];
191
+ let currentClassName = '';
192
+ let offset = 0;
193
+ for (const char of (content + ' ')) {
194
+ if (char.trim() === '') {
195
+ if (currentClassName !== '') {
196
+ classes.push({
197
+ source: 'template',
198
+ className: currentClassName,
199
+ offset: offset + startOffset
200
+ });
201
+ offset += currentClassName.length;
202
+ currentClassName = '';
203
+ }
204
+ offset += char.length;
205
+ }
206
+ else {
207
+ currentClassName += char;
208
+ }
209
+ }
210
+ return classes;
211
+ }
212
+ // isTemplateExpression is missing in tsc
213
+ function isTemplateExpression(node) {
214
+ return node.kind === 228;
215
+ }
72
216
  //# sourceMappingURL=styleScopedClasses.js.map
@@ -2,6 +2,6 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined, isVForChild?: boolean): Generator<Code>;
5
+ export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, prevNode: CompilerDOM.TemplateChildNode | undefined, isVForChild?: boolean): Generator<Code>;
6
6
  export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
7
7
  export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];