Skip to content

Commit

Permalink
fix: supporting let directive (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahinvardar authored Oct 31, 2023
1 parent 04c5d8c commit b9228f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vardario/svelte-ast-printer",
"version": "0.1.5",
"version": "0.1.6",
"description": "",
"license": "MIT",
"author": "Sahin Vardar",
Expand Down
4 changes: 4 additions & 0 deletions src/print-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ describe('Element directives', () => {
testHtmlPrinter('<li animate:flip={{delay: 500}}>{item}</li>');
testHtmlPrinter('<div animate:whizz>{item}</div>');
});

test('let:variable', () => {
testHtmlPrinter('<checkbox let:isChecked/>');
});
});

describe('Template', () => {
Expand Down
14 changes: 9 additions & 5 deletions src/print-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class ElementPrinter extends BaseHtmlNodePrinter {
case 'Animation':
attributeName = 'animate:';
break;

case 'Let':
attributeName = 'let:';
break;
}

attributeName += attribute.name;
Expand Down Expand Up @@ -463,8 +467,8 @@ export default function printHtml(params: PrintHtmlParams) {

walk(_.cloneDeep(params.rootNode), {
enter: function (node: TemplateNode, parent: TemplateNode) {
if(node.skip === true){
return
if (node.skip === true) {
return;
}
const printer = printers[node.type];
if (printer === undefined) {
Expand All @@ -480,10 +484,10 @@ export default function printHtml(params: PrintHtmlParams) {
nestingLevel++;
},
leave: function (node: TemplateNode, parent: TemplateNode) {
if(node.skip === true){
return
if (node.skip === true) {
return;
}

const printer = printers[node.type];

printer.leave(node, parent, {
Expand Down

0 comments on commit b9228f4

Please sign in to comment.