2023-08-17 09:47:40 +00:00
|
|
|
'use strict'
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
let Container = require('./container')
|
|
|
|
let Parser = require('./parser')
|
|
|
|
let Input = require('./input')
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
function parse(css, opts) {
|
2023-08-17 09:47:40 +00:00
|
|
|
let input = new Input(css, opts)
|
|
|
|
let parser = new Parser(input)
|
2022-01-21 08:28:41 +00:00
|
|
|
try {
|
2023-08-17 09:47:40 +00:00
|
|
|
parser.parse()
|
2022-01-21 08:28:41 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
if (e.name === 'CssSyntaxError' && opts && opts.from) {
|
|
|
|
if (/\.scss$/i.test(opts.from)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
e.message +=
|
|
|
|
'\nYou tried to parse SCSS with ' +
|
|
|
|
'the standard CSS parser; ' +
|
|
|
|
'try again with the postcss-scss parser'
|
2022-01-21 08:28:41 +00:00
|
|
|
} else if (/\.sass/i.test(opts.from)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
e.message +=
|
|
|
|
'\nYou tried to parse Sass with ' +
|
|
|
|
'the standard CSS parser; ' +
|
|
|
|
'try again with the postcss-sass parser'
|
2022-01-21 08:28:41 +00:00
|
|
|
} else if (/\.less$/i.test(opts.from)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
e.message +=
|
|
|
|
'\nYou tried to parse Less with ' +
|
|
|
|
'the standard CSS parser; ' +
|
|
|
|
'try again with the postcss-less parser'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
throw e
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
return parser.root
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = parse
|
|
|
|
parse.default = parse
|
|
|
|
|
|
|
|
Container.registerParse(parse)
|