Skip to content

.before() modifies raws.before after insertion. #2017

Description

@pamelalozano16

Given a loud comment with new lines:

@mixin x {
    margin: 10px;
}

/*
* loud
* comment
*
*/

.a {
    @include x;
}

If I wanted to insert a new comment, e.g.:

const node = postcss.comment({
    text: 'New Comment',
    raws: {'inline': true, 'right': '', 'left': ' ', before:''},
});
console.log(node);

The log has the correct raws:

{"raws":{"inline":true,"right":"","left":" ","before":""},"text":"New Comment","type":"comment","inputs":[]}

But after insertion, the raws.before property is cloned from the original comment:

comment.before(node);
const previousComment = comment.prev() as postcss.Comment;
console.log(previousComment)

So the result is the following:

{
"raws": {
    "inline": true,
    "right": "",
    "left": " ",
    "before": "\n\n" // Should be ""
},
"text": "New comment",
"type": "comment",
"inputs": []
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions