Commit 7f27c8b6 authored by David Sveningsson's avatar David Sveningsson

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

parent 884599ae
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment