Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Mar 22, 2025

I attempted fixing this but realizing #9965 (comment) and it might be out of my reach 😓 Please feel free to take over.

In terms of test262 conformance, there was no edge case like #9965 (comment). So, remaining surrogate related mismatch is a following form. This difference is actually not visible in js world since the difference of acorn output is due to how JSON.stringify automatically normalizes string.

@@ -139,7 +139,7 @@
                 "type": "Literal",
                 "start": 408,
                 "end": 416,
-                "value": "\udf06",
+                "value": "\uDF06",
                 "raw": "\"\\uDF06\""
               }
             ],
@@ -299,7 +299,7 @@
                 "type": "Literal",
                 "start": 593,
                 "end": 619,
-                "value": "\ud834𝌆\ud834",
+                "value": "\uD834\uD834\uDF06\uD834",
                 "raw": "\"\\uD834\\uD834\\uDF06\\uD834\""
               }
> console.log(JSON.stringify("\uD834\uD834\uDF06\uD834"))
"\ud834𝌆\ud834"

@github-actions github-actions bot added A-ast Area - AST C-bug Category - Bug labels Mar 22, 2025
Copy link
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


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.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 22, 2025

CodSpeed Instrumentation Performance Report

Merging #9965 will not alter performance

Comparing 03-22-fix_estree_ast_fix_lossy_stringliteral.value_ (92c54aa) with main (eaea5fd)

Summary

✅ 33 untouched benchmarks

Comment on lines +318 to +319
let raw = self.0.raw.unwrap();
JsonSafeString(&raw[1..raw.len() - 1]).serialize(serializer);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought this would work similar to codegen, but this doesn't seem to work.

For example, when js has single quoted with double quote inside:

'\uD800"'

this ends up as invalid json:

{
  "type": "Literal",
  "start": 0,
  "end": 9,
  "value": "\uD800"",  <-- double quote inside double quote
  "raw": "'\\uD800\"'"
}

Copy link
Member

@overlookmotel overlookmotel Mar 24, 2025

Choose a reason for hiding this comment

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

You could check what quotes were used in original code via the 1st byte of raw field. If ", then the way you've done it should work. If ', then you'd need to replace " with \".

I actually have a half-done PR doing exactly that. But was having trouble getting conformance to pass. Maybe after #9964 it will. I'll try and finish it off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds good. I think there is a weird case like this unnecessary escape '\"', so perhaps it requires traversing manually character by character? Anyways, I'll close this in favor of your fix 🙏
I was also not sure about raw deser, so I was mostly giving up. 😅

@graphite-app graphite-app bot changed the base branch from 03-22-fix_parser_handle_invalid_surrogate_pair_as_lossy to graphite-base/9965 March 23, 2025 03:40
@graphite-app graphite-app bot force-pushed the 03-22-fix_estree_ast_fix_lossy_stringliteral.value_ branch from c80b7db to d38e665 Compare March 23, 2025 03:46
@graphite-app graphite-app bot force-pushed the graphite-base/9965 branch from aaf6bf2 to eaea5fd Compare March 23, 2025 03:46
@graphite-app graphite-app bot changed the base branch from graphite-base/9965 to main March 23, 2025 03:47
@graphite-app graphite-app bot force-pushed the 03-22-fix_estree_ast_fix_lossy_stringliteral.value_ branch from d38e665 to 92c54aa Compare March 23, 2025 03:47
@hi-ogawa hi-ogawa closed this Mar 24, 2025
@hi-ogawa hi-ogawa deleted the 03-22-fix_estree_ast_fix_lossy_stringliteral.value_ branch March 24, 2025 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants