fix(parser): string in AST reference arena (#23721)

Fix a bug where a string in AST did not reference a string in the arena - it used a static string.

This breaks raw transfer, because it expects all `Str`s and `Ident`s to point to their string content in the arena - it doesn't know about any memory outside of the arena. The would have caused the string on JS side to be either an empty string, or garbage, instead of "this".

Fix by making the string reference a slice of the source text.

Unfortunately we have no way to enforce this at compile time at present - we'd likely need branded lifetimes for that.
This commit is contained in:
overlookmotel committed 2026-06-22 17:58:52 +00:00
1 parent 10b96c6128
commit 585760f21d
1 file changed
+4 -2
+4 -2
View File
@@ -712,8 +712,10 @@ impl<'a, C: Config> ParserImpl<'a, C> {
let this_span = self.cur_token().span();
self.error(diagnostics::identifier_reserved_word(this_span, "this"));
self.bump_any();
// Recover by creating a dummy identifier
let ident = self.ast.alloc_identifier_reference(this_span, "this");
// Recover by creating an identifier
let this = this_span.source_text(self.source_text);
debug_assert_eq!(this, "this");
let ident = self.ast.alloc_identifier_reference(this_span, this);
return TSModuleReference::IdentifierReference(ident);
}