Skip to content

Commit

Permalink
fix: s-bind error if value is null or undefined #135
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Sep 26, 2021
1 parent 729fee0 commit a4efe27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/compilers/anode-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ export class ANodeCompiler<T extends 'none' | 'typed'> {
aNode.props.map(prop => [L(camelCase(prop.name)), sanExpr(prop.expr)])
)
const bindDirective = aNode.directives.bind
return bindDirective ? new MapAssign(sanExpr(bindDirective.value), [propData]) : propData
return bindDirective
? new MapAssign(
BINARY(sanExpr(bindDirective.value), '||', new MapLiteral([])),
[propData]
)
: propData
}
}
6 changes: 3 additions & 3 deletions src/compilers/element-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { autoCloseTags } from '../utils/dom-util'
import { ANodeCompiler } from './anode-compiler'
import { ExprNode, ANodeProperty, Directive, ANode } from 'san'
import { isExprNumberNode, isExprStringNode, isExprBoolNode } from '../ast/san-ast-type-guards'
import { createIfStrictEqual, createIfNotNull, createDefaultValue, createHTMLLiteralAppend, createHTMLExpressionAppend, NULL, L, I, ASSIGN, DEF } from '../ast/renderer-ast-util'
import { HelperCall, ArrayIncludes, Else, Foreach, If } from '../ast/renderer-ast-dfn'
import { createIfStrictEqual, createIfNotNull, createDefaultValue, createHTMLLiteralAppend, createHTMLExpressionAppend, NULL, L, I, ASSIGN, DEF, BINARY } from '../ast/renderer-ast-util'
import { HelperCall, ArrayIncludes, Else, Foreach, If, MapLiteral } from '../ast/renderer-ast-dfn'
import { sanExpr, OutputType } from './san-expr-compiler'

const BOOL_ATTRIBUTES = ['readonly', 'disabled', 'multiple', 'checked']
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ElementCompiler {

private * compileBindProperties (tagName: string, bindDirective: Directive<any>) {
const bindProps = this.id.next('bindProps')
yield DEF(bindProps, sanExpr(bindDirective.value))
yield DEF(bindProps, BINARY(sanExpr(bindDirective.value), '||', new MapLiteral([])))

const key = I('key')
const value = I('value')
Expand Down

0 comments on commit a4efe27

Please sign in to comment.