Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Question about parsing with comments in selectors

未关闭
#64 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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:

  • /* this
  • is
  • a
  • test */ .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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

postcss/postcss-js 的其他 Issue

查看 postcss/postcss-js 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。