Skip to content

Empty "before" value when input file is UTF-8 encoded. #32

Closed

Description

@MohammadYounes
Input
/*******************************
  Sample Content
*******************************/

/*comment before first rule*/
.sample {
  margin:10px;
}
Output
{ type: 'rule',
  decls:
   [ { type: 'decl',
       parent: [Circular],
       source: [Object],
       before: '\r\n  ',
       prop: 'margin',
       between: '',
       _value: [Object] } ],
  parent:
   { type: 'root',
     rules: [ [Circular] ],
     after: '',
     lastEach: 1,
     indexes: { '1': 0 } },
  source: { start: { line: 1, column: 1 }, end: { line: 8, column: 1 } },
  before: '',
  _selector:
   { raw: '?/*******************************\r\n  Sample Content\r\n************
*******************/\r\n\r\n/*comment before first rule*/\r\n.sample ',
     trimmed: '.sample' },
  semicolon: true,
  after: '\r\n' }

Activity

  1. ai commented on Feb 26, 2014

    @ai
    Member

    Seems like you use outdated PostCSS. PostCSS 0.3 may fix this issue.

    Please update and if issue will be on latest version, be free to reopen issue.

  2. MohammadYounes commented on Feb 26, 2014

    @MohammadYounes
    ContributorAuthor

    Thanks for the quick response, Yes I'm using PostCSS 0.2.0

    Where did decl._value.raw go? The change log says nothing about it being removed ? what is the alterantive ?

  3. ai commented on Feb 26, 2014

    @ai
    Member

    _value is totally internal method ;). Use only .value, .selector and same public getters.

  4. ai commented on Feb 26, 2014

    @ai
    Member

    If raw and trimmed values are same (like in color: black) _value will contain only one value.

    If raw and trimmed values are different (like in border-width: 1px /**/ 1px, decl.value == '1px 1px', but decl._value.raw == '1px /**/ 1px') _value will contain has with two values.

  5. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    For post processing, I think raw value should be always available, even if it's equal to the trimmed value.

    I'll stick to 0.2 for the time being ;)

    Thanks.

  6. ai commented on Feb 27, 2014

    @ai
    Member

    Raw values is avaiable, it is just combined with trimmed :D.

    Now raw property is like a private method with bad API, but I can add some good API to get raw value. Why do you need raw value?

  7. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    I use comments to provide processing instructions, most of them placed after the decl. value

  8. ai commented on Feb 27, 2014

    @ai
    Member

    In PostCSS 0.3 I add Comment node specially for this case :).

    But I plan to write postcss-control-comment library to works with this processing instructions in comments. Can you show me example of your processing instructions, because I think what API should postcss-control-comment supports.

  9. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    I'm using something like replace, append, prepend, for example:

    .example{
       content: '\f0da'/*replace:'\f0d9'*/;
    }
  10. ai commented on Feb 27, 2014

    @ai
    Member

    Hm. I think about structure instruction like:

    /* autoprefixer: off */
    a {
      /* autoprefixer: on */
    }
  11. ai commented on Feb 27, 2014

    @ai
    Member

    What about this API:

    decl.raw('value')
  12. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    Why not keep it exposed as a property

    decl.raw

    I updated to 0.3 and changed the code to perform a check on decl._value.raw != null, but I noticed rule.before does not return the same value as in 0.2 !

    in your example:

    /* autoprefixer: off */
    a {
      /* autoprefixer: on */
    }

    What will get the value /* autoprefixer: off */ ?

  13. ai commented on Feb 27, 2014

    @ai
    Member

    Node can contain several raw values ;).

    Yeap, before logic was changed. But it was very necessary changes to allow code style copy to new nodes and to support Comment nodes.

    In this example every comment will be Comment node. But if comment is inside value or selector, it will be in raw.

  14. 7 remaining items

  15. ai commented on Feb 27, 2014

    @ai
    Member

    I open it as notice to add raw API.

  16. reopened this on Feb 27, 2014
  17. ai commented on Feb 27, 2014

    @ai
    Member

    Maybe decl.rawValue?

  18. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    Oh sorry about that ... decl.rawValue seems great 👍

    In my opinion, a comment is not a rule. and I liked it better when comments were handled by before, between and after properties.

  19. ai commented on Feb 27, 2014

    @ai
    Member

    If we store comment in before, then on decl.clone() we copy this comment. In most of cases it will be unexpected behavior.

    In PostCSS 0.3, when we add new decl or rule node without before, PostCSS will find first same type node and copy before and other code style props from it. If we store comemnt in before it will be copy to new node.

    If we store comment in before it will be very difficult to find source map annotation comment or processing instructions comment, because before can contain several comments and we will need to parse it.

  20. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    How about moving the comments nodes inside the rule rule.comments, and provide a flag for clone clone(bool:include comments) ?

  21. ai commented on Feb 27, 2014

    @ai
    Member

    We will need rule.beforeComments, rule.afterComments, decl.beforeComments. Traveling code will be much diffiult.

    Why you need comments in decl node? You can get previous comment very easy:

    root.eachDecl(function (decl, i) {
      var prev = decl.parent.decls[i - 1];
    });
  22. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    I already figured that out, it just makes more sense to have comments as properties of rules, not rules of type comment!

    Also you don't need all of that, each rule will contain the list of comments preceding it. and the root contains the list of comments after the last rule.

  23. ai commented on Feb 27, 2014

    @ai
    Member

    But comments can be before declarations, so we need decl.beforeComments and between last declatation and rules’s } can be comments too, so we need rule.afterComments ;).

  24. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    For declarations use before and after

    .sample{
    /*before*/
    marging: /*raw*/ 10px /*value*/;
    /*after*/
    }
    before == "/*before*/\n"
    after == "/*after*/\n"
    rawValue ==  " /*raw*/ 10px /*value*/"
  25. ai commented on Feb 27, 2014

    @ai
    Member

    But what will be if rule will not have any declaration inside, only comments? ;)

  26. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    Empty declaration 😄

  27. MohammadYounes commented on Feb 27, 2014

    @MohammadYounes
    ContributorAuthor

    Or may be provide rule.rawValue too, let me know your decision, so I plan my upgrade accordingly ... either way its a pretty awesome framework 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions