Skip to content

Commit

Permalink
Merge pull request #213 from raxjs/release/miniapp-0831
Browse files Browse the repository at this point in the history
Release/miniapp 0831
  • Loading branch information
ChrisCindy authored Aug 31, 2021
2 parents 05c701d + fbb6ec5 commit dcbc803
Show file tree
Hide file tree
Showing 35 changed files with 225 additions and 188 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.35] - 2021-08-27

- Return renamed index in list

## [0.4.34] - 2021-08-24

- Compatible with old version of jsx2mp-runtime, which not support list key
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.34",
"version": "0.4.35",
"license": "BSD-3-Clause",
"description": "Parser for Rax JSX Statements.",
"files": [
Expand Down
18 changes: 14 additions & 4 deletions packages/jsx-compiler/src/modules/__tests__/jsx-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Directives', () => {
<View a:for={array.map((val, ${index}) => {
return {
val: val,
${index}: ${index},
_key: ${key}
};
})} a:key="_key" a:for-item="val" a:for-index="${index}">{{
Expand Down Expand Up @@ -62,9 +63,11 @@ describe('Directives', () => {
item: item.map((item2, ${index2}) => {
return {
item2: item2,
${index2}: ${index2},
_key: ${key2}
};
}),
${index1}: ${index1},
_key: ${key1}
};
})} a:key="_key" a:for-item="item" a:for-index="${index1}">
Expand Down Expand Up @@ -104,17 +107,18 @@ describe('Directives', () => {
row: row.map((col, ${index2}) => {
return {
col: col,
_key: ${key2},
_d0: ${index2}
${index2}: ${index2},
_key: ${key2}
};
}),
${index1}: ${index1},
_key: ${key1},
_d0: 'test_' + ${index1}
};
})} a:key="_key" a:for-item="row" a:for-index="${index1}">
<View a:for={row} a:key="_key" a:for-item="col" a:for-index="${index2}">
<Text key="{{col._d0}}">{{
col._d0
<Text key="{{col.${index2}}}">{{
col.${index2}
}}</Text>
</View>
</View>
Expand All @@ -138,6 +142,7 @@ describe('Directives', () => {
<View a:for={array.map((val, ${index}) => {
return {
val: val,
${index}: ${index},
_key: ${key},
_d0: format(val)
};
Expand All @@ -164,6 +169,7 @@ describe('Directives', () => {
<View a:for={array.map((val, ${index}) => {
return {
val: val,
${index}: ${index},
_key: ${key},
_d0: format(val)
};
Expand All @@ -190,6 +196,7 @@ describe('Directives', () => {
<View a:for={list.map((item, ${index}) => {
return {
item: item,
${index}: ${index},
_key: ${key},
_d0: item.id,
_d1: format(item.val)
Expand Down Expand Up @@ -277,6 +284,7 @@ describe('Directives', () => {
return {
item: item,
${index}: ${index},
_key: ${key},
_d0: "${id}" + ${index}
};
Expand Down Expand Up @@ -314,11 +322,13 @@ describe('Directives', () => {
return {
item: item,
${index2}: ${index2},
_key: ${key2},
_d0: "${id}" + ${index2}
};
})
},
${index1}: ${index1},
_key: ${key1}
};
})} a:key="_key" a:for-item="item" a:for-index="${index1}">
Expand Down
38 changes: 26 additions & 12 deletions packages/jsx-compiler/src/modules/__tests__/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('Transform list', () => {
expect(genCode(ast).code).toEqual(`<View><block a:for={arr.map((val, ${index}) => {
return {
val: val,
_key: ${key},
_d0: ${index}
${index}: ${index},
_key: ${key}
};
})} a:for-item="val" a:for-index="${index}" a:key="_key"><item data-value="{{val.val}}" data-key="{{val._d0}}" /></block></View>`);
})} a:for-item="val" a:for-index="${index}" a:key="_key"><item data-value="{{val.val}}" data-key="{{val.${index}}}" /></block></View>`);
});

it('transform array.map in JSXContainer', () => {
Expand All @@ -40,10 +40,10 @@ describe('Transform list', () => {
expect(genCode(ast).code).toEqual(`<View><block a:for={arr.map((val, ${index}) => {
return {
val: val,
_key: ${key},
_d0: ${index}
${index}: ${index},
_key: ${key}
};
})} a:for-item="val" a:for-index="${index}" a:key="_key"><item data-value="{{val.val}}" data-key="{{val._d0}}" /></block></View>`);
})} a:for-item="val" a:for-index="${index}" a:key="_key"><item data-value="{{val.val}}" data-key="{{val.${index}}}" /></block></View>`);
});

it('bind list variable', () => {
Expand All @@ -59,6 +59,7 @@ describe('Transform list', () => {
expect(genCode(ast).code).toEqual(`<View><block a:for={arr.map((item, ${index}) => {
return {
item: item,
${index}: ${index},
_key: ${key},
_d0: item.title,
_d1: {
Expand All @@ -80,7 +81,7 @@ describe('Transform list', () => {
}, code, adapter);
const key = '_key' + count;
const index = 'index' + count++;
expect(genCode(ast, { concise: true }).code).toEqual(`<View><block a:for={[1, 2, 3].map((val, ${index}) => { return { val: val, _key: ${key}, _d0: ${index} }; })} a:for-item="val" a:for-index="${index}" a:key="_key"><Text>{{ val._d0 }}</Text></block></View>`);
expect(genCode(ast, { concise: true }).code).toEqual(`<View><block a:for={[1, 2, 3].map((val, ${index}) => { return { val: val, ${index}: ${index}, _key: ${key} }; })} a:for-item="val" a:for-index="${index}" a:key="_key"><Text>{{ val.${index} }}</Text></block></View>`);
});

it('nested list', () => {
Expand Down Expand Up @@ -127,9 +128,11 @@ describe('Transform list', () => {
l1: l1.map((l2, ${index2}) => {
return {
l2: l2,
${index2}: ${index2},
_key: ${key2}
};
}),
${index1}: ${index1},
_key: ${key1}
};
})} a:for-item="l1" a:for-index="${index1}" a:key="_key"><View>
Expand Down Expand Up @@ -184,10 +187,12 @@ describe('Transform list', () => {
<block a:for={arr.map((l1, ${index1}) => {
return {
l1: l1,
${index1}: ${index1},
_key: ${key1},
_d0: list[l1].map((l2, ${index2}) => {
return {
l2: l2,
${index2}: ${index2},
_key: ${key2}
};
})
Expand Down Expand Up @@ -247,10 +252,12 @@ describe('Transform list', () => {
list: l1.list.map((l2, ${index2}) => {
return {
l2: l2,
${index2}: ${index2},
_key: ${key2}
};
})
},
${index1}: ${index1},
_key: ${key1}
};
})} a:for-item="l1" a:for-index="${index1}" a:key="_key"><View>
Expand Down Expand Up @@ -307,10 +314,12 @@ describe('Transform list', () => {
const a = l1 || [];
return {
l1: l1,
${index1}: ${index1},
_key: ${key1},
a: a.map((l2, ${index2}) => {
return {
l2: l2,
${index2}: ${index2},
_key: ${key2}
};
})
Expand All @@ -335,7 +344,7 @@ describe('Transform list', () => {
}, code, adapter);
const key = '_key' + count;
const index = 'index' + count++;
expect(genCode(ast, { concise: true }).code).toEqual(`<View><block a:for={[1, 2, 3].map((item, ${index}) => { return { item: item, _key: ${key} }; })} a:for-item="item" a:for-index="${index}" a:key="_key"><Text>test</Text></block></View>`);
expect(genCode(ast, { concise: true }).code).toEqual(`<View><block a:for={[1, 2, 3].map((item, ${index}) => { return { item: item, ${index}: ${index}, _key: ${key} }; })} a:for-item="item" a:for-index="${index}" a:key="_key"><Text>test</Text></block></View>`);
});

it('list style', () => {
Expand All @@ -357,6 +366,7 @@ describe('Transform list', () => {
};
return {
item: item,
${index}: ${index},
_key: ${key},
_s0: __create_style__(style)
};
Expand Down Expand Up @@ -398,10 +408,12 @@ describe('Transform list', () => {
};
return {
it: it,
${index2}: ${index2},
_key: ${key2},
_s0: __create_style__(style)
};
}),
${index1}: ${index1},
_key: ${key1}
};
})} a:for-item="item" a:for-index="${index1}" a:key="_key"><View>
Expand All @@ -423,6 +435,7 @@ describe('Transform list', () => {
expect(genCode(ast).code).toEqual(`<View><block a:for={[1, 2, 3].map((item, ${index}) => {
return {
item: item,
${index}: ${index},
_key: ${key}
};
})} a:for-item="item" a:for-index="${index}" a:key="_key"><Text>test</Text></block></View>`);
Expand All @@ -443,6 +456,7 @@ describe('Transform list', () => {
const a = ${index} * 2 + 10;
return {
item: item,
${index}: ${index},
_key: ${key},
_d0: a
};
Expand All @@ -466,12 +480,12 @@ describe('Transform list', () => {
expect(genCode(ast).code).toEqual(`<View><block a:for={arr.map((val, ${index}) => {
return {
val: val,
${index}: ${index},
_key: ${key},
_d0: ${index},
_d1: format(${index})
_d0: format(${index})
};
})} a:for-item="val" a:for-index="${index}" a:key="_key"><View data-value="{{val.val}}" data-key="{{val._d0}}">{{
val._d1
})} a:for-item="val" a:for-index="${index}" a:key="_key"><View data-value="{{val.val}}" data-key="{{val.${index}}}">{{
val._d0
}}</View></block></View>`);
});
});
1 change: 1 addition & 0 deletions packages/jsx-compiler/src/modules/jsx-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function transformDirectiveList(parsed, code, adapter) {
// Transform x-for forNode to map function
const properties = [
t.objectProperty(params[0], params[0]),
t.objectProperty(params[1], params[1]),
t.objectProperty(t.identifier('_key'), renamedKey),
];
const loopFnBody = t.blockStatement([
Expand Down
1 change: 1 addition & 0 deletions packages/jsx-compiler/src/modules/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function transformMapMethod(path, parsed, code, adapter) {
const forIndex = params[1];
const properties = [
t.objectProperty(params[0], params[0]),
t.objectProperty(renamedIndex, renamedIndex),
t.objectProperty(t.identifier('_key'), renamedKey),
];

Expand Down
6 changes: 6 additions & 0 deletions packages/jsx2mp-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.4.30] - 2021-08-31

### Fixed

- Error can't be catch in eliminateDeadCode

## [0.4.29] - 2021-07-12

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/jsx2mp-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsx2mp-loader",
"version": "0.4.29",
"version": "0.4.30",
"description": "",
"files": [
"src"
Expand Down
3 changes: 1 addition & 2 deletions packages/jsx2mp-loader/src/component-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ module.exports = async function componentLoader(content) {
virtualHost
});

const rawContentAfterDCE = eliminateDeadCode(content);

let transformed;
try {
const rawContentAfterDCE = eliminateDeadCode(content);
transformed = compiler(rawContentAfterDCE, compilerOptions);
} catch (e) {
console.log(chalk.red(`\n[${platform.name}] Error occured when handling Component ${this.resourcePath}`));
Expand Down
6 changes: 6 additions & 0 deletions packages/miniapp-compile-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.2.5] - 2021-08-23

### Added

- Support using miniapp plugin components in miniapp plugin project

## [0.2.4] - 2021-08-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/miniapp-compile-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniapp-compile-config",
"version": "0.2.4",
"version": "0.2.5",
"description": "miniapp compile project config",
"author": "Rax Team",
"homepage": "https://github.com/raxjs/miniapp#readme",
Expand Down
4 changes: 4 additions & 0 deletions packages/miniapp-compile-config/src/setBaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ module.exports = (
if (/\.(css|sass|scss|styl|less)$/.test(request)) {
return callback(null, `commonjs2 ${request}`);
}
// compatible with plugin with miniapp plugin
if (/^plugin\:\/\//.test(request)) {
return callback(null, `commonjs ${request}`);
}
callback();
},
].concat(chainConfig.get('externals') || [])
Expand Down
7 changes: 7 additions & 0 deletions packages/miniapp-render/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.8.2] - 2021-08-31

### Changed

- Remove view and h-element type optimization in baidu and kuaishou miniapp (for flex display)
- Remove useless data in setData

## [2.8.1] - 2021-08-19

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/miniapp-render/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniapp-render",
"version": "2.8.1",
"version": "2.8.2",
"description": "DOM simulator for MiniApp",
"files": [
"dist"
Expand Down
4 changes: 2 additions & 2 deletions packages/miniapp-render/scripts/platform-plugin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const t = require('@babel/types');
// Collect import specifiers
const specified = [];
const platformEnvValues = ['isMiniApp', 'isWeChatMiniProgram'];
const platformEnvValues = ['isMiniApp', 'isWeChatMiniProgram', 'isByteDanceMicroApp', 'isBaiduSmartProgram', 'isKuaiShouMiniProgram'];
const platformMap = {
ali: 'isMiniApp',
wechat: 'isWeChatMiniProgram',
bytedance: 'isByteDanceMicroApp',
baidu: 'isBaiduSmartProgram',
kuaishou: 'isKuaishouMiniProgram'
kuaishou: 'isKuaiShouMiniProgram'
};

function variableDeclarationMethod(name, value) {
Expand Down
Loading

0 comments on commit dcbc803

Please sign in to comment.