Skip to content

Commit

Permalink
Fall back to raw text if there is a parser error in JS
Browse files Browse the repository at this point in the history
Handle default value inside object destructuring that way
sveltejs#163
  • Loading branch information
Simon Holthausen committed Nov 30, 2020
1 parent 88c2566 commit 34dfffd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 10 additions & 6 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each animals as {key, value = []}}
<p>{key}: {value}</p>
{/each}

0 comments on commit 34dfffd

Please sign in to comment.