less / less/less.js

Plan for comment nodes

Open
#2,477 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug feature request needs decision
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

short term

filter nodes passed to functions

long term

  1. move all constructor args to be {}

a) do not use the constructor.. use
Element.create(args)
and
this.clone(newArgs)

where the implementations might look like

create: function(args) {
    foreach(var arg in args) {
        this[arg] = args[arg];
    }
    this.setup();
}
clone: function(args) {
    foreach(var arg in this) {
        this[arg] = args[arg];
    }
    this.create(args);
}

move code from the constructor that sets default properties e.g. isn't just this.a = a; into setup.

E.g.

function constructor() {
}
constructor.prototype.setup = function() {
    this.a = this.a === undefined ? true : this.a;
}

main point and benefit is that we can add properties to a node without breaking things and we can start to push location and whitespace information in at the base class level.

Alternative would be to make all nodes non prototypal objects - actually by moving functions to be static on the type I think we could move to this as a stage after this if we wanted..

b)
This allows us to implement in parser a function to create nodes.

createNode: function(type, args) {
    return type.create(args);
}

c)

This allows us to attach whitespace/comment/location information for each node

d)

We need a way for our Node base class to output comments automatically ? So one way would be rename genCSS to genCSSX and have genCSS implemented in Node, calling genCSSX after having output all pre-comments and post-comments

Alternatives

  • add preComments / postComments to every constructor that needs it - problem is node constructors are unwieldy
  • keep comments as nodes and keep solution to filter for functions. - problem is that visitors have to work-around having comments anywhere, is a bit hacky
  • absorb comments and do not output them - how many css hacks will this effect?

Any more ideas welcome. Also need to decide if I/we do this if it constitutes a breaking change such that we need less v3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names parser node construction, the Node base class, createNode, and genCSS, but no files or tests. Review those entry points and the listed alternatives first; the work is only done once a decided approach supports comment, whitespace, and location information without requiring visitors to filter comment nodes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.