From f9db3b283daddb3d1e9d1270349bce96bed95e2b Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Wed, 13 Oct 2021 08:34:31 -0700 Subject: [PATCH] fix: issue printing destructured tag params resolves #1 --- .../params-destructured.expected/auto.marko | 11 +++++++++++ .../params-destructured.expected/concise.marko | 10 ++++++++++ .../params-destructured.expected/html.marko | 11 +++++++++++ .../params-destructured.expected/with-parens.marko | 11 +++++++++++ src/__tests__/fixtures/params-destructured.marko | 11 +++++++++++ src/index.ts | 7 +++++-- 6 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/__snapshots__/params-destructured.expected/auto.marko create mode 100644 src/__tests__/__snapshots__/params-destructured.expected/concise.marko create mode 100644 src/__tests__/__snapshots__/params-destructured.expected/html.marko create mode 100644 src/__tests__/__snapshots__/params-destructured.expected/with-parens.marko create mode 100644 src/__tests__/fixtures/params-destructured.marko diff --git a/src/__tests__/__snapshots__/params-destructured.expected/auto.marko b/src/__tests__/__snapshots__/params-destructured.expected/auto.marko new file mode 100644 index 0000000..ef39caf --- /dev/null +++ b/src/__tests__/__snapshots__/params-destructured.expected/auto.marko @@ -0,0 +1,11 @@ + + + <@then|{ value, done }|> +
+
  • ${value}
+
  • ${value}
+
  • ${value}
+
+ + +
diff --git a/src/__tests__/__snapshots__/params-destructured.expected/concise.marko b/src/__tests__/__snapshots__/params-destructured.expected/concise.marko new file mode 100644 index 0000000..adb475e --- /dev/null +++ b/src/__tests__/__snapshots__/params-destructured.expected/concise.marko @@ -0,0 +1,10 @@ +macro name="recursive" + await(generator.next()) + @then|{ value, done }| + div + ul + li -- ${value} + ul + li -- ${value} + ul + li -- ${value} diff --git a/src/__tests__/__snapshots__/params-destructured.expected/html.marko b/src/__tests__/__snapshots__/params-destructured.expected/html.marko new file mode 100644 index 0000000..ef39caf --- /dev/null +++ b/src/__tests__/__snapshots__/params-destructured.expected/html.marko @@ -0,0 +1,11 @@ + + + <@then|{ value, done }|> +
+
  • ${value}
+
  • ${value}
+
  • ${value}
+
+ + +
diff --git a/src/__tests__/__snapshots__/params-destructured.expected/with-parens.marko b/src/__tests__/__snapshots__/params-destructured.expected/with-parens.marko new file mode 100644 index 0000000..ef39caf --- /dev/null +++ b/src/__tests__/__snapshots__/params-destructured.expected/with-parens.marko @@ -0,0 +1,11 @@ + + + <@then|{ value, done }|> +
+
  • ${value}
+
  • ${value}
+
  • ${value}
+
+ + +
diff --git a/src/__tests__/fixtures/params-destructured.marko b/src/__tests__/fixtures/params-destructured.marko new file mode 100644 index 0000000..ef39caf --- /dev/null +++ b/src/__tests__/fixtures/params-destructured.marko @@ -0,0 +1,11 @@ + + + <@then|{ value, done }|> +
+
  • ${value}
+
  • ${value}
+
  • ${value}
+
+ + +
diff --git a/src/index.ts b/src/index.ts index 3760092..f8a642a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -600,8 +600,11 @@ export const printers: Record> = { "__js_expression", (doc: any) => { const { contents } = doc.contents[0]; - if (Array.isArray(contents) && contents[0] === "(") { - return contents.slice(1, -1); + if (Array.isArray(contents) && contents[0].startsWith("(")) { + contents[0] = contents[0].slice(1); + contents[contents.length - 1] = contents[ + contents.length - 1 + ].slice(0, -1); } return contents;