Bug 1673932 - [devtools] - Combine `register` calls in highlighters. r=jdescottes

Combine the calls to the highlighter `register()` function in a loop.
One of several possible solutions here.

Differential Revision: https://phabricator.services.mozilla.com/D96302
This commit is contained in:
Cody Welsh 2020-11-12 08:38:59 +00:00
Родитель efbcf065d3
Коммит 049cc3d149
1 изменённых файлов: 43 добавлений и 37 удалений

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

@ -34,14 +34,13 @@ exports.isTypeRegistered = isTypeRegistered;
/**
* Registers a given constructor as highlighter, for the `typeName` given.
*/
const register = (typeName, modulePath) => {
const registerHighlighter = (typeName, modulePath) => {
if (highlighterTypes.has(typeName)) {
throw Error(`${typeName} is already registered.`);
}
highlighterTypes.set(typeName, modulePath);
};
exports.register = register;
/**
* CustomHighlighterActor is a generic Actor that instantiates a custom implementation of
@ -350,38 +349,45 @@ HighlighterEnvironment.prototype = {
},
};
register(
"AccessibleHighlighter",
"devtools/server/actors/highlighters/accessible"
);
register(
"BoxModelHighlighter",
"devtools/server/actors/highlighters/box-model"
);
register("CssGridHighlighter", "devtools/server/actors/highlighters/css-grid");
register(
"CssTransformHighlighter",
"devtools/server/actors/highlighters/css-transform"
);
register("EyeDropper", "devtools/server/actors/highlighters/eye-dropper");
register("FlexboxHighlighter", "devtools/server/actors/highlighters/flexbox");
register("FontsHighlighter", "devtools/server/actors/highlighters/fonts");
register(
"GeometryEditorHighlighter",
"devtools/server/actors/highlighters/geometry-editor"
);
register(
"MeasuringToolHighlighter",
"devtools/server/actors/highlighters/measuring-tool"
);
register(
"PausedDebuggerOverlay",
"devtools/server/actors/highlighters/paused-debugger"
);
register("RulersHighlighter", "devtools/server/actors/highlighters/rulers");
register("SelectorHighlighter", "devtools/server/actors/highlighters/selector");
register("ShapesHighlighter", "devtools/server/actors/highlighters/shapes");
register(
"TabbingOrderHighlighter",
"devtools/server/actors/highlighters/tabbing-order"
);
// This constant object is created to make the calls array more
// readable. Otherwise, linting rules force some array defs to span 4
// lines instead, which is much harder to parse.
const HIGHLIGHTERS = {
accessible: "devtools/server/actors/highlighters/accessible",
boxModel: "devtools/server/actors/highlighters/box-model",
cssGrid: "devtools/server/actors/highlighters/css-grid",
cssTransform: "devtools/server/actors/highlighters/css-transform",
eyeDropper: "devtools/server/actors/highlighters/eye-dropper",
flexbox: "devtools/server/actors/highlighters/flexbox",
fonts: "devtools/server/actors/highlighters/fonts",
geometryEditor: "devtools/server/actors/highlighters/geometry-editor",
measuringTool: "devtools/server/actors/highlighters/measuring-tool",
pausedDebugger: "devtools/server/actors/highlighters/paused-debugger",
rulers: "devtools/server/actors/highlighters/rulers",
selector: "devtools/server/actors/highlighters/selector",
shapes: "devtools/server/actors/highlighters/shapes",
tabbingOrder: "devtools/server/actors/highlighters/tabbing-order",
};
// Each array in this array is called as register(arr[0], arr[1]).
const registerCalls = [
["AccessibleHighlighter", HIGHLIGHTERS.accessible],
["BoxModelHighlighter", HIGHLIGHTERS.boxModel],
["CssGridHighlighter", HIGHLIGHTERS.cssGrid],
["CssTransformHighlighter", HIGHLIGHTERS.cssTransform],
["EyeDropper", HIGHLIGHTERS.eyeDropper],
["FlexboxHighlighter", HIGHLIGHTERS.flexbox],
["FontsHighlighter", HIGHLIGHTERS.fonts],
["GeometryEditorHighlighter", HIGHLIGHTERS.geometryEditor],
["MeasuringToolHighlighter", HIGHLIGHTERS.measuringTool],
["PausedDebuggerOverlay", HIGHLIGHTERS.pausedDebugger],
["RulersHighlighter", HIGHLIGHTERS.rulers],
["SelectorHighlighter", HIGHLIGHTERS.selector],
["ShapesHighlighter", HIGHLIGHTERS.shapes],
["TabbingOrderHighlighter", HIGHLIGHTERS.tabbingOrder],
];
// Register each highlighter above.
registerCalls.forEach(arr => {
registerHighlighter(arr[0], arr[1]);
});