lit-nunjucks
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -167,3 +167,2 @@ const nunjucks = require("nunjucks"); | ||
), | ||
] | ||
@@ -220,2 +219,17 @@ : []), | ||
if ( | ||
node instanceof n.Output && | ||
node.children.length === 1 && | ||
node.children[0] instanceof n.TemplateData | ||
) { | ||
return t.taggedTemplateExpression( | ||
t.identifier("html"), | ||
t.templateLiteral( | ||
node.children.map((c) => | ||
t.templateElement({ raw: c.value }) | ||
), | ||
[] | ||
) | ||
); | ||
} | ||
if (node instanceof n.Output) { | ||
@@ -359,8 +373,8 @@ return this.wrap(node.children[0]); | ||
t.arrowFunctionExpression( | ||
[t.identifier("t")], | ||
t.callExpression(t.identifier("JSON.stringify"), [ | ||
t.identifier("t"), | ||
]) | ||
), | ||
// t.arrowFunctionExpression( | ||
// [t.identifier("t")], | ||
// t.callExpression(t.identifier("JSON.stringify"), [ | ||
// t.identifier("t"), | ||
// ]) | ||
// ), | ||
@@ -367,0 +381,0 @@ t.arrowFunctionExpression( |
{ | ||
"name": "lit-nunjucks", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Nunjucks compiler to lit-html", | ||
@@ -5,0 +5,0 @@ "main": "lit-nunjucks.js", |
@@ -6,3 +6,3 @@ const { compile } = require("../lit-nunjucks"); | ||
const toCode = (src, args = "") => | ||
generate(babel.parse(`function template({${args}}) ${src}`)).code; | ||
generate(babel.parse(`function template({${args}}, _F) ${src}`)).code; | ||
@@ -15,4 +15,4 @@ describe("outputs", () => { | ||
test("should return just html", () => | ||
expect(compile(`source with no vars`)).toEqual( | ||
toCode('{ return "source with no vars"; }') | ||
expect(compile(`<p>source with no vars</p>`)).toEqual( | ||
toCode('{ return html`<p>source with no vars</p>`; }') | ||
)); | ||
@@ -41,3 +41,3 @@ test("should return a template with leading html", () => { | ||
expect(compile(`{{ a|filterThis(1) }}`)).toEqual( | ||
toCode("{ return _F.filterThis(a, 1); }", "_F,a") | ||
toCode("{ return _F.filterThis(a, 1); }", "a") | ||
); | ||
@@ -48,6 +48,3 @@ }); | ||
expect(compile(`<div>{{ a|filterThis(1) }}</div>`)).toEqual( | ||
toCode( | ||
"{ return html`<div>${_F.filterThis(a, 1)}</div>`; }", | ||
"_F,a" | ||
) | ||
toCode("{ return html`<div>${_F.filterThis(a, 1)}</div>`; }", "a") | ||
); | ||
@@ -63,3 +60,3 @@ }); | ||
expect(compile(`{%if question %}yes{%else%}no{% endif %}`)).toEqual( | ||
toCode('{ return question ? "yes": "no" }', "question") | ||
toCode('{ return question ? html`yes`: html`no` }', "question") | ||
); | ||
@@ -74,3 +71,3 @@ }); | ||
expect(compile(`{%if question %}yes{% endif %}`)).toEqual( | ||
toCode('{ return question ? "yes" : "" }', "question") | ||
toCode('{ return question ? html`yes` : "" }', "question") | ||
); | ||
@@ -83,3 +80,6 @@ }); | ||
expect(compile(`{%for item in list %}{{item}}{% endfor%}`)).toEqual( | ||
toCode('{ return Array.isArray(list) ? repeat(list, (item, index) => item) : "" }', "list") | ||
toCode( | ||
'{ return Array.isArray(list) ? repeat(list, (item, index) => item) : "" }', | ||
"list" | ||
) | ||
); | ||
@@ -92,3 +92,3 @@ }); | ||
toCode( | ||
"{ return Array.isArray(list) ? repeat(list, ({name, value}, index) => name) : \"\"; }", | ||
'{ return Array.isArray(list) ? repeat(list, ({name, value}, index) => name) : ""; }', | ||
"list" | ||
@@ -103,3 +103,3 @@ ) | ||
toCode( | ||
"{ return Array.isArray(list) ? repeat(list, (item, index) => html`<div>${item}</div>`) : \"\"; }", | ||
'{ return Array.isArray(list) ? repeat(list, (item, index) => html`<div>${item}</div>`) : ""; }', | ||
"list" | ||
@@ -114,3 +114,3 @@ ) | ||
toCode( | ||
'{return Array.isArray(list) && list.length ? repeat(list, (item, index) => item) : "nothing"; }', | ||
'{return Array.isArray(list) && list.length ? repeat(list, (item, index) => item) : html`nothing`; }', | ||
"list" | ||
@@ -125,4 +125,3 @@ ) | ||
toCode( | ||
'{return Array.isArray(_F.list("foobar")) ? repeat(_F.list("foobar"), (i, index) => html`${i},`):"";}', | ||
"_F" | ||
'{return Array.isArray(_F.list("foobar")) ? repeat(_F.list("foobar"), (i, index) => html`${i},`):"";}' | ||
) | ||
@@ -276,7 +275,7 @@ ); | ||
" ${(() => {\n items = [{\n" + | ||
' name: "foo"\n' + | ||
' "name": "foo"\n' + | ||
" }, {\n" + | ||
' name: "bar"\n' + | ||
' "name": "bar"\n' + | ||
" }, {\n" + | ||
' name: "bear"\n' + | ||
' "name": "bear"\n' + | ||
" }];\n" + | ||
@@ -288,3 +287,3 @@ " })()}\n" + | ||
"}", | ||
"name,_F" | ||
"" | ||
) | ||
@@ -291,0 +290,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51887
1275