JavaScript: a bare E4X name inside with or a filter can be assigned

With Options::e4x set, an E4X name standing alone (@a, @ns::a, @[expr],
ns::a, *) is now a valid target for =, compound assignment, ++, --,
delete and for/for each loops, as well as a read. The target is the
nearest XML or XMLList value in scope whose [[HasProperty]] accepts the
name (ECMA-357 section 11.1). The name is evaluated once, and the
target resolves before the right-hand side runs.

When no XML value in scope holds the name, a read or write throws a
ReferenceError and creates no child or attribute. A read no longer
falls back to the first XML value in scope, so a filter such as
list.(@id == '1') throws when an item has no @id and no outer XML
value holds one, instead of treating that item as not matching.
This commit is contained in:
dotCooCoo
2026-11-11 19:35:59 -08:00
parent 6b8be09699
commit db97cc1a8f
8 changed files with 156 additions and 20 deletions
+5 -1
View File
@@ -160,8 +160,11 @@ pub(crate) enum Op {
parts: u32,
list: bool,
},
/// `name` → the value of the name on the nearest XML value in scope.
/// `name` → the value of the name on the nearest XML value in scope that holds it.
XmlScopeGet,
/// `name` → `object name`: the nearest XML value in scope that holds the name, for an
/// assignment, update or `delete`.
XmlScopeRef,
/// `object` → the filter's state.
XmlFilterStart,
/// `state` → `state item`, or jumps with `state` when the items are used up.
@@ -308,6 +311,7 @@ fn effect(op: Op, finally_tables: &[Vec<u32>]) -> Result<Effect, String> {
Op::XmlDescendants | Op::XmlFilterTest => e(2, 1),
Op::XmlEscape(_) | Op::XmlScopeGet | Op::XmlFilterStart | Op::XmlFilterEnd => e(1, 1),
Op::XmlLiteral { parts, .. } => e(parts, 1),
Op::XmlScopeRef => e(1, 2),
Op::ForEachValue => e(2, 2),
Op::SetDefaultNamespace => e(1, 0),
})