Skip to content

Comments

feat(ast): add escape_raw parameter to template_element builders#18121

Merged
graphite-app[bot] merged 1 commit intomainfrom
feat/template-literal-helper
Jan 19, 2026
Merged

feat(ast): add escape_raw parameter to template_element builders#18121
graphite-app[bot] merged 1 commit intomainfrom
feat/template-literal-helper

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 17, 2026

Summary

  • Add escape_raw: bool parameter to template_element and template_element_with_lone_surrogates builder methods
  • When escape_raw: true, special characters (backticks, ${, backslashes, carriage returns) are automatically escaped in the raw field
  • Parser passes false (already-escaped values from source)
  • Programmatic users pass true (runtime string values need escaping)

This is an alternative approach to #18101 - instead of escaping in codegen, we make the escaping opt-in at the AST builder level.

Closes #18101

Test plan

  • Added test template_literal_escape_when_building_ast in codegen tests
  • Verified parser still works correctly with escape_raw: false

🤖 Generated with Claude Code

@Boshen Boshen requested a review from overlookmotel as a code owner January 17, 2026 06:38
Copilot AI review requested due to automatic review settings January 17, 2026 06:38
@github-actions github-actions bot added A-parser Area - Parser A-ast Area - AST A-codegen Area - Code Generation A-ast-tools Area - AST tools C-enhancement Category - New feature or request labels Jan 17, 2026
Copy link
Contributor

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 adds an escape_raw parameter to the template_element and template_element_with_lone_surrogates AST builder methods to enable automatic escaping of special characters (backticks, ${, backslashes, carriage returns) in template literal raw values. This allows programmatic AST construction to safely pass runtime string values without manual escaping, while the parser continues to pass pre-escaped values from source code.

Changes:

  • Added escape_template_element_raw helper function that escapes special characters in template literal raw values
  • Modified the AST builder generator to add an escape_raw: bool parameter to TemplateElement builders
  • Updated the parser to pass false for escape_raw (values are already escaped from source)
  • Added test demonstrating the escape functionality when building AST programmatically

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
tasks/ast_tools/src/generators/ast_builder.rs Adds escape function and modifies generator to add escape_raw parameter to TemplateElement builder methods
crates/oxc_parser/src/js/expression.rs Updates parser to pass false for the new escape_raw parameter
crates/oxc_codegen/tests/integration/js.rs Adds test verifying escape functionality when building AST with escape_raw: true
crates/oxc_ast/src/generated/ast_builder.rs Generated code with updated builder methods and escape function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 17, 2026

Merging this PR will not alter performance

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/template-literal-helper (7b9e045) with main (a89b245)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (8d292b7) during the generation of this report, so a89b245 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen force-pushed the feat/template-literal-helper branch from 51176d6 to bd8a575 Compare January 17, 2026 06:46
@Boshen Boshen requested a review from Dunqing as a code owner January 17, 2026 06:46
@github-actions github-actions bot added A-minifier Area - Minifier A-transformer Area - Transformer / Transpiler labels Jan 17, 2026
@Boshen Boshen force-pushed the feat/template-literal-helper branch from bd8a575 to 7b9e045 Compare January 17, 2026 07:01
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 19, 2026
Copy link
Member Author

Boshen commented Jan 19, 2026

Merge activity

graphite-app bot pushed a commit that referenced this pull request Jan 19, 2026
)

## Summary

- Add `escape_raw: bool` parameter to `template_element` and `template_element_with_lone_surrogates` builder methods
- When `escape_raw: true`, special characters (backticks, `${`, backslashes, carriage returns) are automatically escaped in the raw field
- Parser passes `false` (already-escaped values from source)
- Programmatic users pass `true` (runtime string values need escaping)

This is an alternative approach to #18101 - instead of escaping in codegen, we make the escaping opt-in at the AST builder level.

Closes #18101

## Test plan

- [x] Added test `template_literal_escape_when_building_ast` in codegen tests
- [x] Verified parser still works correctly with `escape_raw: false`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the feat/template-literal-helper branch from 7b9e045 to 1628f8a Compare January 19, 2026 14:35
)

## Summary

- Add `escape_raw: bool` parameter to `template_element` and `template_element_with_lone_surrogates` builder methods
- When `escape_raw: true`, special characters (backticks, `${`, backslashes, carriage returns) are automatically escaped in the raw field
- Parser passes `false` (already-escaped values from source)
- Programmatic users pass `true` (runtime string values need escaping)

This is an alternative approach to #18101 - instead of escaping in codegen, we make the escaping opt-in at the AST builder level.

Closes #18101

## Test plan

- [x] Added test `template_literal_escape_when_building_ast` in codegen tests
- [x] Verified parser still works correctly with `escape_raw: false`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the feat/template-literal-helper branch from 1628f8a to 2ef5647 Compare January 19, 2026 14:38
@graphite-app graphite-app bot merged commit 2ef5647 into main Jan 19, 2026
22 checks passed
@graphite-app graphite-app bot deleted the feat/template-literal-helper branch January 19, 2026 14:45
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 19, 2026
overlookmotel pushed a commit that referenced this pull request Jan 26, 2026
### 💥 BREAKING CHANGES

- 22dec6a semantic: [**BREAKING**] Remove
`Scoping::scope_build_child_ids` and all related APIs (#18362) (Dunqing)
- 30a4899 oxc: [**BREAKING**] Remove
`CompilerInterface::semantic_child_scope_ids` (#18361) (Dunqing)
- 777fc40 ast: [**BREAKING**] Add `Ident` type (#18354) (Boshen)
- af0ca46 span: [**BREAKING**] Use `ModuleKind::CommonJS` for
`SourceType::cjs()` (#18276) (sapphi-red)

### 🚀 Features

- 0a02026 semantic: Add TS1499 code to diagnostic (#18557) (camc314)
- 8b4618f parser: Add TS1500 code to diagnostic (#18547) (camc314)
- 866b6b3 parser: Add TS1048 code to diagnostic (#18546) (camc314)
- 1117c44 parser: Add TS1054 code to diagnostic (#18541) (camc314)
- e4fcdde semantic: Add TS1053 code to diagnostic (#18539) (camc314)
- bcbf396 semantic: Add TS1052 code to diagnostic (#18538) (camc314)
- 8155edf semantic: Add TS1049 code to diagnostic (#18535) (camc314)
- 51d3b3f parser: Add TS1502 code to diagnostic (#18534) (camc314)
- 00854e8 semantic: Add TS2337 error code to super call diagnostic
(#18531) (camc314)
- 993fd2b parser: Parse unambiguous await with better error messages
(#18480) (Boshen)
- 8db0e78 linter/plugins: Handle BOMs (#18376) (overlookmotel)
- 6ac09e2 linter/plugins: Support source text not being at start of
buffer (#18375) (overlookmotel)
- 2ef5647 ast: Add escape_raw parameter to template_element builders
(#18121) (Boshen)

### 🐛 Bug Fixes

- 74d0998 semantic: Update error msg for multiple `default` cases in
switch stmt (#18526) (camc314)
- c205b0d ast: Remove `ThisExpression` from `TSModuleReference` (#18489)
(Boshen)
- aed3669 parser: Parse HTML-like comments in unambiguous mode (#18442)
(Boshen)
- c4132fb parser: Validate accessor parameters in interface method
signatures (#18391) (Boshen)
- b0cd74d semantic: Allow `var` and `function` with same name in static
blocks (#18358) (Boshen)
- 6037995 semantic: Allow `new.target` in class field initializers
(#18349) (Boshen)
- 9a15c6a semantic: Do not rely on spans for node comparison in
`Function::bind` (#18296) (overlookmotel)

### ⚡ Performance

- 6b600c4 semantic: Skip parent lookup for function declarations in
`Function::bind` (#18293) (overlookmotel)
- c27ad2d semantic: Move check for function declaration out of
`is_function_part_of_if_statement` (#18292) (overlookmotel)
- 63eb89e semantic: Skip checking redeclarations for function
expressions (#18291) (overlookmotel)
- 7c12743 semantic: Skip checking unresolved exports in CommonJS files
(#18250) (overlookmotel)
- 2349031 allocator: Increase initial chunk size from 512B to 16KB
(#18234) (Boshen)

### 📚 Documentation

- 8ccd853 npm: Update package homepage URLs and add keywords (#18509)
(Boshen)
- 9b3165f napi/parser: Clarify when to use `parseAsync` vs `parseSync`
(#18486) (Boshen)
- 1b59f63 napi/parser: Correct typo in README (#18251) (overlookmotel)
- 00ff75f mangler: Fix `top_level` option in example (#18233)
(overlookmotel)
- 2ddc073 semantic: Fix typo in comment (#18238) (overlookmotel)

Co-authored-by: Boshen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools A-codegen Area - Code Generation A-minifier Area - Minifier A-parser Area - Parser A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants