Skip to content

Commit

Permalink
fix: print expression if it is resolved as null or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Apr 29, 2018
1 parent c84f20b commit a4ace5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/view/components/Expression.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import Vue, { VNode } from 'vue'
import { DefaultValue } from '@/parser/script/types'
import { evalWithScope } from '../eval'
import { evalWithScope, EvalSuccess } from '../eval'
export default Vue.extend({
name: 'Expression',
Expand All @@ -22,15 +22,16 @@ export default Vue.extend({
render(h, { props }): VNode {
const { expression: exp, scope } = props
const result = evalWithScope(exp, scope)
const str = result.isSuccess
? toStringForPrint(result.value)
const resolved = result.isSuccess && result.value != null
const str = resolved
? toStringForPrint((result as EvalSuccess).value)
: '{{ ' + exp + ' }}'
return h(
'span',
{
class: {
unresolved: !result.isSuccess
unresolved: !resolved
}
},
[str]
Expand Down
6 changes: 3 additions & 3 deletions test/view/VueComponent/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('VueComponent basic', () => {
expect(wrapper.find('p').text()).toBe('This is replaced text')
})

it('should print an empty string if the expression is resolved as null or undefined', () => {
it('should print an expression if it is resolved as null or undefined', () => {
// prettier-ignore
const template = createTemplate([
h('div', [], [
Expand All @@ -80,8 +80,8 @@ describe('VueComponent basic', () => {
}
]
)
expect(wrapper.find('#foo').text()).toBe('')
expect(wrapper.find('#bar').text()).toBe('')
expect(wrapper.find('#foo').text()).toBe('{{ foo }}')
expect(wrapper.find('#bar').text()).toBe('{{ bar }}')
})

it('should add class', () => {
Expand Down

0 comments on commit a4ace5c

Please sign in to comment.