You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

2 years ago
  1. 'use strict'
  2. let Container = require('./container')
  3. let Parser = require('./parser')
  4. let Input = require('./input')
  5. function parse(css, opts) {
  6. let input = new Input(css, opts)
  7. let parser = new Parser(input)
  8. try {
  9. parser.parse()
  10. } catch (e) {
  11. if (process.env.NODE_ENV !== 'production') {
  12. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  13. if (/\.scss$/i.test(opts.from)) {
  14. e.message +=
  15. '\nYou tried to parse SCSS with ' +
  16. 'the standard CSS parser; ' +
  17. 'try again with the postcss-scss parser'
  18. } else if (/\.sass/i.test(opts.from)) {
  19. e.message +=
  20. '\nYou tried to parse Sass with ' +
  21. 'the standard CSS parser; ' +
  22. 'try again with the postcss-sass parser'
  23. } else if (/\.less$/i.test(opts.from)) {
  24. e.message +=
  25. '\nYou tried to parse Less with ' +
  26. 'the standard CSS parser; ' +
  27. 'try again with the postcss-less parser'
  28. }
  29. }
  30. }
  31. throw e
  32. }
  33. return parser.root
  34. }
  35. module.exports = parse
  36. parse.default = parse
  37. Container.registerParse(parse)