Skip to content

Commit

Permalink
Merge pull request #14820 from webpack/fix-evaluate-tagged-template
Browse files Browse the repository at this point in the history
fix evaluating tagged template
  • Loading branch information
sokra committed Nov 25, 2021
2 parents fc4ff6d + 58edd1a commit c930a76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/javascript/JavascriptParser.js
Expand Up @@ -1189,14 +1189,15 @@ class JavascriptParser extends Parser {
const node = /** @type {TaggedTemplateExpressionNode} */ (_node);
const tag = this.evaluateExpression(node.tag);

if (tag.isIdentifier() && tag.identifier !== "String.raw") return;
const { quasis, parts } = getSimplifiedTemplateResult(
"raw",
node.quasi
);
return new BasicEvaluatedExpression()
.setTemplateString(quasis, parts, "raw")
.setRange(node.range);
if (tag.isIdentifier() && tag.identifier === "String.raw") {
const { quasis, parts } = getSimplifiedTemplateResult(
"raw",
node.quasi
);
return new BasicEvaluatedExpression()
.setTemplateString(quasis, parts, "raw")
.setRange(node.range);
}
});

this.hooks.evaluateCallExpressionMember
Expand Down
4 changes: 4 additions & 0 deletions test/cases/parsing/evaluate-nullish/index.js
@@ -1,5 +1,9 @@
function a() {}

it("should evaluate nullish coalescing", function () {
expect("" ?? require("fail")).toBe("");
expect(String.raw`aaaa` ?? require("fail")).toBe("aaaa");
expect(a`aaaa` ?? "expected").toBe("expected");
expect(null ?? "expected").toBe("expected");
expect(("" ?? require("fail")) && true).toBe("");
let x = 0;
Expand Down

0 comments on commit c930a76

Please sign in to comment.