Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions rust/conformance/cases/lang-super-tagged-template.js
Original file line number Diff line number Diff line change
@@ -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(),
]
93 changes: 93 additions & 0 deletions rust/conformance/cases/lang-super-tagged-template.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions rust/crates/psychoscript/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down