Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

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

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

mdjermanovic
Copy link
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
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
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.

@nzakas nzakas merged commit 8082caa into main Jul 8, 2024
11 checks passed
@nzakas nzakas deleted the catch-pattern-defs branch July 8, 2024 14:42
@github-actions github-actions bot mentioned this pull request Jul 8, 2024
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