How to use the uglify-js-papandreou.TreeWalker function in uglify-js-papandreou

To help you get started, we’ve selected a few uglify-js-papandreou examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assetgraph / assetgraph / lib / assets / JavaScript.js View on Github external
if (node instanceof uglifyJs.AST_Constant) {
                return node;
            } else {
                var foldedNode = uglifyAst.foldConstant(node);
                if (foldedNode instanceof uglifyJs.AST_String) {
                    this.markDirty();
                    return foldedNode;
                } else {
                    return node;
                }
            }
        }.bind(this);

        var seenComments = [];

        var walker = new uglifyJs.TreeWalker(function (node, descend) {
            var stack = walker.stack,
                parentNode = walker.parent();
            [node.start, node.end].forEach(function (token) {
                if (token && token.comments_before) {
                    token.comments_before.forEach(function (comment) {
                        var matchSourceUrlOrSourceMappingUrl = comment.value.match(/[@#]\s*source(Mapping)?URL=([^\s\n]*)/);
                        if (matchSourceUrlOrSourceMappingUrl && seenComments.indexOf(comment) === -1) {
                            if (matchSourceUrlOrSourceMappingUrl[1] === 'Mapping') {
                                outgoingRelations.push(new AssetGraph.JavaScriptSourceMappingUrl({
                                    from: this,
                                    node: comment,
                                    to: {
                                        url: matchSourceUrlOrSourceMappingUrl[2],
                                        // Source maps are currently served as application/json, so prevent the target asset
                                        // from being loaded as a Json asset:
                                        type: 'SourceMap'
github assetgraph / assetgraph / lib / assets / JavaScript.js View on Github external
if (parseTree.end && parseTree.end.comments_before && !parseTree.end._comments_dumped) {
                    parseTree.end.comments_before.forEach(function (comment) {
                        if (this.isPretty || shouldCommentNodeBePreservedInNonPrettyPrintedOutput(parseTree.end, comment)) {
                            if (comment.type === 'comment1') {
                                text += '//' + comment.value + '\n';
                            } else if (comment.type === 'comment2') {
                                text += '/*' + comment.value + '*/';
                            }
                        }
                    }, this);
                }

                this._text = text;

                // Temporary workaround for https://github.com/mishoo/UglifyJS2/issues/218
                parseTree.walk(new uglifyJs.TreeWalker(function (node) {
                    if (node.start) {
                        node.start._comments_dumped = false;
                    }
                    if (node.end) {
                        node.end._comments_dumped = false;
                    }
                }));
            } else {
                this._text = this._getTextFromRawSrc();
            }
        }
        return this._text;
    },
github assetgraph / assetgraph / lib / assets / JavaScript.js View on Github external
isSucceededByDefineWithStringArg = true;
                            }
                        };
                    OUTER:
                    while (parentIndex >= 0) {
                        if (stack[parentIndex] instanceof uglifyJs.AST_Block) {
                            var blockNode = stack[parentIndex];
                            for (var i = blockNode.body.indexOf(stack[parentIndex + 1]) ; i < blockNode.body.length ; i += 1) {
                                if (blockNode.body[i] instanceof uglifyJs.AST_SimpleStatement && isNamedDefineNode(blockNode.body[i].body)) {
                                    isSucceededByDefineWithStringArg = true;
                                    break OUTER;
                                }
                            }
                            break OUTER;
                        } else if (stack[parentIndex] instanceof uglifyJs.AST_Seq) {
                            stack[parentIndex].walk(new uglifyJs.TreeWalker(walkFn));
                            break OUTER;
                        } else {
                            parentIndex -= 1;
                        }
                    }

                    if (!isSucceededByDefineWithStringArg) {
                        var arrayNode = node.args[0];
                        arrayNode.elements.forEach(function (arrayItemAst, i) {
                            arrayItemAst = arrayNode.elements[i] = tryFoldConstantToString(arrayItemAst);
                            if (arrayItemAst instanceof uglifyJs.AST_String) {
                                if (['require', 'exports', 'module'].indexOf(arrayItemAst.value) === -1) {
                                    outgoingRelations.push(new AssetGraph.JavaScriptAmdRequire({
                                        from: this,
                                        callNode: node,
                                        arrayNode: arrayNode,
github assetgraph / assetgraph / lib / assets / JavaScript.js View on Github external
var diveIntoAngularMethodCall = function (argumentNodes, templateCacheVariableName) {
                        var angularWalker = new uglifyJs.TreeWalker(function (node) {
                            var parentNode = angularWalker.parent();
                            if (node instanceof uglifyJs.AST_Object) {
                                node.properties.forEach(function (keyValue) {
                                    if (keyValue.key === 'templateUrl' && keyValue.value instanceof uglifyJs.AST_String) {
                                        outgoingRelations.push(new AssetGraph.JavaScriptAngularJsTemplate({
                                            from: this,
                                            to: {
                                                type: 'Html',
                                                url: keyValue.value.value
                                            },
                                            node: keyValue,
                                            parentNode: node
                                        }));
                                    } else if (keyValue.key === 'template' && keyValue.value instanceof uglifyJs.AST_String) {
                                        outgoingRelations.push(new AssetGraph.JavaScriptAngularJsTemplate({
                                            from: this,