-
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
Syntax proposals (meta issue) #40
Comments
Even though |
I've added |
So does Python, which doesn't use either syntax: #!/usr/bin/env python3
str = """
Hash: #{1 + 2}
Cash: ${1 + 2}
"""
str = '''
Hash: #{1 + 2}
Cash: ${1 + 2}
''' Supporting
This discrepancy feels… wrong. First, it has the potential to mess with code that performs deindentation of its own (or worse still, requires it). Second, an initial template literal might be blank because its tag function interprets a blank string differently to a non-blank one. Consider something like: import {writeFileSync} from "fs";
// Write to the specified file, or stdout if path is empty
function print([to]){
return ([content]) => "" === to
? process.stdout.write(content)
: fs.writeFileSync(to, content, "utf8");
}
print `output.txt``
Contents of file, which are expected
to be written to the destination
verbatim.
`;
print ```
Message written to standard output, indented by one tab.
```; A safer alternative would be to implement a
|
Python does, you just have to preface the literal with a f"""
{1 + 2}
"""
# '\n3\n' |
I confess I didn't know that (because I'm not a Python programmer), but for the sake of this discussion, I'd argue that |
Regarding triple-tick, I'm not sure if "(currently possible) syntax not in use" is quite the same as "property not in use". There's something unsettling about the idea that a tagged template written with the "new" syntax would not be a syntax error in agents which haven't yet implemented it but would instead be a different also-valid expression with different semantics. Would this create bugs? Issues for tooling/ecosystem that currently parse and compile triple ticks differently? Is it exploitable as a way to mask conditional behavior that, being syntactic, cannot be denied in prepared envs? (Not rhetorical questions - I really don't know the answers and they may all be "no". I just get a weird tingle about the premise which suggests these things may need consideration because valid (a) -> valid (b) is a seemingly pretty different scenario from invalid -> valid. Is there a similar example of valid (a) -> valid (b) happening before? Edit: Trying to think through this more and I suspect the answers would depend in part on whether or not a single tick within the “block” still requires escaping. As long as it does, then there’s probably no nasty tricks possible. But if it doesn’t, then whether the following x = () => x;
x
```
`
alert("am i an inert string ... or am I eval? depends on your browser, if single backticks don’t need escaping!");
x
`
``` |
I doubt that anyone except library maintainers will use Maybe we could add the API, as well as some kind of syntax sugar in the same time? |
Based on conversations with other delegates, it's unlikely we'll be able to get a syntax form. I'm planning on doing |
One problem of current template literal is, you can't have unescaped This issue is not directly relate to dedent, but consider the main use cases of dedent is long text, I really hope we can revisit the syntax options which could allow unescaped backticks. Syntax also make |
If we are to introduce new syntax, we should make it worthwhile by including more features and solving 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:
|
In the order in which I find them while going through everything. There seems to be strong support in the community for a syntax feature (based on how many suggestions we're getting), instead of a
String.dedent
tag function.We know this isn't 100% backwards compatible for tagged template expressions, but usage of an empty initial template which (the first
foo``
infoo``````
) returns a function could be low enough that we can continue with this option.(Coffeescript also uses this)
@
prefix syntax #35See also #21 (comment). A syntax feature can be minified, whereas a runtime tag function could only be minified if we unsafely assume runtime behavior.
The text was updated successfully, but these errors were encountered: