var.cjs 1.1 KB

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