Skip to content

Instantly share code, notes, and snippets.

View divyamamgai's full-sized avatar
🎯
Focusing

Divya Mamgai divyamamgai

🎯
Focusing
View GitHub Profile
@divyamamgai
divyamamgai / createGraph.js
Created December 6, 2019 15:43
skope article generateGraph.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const graphviz = require('graphviz')
const FILE_PATH = path.join(__dirname, 'sample.js')
// For more info visit - https://www.graphviz.org/doc/info/attrs.html
const GRAPH_SETTINGS = {
// Removes curved lines.
@divyamamgai
divyamamgai / walkTree.js
Created December 5, 2019 17:17
skope article walkTree.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const acornWalk = require('acorn-walk')
const FILE_PATH = path.join(__dirname, 'sample.js')
const data = fs.readFileSync(FILE_PATH).toString()
const tree = acorn.Parser.parse(data)
@divyamamgai
divyamamgai / getDeclarations.js
Created December 5, 2019 17:13
skope article getDeclarations.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const acornWalk = require('acorn-walk')
const getName = require('../../src/utils/getName')
const getScope = require('../../src/utils/getScope')
const FILE_PATH = path.join(__dirname, 'sample.js')
@divyamamgai
divyamamgai / indirectVariableDeclarations.js
Created December 5, 2019 17:13
skope article indirectVariableDeclarations.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const acornWalk = require('acorn-walk')
const getName = require('../../src/utils/getName')
const getScope = require('../../src/utils/getScope')
const FILE_PATH = path.join(__dirname, 'sample.js')
@divyamamgai
divyamamgai / indirectVariableDeclarations.js
Created December 5, 2019 17:12
skope article indirectVariableDeclarations.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const acornWalk = require('acorn-walk')
const getName = require('../../src/utils/getName')
const getScope = require('../../src/utils/getScope')
const FILE_PATH = path.join(__dirname, 'sample.js')
@divyamamgai
divyamamgai / indirectWindowDeclarations.js
Created December 5, 2019 17:12
skope article indirectWindowDeclarations.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const acornWalk = require('acorn-walk')
const getName = require('../../src/utils/getName')
const FILE_PATH = path.join(__dirname, 'sample.js')
const data = fs.readFileSync(FILE_PATH).toString()
@divyamamgai
divyamamgai / getName.js
Created December 5, 2019 17:11
skope article getName.js
const getName = (node) => {
let name = ''
switch (node.type) {
case 'Identifier':
name = node.name
break
case 'MemberExpression':
name = `${getName(node.object)}.${getName(node.property)}`
break
@divyamamgai
divyamamgai / directDeclarations.js
Created December 5, 2019 17:10
skope article directDeclarations.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const acornWalk = require('acorn-walk')
const getScope = require('../../src/utils/getScope')
const FILE_PATH = path.join(__dirname, 'sample.js')
const data = fs.readFileSync(FILE_PATH).toString()
@divyamamgai
divyamamgai / getScope.js
Created December 5, 2019 17:09
skope article getScope.js
const getScope = (ancestors) => {
let ancestorIndex = ancestors.length - 1
while (ancestorIndex >= 0) {
const ancestor = ancestors[ancestorIndex]
switch (ancestor.type) {
case 'FunctionExpression':
case 'FunctionDeclaration':
case 'Program':
return ancestor
}
@divyamamgai
divyamamgai / generateTree.js
Created December 5, 2019 17:07
skope article generateTree.js
const fs = require('fs')
const path = require('path')
const acorn = require('acorn')
const FILE_PATH = path.join(__dirname, 'sample.js')
const data = fs.readFileSync(FILE_PATH).toString()
const tree = acorn.Parser.parse(data)
console.log(tree)