Url.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var STRING = TYPE.String;
  3. var URL = TYPE.Url;
  4. var RAW = TYPE.Raw;
  5. var RIGHTPARENTHESIS = TYPE.RightParenthesis;
  6. // url '(' S* (string | raw) S* ')'
  7. module.exports = {
  8. name: 'Url',
  9. structure: {
  10. value: ['String', 'Raw']
  11. },
  12. parse: function() {
  13. var start = this.scanner.tokenStart;
  14. var value;
  15. this.scanner.eat(URL);
  16. this.scanner.skipSC();
  17. switch (this.scanner.tokenType) {
  18. case STRING:
  19. value = this.String();
  20. break;
  21. case RAW:
  22. value = this.Raw(this.scanner.currentToken, 0, RAW, true, false);
  23. break;
  24. default:
  25. this.scanner.error('String or Raw is expected');
  26. }
  27. this.scanner.skipSC();
  28. this.scanner.eat(RIGHTPARENTHESIS);
  29. return {
  30. type: 'Url',
  31. loc: this.getLocation(start, this.scanner.tokenStart),
  32. value: value
  33. };
  34. },
  35. generate: function(node) {
  36. this.chunk('url');
  37. this.chunk('(');
  38. this.node(node.value);
  39. this.chunk(')');
  40. }
  41. };