Created
January 30, 2015 16:05
-
-
Save cevek/673f52e144a4736f1940 to your computer and use it in GitHub Desktop.
atom name
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
var name = ''; | |
if (node.expression.text === 'Atom'){ | |
var exps = []; | |
var n = node; | |
var ns = []; | |
var isReturn = false; | |
var isThis = false; | |
var ex = false; | |
while (n = n.parent){ | |
if (n.name && n.kind !== 128){ | |
ns.push(n.name.text); | |
} | |
if (isReturn && (n.kind == 128)){ | |
exps.push(n.name.text); | |
} | |
if (n.kind == 180){ | |
isReturn = true; | |
ex = true; | |
} | |
if (n.left && !ex){ | |
ex = true; | |
var exp = n.left; | |
do { | |
if (exp.argumentExpression){ | |
exps.push('[]'); | |
} | |
if (exp.text) { | |
exps.push(exp.text); | |
} | |
if (exp.name) { | |
exps.push(exp.name.text); | |
} | |
if (exp.kind == 92){ | |
isThis = true; | |
} | |
} | |
while (exp = exp.expression); | |
} | |
} | |
ns = ns.reverse().join("."); | |
exps = exps.reverse().join(".").replace(/\.\[\]/g, '[]'); | |
//console.log("ns", ns); | |
//console.log("exps", exps); | |
//console.log("isThis", isThis); | |
name = ", '" + ns + (ns && exps ? (isThis ? '.' : ':') : '') + exps + "'"; | |
var cache = []; | |
var json = JSON.stringify(node, function(key, value) { | |
if (typeof value === 'object' && value !== null) { | |
if (cache.indexOf(value) !== -1) { | |
// Circular reference found, discard key | |
return '[circular '+ (value.id ? value.id : '') +']'; | |
} | |
// Store value in our collection | |
cache.push(value); | |
} | |
if (typeof value == 'object' && value && value.kind){ | |
value._kind = value.kind; | |
} | |
return value; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment