parse.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. exports.__esModule = true;
  3. exports.default = parse;
  4. var _parser = require('./parser');
  5. var _parser2 = _interopRequireDefault(_parser);
  6. var _input = require('./input');
  7. var _input2 = _interopRequireDefault(_input);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function parse(css, opts) {
  10. if (opts && opts.safe) {
  11. throw new Error('Option safe was removed. ' + 'Use parser: require("postcss-safe-parser")');
  12. }
  13. var input = new _input2.default(css, opts);
  14. var parser = new _parser2.default(input);
  15. try {
  16. parser.tokenize();
  17. parser.loop();
  18. } catch (e) {
  19. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  20. if (/\.scss$/i.test(opts.from)) {
  21. e.message += '\nYou tried to parse SCSS with ' + 'the standard CSS parser; ' + 'try again with the postcss-scss parser';
  22. } else if (/\.less$/i.test(opts.from)) {
  23. e.message += '\nYou tried to parse Less with ' + 'the standard CSS parser; ' + 'try again with the postcss-less parser';
  24. }
  25. }
  26. throw e;
  27. }
  28. return parser.root;
  29. }
  30. module.exports = exports['default'];
  31. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBhcnNlLmVzNiJdLCJuYW1lcyI6WyJwYXJzZSIsImNzcyIsIm9wdHMiLCJzYWZlIiwiRXJyb3IiLCJpbnB1dCIsInBhcnNlciIsInRva2VuaXplIiwibG9vcCIsImUiLCJuYW1lIiwiZnJvbSIsInRlc3QiLCJtZXNzYWdlIiwicm9vdCJdLCJtYXBwaW5ncyI6Ijs7O2tCQUd3QkEsSzs7QUFIeEI7Ozs7QUFDQTs7Ozs7O0FBRWUsU0FBU0EsS0FBVCxDQUFlQyxHQUFmLEVBQW9CQyxJQUFwQixFQUEwQjtBQUNyQyxRQUFLQSxRQUFRQSxLQUFLQyxJQUFsQixFQUF5QjtBQUNyQixjQUFNLElBQUlDLEtBQUosQ0FBVSw4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59XG4iXX0=