estraverse-fb
Advanced tools
Comparing version 1.0.0 to 1.1.0
var estraverse = module.exports = require('estraverse'); | ||
var VisitorKeys = { | ||
XJSIdentifier: [], | ||
XJSNamespacedName: ['namespace', 'name'], | ||
XJSMemberExpression: ['object', 'property'], | ||
XJSEmptyExpression: [], | ||
XJSExpressionContainer: ['expression'], | ||
XJSElement: ['openingElement', 'closingElement', 'children'], | ||
XJSClosingElement: ['name'], | ||
XJSOpeningElement: ['name', 'attributes'], | ||
XJSAttribute: ['name', 'value'], | ||
XJSText: null | ||
}; | ||
var VisitorKeys = require('./keys'); | ||
@@ -16,0 +5,0 @@ for (var nodeType in VisitorKeys) { |
{ | ||
"name": "estraverse-fb", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Drop-in for estraverse that enables traversal over React's JSX nodes.", | ||
@@ -18,10 +18,11 @@ "main": "estraverse-fb.js", | ||
}, | ||
"dependencies": { | ||
"estraverse": "^1.5.0" | ||
"peerDependencies": { | ||
"estraverse": "^1.7.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"esprima-fb": "git+https://github.com/RReverser/esprima-fb.git#fb-harmony", | ||
"esprima-fb": "^8001.1001.0-dev-harmony-fb", | ||
"estraverse": "^1.7.0", | ||
"mocha": "^1.20.0" | ||
} | ||
} |
@@ -6,2 +6,29 @@ estraverse-fb | ||
Check out [estraverse page](https://github.com/Constellation/estraverse) for documentation. | ||
You can use estraverse-fb in two possible ways: | ||
* by default, you just require it and it injects needed keys into your installed version of estraverse (it's installed automatically if you don't have it yet): | ||
```javascript | ||
var estraverse = require('estraverse-fb'); | ||
/* same as: | ||
require('estraverse-fb'); | ||
var estraverse = require('estraverse'); | ||
*/ | ||
estraverse.traverse(ast, { | ||
enter: ..., | ||
leave: ... | ||
}); | ||
``` | ||
* alternatively, you can use it manually for selected traversals: | ||
```javascript | ||
var jsxKeys = require('estraverse-fb/keys'); | ||
estraverse.traverse(ast, { | ||
enter: ..., | ||
leave: ..., | ||
keys: jsxKeys | ||
}) | ||
``` | ||
Check out [estraverse page](https://github.com/Constellation/estraverse) for detailed usage. |
74
test.js
var assert = require('chai').assert; | ||
var parse = require('esprima-fb').parse; | ||
var traverse = require('./').traverse; | ||
it('test', function () { | ||
describe('works', function () { | ||
var code = '<namespace:tag textAttr="value" exprAttr={expr}><object.prop>!</object.prop>{}</namespace:tag>'; | ||
var ast = parse(code); | ||
var actualKeys = []; | ||
traverse(ast, { | ||
enter: function (node) { | ||
if (node.type.slice(0, 3) === 'XJS') { | ||
actualKeys.push(node.type); | ||
} | ||
} | ||
}); | ||
var expectedKeys = [ | ||
@@ -47,3 +36,62 @@ 'XJSElement', | ||
assert.deepEqual(actualKeys, expectedKeys); | ||
beforeEach(function () { | ||
for (var key in require.cache) { | ||
delete require.cache[key]; | ||
} | ||
}); | ||
it('directly from dependency', function () { | ||
var traverse = require('./').traverse; | ||
var actualKeys = []; | ||
traverse(ast, { | ||
enter: function (node) { | ||
if (node.type.slice(0, 3) === 'XJS') { | ||
actualKeys.push(node.type); | ||
} | ||
} | ||
}); | ||
assert.deepEqual(actualKeys, expectedKeys); | ||
}); | ||
it('in injected mode', function () { | ||
require('./'); | ||
var traverse = require('estraverse').traverse; | ||
var actualKeys = []; | ||
traverse(ast, { | ||
enter: function (node) { | ||
if (node.type.slice(0, 3) === 'XJS') { | ||
actualKeys.push(node.type); | ||
} | ||
} | ||
}); | ||
assert.deepEqual(actualKeys, expectedKeys); | ||
}); | ||
it('in single-pass mode', function () { | ||
var traverse = require('estraverse').traverse; | ||
var keys = require('./keys'); | ||
var actualKeys = []; | ||
traverse(ast, { | ||
enter: function (node) { | ||
if (node.type.slice(0, 3) === 'XJS') { | ||
actualKeys.push(node.type); | ||
} | ||
}, | ||
keys: keys | ||
}); | ||
assert.throws(function () { | ||
traverse(ast, { | ||
enter: function () {} | ||
}); | ||
}); | ||
assert.deepEqual(actualKeys, expectedKeys); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5840
8
100
33
4
- Removedestraverse@^1.5.0