@vue/language-core 3.0.5 → 3.0.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 (46) hide show
  1. package/lib/codegen/codeFeatures.d.ts +0 -5
  2. package/lib/codegen/codeFeatures.js +0 -3
  3. package/lib/codegen/script/component.d.ts +1 -1
  4. package/lib/codegen/script/component.js +10 -14
  5. package/lib/codegen/script/componentSelf.js +19 -23
  6. package/lib/codegen/script/scriptSetup.js +1 -1
  7. package/lib/codegen/script/template.d.ts +0 -1
  8. package/lib/codegen/script/template.js +6 -43
  9. package/lib/codegen/template/element.js +4 -18
  10. package/lib/codegen/template/index.js +4 -5
  11. package/lib/codegen/template/slotOutlet.js +2 -2
  12. package/lib/codegen/template/styleScopedClasses.js +6 -10
  13. package/lib/plugins/file-html.js +1 -1
  14. package/lib/plugins/file-md.js +1 -1
  15. package/lib/plugins/file-vue.js +1 -1
  16. package/lib/plugins/vue-root-tags.js +1 -1
  17. package/lib/plugins/vue-script-js.js +1 -1
  18. package/lib/plugins/vue-sfc-customblocks.js +1 -1
  19. package/lib/plugins/vue-sfc-scripts.js +1 -1
  20. package/lib/plugins/vue-sfc-styles.js +5 -5
  21. package/lib/plugins/vue-sfc-template.js +1 -1
  22. package/lib/plugins/vue-template-html.js +1 -1
  23. package/lib/plugins/vue-template-inline-css.js +1 -1
  24. package/lib/plugins/vue-template-inline-ts.js +1 -1
  25. package/lib/plugins/vue-tsx.js +1 -1
  26. package/lib/plugins.js +2 -0
  27. package/lib/types.d.ts +3 -2
  28. package/lib/types.js +1 -1
  29. package/lib/utils/shared.d.ts +3 -1
  30. package/lib/utils/shared.js +13 -0
  31. package/lib/utils/ts.d.ts +7 -6
  32. package/lib/utils/ts.js +43 -66
  33. package/lib/virtualFile/computedSfc.js +13 -8
  34. package/package.json +4 -4
  35. package/lib/codegen/tenp.d.ts +0 -1
  36. package/lib/codegen/tenp.js +0 -3
  37. package/lib/parsers/utils.d.ts +0 -12
  38. package/lib/parsers/utils.js +0 -95
  39. package/lib/plugins/file-css.d.ts +0 -3
  40. package/lib/plugins/file-css.js +0 -57
  41. package/lib/utils/parseCssClassNames.d.ts +0 -4
  42. package/lib/utils/parseCssClassNames.js +0 -17
  43. package/lib/utils/parseCssImports.d.ts +0 -4
  44. package/lib/utils/parseCssImports.js +0 -19
  45. package/lib/utils/parseCssVars.d.ts +0 -6
  46. package/lib/utils/parseCssVars.js +0 -26
@@ -25,11 +25,6 @@ declare const raw: {
25
25
  navigation: {
26
26
  navigation: true;
27
27
  };
28
- navigationWithoutHighlight: {
29
- navigation: {
30
- shouldHighlight: () => false;
31
- };
32
- };
33
28
  navigationWithoutRename: {
34
29
  navigation: {
35
30
  shouldRename: () => false;
@@ -25,9 +25,6 @@ const raw = {
25
25
  navigation: {
26
26
  navigation: true,
27
27
  },
28
- navigationWithoutHighlight: {
29
- navigation: { shouldHighlight: () => false },
30
- },
31
28
  navigationWithoutRename: {
32
29
  navigation: { shouldRename: () => false },
33
30
  },
@@ -3,6 +3,6 @@ import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
- export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
+ export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<string>;
7
7
  export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
8
8
  export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, hasEmitsOption: boolean, inheritAttrs: boolean): Generator<Code>;
@@ -17,23 +17,18 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
17
17
  else {
18
18
  yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
19
19
  }
20
- yield `setup() {${utils_1.newLine}`;
21
20
  const returns = [];
22
21
  if (ctx.bypassDefineComponent) {
23
- yield* `const __VLS_returns = {${utils_1.newLine}`;
24
- yield* generateComponentSetupReturns(scriptSetupRanges);
25
- yield `}${utils_1.endOfLine}`;
26
- returns.push(`typeof __VLS_returns`);
22
+ returns.push(...generateComponentSetupReturns(scriptSetupRanges));
27
23
  }
28
24
  if (scriptSetupRanges.defineExpose) {
29
- returns.push(`typeof __VLS_exposed`);
25
+ returns.push(`__VLS_exposed`);
30
26
  }
31
27
  if (returns.length) {
32
- yield `return {} as `;
33
- yield* (0, merge_1.generateIntersectMerge)(returns);
34
- yield utils_1.endOfLine;
28
+ yield `setup: () => (`;
29
+ yield* (0, merge_1.generateSpreadMerge)(returns);
30
+ yield `),${utils_1.newLine}`;
35
31
  }
36
- yield `},${utils_1.newLine}`;
37
32
  if (!ctx.bypassDefineComponent) {
38
33
  const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
39
34
  yield* emitOptionCodes;
@@ -58,13 +53,14 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
58
53
  function* generateComponentSetupReturns(scriptSetupRanges) {
59
54
  // fill $props
60
55
  if (scriptSetupRanges.defineProps) {
56
+ const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
61
57
  // NOTE: defineProps is inaccurate for $props
62
- yield `$props: __VLS_makeOptional(${scriptSetupRanges.defineProps.name ?? `__VLS_props`}),${utils_1.newLine}`;
63
- yield `...${scriptSetupRanges.defineProps.name ?? `__VLS_props`},${utils_1.newLine}`;
58
+ yield name;
59
+ yield `{} as { $props: Partial<typeof ${name}> }`;
64
60
  }
65
61
  // fill $emit
66
62
  if (scriptSetupRanges.defineEmits) {
67
- yield `$emit: ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'},${utils_1.newLine}`;
63
+ yield `{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`;
68
64
  }
69
65
  }
70
66
  function* generateEmitsOption(options, scriptSetupRanges) {
@@ -99,7 +95,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
99
95
  const getOptionCodes = [];
100
96
  const typeOptionCodes = [];
101
97
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
102
- let attrsType = `Partial<__VLS_InheritedAttrs>`;
98
+ let attrsType = `__VLS_InheritedAttrs`;
103
99
  if (hasEmitsOption) {
104
100
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
105
101
  }
@@ -1,41 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponentSelf = generateComponentSelf;
4
+ const shared_1 = require("@vue/shared");
4
5
  const path = require("path-browserify");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
7
8
  const component_1 = require("./component");
8
- const template_1 = require("./template");
9
9
  function* generateComponentSelf(options, ctx, templateCodegenCtx) {
10
10
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
11
11
  yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
12
- yield `setup() {${utils_1.newLine}`;
13
- yield `return {${utils_1.newLine}`;
12
+ yield `setup: () => ({${utils_1.newLine}`;
14
13
  if (ctx.bypassDefineComponent) {
15
- yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
14
+ for (const code of (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges)) {
15
+ yield `...${code},${utils_1.newLine}`;
16
+ }
16
17
  }
17
18
  // bindings
18
- const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
19
- for (const [content, bindings] of [
20
- [options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
21
- options.sfc.script && options.scriptRanges
22
- ? [options.sfc.script.content, options.scriptRanges.bindings]
23
- : ['', []],
24
- ]) {
25
- for (const { range } of bindings) {
26
- const varName = content.slice(range.start, range.end);
27
- if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
28
- continue;
29
- }
30
- const token = Symbol(varName.length);
31
- yield ['', undefined, 0, { __linkedToken: token }];
32
- yield `${varName}: ${varName} as typeof `;
33
- yield ['', undefined, 0, { __linkedToken: token }];
34
- yield `${varName},${utils_1.newLine}`;
19
+ const templateUsageVars = new Set([
20
+ ...options.sfc.template?.ast?.components.flatMap(c => [(0, shared_1.camelize)(c), (0, shared_1.capitalize)((0, shared_1.camelize)(c))]) ?? [],
21
+ ...options.templateCodegen?.accessExternalVariables.keys() ?? [],
22
+ ...templateCodegenCtx.accessExternalVariables.keys(),
23
+ ]);
24
+ for (const varName of ctx.bindingNames) {
25
+ if (!templateUsageVars.has(varName)) {
26
+ continue;
35
27
  }
28
+ const token = Symbol(varName.length);
29
+ yield ['', undefined, 0, { __linkedToken: token }];
30
+ yield `${varName}: ${varName} as typeof `;
31
+ yield ['', undefined, 0, { __linkedToken: token }];
32
+ yield `${varName},${utils_1.newLine}`;
36
33
  }
37
- yield `}${utils_1.endOfLine}`; // return {
38
- yield `},${utils_1.newLine}`; // setup() {
34
+ yield `}),${utils_1.newLine}`;
39
35
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
40
36
  const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
41
37
  yield* emitOptionCodes;
@@ -54,7 +54,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
54
54
  emitTypes.push(`typeof __VLS_modelEmit`);
55
55
  }
56
56
  yield `return {} as {${utils_1.newLine}`
57
- + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
57
+ + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & __VLS_InheritedAttrs> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
58
58
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.defineExpose ? 'typeof __VLS_exposed' : '{}'}>): void,${utils_1.newLine}`
59
59
  + ` attrs: any,${utils_1.newLine}`
60
60
  + ` slots: __VLS_Slots,${utils_1.newLine}`
@@ -4,4 +4,3 @@ import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
6
6
  export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
7
- export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.generateTemplateDirectives = generateTemplateDirectives;
5
- exports.getTemplateUsageVars = getTemplateUsageVars;
6
- const shared_1 = require("../../utils/shared");
7
5
  const codeFeatures_1 = require("../codeFeatures");
8
6
  const modules_1 = require("../style/modules");
9
7
  const scopedClasses_1 = require("../style/scopedClasses");
@@ -45,18 +43,11 @@ function* generateTemplateComponents(options) {
45
43
  if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
46
44
  const { componentsOption } = options.scriptRanges.exportDefault;
47
45
  yield `const __VLS_componentsOption = `;
48
- yield [
49
- options.sfc.script.content.slice(componentsOption.start, componentsOption.end),
50
- 'script',
51
- componentsOption.start,
52
- codeFeatures_1.codeFeatures.navigation,
53
- ];
46
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, componentsOption.start, componentsOption.end, codeFeatures_1.codeFeatures.navigation);
54
47
  yield utils_1.endOfLine;
55
48
  types.push(`typeof __VLS_componentsOption`);
56
49
  }
57
- yield `type __VLS_LocalComponents =`;
58
- yield* (0, merge_1.generateIntersectMerge)(types);
59
- yield utils_1.endOfLine;
50
+ yield `type __VLS_LocalComponents = ${types.join(` & `)}${utils_1.endOfLine}`;
60
51
  yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
61
52
  }
62
53
  function* generateTemplateDirectives(options) {
@@ -64,18 +55,11 @@ function* generateTemplateDirectives(options) {
64
55
  if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
65
56
  const { directivesOption } = options.scriptRanges.exportDefault;
66
57
  yield `const __VLS_directivesOption = `;
67
- yield [
68
- options.sfc.script.content.slice(directivesOption.start, directivesOption.end),
69
- 'script',
70
- directivesOption.start,
71
- codeFeatures_1.codeFeatures.navigation,
72
- ];
58
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, directivesOption.start, directivesOption.end, codeFeatures_1.codeFeatures.navigation);
73
59
  yield utils_1.endOfLine;
74
60
  types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
75
61
  }
76
- yield `type __VLS_LocalDirectives =`;
77
- yield* (0, merge_1.generateIntersectMerge)(types);
78
- yield utils_1.endOfLine;
62
+ yield `type __VLS_LocalDirectives = ${types.join(` & `)}${utils_1.endOfLine}`;
79
63
  yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
80
64
  }
81
65
  function* generateTemplateBody(options, templateCodegenCtx) {
@@ -101,32 +85,11 @@ function* generateCssVars(options, ctx) {
101
85
  }
102
86
  yield `// CSS variable injection ${utils_1.newLine}`;
103
87
  for (const style of options.sfc.styles) {
104
- for (const cssBind of style.cssVars) {
105
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, cssBind.text, cssBind.offset);
88
+ for (const binding of style.bindings) {
89
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, binding.text, binding.offset);
106
90
  yield utils_1.endOfLine;
107
91
  }
108
92
  }
109
93
  yield `// CSS variable injection end ${utils_1.newLine}`;
110
94
  }
111
- function getTemplateUsageVars(options, ctx) {
112
- const usageVars = new Set();
113
- const components = new Set(options.sfc.template?.ast?.components);
114
- if (options.templateCodegen) {
115
- // fix import components unused report
116
- for (const varName of ctx.bindingNames) {
117
- if (components.has(varName) || components.has((0, shared_1.hyphenateTag)(varName))) {
118
- usageVars.add(varName);
119
- }
120
- }
121
- for (const component of components) {
122
- if (component.includes('.')) {
123
- usageVars.add(component.split('.')[0]);
124
- }
125
- }
126
- for (const [varName] of options.templateCodegen.accessExternalVariables) {
127
- usageVars.add(varName);
128
- }
129
- }
130
- return usageVars;
131
- }
132
95
  //# sourceMappingURL=template.js.map
@@ -20,13 +20,7 @@ const styleScopedClasses_1 = require("./styleScopedClasses");
20
20
  const vSlot_1 = require("./vSlot");
21
21
  const colonReg = /:/g;
22
22
  function* generateComponent(options, ctx, node) {
23
- const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
24
- if (!node.isSelfClosing && options.template.lang === 'html') {
25
- const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
26
- if (endTagOffset > tagOffsets[0]) {
27
- tagOffsets.push(endTagOffset);
28
- }
29
- }
23
+ const tagOffsets = (0, shared_2.getElementTagOffsets)(node, options.template);
30
24
  const failedPropExps = [];
31
25
  const possibleOriginalNames = getPossibleOriginalComponentNames(node.tag, true);
32
26
  const matchImportName = possibleOriginalNames.find(name => options.scriptSetupImportComponentNames.has(name));
@@ -186,21 +180,13 @@ function* generateComponent(options, ctx, node) {
186
180
  }
187
181
  }
188
182
  function* generateElement(options, ctx, node) {
189
- const startTagOffset = node.loc.start.offset
190
- + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
191
- const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
192
- ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
193
- : undefined;
183
+ const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
194
184
  const failedPropExps = [];
195
- const features = {
196
- ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
197
- ...codeFeatures_1.codeFeatures.navigationWithoutHighlight,
198
- };
199
185
  yield `__VLS_asFunctionalElement(__VLS_elements`;
200
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, features);
186
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
201
187
  if (endTagOffset !== undefined) {
202
188
  yield `, __VLS_elements`;
203
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, features);
189
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
204
190
  }
205
191
  yield `)(`;
206
192
  yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
@@ -83,10 +83,9 @@ function* generateSlots(options, ctx) {
83
83
  return `__VLS_Slots`;
84
84
  }
85
85
  function* generateInheritedAttrs(options, ctx) {
86
- yield `type __VLS_InheritedAttrs = {}`;
87
- for (const varName of ctx.inheritedAttrVars) {
88
- yield ` & typeof ${varName}`;
89
- }
86
+ yield `type __VLS_InheritedAttrs = ${ctx.inheritedAttrVars.size
87
+ ? `Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`
88
+ : `{}`}`;
90
89
  yield utils_1.endOfLine;
91
90
  if (ctx.bindingAttrLocs.length) {
92
91
  yield `[`;
@@ -102,7 +101,7 @@ function* generateInheritedAttrs(options, ctx) {
102
101
  }
103
102
  yield `]${utils_1.endOfLine}`;
104
103
  }
105
- return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
104
+ return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & __VLS_InheritedAttrs`;
106
105
  }
107
106
  function* generateTemplateRefs(options, ctx) {
108
107
  yield `type __VLS_TemplateRefs = {}`;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSlotOutlet = generateSlotOutlet;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const shared_1 = require("../../utils/shared");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const inlayHints_1 = require("../inlayHints");
7
8
  const utils_1 = require("../utils");
@@ -11,8 +12,7 @@ const elementProps_1 = require("./elementProps");
11
12
  const interpolation_1 = require("./interpolation");
12
13
  const propertyAccess_1 = require("./propertyAccess");
13
14
  function* generateSlotOutlet(options, ctx, node) {
14
- const startTagOffset = node.loc.start.offset
15
- + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
15
+ const [startTagOffset] = (0, shared_1.getElementTagOffsets)(node, options.template);
16
16
  const startTagEndOffset = startTagOffset + node.tag.length;
17
17
  const propsVar = ctx.getInternalVariable();
18
18
  const nameProp = node.props.find(prop => {
@@ -62,24 +62,24 @@ function collectStyleScopedClassReferences(options, ctx, node) {
62
62
  && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
63
63
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
64
64
  && prop.arg.content === 'class') {
65
- const content = '`${' + prop.exp.content + '}`';
66
- const startOffset = prop.exp.loc.start.offset - 3;
65
+ const content = '(' + prop.exp.content + ')';
66
+ const startOffset = prop.exp.loc.start.offset - 1;
67
67
  const { ts } = options;
68
68
  const ast = ts.createSourceFile('', content, 99);
69
69
  const literals = [];
70
70
  ts.forEachChild(ast, node => {
71
71
  if (!ts.isExpressionStatement(node)
72
- || !isTemplateExpression(node.expression)) {
72
+ || !ts.isParenthesizedExpression(node.expression)) {
73
73
  return;
74
74
  }
75
- const expression = node.expression.templateSpans[0].expression;
75
+ const { expression } = node.expression;
76
76
  if (ts.isStringLiteralLike(expression)) {
77
77
  literals.push(expression);
78
78
  }
79
- if (ts.isArrayLiteralExpression(expression)) {
79
+ else if (ts.isArrayLiteralExpression(expression)) {
80
80
  walkArrayLiteral(expression);
81
81
  }
82
- if (ts.isObjectLiteralExpression(expression)) {
82
+ else if (ts.isObjectLiteralExpression(expression)) {
83
83
  walkObjectLiteral(expression);
84
84
  }
85
85
  });
@@ -160,8 +160,4 @@ function collectClasses(content, startOffset = 0) {
160
160
  }
161
161
  return classes;
162
162
  }
163
- // isTemplateExpression is missing in tsc
164
- function isTemplateExpression(node) {
165
- return node.kind === 228;
166
- }
167
163
  //# sourceMappingURL=styleScopedClasses.js.map
@@ -4,7 +4,7 @@ const sfcBlockReg = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
4
4
  const langReg = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
5
5
  const plugin = ({ vueCompilerOptions }) => {
6
6
  return {
7
- version: 2.1,
7
+ version: 2.2,
8
8
  getLanguageId(fileName) {
9
9
  if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
10
10
  return 'html';
@@ -15,7 +15,7 @@ const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
15
15
  const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
16
16
  const plugin = ({ vueCompilerOptions }) => {
17
17
  return {
18
- version: 2.1,
18
+ version: 2.2,
19
19
  getLanguageId(fileName) {
20
20
  if (vueCompilerOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
21
21
  return 'markdown';
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const parseSfc_1 = require("../utils/parseSfc");
4
4
  const plugin = ({ vueCompilerOptions }) => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  getLanguageId(fileName) {
8
8
  if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
9
  return 'vue';
@@ -4,7 +4,7 @@ const muggle_string_1 = require("muggle-string");
4
4
  const shared_1 = require("./shared");
5
5
  const plugin = () => {
6
6
  return {
7
- version: 2.1,
7
+ version: 2.2,
8
8
  getEmbeddedCodes() {
9
9
  return [{
10
10
  id: 'root_tags',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = ({ modules }) => {
4
4
  return {
5
- version: 2.1,
5
+ version: 2.2,
6
6
  compileSFCScript(lang, script) {
7
7
  if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
8
8
  const ts = modules.typescript;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  return sfc.customBlocks.map((customBlock, i) => ({
9
9
  id: 'custom_block_' + i,
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = () => {
4
4
  return {
5
- version: 2.1,
5
+ version: 2.2,
6
6
  getEmbeddedCodes(_fileName, sfc) {
7
7
  const names = [];
8
8
  if (sfc.script) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  const result = [];
9
9
  for (let i = 0; i < sfc.styles.length; i++) {
@@ -13,7 +13,7 @@ const plugin = () => {
13
13
  id: 'style_' + i,
14
14
  lang: style.lang,
15
15
  });
16
- if (style.cssVars.length) {
16
+ if (style.bindings.length) {
17
17
  result.push({
18
18
  id: 'style_' + i + '_inline_ts',
19
19
  lang: 'ts',
@@ -29,11 +29,11 @@ const plugin = () => {
29
29
  const style = sfc.styles[index];
30
30
  if (embeddedFile.id.endsWith('_inline_ts')) {
31
31
  embeddedFile.parentCodeId = 'style_' + index;
32
- for (const cssVar of style.cssVars) {
32
+ for (const binding of style.bindings) {
33
33
  embeddedFile.content.push('(', [
34
- cssVar.text,
34
+ binding.text,
35
35
  style.name,
36
- cssVar.offset,
36
+ binding.offset,
37
37
  shared_1.allCodeFeatures,
38
38
  ], ');\n');
39
39
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  if (sfc.template?.lang === 'html') {
9
9
  return [{
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shouldAddSuffix = /(?<=<[^>/]+)$/;
4
4
  const plugin = ({ modules }) => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  compileSFCTemplate(lang, template, options) {
8
8
  if (lang === 'html' || lang === 'md') {
9
9
  const compiler = modules['@vue/compiler-dom'];
@@ -10,7 +10,7 @@ const codeFeatures = {
10
10
  };
11
11
  const plugin = () => {
12
12
  return {
13
- version: 2.1,
13
+ version: 2.2,
14
14
  getEmbeddedCodes(_fileName, sfc) {
15
15
  if (!sfc.template?.ast) {
16
16
  return [];
@@ -24,7 +24,7 @@ const formatBrackets = {
24
24
  const plugin = ctx => {
25
25
  const parseds = new WeakMap();
26
26
  return {
27
- version: 2.1,
27
+ version: 2.2,
28
28
  getEmbeddedCodes(_fileName, sfc) {
29
29
  if (!sfc.template?.ast) {
30
30
  return [];
@@ -15,7 +15,7 @@ exports.tsCodegen = new WeakMap();
15
15
  const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
16
16
  const plugin = ctx => {
17
17
  return {
18
- version: 2.1,
18
+ version: 2.2,
19
19
  requiredCompilerOptions: [
20
20
  'noPropertyAccessFromIndexSignature',
21
21
  'exactOptionalPropertyTypes',
package/lib/plugins.js CHANGED
@@ -24,6 +24,7 @@ const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
24
24
  const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
25
25
  const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
26
26
  const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
27
+ const vue_style_css_1 = require("./plugins/vue-style-css");
27
28
  const vue_template_html_1 = require("./plugins/vue-template-html");
28
29
  const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
29
30
  const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
@@ -37,6 +38,7 @@ function createPlugins(pluginContext) {
37
38
  file_html_1.default,
38
39
  vue_root_tags_1.default,
39
40
  vue_script_js_1.default,
41
+ vue_style_css_1.default,
40
42
  vue_template_html_1.default,
41
43
  vue_template_inline_css_1.default,
42
44
  vue_template_inline_ts_1.default,
package/lib/types.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface VueCompilerOptions {
63
63
  plugins: VueLanguagePlugin[];
64
64
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
65
65
  }
66
- export declare const validVersions: readonly [2, 2.1];
66
+ export declare const validVersions: readonly [2, 2.1, 2.2];
67
67
  export type VueLanguagePluginReturn = {
68
68
  version: typeof validVersions[number];
69
69
  name?: string;
@@ -81,6 +81,7 @@ export type VueLanguagePluginReturn = {
81
81
  resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
82
82
  compileSFCScript?(lang: string, script: string): ts.SourceFile | undefined;
83
83
  compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
84
+ compileSFCStyle?(lang: string, style: string): Pick<Sfc['styles'][number], 'imports' | 'bindings' | 'classNames'> | undefined;
84
85
  updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
85
86
  start: number;
86
87
  end: number;
@@ -139,7 +140,7 @@ export interface Sfc {
139
140
  text: string;
140
141
  offset: number;
141
142
  }[];
142
- cssVars: {
143
+ bindings: {
143
144
  text: string;
144
145
  offset: number;
145
146
  }[];
package/lib/types.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validVersions = void 0;
4
- exports.validVersions = [2, 2.1];
4
+ exports.validVersions = [2, 2.1, 2.2];
5
5
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,9 @@
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
1
2
  import type * as ts from 'typescript';
2
- import type { TextRange } from '../types';
3
+ import type { Sfc, TextRange } from '../types';
3
4
  export { hyphenate as hyphenateTag } from '@vue/shared';
4
5
  export declare function hyphenateAttr(str: string): string;
5
6
  export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
7
+ export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): number[];
6
8
  export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
7
9
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
4
  exports.hyphenateAttr = hyphenateAttr;
5
5
  exports.getSlotsPropertyName = getSlotsPropertyName;
6
+ exports.getElementTagOffsets = getElementTagOffsets;
6
7
  exports.getStartEnd = getStartEnd;
7
8
  exports.getNodeText = getNodeText;
8
9
  const shared_1 = require("@vue/shared");
@@ -19,6 +20,18 @@ function hyphenateAttr(str) {
19
20
  function getSlotsPropertyName(vueVersion) {
20
21
  return vueVersion < 3 ? '$scopedSlots' : '$slots';
21
22
  }
23
+ function getElementTagOffsets(node, template) {
24
+ const tagOffsets = [
25
+ template.content.indexOf(node.tag, node.loc.start.offset),
26
+ ];
27
+ if (!node.isSelfClosing && template.lang === 'html') {
28
+ const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
29
+ if (endTagOffset > tagOffsets[0]) {
30
+ tagOffsets.push(endTagOffset);
31
+ }
32
+ }
33
+ return tagOffsets;
34
+ }
22
35
  function getStartEnd(ts, node, ast) {
23
36
  return {
24
37
  start: ts.getTokenPosOfNode(node, ast),
package/lib/utils/ts.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';
3
- export type ParsedCommandLine = ts.ParsedCommandLine & {
3
+ interface ParseConfigHost extends Omit<ts.ParseConfigHost, 'readDirectory'> {
4
+ }
5
+ export interface ParsedCommandLine extends Omit<ts.ParsedCommandLine, 'fileNames'> {
4
6
  vueOptions: VueCompilerOptions;
5
- };
6
- export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost & {
7
- writeFile?(path: string, data: string): void;
8
- }, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
9
- export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
7
+ }
8
+ export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), host: ParseConfigHost, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
9
+ export declare function createParsedCommandLine(ts: typeof import('typescript'), host: ParseConfigHost, configFileName: string): ParsedCommandLine;
10
10
  export declare class CompilerOptionsResolver {
11
11
  fileExists?: ((path: string) => boolean) | undefined;
12
12
  configRoots: Set<string>;
@@ -21,3 +21,4 @@ export declare class CompilerOptionsResolver {
21
21
  }
22
22
  export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
23
23
  export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
24
+ export {};
package/lib/utils/ts.js CHANGED
@@ -8,15 +8,26 @@ exports.writeGlobalTypes = writeGlobalTypes;
8
8
  const shared_1 = require("@vue/shared");
9
9
  const path_browserify_1 = require("path-browserify");
10
10
  const globalTypes_1 = require("../codegen/globalTypes");
11
- const languagePlugin_1 = require("../languagePlugin");
12
11
  const shared_2 = require("./shared");
13
- function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
14
- const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
15
- ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
16
- const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
17
- for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
12
+ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName) {
13
+ const extendedPaths = new Set();
14
+ const proxyHost = {
15
+ ...host,
16
+ readFile(fileName) {
17
+ if (!fileName.endsWith('/package.json')) {
18
+ extendedPaths.add(fileName);
19
+ }
20
+ return host.readFile(fileName);
21
+ },
22
+ readDirectory() {
23
+ return [];
24
+ },
25
+ };
26
+ const parsed = ts.parseJsonConfigFileContent(json, proxyHost, rootDir, {}, configFileName);
27
+ const resolver = new CompilerOptionsResolver(host.fileExists);
28
+ for (const extendPath of [...extendedPaths].reverse()) {
18
29
  try {
19
- const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
30
+ const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
20
31
  const obj = ts.convertToObject(configFile, []);
21
32
  const rawOptions = obj?.vueCompilerOptions ?? {};
22
33
  resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
@@ -25,82 +36,48 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
25
36
  }
26
37
  // ensure the rootDir is added to the config roots
27
38
  resolver.addConfig({}, rootDir);
28
- const resolvedVueOptions = resolver.build();
29
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
30
- .map(extension => ({
31
- extension: extension.slice(1),
32
- isMixedContent: true,
33
- scriptKind: ts.ScriptKind.Deferred,
34
- })));
35
- // fix https://github.com/vuejs/language-tools/issues/1786
36
- // https://github.com/microsoft/TypeScript/issues/30457
37
- // patching ts server broke with outDir + rootDir + composite/incremental
38
- parsed.options.outDir = undefined;
39
39
  return {
40
40
  ...parsed,
41
- vueOptions: resolvedVueOptions,
41
+ vueOptions: resolver.build(),
42
42
  };
43
43
  }
44
- function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
44
+ function createParsedCommandLine(ts, host, configFileName) {
45
45
  try {
46
- const rootDir = path_browserify_1.posix.dirname(tsConfigPath);
47
- const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
48
- const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
49
- ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, rootDir, {}, tsConfigPath);
50
- const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
51
- for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
46
+ const extendedPaths = new Set();
47
+ const proxyHost = {
48
+ ...host,
49
+ readFile(fileName) {
50
+ if (!fileName.endsWith('/package.json')) {
51
+ extendedPaths.add(fileName);
52
+ }
53
+ return host.readFile(fileName);
54
+ },
55
+ readDirectory() {
56
+ return [];
57
+ },
58
+ };
59
+ const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
60
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
61
+ const resolver = new CompilerOptionsResolver(host.fileExists);
62
+ for (const extendPath of [...extendedPaths].reverse()) {
52
63
  try {
53
- const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
64
+ const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
54
65
  const obj = ts.convertToObject(configFile, []);
55
66
  const rawOptions = obj?.vueCompilerOptions ?? {};
56
67
  resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
57
68
  }
58
69
  catch { }
59
70
  }
60
- const resolvedVueOptions = resolver.build();
61
- const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
62
- .map(extension => ({
63
- extension: extension.slice(1),
64
- isMixedContent: true,
65
- scriptKind: ts.ScriptKind.Deferred,
66
- })));
67
- // fix https://github.com/vuejs/language-tools/issues/1786
68
- // https://github.com/microsoft/TypeScript/issues/30457
69
- // patching ts server broke with outDir + rootDir + composite/incremental
70
- parsed.options.outDir = undefined;
71
71
  return {
72
72
  ...parsed,
73
- vueOptions: resolvedVueOptions,
74
- };
75
- }
76
- catch {
77
- // console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
78
- return {
79
- fileNames: [],
80
- options: {},
81
- vueOptions: getDefaultCompilerOptions(),
82
- errors: [],
73
+ vueOptions: resolver.build(),
83
74
  };
84
75
  }
85
- }
86
- function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
87
- const extendConfigPaths = [];
88
- const host = new Proxy(parseConfigHost, {
89
- get(target, key) {
90
- if (key === 'readFile') {
91
- return (fileName) => {
92
- if (!fileName.endsWith('/package.json') && !extendConfigPaths.includes(fileName)) {
93
- extendConfigPaths.push(fileName);
94
- }
95
- return target.readFile(fileName);
96
- };
97
- }
98
- return target[key];
99
- },
100
- });
76
+ catch { }
101
77
  return {
102
- host,
103
- extendConfigPaths,
78
+ options: {},
79
+ errors: [],
80
+ vueOptions: getDefaultCompilerOptions(),
104
81
  };
105
82
  }
106
83
  class CompilerOptionsResolver {
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.templateInlineTsAsts = void 0;
4
4
  exports.computedSfc = computedSfc;
5
5
  const alien_signals_1 = require("alien-signals");
6
- const parseCssClassNames_1 = require("../utils/parseCssClassNames");
7
- const parseCssImports_1 = require("../utils/parseCssImports");
8
- const parseCssVars_1 = require("../utils/parseCssVars");
9
6
  const signals_1 = require("../utils/signals");
10
7
  exports.templateInlineTsAsts = new WeakMap();
11
8
  function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
@@ -106,9 +103,17 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
106
103
  const getSrc = computedAttrValue('__src', base, getBlock);
107
104
  const getModule = computedAttrValue('__module', base, getBlock);
108
105
  const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
109
- const getImports = (0, signals_1.computedItems)(() => [...(0, parseCssImports_1.parseCssImports)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
110
- const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
111
- const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
106
+ const getIr = (0, alien_signals_1.computed)(() => {
107
+ for (const plugin of plugins) {
108
+ const ast = plugin.compileSFCStyle?.(base.lang, base.content);
109
+ if (ast) {
110
+ return ast;
111
+ }
112
+ }
113
+ });
114
+ const getImports = (0, signals_1.computedItems)(() => getIr()?.imports ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
115
+ const getBindings = (0, signals_1.computedItems)(() => getIr()?.bindings ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
116
+ const getClassNames = (0, signals_1.computedItems)(() => getIr()?.classNames ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
112
117
  return () => mergeObject(base, {
113
118
  get src() {
114
119
  return getSrc();
@@ -122,8 +127,8 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
122
127
  get imports() {
123
128
  return getImports();
124
129
  },
125
- get cssVars() {
126
- return getCssVars();
130
+ get bindings() {
131
+ return getBindings();
127
132
  },
128
133
  get classNames() {
129
134
  return getClassNames();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.22",
16
+ "@volar/language-core": "2.4.23",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
18
  "@vue/compiler-vue2": "^2.7.16",
19
19
  "@vue/shared": "^3.5.0",
@@ -26,7 +26,7 @@
26
26
  "@types/node": "^22.10.4",
27
27
  "@types/path-browserify": "^1.0.1",
28
28
  "@types/picomatch": "^4.0.0",
29
- "@volar/typescript": "2.4.22",
29
+ "@volar/typescript": "2.4.23",
30
30
  "@vue/compiler-sfc": "^3.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "036b6b1882179d35586e16f2a5cba5150e5d18e6"
40
+ "gitHead": "59f8cde8a5148e54294868104312b2b0f4c30d1e"
41
41
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=tenp.js.map
@@ -1,12 +0,0 @@
1
- import type * as ts from 'typescript';
2
- import type { TextRange } from '../types';
3
- export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
4
- range: TextRange;
5
- moduleName?: string;
6
- isDefaultImport?: boolean;
7
- isNamespace?: boolean;
8
- }[];
9
- export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
- start: number;
11
- end: number;
12
- } | undefined;
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseBindingRanges = parseBindingRanges;
4
- exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
- const collectBindings_1 = require("../utils/collectBindings");
6
- const shared_1 = require("../utils/shared");
7
- function parseBindingRanges(ts, ast) {
8
- const bindings = [];
9
- ts.forEachChild(ast, node => {
10
- if (ts.isVariableStatement(node)) {
11
- for (const decl of node.declarationList.declarations) {
12
- const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
- bindings.push(...ranges.map(range => ({ range })));
14
- }
15
- }
16
- else if (ts.isFunctionDeclaration(node)) {
17
- if (node.name && ts.isIdentifier(node.name)) {
18
- bindings.push({
19
- range: _getStartEnd(node.name),
20
- });
21
- }
22
- }
23
- else if (ts.isClassDeclaration(node)) {
24
- if (node.name) {
25
- bindings.push({
26
- range: _getStartEnd(node.name),
27
- });
28
- }
29
- }
30
- else if (ts.isEnumDeclaration(node)) {
31
- bindings.push({
32
- range: _getStartEnd(node.name),
33
- });
34
- }
35
- if (ts.isImportDeclaration(node)) {
36
- const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
- if (node.importClause && !node.importClause.isTypeOnly) {
38
- const { name, namedBindings } = node.importClause;
39
- if (name) {
40
- bindings.push({
41
- range: _getStartEnd(name),
42
- moduleName,
43
- isDefaultImport: true,
44
- });
45
- }
46
- if (namedBindings) {
47
- if (ts.isNamedImports(namedBindings)) {
48
- for (const element of namedBindings.elements) {
49
- if (element.isTypeOnly) {
50
- continue;
51
- }
52
- bindings.push({
53
- range: _getStartEnd(element.name),
54
- moduleName,
55
- isDefaultImport: element.propertyName?.text === 'default',
56
- });
57
- }
58
- }
59
- else {
60
- bindings.push({
61
- range: _getStartEnd(namedBindings.name),
62
- moduleName,
63
- isNamespace: true,
64
- });
65
- }
66
- }
67
- }
68
- }
69
- });
70
- return bindings;
71
- function _getStartEnd(node) {
72
- return (0, shared_1.getStartEnd)(ts, node, ast);
73
- }
74
- function _getNodeText(node) {
75
- return (0, shared_1.getNodeText)(ts, node, ast);
76
- }
77
- }
78
- function getClosestMultiLineCommentRange(ts, node, parents, ast) {
79
- for (let i = parents.length - 1; i >= 0; i--) {
80
- if (ts.isStatement(node)) {
81
- break;
82
- }
83
- node = parents[i];
84
- }
85
- const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
86
- ?.reverse()
87
- .find(range => range.kind === 3);
88
- if (comment) {
89
- return {
90
- start: comment.pos,
91
- end: comment.end,
92
- };
93
- }
94
- }
95
- //# sourceMappingURL=utils.js.map
@@ -1,3 +0,0 @@
1
- import type { VueLanguagePlugin } from '../types';
2
- declare const plugin: VueLanguagePlugin;
3
- export default plugin;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const parseSfc_1 = require("../utils/parseSfc");
4
- const plugin = ({ vueCompilerOptions }) => {
5
- return {
6
- version: 2.1,
7
- getLanguageId(fileName) {
8
- if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
- return 'vue';
10
- }
11
- },
12
- isValidFile(_fileName, languageId) {
13
- return languageId === 'vue';
14
- },
15
- parseSFC2(_fileName, languageId, content) {
16
- if (languageId !== 'vue') {
17
- return;
18
- }
19
- return (0, parseSfc_1.parse)(content);
20
- },
21
- updateSFC(sfc, change) {
22
- const blocks = [
23
- sfc.descriptor.template,
24
- sfc.descriptor.script,
25
- sfc.descriptor.scriptSetup,
26
- ...sfc.descriptor.styles,
27
- ...sfc.descriptor.customBlocks,
28
- ].filter(block => !!block);
29
- const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
30
- if (!hitBlock) {
31
- return;
32
- }
33
- const oldContent = hitBlock.content;
34
- const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
35
- + change.newText
36
- + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
37
- // #3449
38
- const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
39
- const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
40
- if (insertedEndTag) {
41
- return;
42
- }
43
- const lengthDiff = change.newText.length - (change.end - change.start);
44
- for (const block of blocks) {
45
- if (block.loc.start.offset > change.end) {
46
- block.loc.start.offset += lengthDiff;
47
- }
48
- if (block.loc.end.offset >= change.end) {
49
- block.loc.end.offset += lengthDiff;
50
- }
51
- }
52
- return sfc;
53
- },
54
- };
55
- };
56
- exports.default = plugin;
57
- //# sourceMappingURL=file-css.js.map
@@ -1,4 +0,0 @@
1
- export declare function parseCssClassNames(css: string): Generator<{
2
- offset: number;
3
- text: string;
4
- }, void, unknown>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCssClassNames = parseCssClassNames;
4
- const parseCssVars_1 = require("./parseCssVars");
5
- const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
6
- const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
7
- function* parseCssClassNames(css) {
8
- css = (0, parseCssVars_1.fillBlank)(css, parseCssVars_1.commentReg, fragmentReg);
9
- const matches = css.matchAll(cssClassNameReg);
10
- for (const match of matches) {
11
- const matchText = match[1];
12
- if (matchText) {
13
- yield { offset: match.index, text: matchText };
14
- }
15
- }
16
- }
17
- //# sourceMappingURL=parseCssClassNames.js.map
@@ -1,4 +0,0 @@
1
- export declare function parseCssImports(css: string): Generator<{
2
- text: string;
3
- offset: number;
4
- }, void, unknown>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCssImports = parseCssImports;
4
- const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
5
- function* parseCssImports(css) {
6
- const matches = css.matchAll(cssImportReg);
7
- for (const match of matches) {
8
- let text = match[0];
9
- let offset = match.index;
10
- if (text.startsWith("'") || text.startsWith('"')) {
11
- text = text.slice(1, -1);
12
- offset += 1;
13
- }
14
- if (text) {
15
- yield { text, offset };
16
- }
17
- }
18
- }
19
- //# sourceMappingURL=parseCssImports.js.map
@@ -1,6 +0,0 @@
1
- export declare const commentReg: RegExp;
2
- export declare function parseCssVars(css: string): Generator<{
3
- offset: number;
4
- text: string;
5
- }, void, unknown>;
6
- export declare function fillBlank(css: string, ...regs: RegExp[]): string;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- // https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.commentReg = void 0;
5
- exports.parseCssVars = parseCssVars;
6
- exports.fillBlank = fillBlank;
7
- const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
8
- exports.commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
9
- function* parseCssVars(css) {
10
- css = fillBlank(css, exports.commentReg);
11
- const matchs = css.matchAll(vBindCssVarReg);
12
- for (const match of matchs) {
13
- const matchText = match.slice(1).find(t => t);
14
- if (matchText) {
15
- const offset = match.index + css.slice(match.index).indexOf(matchText);
16
- yield { offset, text: matchText };
17
- }
18
- }
19
- }
20
- function fillBlank(css, ...regs) {
21
- for (const reg of regs) {
22
- css = css.replace(reg, match => ' '.repeat(match.length));
23
- }
24
- return css;
25
- }
26
- //# sourceMappingURL=parseCssVars.js.map