Commit 994dc1f2 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Enable even more tslint checks

 - 'let' instead of 'var', and prefer 'const'
 - Prefer for-of over indexed interation
 - Variable names should be 'camel-case' or
   all-caps snake-case.
 - Only one variable declaration per line

Change-Id: I645dd2333d6d9a993f24c29121f5f156249f1b71
Notry: true
Bug: v8:7327
Reviewed-on: https://chromium-review.googlesource.com/c/1405320
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58761}
parent 45669e9b
......@@ -32,7 +32,7 @@ export class CodeView extends View {
constructor(parent: HTMLElement, broker: SelectionBroker, sourceResolver: SourceResolver, sourceFunction: Source, codeMode: CodeMode) {
super(parent);
let view = this;
const view = this;
view.broker = broker;
view.sourceResolver = sourceResolver;
view.source = sourceFunction;
......@@ -48,7 +48,7 @@ export class CodeView extends View {
},
select: function (sourcePositions, selected) {
const locations = [];
for (var sourcePosition of sourcePositions) {
for (const sourcePosition of sourcePositions) {
locations.push(sourcePosition);
sourceResolver.addInliningPositions(sourcePosition, locations);
}
......@@ -134,7 +134,7 @@ export class CodeView extends View {
}
initializeCode() {
var view = this;
const view = this;
const source = this.source;
const sourceText = source.sourceText;
if (!sourceText) return;
......@@ -144,14 +144,14 @@ export class CodeView extends View {
} else {
sourceContainer.classList.add("inlined-source");
}
var codeHeader = document.createElement("div");
const codeHeader = document.createElement("div");
codeHeader.setAttribute("id", this.getCodeHeaderHtmlElementName());
codeHeader.classList.add("code-header");
var codeFileFunction = document.createElement("div");
const codeFileFunction = document.createElement("div");
codeFileFunction.classList.add("code-file-function");
codeFileFunction.innerHTML = `${source.sourceName}:${source.functionName}`;
codeHeader.appendChild(codeFileFunction);
var codeModeDiv = document.createElement("div");
const codeModeDiv = document.createElement("div");
codeModeDiv.classList.add("code-mode");
codeModeDiv.innerHTML = `${this.codeMode}`;
codeHeader.appendChild(codeModeDiv);
......@@ -159,7 +159,7 @@ export class CodeView extends View {
clearDiv.style.clear = "both";
codeHeader.appendChild(clearDiv);
sourceContainer.appendChild(codeHeader);
var codePre = document.createElement("pre");
const codePre = document.createElement("pre");
codePre.setAttribute("id", this.getCodeHtmlElementName());
codePre.classList.add("prettyprint");
sourceContainer.appendChild(codePre);
......@@ -204,8 +204,7 @@ export class CodeView extends View {
currentLineElement.id = "li" + i;
currentLineElement.dataset.lineNumber = "" + lineNumber;
const spans = currentLineElement.childNodes;
for (let j = 0; j < spans.length; ++j) {
const currentSpan = spans[j];
for (const currentSpan of spans) {
if (currentSpan instanceof HTMLSpanElement) {
const pos = base + current;
const end = pos + currentSpan.textContent.length;
......
......@@ -41,8 +41,8 @@ export class DisassemblyView extends TextView {
constructor(parentId, broker: SelectionBroker) {
super(parentId, broker);
let view = this;
let ADDRESS_STYLE = {
const view = this;
const ADDRESS_STYLE = {
associateData: (text, fragment: HTMLElement) => {
const matches = text.match(/(?<address>0?x?[0-9a-fA-F]{8,16})(?<addressSpace>\s+)(?<offset>[0-9a-f]+)(?<offsetSpace>\s*)/);
const offset = Number.parseInt(matches.groups["offset"], 16);
......@@ -65,16 +65,16 @@ export class DisassemblyView extends TextView {
}
}
};
let UNCLASSIFIED_STYLE = {
const UNCLASSIFIED_STYLE = {
css: 'com'
};
let NUMBER_STYLE = {
const NUMBER_STYLE = {
css: ['instruction-binary', 'lit']
};
let COMMENT_STYLE = {
const COMMENT_STYLE = {
css: 'com'
};
let OPCODE_ARGS = {
const OPCODE_ARGS = {
associateData: function (text, fragment) {
fragment.innerHTML = text;
const replacer = (match, hexOffset) => {
......@@ -86,12 +86,12 @@ export class DisassemblyView extends TextView {
fragment.innerHTML = html;
}
};
let OPCODE_STYLE = {
const OPCODE_STYLE = {
css: 'kwd'
};
const BLOCK_HEADER_STYLE = {
associateData: function (text, fragment) {
let matches = /\d+/.exec(text);
const matches = /\d+/.exec(text);
if (!matches) return;
const blockId = matches[0];
fragment.dataset.blockId = blockId;
......@@ -103,7 +103,7 @@ export class DisassemblyView extends TextView {
css: 'com'
};
view.SOURCE_POSITION_HEADER_REGEX = /^\s*--[^<]*<.*(not inlined|inlined\((\d+)\)):(\d+)>\s*--/;
let patterns = [
const patterns = [
[
[/^0?x?[0-9a-fA-F]{8,16}\s+[0-9a-f]+\s+/, ADDRESS_STYLE, 1],
[view.SOURCE_POSITION_HEADER_REGEX, SOURCE_POSITION_HEADER_STYLE, -1],
......@@ -223,7 +223,7 @@ export class DisassemblyView extends TextView {
updateSelection(scrollIntoView: boolean = false) {
super.updateSelection(scrollIntoView);
let keyPcOffsets = this.sourceResolver.nodesToKeyPcOffsets(this.selection.selectedKeys());
const keyPcOffsets = this.sourceResolver.nodesToKeyPcOffsets(this.selection.selectedKeys());
if (this.offsetSelection) {
for (const key of this.offsetSelection.selectedKeys()) {
keyPcOffsets.push(Number(key));
......@@ -238,7 +238,7 @@ export class DisassemblyView extends TextView {
}
initializeCode(sourceText, sourcePosition: number = 0) {
let view = this;
const view = this;
view.addrEventCounts = null;
view.totalEventCounts = null;
view.maxEventCounts = null;
......@@ -247,9 +247,9 @@ export class DisassemblyView extends TextView {
// add sourcePosition for lines > 0.
view.posLines[0] = sourcePosition;
if (sourceText && sourceText != "") {
let base = sourcePosition;
const base = sourcePosition;
let current = 0;
let sourceLines = sourceText.split("\n");
const sourceLines = sourceText.split("\n");
for (let i = 1; i < sourceLines.length; i++) {
// Add 1 for newline character that is split off.
current += sourceLines[i - 1].length + 1;
......@@ -259,16 +259,16 @@ export class DisassemblyView extends TextView {
}
initializePerfProfile(eventCounts) {
let view = this;
const view = this;
if (eventCounts !== undefined) {
view.addrEventCounts = eventCounts;
view.totalEventCounts = {};
view.maxEventCounts = {};
for (let evName in view.addrEventCounts) {
for (const evName in view.addrEventCounts) {
if (view.addrEventCounts.hasOwnProperty(evName)) {
let keys = Object.keys(view.addrEventCounts[evName]);
let values = keys.map(key => view.addrEventCounts[evName][key]);
const keys = Object.keys(view.addrEventCounts[evName]);
const values = keys.map(key => view.addrEventCounts[evName][key]);
view.totalEventCounts[evName] = values.reduce((a, b) => a + b);
view.maxEventCounts[evName] = values.reduce((a, b) => Math.max(a, b));
}
......@@ -294,21 +294,21 @@ export class DisassemblyView extends TextView {
}
processLine(line) {
let view = this;
const view = this;
let fragments = super.processLine(line);
// Add profiling data per instruction if available.
if (view.totalEventCounts) {
let matches = /^(0x[0-9a-fA-F]+)\s+\d+\s+[0-9a-fA-F]+/.exec(line);
const matches = /^(0x[0-9a-fA-F]+)\s+\d+\s+[0-9a-fA-F]+/.exec(line);
if (matches) {
let newFragments = [];
for (let event in view.addrEventCounts) {
const newFragments = [];
for (const event in view.addrEventCounts) {
if (!view.addrEventCounts.hasOwnProperty(event)) continue;
let count = view.addrEventCounts[event][matches[1]];
const count = view.addrEventCounts[event][matches[1]];
let str = " ";
let cssCls = "prof";
const cssCls = "prof";
if (count !== undefined) {
let perc = count / view.totalEventCounts[event] * 100;
const perc = count / view.totalEventCounts[event] * 100;
let col = { r: 255, g: 255, b: 255 };
for (let i = 0; i < PROF_COLS.length; i++) {
......@@ -316,11 +316,11 @@ export class DisassemblyView extends TextView {
col = PROF_COLS[i].col;
break;
} else if (perc > PROF_COLS[i].perc && perc < PROF_COLS[i + 1].perc) {
let col1 = PROF_COLS[i].col;
let col2 = PROF_COLS[i + 1].col;
const col1 = PROF_COLS[i].col;
const col2 = PROF_COLS[i + 1].col;
let val = perc - PROF_COLS[i].perc;
let max = PROF_COLS[i + 1].perc - PROF_COLS[i].perc;
const val = perc - PROF_COLS[i].perc;
const max = PROF_COLS[i + 1].perc - PROF_COLS[i].perc;
col.r = Math.round(interpolate(val, max, col1.r, col2.r));
col.g = Math.round(interpolate(val, max, col1.g, col2.g));
......@@ -331,7 +331,7 @@ export class DisassemblyView extends TextView {
str = UNICODE_BLOCK;
let fragment = view.createFragment(str, cssCls);
const fragment = view.createFragment(str, cssCls);
fragment.title = event + ": " + view.humanize(perc) + " (" + count + ")";
fragment.style.color = "rgb(" + col.r + ", " + col.g + ", " + col.b + ")";
......
......@@ -36,16 +36,16 @@ export class Edge {
if (this.backEdgeNumber > 0) {
return graph.maxGraphNodeX + this.backEdgeNumber * MINIMUM_EDGE_SEPARATION;
}
var source = this.source;
var target = this.target;
var index = this.index;
var inputX = target.x + target.getInputX(index);
var inputApproach = target.getInputApproach(this.index);
var outputApproach = source.getOutputApproach(showTypes);
const source = this.source;
const target = this.target;
const index = this.index;
const inputX = target.x + target.getInputX(index);
const inputApproach = target.getInputApproach(this.index);
const outputApproach = source.getOutputApproach(showTypes);
if (inputApproach > outputApproach) {
return inputX;
} else {
var inputOffset = MINIMUM_EDGE_SEPARATION * (index + 1);
const inputOffset = MINIMUM_EDGE_SEPARATION * (index + 1);
return (target.x < source.x)
? (target.x + target.getTotalNodeWidth() + inputOffset)
: (target.x - inputOffset);
......@@ -53,18 +53,18 @@ export class Edge {
}
generatePath(graph: Graph, showTypes: boolean) {
var target = this.target;
var source = this.source;
var inputX = target.x + target.getInputX(this.index);
var arrowheadHeight = 7;
var inputY = target.y - 2 * DEFAULT_NODE_BUBBLE_RADIUS - arrowheadHeight;
var outputX = source.x + source.getOutputX();
var outputY = source.y + source.getNodeHeight(showTypes) + DEFAULT_NODE_BUBBLE_RADIUS;
var inputApproach = target.getInputApproach(this.index);
var outputApproach = source.getOutputApproach(showTypes);
var horizontalPos = this.getInputHorizontalPosition(graph, showTypes);
const target = this.target;
const source = this.source;
const inputX = target.x + target.getInputX(this.index);
const arrowheadHeight = 7;
const inputY = target.y - 2 * DEFAULT_NODE_BUBBLE_RADIUS - arrowheadHeight;
const outputX = source.x + source.getOutputX();
const outputY = source.y + source.getNodeHeight(showTypes) + DEFAULT_NODE_BUBBLE_RADIUS;
let inputApproach = target.getInputApproach(this.index);
const outputApproach = source.getOutputApproach(showTypes);
const horizontalPos = this.getInputHorizontalPosition(graph, showTypes);
var result = "M" + outputX + "," + outputY +
let result = "M" + outputX + "," + outputY +
"L" + outputX + "," + outputApproach +
"L" + horizontalPos + "," + outputApproach;
......
......@@ -141,10 +141,9 @@ function newGraphOccupation(graph: Graph) {
let direction = -1;
let outputEdges = 0;
let inputEdges = 0;
for (let k = 0; k < n.outputs.length; ++k) {
const outputEdge = n.outputs[k];
for (const outputEdge of n.outputs) {
if (outputEdge.isVisible()) {
const output = n.outputs[k].target;
const output = outputEdge.target;
for (let l = 0; l < output.inputs.length; ++l) {
if (output.rank > n.rank) {
const inputEdge = output.inputs[l];
......@@ -202,8 +201,8 @@ function newGraphOccupation(graph: Graph) {
source.outputs.forEach(function (edge) {
if (edge.isVisible()) {
const target = edge.target;
for (let i = 0; i < target.inputs.length; ++i) {
if (target.inputs[i].source === source) {
for (const inputEdge of target.inputs) {
if (inputEdge.source === source) {
const horizontalPos = edge.getInputHorizontalPosition(graph, showTypes);
clearPositionRangeWithMargin(horizontalPos,
horizontalPos,
......@@ -332,8 +331,8 @@ export function layoutNodeGraph(graph: Graph, showTypes: boolean): void {
const originalRank = n.rank;
let newRank = n.rank;
let isFirstInput = true;
for (let l = 0; l < n.outputs.length; ++l) {
const output = n.outputs[l].target;
for (const outputEdge of n.outputs) {
const output = outputEdge.target;
dfsFindRankLate(output);
const outputRank = output.rank;
if (output.visible && (isFirstInput || outputRank <= newRank) &&
......@@ -353,10 +352,9 @@ export function layoutNodeGraph(graph: Graph, showTypes: boolean): void {
function dfsRankOrder(n: GNode) {
if (visited[n.id]) return;
visited[n.id] = true;
for (let l = 0; l < n.outputs.length; ++l) {
const edge = n.outputs[l];
if (edge.isVisible()) {
const output = edge.target;
for (const outputEdge of n.outputs) {
if (outputEdge.isVisible()) {
const output = outputEdge.target;
dfsRankOrder(output);
}
}
......@@ -391,8 +389,8 @@ export function layoutNodeGraph(graph: Graph, showTypes: boolean): void {
rankSets.reverse().forEach(function (rankSet: Array<GNode>) {
for (let i = 0; i < rankSet.length; ++i) {
occupation.clearNodeOutputs(rankSet[i], showTypes);
for (const node of rankSet) {
occupation.clearNodeOutputs(node, showTypes);
}
if (traceLayout) {
......@@ -411,8 +409,7 @@ export function layoutNodeGraph(graph: Graph, showTypes: boolean): void {
}
});
for (let i = 0; i < rankSet.length; ++i) {
const nodeToPlace = rankSet[i];
for (const nodeToPlace of rankSet) {
if (nodeToPlace.visible) {
nodeToPlace.x = occupation.occupyNode(nodeToPlace);
if (traceLayout) {
......@@ -438,8 +435,7 @@ export function layoutNodeGraph(graph: Graph, showTypes: boolean): void {
occupation.print();
}
for (let i = 0; i < rankSet.length; ++i) {
const node = rankSet[i];
for (const node of rankSet) {
occupation.occupyNodeInputs(node, showTypes);
}
......
......@@ -88,7 +88,7 @@ export class GraphView extends View implements PhaseView {
view.updateGraphVisibility();
},
select: function (nodes: Array<GNode>, selected: boolean) {
let locations = [];
const locations = [];
for (const node of nodes) {
if (node.nodeLabel.sourcePosition) {
locations.push(node.nodeLabel.sourcePosition);
......@@ -103,7 +103,7 @@ export class GraphView extends View implements PhaseView {
},
brokeredNodeSelect: function (locations, selected: boolean) {
if (!view.graph) return;
let selection = view.graph.nodes(n => {
const selection = view.graph.nodes(n => {
return locations.has(nodeToStringKey(n))
&& (!view.state.hideDead || n.isLive());
});
......@@ -177,10 +177,10 @@ export class GraphView extends View implements PhaseView {
getEdgeFrontier(nodes: Iterable<GNode>, inEdges: boolean,
edgeFilter: (e: Edge, i: number) => boolean) {
let frontier: Set<Edge> = new Set();
const frontier: Set<Edge> = new Set();
for (const n of nodes) {
const edges = inEdges ? n.inputs : n.outputs;
var edgeNumber = 0;
let edgeNumber = 0;
edges.forEach((edge: Edge) => {
if (edgeFilter == undefined || edgeFilter(edge, edgeNumber)) {
frontier.add(edge);
......@@ -470,7 +470,7 @@ export class GraphView extends View implements PhaseView {
case 57:
// '1'-'9'
showSelectionFrontierNodes(true,
(edge: Edge, index: number) => { return index == (d3.event.keyCode - 49); },
(edge: Edge, index: number) => index == (d3.event.keyCode - 49),
!d3.event.ctrlKey);
break;
case 97:
......@@ -484,19 +484,19 @@ export class GraphView extends View implements PhaseView {
case 105:
// 'numpad 1'-'numpad 9'
showSelectionFrontierNodes(true,
(edge, index) => { return index == (d3.event.keyCode - 97); },
(edge, index) => index == (d3.event.keyCode - 97),
!d3.event.ctrlKey);
break;
case 67:
// 'c'
showSelectionFrontierNodes(d3.event.altKey,
(edge, index) => { return edge.type == 'control'; },
(edge, index) => edge.type == 'control',
true);
break;
case 69:
// 'e'
showSelectionFrontierNodes(d3.event.altKey,
(edge, index) => { return edge.type == 'effect'; },
(edge, index) => edge.type == 'effect',
true);
break;
case 79:
......@@ -638,8 +638,8 @@ export class GraphView extends View implements PhaseView {
.classed("machine", function (n) { return n.isMachine(); })
.on('mouseenter', function (node) {
const visibleEdges = view.visibleEdges.selectAll<SVGPathElement, Edge>('path');
const adjInputEdges = visibleEdges.filter(e => { return e.target === node; });
const adjOutputEdges = visibleEdges.filter(e => { return e.source === node; });
const adjInputEdges = visibleEdges.filter(e => e.target === node);
const adjOutputEdges = visibleEdges.filter(e => e.source === node);
adjInputEdges.attr('relToHover', "input");
adjOutputEdges.attr('relToHover', "output");
const adjInputNodes = adjInputEdges.data().map(e => e.source);
......@@ -651,7 +651,7 @@ export class GraphView extends View implements PhaseView {
})
.on('mouseleave', function (node) {
const visibleEdges = view.visibleEdges.selectAll<SVGPathElement, Edge>('path');
const adjEdges = visibleEdges.filter(e => { return e.target === node || e.source === node; });
const adjEdges = visibleEdges.filter(e => e.target === node || e.source === node);
adjEdges.attr('relToHover', "none");
const adjNodes = adjEdges.data().map(e => e.target).concat(adjEdges.data().map(e => e.source));
const visibleNodes = view.visibleNodes.selectAll<SVGPathElement, GNode>("g");
......@@ -821,10 +821,10 @@ export class GraphView extends View implements PhaseView {
viewSelection() {
const view = this;
var minX;
var maxX;
var minY;
var maxY;
let minX;
let maxX;
let minY;
let maxY;
let hasSelection = false;
view.visibleNodes.selectAll<SVGGElement, GNode>("g").each(function (n) {
if (view.state.selection.isSelected(n)) {
......
......@@ -27,9 +27,9 @@ export class Graph {
});
data.edges.forEach((e: any) => {
var t = this.nodeMap[e.target];
var s = this.nodeMap[e.source];
var newEdge = new Edge(t, e.index, s, e.type);
const t = this.nodeMap[e.target];
const s = this.nodeMap[e.source];
const newEdge = new Edge(t, e.index, s, e.type);
t.inputs.push(newEdge);
s.outputs.push(newEdge);
if (e.type == 'control') {
......
......@@ -85,7 +85,7 @@ export class GNode {
this.isJavaScript() || this.isSimplified());
}
getTotalNodeWidth() {
var inputWidth = this.inputs.length * NODE_INPUT_WIDTH;
const inputWidth = this.inputs.length * NODE_INPUT_WIDTH;
return Math.max(inputWidth, this.width);
}
getTitle() {
......@@ -98,7 +98,7 @@ export class GNode {
return this.nodeLabel.type;
}
getDisplayType() {
var typeString = this.nodeLabel.type;
let typeString = this.nodeLabel.type;
if (typeString == undefined) return "";
if (typeString.length > 24) {
typeString = typeString.substr(0, 25) + "...";
......@@ -106,7 +106,7 @@ export class GNode {
return typeString;
}
deepestInputRank() {
var deepestRank = 0;
let deepestRank = 0;
this.inputs.forEach(function (e) {
if (e.isVisible() && !e.isBackEdge()) {
if (e.source.rank > deepestRank) {
......@@ -117,14 +117,14 @@ export class GNode {
return deepestRank;
}
areAnyOutputsVisible() {
var visibleCount = 0;
let visibleCount = 0;
this.outputs.forEach(function (e) { if (e.isVisible())++visibleCount; });
if (this.outputs.length == visibleCount) return 2;
if (visibleCount != 0) return 1;
return 0;
}
setOutputVisibility(v) {
var result = false;
let result = false;
this.outputs.forEach(function (e) {
e.visible = v;
if (v) {
......@@ -137,7 +137,7 @@ export class GNode {
return result;
}
setInputVisibility(i, v) {
var edge = this.inputs[i];
const edge = this.inputs[i];
edge.visible = v;
if (v) {
if (!edge.source.visible) {
......@@ -163,7 +163,7 @@ export class GNode {
+ DEFAULT_NODE_BUBBLE_RADIUS;
}
getInputX(index) {
var result = this.getTotalNodeWidth() - (NODE_INPUT_WIDTH / 2) +
const result = this.getTotalNodeWidth() - (NODE_INPUT_WIDTH / 2) +
(index - this.inputs.length + 1) * NODE_INPUT_WIDTH;
return result;
}
......
......@@ -35,7 +35,7 @@ class Snapper {
}
getLastExpandedState(type: string, defaultState: boolean): boolean {
var state = window.sessionStorage.getItem("expandedState-" + type);
const state = window.sessionStorage.getItem("expandedState-" + type);
if (state === null) return defaultState;
return state === 'true';
}
......@@ -102,7 +102,7 @@ export class Resizer {
resizerLeft: d3.Selection<HTMLDivElement, any, any, any>;
constructor(panesUpdatedCallback: () => void, deadWidth: number) {
let resizer = this;
const resizer = this;
resizer.panesUpdatedCallback = panesUpdatedCallback;
resizer.deadWidth = deadWidth;
resizer.left = document.getElementById(C.SOURCE_PANE_ID);
......@@ -116,15 +116,15 @@ export class Resizer {
resizer.sepWidthOffset = 7;
this.updateWidths();
let dragResizeLeft = d3.drag()
const dragResizeLeft = d3.drag()
.on('drag', function () {
let x = d3.mouse(this.parentElement)[0];
const x = d3.mouse(this.parentElement)[0];
resizer.sepLeft = Math.min(Math.max(0, x), resizer.sepRight - resizer.sepWidthOffset);
resizer.updatePanes();
})
.on('start', function () {
resizer.resizerLeft.classed("dragged", true);
let x = d3.mouse(this.parentElement)[0];
const x = d3.mouse(this.parentElement)[0];
if (x > deadWidth) {
resizer.sepLeftSnap = resizer.sepLeft;
}
......@@ -137,15 +137,15 @@ export class Resizer {
});
resizer.resizerLeft.call(dragResizeLeft);
let dragResizeRight = d3.drag()
const dragResizeRight = d3.drag()
.on('drag', function () {
let x = d3.mouse(this.parentElement)[0];
const x = d3.mouse(this.parentElement)[0];
resizer.sepRight = Math.max(resizer.sepLeft + resizer.sepWidthOffset, Math.min(x, resizer.clientWidth));
resizer.updatePanes();
})
.on('start', function () {
resizer.resizerRight.classed("dragged", true);
let x = d3.mouse(this.parentElement)[0];
const x = d3.mouse(this.parentElement)[0];
if (x < (resizer.clientWidth - deadWidth)) {
resizer.sepRightSnap = resizer.sepRight;
}
......@@ -175,8 +175,8 @@ export class Resizer {
}
updatePanes() {
let leftSnapped = this.isLeftSnapped();
let rightSnapped = this.isRightSnapped();
const leftSnapped = this.isLeftSnapped();
const rightSnapped = this.isRightSnapped();
this.resizerLeft.classed("snapped", leftSnapped);
this.resizerRight.classed("snapped", rightSnapped);
this.left.style.width = this.sepLeft + 'px';
......
......@@ -44,7 +44,7 @@ export class ScheduleView extends TextView implements PhaseView {
}
createElementFromString(htmlString) {
var div = document.createElement('div');
const div = document.createElement('div');
div.innerHTML = htmlString.trim();
return div.firstChild;
}
......
......@@ -76,7 +76,7 @@ export class SelectionBroker {
}
broadcastBlockSelect(from, blocks, selected) {
for (var b of this.blockHandlers) {
for (const b of this.blockHandlers) {
if (b != from) b.brokeredBlockSelect(blocks, selected);
}
}
......
......@@ -42,16 +42,16 @@ export class MySelection {
}
selectedKeys() {
var result = new Set();
for (var i of this.selection.keys()) {
const result = new Set();
for (const i of this.selection.keys()) {
result.add(i);
}
return result;
}
detachSelection() {
var result = new Set();
for (var i of this.selection.keys()) {
const result = new Set();
for (const i of this.selection.keys()) {
result.add(i);
}
this.clear();
......
......@@ -83,7 +83,7 @@ export class SequenceView extends TextView implements PhaseView {
}
function elementForOperand(operand, searchInfo) {
var text = operand.text;
const text = operand.text;
const operandEl = createElement("div", ["parameter", "tag", "clickable", operand.type], text);
if (operand.tooltip) {
operandEl.setAttribute("title", operand.tooltip);
......@@ -137,7 +137,7 @@ export class SequenceView extends TextView implements PhaseView {
instEl.appendChild(assignEl);
}
var text = instruction.opcode + instruction.flags;
const text = instruction.opcode + instruction.flags;
const instLabel = createElement("div", "node-label", text);
searchInfo.push(text);
view.addHtmlElementForNodeId(text, instLabel);
......
......@@ -151,7 +151,7 @@ export class SourceResolver {
setSources(sources, mainBackup) {
if (sources) {
for (let [sourceId, source] of Object.entries(sources)) {
for (const [sourceId, source] of Object.entries(sources)) {
this.sources[sourceId] = source;
this.sources[sourceId].sourcePositions = [];
}
......@@ -196,7 +196,7 @@ export class SourceResolver {
this.sources[sourceId].sourcePositions.push(sourcePosition);
}
this.nodePositionMap[nodeId] = sourcePosition;
let key = sourcePositionToStringKey(sourcePosition);
const key = sourcePositionToStringKey(sourcePosition);
if (!this.positionToNodes.has(key)) {
this.positionToNodes.set(key, []);
}
......@@ -211,8 +211,8 @@ export class SourceResolver {
sourcePositionsToNodeIds(sourcePositions) {
const nodeIds = new Set();
for (const sp of sourcePositions) {
let key = sourcePositionToStringKey(sp);
let nodeIdsForPosition = this.positionToNodes.get(key);
const key = sourcePositionToStringKey(sp);
const nodeIdsForPosition = this.positionToNodes.get(key);
if (!nodeIdsForPosition) continue;
for (const nodeId of nodeIdsForPosition) {
nodeIds.add(nodeId);
......@@ -224,8 +224,8 @@ export class SourceResolver {
nodeIdsToSourcePositions(nodeIds): Array<AnyPosition> {
const sourcePositions = new Map();
for (const nodeId of nodeIds) {
let sp = this.nodePositionMap[nodeId];
let key = sourcePositionToStringKey(sp);
const sp = this.nodePositionMap[nodeId];
const key = sourcePositionToStringKey(sp);
sourcePositions.set(key, sp);
}
const sourcePositionArray = [];
......@@ -241,7 +241,7 @@ export class SourceResolver {
translateToSourceId(sourceId: number, location?: SourcePosition) {
for (const position of this.getInlineStack(location)) {
let inlining = this.inlinings[position.inliningId];
const inlining = this.inlinings[position.inliningId];
if (!inlining) continue;
if (inlining.sourceId == sourceId) {
return position;
......@@ -251,9 +251,9 @@ export class SourceResolver {
}
addInliningPositions(sourcePosition: AnyPosition, locations: Array<SourcePosition>) {
let inlining = this.inliningsMap.get(sourcePositionToStringKey(sourcePosition));
const inlining = this.inliningsMap.get(sourcePositionToStringKey(sourcePosition));
if (!inlining) return;
let sourceId = inlining.sourceId;
const sourceId = inlining.sourceId;
const source = this.sources[sourceId];
for (const sp of source.sourcePositions) {
locations.push(sp);
......@@ -305,11 +305,11 @@ export class SourceResolver {
getInlineStack(sourcePosition?: SourcePosition) {
if (!sourcePosition) return [];
let inliningStack = [];
const inliningStack = [];
let cur = sourcePosition;
while (cur && cur.inliningId != -1) {
inliningStack.push(cur);
let inlining = this.inlinings[cur.inliningId];
const inlining = this.inlinings[cur.inliningId];
if (!inlining) {
break;
}
......@@ -329,7 +329,7 @@ export class SourceResolver {
node.origin.bytecodePosition != undefined) {
const position = { bytecodePosition: node.origin.bytecodePosition };
this.nodePositionMap[node.id] = position;
let key = sourcePositionToStringKey(position);
const key = sourcePositionToStringKey(position);
if (!this.positionToNodes.has(key)) {
this.positionToNodes.set(key, []);
}
......
......@@ -25,7 +25,7 @@ export abstract class TextView extends View {
constructor(id, broker) {
super(id);
let view = this;
const view = this;
view.textListNode = view.divNode.getElementsByTagName('ul')[0];
view.patterns = null;
view.nodeIdToHtmlElementsMap = new Map();
......@@ -161,14 +161,14 @@ export abstract class TextView extends View {
}
clearText() {
let view = this;
const view = this;
while (view.textListNode.firstChild) {
view.textListNode.removeChild(view.textListNode.firstChild);
}
}
createFragment(text, style) {
let fragment = document.createElement("SPAN");
const fragment = document.createElement("SPAN");
if (typeof style.associateData == 'function') {
style.associateData(text, fragment);
......@@ -186,19 +186,19 @@ export abstract class TextView extends View {
}
processLine(line) {
let view = this;
let result = [];
const view = this;
const result = [];
let patternSet = 0;
while (true) {
let beforeLine = line;
for (let pattern of view.patterns[patternSet]) {
let matches = line.match(pattern[0]);
const beforeLine = line;
for (const pattern of view.patterns[patternSet]) {
const matches = line.match(pattern[0]);
if (matches != null) {
if (matches[0] != '') {
let style = pattern[1] != null ? pattern[1] : {};
let text = matches[0];
const style = pattern[1] != null ? pattern[1] : {};
const text = matches[0];
if (text != '') {
let fragment = view.createFragment(matches[0], style);
const fragment = view.createFragment(matches[0], style);
result.push(fragment);
}
line = line.substr(matches[0].length);
......@@ -224,15 +224,15 @@ export abstract class TextView extends View {
}
processText(text) {
let view = this;
let textLines = text.split(/[\n]/);
const view = this;
const textLines = text.split(/[\n]/);
let lineNo = 0;
for (let line of textLines) {
let li = document.createElement("LI");
for (const line of textLines) {
const li = document.createElement("LI");
li.className = "nolinenums";
li.dataset.lineNo = "" + lineNo++;
let fragments = view.processLine(line);
for (let fragment of fragments) {
const fragments = view.processLine(line);
for (const fragment of fragments) {
li.appendChild(fragment);
}
view.textListNode.appendChild(li);
......@@ -240,7 +240,7 @@ export abstract class TextView extends View {
}
initializeContent(data, rememberedSelection) {
let view = this;
const view = this;
view.clearText();
view.processText(data);
}
......
......@@ -13,12 +13,12 @@ import { Resizer } from "../src/resizer";
import * as C from "../src/constants";
window.onload = function () {
var multiview = null;
var disassemblyView = null;
var sourceViews = [];
var selectionBroker = null;
var sourceResolver = null;
let resizer = new Resizer(panesUpdatedCallback, 100);
let multiview = null;
let disassemblyView = null;
let sourceViews = [];
let selectionBroker = null;
let sourceResolver = null;
const resizer = new Resizer(panesUpdatedCallback, 100);
function panesUpdatedCallback() {
if (multiview) multiview.onresize();
......@@ -68,12 +68,12 @@ window.onload = function () {
sourceContainer.classList.add("viewpane", "scrollable");
sourceTabs.activateTab(sourceTab);
sourceTabs.addTab("&#x2b;").classList.add("open-tab");
let sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, fnc, CodeMode.MAIN_SOURCE);
const sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, fnc, CodeMode.MAIN_SOURCE);
sourceView.show(null, null);
sourceViews.push(sourceView);
sourceResolver.forEachSource(source => {
let sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE);
const sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE);
sourceView.show(null, null);
sourceViews.push(sourceView);
});
......
......@@ -50,8 +50,8 @@ export class ViewElements {
export function sortUnique<T>(arr: Array<T>, f: (a: T, b: T) => number, equal: (a: T, b: T) => boolean) {
if (arr.length == 0) return arr;
arr = arr.sort(f);
let ret = [arr[0]];
for (var i = 1; i < arr.length; i++) {
const ret = [arr[0]];
for (let i = 1; i < arr.length; i++) {
if (!equal(arr[i - 1], arr[i])) {
ret.push(arr[i]);
}
......
......@@ -4,7 +4,7 @@ import { describe, it } from 'mocha';
describe('SourceResolver', () => {
it('should be constructible', () => {
let a: SourceResolver = new SourceResolver();
const a: SourceResolver = new SourceResolver();
expect(a.sources.length).to.equal(0);
});
});
......@@ -6,8 +6,8 @@
"curly": [true, "ignore-same-line"],
"quotemark": [false, "double", "avoid-escape", "avoid-template"],
"only-arrow-functions": [false],
"no-var-keyword": false,
"prefer-const": [false],
"no-var-keyword": true,
"prefer-const": [true],
"max-line-length": [false, {
"limit": 80
}],
......@@ -32,13 +32,13 @@
"interface-name": false,
"no-bitwise": false,
"no-shadowed-variable": false,
"prefer-for-of": false,
"align": false,
"arrow-return-shorthand": false,
"prefer-for-of": true,
"align": true,
"arrow-return-shorthand": true,
"max-classes-per-file": false,
"variable-name": false,
"variable-name": true,
"forin": false,
"one-variable-per-declaration": false,
"one-variable-per-declaration": true,
"no-consecutive-blank-lines": true
},
"rulesDirectory": []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment