Bug 1849144 - Fix the number of whitespaces used for preserving the column number of inline script. r=ochameau,devtools-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D186596
This commit is contained in:
Tooru Fujisawa 2023-08-22 09:25:34 +00:00
parent 48a0286c9f
commit b2a6c970c5
7 changed files with 52 additions and 20 deletions

View file

@ -2536,7 +2536,7 @@
"byName": {},
"byBlocks": {},
"usedIds": {
"1": 1
"0": 0
}
}
}
@ -2557,7 +2557,7 @@
"byName": {},
"byBlocks": {},
"usedIds": {
"1": 1
"0": 0
}
}
}

View file

@ -30492,10 +30492,6 @@
return locations.map(parser);
}
function generateWhitespace(length) {
return Array.from(new Array(length + 1)).join(" ");
}
function calcLineAndColumn(source, index) {
const lines = source.substring(0, index).split(newLines);
const line = lines.length;
@ -30513,7 +30509,8 @@
line,
column,
// prepend whitespace for scripts that do not start on the first column
source: generateWhitespace(column) + location.source,
// NOTE: `column` is 1-based
source: " ".repeat(column - 1) + location.source,
});
}

View file

@ -71,10 +71,6 @@ function parseScripts(locations, parser) {
return locations.map(parser);
}
function generateWhitespace(length) {
return Array.from(new Array(length + 1)).join(" ");
}
function calcLineAndColumn(source, index) {
const lines = source.substring(0, index).split(newLines);
const line = lines.length;
@ -92,7 +88,8 @@ function adjustForLineAndColumn(fullSource, location) {
line,
column,
// prepend whitespace for scripts that do not start on the first column
source: generateWhitespace(column) + location.source,
// NOTE: `column` is 1-based
source: " ".repeat(column - 1) + location.source,
});
}
@ -132,9 +129,4 @@ function parseScriptTags(source, parser) {
}
export default parseScriptTags;
export {
generateWhitespace,
getCandidateScriptLocations,
parseScripts,
parseScriptTags,
};
export { getCandidateScriptLocations, parseScripts, parseScriptTags };

View file

@ -9,7 +9,6 @@ import * as types from "@babel/types";
import * as babelParser from "@babel/parser";
import {
generateWhitespace,
getCandidateScriptLocations,
parseScripts as customParseScripts,
parseScriptTags as customParseScriptTags,
@ -54,7 +53,6 @@ function parseScriptTags(source, parser = parseScript) {
export default parseScriptTags;
export {
extractScriptTags,
generateWhitespace,
getCandidateScriptLocations,
parseScript,
parseScripts,

View file

@ -141,6 +141,7 @@ skip-if = ccov && os == 'win' # Bug 1443132
[browser_dbg-inline-preview.js]
skip-if = true # bug 1607636
[browser_dbg-inline-exceptions.js]
[browser_dbg-inline-exceptions-inline-script.js]
[browser_dbg-inspector-integration.js]
[browser_dbg-keyboard-navigation.js]
[browser_dbg-keyboard-shortcuts-modal.js]

View file

@ -0,0 +1,34 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// This test checks the appearance of an inline exception in inline script
// and the content of the exception tooltip.
"use strict";
add_task(async function () {
const dbg = await initDebugger("doc-exceptions-inline-script.html");
await selectSource(dbg, "doc-exceptions-inline-script.html");
info("Hovers over the inline exception mark text.");
await assertInlineExceptionPreview(dbg, 7, 39, {
fields: [
[
"<anonymous>",
"https://example.com/browser/devtools/client/debugger/test/mochitest/examples/doc-exceptions-inline-script.html:7",
],
],
result: "TypeError: [].plop is not a function",
expression: "plop",
});
const excLineEls = findAllElementsWithSelector(dbg, ".line-exception");
const excTextMarkEls = findAllElementsWithSelector(
dbg,
".mark-text-exception"
);
is(excLineEls.length, 1, "The editor has one exception line");
is(excTextMarkEls.length, 1, "One token is marked as an exception.");
});

View file

@ -0,0 +1,10 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<html>
<head>
<title>Debugger test page</title>
<script type="text/javascript">[].plop()</script>
</head>
<body></body>
</html>