Patch strict resolution
This commit is contained in:
parent
d387776b9e
commit
bdd94d5796
3 changed files with 39 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
25
jael/test/render/custom_element_test.dart
Normal file
25
jael/test/render/custom_element_test.dart
Normal 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();
|
||||
}
|
Loading…
Reference in a new issue