quotes.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var IPropertyDescriptor_1 = require("../IPropertyDescriptor");
  4. var parser_1 = require("../syntax/parser");
  5. var tokenizer_1 = require("../syntax/tokenizer");
  6. exports.quotes = {
  7. name: 'quotes',
  8. initialValue: 'none',
  9. prefix: true,
  10. type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
  11. parse: function (tokens) {
  12. if (tokens.length === 0) {
  13. return null;
  14. }
  15. var first = tokens[0];
  16. if (first.type === tokenizer_1.TokenType.IDENT_TOKEN && first.value === 'none') {
  17. return null;
  18. }
  19. var quotes = [];
  20. var filtered = tokens.filter(parser_1.isStringToken);
  21. if (filtered.length % 2 !== 0) {
  22. return null;
  23. }
  24. for (var i = 0; i < filtered.length; i += 2) {
  25. var open_1 = filtered[i].value;
  26. var close_1 = filtered[i + 1].value;
  27. quotes.push({ open: open_1, close: close_1 });
  28. }
  29. return quotes;
  30. }
  31. };
  32. exports.getQuote = function (quotes, depth, open) {
  33. if (!quotes) {
  34. return '';
  35. }
  36. var quote = quotes[Math.min(depth, quotes.length - 1)];
  37. if (!quote) {
  38. return '';
  39. }
  40. return open ? quote.open : quote.close;
  41. };
  42. //# sourceMappingURL=quotes.js.map