h2x-traverse
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -17,2 +17,3 @@ 'use strict'; | ||
function traverse(ast, opts = {}, state = {}) { | ||
if (!ast) return; | ||
const keys = (0, _h2xTypes.getNodeVisitorKeys)(ast); | ||
@@ -22,4 +23,25 @@ if (!keys) return; | ||
const context = new _TraversalContext2.default({ opts, state }); | ||
for (const key of keys) { | ||
if (context.visit(ast, key)) return; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const key = _step.value; | ||
if (context.visit(ast, key)) return; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -26,0 +48,0 @@ } |
@@ -70,2 +70,8 @@ 'use strict'; | ||
remove() { | ||
this.shouldStop = true; | ||
this.node = null; | ||
this.container[this.key] = null; | ||
} | ||
_call(fns) { | ||
@@ -75,13 +81,34 @@ if (!fns) return false; | ||
for (const fn of fns) { | ||
if (!fn) continue; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
// Node has been removed, it will have been requeued | ||
const node = this.node; | ||
try { | ||
for (var _iterator = fns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const fn = _step.value; | ||
const ret = fn(this, this.state); | ||
if (ret) throw new Error(`Unexpected return value from visitor method ${fn}`); | ||
if (!fn) continue; | ||
// node has been replaced, it will have been requeued | ||
if (this.node !== node) return true; | ||
const node = this.node; | ||
if (!node) return true; | ||
const ret = fn(this, this.state); | ||
if (ret) throw new Error(`Unexpected return value from visitor method ${fn}`); | ||
// node has been replaced, it will have been requeued | ||
if (this.node !== node) return true; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -88,0 +115,0 @@ |
@@ -31,6 +31,8 @@ 'use strict'; | ||
let shouldStop = false; | ||
for (let key = 0; key < container.length; key += 1) { | ||
Array.from(container).forEach((value, key) => { | ||
if (!value) return; | ||
const nodePath = this.create(parent, container, key, listKey); | ||
if (nodePath && nodePath.visit()) shouldStop = true; | ||
} | ||
}); | ||
@@ -37,0 +39,0 @@ return shouldStop; |
{ | ||
"name": "h2x-traverse", | ||
"description": "Traverse and modify h2x AST.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"repository": "https://github.com/smooth-code/h2x/tree/master/packages/h2x-traverse", | ||
@@ -6,0 +6,0 @@ "author": "Bergé Greg <berge.greg@gmail.com>", |
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
5764
172