-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Triple tick syntax backwards compatibility #8
Comments
Here is some code like this in the wild. |
@bakkot I can’t decide if I love this or hate it haha. Throw in a custom toString and the intern-trolling potential goes through the roof. |
Ah, I hadn't considered the tag continually returning a function. I think when we reasoned this, we were just looking at the untagged form (which is definitely a runtime error). I still think the compat risk here is minimal, but it's not 0% anymore. |
Great find @bakkot - and the gist isn't even that contrived. Jsonnet (mentioned in the readme) uses |
What about using |
I think both I think the ship has sailed on new delimiters for strings. I'd considered proposing ``` a couple of years ago but I'd not had much luck raising the prospects of dedented strings back before template strings were finalised. There were some interesting suggestions in that original thread, maybe it's worth looking at these ideas again? Particularly, someone proposed a keyword after the delimiter: var a = `This is a template string.
Even though each line is indented to keep the
code neat and tidy, the white space used to indent
is not in the resulting string` trim-indent; Not sure how feasible this is as you'd probably want the parser to know up front whether the indent should be dropped. There's also no existing precedent for this kind of directive in the language or similar languages (that I can think of). |
Another option might be to use
Allow any number of leading Currently |
If we introduce new syntax, we should make it worthwhile to include more features and solve as many problems as possible, otherwise the features proposed too late will become breaking changes in the future. Here is my proposal of adding raw string literal to ECMAScript/JavaScript to solve multiple problems together:
(Mentioned in #40 as well) |
The Q&A section has an "Is this backwards compatible?" section which acknowledges that the proposed syntax is already syntactically valid with a different meaning, but concludes that it's nonetheless a backwards-compatible change because it would always result in a runtime error.
This seems to assume that the result of a tagged template expression is always a string, which isn't the case. The expression can return anything, including another template tag function.
The proposal itself would be very useful imo, but will likely need to rethink the syntax; given chaining tags like this has been valid JS for five years, altering its meaning now isn't safe (even in the unlikely event that no code like this is found in the wild, since it creates a mechanism to craft code that successfully evaluates with different meanings depending on the agent).
The text was updated successfully, but these errors were encountered: