@vue/language-core 2.2.8 → 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 (47) hide show
  1. package/index.d.ts +1 -2
  2. package/index.js +1 -1
  3. package/lib/codegen/globalTypes.js +3 -9
  4. package/lib/codegen/script/component.js +21 -9
  5. package/lib/codegen/script/index.d.ts +0 -1
  6. package/lib/codegen/script/index.js +1 -4
  7. package/lib/codegen/script/scriptSetup.js +1 -10
  8. package/lib/codegen/script/src.js +1 -20
  9. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  10. package/lib/codegen/script/styleModulesType.js +2 -2
  11. package/lib/codegen/script/template.js +4 -1
  12. package/lib/codegen/template/context.d.ts +26 -17
  13. package/lib/codegen/template/context.js +89 -53
  14. package/lib/codegen/template/element.d.ts +2 -2
  15. package/lib/codegen/template/element.js +24 -57
  16. package/lib/codegen/template/elementChildren.d.ts +1 -1
  17. package/lib/codegen/template/elementChildren.js +4 -6
  18. package/lib/codegen/template/elementDirectives.js +1 -11
  19. package/lib/codegen/template/elementEvents.d.ts +1 -0
  20. package/lib/codegen/template/elementEvents.js +39 -17
  21. package/lib/codegen/template/elementProps.js +4 -8
  22. package/lib/codegen/template/index.d.ts +0 -1
  23. package/lib/codegen/template/index.js +22 -10
  24. package/lib/codegen/template/interpolation.d.ts +1 -1
  25. package/lib/codegen/template/interpolation.js +53 -53
  26. package/lib/codegen/template/slotOutlet.js +1 -2
  27. package/lib/codegen/template/styleScopedClasses.js +2 -2
  28. package/lib/codegen/template/templateChild.d.ts +1 -1
  29. package/lib/codegen/template/templateChild.js +12 -46
  30. package/lib/codegen/template/vFor.js +5 -10
  31. package/lib/codegen/template/vIf.js +2 -10
  32. package/lib/codegen/template/vSlot.d.ts +1 -2
  33. package/lib/codegen/template/vSlot.js +84 -62
  34. package/lib/codegen/utils/index.js +2 -2
  35. package/lib/parsers/scriptRanges.js +7 -3
  36. package/lib/parsers/scriptSetupRanges.d.ts +0 -3
  37. package/lib/parsers/scriptSetupRanges.js +18 -28
  38. package/lib/plugins/vue-tsx.d.ts +24 -15
  39. package/lib/plugins/vue-tsx.js +31 -23
  40. package/lib/types.d.ts +2 -2
  41. package/lib/utils/forEachElementNode.d.ts +1 -0
  42. package/lib/utils/forEachElementNode.js +3 -0
  43. package/lib/utils/shared.d.ts +5 -1
  44. package/lib/utils/shared.js +16 -4
  45. package/lib/utils/ts.d.ts +0 -4
  46. package/lib/utils/ts.js +1 -10
  47. package/package.json +2 -2
@@ -12,7 +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 fileEditTimes = new Map();
15
+ const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
16
16
  const plugin = ctx => {
17
17
  let appendedGlobalTypes = false;
18
18
  return {
@@ -23,11 +23,10 @@ const plugin = ctx => {
23
23
  ],
24
24
  getEmbeddedCodes(fileName, sfc) {
25
25
  const codegen = useCodegen(fileName, sfc);
26
- const files = [];
27
- if (['js', 'ts', 'jsx', 'tsx'].includes(codegen.getLang())) {
28
- files.push({ id: 'script_' + codegen.getLang(), lang: codegen.getLang() });
29
- }
30
- return files;
26
+ return [{
27
+ id: 'script_' + codegen.getLang(),
28
+ lang: codegen.getLang(),
29
+ }];
31
30
  },
32
31
  resolveEmbeddedCode(fileName, sfc, embeddedFile) {
33
32
  if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
@@ -54,11 +53,23 @@ const plugin = ctx => {
54
53
  exports.default = plugin;
55
54
  function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
56
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
+ });
57
67
  const getLang = (0, alien_signals_1.computed)(() => {
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
61
- : 'js';
68
+ const rawLang = getRawLang();
69
+ if (rawLang && validLangs.has(rawLang)) {
70
+ return rawLang;
71
+ }
72
+ return 'ts';
62
73
  });
63
74
  const getResolvedOptions = (0, alien_signals_1.computed)(() => {
64
75
  const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
@@ -69,13 +80,13 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
69
80
  }
70
81
  return ctx.vueCompilerOptions;
71
82
  });
72
- const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
83
+ const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
73
84
  ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
74
85
  : undefined);
75
- const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
86
+ const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
76
87
  ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
77
88
  : undefined);
78
- const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
89
+ const getSetupBindingNames = (0, signals_1.computedSet)(() => {
79
90
  const newNames = new Set();
80
91
  const bindings = getScriptSetupRanges()?.bindings;
81
92
  if (sfc.scriptSetup && bindings) {
@@ -84,8 +95,8 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
84
95
  }
85
96
  }
86
97
  return newNames;
87
- }));
88
- const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
98
+ });
99
+ const getSetupImportComponentNames = (0, signals_1.computedSet)(() => {
89
100
  const newNames = new Set();
90
101
  const bindings = getScriptSetupRanges()?.bindings;
91
102
  if (sfc.scriptSetup && bindings) {
@@ -99,21 +110,21 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
99
110
  }
100
111
  }
101
112
  return newNames;
102
- }));
103
- const getSetupDestructuredPropNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
113
+ });
114
+ const getSetupDestructuredPropNames = (0, signals_1.computedSet)(() => {
104
115
  const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
105
116
  const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
106
117
  if (rest) {
107
118
  newNames.add(rest);
108
119
  }
109
120
  return newNames;
110
- }));
111
- const getSetupTemplateRefNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
121
+ });
122
+ const getSetupTemplateRefNames = (0, signals_1.computedSet)(() => {
112
123
  const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
113
124
  .map(({ name }) => name)
114
125
  .filter(name => name !== undefined));
115
126
  return newNames;
116
- }));
127
+ });
117
128
  const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
118
129
  const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
119
130
  const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
@@ -144,7 +155,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
144
155
  compilerOptions: ctx.compilerOptions,
145
156
  vueCompilerOptions: getResolvedOptions(),
146
157
  template: sfc.template,
147
- edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
148
158
  scriptSetupBindingNames: getSetupBindingNames(),
149
159
  scriptSetupImportComponentNames: getSetupImportComponentNames(),
150
160
  destructuredPropNames: getSetupDestructuredPropNames(),
@@ -173,7 +183,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
173
183
  compilerOptions: ctx.compilerOptions,
174
184
  vueCompilerOptions: getResolvedOptions(),
175
185
  sfc: sfc,
176
- edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
177
186
  fileName,
178
187
  lang: getLang(),
179
188
  scriptRanges: getScriptRanges(),
@@ -183,7 +192,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
183
192
  templateRefNames: getSetupTemplateRefNames(),
184
193
  appendGlobalTypes,
185
194
  });
186
- fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
187
195
  let current = codegen.next();
188
196
  while (!current.done) {
189
197
  const code = current.value;
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 {
@@ -23,6 +23,7 @@ export interface VueCompilerOptions {
23
23
  vitePressExtensions: string[];
24
24
  petiteVueExtensions: string[];
25
25
  jsxSlots: boolean;
26
+ strictVModel: boolean;
26
27
  checkUnknownProps: boolean;
27
28
  checkUnknownEvents: boolean;
28
29
  checkUnknownDirectives: boolean;
@@ -61,7 +62,6 @@ export interface VueCompilerOptions {
61
62
  __setupedGlobalTypes?: true | {
62
63
  absolutePath: string;
63
64
  };
64
- __test?: boolean;
65
65
  }
66
66
  export declare const validVersions: readonly [2, 2.1];
67
67
  export type VueLanguagePluginReturn = {
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=forEachElementNode.js.map
@@ -1,3 +1,7 @@
1
- export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
1
+ import type * as ts from 'typescript';
2
+ import type { TextRange } from '../types';
2
3
  export { hyphenate as hyphenateTag } from '@vue/shared';
3
4
  export declare function hyphenateAttr(str: string): string;
5
+ export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
6
+ export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
7
+ export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
- exports.getSlotsPropertyName = getSlotsPropertyName;
5
4
  exports.hyphenateAttr = hyphenateAttr;
5
+ exports.getSlotsPropertyName = getSlotsPropertyName;
6
+ exports.getStartEnd = getStartEnd;
7
+ exports.getNodeText = getNodeText;
6
8
  const shared_1 = require("@vue/shared");
7
- function getSlotsPropertyName(vueVersion) {
8
- return vueVersion < 3 ? '$scopedSlots' : '$slots';
9
- }
10
9
  var shared_2 = require("@vue/shared");
11
10
  Object.defineProperty(exports, "hyphenateTag", { enumerable: true, get: function () { return shared_2.hyphenate; } });
12
11
  function hyphenateAttr(str) {
@@ -17,4 +16,17 @@ function hyphenateAttr(str) {
17
16
  }
18
17
  return hyphencase;
19
18
  }
19
+ function getSlotsPropertyName(vueVersion) {
20
+ return vueVersion < 3 ? '$scopedSlots' : '$slots';
21
+ }
22
+ function getStartEnd(ts, node, ast) {
23
+ return {
24
+ start: ts.getTokenPosOfNode(node, ast),
25
+ end: node.end,
26
+ };
27
+ }
28
+ function getNodeText(ts, node, ast) {
29
+ const { start, end } = getStartEnd(ts, node, ast);
30
+ return ast.text.slice(start, end);
31
+ }
20
32
  //# sourceMappingURL=shared.js.map
package/lib/utils/ts.d.ts CHANGED
@@ -16,10 +16,6 @@ export declare class CompilerOptionsResolver {
16
16
  build(defaults?: VueCompilerOptions): VueCompilerOptions;
17
17
  }
18
18
  export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
19
- /**
20
- * @deprecated use `getDefaultCompilerOptions` instead
21
- */
22
- export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>): VueCompilerOptions;
23
19
  export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
24
20
  fileExists(path: string): boolean;
25
21
  writeFile?(path: string, data: string): void;
package/lib/utils/ts.js CHANGED
@@ -4,7 +4,6 @@ exports.CompilerOptionsResolver = void 0;
4
4
  exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
5
5
  exports.createParsedCommandLine = createParsedCommandLine;
6
6
  exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
7
- exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
8
7
  exports.setupGlobalTypes = setupGlobalTypes;
9
8
  const shared_1 = require("@vue/shared");
10
9
  const path_browserify_1 = require("path-browserify");
@@ -218,6 +217,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
218
217
  vitePressExtensions: [],
219
218
  petiteVueExtensions: [],
220
219
  jsxSlots: false,
220
+ strictVModel: strictTemplates,
221
221
  checkUnknownProps: strictTemplates,
222
222
  checkUnknownEvents: strictTemplates,
223
223
  checkUnknownDirectives: strictTemplates,
@@ -271,15 +271,6 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
271
271
  },
272
272
  };
273
273
  }
274
- /**
275
- * @deprecated use `getDefaultCompilerOptions` instead
276
- */
277
- function resolveVueCompilerOptions(options) {
278
- return {
279
- ...getDefaultCompilerOptions(options.target, options.lib),
280
- ...options,
281
- };
282
- }
283
274
  function setupGlobalTypes(rootDir, vueOptions, host) {
284
275
  if (!host.writeFile) {
285
276
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.2.8",
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": "cdf00e6f19971260607ea2347924b94126a254fc"
40
+ "gitHead": "79247b7c24b7202ec676723440fdb36c38e6d450"
41
41
  }