Repository: sveltejs/prettier-plugin-svelte
Pull request #164 (2020-11-30 12:48:17)

Fall back to raw text if there is a parser error in JS
Handle default value inside object destructuring that way
#163


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 747d812..b1e26fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # prettier-plugin-svelte changelog
 
+## Unreleased
+
+* Pass options to embedded parser ([#162](https://github.com/sveltejs/prettier-plugin-svelte/issues/162))
+
 ## 1.4.1
 
 * Format next node correctly when previous node has a comment as last child ([#152](https://github.com/sveltejs/prettier-plugin-svelte/issues/152))
diff --git a/package-lock.json b/package-lock.json
index 917278b..360ca94 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4366,9 +4366,9 @@
             }
         },
         "svelte": {
-            "version": "3.28.0",
-            "resolved": "https://registry.npmjs.org/svelte/-/svelte-3.28.0.tgz",
-            "integrity": "sha512-WJW8wD+aTmU5GUnTUjdhVF35mve2MjylubLgB6fGWoXHpYENdwcwWsWvjMQLayzMynqNH733h1Ck8wJzNR7gdQ==",
+            "version": "3.30.0",
+            "resolved": "https://registry.npmjs.org/svelte/-/svelte-3.30.0.tgz",
+            "integrity": "sha512-z+hdIACb9TROGvJBQWcItMtlr4s0DBUgJss6qWrtFkOoIInkG+iAMo/FJZQFyDBQZc+dul2+TzYSi/tpTT5/Ag==",
             "dev": true
         },
         "symbol-observable": {
diff --git a/package.json b/package.json
index a3137df..85f1a3f 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
         "rollup-plugin-commonjs": "9.2.0",
         "rollup-plugin-node-resolve": "4.0.0",
         "rollup-plugin-typescript": "1.0.0",
-        "svelte": "^3.28.0",
+        "svelte": "^3.30.0",
         "ts-node": "^7.0.1",
         "tslib": "^1.9.3",
         "typescript": "3.2.4"
diff --git a/src/embed.ts b/src/embed.ts
index d10eb86..db070e0 100644
--- a/src/embed.ts
+++ b/src/embed.ts
@@ -24,12 +24,16 @@ export function embed(
     const node: Node = path.getNode();
 
     if (node.isJS) {
-        return removeLines(
-            textToDoc(forceIntoExpression(getText(node, options)), {
-                parser: expressionParser,
-                singleQuote: true,
-            }),
-        );
+        try {
+            return removeLines(
+                textToDoc(forceIntoExpression(getText(node, options)), {
+                    parser: expressionParser,
+                    singleQuote: true,
+                }),
+            );
+        } catch (e) {
+            return getText(node, options);
+        }
     }
 
     const embedType = (tag: string, parser: 'typescript' | 'css', isTopLevel: boolean) =>
@@ -67,8 +71,8 @@ function forceIntoExpression(statement: string) {
     return `(${statement}\n)`;
 }
 
-function expressionParser(text: string, parsers: any) {
-    const ast = parsers.babel(text);
+function expressionParser(text: string, parsers: any, options: any) {
+    const ast = parsers.babel(text, parsers, options);
 
     return { ...ast, program: ast.program.body[0].expression };
 }


Test patch:
diff --git a/test/printer/samples/each-block-destructured-default-value.html b/test/printer/samples/each-block-destructured-default-value.html
new file mode 100644
index 0000000..81b2a42
--- /dev/null
+++ b/test/printer/samples/each-block-destructured-default-value.html
@@ -0,0 +1,3 @@
+{#each animals as {key, value = []}}
+    <p>{key}: {value}</p>
+{/each}