Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/language-tools
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.2
Choose a base ref
...
head repository: vuejs/language-tools
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5e197d08eaef57209ff2927c943ba1db3bf4eff6
Choose a head ref

Commits on Aug 29, 2024

  1. chore: update insiders.json

    johnsoncodehk committed Aug 29, 2024
    Copy the full SHA
    4cf3c33 View commit details
  2. fix: apply snake case on globalTypes filename (#4749)

    KazariEX authored Aug 29, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d18cade View commit details

Commits on Aug 30, 2024

  1. feat: generate global types file into node_modules/.vue-global-types (

    KazariEX authored Aug 30, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    07bc594 View commit details
  2. Copy the full SHA
    931444f View commit details
  3. chore: code consistency

    johnsoncodehk committed Aug 30, 2024
    Copy the full SHA
    ac1bec7 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a94ed38 View commit details
  5. fix: Whitelist ms-dynamics-smb.al extension for Vue Hybrid Mode. (#4765)

    Add ms-dynamics-smb.al extension (Microsoft Dynamics) to whitelist.
    kyleweishaupt authored Aug 30, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    950c9e1 View commit details
  6. fix(language-core): hoist $refs type (#4763)

    johnsoncodehk authored Aug 30, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    306936b View commit details
  7. fix(language-server): leaking named pipes

    johnsoncodehk committed Aug 30, 2024
    Copy the full SHA
    8bc2416 View commit details
  8. fix(language-core): disable lib check on global types file (#4767)

    KazariEX authored Aug 30, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    63fca0b View commit details

Commits on Aug 31, 2024

  1. feat(language-core): navigation support for template-ref (#4726)

    KazariEX authored Aug 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    69be985 View commit details
  2. fix(vscode): correct highlighting on tag starting with template (#4770

    )
    KazariEX authored Aug 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    923f835 View commit details
  3. fix(typescript-plugin): compatible with Yarn PnP

    close #4751
    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    af7fc39 View commit details
  4. fix(language-core): prevent circular reference of templateRef (#4768)

    zhiyuanzmj authored Aug 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a081e07 View commit details
  5. Revert "fix(vscode): correct highlighting on tag starting with `templ…

    …ate` (#4770)"
    
    This reverts commit 923f835.
    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    05a8020 View commit details
  6. fix(language-core): using interface merging for GlobalComponents

    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    8d8e069 View commit details
  7. fix(language-core): fallthroughAttributes causes global components …

    …to be self-referential
    
    close #4761
    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    9e2aaf7 View commit details
  8. fix(language-core): re-fix Yarn PnP compatibility

    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    4fae9dd View commit details
  9. fix(language-core): auto-completion for the last line of template blo…

    …ck (#4771)
    zhiyuanzmj authored Aug 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    87a804a View commit details
  10. chore: 2.1.4 changelog

    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    be5c92f View commit details
  11. fix(language-core): update ast correctly on repeated v-for modifica…

    …tions (#4772)
    KazariEX authored Aug 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ea9bb02 View commit details
  12. Copy the full SHA
    b3bfc44 View commit details
  13. Update CHANGELOG.md

    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    b5723b4 View commit details
  14. Add --no-git-tag-version flag

    johnsoncodehk committed Aug 31, 2024
    Copy the full SHA
    5e197d0 View commit details
Showing with 422 additions and 182 deletions.
  1. +11 −0 .github/ISSUE_TEMPLATE/bug_report.yml
  2. +25 −0 CHANGELOG.md
  3. +1 −0 extensions/vscode/src/common.ts
  4. +9 −1 insiders.json
  5. +1 −1 package.json
  6. +23 −14 packages/component-meta/lib/base.ts
  7. +47 −25 packages/language-core/lib/codegen/globalTypes.ts
  8. +0 −15 packages/language-core/lib/codegen/localTypes.ts
  9. +10 −1 packages/language-core/lib/codegen/script/index.ts
  10. +0 −3 packages/language-core/lib/codegen/script/internalComponent.ts
  11. +9 −1 packages/language-core/lib/codegen/script/scriptSetup.ts
  12. +54 −13 packages/language-core/lib/codegen/script/template.ts
  13. +20 −30 packages/language-core/lib/codegen/template/element.ts
  14. +13 −8 packages/language-core/lib/codegen/template/index.ts
  15. +8 −2 packages/language-core/lib/parsers/scriptSetupRanges.ts
  16. +35 −3 packages/language-core/lib/plugins/vue-template-html.ts
  17. +1 −0 packages/language-core/lib/types.ts
  18. +1 −0 packages/language-server/lib/hybridModeProject.ts
  19. +23 −14 packages/language-server/lib/initialize.ts
  20. +48 −0 packages/language-server/tests/renaming.spec.ts
  21. +17 −6 packages/tsc/index.ts
  22. +4 −28 packages/tsc/tests/__snapshots__/dts.spec.ts.snap
  23. +17 −6 packages/tsc/tests/dts.spec.ts
  24. +17 −6 packages/typescript-plugin/index.ts
  25. +7 −0 test-workspace/tsc/passedFixtures/vue3.5/templateRef/components.d.ts
  26. +1 −1 test-workspace/tsc/passedFixtures/vue3.5/templateRef/main.vue
  27. +12 −4 test-workspace/tsc/passedFixtures/vue3.5/templateRef/template-ref.vue
  28. +8 −0 test-workspace/tsc/passedFixtures/vue3.5/templateRef_missingImport/main.vue
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -47,6 +47,17 @@ body:
description: Output of `npx envinfo --system --binaries --browsers`
render: shell
placeholder: System, Binaries, Browsers
- type: textarea
id: dependencies
attributes:
label: package.json dependencies
description: You may add your list of dependencies here as it helps us to investigate your report.
render: json
placeholder: |
{
"dependencies": {},
"devDependencies": {},
}
- type: textarea
id: steps-to-reproduce
attributes:
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,31 @@

> [Join the Insiders Program](https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition) for more exclusive features and updates.
## 2.1.4 <sup>official</sup>, 2.1.5 <sup>insiders</sup> (2024-09-01)

### Features

- **typescript-plugin, language-server:** generate global types file into `node_modules/.vue-global-types` (#4752) - Thanks to @KazariEX!
- **language-core:** navigation support for template-ref (#4726) - Thanks to @KazariEX!

### Bug Fixes

- **language-core, typescript-plugin, language-server:** apply snake case on globalTypes filename (#4749) - Thanks to @KazariEX!
- **language-core:** hoist `$refs` type (#4763)
- **language-core:** disable lib check on global types file (#4767) - Thanks to @KazariEX!
- **language-core:** prevent circular reference of templateRef (#4768) - Thanks to @zhiyuanzmj!
- **language-core:** using interface merging for `GlobalComponents`
- **language-core:** `fallthroughAttributes` causes global components to be self-referential (#4761)
- **language-core:** auto-completion for the last line of template block (#4771) - Thanks to @zhiyuanzmj!
- **language-core:** update ast correctly on repeated `v-for` modifications (#4772) - Thanks to @KazariEX!
- **language-server:** leaking named pipes (#4672)
- **typescript-plugin:** compatible with Yarn PnP (#4751)
- **vscode:** whitelist `ms-dynamics-smb.al` extension for Vue Hybrid Mode. (#4765) - Thanks to @kyleweishaupt!

### Other Changes

- Add optional "dependencies" textarea to issue template (#4758) - Thanks to @davidmatter!

## 2.1.2 <sup>official</sup>, 2.1.3 <sup>insiders</sup> (2024-08-29)

### Bug Fixes
1 change: 1 addition & 0 deletions extensions/vscode/src/common.ts
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ function isExtensionCompatibleWithHybridMode(extension: vscode.Extension<any>) {
|| extension.id === 'Divlo.vscode-styled-jsx-languageserver'
|| extension.id === 'nrwl.angular-console'
|| extension.id === 'ShenQingchuan.vue-vine-extension'
|| extension.id === 'ms-dynamics-smb.al'
) {
return true;
}
10 changes: 9 additions & 1 deletion insiders.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"latest": "2.1.1",
"latest": "2.1.3",
"versions": [
{
"version": "2.1.3",
"date": "2024-8-29",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.3",
"AFDIAN": "https://afdian.com/p/28e5269865e111ef95ff52540025c377"
}
},
{
"version": "2.1.1",
"date": "2024-8-29",
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
"prerelease": "npm run build && npm run test",
"version:test": "lerna version --exact --force-publish --yes --sync-workspace-lock --no-push --no-git-tag-version",
"release": "npm run release:base && npm run release:vue",
"release:base": "lerna publish --exact --force-publish --yes --sync-workspace-lock",
"release:base": "lerna publish --exact --force-publish --yes --sync-workspace-lock --no-git-tag-version",
"release:vue": "cd ./extensions/vscode && npm run release",
"release:next": "npm run release:next-base && npm run release:next-vue",
"release:next-base": "npm run release:base -- --dist-tag next",
37 changes: 23 additions & 14 deletions packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
@@ -86,7 +86,10 @@ export function baseCreate(
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
ts,
projectHost.getCompilationSettings(),
commandLine.vueOptions,
{
...commandLine.vueOptions,
__setupedGlobalTypes: () => true,
},
id => id
);
const language = vue.createLanguage(
@@ -135,27 +138,33 @@ export function baseCreate(
const { languageServiceHost } = createLanguageServiceHost(ts, ts.sys, language, s => s, projectHost);
const tsLs = ts.createLanguageService(languageServiceHost);

const directoryExists = languageServiceHost.directoryExists?.bind(languageServiceHost);
const fileExists = languageServiceHost.fileExists.bind(languageServiceHost);
const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost);
const globalTypesName = `__globalTypes_${commandLine.vueOptions.target}_${commandLine.vueOptions.strictTemplates}.d.ts`;
const snapshots = new Map<string, ts.IScriptSnapshot>();
const globalTypesName = `${commandLine.vueOptions.lib}_${commandLine.vueOptions.target}_${commandLine.vueOptions.strictTemplates}.d.ts`;
const globalTypesContents = vue.generateGlobalTypes('global', commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates);
const globalTypesSnapshot: ts.IScriptSnapshot = {
getText: (start, end) => globalTypesContents.substring(start, end),
getLength: () => globalTypesContents.length,
getChangeRange: () => undefined,
};
if (directoryExists) {
languageServiceHost.directoryExists = path => {
if (path.endsWith('.vue-global-types')) {
return true;
}
return directoryExists(path);
};
}
languageServiceHost.fileExists = path => {
if (path.endsWith(globalTypesName)) {
if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) {
return true;
}
return fileExists(path);
};
languageServiceHost.getScriptSnapshot = path => {
if (path.endsWith(globalTypesName)) {
if (!snapshots.has(path)) {
const contents = vue.generateGlobalTypes(commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates);
snapshots.set(path, {
getText: (start, end) => contents.substring(start, end),
getLength: () => contents.length,
getChangeRange: () => undefined,
});
}
return snapshots.get(path)!;
if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) {
return globalTypesSnapshot;
}
return getScriptSnapshot(path);
};
72 changes: 47 additions & 25 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { getSlotsPropertyName } from '../utils/shared';
import { endOfLine, newLine } from './common';

export function generateGlobalTypes(lib: string, target: number, strictTemplates: boolean) {
export function generateGlobalTypes(mode: 'global' | 'local', lib: string, target: number, strictTemplates: boolean) {
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record<string, unknown>'}`;
return `
const __VLS_globalComponents = { ...{} as import('${lib}').GlobalComponents };

declare const __VLS_intrinsicElements: __VLS_IntrinsicElements;
declare const __VLS_directiveBindingRestFields = { instance: null, oldValue: null, modifiers: null as any, dir: null as any };
let str = '';
let globalComponentsType: string;

if (mode === 'global') {
str += `// @ts-nocheck${newLine}`;
str += `export {}${endOfLine}`;
str += `declare module '${lib}' {${newLine}`;
str += ` export interface GlobalComponents { }${newLine}`;
str += `}${newLine}`;
str += `declare global {${newLine}`;
globalComponentsType = `import('${lib}').GlobalComponents`;
}
else {
str += `const __VLS_globalComponents = { ...{} as import('${lib}').GlobalComponents }${endOfLine}`;
globalComponentsType = `void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents`;
}

str += `
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
const __VLS_directiveBindingRestFields = { instance: null, oldValue: null, modifiers: null as any, dir: null as any };
type __VLS_IntrinsicElements = ${(
target >= 3.3
@@ -20,8 +37,8 @@ type __VLS_Element = ${(
)}
type __VLS_GlobalComponents = ${(
target >= 3.5
? `void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents;`
: `(void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents) & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`
? globalComponentsType
: `(${globalComponentsType}) & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`
)}
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
@@ -70,40 +87,40 @@ type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
>;
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
declare function __VLS_getVForSourceType(source: number): [number, number, number][];
declare function __VLS_getVForSourceType(source: string): [string, number, number][];
declare function __VLS_getVForSourceType<T extends any[]>(source: T): [
function __VLS_getVForSourceType(source: number): [number, number, number][];
function __VLS_getVForSourceType(source: string): [string, number, number][];
function __VLS_getVForSourceType<T extends any[]>(source: T): [
item: T[number],
key: number,
index: number,
][];
declare function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
key: number,
index: undefined,
][];
// #3845
declare function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
key: number,
index: undefined,
][];
declare function __VLS_getVForSourceType<T>(source: T): [
function __VLS_getVForSourceType<T>(source: T): [
item: T[keyof T],
key: keyof T,
index: number,
][];
// @ts-ignore
declare function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
// @ts-ignore
declare function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
declare function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
? T | __VLS_unknownDirective
: NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
declare function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
declare function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
declare function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends new (...args: any) => any
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
attrs?: any,
@@ -113,13 +130,18 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
: T extends (...args: any) => any ? T
: (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
declare function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
>>;
declare function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
declare function __VLS_tryAsConstant<const T>(t: T): T;
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
function __VLS_tryAsConstant<const T>(t: T): T;
`;

if (mode === 'global') {
str += `}${newLine}`;
}
return str;
};
15 changes: 0 additions & 15 deletions packages/language-core/lib/codegen/localTypes.ts
Original file line number Diff line number Diff line change
@@ -80,19 +80,6 @@ type __VLS_TypePropsToOption<T> = {
`__VLS_OmitIndexSignature`,
() => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${endOfLine}`
);
const PickRefsExpose = defineHelper(
`__VLS_PickRefsExpose`,
() => `
type __VLS_PickRefsExpose<T> = T extends object
? { [K in keyof T]: (T[K] extends any[]
? Parameters<T[K][0]['expose']>[0][]
: T[K] extends { expose?: (exposed: infer E) => void }
? E
: T[K]) | null }
: never;
`.trimStart()
);

const helpers = {
[PrettifyLocal.name]: PrettifyLocal,
[OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
@@ -101,7 +88,6 @@ type __VLS_PickRefsExpose<T> = T extends object
[PropsChildren.name]: PropsChildren,
[TypePropsToOption.name]: TypePropsToOption,
[OmitIndexSignature.name]: OmitIndexSignature,
[PickRefsExpose.name]: PickRefsExpose,
};
used.clear();

@@ -117,7 +103,6 @@ type __VLS_PickRefsExpose<T> = T extends object
get PropsChildren() { return PropsChildren.name; },
get TypePropsToOption() { return TypePropsToOption.name; },
get OmitIndexSignature() { return OmitIndexSignature.name; },
get PickRefsExpose() { return PickRefsExpose.name; },
};

function* generate(names: string[]) {
11 changes: 10 additions & 1 deletion packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import { createScriptCodegenContext, ScriptCodegenContext } from './context';
import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup';
import { generateSrc } from './src';
import { generateTemplate } from './template';
import { generateGlobalTypes } from '../globalTypes';

export const codeFeatures = {
all: {
@@ -51,7 +52,12 @@ export interface ScriptCodegenOptions {
export function* generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext> {
const ctx = createScriptCodegenContext(options);

yield `/// <reference types="${options.vueCompilerOptions.lib}/dist/__globalTypes_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
if (options.vueCompilerOptions.__setupedGlobalTypes?.()) {
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
}
else {
yield `/* placeholder */`;
}

if (options.sfc.script?.src) {
yield* generateSrc(options.sfc.script, options.sfc.script.src);
@@ -136,6 +142,9 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${endOfLine}`;
}
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
if (!options.vueCompilerOptions.__setupedGlobalTypes?.()) {
yield generateGlobalTypes('local', options.vueCompilerOptions.lib, options.vueCompilerOptions.target, options.vueCompilerOptions.strictTemplates);
}

if (options.sfc.scriptSetup) {
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures.verification];
Original file line number Diff line number Diff line change
@@ -47,9 +47,6 @@ export function* generateInternalComponent(
}
yield `}${endOfLine}`; // return {
yield `},${newLine}`; // setup() {
if (options.vueCompilerOptions.target >= 3.5) {
yield `__typeRefs: {} as __VLS_Refs,${newLine}`;
}
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
const emitOptionCodes = [...generateEmitsOption(options, options.sfc.scriptSetup, options.scriptSetupRanges)];
for (const code of emitOptionCodes) {
10 changes: 9 additions & 1 deletion packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
@@ -244,7 +244,15 @@ function* generateSetupFunction(
}
for (const { define } of scriptSetupRanges.templateRefs) {
if (define?.arg) {
setupCodeModifies.push([[`<__VLS_Refs[${scriptSetup.content.slice(define.arg.start, define.arg.end)}], keyof __VLS_Refs>`], define.arg.start - 1, define.arg.start - 1]);
setupCodeModifies.push([
[
`<__VLS_Refs[`,
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.navigation),
`], keyof __VLS_Refs>`
],
define.arg.start - 1,
define.arg.start - 1
]);
}
}
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
Loading