Print parentheses around identifier let where necessary (#13269)

This commit is contained in:
Stuart Cook
2021-05-07 05:10:45 +10:00
committed by GitHub
parent 96fce81438
commit 68bc4dfd31
5 changed files with 154 additions and 12 deletions

View File

@@ -0,0 +1,31 @@
/* ExpressionStatement */
let;
\u006cet[x];
(let)[x];
a[let[x]];
/* ForStatement */
for (let;;);
for (\u006cet[x];;);
for ((let)[x];;);
for (a[let[x]];;);
/* ForInStatement */
for (let in {});
for (\u006cet[x] in {});
for ((let)[x] in {});
for (a[let[x]] in {});
/* ForOfStatement { await: false } */
for ((let) of []);
for (\u006cet of []);
for ((let)[x] of []);
for (a[let] of []);
/* ForOfStatement { await: true } */
async () => {
for await ((let) of []);
for await (\u006cet of []);
for await ((let)[x] of []);
for await (a[let] of []);
}

View File

@@ -0,0 +1,4 @@
{
"sourceType": "script",
"strictMode": false
}

View File

@@ -0,0 +1,46 @@
/* ExpressionStatement */
let;
(let)[x];
(let)[x];
a[let[x]];
/* ForStatement */
for (let;;);
for ((let)[x];;);
for ((let)[x];;);
for (a[let[x]];;);
/* ForInStatement */
for (let in {});
for ((let)[x] in {});
for ((let)[x] in {});
for (a[let[x]] in {});
/* ForOfStatement { await: false } */
for ((let) of []);
for ((let) of []);
for ((let)[x] of []);
for (a[let] of []);
/* ForOfStatement { await: true } */
async () => {
for await ((let) of []);
for await ((let) of []);
for await ((let)[x] of []);
for await (a[let] of []);
};

View File

@@ -763,6 +763,18 @@ describe("programmatic generation", function () {
expect(output).toBe("interface A {}");
});
});
describe("identifier let", () => {
it("detects open bracket from non-optional OptionalMemberExpression", () => {
const ast = parse(`for (let?.[x];;);`, {
sourceType: "script",
strictMode: "false",
});
ast.program.body[0].init.optional = false;
const output = generate(ast).code;
expect(output).toBe("for ((let)[x];;);");
});
});
});
describe("CodeGenerator", function () {