Skip to content

refactor: cached parse template literal #391

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 3 commits into from
Jul 19, 2025
Merged

refactor: cached parse template literal #391

merged 3 commits into from
Jul 19, 2025

Conversation

yeonjuan
Copy link
Owner

@yeonjuan yeonjuan commented Jul 19, 2025

@yeonjuan yeonjuan requested a review from Copilot July 19, 2025 10:39
Copilot

This comment was marked as outdated.

@yeonjuan yeonjuan marked this pull request as ready for review July 19, 2025 10:41
@yeonjuan yeonjuan requested a review from Copilot July 19, 2025 11:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors template literal parsing to improve caching by separating parsing from visitor traversal. Instead of requiring visitors during parsing, it now caches the parsed AST and allows optional visitor execution during retrieval.

  • Makes the visitor parameter optional in the parse function
  • Introduces a new parseTemplateLiteral utility that handles caching and optional visitor traversal
  • Updates all rule implementations to use the new unified interface

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/template-parser/lib/traverser.js Makes parent parameter optional with default value
packages/template-parser/lib/template-parser.js Makes visitor parameter optional and conditionally executes traversal
packages/template-parser/lib/index.js Exports traverse function publicly
packages/eslint-plugin/lib/rules/utils/template-literal.js Replaces getCachedParseResult with parseTemplateLiteral that handles both caching and visitor execution
packages/eslint-plugin/lib/rules/utils/visitors.js Updates to use new parseTemplateLiteral function
packages/eslint-plugin/lib/rules/*.js Updates all rules to use parseTemplateLiteral instead of separate parse and traverse calls
packages/eslint-plugin/tests/rules/utils/template-literal.test.js Adds tests for caching behavior and visitor execution
packages/eslint-plugin/tests/rules/*.test.js Adds test cases for template literal parsing with different syntax patterns
Comments suppressed due to low confidence (1)

packages/template-parser/lib/template-parser.js:15

  • The parameter name 'visitor' is inconsistent with the JSDoc comment which still references 'visitors' (plural). Consider updating the JSDoc to use 'visitor' (singular) to match the parameter name.
function parse(node, sourceCode, visitor) {

@yeonjuan yeonjuan merged commit d534f44 into main Jul 19, 2025
6 checks passed
Copy link

codecov bot commented Jul 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.52%. Comparing base (8823fb3) to head (bcbaa68).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #391      +/-   ##
==========================================
+ Coverage   98.30%   98.52%   +0.22%     
==========================================
  Files          82       82              
  Lines        2657     2651       -6     
  Branches      726      730       +4     
==========================================
  Hits         2612     2612              
+ Misses         45       39       -6     
Flag Coverage Δ
unittest 98.52% <100.00%> (+0.22%) ⬆️

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

Files with missing lines Coverage Δ
packages/eslint-plugin/lib/rules/indent/indent.js 99.43% <100.00%> (-0.01%) ⬇️
...ackages/eslint-plugin/lib/rules/no-duplicate-id.js 100.00% <100.00%> (+4.76%) ⬆️
...es/eslint-plugin/lib/rules/no-duplicate-in-head.js 100.00% <100.00%> (ø)
...eslint-plugin/lib/rules/no-multiple-empty-lines.js 100.00% <100.00%> (ø)
...ages/eslint-plugin/lib/rules/no-trailing-spaces.js 100.00% <100.00%> (+7.14%) ⬆️
.../eslint-plugin/lib/rules/utils/template-literal.js 100.00% <100.00%> (ø)
packages/eslint-plugin/lib/rules/utils/visitors.js 100.00% <100.00%> (ø)
packages/template-parser/lib/template-parser.js 100.00% <100.00%> (ø)
packages/template-parser/lib/traverser.js 100.00% <100.00%> (ø)
🚀 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.

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.

1 participant