Patch strict resolution

This commit is contained in:
Tobe O 2018-06-27 20:36:17 -04:00
parent d387776b9e
commit bdd94d5796
3 changed files with 39 additions and 4 deletions

View file

@ -20,8 +20,12 @@ class Conditional extends Expression {
@override
compute(scope) {
return (condition.compute(scope) == true)
? ifTrue.compute(scope)
: ifFalse.compute(scope);
var v = condition.compute(scope) as bool;
if (scope.resolve('!strict!')?.value == false) {
v = v == true;
}
return v ? ifTrue.compute(scope) : ifFalse.compute(scope);
}
}

View file

@ -22,6 +22,12 @@ class Negation extends Expression {
@override
compute(SymbolTable scope) {
return !(expression.compute(scope) == true);
var v = expression.compute(scope) as bool;
if (scope.resolve('!strict!')?.value == false) {
v = v == true;
}
return !v;
}
}

View file

@ -0,0 +1,25 @@
import 'dart:math';
import 'package:code_buffer/code_buffer.dart';
import 'package:jael/jael.dart' as jael;
import 'package:symbol_table/symbol_table.dart';
import 'package:test/test.dart';
void main() {
test('render into div', () {
var template = '''
<element name="square-root">
The square root of {{ n }} is {{ sqrt(n) }}.
</element>
<square-root n="16" />
''';
var html = render(template, {'sqrt': sqrt});
});
}
String render(String template, [Map<String, dynamic> values]) {
var doc = jael.parseDocument(template, onError: (e) => throw e);
var buffer = new CodeBuffer();
const jael.Renderer().render(doc, buffer, new SymbolTable(values: values));
return buffer.toString();
}