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

Trim leading whitespace #289

Open
kj opened this issue Oct 28, 2024 · 0 comments
Open

Trim leading whitespace #289

kj opened this issue Oct 28, 2024 · 0 comments

Comments

@kj
Copy link

kj commented Oct 28, 2024

I was trying to write a command over multiple lines. My first instinct was to use \ at the end of each line as in sh, but it doesn't seem like that's necessary so I guess it just collapses the extra whitespace/newlines. I noticed that I can write a command over multiple lines as long as there is no newline before the command in the template string. If there is, it throws an error.

$ cat a.ts
import { $ } from 'jsr:@david/dax';

await $`echo
  one
  two
`;
$ cat b.ts
import { $ } from 'jsr:@david/dax';

await $`
  echo
    one
    two
`;
$ deno run -A a.ts
one two
$ deno run -A b.ts
error: Uncaught (in promise) "Unexpected character.\n  \n  echo\n    one\n    two\n\n  ~"

It seems like allowing for the latter style (b.ts) should be as simple as trimming any whitespace from the start of the string? For now I'm just using the former method, but I'd like to be able to use the latter as I find it a little more readable.

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

1 participant