Print parentheses around identifier let where necessary (#13269)
This commit is contained in:
31
packages/babel-generator/test/fixtures/edgecase/let-identifier/input.js
vendored
Normal file
31
packages/babel-generator/test/fixtures/edgecase/let-identifier/input.js
vendored
Normal 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 []);
|
||||
}
|
||||
4
packages/babel-generator/test/fixtures/edgecase/let-identifier/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/edgecase/let-identifier/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"strictMode": false
|
||||
}
|
||||
46
packages/babel-generator/test/fixtures/edgecase/let-identifier/output.js
vendored
Normal file
46
packages/babel-generator/test/fixtures/edgecase/let-identifier/output.js
vendored
Normal 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 []);
|
||||
};
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user