Skip to content
Snippets Groups Projects
Commit 7f27c8b6 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(transform): ignore non-string values in `TemplateExtractor`

parent 884599ae
No related branches found
No related tags found
1 merge request!381Misc fixes, mostly documentation
......@@ -30,6 +30,19 @@ describe("TemplateExtractor", () => {
]);
});
it.each`
type | value
${"null"} | ${null}
${"undefined"} | ${undefined}
${"boolean"} | ${true}
${"number"} | ${12}
${"regexp"} | ${/foo/}
${"identifier"} | ${"foo"}
`("should ignore $type value", ({ value }) => {
const te = TemplateExtractor.fromString(`foo({"template": ${value}})`);
expect(te.extractObjectProperty("template")).toEqual([]);
});
it("should ignore other properties", () => {
const te = TemplateExtractor.fromString('foo({bar: "<b>foo</b>"})');
expect(te.extractObjectProperty("template")).toEqual([]);
......
......@@ -65,9 +65,13 @@ function extractLiteral(
switch (node.type) {
/* ignored nodes */
case "FunctionExpression":
case "Identifier":
return null;
case "Literal":
if (typeof node.value !== "string") {
return null;
}
return {
data: node.value.toString(),
filename: null,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment