Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

fix: Definition#name in catch patterns should be Identifier node#127

Merged
nzakas merged 2 commits intomainfrom
catch-pattern-defs
Jul 8, 2024
Merged

fix: Definition#name in catch patterns should be Identifier node#127
nzakas merged 2 commits intomainfrom
catch-pattern-defs

Conversation

@mdjermanovic
Copy link
Copy Markdown
Member

@mdjermanovic mdjermanovic commented Jul 6, 2024

Refs eslint/eslint#18636 (review)

Currently, if catch param is a pattern, Definition#name of variables created in the pattern points to the pattern instead of the Identifier nodes.

Repro:

import * as eslintScope from 'eslint-scope';
import * as espree from 'espree';

const code = "try {} catch({ message }) {}";

const ast = espree.parse(code, { range: true, ecmaVersion: 2015 });
const scopeManager = eslintScope.analyze(ast, { ecmaVersion: 2015 });

const catchScope = scopeManager.scopes[2];
const variable = catchScope.variables[0];

console.log(variable.name); // "message"

console.log(variable.defs[0].name.type); // "ObjectPattern" !

This fixes the mentioned Definitions to point to Identifier nodes.

I've verified that all tests in eslint/eslint are still passing after this change. All new tests added in eslint/eslint#18636 are also passing after this change.

Copy link
Copy Markdown
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Would like @nzakas to verify.

Copy link
Copy Markdown
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants