Skip to content

fix(language-core): avoid generic type loss due to destructured props #4821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
perf: use Set
  • Loading branch information
KazariEX committed Sep 6, 2024
commit 4cf221704fcb55ac63fc15b61bf308697eeb6b10
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/componentSelf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function* generateComponentSelf(
if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
continue;
}
if (options.scriptSetupRanges.props.destructured?.includes(varName)) {
if (options.scriptSetupRanges.props.destructured?.has(varName)) {
continue;
}
const templateOffset = options.getGeneratedLength();
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/parsers/scriptSetupRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function parseScriptSetupRanges(

const props: {
name?: string;
destructured?: string[];
destructured?: Set<string>;
define?: ReturnType<typeof parseDefineFunction> & {
statement: TextRange;
};
Expand Down Expand Up @@ -308,7 +308,7 @@ export function parseScriptSetupRanges(
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
if (ts.isVariableDeclaration(parent)) {
if (ts.isObjectBindingPattern(parent.name)) {
props.destructured = collectVars(ts, parent.name, ast, [], false);
props.destructured = new Set(collectVars(ts, parent.name, ast, [], false));
}
else {
props.name = getNodeText(ts, parent.name, ast);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/lib/plugins/vue-inlayhints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Scope = Record<string, boolean>;
export function findDestructuredProps(
ts: typeof import('typescript'),
ast: ts.SourceFile,
props: string[]
props: Set<string>
) {
const rootScope: Scope = {};
const scopeStack: Scope[] = [rootScope];
Expand Down