Bug 1828588 - [devtools] Better handle arrow functions. r=devtools-reviewers,ochameau.

Differential Revision: https://phabricator.services.mozilla.com/D175768
This commit is contained in:
Nicolas Chevobbe 2023-04-19 09:48:20 +00:00
Родитель 60bcb38c56
Коммит 869397f59b
6 изменённых файлов: 70 добавлений и 5 удалений

Просмотреть файл

@ -10239,6 +10239,9 @@
if (token.type.label == "?") {
return true;
}
if (token.type.label == "=>") {
return true;
}
return false;
}
@ -10273,6 +10276,9 @@
if (lastTokenTypeLabel == "${") {
return true;
}
if (lastTokenTypeLabel == "=>") {
return true;
}
return false;
}

Просмотреть файл

@ -977,6 +977,9 @@ function needsSpaceAfter(token, lastToken) {
if (token.type.label == "?") {
return true;
}
if (token.type.label == "=>") {
return true;
}
return false;
}
@ -1011,6 +1014,9 @@ function needsSpaceBeforeLastToken(lastToken) {
if (lastTokenTypeLabel == "${") {
return true;
}
if (lastTokenTypeLabel == "=>") {
return true;
}
return false;
}

Просмотреть файл

@ -795,6 +795,51 @@ Array [
]
`;
exports[`Fat arrow function 1`] = `
"const a = () => 42
addEventListener('click', e => {
return false
});
const sum = (c, d) => c + d
"
`;
exports[`Fat arrow function 2`] = `
Array [
"(1, 0) -> (2, 6)",
"(1, 6) -> (2, 12)",
"(1, 8) -> (2, 14)",
"(1, 10) -> (2, 16)",
"(1, 11) -> (2, 17)",
"(1, 13) -> (2, 19)",
"(1, 16) -> (2, 22)",
"(2, 0) -> (3, 6)",
"(2, 16) -> (3, 22)",
"(2, 17) -> (3, 23)",
"(2, 24) -> (3, 30)",
"(2, 26) -> (3, 32)",
"(2, 28) -> (3, 34)",
"(2, 31) -> (3, 37)",
"(3, 2) -> (3, 39)",
"(3, 9) -> (3, 46)",
"(4, 0) -> (3, 52)",
"(4, 1) -> (3, 53)",
"(4, 2) -> (3, 54)",
"(5, 0) -> (4, 6)",
"(5, 6) -> (4, 12)",
"(5, 10) -> (4, 16)",
"(5, 12) -> (4, 18)",
"(5, 13) -> (4, 19)",
"(5, 14) -> (4, 20)",
"(5, 16) -> (4, 21)",
"(5, 17) -> (4, 22)",
"(5, 19) -> (4, 24)",
"(5, 22) -> (4, 27)",
"(5, 24) -> (4, 28)",
"(5, 26) -> (4, 29)",
]
`;
exports[`For loop 1`] = `
"for (var i = 0; i < n; i++) {
console.log(i);

Просмотреть файл

@ -400,6 +400,14 @@ const cases = [
const x = ({thisIsAnotherVeryLongPropertyName: "but should not cause the paren to be a line delimiter"})
`,
},
{
name: "Fat arrow function",
input: `
const a = () => 42
addEventListener("click", e => { return false });
const sum = (c,d) => c+d
`,
},
];
const includesOnly = cases.find(({ only }) => only);

Просмотреть файл

@ -231,7 +231,7 @@ function getExpectedPrettyPrintedHtml() {
<script>
{
'use strict';
document.querySelector('h1').addEventListener('mousedown', e=>{
document.querySelector('h1').addEventListener('mousedown', e => {
console.log('mousedown on h1')
})
}
@ -247,7 +247,7 @@ function getExpectedPrettyPrintedHtml() {
2,
3
];
y.map(i=>i * 2)
y.map(i => i * 2)
</script>
</body>
</html>

Просмотреть файл

@ -32,7 +32,7 @@ add_task(async function() {
prettySourceValue.trim(),
`debugger;
var foo;
document.addEventListener('click', e=>{
document.addEventListener('click', e => {
debugger;
}, {
once: true
@ -80,9 +80,9 @@ document.addEventListener('click', e=>{
prettyEvalSourceValue.trim(),
`
setTimeout(
() =>{
() => {
debugger;
document.addEventListener('click', e=>{
document.addEventListener('click', e => {
debugger;
}, {
once: true