This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getName = (node) => { | |
let name = '' | |
switch (node.type) { | |
case 'Identifier': | |
name = node.name | |
break | |
case 'MemberExpression': | |
name = `${getName(node.object)}.${getName(node.property)}` | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder