Dimension.js 811 B

1234567891011121314151617181920212223242526272829
  1. var consumeNumber = require('../../tokenizer/utils').consumeNumber;
  2. var TYPE = require('../../tokenizer').TYPE;
  3. var DIMENSION = TYPE.Dimension;
  4. module.exports = {
  5. name: 'Dimension',
  6. structure: {
  7. value: String,
  8. unit: String
  9. },
  10. parse: function() {
  11. var start = this.scanner.tokenStart;
  12. var numberEnd = consumeNumber(this.scanner.source, start);
  13. this.eat(DIMENSION);
  14. return {
  15. type: 'Dimension',
  16. loc: this.getLocation(start, this.scanner.tokenStart),
  17. value: this.scanner.source.substring(start, numberEnd),
  18. unit: this.scanner.source.substring(numberEnd, this.scanner.tokenStart)
  19. };
  20. },
  21. generate: function(node) {
  22. this.chunk(node.value);
  23. this.chunk(node.unit);
  24. }
  25. };