Skip to content

Commit

Permalink
Merge pull request #209 from raxjs/fix/compat_old_version
Browse files Browse the repository at this point in the history
Fix/compat if runtime not support list key
  • Loading branch information
cryzzchen authored Aug 24, 2021
2 parents 01f06db + 4d110b8 commit 05c701d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/jsx-compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.4.34] - 2021-08-24

- Compatible with old version of jsx2mp-runtime, which not support list key

## [0.4.33] - 2021-08-19

- Support key in list (x-for, map)
Expand Down
2 changes: 1 addition & 1 deletion packages/jsx-compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsx-compiler",
"version": "0.4.33",
"version": "0.4.34",
"license": "BSD-3-Clause",
"description": "Parser for Rax JSX Statements.",
"files": [
Expand Down
21 changes: 17 additions & 4 deletions packages/jsx-compiler/src/modules/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ module.exports = {
const listsKeyProps = listKeyProps || {};
Object.keys(listsKeyProps).forEach((renamedIndex) => {
const { originalKey, renamedKey, parentNode } = listsKeyProps[renamedIndex];
// const key2 = this._getUniqKey('index2', item.key, index2);
// const key2 = this._getUniqKey ? this._getUniqKey('index2', item.key, index2) : index2;
const getTagIdArgs = [
t.stringLiteral(renamedIndex + ''),
originalKey,
t.identifier(renamedIndex)
];
const conditionExp = t.conditionalExpression(
getTagId,
t.callExpression(getTagId, getTagIdArgs),
t.identifier(renamedIndex)
);
const keyDeclaration = t.variableDeclaration('const', [
t.variableDeclarator(renamedKey, t.callExpression(getTagId, getTagIdArgs))
t.variableDeclarator(renamedKey, conditionExp)
]);

const targetNode = parentNode || fnBody;
Expand Down Expand Up @@ -645,6 +650,14 @@ function isImportAppJSON(mod, resourcePath, sourcePath, type) {

function addClearKeyCache(renderFunctionPath) {
const fnBody = renderFunctionPath.node.body.body;
// this._clearKeyCache();
fnBody.push(t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('_clearTagCache')), [])));
// this._clearKeyCache && this._clearKeyCache();
const clearExp = t.memberExpression(t.thisExpression(), t.identifier('_clearKeyCache'));
fnBody.push(
t.expressionStatement(
t.logicalExpression('&&',
clearExp,
t.callExpression(clearExp, [])
)
)
);
}

0 comments on commit 05c701d

Please sign in to comment.