New jQuery usage rule
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
var debug = require('debug')('ylt:jsExecutionTransformer');
|
||||
|
||||
var offendersHelpers = require('../offendersHelpers');
|
||||
var offendersHelpers = require('../offendersHelpers');
|
||||
var Collection = require('./phantomas/custom_modules/util/collection');
|
||||
|
||||
var jsExecutionTransformer = function() {
|
||||
|
||||
this.transform = function(data) {
|
||||
var javascriptExecutionTree = {};
|
||||
var scrollExecutionTree = {};
|
||||
var jQueryFunctionsCollection = new Collection();
|
||||
|
||||
var metrics = {
|
||||
DOMaccesses: 0,
|
||||
@@ -17,6 +19,10 @@ var jsExecutionTransformer = function() {
|
||||
jQueryNotDelegatedEvent: 0
|
||||
};
|
||||
|
||||
var offenders = {
|
||||
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
debug('Starting JS execution transformation');
|
||||
@@ -44,6 +50,7 @@ var jsExecutionTransformer = function() {
|
||||
|
||||
if (node.data.type.indexOf('jQuery - ') === 0) {
|
||||
metrics.jQueryCalls ++;
|
||||
jQueryFunctionsCollection.push(node.data.type);
|
||||
}
|
||||
|
||||
// Mark errors with an error flag
|
||||
@@ -78,14 +85,32 @@ var jsExecutionTransformer = function() {
|
||||
// Count the number of DOM accesses, by counting the tree leafs
|
||||
metrics.DOMaccesses += countTreeLeafs(node);
|
||||
});
|
||||
|
||||
// Count the number of different jQuery functions called
|
||||
if (data.toolsResults.phantomas.metrics.jQueryVersionsLoaded) {
|
||||
metrics.jQueryFunctionsUsed = 0;
|
||||
offenders.jQueryFunctionsUsed = [];
|
||||
|
||||
jQueryFunctionsCollection.sort().forEach(function(fnName, cnt) {
|
||||
if (fnName === 'jQuery - find') {
|
||||
fnName = 'jQuery - $';
|
||||
}
|
||||
metrics.jQueryFunctionsUsed ++;
|
||||
offenders.jQueryFunctionsUsed.push({
|
||||
functionName: fnName.substring(9),
|
||||
count: cnt
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
debug('JS execution transformation complete');
|
||||
|
||||
|
||||
debug('Starting scroll execution transformation');
|
||||
scrollExecutionTree = JSON.parse(data.toolsResults.phantomas.offenders.scrollExecutionTree[0]);
|
||||
if (scrollExecutionTree.children) {
|
||||
scrollExecutionTree.children.forEach(function(node) {
|
||||
offenders.scrollExecutionTree = JSON.parse(data.toolsResults.phantomas.offenders.scrollExecutionTree[0]);
|
||||
if (offenders.scrollExecutionTree.children) {
|
||||
offenders.scrollExecutionTree.children.forEach(function(node) {
|
||||
|
||||
// Mark a event flag
|
||||
if (['documentScroll', 'windowScroll', 'window.onscroll'].indexOf(node.data.type) >= 0) {
|
||||
@@ -109,9 +134,7 @@ var jsExecutionTransformer = function() {
|
||||
|
||||
data.toolsResults.jsExecutionTransformer = {
|
||||
metrics: metrics,
|
||||
offenders: {
|
||||
DOMaccessesOnScroll: scrollExecutionTree
|
||||
}
|
||||
offenders: offenders
|
||||
};
|
||||
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user