Skip to content

Instantly share code, notes, and snippets.

View juanpicado's full-sized avatar
🌴
holidays

Juan Picado juanpicado

🌴
holidays
View GitHub Profile
@juanpicado
juanpicado / scope.js
Created March 20, 2016 17:24
Esprima and Escope
var escope = require('escope');
var esprima = require('esprima');
var estraverse = require('estraverse');
var code = require('./ast');
var ast = code.esprimaAST();
var scopeManager = escope.analyze(ast);
var scopes = scopeManager.scopes;
// return an array of scopes, in our example we have 2, the global and inside of the function
var currentScope = scopeManager.acquire(ast);
// return the global scope, the current one
@juanpicado
juanpicado / estraverse.js
Last active March 20, 2016 16:58
Estraverse example
var estraverse = require('estraverse');
var escodegen = require('escodegen');
var ast = require('./ast');
var a = ast.esprimaAST();
// 'function bar(){ var longVariable; console.log("foo", longVariable);}'
estraverse.traverse(a, {
enter: function (node, parent) {
if (node.type == 'Identifier' && node.name == 'longVariable') {
console.log(node);
node.name = 'b';
@juanpicado
juanpicado / escodegen.js
Last active March 20, 2016 17:05
escodegen.js
var escodegen = require('escodegen');
var js = escodegen.generate({
"type": "VariableDeclaration",
"start": 0,
"end": 6,
"range": [
0,
6
],
"declarations": [
// esprima
var ast = esprima.parse("var foo = 'bar';");
// acorn
var ast = acorn.parse('var a;', {
// collect ranges for each node
ranges: true
});
@juanpicado
juanpicado / esprima.test.js
Last active March 19, 2016 23:31
Esprima example
var ast = esprima.parse("var a;");
@juanpicado
juanpicado / pom.xml
Created August 8, 2015 17:46
grunt and maven
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.23</version>
<configuration>
<workingDirectory>src/main/resources/resource</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
@juanpicado
juanpicado / gruntFile.js
Created August 8, 2015 17:38
less and grunt
less: {
development: {
options: {
compress: false,
yuicompress: false,
//sourceMap : true,
optimization: 1
},
files: {
"<%= dirs.css_src %>/tweetpoll.css": "<%= dirs.less_src %>/tweetpoll.less",
@juanpicado
juanpicado / javascript
Created August 8, 2015 17:37
intern grunt task
intern: {
local_browser: {
options: {
runType: 'runner',
config: '<%= dirs.tests %>/intern_local_browser'
}
},
remote_local: {
options: {
runType: 'runner',
@juanpicado
juanpicado / json
Last active August 29, 2015 14:26
bower.json
{
"name": "resources-enme-war",
"version": "1.5.2",
"homepage": "https://github.com/encuestame/encuestame",
"authors": [
"Juan Picado (@jotadeveloper) <[email protected]>"
],
"license": "APL2",
"ignore": [
"**/.*",
@juanpicado
juanpicado / ast.js
Created July 29, 2015 05:58
Estraverse example
var fs = require('fs');
var esprima = require('esprima');
var escodegen = require('escodegen');
var estraverse = require('estraverse');
fs.readFile('test_1.js', 'utf8', function(err, contents) {
var ast = esprima.parse(contents);
estraverse.replace(ast, {
enter : function (node, parent) {
if (node.type === 'Property' && node.key.name.indexOf('jota') != -1) {
this.remove();