Skip to content

Commit

Permalink
fix(transformer): 空格强行换行,close #992
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Nov 13, 2018
1 parent a98f8ec commit 3a20233
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
31 changes: 13 additions & 18 deletions packages/taro-transformer-wx/__tests__/loop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
evalClass,
removeShadowData
} from './utils'
import { flatten } from 'lodash'
import { prettyPrint } from 'html'
import * as html from 'html'

function prettyPrint (str: string): string {
return html.prettyPrint(str, { max_char: 0 })
}

describe('loop', () => {
describe('有 block 有 return', () => {
Expand Down Expand Up @@ -87,10 +90,8 @@ describe('loop', () => {
`
<block>
<view>
<view wx:key="{{i}}" class="ratio-16-9 image-company-album" wx:for="{{loopArray0}}"
wx:for-item="e" wx:for-index="i">loop1: {{i}}
<view wx:key="{{j}}" class="ratio-16-9 image-company-album"
wx:for="{{e.$anonymousCallee__0}}" wx:for-item="el" wx:for-index="j">loop2: {{j}}</view>
<view wx:key="{{i}}" class="ratio-16-9 image-company-album" wx:for="{{loopArray0}}" wx:for-item="e" wx:for-index="i">loop1: {{i}}
<view wx:key="{{j}}" class="ratio-16-9 image-company-album" wx:for="{{e.$anonymousCallee__0}}" wx:for-item="el" wx:for-index="j">loop2: {{j}}</view>
</view>
</view>
</block>
Expand Down Expand Up @@ -130,8 +131,7 @@ describe('loop', () => {
`
<block>
<view>
<block wx:if=\"{{!(arr1.length > 1)}}\" wx:for=\"{{$anonymousCallee__2}}\"
wx:for-item=\"e\" wx:for-index=\"i\" wx:key=\"{{i}}\">
<block wx:if=\"{{!(arr1.length > 1)}}\" wx:for=\"{{$anonymousCallee__2}}\" wx:for-item=\"e\" wx:for-index=\"i\" wx:key=\"{{i}}\">
<view class=\"ratio-16-9 image-company-album\">loop1: {{i}}</view>
</block>
</view>
Expand Down Expand Up @@ -171,8 +171,7 @@ describe('loop', () => {
`
<block>
<view>
<block wx:if=\"{{!e.$loopState__temp2}}\" wx:for=\"{{loopArray0}}\" wx:for-item=\"e\"
wx:for-index=\"i\" wx:key=\"{{i}}\">
<block wx:if=\"{{!e.$loopState__temp2}}\" wx:for=\"{{loopArray0}}\" wx:for-item=\"e\" wx:for-index=\"i\" wx:key=\"{{i}}\">
<view class=\"ratio-16-9 image-company-album\">loop1: {{i}}</view>
</block>
</view>
Expand Down Expand Up @@ -216,8 +215,7 @@ describe('loop', () => {
<view></view>
</block>
<block wx:else>
<view wx:key=\"{{i}}\" class=\"ratio-16-9 image-company-album\" wx:for=\"{{$anonymousCallee__4}}\"
wx:for-item=\"e\" wx:for-index=\"i\">loop1: {{i}}</view>
<view wx:key=\"{{i}}\" class=\"ratio-16-9 image-company-album\" wx:for=\"{{$anonymousCallee__4}}\" wx:for-item=\"e\" wx:for-index=\"i\">loop1: {{i}}</view>
</block>
</block>
</view>
Expand Down Expand Up @@ -274,8 +272,7 @@ describe('loop', () => {
<view></view>
</block>
<block wx:else>
<view wx:key=\"{{i}}\" class=\"ratio-16-9 image-company-album\" wx:for=\"{{a2}}\"
wx:for-item=\"e\" wx:for-index=\"i\">loop1: {{i}}
<view wx:key=\"{{i}}\" class=\"ratio-16-9 image-company-album\" wx:for=\"{{a2}}\" wx:for-item=\"e\" wx:for-index=\"i\">loop1: {{i}}
<block>
<block wx:if=\"{{b1}}\">
<view></view>
Expand Down Expand Up @@ -2762,8 +2759,7 @@ describe('loop', () => {
<block>
<view wx:key="{{index}}" wx:for="{{loopArray0}}" wx:for-item="key" wx:for-index="index">
<view>{{key.$original}}</view>
<view wx:key="{{id}}" wx:for="{{key.$anonymousCallee__7}}"
wx:for-item="value" wx:for-index="id">{{value.$original}}</view>
<view wx:key="{{id}}" wx:for="{{key.$anonymousCallee__7}}" wx:for-item="value" wx:for-index="id">{{value.$original}}</view>
</view>
</block>
`)
Expand Down Expand Up @@ -2835,8 +2831,7 @@ describe('loop', () => {
<block>
<view wx:key="{{index}}" wx:for="{{loopArray0}}" wx:for-item="key" wx:for-index="index">
<view>{{key.$original}}</view>
<view wx:key="{{id}}" wx:for="{{key.ks}}"
wx:for-item="value" wx:for-index="id">{{value}}</view>
<view wx:key="{{id}}" wx:for="{{key.ks}}" wx:for-item="value" wx:for-index="id">{{value}}</view>
</view>
</block>
`)
Expand Down
4 changes: 3 additions & 1 deletion packages/taro-transformer-wx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ export default function transform (options: Options): TransformResult {
result = new Transformer(mainClass, options.sourcePath, componentProperies).result
result.code = generate(ast).code
result.ast = ast
result.template = prettyPrint(result.template)
result.template = prettyPrint(result.template, {
max_char: 0
})
result.imageSrcs = Array.from(imageSource)
return result
}

0 comments on commit 3a20233

Please sign in to comment.