Skip to content
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

Feedback #85

Open
daniel-nagy opened this issue May 17, 2024 · 7 comments
Open

Feedback #85

daniel-nagy opened this issue May 17, 2024 · 7 comments

Comments

@daniel-nagy
Copy link

daniel-nagy commented May 17, 2024

I started a list of potential ECMAScript proposals and this was on my list 😄.

I think the README does a pretty good job of explaining why this feature is necessary. However, I had a different syntax in mind. Have you considered using triple back ticks? e.g.

class MyClass {
  print() {
    console.log(```
      create table student(
        id int primary key,
        name text
      )
    ```);
  }
}

I think this would behave like multiline strings in Elixir. Sepcifically, the indentation of the last ``` would determine where the indentation starts. I call these lexically indented template literals.

Maybe I'm wrong, but it doesn't seem like this proposal would support the case where you want all lines to be indented by some amount. Specifically, this criteria

  • The "common indentation" of all non-empty content lines (lines that are not the opening or closing) are calculated.
  • That common indentation is removed from the start of every line.

e.g.

class MyClass {
  print() {
    string.indent`
      create table student(
        id int primary key,
        name text
      )
    `;
  }
}

would result in

create table student(
  id int primary key,
  name text
)

but maybe I acutally want the starting indentation

  create table student(
    id int primary key,
    name text
  )

With this proposal, that doesn't seem possible.

Another benefit of triple back ticks, in my opinion, is that they are more ergonomic with tagged template literals. I can lift any existing tagged template literal by simply replacing single backticks with triple back ticks, e.g.

const query = String.dedent(sql)`
  create table student(
    id int primary key,
    name text
  )
`

vs

const query = sql```
  create table student(
    id int primary key,
    name text
  )
  ```

What do you think?

@bakkot
Copy link
Contributor

bakkot commented May 17, 2024

Have you considered using triple back ticks?

Yes, please see existing issues. Note that the code you've given is in fact already legal and so cannot be used.

Maybe I'm wrong, but it doesn't seem like this proposal would support the case where you want all lines to be indented by some amount.

True, this proposal aims to solve dedenting, not indenting.

@daniel-nagy
Copy link
Author

True, this proposal aims to solve dedenting, not indenting.

Wouldn't it be better if it solved both?

@bakkot
Copy link
Contributor

bakkot commented May 17, 2024

Depends on what additional complexity is required to do so, and how valuable we think doing so is. Personally I don't think indenting is very valuable so I am not inclined to incur any additional complexity to enable it.

@daniel-nagy
Copy link
Author

Personally I don't think indenting is very valuable so I am not inclined to incur any additional complexity to enable it.

I have run into use cases where I needed to control indenting.

@daniel-nagy
Copy link
Author

Note that the code you've given is in fact already legal and so cannot be used.

Can you elaborate more on this? When I test the code I provided I get an error

Uncaught TypeError: "" is not a function

Even if the syntax is lexically valid, I don't think it has any semantic meaning.

@bakkot
Copy link
Contributor

bakkot commented May 18, 2024

See previous issues.

@daniel-nagy
Copy link
Author

Oof, ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants