本文整理汇总了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;未经允许,请勿转载。 |
请发表评论