@vue/language-core 3.0.3 → 3.0.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.
package/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export * from './lib/codegen/globalTypes';
2
2
  export * from './lib/codegen/template';
3
- export * from './lib/codegen/utils';
4
3
  export * from './lib/languagePlugin';
5
4
  export * from './lib/parsers/scriptSetupRanges';
6
5
  export * from './lib/plugins';
7
6
  export * from './lib/types';
7
+ export * from './lib/utils/collectBindings';
8
8
  export * from './lib/utils/parseSfc';
9
9
  export * from './lib/utils/shared';
10
10
  export * from './lib/utils/ts';
package/index.js CHANGED
@@ -17,11 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.tsCodegen = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
- __exportStar(require("./lib/codegen/utils"), exports);
21
20
  __exportStar(require("./lib/languagePlugin"), exports);
22
21
  __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
23
22
  __exportStar(require("./lib/plugins"), exports);
24
23
  __exportStar(require("./lib/types"), exports);
24
+ __exportStar(require("./lib/utils/collectBindings"), exports);
25
25
  __exportStar(require("./lib/utils/parseSfc"), exports);
26
26
  __exportStar(require("./lib/utils/shared"), exports);
27
27
  __exportStar(require("./lib/utils/ts"), exports);
@@ -87,6 +87,21 @@ declare const raw: {
87
87
  navigation: true;
88
88
  completion: true;
89
89
  };
90
+ doNotReportTs2339AndTs2551: {
91
+ verification: {
92
+ shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
93
+ };
94
+ };
95
+ doNotReportTs2353AndTs2561: {
96
+ verification: {
97
+ shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
98
+ };
99
+ };
100
+ doNotReportTs6133: {
101
+ verification: {
102
+ shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
103
+ };
104
+ };
90
105
  };
91
106
  export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
92
107
  export {};
@@ -73,6 +73,26 @@ const raw = {
73
73
  navigation: true,
74
74
  completion: true,
75
75
  },
76
+ doNotReportTs2339AndTs2551: {
77
+ verification: {
78
+ // https://typescript.tv/errors/#ts2339
79
+ // https://typescript.tv/errors/#ts2551
80
+ shouldReport: (_source, code) => String(code) !== '2339' && String(code) !== '2551',
81
+ },
82
+ },
83
+ doNotReportTs2353AndTs2561: {
84
+ verification: {
85
+ // https://typescript.tv/errors/#ts2353
86
+ // https://typescript.tv/errors/#ts2561
87
+ shouldReport: (_source, code) => String(code) !== '2353' && String(code) !== '2561',
88
+ },
89
+ },
90
+ doNotReportTs6133: {
91
+ verification: {
92
+ // https://typescript.tv/errors/#ts6133
93
+ shouldReport: (_source, code) => String(code) !== '6133',
94
+ },
95
+ },
76
96
  };
77
97
  exports.codeFeatures = raw;
78
98
  //# sourceMappingURL=codeFeatures.js.map
@@ -1,3 +1,3 @@
1
1
  import type { VueCompilerOptions } from '../types';
2
- export declare function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
3
- export declare function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
2
+ export declare function getGlobalTypesFileName(options: VueCompilerOptions): string;
3
+ export declare function generateGlobalTypes(options: VueCompilerOptions): string;
@@ -3,16 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGlobalTypesFileName = getGlobalTypesFileName;
4
4
  exports.generateGlobalTypes = generateGlobalTypes;
5
5
  const shared_1 = require("../utils/shared");
6
- function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
6
+ function getGlobalTypesFileName(options) {
7
7
  return [
8
- lib,
9
- target,
10
- checkUnknownProps,
11
- checkUnknownEvents,
12
- checkUnknownComponents,
8
+ options.lib,
9
+ options.target,
10
+ options.checkUnknownProps,
13
11
  ].map(v => (typeof v === 'boolean' ? Number(v) : v)).join('_') + '.d.ts';
14
12
  }
15
- function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
13
+ function generateGlobalTypes(options) {
14
+ const { lib, target, checkUnknownProps } = options;
16
15
  const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
17
16
  let text = `// @ts-nocheck\nexport {};\n`;
18
17
  if (target < 3.5) {
@@ -50,7 +49,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
50
49
  N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
51
50
  N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
52
51
  N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
53
- ${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
52
+ {};
54
53
  type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
55
54
  ? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
56
55
  , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
@@ -61,12 +60,12 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
61
60
  : {};
62
61
  type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
63
62
  __ctx?: {
64
- attrs?: any,
65
- slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>,
66
- emit?: T extends { $emit: infer Emit } ? Emit : {},
67
- props?: ${fnPropsType},
68
- expose?: (exposed: T) => void,
69
- }
63
+ attrs?: any;
64
+ slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>;
65
+ emit?: T extends { $emit: infer Emit } ? Emit : {};
66
+ props?: ${fnPropsType};
67
+ expose?: (exposed: T) => void;
68
+ };
70
69
  };
71
70
  type __VLS_IsFunction<T, K> = K extends keyof T
72
71
  ? __VLS_IsAny<T[K]> extends false
@@ -75,15 +74,19 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
75
74
  : true
76
75
  : false
77
76
  : false;
78
- type __VLS_NormalizeComponentEvent<Props, Emits, onEvent extends keyof Props, Event extends keyof Emits, CamelizedEvent extends keyof Emits> = (
79
- __VLS_IsFunction<Props, onEvent> extends true
80
- ? Props
81
- : __VLS_IsFunction<Emits, Event> extends true
82
- ? { [K in onEvent]?: Emits[Event] }
83
- : __VLS_IsFunction<Emits, CamelizedEvent> extends true
84
- ? { [K in onEvent]?: Emits[CamelizedEvent] }
85
- : Props
86
- )${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
77
+ type __VLS_NormalizeComponentEvent<
78
+ Props,
79
+ Emits,
80
+ onEvent extends keyof Props,
81
+ Event extends keyof Emits,
82
+ CamelizedEvent extends keyof Emits,
83
+ > = __VLS_IsFunction<Props, onEvent> extends true
84
+ ? Props
85
+ : __VLS_IsFunction<Emits, Event> extends true
86
+ ? { [K in onEvent]?: Emits[Event] }
87
+ : __VLS_IsFunction<Emits, CamelizedEvent> extends true
88
+ ? { [K in onEvent]?: Emits[CamelizedEvent] }
89
+ : Props;
87
90
  // fix https://github.com/vuejs/language-tools/issues/926
88
91
  type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
89
92
  type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -150,7 +153,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
150
153
  : T extends (...args: any) => any ? T
151
154
  : __VLS_FunctionalComponent<{}>;
152
155
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
153
- function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
156
+ function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownProps ? '' : ' & Record<string, unknown>'}) => void;
154
157
  function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
155
158
  function __VLS_tryAsConstant<const T>(t: T): T;
156
159
  }
@@ -248,10 +248,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
248
248
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
249
249
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
250
250
  if (syntax) {
251
- if (!options.vueCompilerOptions.skipTemplateCodegen
252
- && (scriptSetupRanges.defineSlots
253
- || options.templateCodegen?.slots.length
254
- || options.templateCodegen?.dynamicSlots.length)) {
251
+ if (scriptSetupRanges.defineSlots
252
+ || options.templateCodegen?.slots.length
253
+ || options.templateCodegen?.dynamicSlots.length) {
255
254
  yield `const __VLS_component = `;
256
255
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
257
256
  yield utils_1.endOfLine;
@@ -130,6 +130,9 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
130
130
  withoutHighlightAndCompletion: VueCodeInformation;
131
131
  withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
132
132
  withoutSemantic: VueCodeInformation;
133
+ doNotReportTs2339AndTs2551: VueCodeInformation;
134
+ doNotReportTs2353AndTs2561: VueCodeInformation;
135
+ doNotReportTs6133: VueCodeInformation;
133
136
  };
134
137
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
135
138
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
@@ -110,7 +110,12 @@ function* generateComponent(options, ctx, node) {
110
110
  .map(name => `'${name}'`)
111
111
  .join(`, `);
112
112
  yield `>).`;
113
- yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
113
+ yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.resolveCodeFeatures({
114
+ ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
115
+ ...options.vueCompilerOptions.checkUnknownComponents
116
+ ? codeFeatures_1.codeFeatures.verification
117
+ : codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
118
+ }));
114
119
  yield `${utils_1.endOfLine}`;
115
120
  const camelizedTag = (0, shared_1.camelize)(node.tag);
116
121
  if (utils_1.identifierRegex.test(camelizedTag)) {
@@ -140,14 +145,7 @@ function* generateComponent(options, ctx, node) {
140
145
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
141
146
  yield `}))${utils_1.endOfLine}`;
142
147
  yield `const `;
143
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.resolveCodeFeatures({
144
- verification: {
145
- shouldReport(_source, code) {
146
- // https://typescript.tv/errors/#ts6133
147
- return String(code) !== '6133';
148
- },
149
- },
150
- }), componentVNodeVar);
148
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.doNotReportTs6133, componentVNodeVar);
151
149
  yield ` = ${componentFunctionalVar}`;
152
150
  yield* generateComponentGeneric(ctx);
153
151
  yield `(`;
@@ -4,7 +4,7 @@ import type { Code, VueCodeInformation } from '../../types';
4
4
  import type { TemplateCodegenContext } from './context';
5
5
  import type { TemplateCodegenOptions } from './index';
6
6
  export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
7
- export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
7
+ export declare function generateEventArg(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
8
8
  export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
9
9
  export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
10
10
  export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
@@ -7,6 +7,7 @@ exports.generateModelEventExpression = generateModelEventExpression;
7
7
  exports.isCompoundExpression = isCompoundExpression;
8
8
  const CompilerDOM = require("@vue/compiler-dom");
9
9
  const shared_1 = require("@vue/shared");
10
+ const codeFeatures_1 = require("../codeFeatures");
10
11
  const utils_1 = require("../utils");
11
12
  const camelized_1 = require("../utils/camelized");
12
13
  const wrapWith_1 = require("../utils/wrapWith");
@@ -48,12 +49,12 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
48
49
  yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
49
50
  if (prop.name === 'on') {
50
51
  yield `{ `;
51
- yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
+ yield* generateEventArg(options, ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
53
  yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
53
54
  }
54
55
  yield `{ `;
55
56
  if (prop.name === 'on') {
56
- yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
57
+ yield* generateEventArg(options, ctx, source, start, propPrefix.slice(0, -1));
57
58
  yield `: `;
58
59
  yield* generateEventExpression(options, ctx, prop);
59
60
  }
@@ -65,10 +66,14 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
65
66
  }
66
67
  }
67
68
  }
68
- function* generateEventArg(ctx, name, start, directive = 'on', features = {
69
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
70
- ...ctx.codeFeatures.navigationWithoutRename,
71
- }) {
69
+ function* generateEventArg(options, ctx, name, start, directive = 'on', features) {
70
+ features ??= ctx.resolveCodeFeatures({
71
+ ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
72
+ ...codeFeatures_1.codeFeatures.navigationWithoutRename,
73
+ ...options.vueCompilerOptions.checkUnknownEvents
74
+ ? codeFeatures_1.codeFeatures.verification
75
+ : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
76
+ });
72
77
  if (directive.length) {
73
78
  name = (0, shared_1.capitalize)(name);
74
79
  }
@@ -27,7 +27,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
27
27
  && !prop.arg.loc.source.endsWith(']')) {
28
28
  if (!isComponent) {
29
29
  yield `...{ `;
30
- yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
30
+ yield* (0, elementEvents_1.generateEventArg)(options, ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
31
31
  yield `: `;
32
32
  yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
33
33
  yield `},`;
@@ -223,16 +223,9 @@ function getShouldCamelize(options, prop, propName) {
223
223
  function getPropsCodeInfo(ctx, strictPropsCheck) {
224
224
  return ctx.resolveCodeFeatures({
225
225
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
226
- verification: strictPropsCheck || {
227
- shouldReport(_source, code) {
228
- // https://typescript.tv/errors/#ts2353
229
- // https://typescript.tv/errors/#ts2561
230
- if (String(code) === '2353' || String(code) === '2561') {
231
- return false;
232
- }
233
- return true;
234
- },
235
- },
226
+ ...strictPropsCheck
227
+ ? codeFeatures_1.codeFeatures.verification
228
+ : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
236
229
  });
237
230
  }
238
231
  function getModelPropName(node, vueCompilerOptions) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateInterpolation = generateInterpolation;
4
4
  const shared_1 = require("@vue/shared");
5
+ const collectBindings_1 = require("../../utils/collectBindings");
5
6
  const shared_2 = require("../../utils/shared");
6
7
  const utils_1 = require("../utils");
7
8
  // https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
@@ -133,7 +134,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
133
134
  walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars);
134
135
  }
135
136
  else if (ts.isVariableDeclaration(node)) {
136
- const bindingNames = (0, utils_1.collectBindingNames)(ts, node.name, ast);
137
+ const bindingNames = (0, collectBindings_1.collectBindingNames)(ts, node.name, ast);
137
138
  for (const name of bindingNames) {
138
139
  ctx.addLocalVariable(name);
139
140
  blockVars.push(name);
@@ -195,7 +196,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
195
196
  function walkIdentifiersInFunction(ts, node, ast, cb, ctx) {
196
197
  const functionArgs = [];
197
198
  for (const param of node.parameters) {
198
- functionArgs.push(...(0, utils_1.collectBindingNames)(ts, param.name, ast));
199
+ functionArgs.push(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
199
200
  if (param.type) {
200
201
  walkIdentifiersInTypeNode(ts, param.type, cb);
201
202
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVFor = generateVFor;
4
4
  exports.parseVForNode = parseVForNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
+ const collectBindings_1 = require("../../utils/collectBindings");
6
7
  const utils_1 = require("../utils");
7
8
  const elementChildren_1 = require("./elementChildren");
8
9
  const interpolation_1 = require("./interpolation");
@@ -13,7 +14,7 @@ function* generateVFor(options, ctx, node) {
13
14
  yield `for (const [`;
14
15
  if (leftExpressionRange && leftExpressionText) {
15
16
  const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
16
- forBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, collectAst, collectAst));
17
+ forBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, collectAst, collectAst));
17
18
  yield [
18
19
  leftExpressionText,
19
20
  'template',
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVSlot = generateVSlot;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const collectBindings_1 = require("../../utils/collectBindings");
5
6
  const shared_1 = require("../../utils/shared");
6
7
  const utils_1 = require("../utils");
7
8
  const wrapWith_1 = require("../utils/wrapWith");
@@ -35,7 +36,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
35
36
  }
36
37
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
37
38
  const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
38
- slotBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, slotAst, slotAst));
39
+ slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
39
40
  yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
40
41
  }
41
42
  for (const varName of slotBlockVars) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tenp.js.map
@@ -5,16 +5,6 @@ export declare const newLine = "\n";
5
5
  export declare const endOfLine = ";\n";
6
6
  export declare const combineLastMapping: VueCodeInformation;
7
7
  export declare const identifierRegex: RegExp;
8
- export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
9
- export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
10
- id: ts.Identifier;
11
- isRest: boolean;
12
- initializer: ts.Expression | undefined;
13
- }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
14
- id: ts.Identifier;
15
- isRest: boolean;
16
- initializer: ts.Expression | undefined;
17
- }[];
18
8
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
19
9
  export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
20
10
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
@@ -1,40 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
4
- exports.collectBindingNames = collectBindingNames;
5
- exports.collectIdentifiers = collectIdentifiers;
6
4
  exports.normalizeAttributeValue = normalizeAttributeValue;
7
5
  exports.createTsAst = createTsAst;
8
6
  exports.generateSfcBlockSection = generateSfcBlockSection;
9
- const shared_1 = require("../../utils/shared");
10
7
  exports.newLine = `\n`;
11
8
  exports.endOfLine = `;${exports.newLine}`;
12
9
  exports.combineLastMapping = { __combineOffset: 1 };
13
10
  exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
14
- function collectBindingNames(ts, node, ast) {
15
- return collectIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
16
- }
17
- function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
18
- if (ts.isIdentifier(node)) {
19
- results.push({ id: node, isRest, initializer });
20
- }
21
- else if (ts.isObjectBindingPattern(node)) {
22
- for (const el of node.elements) {
23
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
24
- }
25
- }
26
- else if (ts.isArrayBindingPattern(node)) {
27
- for (const el of node.elements) {
28
- if (ts.isBindingElement(el)) {
29
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
30
- }
31
- }
32
- }
33
- else {
34
- ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
35
- }
36
- return results;
37
- }
38
11
  function normalizeAttributeValue(node) {
39
12
  let offset = node.loc.start.offset;
40
13
  let content = node.loc.source;
@@ -72,5 +72,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
72
72
  isDefaultImport?: boolean;
73
73
  isNamespace?: boolean;
74
74
  }[];
75
- export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
76
75
  export {};
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
4
  exports.parseBindingRanges = parseBindingRanges;
5
- exports.findBindingVars = findBindingVars;
6
- const utils_1 = require("../codegen/utils");
5
+ const collectBindings_1 = require("../utils/collectBindings");
7
6
  const shared_1 = require("../utils/shared");
8
7
  const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
9
8
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
@@ -147,7 +146,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
147
146
  };
148
147
  if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
149
148
  defineProps.destructured = new Map();
150
- const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name);
149
+ const identifiers = (0, collectBindings_1.collectBindingIdentifiers)(ts, parent.name);
151
150
  for (const { id, isRest, initializer } of identifiers) {
152
151
  const name = _getNodeText(id);
153
152
  if (isRest) {
@@ -267,8 +266,8 @@ function parseBindingRanges(ts, ast) {
267
266
  ts.forEachChild(ast, node => {
268
267
  if (ts.isVariableStatement(node)) {
269
268
  for (const decl of node.declarationList.declarations) {
270
- const vars = _findBindingVars(decl.name);
271
- bindings.push(...vars.map(range => ({ range })));
269
+ const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
270
+ bindings.push(...ranges.map(range => ({ range })));
272
271
  }
273
272
  }
274
273
  else if (ts.isFunctionDeclaration(node)) {
@@ -332,41 +331,6 @@ function parseBindingRanges(ts, ast) {
332
331
  function _getNodeText(node) {
333
332
  return (0, shared_1.getNodeText)(ts, node, ast);
334
333
  }
335
- function _findBindingVars(left) {
336
- return findBindingVars(ts, left, ast);
337
- }
338
- }
339
- function findBindingVars(ts, left, ast) {
340
- const vars = [];
341
- worker(left);
342
- return vars;
343
- function worker(node) {
344
- if (ts.isIdentifier(node)) {
345
- vars.push((0, shared_1.getStartEnd)(ts, node, ast));
346
- }
347
- // { ? } = ...
348
- // [ ? ] = ...
349
- else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
350
- for (const property of node.elements) {
351
- if (ts.isBindingElement(property)) {
352
- worker(property.name);
353
- }
354
- }
355
- }
356
- // { foo: ? } = ...
357
- else if (ts.isPropertyAssignment(node)) {
358
- worker(node.initializer);
359
- }
360
- // { foo } = ...
361
- else if (ts.isShorthandPropertyAssignment(node)) {
362
- vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
363
- }
364
- // { ...? } = ...
365
- // [ ...? ] = ...
366
- else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
367
- worker(node.expression);
368
- }
369
- }
370
334
  }
371
335
  function getStatementRange(ts, parents, node, ast) {
372
336
  let statementRange;
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parseSfc_1 = require("../utils/parseSfc");
4
+ const plugin = ({ vueCompilerOptions }) => {
5
+ return {
6
+ version: 2.1,
7
+ getLanguageId(fileName) {
8
+ if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
+ return 'vue';
10
+ }
11
+ },
12
+ isValidFile(_fileName, languageId) {
13
+ return languageId === 'vue';
14
+ },
15
+ parseSFC2(_fileName, languageId, content) {
16
+ if (languageId !== 'vue') {
17
+ return;
18
+ }
19
+ return (0, parseSfc_1.parse)(content);
20
+ },
21
+ updateSFC(sfc, change) {
22
+ const blocks = [
23
+ sfc.descriptor.template,
24
+ sfc.descriptor.script,
25
+ sfc.descriptor.scriptSetup,
26
+ ...sfc.descriptor.styles,
27
+ ...sfc.descriptor.customBlocks,
28
+ ].filter(block => !!block);
29
+ const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
30
+ if (!hitBlock) {
31
+ return;
32
+ }
33
+ const oldContent = hitBlock.content;
34
+ const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
35
+ + change.newText
36
+ + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
37
+ // #3449
38
+ const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
39
+ const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
40
+ if (insertedEndTag) {
41
+ return;
42
+ }
43
+ const lengthDiff = change.newText.length - (change.end - change.start);
44
+ for (const block of blocks) {
45
+ if (block.loc.start.offset > change.end) {
46
+ block.loc.start.offset += lengthDiff;
47
+ }
48
+ if (block.loc.end.offset >= change.end) {
49
+ block.loc.end.offset += lengthDiff;
50
+ }
51
+ }
52
+ return sfc;
53
+ },
54
+ };
55
+ };
56
+ exports.default = plugin;
57
+ //# sourceMappingURL=file-css.js.map
@@ -15,23 +15,16 @@ const plugin = () => {
15
15
  if (embeddedFile.id === 'root_tags') {
16
16
  embeddedFile.content.push([sfc.content, undefined, 0, shared_1.allCodeFeatures]);
17
17
  for (const block of [
18
+ sfc.template,
18
19
  sfc.script,
19
20
  sfc.scriptSetup,
20
- sfc.template,
21
21
  ...sfc.styles,
22
22
  ...sfc.customBlocks,
23
23
  ]) {
24
24
  if (!block) {
25
25
  continue;
26
26
  }
27
- let content = block.content;
28
- if (content.endsWith('\r\n')) {
29
- content = content.slice(0, -2);
30
- }
31
- else if (content.endsWith('\n')) {
32
- content = content.slice(0, -1);
33
- }
34
- const offset = content.lastIndexOf('\n') + 1;
27
+ const offset = block.content.lastIndexOf('\n', block.content.lastIndexOf('\n') - 1) + 1;
35
28
  // fix folding range end position failed to mapping
36
29
  (0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.slice(block.startTagEnd, block.startTagEnd + offset), [
37
30
  '',
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const plugin = () => {
4
+ return {
5
+ version: 2.1,
6
+ compileSFCStyle(_lang, style) {
7
+ return {
8
+ imports: [...parseCssImports(style)],
9
+ bindings: [...parseCssBindings(style)],
10
+ classNames: [...parseCssClassNames(style)],
11
+ };
12
+ },
13
+ };
14
+ };
15
+ exports.default = plugin;
16
+ const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
17
+ const cssBindingReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
18
+ const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
19
+ const commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
20
+ const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
21
+ function* parseCssImports(css) {
22
+ const matches = css.matchAll(cssImportReg);
23
+ for (const match of matches) {
24
+ let text = match[0];
25
+ let offset = match.index;
26
+ if (text.startsWith("'") || text.startsWith('"')) {
27
+ text = text.slice(1, -1);
28
+ offset += 1;
29
+ }
30
+ if (text) {
31
+ yield { text, offset };
32
+ }
33
+ }
34
+ }
35
+ function* parseCssBindings(css) {
36
+ css = fillBlank(css, commentReg);
37
+ const matchs = css.matchAll(cssBindingReg);
38
+ for (const match of matchs) {
39
+ const matchText = match.slice(1).find(t => t);
40
+ if (matchText) {
41
+ const offset = match.index + css.slice(match.index).indexOf(matchText);
42
+ yield { offset, text: matchText };
43
+ }
44
+ }
45
+ }
46
+ function* parseCssClassNames(css) {
47
+ css = fillBlank(css, commentReg, fragmentReg);
48
+ const matches = css.matchAll(cssClassNameReg);
49
+ for (const match of matches) {
50
+ const matchText = match[1];
51
+ if (matchText) {
52
+ yield { offset: match.index, text: matchText };
53
+ }
54
+ }
55
+ }
56
+ function fillBlank(css, ...regs) {
57
+ for (const reg of regs) {
58
+ css = css.replace(reg, match => ' '.repeat(match.length));
59
+ }
60
+ return css;
61
+ }
62
+ //# sourceMappingURL=vue-style-css.js.map
@@ -1,5 +1,6 @@
1
1
  import type { Code, Sfc, VueLanguagePlugin } from '../types';
2
2
  export declare const tsCodegen: WeakMap<Sfc, {
3
+ getLang: () => string;
3
4
  getScriptRanges: () => {
4
5
  exportDefault: (import("../types").TextRange & {
5
6
  expression: import("../types").TextRange;
@@ -115,7 +116,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
115
116
  name?: string;
116
117
  })[];
117
118
  } | undefined;
118
- getLang: () => string;
119
+ getSetupSlotsAssignName: () => string | undefined;
119
120
  getGeneratedScript: () => {
120
121
  codes: Code[];
121
122
  generatedTemplate: boolean;
@@ -166,6 +167,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
166
167
  withoutHighlightAndCompletion: import("../types").VueCodeInformation;
167
168
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
168
169
  withoutSemantic: import("../types").VueCodeInformation;
170
+ doNotReportTs2339AndTs2551: import("../types").VueCodeInformation;
171
+ doNotReportTs2353AndTs2561: import("../types").VueCodeInformation;
172
+ doNotReportTs6133: import("../types").VueCodeInformation;
169
173
  };
170
174
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
175
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
@@ -198,9 +198,10 @@ function createTsx(fileName, sfc, ctx) {
198
198
  };
199
199
  });
200
200
  return {
201
+ getLang,
201
202
  getScriptRanges,
202
203
  getScriptSetupRanges,
203
- getLang,
204
+ getSetupSlotsAssignName,
204
205
  getGeneratedScript,
205
206
  getGeneratedTemplate,
206
207
  };
package/lib/types.d.ts CHANGED
@@ -20,7 +20,7 @@ export type Code = Segment<VueCodeInformation>;
20
20
  export interface VueCompilerOptions {
21
21
  target: number;
22
22
  lib: string;
23
- globalTypesPath: (fileName: string) => string | undefined;
23
+ globalTypesPath: (fileName: string) => string | void;
24
24
  extensions: string[];
25
25
  vitePressExtensions: string[];
26
26
  petiteVueExtensions: string[];
@@ -0,0 +1,12 @@
1
+ import type * as ts from 'typescript';
2
+ export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
3
+ export declare function collectBindingRanges(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): import("../types").TextRange[];
4
+ export declare function collectBindingIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
5
+ id: ts.Identifier;
6
+ isRest: boolean;
7
+ initializer: ts.Expression | undefined;
8
+ }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
9
+ id: ts.Identifier;
10
+ isRest: boolean;
11
+ initializer: ts.Expression | undefined;
12
+ }[];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectBindingNames = collectBindingNames;
4
+ exports.collectBindingRanges = collectBindingRanges;
5
+ exports.collectBindingIdentifiers = collectBindingIdentifiers;
6
+ const shared_1 = require("./shared");
7
+ function collectBindingNames(ts, node, ast) {
8
+ return collectBindingIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
9
+ }
10
+ function collectBindingRanges(ts, node, ast) {
11
+ return collectBindingIdentifiers(ts, node).map(({ id }) => (0, shared_1.getStartEnd)(ts, id, ast));
12
+ }
13
+ function collectBindingIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
14
+ if (ts.isIdentifier(node)) {
15
+ results.push({ id: node, isRest, initializer });
16
+ }
17
+ else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
18
+ for (const el of node.elements) {
19
+ if (ts.isBindingElement(el)) {
20
+ collectBindingIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
21
+ }
22
+ }
23
+ }
24
+ else {
25
+ ts.forEachChild(node, node => collectBindingIdentifiers(ts, node, results, false));
26
+ }
27
+ return results;
28
+ }
29
+ //# sourceMappingURL=collectBindings.js.map
package/lib/utils/ts.js CHANGED
@@ -179,23 +179,25 @@ class CompilerOptionsResolver {
179
179
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
180
180
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
181
181
  };
182
- if (this.fileExists && this.globalTypesPath === undefined) {
183
- const fileDirToGlobalTypesPath = new Map();
184
- resolvedOptions.globalTypesPath = fileName => {
185
- const fileDir = path_browserify_1.posix.dirname(fileName);
186
- if (fileDirToGlobalTypesPath.has(fileDir)) {
187
- return fileDirToGlobalTypesPath.get(fileDir);
188
- }
189
- const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
190
- const result = root
191
- ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
192
- : undefined;
193
- fileDirToGlobalTypesPath.set(fileDir, result);
194
- return result;
195
- };
196
- }
197
- else {
198
- resolvedOptions.globalTypesPath = () => this.globalTypesPath;
182
+ if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
183
+ if (this.fileExists && this.globalTypesPath === undefined) {
184
+ const fileDirToGlobalTypesPath = new Map();
185
+ resolvedOptions.globalTypesPath = fileName => {
186
+ const fileDir = path_browserify_1.posix.dirname(fileName);
187
+ if (fileDirToGlobalTypesPath.has(fileDir)) {
188
+ return fileDirToGlobalTypesPath.get(fileDir);
189
+ }
190
+ const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
191
+ const result = root
192
+ ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
193
+ : undefined;
194
+ fileDirToGlobalTypesPath.set(fileDir, result);
195
+ return result;
196
+ };
197
+ }
198
+ else {
199
+ resolvedOptions.globalTypesPath = () => this.globalTypesPath;
200
+ }
199
201
  }
200
202
  return resolvedOptions;
201
203
  }
@@ -239,7 +241,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
239
241
  return {
240
242
  target,
241
243
  lib,
242
- globalTypesPath: () => undefined,
244
+ globalTypesPath: shared_1.NOOP,
243
245
  extensions: ['.vue'],
244
246
  vitePressExtensions: [],
245
247
  petiteVueExtensions: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "129f30ff8d8d976abf0431063be5c6c4cf88f0fd"
40
+ "gitHead": "148d386f9779c2de64cdcbd35310e03b36943b05"
41
41
  }