Skip to content

Instantly share code, notes, and snippets.

@mrchief
Created October 14, 2013 05:00
Show Gist options
  • Save mrchief/6970995 to your computer and use it in GitHub Desktop.
Save mrchief/6970995 to your computer and use it in GitHub Desktop.
body {
padding: 0;
margin: 0;
}
.wrapper {
width: 100%;
margin: 0 auto;
}
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<meta charset=utf-8 />
<title>Welcome to JS Bin</title>
<meta name="viewport" content="width=device-width">
<link href='http://fonts.googleapis.com/css?family=Doppio+One' rel='stylesheet' type='text/css'>
</head>
<body>
<pre class="wrapper">
</pre>
</body>
</html>
var doc = {
"type": "Program",
"body": [{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "define"
},
"arguments": [{
"type": "Literal",
"value": "djx.vendor.resources/backbone",
"raw": "'djx.vendor.resources/backbone'"
}, {
"type": "ArrayExpression",
"elements": [{
"type": "Literal",
"value": "djx.vendor.resources/jquery",
"raw": "'djx.vendor.resources/jquery'"
}, {
"type": "Literal",
"value": "djx.vendor.resources/underscore",
"raw": "'djx.vendor.resources/underscore'"
}]
}, {
"type": "FunctionExpression",
"id": null,
"params": [{
"type": "Identifier",
"name": "$"
}, {
"type": "Identifier",
"name": "_"
}],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": []
},
"rest": null,
"generator": false,
"expression": false
}]
}
}]
};
function evaluate() {
var ret = doc.body.filter(function(x) {
return x.type === 'ExpressionStatement' && x.expression.type === 'CallExpression' && x.expression.callee.name === 'define';
}).map(function(x) {
//console.log('args:', x.expression['arguments']);
var id, deps = [];
x.expression['arguments'].forEach(function(y) {
//console.log('y:', y);
if (y.type === 'Literal') {
id = y.value;
return;
};
if (y.type === 'ArrayExpression') {
deps = y.elements.map(function(z) {
return z.value.split('/')[0];
});
return;
}
});
return {
id: id,
deps: deps
};
});
console.log(ret);
}
evaluate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment