dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
965 stars 33 forks source link

Support for subshells breaks escaped parentheses #234

Closed luangong closed 5 months ago

luangong commented 5 months ago

Running the following code with deno:

import $ from 'https://deno.land/x/dax/mod.ts';

await $`echo \( foo bar \)`;

An error will be produced:

error: Uncaught (in promise) "Unexpected character.\n  ( bar )\n  ~"

The expected output is:

( foo bar )

Given the following content of deno.json:

{
  "tasks": {
    "paren": "echo ( foo bar )",
    "paren2": "echo \\( foo bar \\)",
    "paren3": "echo \\(\nfoo bar\n\\)"
  }
}

And running deno task paren2 and deno task paren3 both produce the expected output:

$ deno task paren2
Task paren2 echo \( foo bar \)
( foo bar )

$ deno task paren3
Task paren3 echo \(
foo bar
\)
( foo bar )

Support for escaped parentheses was added in https://github.com/denoland/deno_task_shell/pull/99, but it seems that https://github.com/dsherret/dax/pull/232 broke it.

Related:

luangong commented 5 months ago

It seems that it requires double-escaping. The following code works:

import $ from 'https://deno.land/x/dax/mod.ts';

await $`echo \\( foo bar \\)`;