Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function constructSwitch(stateExpr: Switch & HasGroup & HasAttrValue, rewrite: IndexedClassRewrite
function constructDependency(stateExpr: Dependency, rewrite: IndexedClassRewrite
if (hasDependency(stateExpr)) {
expr.push(builders.number(SourceExpression.switchWithDep));
expr.push(...constructDependency(stateExpr, rewrite));
} else {
expr.push(builders.number(SourceExpression.switch));
}
expr.push(...constructSwitch(stateExpr, rewrite));
} else {
let type = 0;
if (hasDependency(stateExpr)) {
type = type | SourceExpression.dependency;
}
if (isConditional(stateExpr)) {
type = type | SourceExpression.boolean;
}
expr.push(builders.number(type));
if (hasDependency(stateExpr)) {
expr.push(...constructDependency(stateExpr, rewrite));
}
if (isConditional(stateExpr)) {
expr.push(...constructConditional(stateExpr, rewrite));
}
expr.push(...constructStateReferences(stateExpr, rewrite));
}
}
return expr;
}
function constructBoolean(bool: ConditionalArg): AST.Expression[] {
if (typeof bool === "number") {
return [builders.number(bool)];
} else if (isAndExpression(bool)) {
return constructAndExpression(bool);
} else if (isOrExpression(bool)) {
return constructOrExpression(bool);
} else if (isNotExpression(bool)) {
return constructNotExpression(bool);
} else {
assertNever(bool);
return [builders.null()];
}
}
function constructConditionalExpression(type: BooleanExpr, args: Array): AST.Expression[] {
let expr = new Array();
if (args.length === 1) {
let n = args[0];
if (typeof n === "number") {
expr.push(builders.number(n));
return expr;
}
}
expr.push(builders.number(type));
expr.push(builders.number(args.length));
for (let e of args) {
if (typeof e === "number") {
expr.push(builders.number(e));
} else {
expr.push(...constructBoolean(e));
}
}
return expr;
}
function constructConditionalExpression(type: BooleanExpr, args: Array): AST.Expression[] {
let expr = new Array();
if (args.length === 1) {
let n = args[0];
if (typeof n === "number") {
expr.push(builders.number(n));
return expr;
}
}
expr.push(builders.number(type));
expr.push(builders.number(args.length));
for (let e of args) {
if (typeof e === "number") {
expr.push(builders.number(e));
} else {
expr.push(...constructBoolean(e));
}
}
return expr;
}
function constructArgs(rewrite: IndexedClassRewrite, element: TemplateElement): AST.Expression[] {
let expr = new Array();
expr.push(builders.number(element.dynamicClasses.length + element.dynamicAttributes.length));
expr.push(builders.number(rewrite.dynamicClasses.length));
expr.push(...constructSourceArgs(rewrite, element));
expr.push(...constructOutputArgs(rewrite));
return expr;
}
function constructConditionalExpression(type: BooleanExpr, args: Array): AST.Expression[] {
let expr = new Array();
if (args.length === 1) {
let n = args[0];
if (typeof n === "number") {
expr.push(builders.number(n));
return expr;
}
}
expr.push(builders.number(type));
expr.push(builders.number(args.length));
for (let e of args) {
if (typeof e === "number") {
expr.push(builders.number(e));
} else {
expr.push(...constructBoolean(e));
}
}
return expr;
}