diff --git a/rust/conformance/cases/lang-super-tagged-template.js b/rust/conformance/cases/lang-super-tagged-template.js new file mode 100644 index 00000000..8a3baecf --- /dev/null +++ b/rust/conformance/cases/lang-super-tagged-template.js @@ -0,0 +1,94 @@ +// Tagged templates with `super.m` and `super[k]` tags bind `this` to the receiver. +const log = [] +const sites = [] +class Base { + m(strings, ...values) { + sites.push(strings) + return [this.tag, strings, strings.raw, values] + } + get getterTag() { + const seenThis = this.tag + return function (strings, ...values) { + return [seenThis, this.tag, strings[0], values[0]] + } + } + static sm(strings, ...values) { + return [this.name, strings, values] + } +} + +class Derived extends Base { + constructor(tag) { + super() + this.tag = tag + } + staticMember() { + return super.m`hi ${1 + 1}\n!` + } + computedMember() { + const key = { + toString() { + log.push("key") + return "m" + }, + } + return super[key]`yo ${(log.push("arg"), this.tag)}` + } + literalComputed() { + return super["m"]`raw` + } + getterMember() { + return super.getterTag`g=${9}` + } + arrowMember() { + return (() => super.m`arr ${this.tag}`)() + } + parenMember() { + return (super.m)`paren` + } + sameSite() { + return super.m`same` + } + missingTag() { + try { + return super.missing`nope` + } catch (e) { + return e.name + } + } + static staticCall() { + return super.sm`st ${42}` + } +} + +const obj = { + [Symbol.toStringTag]: "ObjTag", + f() { + return super.toString`ignored` + }, +} + +const d = new Derived("D") +const rStatic = d.staticMember() +const rComputed = d.computedMember() +const rLitComputed = d.literalComputed() +const rGetter = d.getterMember() +const rArrow = d.arrowMember() +const rParen = d.parenMember() +const sBefore = sites.length +d.sameSite() +d.sameSite() +const sameSiteIdentity = sites[sBefore] === sites[sBefore + 1] +return [ + rStatic, + rComputed, + log, + rLitComputed, + rGetter, + rArrow, + rParen, + sameSiteIdentity, + d.missingTag(), + Derived.staticCall(), + obj.f(), +] diff --git a/rust/conformance/cases/lang-super-tagged-template.json b/rust/conformance/cases/lang-super-tagged-template.json new file mode 100644 index 00000000..7d677c97 --- /dev/null +++ b/rust/conformance/cases/lang-super-tagged-template.json @@ -0,0 +1,93 @@ +{ + "bindings": {}, + "ok": true, + "value": [ + [ + "D", + [ + "hi ", + "\n!" + ], + [ + "hi ", + "\\n!" + ], + [ + 2 + ] + ], + [ + "D", + [ + "yo ", + "" + ], + [ + "yo ", + "" + ], + [ + "D" + ] + ], + [ + "key", + "arg" + ], + [ + "D", + [ + "raw" + ], + [ + "raw" + ], + [] + ], + [ + "D", + "D", + "g=", + 9 + ], + [ + "D", + [ + "arr ", + "" + ], + [ + "arr ", + "" + ], + [ + "D" + ] + ], + [ + "D", + [ + "paren" + ], + [ + "paren" + ], + [] + ], + true, + "TypeError", + [ + "Derived", + [ + "st ", + "" + ], + [ + 42 + ] + ], + "[object ObjTag]" + ], + "logs": [], + "metadata": null +} diff --git a/rust/crates/psychoscript/src/compiler.rs b/rust/crates/psychoscript/src/compiler.rs index bb3eb3c9..94a4cdc2 100644 --- a/rust/crates/psychoscript/src/compiler.rs +++ b/rust/crates/psychoscript/src/compiler.rs @@ -3687,6 +3687,11 @@ impl<'a, 's> Compiler<'a, 's> { /// `tag\`...\``: calls the tag, read like a callee, with the site's strings array and the substitutions. fn tagged_template(&mut self, t: &'a TaggedTemplateExpression<'a>) -> R<()> { match &t.tag { + tag if Self::super_member(tag.as_member_expression()).is_some() => { + if let Some(m) = tag.as_member_expression() { + self.super_get(m, true)?; + } + } Expression::StaticMemberExpression(m) => { self.expr(&m.object)?; let a = self.atom(m.property.name.as_str());