Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/jsx-compiler/src/modules/__tests__/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,36 @@ describe('Transiform condition render function', () => {
setState(a);
}, []);
return <View>{a}</View>;
}`);
});

it('statement without square bracket in alternate', () => {
const ast = parseExpression(`(function render(props) {
const [loggined, setLoggined] = useState(false);
useEffect(() => {
const { isLogin } = app;
if (isLogin) {
setLoggined(true);
} else setLoggined(false);
}, [])
return <View>{loggined}</View>;
})
`);

const tmpVars = _transformRenderFunction(ast, adapter);
expect(genExpression(tmpVars.vdom)).toEqual('');
expect(genExpression(ast)).toEqual(`function render(props) {
const [loggined, setLoggined] = useState(false);
useEffect(() => {
const {
isLogin
} = app;

if (isLogin) {
setLoggined(true);
} else setLoggined(false);
}, []);
return <View>{loggined}</View>;
}`);
});
});
6 changes: 3 additions & 3 deletions packages/jsx-compiler/src/modules/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function transformRenderFunction(renderPath, adapter) {
}

if (!alternatePath.isIfStatement() && alternatePath.node) {
const alternateBodyPath = alternatePath.get('body');
if (alternateBodyPath) {
if (alternatePath.isBlockStatement()) {
const alternateBodyPath = alternatePath.get('body');
alternateBodyPath.map((statementPath) => {
handleAlternate(
statementPath.get('expression'),
Expand Down Expand Up @@ -322,7 +322,7 @@ function handleConsequent(path, expressionPath, templateMap, renderScope, adapte
// Remove only if the expression contains JSX
expressionPath.remove();
}
}
} else handleAlternate(expressionPath, templateMap, adapter)
}
}

Expand Down