Skip to content

fix(typescript-estree): the token value of an escaped identifier differs with espree #11116

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dbarabashh
Copy link
Contributor

@dbarabashh dbarabashh commented Apr 29, 2025

PR Checklist

Overview

Show case 1 Show case 2

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @dbarabashh!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Apr 29, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit b0b6876
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6815377af6e75100085e5fc6
😎 Deploy Preview https://deploy-preview-11116--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97 (🔴 down 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Apr 29, 2025

View your CI Pipeline Execution ↗ for commit b0b6876.

Command Status Duration Result
nx typecheck ast-spec ✅ Succeeded 3s View ↗
nx run-many --target=build --exclude website --... ✅ Succeeded 50s View ↗
nx run-many --target=clean ✅ Succeeded 11s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-05 15:20:23 UTC

@dbarabashh dbarabashh changed the title fix(eslint-plugin): decode unicode escapes in identifier tokens fix(eslint-plugin): the token value of an escaped identifier differs with espree Apr 29, 2025
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.84%. Comparing base (bca8a91) to head (b0b6876).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11116   +/-   ##
=======================================
  Coverage   90.84%   90.84%           
=======================================
  Files         497      497           
  Lines       50320    50332   +12     
  Branches     8311     8315    +4     
=======================================
+ Hits        45714    45726   +12     
  Misses       4591     4591           
  Partials       15       15           
Flag Coverage Δ
unittest 90.84% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/typescript-estree/src/node-utils.ts 63.81% <100.00%> (+0.68%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dbarabashh dbarabashh changed the title fix(eslint-plugin): the token value of an escaped identifier differs with espree fix(typescript-estree): the token value of an escaped identifier differs with espree Apr 29, 2025
@dbarabashh

This comment was marked as resolved.

@rubiesonthesky

This comment was marked as resolved.

@JoshuaKGoldberg

This comment was marked as resolved.

return String.fromCodePoint(codePoint);
},
);
}
Copy link
Member

Choose a reason for hiding this comment

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

[Question] I'm not very familiar with these \u shenanigans and don't particularly feel a drive to be. Is there a standard package that does this? If not, maybe it would make sense to make one?

JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes May 2, 2025
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg 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! 🚀

I would definitely prefer someone like @bradzacher who's more familiar with text parsing review. But from my less-than-expert perspective this all looks great.

expect(unescapeUnicodeIdentifier('\\u00ZZ')).toBe('\\u00ZZ');
expect(unescapeUnicodeIdentifier('\\u{ZZ}')).toBe('\\u{ZZ}');
});
});
Copy link
Member

Choose a reason for hiding this comment

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

[Testing] Nit: I'm a fan of having one thing under test per it() case. I think it would make sense to split each of these two-paired ones into two it()s. But I wouldn't block on it, this file already doesn't align to that (and even more so in existing code!).

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label May 2, 2025
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

my only concern here is that we're going to be doing a regex scan over every single Identifier in every single file we parse just so that we can potentially catch one specific edge-case that (a) likely isn't present in 99.9999% of code and (b) likely doesn't impact anyone's lint rules...

acorn gets away with producing a token with the non-encoded character because it is a true parser -- it derives the AST from the tokens it produces.

Truth be told -- I'm honestly not completely sold on us landing this to align with acorn/espree. WDYT @typescript-eslint/triage-team?

@dbarabashh
Copy link
Contributor Author

@bradzacher what if add a check before running the regex? Something like:

if (!text.includes('\\u')) {
  return text;
}

this way we keep the compatibility but only run the expensive regex when there's actually a unicode escape. Should solve the performance concern since 99.9% of identifiers will take the fast path. any thoughts?

@JoshuaKGoldberg JoshuaKGoldberg removed the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label May 5, 2025
@JoshuaKGoldberg JoshuaKGoldberg requested a review from bradzacher May 5, 2025 15:25
@JoshuaKGoldberg JoshuaKGoldberg dismissed their stale review May 5, 2025 15:26

Brad raises a good point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: The token value of an escaped identifier differs with espree
4 participants