Skip to content

Commit

Permalink
refactor(transformer): 测试环境也需要提醒无法使用 index 作为 key
Browse files Browse the repository at this point in the history
* fix: key detection

* refactor(transformer): 测试环境也需要提醒无法使用 index 作为 key
  • Loading branch information
yesmeck authored and yuche committed Apr 9, 2019
1 parent 0ece48e commit 72e9200
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,8 @@ export class RenderParser {
component.traverse({
JSXAttribute: !t.isIdentifier(indexParam) ? noop : (path: NodePath<t.JSXAttribute>) => {
const { value } = path.node
if (t.isJSXExpressionContainer(value) && t.isIdentifier(path.node.name, { name: 'key' }) && t.isIdentifier(value.expression, { name: indexParam.name })) {
if (process.env.TERM_PROGRAM) { // 无法找到 cli 名称的工具(例如 idea/webstorm)显示这个报错可能会乱码
if (t.isJSXExpressionContainer(value) && t.isJSXIdentifier(path.node.name, { name: 'key' }) && t.isIdentifier(value.expression, { name: indexParam.name })) {
if (process.env.TERM_PROGRAM || process.env.NODE_ENV === 'test') { // 无法找到 cli 名称的工具(例如 idea/webstorm)显示这个报错可能会乱码
// tslint:disable-next-line:no-console
console.log(codeFrameError(value.expression, '建议修改:使用循环的 index 变量作为 key 是一种反优化。参考:https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md').message)
}
Expand Down

0 comments on commit 72e9200

Please sign in to comment.