The `Node` superclass setting defaults for its subclass is error prone.
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 30/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- javascript, typescript
- Domínio
- web-dev
Direção de pesquisa
Start with the Node constructor in lib/node.js at the linked line, then reproduce the TypeScript subclass example using an ES2022 target and useDefineForClassFields. Define and document a safe default-value behavior for subclasses, with regression coverage showing that values passed to super() are not silently reset.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
The constructor for the Node class receives a map of default values, and then assigns the values to itself the following way:
https://github.com/postcss/postcss/blob/1cc6ac3bf43a12460d3396e2cb76f14075daea1b/lib/node.js#L52
This pattern is error prone because in JS, property initialization happens after calling the super() constructor. That means that even if a value is set by calling super(defaults) from a child node, the value could then be silently reset to undefined or some other initial value if the property happens to be declared in the subclass.
Example snippet in typescript:
class MyNode extends Node {
private _foo!: string;
get foo() { return _foo }
set foo(f: string) { this._foo = f };
constructor(defaults) {
super(defaults);
}
}
const myNode = new MyNode({foo: 'foo'});
console.log(myNode.foo); // OUTPUT: undefined
We expected the output to be "foo", but instead it was undefined because the MyNode properties are initialized after calling super(). This is JS behavior according to spec, and it can only be seen when compiling TS using the ES2022 target (or above) and enabling the tsconfig option useDefineForClassFields. The reason TS didn't fail is because TS moved the property initialization prior to calling the constructor, but it fails now that it emits more accurate JS.
The fix for this example using the current PostCSS API in this case is to replace private _foo!: string with declare _foo: string. However, this has two issues. First, it's not ideal to use declare in this case. Second, the error is silent and is only noticeable with thorough testing, which is therefore error prone because it's somewhat easy to miss.
So, I believe the PostCSS API should do something different to keep/set the default values in a different way that doesn't invite the user to write this pattern. Maybe the node super class could just keep an internal copy of the default values inside a JSON property called _defaults, and the getters/setters would just access that?
- Linguagem predominante
- TypeScript
- Estrelas
- 29k
- Forks
- 1.7k
- Merge médio
- 1d 14h
- PRs com merge (30d)
- 9
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de postcss/postcss
-
Put opnly `major.minor` in `Processor.version`Talvez já em andamento @MahinAnowar assumiu há 127 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 50/100
postcss/postcss#2160 · 3 comentários · 2 reações ·
Mantenedores costumam responder em até 1 dia
-
Multiple BOM symbols inside generated css in v8.5.24Talvez já em andamento @arronKler assumiu há 87 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 50/100
postcss/postcss#2133 · 9 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Remove colors libTalvez já em andamento @mrpmohiburrahman assumiu há 83 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
Mantenedores costumam responder em até 1 dia
-
Add a way to create plugins in TypeScriptTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
postcss/postcss#2102 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de postcss/postcss
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
WalletConnect/walletconnect-monorepo#7392 · 1 comentário ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
fehler
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Azure/azure-functions-nodejs-extensions#180 ·
Mantenedores costumam responder em até 1 dia
-
bug good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
laaielichter/Threesmith#28 ·
Mantenedores costumam responder em até 1 dia