@vue/language-core 2.2.2 → 2.2.4

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 (72) hide show
  1. package/lib/codegen/globalTypes.js +20 -28
  2. package/lib/codegen/script/component.js +10 -6
  3. package/lib/codegen/script/index.js +4 -6
  4. package/lib/codegen/script/scriptSetup.js +45 -34
  5. package/lib/codegen/script/src.d.ts +2 -2
  6. package/lib/codegen/script/src.js +36 -37
  7. package/lib/codegen/script/template.d.ts +1 -2
  8. package/lib/codegen/script/template.js +4 -50
  9. package/lib/codegen/style/classProperty.d.ts +2 -0
  10. package/lib/codegen/style/classProperty.js +31 -0
  11. package/lib/codegen/style/modules.d.ts +3 -0
  12. package/lib/codegen/{script/styleModulesType.js → style/modules.js} +14 -14
  13. package/lib/codegen/style/scopedClasses.d.ts +4 -0
  14. package/lib/codegen/style/scopedClasses.js +32 -0
  15. package/lib/codegen/template/context.d.ts +106 -5
  16. package/lib/codegen/template/context.js +129 -5
  17. package/lib/codegen/template/element.d.ts +1 -1
  18. package/lib/codegen/template/element.js +61 -85
  19. package/lib/codegen/template/elementChildren.d.ts +1 -1
  20. package/lib/codegen/template/elementChildren.js +1 -13
  21. package/lib/codegen/template/elementDirectives.js +2 -1
  22. package/lib/codegen/template/elementEvents.d.ts +1 -1
  23. package/lib/codegen/template/elementEvents.js +15 -11
  24. package/lib/codegen/template/elementProps.d.ts +1 -1
  25. package/lib/codegen/template/elementProps.js +11 -9
  26. package/lib/codegen/template/index.js +27 -13
  27. package/lib/codegen/template/interpolation.js +5 -5
  28. package/lib/codegen/template/slotOutlet.js +11 -10
  29. package/lib/codegen/template/styleScopedClasses.js +5 -9
  30. package/lib/codegen/template/templateChild.js +60 -28
  31. package/lib/codegen/template/vFor.js +2 -2
  32. package/lib/codegen/template/vIf.js +3 -3
  33. package/lib/codegen/template/vSlot.d.ts +1 -0
  34. package/lib/codegen/template/vSlot.js +12 -0
  35. package/lib/codegen/utils/index.d.ts +2 -1
  36. package/lib/codegen/utils/index.js +18 -2
  37. package/lib/parsers/scriptSetupRanges.js +20 -28
  38. package/lib/plugins/file-md.js +3 -0
  39. package/lib/plugins/vue-template-inline-ts.js +3 -3
  40. package/lib/plugins/vue-tsx.d.ts +9 -5
  41. package/lib/plugins/vue-tsx.js +20 -20
  42. package/lib/types.d.ts +23 -14
  43. package/lib/utils/parseSfc.js +40 -16
  44. package/lib/utils/ts.js +17 -0
  45. package/lib/virtualFile/computedEmbeddedCodes.js +3 -13
  46. package/lib/virtualFile/computedSfc.js +21 -28
  47. package/lib/virtualFile/vueFile.d.ts +7 -10
  48. package/lib/virtualFile/vueFile.js +10 -4
  49. package/package.json +2 -2
  50. package/lib/codeFeatures.d.ts +0 -1
  51. package/lib/codeFeatures.js +0 -3
  52. package/lib/codegen/common.d.ts +0 -12
  53. package/lib/codegen/common.js +0 -79
  54. package/lib/codegen/script/binding.d.ts +0 -4
  55. package/lib/codegen/script/binding.js +0 -41
  56. package/lib/codegen/script/styleModulesType.d.ts +0 -4
  57. package/lib/codegen/template/camelized.d.ts +0 -2
  58. package/lib/codegen/template/camelized.js +0 -31
  59. package/lib/codegen/utils/src.d.ts +0 -2
  60. package/lib/codegen/utils/src.js +0 -19
  61. package/lib/plugins/vue-style-class-names.d.ts +0 -5
  62. package/lib/plugins/vue-style-class-names.js +0 -32
  63. package/lib/plugins/vue-style-reference-link.d.ts +0 -1
  64. package/lib/plugins/vue-style-reference-link.js +0 -3
  65. package/lib/plugins/vue-style-reference-links.d.ts +0 -3
  66. package/lib/plugins/vue-style-reference-links.js +0 -26
  67. package/lib/plugins/vue-vine.d.ts +0 -3
  68. package/lib/plugins/vue-vine.js +0 -35
  69. package/lib/utils/findDestructuredProps.d.ts +0 -1
  70. package/lib/utils/findDestructuredProps.js +0 -3
  71. package/lib/utils/parseCssImports.d.ts +0 -4
  72. package/lib/utils/parseCssImports.js +0 -19
@@ -1,6 +1,6 @@
1
1
  import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type * as ts from 'typescript';
3
- import type { Code, SfcBlock, VueCodeInformation } from '../../types';
3
+ import type { Code, SfcBlock, SfcBlockAttr, VueCodeInformation } from '../../types';
4
4
  export declare const newLine = "\n";
5
5
  export declare const endOfLine = ";\n";
6
6
  export declare const combineLastMapping: VueCodeInformation;
@@ -19,3 +19,4 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
19
19
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
20
20
  export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
21
21
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
22
+ export declare function generateSfcBlockAttrValue(src: SfcBlockAttr & object, text: string, features: VueCodeInformation): Generator<Code>;
@@ -7,10 +7,11 @@ exports.collectIdentifiers = collectIdentifiers;
7
7
  exports.normalizeAttributeValue = normalizeAttributeValue;
8
8
  exports.createTsAst = createTsAst;
9
9
  exports.generateSfcBlockSection = generateSfcBlockSection;
10
+ exports.generateSfcBlockAttrValue = generateSfcBlockAttrValue;
10
11
  const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
11
12
  exports.newLine = `\n`;
12
13
  exports.endOfLine = `;${exports.newLine}`;
13
- exports.combineLastMapping = { __combineLastMapping: true };
14
+ exports.combineLastMapping = { __combineOffset: 1 };
14
15
  exports.variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
15
16
  function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
16
17
  yield ['', 'template', startOffset, features];
@@ -21,7 +22,7 @@ function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
21
22
  }
22
23
  yield wrapCode;
23
24
  }
24
- yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
25
+ yield ['', 'template', endOffset, { __combineOffset: offset }];
25
26
  }
26
27
  function collectVars(ts, node, ast, results = []) {
27
28
  const identifiers = collectIdentifiers(ts, node, []);
@@ -76,4 +77,19 @@ function generateSfcBlockSection(block, start, end, features) {
76
77
  features,
77
78
  ];
78
79
  }
80
+ function* generateSfcBlockAttrValue(src, text, features) {
81
+ const { offset, quotes } = src;
82
+ if (!quotes) {
83
+ yield [``, 'main', offset, { verification: true }];
84
+ }
85
+ yield [
86
+ `'${text}'`,
87
+ 'main',
88
+ quotes ? offset - 1 : offset,
89
+ features
90
+ ];
91
+ if (!quotes) {
92
+ yield [``, 'main', offset + text.length, { __combineOffset: 2 }];
93
+ }
94
+ }
79
95
  //# sourceMappingURL=index.js.map
@@ -196,26 +196,21 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
196
196
  }
197
197
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
198
198
  defineProps = {
199
- ...parseCallExpression(node),
199
+ ...parseCallExpressionAssignment(node, parent),
200
200
  statement: getStatementRange(ts, parents, node, ast),
201
201
  argNode: node.arguments[0]
202
202
  };
203
- if (ts.isVariableDeclaration(parent)) {
204
- if (ts.isObjectBindingPattern(parent.name)) {
205
- defineProps.destructured = new Map();
206
- const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
207
- for (const { id, isRest, initializer } of identifiers) {
208
- const name = _getNodeText(id);
209
- if (isRest) {
210
- defineProps.destructuredRest = name;
211
- }
212
- else {
213
- defineProps.destructured.set(name, initializer);
214
- }
203
+ if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
204
+ defineProps.destructured = new Map();
205
+ const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
206
+ for (const { id, isRest, initializer } of identifiers) {
207
+ const name = _getNodeText(id);
208
+ if (isRest) {
209
+ defineProps.destructuredRest = name;
210
+ }
211
+ else {
212
+ defineProps.destructured.set(name, initializer);
215
213
  }
216
- }
217
- else {
218
- defineProps.name = _getNodeText(parent.name);
219
214
  }
220
215
  }
221
216
  else if (ts.isCallExpression(parent)
@@ -237,12 +232,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
237
232
  }
238
233
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
239
234
  defineEmits = {
240
- ...parseCallExpression(node),
235
+ ...parseCallExpressionAssignment(node, parent),
241
236
  statement: getStatementRange(ts, parents, node, ast)
242
237
  };
243
- if (ts.isVariableDeclaration(parent)) {
244
- defineEmits.name = _getNodeText(parent.name);
245
- }
246
238
  if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
247
239
  for (const member of node.typeArguments[0].members) {
248
240
  if (ts.isCallSignatureDeclaration(member)) {
@@ -257,12 +249,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
257
249
  }
258
250
  else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
259
251
  defineSlots = {
260
- ...parseCallExpression(node),
252
+ ...parseCallExpressionAssignment(node, parent),
261
253
  statement: getStatementRange(ts, parents, node, ast)
262
254
  };
263
- if (ts.isVariableDeclaration(parent)) {
264
- defineSlots.name = _getNodeText(parent.name);
265
- }
266
255
  }
267
256
  else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
268
257
  defineExpose = parseCallExpression(node);
@@ -295,10 +284,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
295
284
  }
296
285
  else if (vueCompilerOptions.composables.useTemplateRef.includes(callText)
297
286
  && !node.typeArguments?.length) {
298
- useTemplateRef.push({
299
- name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
300
- ...parseCallExpression(node)
301
- });
287
+ useTemplateRef.push(parseCallExpressionAssignment(node, parent));
302
288
  }
303
289
  }
304
290
  ts.forEachChild(node, child => {
@@ -318,6 +304,12 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
318
304
  typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
319
305
  };
320
306
  }
307
+ function parseCallExpressionAssignment(node, parent) {
308
+ return {
309
+ name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
310
+ ...parseCallExpression(node),
311
+ };
312
+ }
321
313
  function _getStartEnd(node) {
322
314
  return getStartEnd(ts, node, ast);
323
315
  }
@@ -6,6 +6,7 @@ const buildMappings_1 = require("../utils/buildMappings");
6
6
  const parseSfc_1 = require("../utils/parseSfc");
7
7
  const codeblockReg = /(`{3,})[\s\S]+?\1/g;
8
8
  const inlineCodeblockReg = /`[^\n`]+?`/g;
9
+ const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
9
10
  const scriptSetupReg = /\\\<[\s\S]+?\>\n?/g;
10
11
  const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g;
11
12
  const angleBracketReg = /\<\S*\:\S*\>/g;
@@ -31,6 +32,8 @@ const plugin = ({ vueCompilerOptions }) => {
31
32
  .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
32
33
  // inline code block
33
34
  .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
35
+ // latex block
36
+ .replace(latexBlockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
34
37
  // # \<script setup>
35
38
  .replace(scriptSetupReg, match => ' '.repeat(match.length))
36
39
  // <<< https://vitepress.dev/guide/markdown#import-code-snippets
@@ -60,10 +60,10 @@ const plugin = ctx => {
60
60
  return data;
61
61
  function visit(node) {
62
62
  if (node.type === CompilerDOM.NodeTypes.COMMENT) {
63
- const match = node.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
63
+ const match = node.loc.source.match(/^<!--\s*@vue-generic\s*\{(?<content>[\s\S]*)\}\s*-->$/);
64
64
  if (match) {
65
- const { content } = match.groups ?? {};
66
- addFormatCodes(content, node.loc.start.offset + match[0].indexOf(content), formatBrackets.generic);
65
+ const { content } = match.groups;
66
+ addFormatCodes(content, node.loc.start.offset + node.loc.source.indexOf('{') + 1, formatBrackets.generic);
67
67
  }
68
68
  }
69
69
  else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
@@ -169,7 +169,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
169
169
  expVar: string;
170
170
  propsVar: string;
171
171
  }[];
172
- specialVars: Set<string>;
172
+ dollarVars: Set<string>;
173
173
  accessExternalVariables: Map<string, Set<number>>;
174
174
  lastGenericComment: {
175
175
  content: string;
@@ -183,21 +183,25 @@ export declare const tsCodegen: WeakMap<Sfc, {
183
183
  }[];
184
184
  emptyClassOffsets: number[];
185
185
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
186
- hasSlot: boolean;
187
186
  bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
188
187
  inheritedAttrVars: Set<string>;
189
- templateRefs: Map<string, [varName: string, offset: number]>;
188
+ templateRefs: Map<string, {
189
+ typeExp: string;
190
+ offset: number;
191
+ }>;
190
192
  currentComponent: {
191
193
  ctxVar: string;
192
194
  used: boolean;
193
195
  } | undefined;
194
- singleRootElType: string | undefined;
195
- singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
196
+ singleRootElTypes: string[];
197
+ singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
196
198
  accessExternalVariable(name: string, offset?: number): void;
197
199
  hasLocalVariable: (name: string) => boolean;
198
200
  addLocalVariable: (name: string) => void;
199
201
  removeLocalVariable: (name: string) => void;
200
202
  getInternalVariable: () => string;
203
+ getHoistVariable: (originalVar: string) => string;
204
+ generateHoistVariables: () => Generator<string, void, unknown>;
201
205
  ignoreError: () => Generator<Code>;
202
206
  expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
203
207
  resetDirectiveComments: (endStr: string) => Generator<Code>;
@@ -53,16 +53,16 @@ const plugin = ctx => {
53
53
  }
54
54
  };
55
55
  exports.default = plugin;
56
- function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
56
+ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
57
57
  const ts = ctx.modules.typescript;
58
58
  const getLang = (0, alien_signals_1.computed)(() => {
59
- return !_sfc.script && !_sfc.scriptSetup ? 'ts'
60
- : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
61
- : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
59
+ return !sfc.script && !sfc.scriptSetup ? 'ts'
60
+ : sfc.scriptSetup && sfc.scriptSetup.lang !== 'js' ? sfc.scriptSetup.lang
61
+ : sfc.script && sfc.script.lang !== 'js' ? sfc.script.lang
62
62
  : 'js';
63
63
  });
64
64
  const getResolvedOptions = (0, alien_signals_1.computed)(() => {
65
- const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(_sfc.comments);
65
+ const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
66
66
  if (options) {
67
67
  const resolver = new ts_1.CompilerOptionsResolver();
68
68
  resolver.addConfig(options, path.dirname(fileName));
@@ -70,18 +70,18 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
70
70
  }
71
71
  return ctx.vueCompilerOptions;
72
72
  });
73
- const getScriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
74
- ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
73
+ const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
74
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
75
75
  : undefined);
76
- const getScriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
77
- ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, getResolvedOptions())
76
+ const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
77
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
78
78
  : undefined);
79
79
  const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
80
80
  const newNames = new Set();
81
81
  const bindings = getScriptSetupRanges()?.bindings;
82
- if (_sfc.scriptSetup && bindings) {
82
+ if (sfc.scriptSetup && bindings) {
83
83
  for (const { range } of bindings) {
84
- newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
84
+ newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
85
85
  }
86
86
  }
87
87
  return newNames;
@@ -89,13 +89,13 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
89
89
  const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
90
90
  const newNames = new Set();
91
91
  const bindings = getScriptSetupRanges()?.bindings;
92
- if (_sfc.scriptSetup && bindings) {
92
+ if (sfc.scriptSetup && bindings) {
93
93
  for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
94
94
  if (moduleName
95
95
  && isDefaultImport
96
96
  && !isNamespace
97
97
  && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
98
- newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
98
+ newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
99
99
  }
100
100
  }
101
101
  }
@@ -124,19 +124,19 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
124
124
  });
125
125
  const getComponentSelfName = (0, alien_signals_1.computed)(() => {
126
126
  const { exportDefault } = getScriptRanges() ?? {};
127
- if (_sfc.script && exportDefault?.nameOption) {
127
+ if (sfc.script && exportDefault?.nameOption) {
128
128
  const { nameOption } = exportDefault;
129
- return _sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
129
+ return sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
130
130
  }
131
131
  const { defineOptions } = getScriptSetupRanges() ?? {};
132
- if (_sfc.scriptSetup && defineOptions?.name) {
132
+ if (sfc.scriptSetup && defineOptions?.name) {
133
133
  return defineOptions.name;
134
134
  }
135
135
  const baseName = path.basename(fileName);
136
136
  return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
137
137
  });
138
138
  const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
139
- if (getResolvedOptions().skipTemplateCodegen || !_sfc.template) {
139
+ if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
140
140
  return;
141
141
  }
142
142
  const codes = [];
@@ -144,7 +144,7 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
144
144
  ts,
145
145
  compilerOptions: ctx.compilerOptions,
146
146
  vueCompilerOptions: getResolvedOptions(),
147
- template: _sfc.template,
147
+ template: sfc.template,
148
148
  edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
149
149
  scriptSetupBindingNames: getSetupBindingNames(),
150
150
  scriptSetupImportComponentNames: getSetupImportComponentNames(),
@@ -168,14 +168,14 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
168
168
  };
169
169
  });
170
170
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
171
- const codes = [];
172
171
  const linkedCodeMappings = [];
173
172
  let generatedLength = 0;
173
+ const codes = [];
174
174
  const codegen = (0, script_1.generateScript)({
175
175
  ts,
176
176
  compilerOptions: ctx.compilerOptions,
177
177
  vueCompilerOptions: getResolvedOptions(),
178
- sfc: _sfc,
178
+ sfc: sfc,
179
179
  edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
180
180
  fileName,
181
181
  lang: getLang(),
package/lib/types.d.ts CHANGED
@@ -12,8 +12,7 @@ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' |
12
12
  plugins?: string[];
13
13
  };
14
14
  export interface VueCodeInformation extends CodeInformation {
15
- __combineLastMapping?: boolean;
16
- __combineOffsetMapping?: number;
15
+ __combineOffset?: number;
17
16
  }
18
17
  export type Code = Segment<VueCodeInformation>;
19
18
  export interface VueCompilerOptions {
@@ -27,8 +26,15 @@ export interface VueCompilerOptions {
27
26
  checkUnknownEvents: boolean;
28
27
  checkUnknownDirectives: boolean;
29
28
  checkUnknownComponents: boolean;
29
+ inferComponentDollarEl: boolean;
30
+ inferComponentDollarRefs: boolean;
31
+ inferTemplateDollarAttrs: boolean;
32
+ inferTemplateDollarEl: boolean;
33
+ inferTemplateDollarRefs: boolean;
34
+ inferTemplateDollarSlots: boolean;
30
35
  skipTemplateCodegen: boolean;
31
36
  fallthroughAttributes: boolean;
37
+ fallthroughComponentNames: string[];
32
38
  dataAttributes: string[];
33
39
  htmlAttributes: string[];
34
40
  optionsWrapper: [string, string] | [];
@@ -103,6 +109,11 @@ export interface SfcBlock {
103
109
  content: string;
104
110
  attrs: Record<string, string | true>;
105
111
  }
112
+ export type SfcBlockAttr = true | {
113
+ text: string;
114
+ offset: number;
115
+ quotes: boolean;
116
+ };
106
117
  export interface Sfc {
107
118
  content: string;
108
119
  comments: string[];
@@ -112,21 +123,16 @@ export interface Sfc {
112
123
  warnings: CompilerDOM.CompilerError[];
113
124
  } | undefined;
114
125
  script: (SfcBlock & {
115
- src: string | undefined;
116
- srcOffset: number;
126
+ src: SfcBlockAttr | undefined;
117
127
  ast: ts.SourceFile;
118
128
  }) | undefined;
119
129
  scriptSetup: SfcBlock & {
120
- generic: string | undefined;
121
- genericOffset: number;
130
+ generic: SfcBlockAttr | undefined;
122
131
  ast: ts.SourceFile;
123
132
  } | undefined;
124
133
  styles: readonly (SfcBlock & {
125
134
  scoped: boolean;
126
- module?: {
127
- name: string;
128
- offset?: number;
129
- };
135
+ module?: SfcBlockAttr | undefined;
130
136
  cssVars: {
131
137
  text: string;
132
138
  offset: number;
@@ -141,11 +147,14 @@ export interface Sfc {
141
147
  })[];
142
148
  }
143
149
  declare module '@vue/compiler-sfc' {
150
+ interface SFCBlock {
151
+ __src?: SfcBlockAttr;
152
+ }
153
+ interface SFCScriptBlock {
154
+ __generic?: SfcBlockAttr;
155
+ }
144
156
  interface SFCStyleBlock {
145
- __module?: {
146
- name: string;
147
- offset?: number;
148
- };
157
+ __module?: SfcBlockAttr;
149
158
  }
150
159
  }
151
160
  export interface TextRange {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parse = parse;
4
- const compiler = require("@vue/compiler-dom");
4
+ const CompilerDOM = require("@vue/compiler-dom");
5
5
  function parse(source) {
6
6
  const errors = [];
7
- const ast = compiler.parse(source, {
7
+ const ast = CompilerDOM.parse(source, {
8
8
  // there are no components at SFC parsing level
9
9
  isNativeTag: () => true,
10
10
  // preserve all whitespaces
@@ -29,11 +29,11 @@ function parse(source) {
29
29
  shouldForceReload: () => false,
30
30
  };
31
31
  ast.children.forEach(node => {
32
- if (node.type === compiler.NodeTypes.COMMENT) {
32
+ if (node.type === CompilerDOM.NodeTypes.COMMENT) {
33
33
  descriptor.comments.push(node.content);
34
34
  return;
35
35
  }
36
- else if (node.type !== compiler.NodeTypes.ELEMENT) {
36
+ else if (node.type !== CompilerDOM.NodeTypes.ELEMENT) {
37
37
  return;
38
38
  }
39
39
  switch (node.tag) {
@@ -99,31 +99,55 @@ function createBlock(node, source) {
99
99
  attrs
100
100
  };
101
101
  node.props.forEach(p => {
102
- if (p.type === compiler.NodeTypes.ATTRIBUTE) {
102
+ if (p.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
103
103
  attrs[p.name] = p.value ? p.value.content || true : true;
104
104
  if (p.name === 'lang') {
105
- block.lang = p.value && p.value.content;
105
+ block.lang = p.value?.content;
106
106
  }
107
107
  else if (p.name === 'src') {
108
- block.src = p.value && p.value.content;
108
+ block.__src = parseAttr(p, node);
109
109
  }
110
- else if (type === 'style') {
110
+ else if (isScriptBlock(block)) {
111
+ if (p.name === 'setup' || p.name === 'vapor') {
112
+ block.setup = attrs[p.name];
113
+ }
114
+ else if (p.name === 'generic') {
115
+ block.__generic = parseAttr(p, node);
116
+ }
117
+ }
118
+ else if (isStyleBlock(block)) {
111
119
  if (p.name === 'scoped') {
112
120
  block.scoped = true;
113
121
  }
114
122
  else if (p.name === 'module') {
115
- block.__module = {
116
- name: p.value?.content ?? '$style',
117
- offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
118
- };
123
+ block.__module = parseAttr(p, node);
119
124
  }
120
125
  }
121
- else if (type === 'script'
122
- && (p.name === 'setup' || p.name === 'vapor')) {
123
- block.setup = attrs[p.name];
124
- }
125
126
  }
126
127
  });
127
128
  return block;
128
129
  }
130
+ function isScriptBlock(block) {
131
+ return block.type === 'script';
132
+ }
133
+ function isStyleBlock(block) {
134
+ return block.type === 'style';
135
+ }
136
+ function parseAttr(p, node) {
137
+ if (!p.value) {
138
+ return true;
139
+ }
140
+ const text = p.value.content;
141
+ const source = p.value.loc.source;
142
+ let offset = p.value.loc.start.offset - node.loc.start.offset;
143
+ const quotes = source.startsWith('"') || source.startsWith("'");
144
+ if (quotes) {
145
+ offset++;
146
+ }
147
+ return {
148
+ text,
149
+ offset,
150
+ quotes,
151
+ };
152
+ }
129
153
  //# sourceMappingURL=parseSfc.js.map
package/lib/utils/ts.js CHANGED
@@ -10,6 +10,7 @@ const shared_1 = require("@vue/shared");
10
10
  const path_browserify_1 = require("path-browserify");
11
11
  const globalTypes_1 = require("../codegen/globalTypes");
12
12
  const languagePlugin_1 = require("../languagePlugin");
13
+ const shared_2 = require("./shared");
13
14
  function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json', skipGlobalTypesSetup = false) {
14
15
  const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
15
16
  ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
@@ -174,6 +175,10 @@ class CompilerOptionsResolver {
174
175
  ...defaults.composables,
175
176
  ...this.options.composables,
176
177
  },
178
+ fallthroughComponentNames: [
179
+ ...defaults.fallthroughComponentNames,
180
+ ...this.options.fallthroughComponentNames ?? []
181
+ ].map(shared_2.hyphenateTag),
177
182
  // https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
178
183
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
179
184
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
@@ -217,8 +222,20 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
217
222
  checkUnknownEvents: strictTemplates,
218
223
  checkUnknownDirectives: strictTemplates,
219
224
  checkUnknownComponents: strictTemplates,
225
+ inferComponentDollarEl: false,
226
+ inferComponentDollarRefs: false,
227
+ inferTemplateDollarAttrs: false,
228
+ inferTemplateDollarEl: false,
229
+ inferTemplateDollarRefs: false,
230
+ inferTemplateDollarSlots: false,
220
231
  skipTemplateCodegen: false,
221
232
  fallthroughAttributes: false,
233
+ fallthroughComponentNames: [
234
+ 'Transition',
235
+ 'KeepAlive',
236
+ 'Teleport',
237
+ 'Suspense',
238
+ ],
222
239
  dataAttributes: [],
223
240
  htmlAttributes: ['aria-*'],
224
241
  optionsWrapper: target >= 2.7
@@ -171,28 +171,18 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByN
171
171
  ];
172
172
  }));
173
173
  const newMappings = [];
174
- let lastValidMapping;
175
174
  for (let i = 0; i < mappings.length; i++) {
176
175
  const mapping = mappings[i];
177
- if (mapping.data.__combineOffsetMapping !== undefined) {
178
- const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping];
176
+ if (mapping.data.__combineOffset !== undefined) {
177
+ const offsetMapping = mappings[i - mapping.data.__combineOffset];
179
178
  if (typeof offsetMapping === 'string' || !offsetMapping) {
180
- throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffsetMapping);
179
+ throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffset);
181
180
  }
182
181
  offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
183
182
  offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
184
183
  offsetMapping.lengths.push(...mapping.lengths);
185
184
  continue;
186
185
  }
187
- else if (mapping.data.__combineLastMapping) {
188
- lastValidMapping.sourceOffsets.push(...mapping.sourceOffsets);
189
- lastValidMapping.generatedOffsets.push(...mapping.generatedOffsets);
190
- lastValidMapping.lengths.push(...mapping.lengths);
191
- continue;
192
- }
193
- else {
194
- lastValidMapping = mapping;
195
- }
196
186
  newMappings.push(mapping);
197
187
  }
198
188
  return {