Skip to content

Commit

Permalink
Support {#key} block (#147)
Browse files Browse the repository at this point in the history
Needed for Svelte >2.28
  • Loading branch information
dummdidumm authored Sep 26, 2020
1 parent 9f4210f commit d9d3a77
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 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.20.0",
"svelte": "^3.28.0",
"ts-node": "^7.0.1",
"tslib": "^1.9.3",
"typescript": "3.2.4"
Expand Down
12 changes: 12 additions & 0 deletions src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D

return group(concat(block));
}
case 'KeyBlock': {
const def: Doc[] = [
'{#key ',
printJS(path, print, 'expression'),
'}',
printIndentedWithNewlines(path, print),
];

def.push('{/key}');

return concat([group(concat(def)), breakParent]);
}
case 'ThenBlock':
case 'PendingBlock':
case 'CatchBlock':
Expand Down
7 changes: 7 additions & 0 deletions src/print/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export interface AwaitBlockNode extends BaseNode {
catch: CatchBlockNode;
}

export interface KeyBlockNode extends BaseNode {
type: 'KeyBlock';
expression: Node;
children: Node[];
}

export interface ThenBlockNode extends BaseNode {
type: 'ThenBlock';
children: Node[];
Expand Down Expand Up @@ -257,6 +263,7 @@ export type Node =
| ElseBlockNode
| EachBlockNode
| AwaitBlockNode
| KeyBlockNode
| ThenBlockNode
| PendingBlockNode
| CatchBlockNode
Expand Down
10 changes: 10 additions & 0 deletions test/printer/samples/key-block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{#key value}
<p>hello</p>
<p>hello</p>
{/key}
{#key $store}
<p>hello</p>
{/key}
{#key expr.obj}
<p>hello</p>
{/key}

0 comments on commit d9d3a77

Please sign in to comment.