@vue/language-core 2.2.2 → 2.2.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 (90) hide show
  1. package/lib/codegen/globalTypes.js +21 -34
  2. package/lib/codegen/script/component.js +11 -9
  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 +8 -12
  8. package/lib/codegen/script/scriptSetup.js +90 -70
  9. package/lib/codegen/script/src.d.ts +2 -2
  10. package/lib/codegen/script/src.js +36 -37
  11. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  12. package/lib/codegen/script/styleModulesType.js +2 -2
  13. package/lib/codegen/script/template.d.ts +1 -2
  14. package/lib/codegen/script/template.js +5 -53
  15. package/lib/codegen/style/classProperty.d.ts +2 -0
  16. package/lib/codegen/style/classProperty.js +18 -0
  17. package/lib/codegen/style/modules.d.ts +3 -0
  18. package/lib/codegen/style/modules.js +34 -0
  19. package/lib/codegen/style/scopedClasses.d.ts +4 -0
  20. package/lib/codegen/style/scopedClasses.js +32 -0
  21. package/lib/codegen/template/context.d.ts +106 -5
  22. package/lib/codegen/template/context.js +131 -6
  23. package/lib/codegen/template/element.d.ts +1 -1
  24. package/lib/codegen/template/element.js +74 -97
  25. package/lib/codegen/template/elementChildren.d.ts +1 -1
  26. package/lib/codegen/template/elementChildren.js +1 -13
  27. package/lib/codegen/template/elementDirectives.js +8 -6
  28. package/lib/codegen/template/elementEvents.d.ts +2 -1
  29. package/lib/codegen/template/elementEvents.js +52 -28
  30. package/lib/codegen/template/elementProps.d.ts +1 -1
  31. package/lib/codegen/template/elementProps.js +23 -20
  32. package/lib/codegen/template/index.js +29 -14
  33. package/lib/codegen/template/interpolation.js +5 -5
  34. package/lib/codegen/template/objectProperty.js +5 -4
  35. package/lib/codegen/template/propertyAccess.js +1 -1
  36. package/lib/codegen/template/slotOutlet.js +13 -11
  37. package/lib/codegen/template/styleScopedClasses.js +8 -58
  38. package/lib/codegen/template/templateChild.js +60 -28
  39. package/lib/codegen/template/vFor.js +2 -2
  40. package/lib/codegen/template/vIf.js +4 -8
  41. package/lib/codegen/template/vSlot.d.ts +1 -0
  42. package/lib/codegen/template/vSlot.js +14 -1
  43. package/lib/codegen/utils/camelized.d.ts +1 -1
  44. package/lib/codegen/utils/camelized.js +6 -6
  45. package/lib/codegen/utils/escaped.d.ts +2 -0
  46. package/lib/codegen/utils/escaped.js +23 -0
  47. package/lib/codegen/utils/index.d.ts +3 -3
  48. package/lib/codegen/utils/index.js +19 -15
  49. package/lib/codegen/utils/objectProperty.d.ts +3 -0
  50. package/lib/codegen/utils/objectProperty.js +41 -0
  51. package/lib/codegen/utils/stringLiteralKey.js +2 -1
  52. package/lib/codegen/utils/unicode.js +2 -2
  53. package/lib/codegen/utils/wrapWith.d.ts +3 -0
  54. package/lib/codegen/utils/wrapWith.js +24 -0
  55. package/lib/parsers/scriptSetupRanges.d.ts +2 -0
  56. package/lib/parsers/scriptSetupRanges.js +84 -106
  57. package/lib/plugins/file-md.js +3 -0
  58. package/lib/plugins/vue-template-inline-ts.js +3 -3
  59. package/lib/plugins/vue-tsx.d.ts +11 -8
  60. package/lib/plugins/vue-tsx.js +19 -28
  61. package/lib/types.d.ts +24 -14
  62. package/lib/utils/parseSfc.js +40 -16
  63. package/lib/utils/ts.js +17 -0
  64. package/lib/virtualFile/computedEmbeddedCodes.js +18 -11
  65. package/lib/virtualFile/computedSfc.js +21 -28
  66. package/lib/virtualFile/vueFile.d.ts +7 -10
  67. package/lib/virtualFile/vueFile.js +10 -4
  68. package/package.json +2 -2
  69. package/lib/codeFeatures.d.ts +0 -1
  70. package/lib/codeFeatures.js +0 -3
  71. package/lib/codegen/common.d.ts +0 -12
  72. package/lib/codegen/common.js +0 -79
  73. package/lib/codegen/script/binding.d.ts +0 -4
  74. package/lib/codegen/script/binding.js +0 -41
  75. package/lib/codegen/template/camelized.d.ts +0 -2
  76. package/lib/codegen/template/camelized.js +0 -31
  77. package/lib/codegen/utils/src.d.ts +0 -2
  78. package/lib/codegen/utils/src.js +0 -19
  79. package/lib/plugins/vue-style-class-names.d.ts +0 -5
  80. package/lib/plugins/vue-style-class-names.js +0 -32
  81. package/lib/plugins/vue-style-reference-link.d.ts +0 -1
  82. package/lib/plugins/vue-style-reference-link.js +0 -3
  83. package/lib/plugins/vue-style-reference-links.d.ts +0 -3
  84. package/lib/plugins/vue-style-reference-links.js +0 -26
  85. package/lib/plugins/vue-vine.d.ts +0 -3
  86. package/lib/plugins/vue-vine.js +0 -35
  87. package/lib/utils/findDestructuredProps.d.ts +0 -1
  88. package/lib/utils/findDestructuredProps.js +0 -3
  89. package/lib/utils/parseCssImports.d.ts +0 -4
  90. package/lib/utils/parseCssImports.js +0 -19
@@ -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: {
@@ -169,7 +168,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
169
168
  expVar: string;
170
169
  propsVar: string;
171
170
  }[];
172
- specialVars: Set<string>;
171
+ dollarVars: Set<string>;
173
172
  accessExternalVariables: Map<string, Set<number>>;
174
173
  lastGenericComment: {
175
174
  content: string;
@@ -183,21 +182,25 @@ export declare const tsCodegen: WeakMap<Sfc, {
183
182
  }[];
184
183
  emptyClassOffsets: number[];
185
184
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
186
- hasSlot: boolean;
187
185
  bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
188
186
  inheritedAttrVars: Set<string>;
189
- templateRefs: Map<string, [varName: string, offset: number]>;
187
+ templateRefs: Map<string, {
188
+ typeExp: string;
189
+ offset: number;
190
+ }>;
190
191
  currentComponent: {
191
192
  ctxVar: string;
192
193
  used: boolean;
193
194
  } | undefined;
194
- singleRootElType: string | undefined;
195
- singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
195
+ singleRootElTypes: string[];
196
+ singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
196
197
  accessExternalVariable(name: string, offset?: number): void;
197
198
  hasLocalVariable: (name: string) => boolean;
198
199
  addLocalVariable: (name: string) => void;
199
200
  removeLocalVariable: (name: string) => void;
200
201
  getInternalVariable: () => string;
202
+ getHoistVariable: (originalVar: string) => string;
203
+ generateHoistVariables: () => Generator<string, void, unknown>;
201
204
  ignoreError: () => Generator<Code>;
202
205
  expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
203
206
  resetDirectiveComments: (endStr: string) => Generator<Code>;
@@ -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
  },
@@ -53,16 +52,16 @@ const plugin = ctx => {
53
52
  }
54
53
  };
55
54
  exports.default = plugin;
56
- function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
55
+ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
57
56
  const ts = ctx.modules.typescript;
58
57
  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
58
+ return !sfc.script && !sfc.scriptSetup ? 'ts'
59
+ : sfc.scriptSetup && sfc.scriptSetup.lang !== 'js' ? sfc.scriptSetup.lang
60
+ : sfc.script && sfc.script.lang !== 'js' ? sfc.script.lang
62
61
  : 'js';
63
62
  });
64
63
  const getResolvedOptions = (0, alien_signals_1.computed)(() => {
65
- const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(_sfc.comments);
64
+ const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
66
65
  if (options) {
67
66
  const resolver = new ts_1.CompilerOptionsResolver();
68
67
  resolver.addConfig(options, path.dirname(fileName));
@@ -70,18 +69,18 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
70
69
  }
71
70
  return ctx.vueCompilerOptions;
72
71
  });
73
- const getScriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
74
- ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
72
+ const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
73
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
75
74
  : undefined);
76
- const getScriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
77
- ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, getResolvedOptions())
75
+ const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
76
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
78
77
  : undefined);
79
78
  const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
80
79
  const newNames = new Set();
81
80
  const bindings = getScriptSetupRanges()?.bindings;
82
- if (_sfc.scriptSetup && bindings) {
81
+ if (sfc.scriptSetup && bindings) {
83
82
  for (const { range } of bindings) {
84
- newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
83
+ newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
85
84
  }
86
85
  }
87
86
  return newNames;
@@ -89,13 +88,13 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
89
88
  const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
90
89
  const newNames = new Set();
91
90
  const bindings = getScriptSetupRanges()?.bindings;
92
- if (_sfc.scriptSetup && bindings) {
91
+ if (sfc.scriptSetup && bindings) {
93
92
  for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
94
93
  if (moduleName
95
94
  && isDefaultImport
96
95
  && !isNamespace
97
96
  && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
98
- newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
97
+ newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
99
98
  }
100
99
  }
101
100
  }
@@ -124,19 +123,19 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
124
123
  });
125
124
  const getComponentSelfName = (0, alien_signals_1.computed)(() => {
126
125
  const { exportDefault } = getScriptRanges() ?? {};
127
- if (_sfc.script && exportDefault?.nameOption) {
126
+ if (sfc.script && exportDefault?.nameOption) {
128
127
  const { nameOption } = exportDefault;
129
- return _sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
128
+ return sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
130
129
  }
131
130
  const { defineOptions } = getScriptSetupRanges() ?? {};
132
- if (_sfc.scriptSetup && defineOptions?.name) {
131
+ if (sfc.scriptSetup && defineOptions?.name) {
133
132
  return defineOptions.name;
134
133
  }
135
134
  const baseName = path.basename(fileName);
136
135
  return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
137
136
  });
138
137
  const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
139
- if (getResolvedOptions().skipTemplateCodegen || !_sfc.template) {
138
+ if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
140
139
  return;
141
140
  }
142
141
  const codes = [];
@@ -144,7 +143,7 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
144
143
  ts,
145
144
  compilerOptions: ctx.compilerOptions,
146
145
  vueCompilerOptions: getResolvedOptions(),
147
- template: _sfc.template,
146
+ template: sfc.template,
148
147
  edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
149
148
  scriptSetupBindingNames: getSetupBindingNames(),
150
149
  scriptSetupImportComponentNames: getSetupImportComponentNames(),
@@ -169,13 +168,11 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
169
168
  });
170
169
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
171
170
  const codes = [];
172
- const linkedCodeMappings = [];
173
- let generatedLength = 0;
174
171
  const codegen = (0, script_1.generateScript)({
175
172
  ts,
176
173
  compilerOptions: ctx.compilerOptions,
177
174
  vueCompilerOptions: getResolvedOptions(),
178
- sfc: _sfc,
175
+ sfc: sfc,
179
176
  edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
180
177
  fileName,
181
178
  lang: getLang(),
@@ -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
@@ -12,8 +12,8 @@ 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;
16
+ __linkedToken?: symbol;
17
17
  }
18
18
  export type Code = Segment<VueCodeInformation>;
19
19
  export interface VueCompilerOptions {
@@ -27,8 +27,15 @@ export interface VueCompilerOptions {
27
27
  checkUnknownEvents: boolean;
28
28
  checkUnknownDirectives: boolean;
29
29
  checkUnknownComponents: boolean;
30
+ inferComponentDollarEl: boolean;
31
+ inferComponentDollarRefs: boolean;
32
+ inferTemplateDollarAttrs: boolean;
33
+ inferTemplateDollarEl: boolean;
34
+ inferTemplateDollarRefs: boolean;
35
+ inferTemplateDollarSlots: boolean;
30
36
  skipTemplateCodegen: boolean;
31
37
  fallthroughAttributes: boolean;
38
+ fallthroughComponentNames: string[];
32
39
  dataAttributes: string[];
33
40
  htmlAttributes: string[];
34
41
  optionsWrapper: [string, string] | [];
@@ -103,6 +110,11 @@ export interface SfcBlock {
103
110
  content: string;
104
111
  attrs: Record<string, string | true>;
105
112
  }
113
+ export type SfcBlockAttr = true | {
114
+ text: string;
115
+ offset: number;
116
+ quotes: boolean;
117
+ };
106
118
  export interface Sfc {
107
119
  content: string;
108
120
  comments: string[];
@@ -112,21 +124,16 @@ export interface Sfc {
112
124
  warnings: CompilerDOM.CompilerError[];
113
125
  } | undefined;
114
126
  script: (SfcBlock & {
115
- src: string | undefined;
116
- srcOffset: number;
127
+ src: SfcBlockAttr | undefined;
117
128
  ast: ts.SourceFile;
118
129
  }) | undefined;
119
130
  scriptSetup: SfcBlock & {
120
- generic: string | undefined;
121
- genericOffset: number;
131
+ generic: SfcBlockAttr | undefined;
122
132
  ast: ts.SourceFile;
123
133
  } | undefined;
124
134
  styles: readonly (SfcBlock & {
125
135
  scoped: boolean;
126
- module?: {
127
- name: string;
128
- offset?: number;
129
- };
136
+ module?: SfcBlockAttr | undefined;
130
137
  cssVars: {
131
138
  text: string;
132
139
  offset: number;
@@ -141,11 +148,14 @@ export interface Sfc {
141
148
  })[];
142
149
  }
143
150
  declare module '@vue/compiler-sfc' {
151
+ interface SFCBlock {
152
+ __src?: SfcBlockAttr;
153
+ }
154
+ interface SFCScriptBlock {
155
+ __generic?: SfcBlockAttr;
156
+ }
144
157
  interface SFCStyleBlock {
145
- __module?: {
146
- name: string;
147
- offset?: number;
148
- };
158
+ __module?: SfcBlockAttr;
149
159
  }
150
160
  }
151
161
  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,35 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByN
171
171
  ];
172
172
  }));
173
173
  const newMappings = [];
174
- let lastValidMapping;
174
+ const tokenMappings = new Map();
175
175
  for (let i = 0; i < mappings.length; i++) {
176
176
  const mapping = mappings[i];
177
- if (mapping.data.__combineOffsetMapping !== undefined) {
178
- const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping];
177
+ if (mapping.data.__combineOffset !== undefined) {
178
+ const offsetMapping = mappings[i - mapping.data.__combineOffset];
179
179
  if (typeof offsetMapping === 'string' || !offsetMapping) {
180
- throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffsetMapping);
180
+ throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffset);
181
181
  }
182
182
  offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
183
183
  offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
184
184
  offsetMapping.lengths.push(...mapping.lengths);
185
185
  continue;
186
186
  }
187
- else if (mapping.data.__combineLastMapping) {
188
- lastValidMapping.sourceOffsets.push(...mapping.sourceOffsets);
189
- lastValidMapping.generatedOffsets.push(...mapping.generatedOffsets);
190
- lastValidMapping.lengths.push(...mapping.lengths);
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
+ }
191
201
  continue;
192
202
  }
193
- else {
194
- lastValidMapping = mapping;
195
- }
196
203
  newMappings.push(mapping);
197
204
  }
198
205
  return {
@@ -32,12 +32,8 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
32
32
  });
33
33
  });
34
34
  const getScript = computedNullableSfcBlock('script', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.script ?? undefined), (block, base) => {
35
- const src = (0, alien_signals_1.computed)(() => block().src);
36
- const srcOffset = (0, alien_signals_1.computed)(() => {
37
- const _src = src();
38
- return _src ? getUntrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_src) - base.startTagEnd : -1;
39
- });
40
- const ast = (0, alien_signals_1.computed)(() => {
35
+ const getSrc = computedAttrValue('__src', base, block);
36
+ const getAst = (0, alien_signals_1.computed)(() => {
41
37
  for (const plugin of plugins) {
42
38
  const ast = plugin.compileSFCScript?.(base.lang, base.content);
43
39
  if (ast) {
@@ -47,21 +43,13 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
47
43
  return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
48
44
  });
49
45
  return mergeObject(base, {
50
- get src() { return src(); },
51
- get srcOffset() { return srcOffset(); },
52
- get ast() { return ast(); },
46
+ get src() { return getSrc(); },
47
+ get ast() { return getAst(); },
53
48
  });
54
49
  });
55
50
  const getOriginalScriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.scriptSetup ?? undefined), (block, base) => {
56
- const generic = (0, alien_signals_1.computed)(() => {
57
- const _block = block();
58
- return typeof _block.attrs.generic === 'string' ? _block.attrs.generic : undefined;
59
- });
60
- const genericOffset = (0, alien_signals_1.computed)(() => {
61
- const _generic = generic();
62
- return _generic !== undefined ? getUntrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_generic) - base.startTagEnd : -1;
63
- });
64
- const ast = (0, alien_signals_1.computed)(() => {
51
+ const getGeneric = computedAttrValue('__generic', base, block);
52
+ const getAst = (0, alien_signals_1.computed)(() => {
65
53
  for (const plugin of plugins) {
66
54
  const ast = plugin.compileSFCScript?.(base.lang, base.content);
67
55
  if (ast) {
@@ -71,9 +59,8 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
71
59
  return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
72
60
  });
73
61
  return mergeObject(base, {
74
- get generic() { return generic(); },
75
- get genericOffset() { return genericOffset(); },
76
- get ast() { return ast(); },
62
+ get generic() { return getGeneric(); },
63
+ get ast() { return getAst(); },
77
64
  });
78
65
  });
79
66
  const hasScript = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.script);
@@ -99,13 +86,7 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
99
86
  });
100
87
  const styles = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.styles ?? []), (getBlock, i) => {
101
88
  const base = computedSfcBlock('style_' + i, 'css', getBlock);
102
- const getModule = (0, alien_signals_1.computed)(() => {
103
- const { __module } = getBlock();
104
- return __module ? {
105
- name: __module.name,
106
- offset: __module.offset ? base.start + __module.offset : undefined
107
- } : undefined;
108
- });
89
+ const getModule = computedAttrValue('__module', base, getBlock);
109
90
  const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
110
91
  const getCssVars = (0, alien_signals_1.computed)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)]);
111
92
  const getClassNames = (0, alien_signals_1.computed)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)]);
@@ -243,6 +224,18 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
243
224
  get end() { return getEnd(); },
244
225
  };
245
226
  }
227
+ function computedAttrValue(key, base, getBlock) {
228
+ return (0, alien_signals_1.computed)(() => {
229
+ const val = getBlock()[key];
230
+ if (typeof val === 'object') {
231
+ return {
232
+ ...val,
233
+ offset: base.start + val.offset,
234
+ };
235
+ }
236
+ return val;
237
+ });
238
+ }
246
239
  }
247
240
  function mergeObject(a, b) {
248
241
  return Object.defineProperties(a, Object.getOwnPropertyDescriptors(b));
@@ -10,17 +10,14 @@ export declare class VueVirtualCode implements VirtualCode {
10
10
  ts: typeof import('typescript');
11
11
  id: string;
12
12
  private _snapshot;
13
- _vueSfc: () => import("@vue/compiler-sfc").SFCParseResult | undefined;
14
- _sfc: import("../types").Sfc;
15
- _mappings: () => {
16
- sourceOffsets: number[];
17
- generatedOffsets: number[];
18
- lengths: number[];
19
- data: import("@volar/language-core").CodeInformation;
20
- }[];
21
- _embeddedCodes: () => VirtualCode[];
22
- get embeddedCodes(): VirtualCode[];
13
+ private _vueSfc;
14
+ private _sfc;
15
+ private _embeddedCodes;
16
+ private _mappings;
23
17
  get snapshot(): ts.IScriptSnapshot;
18
+ get vueSfc(): import("@vue/compiler-sfc").SFCParseResult | undefined;
19
+ get sfc(): import("../types").Sfc;
20
+ get embeddedCodes(): VirtualCode[];
24
21
  get mappings(): {
25
22
  sourceOffsets: number[];
26
23
  generatedOffsets: number[];
@@ -8,12 +8,18 @@ const computedSfc_1 = require("./computedSfc");
8
8
  const computedVueSfc_1 = require("./computedVueSfc");
9
9
  class VueVirtualCode {
10
10
  // others
11
- get embeddedCodes() {
12
- return this._embeddedCodes();
13
- }
14
11
  get snapshot() {
15
12
  return this._snapshot();
16
13
  }
14
+ get vueSfc() {
15
+ return this._vueSfc();
16
+ }
17
+ get sfc() {
18
+ return this._sfc;
19
+ }
20
+ get embeddedCodes() {
21
+ return this._embeddedCodes();
22
+ }
17
23
  get mappings() {
18
24
  return this._mappings();
19
25
  }
@@ -30,6 +36,7 @@ class VueVirtualCode {
30
36
  // computeds
31
37
  this._vueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, this.languageId, this._snapshot);
32
38
  this._sfc = (0, computedSfc_1.computedSfc)(this.ts, this.plugins, this.fileName, this._snapshot, this._vueSfc);
39
+ this._embeddedCodes = (0, computedEmbeddedCodes_1.computedEmbeddedCodes)(this.plugins, this.fileName, this._sfc);
33
40
  this._mappings = (0, alien_signals_1.computed)(() => {
34
41
  const snapshot = this._snapshot();
35
42
  return [{
@@ -39,7 +46,6 @@ class VueVirtualCode {
39
46
  data: plugins_1.allCodeFeatures,
40
47
  }];
41
48
  });
42
- this._embeddedCodes = (0, computedEmbeddedCodes_1.computedEmbeddedCodes)(this.plugins, this.fileName, this._sfc);
43
49
  this._snapshot(initSnapshot);
44
50
  }
45
51
  update(newSnapshot) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.2.2",
3
+ "version": "2.2.6",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "30757908b67f40f779c36795665163634fb81868"
40
+ "gitHead": "f2088e256dc0220db9549d28d9f865a5711dcfbe"
41
41
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=codeFeatures.js.map
@@ -1,12 +0,0 @@
1
- import type * as ts from 'typescript';
2
- import type { Code, SfcBlock, VueCodeInformation } from '../types';
3
- export declare const newLine = "\n";
4
- export declare const endOfLine = ";\n";
5
- export declare const combineLastMapping: VueCodeInformation;
6
- export declare const variableNameRegex: RegExp;
7
- export declare function conditionWrapWith(condition: boolean, startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
8
- export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
9
- export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
10
- export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: [id: ts.Identifier, isRest: boolean][], isRest?: boolean): [id: ts.Identifier, isRest: boolean][];
11
- export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
12
- export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;