mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
Fix boolean expressions
commit_hash:e44dac4a5891c15da87b0d44fad541d370f32e3b
This commit is contained in:
@@ -5,7 +5,7 @@ import { walk } from './walk';
|
||||
import { parseColor, type ParsedColor } from '../utils/correctColor';
|
||||
import { padLeft } from '../utils/padLeft';
|
||||
import { MAX_INT, MIN_INT, toBigInt } from './bigint';
|
||||
import { NUMBER } from './const';
|
||||
import { BOOLEAN, NUMBER } from './const';
|
||||
|
||||
export function valToInternal(val: EvalValue): EvalValue {
|
||||
if (val.type === 'url' || val.type === 'color') {
|
||||
@@ -213,6 +213,9 @@ export function convertJsValueToDivKit(ctx: EvalContext, val: unknown, evalType:
|
||||
if (jsType === 'string' && evalType === 'url') {
|
||||
checkUrl(val);
|
||||
}
|
||||
if (jsType === 'boolean' && evalType === BOOLEAN) {
|
||||
val = val ? 1 : 0;
|
||||
}
|
||||
|
||||
return {
|
||||
type: evalType,
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { EvalValue } from './eval';
|
||||
import { parseColor } from '../utils/correctColor';
|
||||
import { bigIntZero, toBigInt } from './bigint';
|
||||
import { checkUrl } from './utils';
|
||||
import { BOOLEAN } from './const';
|
||||
|
||||
export type VariableType = 'string' | 'number' | 'integer' | 'boolean' | 'color' | 'url' | 'dict' | 'array';
|
||||
export type VariableValue = string | number | bigint | boolean | null | undefined | object | unknown[];
|
||||
@@ -362,8 +363,15 @@ export function defaultValueByType(type: keyof typeof TYPE_TO_CLASS): VariableVa
|
||||
}
|
||||
|
||||
export function variableToValue(variable: Variable): EvalValue {
|
||||
const type = variable.getType();
|
||||
let value = variable.getValue();
|
||||
|
||||
if (type === BOOLEAN) {
|
||||
value = value ? 1 : 0;
|
||||
}
|
||||
|
||||
return {
|
||||
type: variable.getType(),
|
||||
value: variable.getValue()
|
||||
type,
|
||||
value
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,6 +103,48 @@
|
||||
"web",
|
||||
"flutter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"expression": "@{d.getBoolean('b') == false}",
|
||||
"expected": {
|
||||
"type": "boolean",
|
||||
"value": true
|
||||
},
|
||||
"variables": [
|
||||
{
|
||||
"type": "dict",
|
||||
"value": {
|
||||
"b": false
|
||||
},
|
||||
"name": "d"
|
||||
}
|
||||
],
|
||||
"platforms": [
|
||||
"android",
|
||||
"ios",
|
||||
"web",
|
||||
"flutter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"expression": "@{(1 >= 2) == a}",
|
||||
"expected": {
|
||||
"type": "boolean",
|
||||
"value": true
|
||||
},
|
||||
"variables": [
|
||||
{
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"platforms": [
|
||||
"android",
|
||||
"ios",
|
||||
"web",
|
||||
"flutter"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user