CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
README.md154 linesDownload Raw Back to estraverse
1### Estraverse [![Build Status](https://secure.travis-ci.org/estools/estraverse.svg)](http://travis-ci.org/estools/estraverse)2 3Estraverse ([estraverse](http://github.com/estools/estraverse)) is4[ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)5traversal functions from [esmangle project](http://github.com/estools/esmangle).6 7### Documentation8 9You can find usage docs at [wiki page](https://github.com/estools/estraverse/wiki/Usage).10 11### Example Usage12 13The following code will output all variables declared at the root of a file.14 15```javascript16estraverse.traverse(ast, {17    enter: function (node, parent) {18        if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')19            return estraverse.VisitorOption.Skip;20    },21    leave: function (node, parent) {22        if (node.type == 'VariableDeclarator')23          console.log(node.id.name);24    }25});26```27 28We can use `this.skip`, `this.remove` and `this.break` functions instead of using Skip, Remove and Break.29 30```javascript31estraverse.traverse(ast, {32    enter: function (node) {33        this.break();34    }35});36```37 38And estraverse provides `estraverse.replace` function. When returning node from `enter`/`leave`, current node is replaced with it.39 40```javascript41result = estraverse.replace(tree, {42    enter: function (node) {43        // Replace it with replaced.44        if (node.type === 'Literal')45            return replaced;46    }47});48```49 50By passing `visitor.keys` mapping, we can extend estraverse traversing functionality.51 52```javascript53// This tree contains a user-defined `TestExpression` node.54var tree = {55    type: 'TestExpression',56 57    // This 'argument' is the property containing the other **node**.58    argument: {59        type: 'Literal',60        value: 2061    },62 63    // This 'extended' is the property not containing the other **node**.64    extended: true65};66estraverse.traverse(tree, {67    enter: function (node) { },68 69    // Extending the existing traversing rules.70    keys: {71        // TargetNodeName: [ 'keys', 'containing', 'the', 'other', '**node**' ]72        TestExpression: ['argument']73    }74});75```76 77By passing `visitor.fallback` option, we can control the behavior when encountering unknown nodes.78 79```javascript80// This tree contains a user-defined `TestExpression` node.81var tree = {82    type: 'TestExpression',83 84    // This 'argument' is the property containing the other **node**.85    argument: {86        type: 'Literal',87        value: 2088    },89 90    // This 'extended' is the property not containing the other **node**.91    extended: true92};93estraverse.traverse(tree, {94    enter: function (node) { },95 96    // Iterating the child **nodes** of unknown nodes.97    fallback: 'iteration'98});99```100 101When `visitor.fallback` is a function, we can determine which keys to visit on each node.102 103```javascript104// This tree contains a user-defined `TestExpression` node.105var tree = {106    type: 'TestExpression',107 108    // This 'argument' is the property containing the other **node**.109    argument: {110        type: 'Literal',111        value: 20112    },113 114    // This 'extended' is the property not containing the other **node**.115    extended: true116};117estraverse.traverse(tree, {118    enter: function (node) { },119 120    // Skip the `argument` property of each node121    fallback: function(node) {122        return Object.keys(node).filter(function(key) {123            return key !== 'argument';124        });125    }126});127```128 129### License130 131Copyright (C) 2012-2016 [Yusuke Suzuki](http://github.com/Constellation)132 (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.133 134Redistribution and use in source and binary forms, with or without135modification, are permitted provided that the following conditions are met:136 137  * Redistributions of source code must retain the above copyright138    notice, this list of conditions and the following disclaimer.139 140  * Redistributions in binary form must reproduce the above copyright141    notice, this list of conditions and the following disclaimer in the142    documentation and/or other materials provided with the distribution.143 144THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"145AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE146IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE147ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY148DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES149(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;150LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND151ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT152(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF153THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.154 
basant307/AI_Governance_Project · CoolFace