@vue/language-core 2.2.4 → 2.2.8

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 (43) hide show
  1. package/lib/codegen/globalTypes.js +1 -6
  2. package/lib/codegen/script/component.js +1 -3
  3. package/lib/codegen/script/componentSelf.js +4 -11
  4. package/lib/codegen/script/context.d.ts +0 -1
  5. package/lib/codegen/script/context.js +0 -1
  6. package/lib/codegen/script/index.d.ts +1 -4
  7. package/lib/codegen/script/index.js +4 -6
  8. package/lib/codegen/script/scriptSetup.js +46 -37
  9. package/lib/codegen/script/styleModulesType.d.ts +4 -0
  10. package/lib/codegen/script/styleModulesType.js +34 -0
  11. package/lib/codegen/script/template.js +1 -3
  12. package/lib/codegen/style/classProperty.js +4 -17
  13. package/lib/codegen/template/context.js +2 -1
  14. package/lib/codegen/template/element.js +13 -12
  15. package/lib/codegen/template/elementDirectives.js +6 -5
  16. package/lib/codegen/template/elementEvents.js +5 -5
  17. package/lib/codegen/template/elementProps.js +15 -14
  18. package/lib/codegen/template/index.js +2 -1
  19. package/lib/codegen/template/objectProperty.js +5 -4
  20. package/lib/codegen/template/propertyAccess.js +1 -1
  21. package/lib/codegen/template/slotOutlet.js +4 -3
  22. package/lib/codegen/template/styleScopedClasses.js +4 -50
  23. package/lib/codegen/template/vIf.js +2 -6
  24. package/lib/codegen/template/vSlot.js +3 -2
  25. package/lib/codegen/utils/camelized.d.ts +1 -1
  26. package/lib/codegen/utils/camelized.js +6 -6
  27. package/lib/codegen/utils/escaped.d.ts +2 -0
  28. package/lib/codegen/utils/escaped.js +23 -0
  29. package/lib/codegen/utils/index.d.ts +1 -2
  30. package/lib/codegen/utils/index.js +2 -14
  31. package/lib/codegen/utils/objectProperty.d.ts +3 -0
  32. package/lib/codegen/utils/objectProperty.js +41 -0
  33. package/lib/codegen/utils/stringLiteralKey.js +2 -1
  34. package/lib/codegen/utils/unicode.js +2 -2
  35. package/lib/codegen/utils/wrapWith.d.ts +3 -0
  36. package/lib/codegen/utils/wrapWith.js +24 -0
  37. package/lib/parsers/scriptSetupRanges.d.ts +2 -0
  38. package/lib/parsers/scriptSetupRanges.js +64 -78
  39. package/lib/plugins/vue-tsx.d.ts +2 -3
  40. package/lib/plugins/vue-tsx.js +0 -9
  41. package/lib/types.d.ts +1 -0
  42. package/lib/virtualFile/computedEmbeddedCodes.js +17 -0
  43. package/package.json +2 -2
@@ -74,91 +74,48 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
74
74
  if (ts.isCallExpression(node)
75
75
  && ts.isIdentifier(node.expression)) {
76
76
  const callText = _getNodeText(node.expression);
77
- if (vueCompilerOptions.macros.defineModel.includes(callText)) {
77
+ const isDefineModel = vueCompilerOptions.macros.defineModel.includes(callText);
78
+ if (isDefineModel || callText === 'defineProp') {
78
79
  let localName;
79
80
  let propName;
80
81
  let options;
82
+ let type;
83
+ let modifierType;
84
+ let runtimeType;
85
+ let defaultValue;
86
+ let required = false;
81
87
  if (ts.isVariableDeclaration(parent) &&
82
88
  ts.isIdentifier(parent.name)) {
83
89
  localName = _getStartEnd(parent.name);
84
90
  }
85
- if (node.arguments.length >= 2) {
86
- propName = _getStartEnd(node.arguments[0]);
87
- options = node.arguments[1];
88
- }
89
- else if (node.arguments.length >= 1) {
90
- if (ts.isStringLiteralLike(node.arguments[0])) {
91
- propName = _getStartEnd(node.arguments[0]);
91
+ if (node.typeArguments) {
92
+ if (node.typeArguments.length >= 1) {
93
+ type = _getStartEnd(node.typeArguments[0]);
92
94
  }
93
- else {
94
- options = node.arguments[0];
95
+ if (node.typeArguments.length >= 2) {
96
+ modifierType = _getStartEnd(node.typeArguments[1]);
95
97
  }
96
98
  }
97
- let runtimeType;
98
- let defaultValue;
99
- let required = false;
100
- if (options && ts.isObjectLiteralExpression(options)) {
101
- for (const property of options.properties) {
102
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
103
- continue;
104
- }
105
- const text = _getNodeText(property.name);
106
- if (text === 'type') {
107
- runtimeType = _getStartEnd(property.initializer);
108
- }
109
- else if (text === 'default') {
110
- defaultValue = _getStartEnd(property.initializer);
99
+ if (isDefineModel) {
100
+ if (node.arguments.length >= 2) {
101
+ propName = node.arguments[0];
102
+ options = node.arguments[1];
103
+ }
104
+ else if (node.arguments.length >= 1) {
105
+ if (ts.isStringLiteralLike(node.arguments[0])) {
106
+ propName = node.arguments[0];
111
107
  }
112
- else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
113
- required = true;
108
+ else {
109
+ options = node.arguments[0];
114
110
  }
115
111
  }
116
112
  }
117
- defineProp.push({
118
- localName,
119
- name: propName,
120
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
121
- modifierType: node.typeArguments && node.typeArguments?.length >= 2 ? _getStartEnd(node.typeArguments[1]) : undefined,
122
- runtimeType,
123
- defaultValue,
124
- required,
125
- isModel: true,
126
- });
127
- }
128
- else if (callText === 'defineProp') {
129
- let localName;
130
- let propName;
131
- let options;
132
- if (ts.isVariableDeclaration(parent) &&
133
- ts.isIdentifier(parent.name)) {
134
- localName = _getStartEnd(parent.name);
135
- }
136
- let runtimeType;
137
- let defaultValue;
138
- let required = false;
139
- if (definePropProposalA) {
113
+ else if (definePropProposalA) {
140
114
  if (node.arguments.length >= 2) {
141
115
  options = node.arguments[1];
142
116
  }
143
117
  if (node.arguments.length >= 1) {
144
- propName = _getStartEnd(node.arguments[0]);
145
- }
146
- if (options && ts.isObjectLiteralExpression(options)) {
147
- for (const property of options.properties) {
148
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
149
- continue;
150
- }
151
- const text = _getNodeText(property.name);
152
- if (text === 'type') {
153
- runtimeType = _getStartEnd(property.initializer);
154
- }
155
- else if (text === 'default') {
156
- defaultValue = _getStartEnd(property.initializer);
157
- }
158
- else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
159
- required = true;
160
- }
161
- }
118
+ propName = node.arguments[0];
162
119
  }
163
120
  }
164
121
  else if (definePropProposalB) {
@@ -173,25 +130,39 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
173
130
  if (node.arguments.length >= 1) {
174
131
  defaultValue = _getStartEnd(node.arguments[0]);
175
132
  }
176
- if (options && ts.isObjectLiteralExpression(options)) {
177
- for (const property of options.properties) {
178
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
179
- continue;
180
- }
181
- const text = _getNodeText(property.name);
182
- if (text === 'type') {
183
- runtimeType = _getStartEnd(property.initializer);
184
- }
133
+ }
134
+ if (options && ts.isObjectLiteralExpression(options)) {
135
+ for (const property of options.properties) {
136
+ if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
137
+ continue;
138
+ }
139
+ const text = _getNodeText(property.name);
140
+ if (text === 'type') {
141
+ runtimeType = _getStartEnd(property.initializer);
142
+ }
143
+ else if (text === 'default') {
144
+ defaultValue = _getStartEnd(property.initializer);
145
+ }
146
+ else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
147
+ required = true;
185
148
  }
186
149
  }
187
150
  }
151
+ let name;
152
+ if (propName && ts.isStringLiteralLike(propName)) {
153
+ name = _getStartEnd(propName);
154
+ }
188
155
  defineProp.push({
189
156
  localName,
190
- name: propName,
191
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
157
+ name,
158
+ type,
159
+ modifierType,
192
160
  runtimeType,
193
161
  defaultValue,
194
162
  required,
163
+ isModel: isDefineModel,
164
+ comments: getCommentsRange(ts, node, parents, ast),
165
+ argNode: options,
195
166
  });
196
167
  }
197
168
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
@@ -451,4 +422,19 @@ function getStatementRange(ts, parents, node, ast) {
451
422
  }
452
423
  return statementRange;
453
424
  }
425
+ function getCommentsRange(ts, node, parents, ast) {
426
+ for (let i = parents.length - 1; i >= 0; i--) {
427
+ if (ts.isStatement(node)) {
428
+ break;
429
+ }
430
+ node = parents[i];
431
+ }
432
+ const comments = ts.getLeadingCommentRanges(ast.text, node.pos);
433
+ if (comments?.length) {
434
+ return {
435
+ start: comments[0].pos,
436
+ end: comments.at(-1).end,
437
+ };
438
+ }
439
+ }
454
440
  //# sourceMappingURL=scriptSetupRanges.js.map
@@ -1,4 +1,3 @@
1
- import type { Mapping } from '@volar/language-core';
2
1
  import type { Code, Sfc, VueLanguagePlugin } from '../types';
3
2
  export declare const tsCodegen: WeakMap<Sfc, {
4
3
  getScriptRanges: () => {
@@ -38,6 +37,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
38
37
  defaultValue?: import("../types").TextRange;
39
38
  required?: boolean;
40
39
  isModel?: boolean;
40
+ comments?: import("../types").TextRange;
41
+ argNode?: import("typescript").Expression;
41
42
  }[];
42
43
  defineProps: ({
43
44
  callExp: import("../types").TextRange;
@@ -118,10 +119,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
118
119
  getLang: () => string;
119
120
  getGeneratedScript: () => {
120
121
  codes: Code[];
121
- linkedCodeMappings: Mapping<unknown>[];
122
122
  generatedTemplate: boolean;
123
123
  generatedPropsType: boolean;
124
- scriptSetupGeneratedOffset: number | undefined;
125
124
  bypassDefineComponent: boolean;
126
125
  bindingNames: Set<string>;
127
126
  localTypes: {
@@ -35,7 +35,6 @@ const plugin = ctx => {
35
35
  const tsx = codegen.getGeneratedScript();
36
36
  if (tsx) {
37
37
  embeddedFile.content = [...tsx.codes];
38
- embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
39
38
  }
40
39
  }
41
40
  },
@@ -168,8 +167,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
168
167
  };
169
168
  });
170
169
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
171
- const linkedCodeMappings = [];
172
- let generatedLength = 0;
173
170
  const codes = [];
174
171
  const codegen = (0, script_1.generateScript)({
175
172
  ts,
@@ -184,8 +181,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
184
181
  templateCodegen: getGeneratedTemplate(),
185
182
  destructuredPropNames: getSetupDestructuredPropNames(),
186
183
  templateRefNames: getSetupTemplateRefNames(),
187
- getGeneratedLength: () => generatedLength,
188
- linkedCodeMappings,
189
184
  appendGlobalTypes,
190
185
  });
191
186
  fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
@@ -193,15 +188,11 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
193
188
  while (!current.done) {
194
189
  const code = current.value;
195
190
  codes.push(code);
196
- generatedLength += typeof code === 'string'
197
- ? code.length
198
- : code[0].length;
199
191
  current = codegen.next();
200
192
  }
201
193
  return {
202
194
  ...current.value,
203
195
  codes,
204
- linkedCodeMappings,
205
196
  };
206
197
  });
207
198
  return {
package/lib/types.d.ts CHANGED
@@ -13,6 +13,7 @@ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' |
13
13
  };
14
14
  export interface VueCodeInformation extends CodeInformation {
15
15
  __combineOffset?: number;
16
+ __linkedToken?: symbol;
16
17
  }
17
18
  export type Code = Segment<VueCodeInformation>;
18
19
  export interface VueCompilerOptions {
@@ -171,6 +171,7 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByN
171
171
  ];
172
172
  }));
173
173
  const newMappings = [];
174
+ const tokenMappings = new Map();
174
175
  for (let i = 0; i < mappings.length; i++) {
175
176
  const mapping = mappings[i];
176
177
  if (mapping.data.__combineOffset !== undefined) {
@@ -183,6 +184,22 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByN
183
184
  offsetMapping.lengths.push(...mapping.lengths);
184
185
  continue;
185
186
  }
187
+ if (mapping.data.__linkedToken !== undefined) {
188
+ const token = mapping.data.__linkedToken;
189
+ if (tokenMappings.has(token)) {
190
+ const prevMapping = tokenMappings.get(token);
191
+ code.linkedCodeMappings.push({
192
+ sourceOffsets: [prevMapping.generatedOffsets[0]],
193
+ generatedOffsets: [mapping.generatedOffsets[0]],
194
+ lengths: [Number(token.description)],
195
+ data: undefined,
196
+ });
197
+ }
198
+ else {
199
+ tokenMappings.set(token, mapping);
200
+ }
201
+ continue;
202
+ }
186
203
  newMappings.push(mapping);
187
204
  }
188
205
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.2.4",
3
+ "version": "2.2.8",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "c28986596935cb43979c9d437c25f292bdb36cef"
40
+ "gitHead": "cdf00e6f19971260607ea2347924b94126a254fc"
41
41
  }