• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript falafel.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中falafel.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: simplify

export function simplify(javascript_str: string):string{
    var simplify_fn = function(node){
        node.precedence = 1000; //default precedence for all nodes other than operator nodes, e.g. terminals
        if(node.type == "BinaryExpression" || node.type == "BooleanExpression" || node.type == "LogicalExpression"){
            node.precedence = js_precedence(node.operator); //overwrite with actual precedence
            var LHS:any, RHS:any;
            if(node.left.precedence >= node.precedence){
                LHS = node.left.source(); //LHS is already strongly bound
            }else if(node.left.precedence < node.precedence){
                LHS = "("+node.left.source()+")"; //LHS is not strongly bound, boost with brackets
            }

            if(node.right.precedence == node.precedence && isCommunicativeUniquePrecedence(node.operator)){
                //special case for communicative operators
                RHS = node.right.source();
            }else if(node.right.precedence > node.precedence){
                //NOTE: > NOT >=
                RHS = node.right.source(); //RHS is already strongly bound
            }else if(node.right.precedence <= node.precedence){
                RHS = "("+node.right.source()+")"; //RHS is not strongly bound, boost with brackets
            }
            node.update(LHS + node.operator + RHS);
        }
    };

    return falafel(javascript_str.toString(), {}, simplify_fn).toString();
}
开发者ID:sheng168,项目名称:blaze_compiler,代码行数:27,代码来源:optimizer.ts


示例2: sanitizeQuotes

export function sanitizeQuotes(javascript_str: string) {
    var simplify_fn = function(node){
        if (node.type == "Literal") {
            //double quoted string needs to be changed to single quotes
            if (node.raw.indexOf('"') == 0) node.update("'" + escapeSingleQuotes(node.value) + "'")
        }
    };

    return falafel(javascript_str.toString(), {}, simplify_fn).toString();
}
开发者ID:Jiaaale,项目名称:blaze_compiler,代码行数:10,代码来源:optimizer.ts


示例3: parentIsObjectCheckRemoval

export function parentIsObjectCheckRemoval(javascript_str: string) {
    //if on the top level && we are checking to see if our parent is an object or null, we are doing a redundant check because
    //we can only write either null, a primitive or an object at newData location
    //therefore our parent  will flip only to null, or an object, thus we don't need to check for this pattern

    //((!newData.parent().parent().parent().parent().parent().exists()||newData.parent().parent().parent().parent().parent().hasChildren())
    var simplify_fn = function(node){
        //detect the above situation and rewrite
        if (node.type == 'LogicalExpression' && node.operator == '||') {
            var match = parent_pattern.exec(node.source());
            if (match != null && match[1] == match[2]) { //check the number of ".parent()" match between exists and hasChildren
                node.update("true")
            }
        }
    };

    return falafel(javascript_str.toString(), {}, simplify_fn).toString();

}
开发者ID:Jiaaale,项目名称:blaze_compiler,代码行数:19,代码来源:optimizer.ts


示例4: clauseRepetitionElimination

export function clauseRepetitionElimination(javascript_str: string): string {
    if (clauseRepetitionEliminationMemory[javascript_str]) return clauseRepetitionEliminationMemory[javascript_str];

    var simplify_fn = function(node){
        if(node.type == "LogicalExpression") {
            if (node.parent.type == "LogicalExpression" && node.parent.operator == node.operator) {
                //so the parent is part of the same group so we don't want to do the expensive optimization yet
            } else {
                //we are the top level logical expression, lets hunt for repetitions
                //the left pointer should be another logical expression
                //the right should be a single expression
                var operator = node.operator;
                var clauses = [];
                var logical = node;

                while (logical.type == "LogicalExpression" && logical.operator == operator) {
                    clauses.push(logical.right.source());
                    logical = logical.left;
                }
                clauses.push(logical.source()); //logical was the left of the previous seen logical expression
                var clauses = clauses.reverse(); //make the LHS first

                for (var primaryClause = 0; primaryClause < clauses.length; primaryClause++) {
                    for (var repeatClause = primaryClause + 1; repeatClause < clauses.length; repeatClause++) {
                        if (clauses[primaryClause] == clauses[repeatClause]) {
                            //secondaryClause repeats the primary clause, so delete it and adjust the indexing
                            clauses.splice(repeatClause,1);
                            repeatClause--; //adjustment for an element being removed during a loop
                        }
                    }
                }

                //now clauses should have no repeatitions and should be in the correct order LEFT to RIGHT
                node.update(simplify("((" + clauses.join(")" + operator + "(") + "))"))

            }
        }
    };

    var result =  falafel(javascript_str.toString(), {}, simplify_fn).toString();
    clauseRepetitionEliminationMemory[javascript_str] = result;
    return result;
}
开发者ID:RicardoSiebertG,项目名称:blaze_compiler,代码行数:43,代码来源:optimizer.ts


示例5: pruneBooleanLiterals

export function pruneBooleanLiterals(javascript_str: string): string {
    if (pruneBooleanLiteralsMemory[javascript_str]) return pruneBooleanLiteralsMemory[javascript_str];
    var simplify_fn = function(node){
        if (node.type == "UnaryExpression") {
            //!true => false
            if (node.operator == '!' && node.argument.type == 'Literal') {
                node.update(!node.argument.value)
            }
        } else if(node.type == "LogicalExpression") {
            //helper functions for querying literal arguments
            node.left.is  = function(val) {return node.left.type == 'Literal' && node.left.value == val;};
            node.right.is = function(val) {return node.right.type == 'Literal' && node.right.value == val;};

            if (node.operator == '&&' && node.left.is(true) && node.right.is(true)) {
                node.update("true")
            } else if (node.operator == '&&' && node.left.is(false)) {
                node.update("false")
            } else if (node.operator == '&&' && node.right.is(false)) {
                node.update("false")
            } else if (node.operator == '&&' && node.left.is(true)) {
                node.update("("+node.right.source() + ")")
            } else if (node.operator == '&&' && node.right.is(true)) {
                node.update("("+node.left.source() + ")")
            } else if (node.operator == '||' && node.left.is(false) && node.right.is(false)) {
                node.update("false")
            } else if (node.operator == '||' && node.left.is(true)) {
                node.update("true")
            } else if (node.operator == '||' && node.right.is(true)) {
                node.update("true")
            } else if (node.operator == '||' && node.left.is(false)) {
                node.update("("+node.right.source() + ")")
            } else if (node.operator == '||' && node.right.is(false)) {
                node.update("("+node.left.source() + ")")
            }
        }
    };

    var result = falafel(javascript_str.toString(), {}, simplify_fn).toString();
    pruneBooleanLiteralsMemory[javascript_str] = result;
    return result;
}
开发者ID:RicardoSiebertG,项目名称:blaze_compiler,代码行数:41,代码来源:optimizer.ts


示例6: childParentAnnihilation

export function childParentAnnihilation(javascript_str: string): string {

/*
data.child('x').parent().val()
AST expansion looks like:-

{
    "type": "Program",
    "body": [
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "CallExpression",
                "callee": {
                    "type": "MemberExpression",  <--- start hunting here
                    "computed": false,
                    "object": {
                        "type": "CallExpression", <---- () of parent, this will be removed
                        "callee": {
                            "type": "MemberExpression",
                            "computed": false,
                            "object": {
                                "type": "CallExpression",
                                "callee": {
                                    "type": "MemberExpression",
                                    "computed": false,
                                    "object": { <--- kept
                                        "type": "Identifier",
                                        "name": "data"
                                    },
                                    "property": {
                                        "type": "Identifier",
                                        "name": "child"
                                    }
                                },
                                "arguments": [ <---- irrelavant
                                    {
                                        "type": "Literal",
                                        "value": "x",
                                        "raw": "'x'"
                                    }
                                ]
                            },
                            "property": {
                                "type": "Identifier",
                                "name": "parent"
                            }
                        },
                        "arguments": []
                    },
                    "property": {
                        "type": "Identifier",
                        "name": "val"
                    }
                },
                "arguments": []
            }
        }
    ]
}
*/
    var simplify_fn = function(node){
        //detect the above situation and rewrite
        if (node.type == 'MemberExpression' &&
            node.object.type == 'CallExpression' &&
            node.object.arguments.length == 0 &&
            node.object.callee.type == 'MemberExpression' &&
            node.object.callee.property.type == 'Identifier' &&
            node.object.callee.property.name == 'parent' &&
            node.object.callee.object.type == 'CallExpression' &&
            node.object.callee.object.callee.type == 'MemberExpression' &&
            node.object.callee.object.callee.property.type == 'Identifier' &&
            node.object.callee.object.callee.property.name == 'child') {

            //rewrite node
            node.object.update(node.object.callee.object.callee.object.source())
        }
    };

    return falafel(javascript_str.toString(), {}, simplify_fn).toString();
}
开发者ID:Jiaaale,项目名称:blaze_compiler,代码行数:81,代码来源:optimizer.ts



注:本文中的falafel.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript falcor-express.dataSourceRoute函数代码示例发布时间:2022-05-25
下一篇:
TypeScript faker.system类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap