Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logical attribute calc css variable logic error #177

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: update logic
Wxh16144 committed Mar 12, 2024
commit 096326499168fdb12d305ed4aaf1f12a4c70fe6b
6 changes: 3 additions & 3 deletions src/transformers/legacyLogicalProperties.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ function splitValues(

const splitStyle = (importantCells ? importantCells[1] : rawStyle)
.trim()
.split(/(?<!\(.*)\s+(?![^\(]*\))/);
.split(/\s+/);

// Combine styles split in brackets, like `calc(1px + 2px)`
let temp = '';
@@ -26,10 +26,10 @@ function splitValues(
brackets += left - right;
}
if (brackets === 0) {
list.push(temp + item);
list.push(`${temp} ${item}`);
temp = '';
} else if (brackets > 0) {
temp += item;
temp += ` ${item}`;
Copy link
Contributor

@yoyo837 yoyo837 Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥不都用数组push, 然后最终join(' ')呢?字符串玩着玩着容易玩出这种问题。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这段代码已经比较精简了,没有可操作空间了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  let temp: string[] = [];
  let brackets = 0;
  return [
    splitStyle.reduce<string[]>((list, item) => {
      if (item.includes('(') || item.includes(')')) {
        const left = item.split('(').length - 1;
        const right = item.split(')').length - 1;
        brackets += left - right;
      }
      if (brackets >= 0) {
        temp.push(item);
      }
      if (brackets === 0) {
        list.push(temp.join(' '));
        temp = [];
      }
      return list;
    }, []),
    !!importantCells,
  ];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoyo837 可以直接用 suggestion 能力。

图片

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

跨越很多行,还涉及一些未修改的行,这种情况我不会 suggestion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push 了,再 review 一下吧

}
return list;
}, []),