本文整理汇总了TypeScript中lodash-es/map.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: generateGlsl
function generateGlsl(codeAst: ICodeAst, tables: ISymbolTables, glslFuncs: string[]): string {
const generateNode = (ast) => {
if (ast instanceof Ast.BinaryExpr) {
return "(" + generateNode(ast.leftOperand) + ast.operator + generateNode(ast.rightOperand) + ")";
}
if (ast instanceof Ast.UnaryExpr) {
return "(" + ast.operator + generateNode(ast.operand) + ")";
}
if (ast instanceof Ast.FuncCall) {
if (ast.preComputeUniformName) {
return "(" + ast.preComputeUniformName + ")";
}
switch (ast.funcName) {
case "above":
return [
"(",
generateNode(ast.args[0]),
">",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "below":
return [
"(",
generateNode(ast.args[0]),
"<",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "equal":
return [
"(",
generateNode(ast.args[0]),
"==",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "if":
return [
"(",
generateNode(ast.args[0]),
"!=0.0?",
generateNode(ast.args[1]),
":",
generateNode(ast.args[2]),
")",
].join("");
case "select": {
const selectExpr = generateNode(ast.args[0]);
const generateSelect = (args, i) => {
if (args.length === 1) {
return generateNode(args[0]);
} else {
return [
"((" + selectExpr + " === " + i + ")?",
"(" + generateNode(args[0]) + "):",
"(" + generateSelect(takeRight(args, args.length - 1), i + 1) + "))",
].join("");
}
};
return generateSelect(takeRight(ast.args, ast.args.length - 1), 0);
}
case "sqr":
return "(pow((" + generateNode(ast.args[0]) + "), 2))";
case "band":
return "(float((" + generateNode(ast.args[0]) + ")&&(" + generateNode(ast.args[1]) + ")))";
case "bor":
return "(float((" + generateNode(ast.args[0]) + ")||(" + generateNode(ast.args[1]) + ")))";
case "bnot":
return "(float(!(" + generateNode(ast.args[0]) + ")))";
case "invsqrt":
return "(inversesqrt(" + generateNode(ast.args[0]) + "))";
case "atan2":
return "(atan((" + generateNode(ast.args[0]) + "),(" + generateNode(ast.args[1]) + "))";
default: {
const args = map(ast.args, (arg) => generateNode(arg)).join(",");
return "(" + ast.funcName + "(" + args + "))";
}
}
}
if (ast instanceof Ast.Assignment) {
return generateNode(ast.lhs) + "=" + generateNode(ast.expr);
}
if (ast instanceof Ast.Program) {
const stmts = map(ast.statements, (stmt) => generateNode(stmt));
return stmts.join(";\n") + ";";
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "VALUE") {
return glslFloatRepr(ast.value);
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "CONST") {
return translateConstants(ast.value).toString();
}
if (ast instanceof Ast.PrimaryExpr && (ast.type === "ID" || ast.type === "REG")) {
return ast.value;
}
};
let glslCode = [];
//.........这里部分代码省略.........
开发者ID:azeem,项目名称:webvs,代码行数:101,代码来源:compileExpr.ts
示例2: generateNode
const generateNode = (ast) => {
if (ast instanceof Ast.BinaryExpr) {
return "(" + generateNode(ast.leftOperand) + ast.operator + generateNode(ast.rightOperand) + ")";
}
if (ast instanceof Ast.UnaryExpr) {
return "(" + ast.operator + generateNode(ast.operand) + ")";
}
if (ast instanceof Ast.FuncCall) {
switch (ast.funcName) {
case "above":
return [
"(",
generateNode(ast.args[0]),
">",
generateNode(ast.args[1]),
"?1:0)",
].join("");
case "below":
return [
"(",
generateNode(ast.args[0]),
"<",
generateNode(ast.args[1]),
"?1:0)",
].join("");
case "equal":
return [
"(",
generateNode(ast.args[0]),
"==",
generateNode(ast.args[1]),
"?1:0)",
].join("");
case "if":
return [
"(",
generateNode(ast.args[0]),
"!==0?",
generateNode(ast.args[1]),
":",
generateNode(ast.args[2]),
")",
].join("");
case "select":
const code = ["((function() {"];
code.push("switch(" + generateNode(ast.args[0]) + ") {");
each(takeRight(ast.args, ast.args.length - 1), (arg, i) => {
code.push("case " + i + ": return " + generateNode(arg) + ";");
});
code.push("default : throw new Error('Unknown selector value in select');");
code.push("}}).call(this))");
return code.join("");
case "sqr":
return "(Math.pow((" + generateNode(ast.args[0]) + "),2))";
case "band":
return "(((" + generateNode(ast.args[0]) + ")&&(" + generateNode(ast.args[1]) + "))?1:0)";
case "bor":
return "(((" + generateNode(ast.args[0]) + ")||(" + generateNode(ast.args[1]) + "))?1:0)";
case "bnot":
return "((!(" + generateNode(ast.args[0]) + "))?1:0)";
case "invsqrt":
return "(1/Math.sqrt(" + generateNode(ast.args[0]) + "))";
case "atan2":
return "(Math.atan((" + generateNode(ast.args[0]) + ")/(" + generateNode(ast.args[1]) + ")))";
default:
let prefix;
const args = map(ast.args, (arg) => generateNode(arg)).join(",");
if (jsMathFuncs.indexOf(ast.funcName) >= 0) {
prefix = "Math.";
} else {
prefix = "this.";
}
return "(" + prefix + ast.funcName + "(" + args + "))";
}
}
if (ast instanceof Ast.Assignment) {
return generateNode(ast.lhs) + "=" + generateNode(ast.expr);
}
if (ast instanceof Ast.Program) {
const stmts = map(ast.statements, (stmt) => generateNode(stmt));
return stmts.join(";\n");
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "VALUE") {
return ast.value.toString();
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "CONST") {
return translateConstants(ast.value).toString();
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "ID") {
return "this." + ast.value;
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "REG") {
return "this.registerBank[\"" + ast.value + "\"]";
}
};
开发者ID:azeem,项目名称:webvs,代码行数:95,代码来源:compileExpr.ts
示例3: generateNode
const generateNode = (ast) => {
if (ast instanceof Ast.BinaryExpr) {
return "(" + generateNode(ast.leftOperand) + ast.operator + generateNode(ast.rightOperand) + ")";
}
if (ast instanceof Ast.UnaryExpr) {
return "(" + ast.operator + generateNode(ast.operand) + ")";
}
if (ast instanceof Ast.FuncCall) {
if (ast.preComputeUniformName) {
return "(" + ast.preComputeUniformName + ")";
}
switch (ast.funcName) {
case "above":
return [
"(",
generateNode(ast.args[0]),
">",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "below":
return [
"(",
generateNode(ast.args[0]),
"<",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "equal":
return [
"(",
generateNode(ast.args[0]),
"==",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "if":
return [
"(",
generateNode(ast.args[0]),
"!=0.0?",
generateNode(ast.args[1]),
":",
generateNode(ast.args[2]),
")",
].join("");
case "select": {
const selectExpr = generateNode(ast.args[0]);
const generateSelect = (args, i) => {
if (args.length === 1) {
return generateNode(args[0]);
} else {
return [
"((" + selectExpr + " === " + i + ")?",
"(" + generateNode(args[0]) + "):",
"(" + generateSelect(takeRight(args, args.length - 1), i + 1) + "))",
].join("");
}
};
return generateSelect(takeRight(ast.args, ast.args.length - 1), 0);
}
case "sqr":
return "(pow((" + generateNode(ast.args[0]) + "), 2))";
case "band":
return "(float((" + generateNode(ast.args[0]) + ")&&(" + generateNode(ast.args[1]) + ")))";
case "bor":
return "(float((" + generateNode(ast.args[0]) + ")||(" + generateNode(ast.args[1]) + ")))";
case "bnot":
return "(float(!(" + generateNode(ast.args[0]) + ")))";
case "invsqrt":
return "(1/sqrt(" + generateNode(ast.args[0]) + "))";
case "atan2":
return "(atan((" + generateNode(ast.args[0]) + "),(" + generateNode(ast.args[1]) + "))";
default: {
const args = map(ast.args, (arg) => generateNode(arg)).join(",");
return "(" + ast.funcName + "(" + args + "))";
}
}
}
if (ast instanceof Ast.Assignment) {
return generateNode(ast.lhs) + "=" + generateNode(ast.expr);
}
if (ast instanceof Ast.Program) {
const stmts = map(ast.statements, (stmt) => generateNode(stmt));
return stmts.join(";\n") + ";";
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "VALUE") {
return glslFloatRepr(ast.value);
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "CONST") {
return translateConstants(ast.value).toString();
}
if (ast instanceof Ast.PrimaryExpr && (ast.type === "ID" || ast.type === "REG")) {
return ast.value;
}
};
开发者ID:idleberg,项目名称:webvs,代码行数:96,代码来源:compileExpr.ts
示例4: parseColorNorm
export function parseColorNorm(color: string | Color): Color {
return map(parseColor(color), (value) => value / 255) as Color;
}
开发者ID:azeem,项目名称:webvs,代码行数:3,代码来源:utils.ts
示例5: createChoiceViewModels
export function createChoiceViewModels(id: string, searchTerm: string, choices: Dictionary<Ro.Value>) {
return Promise.resolve(map(choices, (v, k) => new ChoiceViewModel(v, id, k, searchTerm)));
}
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:3,代码来源:helpers-view-models.ts
注:本文中的lodash-es/map.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论