Question about parsing with comments in selectors
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- frontend
调研方向
Start by running the example from the issue with postcss-js and inspect the resulting rule.selector and rule.selectors values. Compare that behavior with postcss-selector-parser's handling of comments and selector updates. Done means determining whether the reported comment form is supported and, if so, preserving the comment without splitting comma-containing comments into selector entries.
由索引模型根据 Issue 内容生成。
描述
The Problem
First off I know this is a bit odd but, when parsing a selector with a comment before it PostCSS will treat it as a comment node. These can show up in IDEs (like VSCode for example) with information about the class. When using postcss-js the only way to do this, that I know of, is to add a comment to the selector itself. This seems to work okay-ish as long as the comment does not contain commas. If it does, any code relying on rule.selectors can break because it recieves pieces of a comment along with the other pieces of the selector.
Example Code
So, given the following:
import postcssJs from "postcss-js"
import postcss from "postcss"
const result = postcss().process({
'/* this, is, a, test */ .test': {
'color': 'blue'
}
}, {
parser: postcssJs,
}).sync()
console.log({
selector: result.root.nodes[0].selector,
selectors: result.root.nodes[0].selectors
})
You'll see that selector turns out to be: /* this, is, a, test */ .test instead of having a comment node before the rule.
The main problem though is that rule.selectors becomes an array with 4 items:
/* thisisatest */ .test
My Question
Is this something postcss-js is just not intended to support? If not, is there another possible solution? I noticed that postcss-selector-parser seems to handle comments in selectors fine — at least on some level. Though it doesn't clean out the selector of a rule when using updateSelector. I'd be happy to prep a PR that uses the selector parser to clean them but I have a feeling this might be a bit complicated because comments can technically appear in between parts of a selector which would require updating raws.
- 主要语言
- JavaScript
- 星标
- 667
- 派生
- 24
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
postcss/postcss-js 的其他 Issue
-
.sync API 未关闭
难度 1/5 1 小时以内 新手友好度 48/100
postcss/postcss-js#72 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 38/100
postcss/postcss-js#69 · 7 条评论 ·
查看 postcss/postcss-js 的全部 Issue
相似的 Issue
-
Bug
难度 2/5 1-3 小时 新手友好度 70/100
Automattic/safe-publish#594 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
dream-num/dsh-univer-office#104 ·
-
comp/dashboard invalid P3
难度 2/5 1-3 小时 新手友好度 70/100
NousResearch/hermes-agent#121143 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
avniproject/avni-webapp#1811 ·
-
area/auroraboot area/webui bug
难度 2/5 1-3 小时 新手友好度 75/100