a zip code crypto-currency system good for red ONLY

parse-imports.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var tokenizer = require('scss-tokenizer');
  2. function parseImports(content, isIndentedSyntax) {
  3. var tokens = tokenizer.tokenize(content);
  4. var results = [];
  5. var tmp = '';
  6. var inImport = false;
  7. var inParen = false;
  8. var prevToken = tokens[0];
  9. var i, token;
  10. for (i = 1; i < tokens.length; i++) {
  11. token = tokens[i];
  12. if (inImport && !inParen && token[0] === 'string') {
  13. results.push(token[1]);
  14. }
  15. else if (token[1] === 'import' && prevToken[1] === '@') {
  16. if (inImport && !isIndentedSyntax) {
  17. throw new Error('Encountered invalid @import syntax.');
  18. }
  19. inImport = true;
  20. }
  21. else if (inImport && !inParen && (token[0] === 'ident' || token[0] === '/')) {
  22. tmp += token[1];
  23. }
  24. else if (inImport && !inParen && (token[0] === 'space' || token[0] === 'newline')) {
  25. if (tmp !== '') {
  26. results.push(tmp);
  27. tmp = '';
  28. if (isIndentedSyntax) {
  29. inImport = false;
  30. }
  31. }
  32. }
  33. else if (inImport && token[0] === ';') {
  34. inImport = false;
  35. if (tmp !== '') {
  36. results.push(tmp);
  37. tmp = '';
  38. }
  39. }
  40. else if (inImport && token[0] === '(') {
  41. inParen = true;
  42. tmp = '';
  43. }
  44. else if (inParen && token[0] === ')') {
  45. inParen = false;
  46. }
  47. prevToken = token;
  48. }
  49. if (tmp !== '') {
  50. results.push(tmp);
  51. }
  52. return results;
  53. }
  54. module.exports = parseImports;