Permit %%placeholder%% in left-hand-side of a let declaration (#12725)

* Permit %%placeholder%% in left-hand-side of a let declaration

* Test that "let" followed by modulo is still treated as an identifier

* More tests for edge-case handling of "let" with placeholders enabled
This commit is contained in:
Stuart Cook
2021-02-02 12:00:21 +11:00
committed by GitHub
parent ecfe20395b
commit 20664a430e
16 changed files with 375 additions and 0 deletions

View File

@@ -393,5 +393,29 @@ describe("@babel/template", function () {
});
});
});
it("works in var declaration", () => {
const output = template("var %%LHS%% = %%RHS%%")({
LHS: t.identifier("x"),
RHS: t.numericLiteral(7),
});
expect(generator(output).code).toMatchInlineSnapshot(`"var x = 7;"`);
});
it("works in const declaration", () => {
const output = template("const %%LHS%% = %%RHS%%")({
LHS: t.identifier("x"),
RHS: t.numericLiteral(7),
});
expect(generator(output).code).toMatchInlineSnapshot(`"const x = 7;"`);
});
it("works in let declaration", () => {
const output = template("let %%LHS%% = %%RHS%%")({
LHS: t.identifier("x"),
RHS: t.numericLiteral(7),
});
expect(generator(output).code).toMatchInlineSnapshot(`"let x = 7;"`);
});
});
});