Skip to content

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Nov 18, 2025

Fixes the issue identified in #15664 where the tagged template transform plugin incorrectly handled template literals containing escape sequences.

Examples

// Input
foo`</script>\n`
// Before (incorrect): 
foo(_t || (_t = taggedTemplateLiteral(["</script>\\n"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral(["</script>\n"], ["</script>\\n"])));

// Input with invalid escape
foo`</script>\u`
// Before (syntax error):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\u"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral([void 0], ["</script>\\u"])));

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Nov 18, 2025
Copy link
Member Author

Dunqing commented Nov 18, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Dunqing Dunqing changed the title fix(transformer): handle escape sequences in tagged template transform fix(transformer/tagged-template-transform): handle escape sequences Nov 18, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 18, 2025

CodSpeed Performance Report

Merging #15830 will not alter performance

Comparing 11-18-fix_transformer_handle_escape_sequences_in_tagged_template_transform (d973355) with main (2191ae9)

Summary

✅ 38 untouched
⏩ 7 skipped1

Footnotes

  1. 7 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.

@Dunqing Dunqing changed the title fix(transformer/tagged-template-transform): handle escape sequences fix(transformer/tagged-template-transform): handle \n escape sequences Nov 18, 2025
@Dunqing Dunqing force-pushed the 11-18-fix_transformer_handle_escape_sequences_in_tagged_template_transform branch from 603308c to d973355 Compare November 18, 2025 08:44
@Dunqing Dunqing marked this pull request as ready for review November 18, 2025 12:31
Copilot AI review requested due to automatic review settings November 18, 2025 12:31
Copilot finished reviewing on behalf of Dunqing November 18, 2025 12:33
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 fixes the handling of escape sequences in the tagged template transform plugin. Previously, the plugin incorrectly transformed template literals containing escape sequences (like \n, \t) or invalid escape sequences (like incomplete \u), causing either incorrect output or syntax errors.

The key changes include:

  • Modified the transform to generate both "cooked" and "raw" string arrays when they differ
  • Added support for invalid escape sequences using void 0 in the cooked array
  • Added comprehensive test coverage for both valid and invalid escape sequences

Reviewed Changes

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

Show a summary per file
File Description
crates/oxc_transformer/src/plugins/tagged_template_transform.rs Updated transform logic to detect when cooked differs from raw, generate both cooked and raw arrays when needed, and use void 0 for invalid escapes
tasks/transform_conformance/tests/plugin-tagged-template-transform/test/fixtures/escape-sequence/input.js Added test input for valid escape sequences (\n and \t)
tasks/transform_conformance/tests/plugin-tagged-template-transform/test/fixtures/escape-sequence/output.js Added expected output showing correct handling of escape sequences with dual array arguments
tasks/transform_conformance/tests/plugin-tagged-template-transform/test/fixtures/invalid-escape/input.js Added test input for invalid escape sequence (\u)
tasks/transform_conformance/tests/plugin-tagged-template-transform/test/fixtures/invalid-escape/output.js Added expected output showing void 0 in cooked array for invalid escape
tasks/transform_conformance/snapshots/oxc.snap.md Updated test pass count from 198/329 to 200/331, reflecting the 2 new passing tests

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

Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Looks good!

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Nov 19, 2025
Copy link
Member

overlookmotel commented Nov 19, 2025

Merge activity

…ces (#15830)

Fixes the issue identified in #15664 where the tagged template transform plugin incorrectly handled template literals containing escape sequences.

### Examples

```js
// Input
foo`</script>\n`
// Before (incorrect):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\n"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral(["</script>\n"], ["</script>\\n"])));

// Input with invalid escape
foo`</script>\u`
// Before (syntax error):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\u"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral([void 0], ["</script>\\u"])));
@graphite-app graphite-app bot force-pushed the 11-18-fix_transformer_handle_escape_sequences_in_tagged_template_transform branch from d973355 to 7c46a9e Compare November 19, 2025 23:36
@graphite-app graphite-app bot merged commit 7c46a9e into main Nov 19, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 11-18-fix_transformer_handle_escape_sequences_in_tagged_template_transform branch November 19, 2025 23:41
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 19, 2025
Copilot AI pushed a commit that referenced this pull request Nov 21, 2025
…ces (#15830)

Fixes the issue identified in #15664 where the tagged template transform plugin incorrectly handled template literals containing escape sequences.

### Examples

```js
// Input
foo`</script>\n`
// Before (incorrect):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\n"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral(["</script>\n"], ["</script>\\n"])));

// Input with invalid escape
foo`</script>\u`
// Before (syntax error):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\u"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral([void 0], ["</script>\\u"])));
overlookmotel pushed a commit that referenced this pull request Nov 24, 2025
### 💥 BREAKING CHANGES

- cbb27fd ast: [**BREAKING**] Add `TSGlobalDeclaration` type (#15712)
(overlookmotel)

### 🚀 Features

- 0c1f82b linter/plugins: Add `tokens` property to `Program` (#16020)
(overlookmotel)
- 6cff132 span: Add `Span::merge_within` method (#15869) (sapphi-red)
- 102365d allocator/vec: Add `Vec::into_bump_slice` method (#15770)
(Dunqing)

### 🐛 Bug Fixes

- e2ca770 codegen: Add support for printing type arguments in new
expressions (#15963) (Ives van Hoorne)
- 2bd3cb6 apps, editors, napi: Fix `oxlint-disable` comments (#16014)
(overlookmotel)
- 622cb5e parser: Preserve legal comments with @preserve/@license when
preceded by other annotations (#15929) (copilot-swe-agent)
- 7c46a9e transformer/tagged-template-transform: Handle `\n` escape
sequences (#15830) (Dunqing)
- f386efc minifier: Avoid generating invalid spans (#15778) (sapphi-red)
- d4ff004 parser: Forbid invalid modifiers on `module` and `global`
(#15723) (overlookmotel)
- 2191ae9 semantic: Allow reserved keywords in typescript ambient
contexts (#15495) (sapphi-red)
- 7d1ebad isolated-declarations: Incorrect nested namespace output in
isolated declarations (#15800) (copilot-swe-agent)

### ⚡ Performance

- b4b0ed8 transformer/typescript: Reverse order of checks (#15722)
(overlookmotel)

### 📚 Documentation

- c81a331 data_structures: Doc comments on fields of `Stack` (#15793)
(overlookmotel)
- cfae31d allocator: Use `allocator` as var name in examples (#15781)
(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-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants