Conversation
| if (acc == null) return expr; | ||
| return Node.createBinaryExpression(Token.PLUS, acc, expr, tn.range(startPos, tn.pos)); | ||
| }, null); | ||
| } |
There was a problem hiding this comment.
Ideally this would generate a TemplateLiteral node holding the nodes of the template literal plus having a step to compile such a node in the compiler, instead of transpiling. Otherwise the AST cannot be reused for syntax highlighting in a future IDE extension. On such a node, I could imagine properties like stringParts[N], expressionParts[N-1].
There was a problem hiding this comment.
Ahh good point. Should we also add a default toString to all reference types?
There was a problem hiding this comment.
My vote is that the expressions must have a type String in the expressionParts field. Although, it would be nice to check for an empty toString() method. I realize this might not be possible.
There was a problem hiding this comment.
The basic types already have #toString implementations, like I32#toString for i32s, String#toString (returning itself) for strings etc. Typically one would resolve the expression parts, obtaining their type, and error if there is no toString or call it otherwise before concatenating with string parts.
There was a problem hiding this comment.
I vote for a default toString() method, that uses something like nameof<T>().
There was a problem hiding this comment.
It's entirely possible to do something like this:
if (!isDefined(obj.toString())) ERROR("Must implement toString()");As-pect uses this technique now.
There was a problem hiding this comment.
In the compiler context, perhaps this might not be so useful, actually.
|
Already implemented in #1715 so closing this. |
Add typescript like string interpolation:
foo ${variable} barby @willemneal