Skip to content

Commit

Permalink
merge updates from official devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Jul 15, 2019
2 parents 4180488 + 4946c75 commit 5c7e328
Show file tree
Hide file tree
Showing 24 changed files with 2,236 additions and 2,086 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
const cachedResources = Runtime.cachedResources;

module.exports = {
REPORT_CSS: cachedResources['audits/lighthouse/report.css'],
REPORT_JAVASCRIPT: cachedResources['audits/lighthouse/report.js'],
REPORT_TEMPLATE: cachedResources['audits/lighthouse/template.html'],
REPORT_TEMPLATES: cachedResources['audits/lighthouse/templates.html'],
get REPORT_CSS() {
return cachedResources['audits/lighthouse/report.css'];
},
get REPORT_JAVASCRIPT() {
return cachedResources['audits/lighthouse/report.js'];
},
get REPORT_TEMPLATE() {
return cachedResources['audits/lighthouse/template.html'];
},
get REPORT_TEMPLATES() {
return cachedResources['audits/lighthouse/templates.html'];
},
};

},{}],1:[function(require,module,exports){
Expand Down
5 changes: 3 additions & 2 deletions resources/unpacked/devtools/front_end/cm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ This requires the following steps to be done:
1. File `headlesscodemirror.js` is a `runmode-standalone.js` file from CodeMirror distribution, but wrapped in `(function(window) { ... }(this))`
construction. This is needed to support in web workers.
2. File `markselection.js` is a `mark-selection.js` from CodeMirror distribution. The "dash" is removed due to the restriction on the chromium grd generator.
4. File codemirror.css contains both the default theme of CodeMirror and structural css required for it to work. Discard everything in the file up to the word `/* STOP */`.
3. All other files in front_end/cm/ folder should be substituted with their newer versions from the upstream.
3. File codemirror.css contains both the default theme of CodeMirror and structural css required for it to work. Discard everything in the file up to the word `/* STOP */`.
4. All other files in front_end/cm/ folder should be substituted with their newer versions from the upstream. Note that some need to be renamed to remove `-` from the file name.
5. All files in front_end/cm_web_modes/ and front_end/cm_modes/ should be updated with newer versions from upstream.

## Testing
DevTools wrap CodeMirror via `CodeMirrorTextEditor.js` and `cmdevtools.css` files.
Expand Down
102 changes: 41 additions & 61 deletions resources/unpacked/devtools/front_end/cm/brace-fold.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,74 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Distributed under an MIT license: https://codemirror.net/LICENSE

(function(mod) {
if (typeof exports == 'object' && typeof module == 'object') // CommonJS
mod(require('../../lib/codemirror'));
else if (typeof define == 'function' && define.amd) // AMD
define(['../../lib/codemirror'], mod);
else // Plain browser env
mod(CodeMirror);
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
'use strict';
"use strict";

CodeMirror.registerHelper('fold', 'brace', function(cm, start) {
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var tokenType;

function findOpening(openCh) {
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
if (found == -1) {
if (pass == 1)
break;
if (pass == 1) break;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch)
break;
if (pass == 1 && found < start.ch) break;
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
if (!/^(comment|string)/.test(tokenType))
return found + 1;
if (!/^(comment|string)/.test(tokenType)) return found + 1;
at = found - 1;
}
}

var startToken = '{', endToken = '}', startCh = findOpening('{');
var startToken = "{", endToken = "}", startCh = findOpening("{");
if (startCh == null) {
startToken = '[', endToken = ']';
startCh = findOpening('[');
startToken = "[", endToken = "]";
startCh = findOpening("[");
}

if (startCh == null)
return;
if (startCh == null) return;
var count = 1, lastLine = cm.lastLine(), end, endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0)
nextOpen = text.length;
if (nextClose < 0)
nextClose = text.length;
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length)
break;
if (pos == text.length) break;
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
if (pos == nextOpen)
++count;
else if (!--count) {
end = i;
endCh = pos;
break outer;
}
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
}
++pos;
}
}
if (end == null || line == end && endCh == startCh)
return;
return {from: CodeMirror.Pos(line, startCh), to: CodeMirror.Pos(end, endCh)};
if (end == null || line == end) return;
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});

CodeMirror.registerHelper('fold', 'import', function(cm, start) {
CodeMirror.registerHelper("fold", "import", function(cm, start) {
function hasImport(line) {
if (line < cm.firstLine() || line > cm.lastLine())
return null;
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string))
start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type != 'keyword' || start.string != 'import')
return null;
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type != "keyword" || start.string != "import") return null;
// Now find closing semicolon, return its position
for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
var text = cm.getLine(i), semi = text.indexOf(';');
if (semi != -1)
return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
var text = cm.getLine(i), semi = text.indexOf(";");
if (semi != -1) return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
}
}

Expand All @@ -93,33 +77,29 @@ CodeMirror.registerHelper('fold', 'import', function(cm, start) {
return null;
for (var end = has.end;;) {
var next = hasImport(end.line + 1);
if (next == null)
break;
if (next == null) break;
end = next.end;
}
return {from: cm.clipPos(CodeMirror.Pos(startLine, has.startCh + 1)), to: end};
});

CodeMirror.registerHelper('fold', 'include', function(cm, start) {
CodeMirror.registerHelper("fold", "include", function(cm, start) {
function hasInclude(line) {
if (line < cm.firstLine() || line > cm.lastLine())
return null;
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string))
start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type == 'meta' && start.string.slice(0, 8) == '#include')
return start.start + 8;
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
}

var startLine = start.line, has = hasInclude(startLine);
if (has == null || hasInclude(startLine - 1) != null)
return null;
if (has == null || hasInclude(startLine - 1) != null) return null;
for (var end = startLine;;) {
var next = hasInclude(end + 1);
if (next == null)
break;
if (next == null) break;
++end;
}
return {from: CodeMirror.Pos(startLine, has + 1), to: cm.clipPos(CodeMirror.Pos(end))};
return {from: CodeMirror.Pos(startLine, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
});

});
});
6 changes: 5 additions & 1 deletion resources/unpacked/devtools/front_end/cm/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
})(function(CodeMirror) {
var defaults = {
pairs: "()[]{}''\"\"",
closeBefore: ")]}'\":;>",
triples: "",
explode: "[]{}"
};
Expand Down Expand Up @@ -109,6 +110,9 @@
var pairs = getOption(conf, "pairs");
var pos = pairs.indexOf(ch);
if (pos == -1) return CodeMirror.Pass;

var closeBefore = getOption(conf,"closeBefore");

var triples = getOption(conf, "triples");

var identical = pairs.charAt(pos + 1) == ch;
Expand Down Expand Up @@ -136,7 +140,7 @@
var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur)
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both";
else return CodeMirror.Pass;
} else if (opening) {
} else if (opening && (next.length === 0 || /\s/.test(next) || closeBefore.indexOf(next) > -1)) {
curType = "both";
} else {
return CodeMirror.Pass;
Expand Down
Loading

0 comments on commit 5c7e328

Please sign in to comment.