зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1615781 - Enable nullish coalescing and optional chaining operators when parsing console expression. r=loganfsmyth.
Since both operators are now supported in Firefox, we should make sure we can use them in top-level await expression in the console. Unit tests are added to ensure this works as expected. Differential Revision: https://phabricator.services.mozilla.com/D63043 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
2451cdd8a0
Коммит
8b0f78c90b
|
@ -7156,7 +7156,7 @@ function parseVueScript(code) {
|
|||
function parseConsoleScript(text, opts) {
|
||||
try {
|
||||
return _parse(text, {
|
||||
plugins: ["objectRestSpread", "dynamicImport"],
|
||||
plugins: ["objectRestSpread", "dynamicImport", "nullishCoalescingOperator", "optionalChaining"],
|
||||
...opts,
|
||||
allowAwaitOutsideFunction: true
|
||||
});
|
||||
|
|
|
@ -522,6 +522,58 @@ describe("mapExpression", () => {
|
|||
originalExpression: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "await (nullish coalesce operator)",
|
||||
expression: "await x; true ?? false",
|
||||
newExpression: `(async () => {
|
||||
await x;
|
||||
return true ?? false;
|
||||
})()`,
|
||||
shouldMapBindings: false,
|
||||
expectedMapped: {
|
||||
await: true,
|
||||
bindings: false,
|
||||
originalExpression: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "await (optional chaining operator)",
|
||||
expression: "await x; x?.y?.z",
|
||||
newExpression: `(async () => {
|
||||
await x;
|
||||
return x?.y?.z;
|
||||
})()`,
|
||||
shouldMapBindings: false,
|
||||
expectedMapped: {
|
||||
await: true,
|
||||
bindings: false,
|
||||
originalExpression: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "await (async function declaration with nullish coalesce operator)",
|
||||
expression: "async function coalesce(x) { await x; return x ?? false; }",
|
||||
newExpression:
|
||||
"async function coalesce(x) { await x; return x ?? false; }",
|
||||
shouldMapBindings: false,
|
||||
expectedMapped: {
|
||||
await: false,
|
||||
bindings: false,
|
||||
originalExpression: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name:
|
||||
"await (async function declaration with optional chaining operator)",
|
||||
expression: "async function chain(x) { await x; return x?.y?.z; }",
|
||||
newExpression: "async function chain(x) { await x; return x?.y?.z; }",
|
||||
shouldMapBindings: false,
|
||||
expectedMapped: {
|
||||
await: false,
|
||||
bindings: false,
|
||||
originalExpression: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "simple",
|
||||
expression: "a",
|
||||
|
|
|
@ -101,7 +101,12 @@ function parseVueScript(code) {
|
|||
export function parseConsoleScript(text: string, opts?: Object): Object | null {
|
||||
try {
|
||||
return _parse(text, {
|
||||
plugins: ["objectRestSpread", "dynamicImport"],
|
||||
plugins: [
|
||||
"objectRestSpread",
|
||||
"dynamicImport",
|
||||
"nullishCoalescingOperator",
|
||||
"optionalChaining",
|
||||
],
|
||||
...opts,
|
||||
allowAwaitOutsideFunction: true,
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче