-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfind-platform-module-LOC.js
More file actions
31 lines (30 loc) · 1.18 KB
/
find-platform-module-LOC.js
File metadata and controls
31 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const fs = require('fs');
const babylon = require('babylon');
const traverse = require('babel-traverse').default;
let platformModuleLOCTotal = 0;
process.argv.slice(2).forEach((filePath) => {
const data = fs.readFileSync(filePath, {encoding: 'utf8'});
traverse(
babylon.parse(data, {sourceType: 'module', plugins: ['jsx', 'flow', 'objectRestSpread', 'classProperties']}),
{
ImportDeclaration(path, state) {
if(path.get('source').node.value === 'react-native') {
path.get('specifiers').forEach(function(specifier) {
if(specifier.node.imported) {
const importedIdentifierName = specifier.node.imported.name;
if(importedIdentifierName === 'Platform') {
const platformModuleLOC = new Set();
const {referencePaths} = path.scope.getBinding(importedIdentifierName);
referencePaths.forEach(function(referencePath) {
platformModuleLOC.add(referencePath.node.loc.start.line);
});
platformModuleLOCTotal += platformModuleLOC.size;
}
}
});
}
}
}
);
});
console.log(platformModuleLOCTotal);