var.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var rawMode = require('../node/Raw').mode;
  3. var COMMA = TYPE.Comma;
  4. var WHITESPACE = TYPE.WhiteSpace;
  5. // var( <ident> , <value>? )
  6. module.exports = function() {
  7. var children = this.createList();
  8. this.scanner.skipSC();
  9. // NOTE: Don't check more than a first argument is an ident, rest checks are for lexer
  10. children.push(this.Identifier());
  11. this.scanner.skipSC();
  12. if (this.scanner.tokenType === COMMA) {
  13. children.push(this.Operator());
  14. const startIndex = this.scanner.tokenIndex;
  15. const value = this.parseCustomProperty
  16. ? this.Value(null)
  17. : this.Raw(this.scanner.tokenIndex, rawMode.exclamationMarkOrSemicolon, false);
  18. if (value.type === 'Value' && value.children.isEmpty()) {
  19. for (let offset = startIndex - this.scanner.tokenIndex; offset <= 0; offset++) {
  20. if (this.scanner.lookupType(offset) === WHITESPACE) {
  21. value.children.appendData({
  22. type: 'WhiteSpace',
  23. loc: null,
  24. value: ' '
  25. });
  26. break;
  27. }
  28. }
  29. }
  30. children.push(value);
  31. }
  32. return children;
  33. };