Title: [192076] trunk/Source/WebInspectorUI
- Revision
- 192076
- Author
- [email protected]
- Date
- 2015-11-05 14:14:52 -0800 (Thu, 05 Nov 2015)
Log Message
Web Inspector: Pretty print falsely triggers on some JS that wasn't minified
https://bugs.webkit.org/show_bug.cgi?id=150876
Change the minification detection heuristic. Look for the ratio of whitespace to
non-whitespace characters in the first 5000 characters.
The previous heuristic looked for lines longer than 500 characters. Not only it was
slower on large unminified files, it also had a false positive on unminified codemirror.js.
Reviewed by Timothy Hatcher.
* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor.prototype._contentWillPopulate):
(WebInspector.SourceCodeTextEditor.prototype._isLikelyMinified):
Exit early if whitespace to non-whitespace ratio drops below 5%.
Modified Paths
Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (192075 => 192076)
--- trunk/Source/WebInspectorUI/ChangeLog 2015-11-05 22:12:28 UTC (rev 192075)
+++ trunk/Source/WebInspectorUI/ChangeLog 2015-11-05 22:14:52 UTC (rev 192076)
@@ -1,3 +1,21 @@
+2015-11-05 Nikita Vasilyev <[email protected]>
+
+ Web Inspector: Pretty print falsely triggers on some JS that wasn't minified
+ https://bugs.webkit.org/show_bug.cgi?id=150876
+
+ Change the minification detection heuristic. Look for the ratio of whitespace to
+ non-whitespace characters in the first 5000 characters.
+
+ The previous heuristic looked for lines longer than 500 characters. Not only it was
+ slower on large unminified files, it also had a false positive on unminified codemirror.js.
+
+ Reviewed by Timothy Hatcher.
+
+ * UserInterface/Views/SourceCodeTextEditor.js:
+ (WebInspector.SourceCodeTextEditor.prototype._contentWillPopulate):
+ (WebInspector.SourceCodeTextEditor.prototype._isLikelyMinified):
+ Exit early if whitespace to non-whitespace ratio drops below 5%.
+
2015-11-05 Matt Baker <[email protected]>
Web Inspector: Convert TimelineRuler to View base class
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js (192075 => 192076)
--- trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js 2015-11-05 22:12:28 UTC (rev 192075)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js 2015-11-05 22:14:52 UTC (rev 192076)
@@ -388,27 +388,30 @@
// Automatically format the content if it looks minified and it can be formatted.
console.assert(!this.formatted);
- if (this.canBeFormatted()) {
- var lastNewlineIndex = 0;
- while (true) {
- var nextNewlineIndex = content.indexOf("\n", lastNewlineIndex);
- if (nextNewlineIndex === -1) {
- if (content.length - lastNewlineIndex > WebInspector.SourceCodeTextEditor.AutoFormatMinimumLineLength) {
- this.autoFormat = true;
- this._isProbablyMinified = true;
- }
- break;
- }
+ if (this.canBeFormatted() && this._isLikelyMinified(content)) {
+ this.autoFormat = true;
+ this._isProbablyMinified = true;
+ }
+ }
- if (nextNewlineIndex - lastNewlineIndex > WebInspector.SourceCodeTextEditor.AutoFormatMinimumLineLength) {
- this.autoFormat = true;
- this._isProbablyMinified = true;
- break;
- }
+ _isLikelyMinified(content)
+ {
+ let whiteSpaceCount = 0;
+ let ratio = 0;
- lastNewlineIndex = nextNewlineIndex + 1;
+ for (let i = 0, size = Math.min(5000, content.length); i < size; i++) {
+ let char = content[i];
+ if (char === " " || char === "\n" || char === "\t")
+ whiteSpaceCount++;
+
+ if (i >= 500) {
+ ratio = whiteSpaceCount / i;
+ if (ratio < 0.05)
+ return true;
}
}
+
+ return ratio < 0.1;
}
_contentDidPopulate()
@@ -1795,7 +1798,6 @@
WebInspector.SourceCodeTextEditor.DurationToMouseOverTokenToMakeHoveredToken = 500;
WebInspector.SourceCodeTextEditor.DurationToMouseOutOfHoveredTokenToRelease = 1000;
WebInspector.SourceCodeTextEditor.DurationToUpdateTypeTokensAfterScrolling = 100;
-WebInspector.SourceCodeTextEditor.AutoFormatMinimumLineLength = 500;
WebInspector.SourceCodeTextEditor.WidgetContainsMultipleIssuesSymbol = Symbol("source-code-widget-contains-multiple-issues");
WebInspector.SourceCodeTextEditor.Event = {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes