@vue/language-core 3.0.0-alpha.0 → 3.0.0-alpha.2

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 (34) hide show
  1. package/lib/codegen/globalTypes.js +2 -4
  2. package/lib/codegen/script/component.js +21 -9
  3. package/lib/codegen/script/index.js +1 -1
  4. package/lib/codegen/script/scriptSetup.js +1 -10
  5. package/lib/codegen/script/styleModulesType.d.ts +4 -0
  6. package/lib/codegen/script/styleModulesType.js +34 -0
  7. package/lib/codegen/template/context.d.ts +25 -17
  8. package/lib/codegen/template/context.js +87 -53
  9. package/lib/codegen/template/element.d.ts +2 -2
  10. package/lib/codegen/template/element.js +10 -24
  11. package/lib/codegen/template/elementChildren.d.ts +1 -1
  12. package/lib/codegen/template/elementChildren.js +4 -6
  13. package/lib/codegen/template/elementDirectives.js +1 -3
  14. package/lib/codegen/template/elementEvents.js +0 -1
  15. package/lib/codegen/template/elementProps.js +1 -1
  16. package/lib/codegen/template/index.js +20 -7
  17. package/lib/codegen/template/interpolation.d.ts +1 -1
  18. package/lib/codegen/template/interpolation.js +52 -52
  19. package/lib/codegen/template/slotOutlet.js +1 -2
  20. package/lib/codegen/template/templateChild.d.ts +1 -1
  21. package/lib/codegen/template/templateChild.js +12 -46
  22. package/lib/codegen/template/vFor.js +5 -10
  23. package/lib/codegen/template/vIf.js +2 -10
  24. package/lib/codegen/template/vSlot.d.ts +1 -2
  25. package/lib/codegen/template/vSlot.js +84 -62
  26. package/lib/codegen/utils/objectProperty.d.ts +3 -0
  27. package/lib/codegen/utils/objectProperty.js +41 -0
  28. package/lib/parsers/scriptSetupRanges.js +8 -6
  29. package/lib/plugins/vue-tsx.d.ts +24 -16
  30. package/lib/plugins/vue-tsx.js +31 -19
  31. package/lib/types.d.ts +1 -1
  32. package/lib/utils/forEachElementNode.d.ts +1 -0
  33. package/lib/utils/forEachElementNode.js +3 -0
  34. package/package.json +2 -2
@@ -138,6 +138,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
138
138
  };
139
139
  getGeneratedTemplate: () => {
140
140
  codes: Code[];
141
+ currentInfo: {
142
+ ignoreError?: boolean;
143
+ expectError?: {
144
+ token: number;
145
+ node: import("@vue/compiler-dom").CommentNode;
146
+ };
147
+ generic?: {
148
+ content: string;
149
+ offset: number;
150
+ };
151
+ };
141
152
  codeFeatures: {
142
153
  all: import("../types").VueCodeInformation;
143
154
  none: import("../types").VueCodeInformation;
@@ -157,6 +168,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
157
168
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
158
169
  };
159
170
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
+ inVFor: boolean;
160
172
  slots: {
161
173
  name: string;
162
174
  offset?: number;
@@ -170,10 +182,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
170
182
  }[];
171
183
  dollarVars: Set<string>;
172
184
  accessExternalVariables: Map<string, Set<number>>;
173
- lastGenericComment: {
174
- content: string;
175
- offset: number;
176
- } | undefined;
177
185
  blockConditions: string[];
178
186
  scopedClasses: {
179
187
  source: string;
@@ -187,25 +195,25 @@ export declare const tsCodegen: WeakMap<Sfc, {
187
195
  templateRefs: Map<string, {
188
196
  typeExp: string;
189
197
  offset: number;
190
- }>;
198
+ }[]>;
191
199
  currentComponent: {
192
200
  ctxVar: string;
193
201
  used: boolean;
194
202
  } | undefined;
195
203
  singleRootElTypes: string[];
196
204
  singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
205
+ addTemplateRef(name: string, typeExp: string, offset: number): void;
197
206
  accessExternalVariable(name: string, offset?: number): void;
198
- hasLocalVariable: (name: string) => boolean;
199
- addLocalVariable: (name: string) => void;
200
- removeLocalVariable: (name: string) => void;
201
- getInternalVariable: () => string;
202
- getHoistVariable: (originalVar: string) => string;
203
- generateHoistVariables: () => Generator<string, void, unknown>;
204
- generateConditionGuards: () => Generator<string, void, unknown>;
205
- ignoreError: () => Generator<Code>;
206
- expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
207
- resetDirectiveComments: (endStr: string) => Generator<Code>;
208
- generateAutoImportCompletion: () => Generator<Code>;
207
+ hasLocalVariable(name: string): boolean;
208
+ addLocalVariable(name: string): void;
209
+ removeLocalVariable(name: string): void;
210
+ getInternalVariable(): string;
211
+ getHoistVariable(originalVar: string): string;
212
+ generateHoistVariables(): Generator<string, void, unknown>;
213
+ generateConditionGuards(): Generator<string, void, unknown>;
214
+ generateAutoImportCompletion(): Generator<Code>;
215
+ enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
216
+ exit(): Generator<Code>;
209
217
  } | undefined;
210
218
  }>;
211
219
  declare const plugin: VueLanguagePlugin;
@@ -12,6 +12,7 @@ const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
12
12
  const signals_1 = require("../utils/signals");
13
13
  const ts_1 = require("../utils/ts");
14
14
  exports.tsCodegen = new WeakMap();
15
+ const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
15
16
  const plugin = ctx => {
16
17
  let appendedGlobalTypes = false;
17
18
  return {
@@ -22,11 +23,10 @@ const plugin = ctx => {
22
23
  ],
23
24
  getEmbeddedCodes(fileName, sfc) {
24
25
  const codegen = useCodegen(fileName, sfc);
25
- const files = [];
26
- if (['js', 'ts', 'jsx', 'tsx'].includes(codegen.getLang())) {
27
- files.push({ id: 'script_' + codegen.getLang(), lang: codegen.getLang() });
28
- }
29
- return files;
26
+ return [{
27
+ id: 'script_' + codegen.getLang(),
28
+ lang: codegen.getLang(),
29
+ }];
30
30
  },
31
31
  resolveEmbeddedCode(fileName, sfc, embeddedFile) {
32
32
  if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
@@ -53,11 +53,23 @@ const plugin = ctx => {
53
53
  exports.default = plugin;
54
54
  function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
55
55
  const ts = ctx.modules.typescript;
56
+ const getRawLang = (0, alien_signals_1.computed)(() => {
57
+ if (sfc.script && sfc.scriptSetup) {
58
+ if (sfc.scriptSetup.lang !== 'js') {
59
+ return sfc.scriptSetup.lang;
60
+ }
61
+ else {
62
+ return sfc.script.lang;
63
+ }
64
+ }
65
+ return sfc.scriptSetup?.lang ?? sfc.script?.lang;
66
+ });
56
67
  const getLang = (0, alien_signals_1.computed)(() => {
57
- return !sfc.script && !sfc.scriptSetup ? 'ts'
58
- : sfc.scriptSetup && sfc.scriptSetup.lang !== 'js' ? sfc.scriptSetup.lang
59
- : sfc.script && sfc.script.lang !== 'js' ? sfc.script.lang
60
- : 'js';
68
+ const rawLang = getRawLang();
69
+ if (rawLang && validLangs.has(rawLang)) {
70
+ return rawLang;
71
+ }
72
+ return 'ts';
61
73
  });
62
74
  const getResolvedOptions = (0, alien_signals_1.computed)(() => {
63
75
  const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
@@ -68,13 +80,13 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
68
80
  }
69
81
  return ctx.vueCompilerOptions;
70
82
  });
71
- const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
83
+ const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
72
84
  ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
73
85
  : undefined);
74
- const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
86
+ const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
75
87
  ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
76
88
  : undefined);
77
- const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
89
+ const getSetupBindingNames = (0, signals_1.computedSet)(() => {
78
90
  const newNames = new Set();
79
91
  const bindings = getScriptSetupRanges()?.bindings;
80
92
  if (sfc.scriptSetup && bindings) {
@@ -83,8 +95,8 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
83
95
  }
84
96
  }
85
97
  return newNames;
86
- }));
87
- const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
98
+ });
99
+ const getSetupImportComponentNames = (0, signals_1.computedSet)(() => {
88
100
  const newNames = new Set();
89
101
  const bindings = getScriptSetupRanges()?.bindings;
90
102
  if (sfc.scriptSetup && bindings) {
@@ -98,21 +110,21 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
98
110
  }
99
111
  }
100
112
  return newNames;
101
- }));
102
- const getSetupDestructuredPropNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
113
+ });
114
+ const getSetupDestructuredPropNames = (0, signals_1.computedSet)(() => {
103
115
  const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
104
116
  const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
105
117
  if (rest) {
106
118
  newNames.add(rest);
107
119
  }
108
120
  return newNames;
109
- }));
110
- const getSetupTemplateRefNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
121
+ });
122
+ const getSetupTemplateRefNames = (0, signals_1.computedSet)(() => {
111
123
  const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
112
124
  .map(({ name }) => name)
113
125
  .filter(name => name !== undefined));
114
126
  return newNames;
115
- }));
127
+ });
116
128
  const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
117
129
  const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
118
130
  const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
package/lib/types.d.ts CHANGED
@@ -8,7 +8,7 @@ export type { SFCParseResult } from '@vue/compiler-sfc';
8
8
  export { VueEmbeddedCode };
9
9
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
10
10
  strictTemplates?: boolean;
11
- target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 99 | number;
11
+ target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
12
12
  plugins?: string[];
13
13
  };
14
14
  export interface VueCodeInformation extends CodeInformation {
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=forEachElementNode.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "4b49cbe09097e482def4603b90f6c3b93bb2e913"
40
+ "gitHead": "79247b7c24b7202ec676723440fdb36c38e6d450"
41
41
  }