@vue/language-core 3.3.6 → 3.3.7

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.
@@ -22,7 +22,7 @@ function generate(options) {
22
22
  function* generateWorker(options, ctx) {
23
23
  const scope = ctx.scope();
24
24
  scope.declare(...options.setupConsts);
25
- yield* (0, scopedClasses_1.generateStyleScopedClasses)(options);
25
+ yield* (0, scopedClasses_1.generateStyleScopedClasses)(options, ctx);
26
26
  yield* (0, modules_1.generateStyleModules)(options, ctx);
27
27
  yield* generateCssVars(options, ctx);
28
28
  yield* scope.end();
@@ -1,4 +1,4 @@
1
1
  import type { Code } from '../../types';
2
2
  import type { TemplateCodegenContext } from '../template/context';
3
3
  import type { StyleCodegenOptions } from '.';
4
- export declare function generateStyleModules({ styles, vueCompilerOptions }: StyleCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
4
+ export declare function generateStyleModules({ vueCompilerOptions, styles }: StyleCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
@@ -5,7 +5,7 @@ const codeFeatures_1 = require("../codeFeatures");
5
5
  const names_1 = require("../names");
6
6
  const utils_1 = require("../utils");
7
7
  const common_1 = require("./common");
8
- function* generateStyleModules({ styles, vueCompilerOptions }, ctx) {
8
+ function* generateStyleModules({ vueCompilerOptions, styles }, ctx) {
9
9
  const styleModules = styles.filter(style => style.module);
10
10
  if (!styleModules.length) {
11
11
  return;
@@ -1,3 +1,4 @@
1
1
  import type { Code } from '../../types';
2
+ import type { TemplateCodegenContext } from '../template/context';
2
3
  import type { StyleCodegenOptions } from '.';
3
- export declare function generateStyleScopedClasses({ vueCompilerOptions, styles }: StyleCodegenOptions): Generator<Code>;
4
+ export declare function generateStyleScopedClasses({ vueCompilerOptions, styles }: StyleCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
@@ -5,7 +5,7 @@ const names_1 = require("../names");
5
5
  const styleScopedClasses_1 = require("../template/styleScopedClasses");
6
6
  const utils_1 = require("../utils");
7
7
  const common_1 = require("./common");
8
- function* generateStyleScopedClasses({ vueCompilerOptions, styles }) {
8
+ function* generateStyleScopedClasses({ vueCompilerOptions, styles }, ctx) {
9
9
  const { resolveStyleClassNames, resolveStyleImports } = vueCompilerOptions;
10
10
  if (!resolveStyleClassNames) {
11
11
  return;
@@ -14,8 +14,9 @@ function* generateStyleScopedClasses({ vueCompilerOptions, styles }) {
14
14
  if (!scopedStyles.length) {
15
15
  return;
16
16
  }
17
+ ctx.generatedTypes.add(names_1.names.StyleScopedClasses);
17
18
  const visited = new Set();
18
- const deferredGenerations = [];
19
+ const deferredGenerates = [];
19
20
  yield `type ${names_1.names.StyleScopedClasses} = {}`;
20
21
  for (const style of scopedStyles) {
21
22
  if (resolveStyleImports) {
@@ -27,12 +28,12 @@ function* generateStyleScopedClasses({ vueCompilerOptions, styles }) {
27
28
  yield* (0, common_1.generateClassProperty)(style.name, className.text, className.offset, 'boolean');
28
29
  }
29
30
  else {
30
- deferredGenerations.push((0, styleScopedClasses_1.generateStyleScopedClassReference)(style, className.text.slice(1), className.offset + 1));
31
+ deferredGenerates.push((0, styleScopedClasses_1.generateStyleScopedClassReference)(style, className.text.slice(1), className.offset + 1));
31
32
  }
32
33
  }
33
34
  }
34
35
  yield utils_1.endOfLine;
35
- for (const generate of deferredGenerations) {
36
+ for (const generate of deferredGenerates) {
36
37
  yield* generate;
37
38
  }
38
39
  }
@@ -229,7 +229,7 @@ function* generateComponent(options, ctx, node) {
229
229
  ctx.inheritedAttrVars.add(getPropsVar());
230
230
  }
231
231
  }
232
- yield* generateStyleScopedClassReferences(options, node);
232
+ yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(options, node);
233
233
  const slotDir = node.props.find(CompilerDOM.isVSlot);
234
234
  if (slotDir || node.children.length) {
235
235
  yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
@@ -275,7 +275,7 @@ function* generateElement(options, ctx, node) {
275
275
  if (hasVBindAttrs(options, ctx, node)) {
276
276
  ctx.inheritedAttrVars.add(`${names_1.names.intrinsics}.${node.tag}`);
277
277
  }
278
- yield* generateStyleScopedClassReferences(options, node);
278
+ yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(options, node);
279
279
  for (const child of node.children) {
280
280
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
281
281
  }
@@ -296,92 +296,6 @@ function* generateFragment(options, ctx, node) {
296
296
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
297
297
  }
298
298
  }
299
- function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
300
- for (const prop of node.props) {
301
- if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
302
- && prop.name === 'class'
303
- && prop.value) {
304
- const [text, start] = (0, shared_2.normalizeAttributeValue)(prop.value);
305
- for (const [className, offset] of forEachClassName(text)) {
306
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, className, start + offset);
307
- }
308
- }
309
- else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
310
- && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
311
- && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
312
- && prop.arg.content === 'class') {
313
- const content = '(' + prop.exp.content + ')';
314
- const startOffset = prop.exp.loc.start.offset - 1;
315
- const ast = (0, utils_1.getTypeScriptAST)(ts, template, content);
316
- const literals = [];
317
- for (const node of (0, utils_1.forEachNode)(ts, ast)) {
318
- if (!ts.isExpressionStatement(node)
319
- || !ts.isParenthesizedExpression(node.expression)) {
320
- continue;
321
- }
322
- const { expression } = node.expression;
323
- if (ts.isStringLiteralLike(expression)) {
324
- literals.push(expression);
325
- }
326
- else if (ts.isArrayLiteralExpression(expression)) {
327
- yield* walkArrayLiteral(expression);
328
- }
329
- else if (ts.isObjectLiteralExpression(expression)) {
330
- yield* walkObjectLiteral(expression);
331
- }
332
- }
333
- for (const literal of literals) {
334
- const start = literal.end - literal.text.length - 1 + startOffset;
335
- for (const [className, offset] of forEachClassName(literal.text)) {
336
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, className, start + offset);
337
- }
338
- }
339
- function* walkArrayLiteral(node) {
340
- const { elements } = node;
341
- for (const element of elements) {
342
- if (ts.isStringLiteralLike(element)) {
343
- literals.push(element);
344
- }
345
- else if (ts.isObjectLiteralExpression(element)) {
346
- yield* walkObjectLiteral(element);
347
- }
348
- }
349
- }
350
- function* walkObjectLiteral(node) {
351
- const { properties } = node;
352
- for (const property of properties) {
353
- if (ts.isPropertyAssignment(property)) {
354
- const { name } = property;
355
- if (ts.isIdentifier(name)) {
356
- const text = (0, shared_2.getNodeText)(ts, name, ast);
357
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, name.end - text.length + startOffset);
358
- }
359
- else if (ts.isStringLiteral(name)) {
360
- literals.push(name);
361
- }
362
- else if (ts.isComputedPropertyName(name)) {
363
- const { expression } = name;
364
- if (ts.isStringLiteralLike(expression)) {
365
- literals.push(expression);
366
- }
367
- }
368
- }
369
- else if (ts.isShorthandPropertyAssignment(property)) {
370
- const text = (0, shared_2.getNodeText)(ts, property.name, ast);
371
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, property.name.end - text.length + startOffset);
372
- }
373
- }
374
- }
375
- }
376
- }
377
- }
378
- function* forEachClassName(content) {
379
- let offset = 0;
380
- for (const className of content.split(' ')) {
381
- yield [className, offset];
382
- offset += className.length + 1;
383
- }
384
- }
385
299
  function* generateFailedExpressions(options, ctx, failedPropExps) {
386
300
  for (const { node, prefix, suffix } of failedPropExps) {
387
301
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, node.loc.source, node.loc.start.offset, prefix, suffix);
@@ -154,9 +154,13 @@ function* generateEventExpression(options, ctx, prop) {
154
154
  scope.declare('$event');
155
155
  yield* ctx.generateConditionGuards();
156
156
  if (isSingleExpression(options.typescript, ast)) {
157
- yield `return `;
157
+ yield `return (`;
158
+ yield* interpolation;
159
+ yield `)`;
160
+ }
161
+ else {
162
+ yield* interpolation;
158
163
  }
159
- yield* interpolation;
160
164
  yield utils_2.endOfLine;
161
165
  yield* scope.end();
162
166
  yield `}`;
@@ -1,3 +1,6 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
1
2
  import type { Code, IRBlock } from '../../types';
3
+ import type { TemplateCodegenOptions } from './index';
2
4
  export declare const references: WeakMap<IRBlock, [version: string, [className: string, offset: number][]]>;
5
+ export declare function generateStyleScopedClassReferences({ template, typescript: ts }: TemplateCodegenOptions, node: CompilerDOM.ElementNode): Generator<Code>;
3
6
  export declare function generateStyleScopedClassReference(block: IRBlock, className: string, offset: number, fullStart?: number): Generator<Code>;
@@ -1,7 +1,43 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.references = void 0;
37
+ exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
4
38
  exports.generateStyleScopedClassReference = generateStyleScopedClassReference;
39
+ const CompilerDOM = __importStar(require("@vue/compiler-dom"));
40
+ const shared_1 = require("../../utils/shared");
5
41
  const codeFeatures_1 = require("../codeFeatures");
6
42
  const names_1 = require("../names");
7
43
  const utils_1 = require("../utils");
@@ -10,6 +46,92 @@ const escaped_1 = require("../utils/escaped");
10
46
  const classNameEscapeRE = /([\\'])/;
11
47
  // For language-service/lib/plugins/vue-scoped-class-links.ts usage
12
48
  exports.references = new WeakMap();
49
+ function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
50
+ for (const prop of node.props) {
51
+ if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
52
+ && prop.name === 'class'
53
+ && prop.value) {
54
+ const [text, start] = (0, shared_1.normalizeAttributeValue)(prop.value);
55
+ for (const [className, offset] of forEachClassName(text)) {
56
+ yield* generateStyleScopedClassReference(template, className, start + offset);
57
+ }
58
+ }
59
+ else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
60
+ && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
61
+ && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
62
+ && prop.arg.content === 'class') {
63
+ const content = '(' + prop.exp.content + ')';
64
+ const startOffset = prop.exp.loc.start.offset - 1;
65
+ const ast = (0, utils_1.getTypeScriptAST)(ts, template, content);
66
+ const literals = [];
67
+ for (const node of (0, utils_1.forEachNode)(ts, ast)) {
68
+ if (!ts.isExpressionStatement(node)
69
+ || !ts.isParenthesizedExpression(node.expression)) {
70
+ continue;
71
+ }
72
+ const { expression } = node.expression;
73
+ if (ts.isStringLiteralLike(expression)) {
74
+ literals.push(expression);
75
+ }
76
+ else if (ts.isArrayLiteralExpression(expression)) {
77
+ yield* walkArrayLiteral(expression);
78
+ }
79
+ else if (ts.isObjectLiteralExpression(expression)) {
80
+ yield* walkObjectLiteral(expression);
81
+ }
82
+ }
83
+ for (const literal of literals) {
84
+ const start = literal.end - literal.text.length - 1 + startOffset;
85
+ for (const [className, offset] of forEachClassName(literal.text)) {
86
+ yield* generateStyleScopedClassReference(template, className, start + offset);
87
+ }
88
+ }
89
+ function* walkArrayLiteral(node) {
90
+ const { elements } = node;
91
+ for (const element of elements) {
92
+ if (ts.isStringLiteralLike(element)) {
93
+ literals.push(element);
94
+ }
95
+ else if (ts.isObjectLiteralExpression(element)) {
96
+ yield* walkObjectLiteral(element);
97
+ }
98
+ }
99
+ }
100
+ function* walkObjectLiteral(node) {
101
+ const { properties } = node;
102
+ for (const property of properties) {
103
+ if (ts.isPropertyAssignment(property)) {
104
+ const { name } = property;
105
+ if (ts.isIdentifier(name)) {
106
+ const text = (0, shared_1.getNodeText)(ts, name, ast);
107
+ yield* generateStyleScopedClassReference(template, text, name.end - text.length + startOffset);
108
+ }
109
+ else if (ts.isStringLiteral(name)) {
110
+ literals.push(name);
111
+ }
112
+ else if (ts.isComputedPropertyName(name)) {
113
+ const { expression } = name;
114
+ if (ts.isStringLiteralLike(expression)) {
115
+ literals.push(expression);
116
+ }
117
+ }
118
+ }
119
+ else if (ts.isShorthandPropertyAssignment(property)) {
120
+ const text = (0, shared_1.getNodeText)(ts, property.name, ast);
121
+ yield* generateStyleScopedClassReference(template, text, property.name.end - text.length + startOffset);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ function* forEachClassName(content) {
129
+ let offset = 0;
130
+ for (const className of content.split(' ')) {
131
+ yield [className, offset];
132
+ offset += className.length + 1;
133
+ }
134
+ }
13
135
  function* generateStyleScopedClassReference(block, className, offset, fullStart = offset) {
14
136
  if (!className) {
15
137
  yield `/** @type {${names_1.names.StyleScopedClasses}['`;
package/lib/types.d.ts CHANGED
@@ -71,7 +71,7 @@ export interface VueCompilerOptions {
71
71
  }
72
72
  export declare const validVersions: readonly [2, 2.1, 2.2];
73
73
  export interface VueLanguagePluginReturn {
74
- version: (typeof validVersions)[number];
74
+ version: typeof validVersions[number];
75
75
  name?: string;
76
76
  order?: number;
77
77
  requiredCompilerOptions?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.3.6",
3
+ "version": "3.3.7",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "index.d.ts",
@@ -22,17 +22,17 @@
22
22
  "@volar/language-core": "2.4.28",
23
23
  "@vue/compiler-dom": "^3.5.0",
24
24
  "@vue/shared": "^3.5.0",
25
- "alien-signals": "^3.2.0",
25
+ "alien-signals": "^3.2.1",
26
26
  "muggle-string": "^0.4.1",
27
27
  "path-browserify": "^1.0.1",
28
28
  "picomatch": "^4.0.4"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/node": "^24.1.0",
31
+ "@types/node": "^26.0.1",
32
32
  "@types/path-browserify": "^1.0.3",
33
33
  "@types/picomatch": "^4.0.3",
34
34
  "@volar/typescript": "2.4.28",
35
35
  "@vue/compiler-sfc": "^3.5.0"
36
36
  },
37
- "gitHead": "4893ec6a4b5ca0d00f8add9aa36c17c47085f05a"
37
+ "gitHead": "f6cc297eb9b2fddb3bed535b099b9697c909764d"
38
38
  }