@vue/language-core 3.3.5 → 3.3.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 (66) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/codegen/codeFeatures.d.ts +24 -84
  4. package/lib/codegen/codeFeatures.js +46 -4
  5. package/lib/codegen/names.d.ts +3 -4
  6. package/lib/codegen/names.js +3 -4
  7. package/lib/codegen/script/index.js +5 -5
  8. package/lib/codegen/script/scriptSetup.js +4 -4
  9. package/lib/codegen/style/common.js +7 -11
  10. package/lib/codegen/style/index.d.ts +55 -27
  11. package/lib/codegen/style/index.js +3 -3
  12. package/lib/codegen/template/context.d.ts +55 -124
  13. package/lib/codegen/template/context.js +187 -269
  14. package/lib/codegen/template/element.js +16 -15
  15. package/lib/codegen/template/elementDirectives.js +11 -11
  16. package/lib/codegen/template/elementEvents.js +45 -44
  17. package/lib/codegen/template/elementProps.js +12 -12
  18. package/lib/codegen/template/index.d.ts +55 -27
  19. package/lib/codegen/template/index.js +7 -7
  20. package/lib/codegen/template/interpolation.js +28 -28
  21. package/lib/codegen/template/objectProperty.js +5 -5
  22. package/lib/codegen/template/propertyAccess.js +1 -1
  23. package/lib/codegen/template/slotOutlet.js +8 -10
  24. package/lib/codegen/template/styleScopedClasses.js +4 -4
  25. package/lib/codegen/template/vFor.js +3 -3
  26. package/lib/codegen/template/vIf.js +4 -4
  27. package/lib/codegen/template/vSlot.js +9 -9
  28. package/lib/codegen/utils/boundary.d.ts +7 -2
  29. package/lib/codegen/utils/boundary.js +15 -9
  30. package/lib/codegen/utils/camelized.js +5 -13
  31. package/lib/codegen/utils/escaped.js +4 -9
  32. package/lib/codegen/utils/index.d.ts +1 -1
  33. package/lib/codegen/utils/index.js +3 -3
  34. package/lib/codegen/utils/stringLiteralKey.js +3 -3
  35. package/lib/codegen/utils/unicode.d.ts +1 -1
  36. package/lib/codegen/utils/unicode.js +4 -4
  37. package/lib/languagePlugin.js +2 -1
  38. package/lib/parsers/scriptRanges.d.ts +2 -2
  39. package/lib/parsers/scriptRanges.js +3 -10
  40. package/lib/parsers/scriptSetupRanges.d.ts +2 -2
  41. package/lib/parsers/scriptSetupRanges.js +3 -10
  42. package/lib/parsers/utils.d.ts +1 -0
  43. package/lib/parsers/utils.js +10 -0
  44. package/lib/parsers/vueCompilerOptions.js +2 -2
  45. package/lib/plugins/file-html.js +4 -4
  46. package/lib/plugins/file-md.js +15 -15
  47. package/lib/plugins/file-vue.js +2 -2
  48. package/lib/plugins/vue-root-tags.js +3 -3
  49. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  50. package/lib/plugins/vue-sfc-scripts.js +2 -4
  51. package/lib/plugins/vue-sfc-styles.js +3 -3
  52. package/lib/plugins/vue-sfc-template.js +2 -2
  53. package/lib/plugins/vue-style-css.js +86 -33
  54. package/lib/plugins/vue-template-html.js +3 -3
  55. package/lib/plugins/vue-template-inline-css.js +2 -7
  56. package/lib/plugins/vue-template-inline-ts.js +4 -5
  57. package/lib/plugins/vue-tsx.d.ts +61 -31
  58. package/lib/plugins/vue-tsx.js +26 -23
  59. package/lib/plugins.d.ts +0 -1
  60. package/lib/plugins.js +0 -15
  61. package/lib/utils/forEachTemplateNode.js +36 -43
  62. package/lib/virtualCode/index.js +2 -2
  63. package/package.json +2 -2
  64. package/types/template-helpers.d.ts +14 -24
  65. package/lib/plugins/shared.d.ts +0 -2
  66. package/lib/plugins/shared.js +0 -12
@@ -2,106 +2,8 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code, VueCodeInformation } from '../../types';
3
3
  import type { InlayHintInfo } from '../inlayHints';
4
4
  export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
5
- /**
6
- * Creates and returns a Context object used for generating type-checkable TS code
7
- * from the template section of a .vue file.
8
- *
9
- * ## Implementation Notes for supporting `@vue-ignore`, `@vue-expect-error`, and `@vue-skip` directives.
10
- *
11
- * Vue language tooling supports a number of directives for suppressing diagnostics within
12
- * Vue templates (https://github.com/vuejs/language-tools/pull/3215)
13
- *
14
- * Here is an overview for how support for how @vue-expect-error is implemented within this file
15
- * (@vue-expect-error is the most complicated directive to support due to its behavior of raising
16
- * a diagnostic when it is annotating a piece of code that doesn't actually have any errors/warning/diagnostics).
17
- *
18
- * Given .vue code:
19
- *
20
- * ```vue
21
- * <script setup lang="ts">
22
- * defineProps<{
23
- * knownProp1: string;
24
- * knownProp2: string;
25
- * knownProp3: string;
26
- * knownProp4_will_trigger_unused_expect_error: string;
27
- * }>();
28
- * </script>
29
- *
30
- * <template>
31
- * {{ knownProp1 }}
32
- * {{ error_unknownProp }} <!-- ERROR: Property 'error_unknownProp' does not exist on type [...] -->
33
- * {{ knownProp2 }}
34
- * <!-- @vue-expect-error This suppresses an Unknown Property Error -->
35
- * {{ suppressed_error_unknownProp }}
36
- * {{ knownProp3 }}
37
- * <!-- @vue-expect-error This will trigger Unused '@ts-expect-error' directive.ts(2578) -->
38
- * {{ knownProp4_will_trigger_unused_expect_error }}
39
- * </template>
40
- * ```
41
- *
42
- * The above code should raise two diagnostics:
43
- *
44
- * 1. Property 'error_unknownProp' does not exist on type [...]
45
- * 2. Unused '@ts-expect-error' directive.ts(2578) -- this is the bottom `@vue-expect-error` directive
46
- * that covers code that doesn't actually raise an error -- note that all `@vue-...` directives
47
- * will ultimately translate into `@ts-...` diagnostics.
48
- *
49
- * The above code will produce the following type-checkable TS code (note: omitting asterisks
50
- * to prevent VSCode syntax double-greying out double-commented code).
51
- *
52
- * ```ts
53
- * ( __VLS_ctx.knownProp1 );
54
- * ( __VLS_ctx.error_unknownProp ); // ERROR: Property 'error_unknownProp' does not exist on type [...]
55
- * ( __VLS_ctx.knownProp2 );
56
- * // @vue-expect-error start
57
- * ( __VLS_ctx.suppressed_error_unknownProp );
58
- * // @ts-expect-error __VLS_TS_EXPECT_ERROR
59
- * ;
60
- * // @vue-expect-error end of INTERPOLATION
61
- * ( __VLS_ctx.knownProp3 );
62
- * // @vue-expect-error start
63
- * ( __VLS_ctx.knownProp4_will_trigger_unused_expect_error );
64
- * // @ts-expect-error __VLS_TS_EXPECT_ERROR
65
- * ;
66
- * // @vue-expect-error end of INTERPOLATION
67
- * ```
68
- *
69
- * In the generated code, there are actually 3 diagnostic errors that'll be raised in the first
70
- * pass on this generated code (but through cleverness described below, not all of them will be
71
- * propagated back to the original .vue file):
72
- *
73
- * 1. Property 'error_unknownProp' does not exist on type [...]
74
- * 2. Unused '@ts-expect-error' directive.ts(2578) from the 1st `@ts-expect-error __VLS_TS_EXPECT_ERROR`
75
- * 3. Unused '@ts-expect-error' directive.ts(2578) from the 2nd `@ts-expect-error __VLS_TS_EXPECT_ERROR`
76
- *
77
- * Be sure to pay careful attention to the mixture of `@vue-expect-error` and `@ts-expect-error`;
78
- * Within the TS file, the only "real" directives recognized by TS are going to be prefixed with `@ts-`;
79
- * any `@vue-` prefixed directives in the comments are only for debugging purposes.
80
- *
81
- * As mentioned above, there are 3 diagnostics errors that'll be generated for the above code, but
82
- * only 2 should be propagated back to the original .vue file.
83
- *
84
- * (The reason we structure things this way is somewhat complicated, but in short it allows us
85
- * to lean on TS as much as possible to generate actual `unused @ts-expect-error directive` errors
86
- * while covering a number of edge cases.)
87
- *
88
- * So, we need a way to dynamically decide whether each of the `@ts-expect-error __VLS_TS_EXPECT_ERROR`
89
- * directives should be reported as an unused directive or not.
90
- *
91
- * To do this, we'll make use of the `shouldReport` callback that'll optionally be provided to the
92
- * `verification` property of the `CodeInformation` object attached to the mapping between source .vue
93
- * and generated .ts code. The `verification` property determines whether "verification" (which includes
94
- * semantic diagnostics) should be performed on the generated .ts code, and `shouldReport`, if provided,
95
- * can be used to determine whether a given diagnostic should be reported back "upwards" to the original
96
- * .vue file or not.
97
- *
98
- * See the comments in the code below for how and where we use this hook to keep track of whether
99
- * an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
100
- * and additionally how we use that to determine whether to propagate diagnostics back upward.
101
- */
102
5
  export declare function createTemplateCodegenContext(): {
103
- generatedTypes: Set<string>;
104
- readonly currentInfo: {
6
+ getCommentInfo: () => {
105
7
  ignoreError?: boolean;
106
8
  expectError?: {
107
9
  token: number;
@@ -112,40 +14,69 @@ export declare function createTemplateCodegenContext(): {
112
14
  offset: number;
113
15
  };
114
16
  };
17
+ enter: (node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode) => boolean;
18
+ exit: () => Generator<Code>;
115
19
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
116
- inVFor: boolean;
20
+ getInternalVariable: () => string;
21
+ scopes: {
22
+ add(value: string): /*elided*/ any;
23
+ declare(...variables: string[]): void;
24
+ end(): Generator<Code, any, any>;
25
+ clear(): void;
26
+ delete(value: string): boolean;
27
+ forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
28
+ has(value: string): boolean;
29
+ readonly size: number;
30
+ [Symbol.iterator](): SetIterator<string>;
31
+ entries(): SetIterator<[string, string]>;
32
+ keys(): SetIterator<string>;
33
+ values(): SetIterator<string>;
34
+ readonly [Symbol.toStringTag]: string;
35
+ }[];
36
+ scope: () => {
37
+ add(value: string): any;
38
+ declare(...variables: string[]): void;
39
+ end(): Generator<Code, any, any>;
40
+ clear(): void;
41
+ delete(value: string): boolean;
42
+ forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
43
+ has(value: string): boolean;
44
+ readonly size: number;
45
+ [Symbol.iterator](): SetIterator<string>;
46
+ entries(): SetIterator<[string, string]>;
47
+ keys(): SetIterator<string>;
48
+ values(): SetIterator<string>;
49
+ readonly [Symbol.toStringTag]: string;
50
+ };
51
+ contextAccesses: Map<string, Map<string, Set<number>>>;
52
+ accessVariable: (source: string, name: string, offset?: number) => void;
53
+ generateAutoImport: () => Generator<Code>;
54
+ conditions: string[];
55
+ generateConditionGuards: () => Generator<string, void, unknown>;
56
+ hoistVars: Map<string, string>;
57
+ getHoistVariable: (originalVar: string) => string;
58
+ generateHoistVariables: () => Generator<string, void, unknown>;
59
+ templateRefs: Map<string, {
60
+ typeExp: string;
61
+ offset: number;
62
+ }[]>;
63
+ addTemplateRef: (name: string, typeExp: string, offset: number) => void;
64
+ components: (() => string)[];
65
+ dollarVars: Set<string>;
66
+ inlayHints: InlayHintInfo[];
67
+ generatedTypes: Set<string>;
68
+ inheritedAttrVars: Set<string>;
69
+ singleRootElTypes: Set<string>;
70
+ singleRootNodes: Set<CompilerDOM.ElementNode | null>;
117
71
  slots: {
118
72
  name: string;
119
73
  offset?: number;
120
74
  tagRange: [number, number];
121
- nodeLoc: any;
122
75
  propsVar: string;
123
76
  }[];
124
77
  dynamicSlots: {
125
78
  expVar: string;
126
79
  propsVar: string;
127
80
  }[];
128
- dollarVars: Set<string>;
129
- componentAccessMap: Map<string, Map<string, Set<number>>>;
130
- blockConditions: string[];
131
- inlayHints: InlayHintInfo[];
132
- inheritedAttrVars: Set<string>;
133
- templateRefs: Map<string, {
134
- typeExp: string;
135
- offset: number;
136
- }[]>;
137
- singleRootElTypes: Set<string>;
138
- singleRootNodes: Set<CompilerDOM.ElementNode | null>;
139
- addTemplateRef(name: string, typeExp: string, offset: number): void;
140
- recordComponentAccess(source: string, name: string, offset?: number): void;
141
- scopes: Set<string>[];
142
- components: (() => string)[];
143
- declare(...varNames: string[]): void;
144
- startScope(): () => Generator<Code, any, any>;
145
- getInternalVariable(): string;
146
- getHoistVariable(originalVar: string): string;
147
- generateHoistVariables(): Generator<string, void, unknown>;
148
- generateConditionGuards(): Generator<string, void, unknown>;
149
- enter(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): boolean;
150
- exit(): Generator<Code>;
81
+ inVFor: boolean;
151
82
  };