source: trip-planner-front/node_modules/postcss-import/lib/process-content.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"use strict"
2
3// builtin tooling
4const path = require("path")
5
6// placeholder tooling
7let sugarss
8
9module.exports = function processContent(
10 result,
11 content,
12 filename,
13 options,
14 postcss
15) {
16 const { plugins } = options
17 const ext = path.extname(filename)
18
19 const parserList = []
20
21 // SugarSS support:
22 if (ext === ".sss") {
23 if (!sugarss) {
24 try {
25 sugarss = require("sugarss")
26 } catch {} // Ignore
27 }
28 if (sugarss)
29 return runPostcss(postcss, content, filename, plugins, [sugarss])
30 }
31
32 // Syntax support:
33 if (result.opts.syntax && result.opts.syntax.parse) {
34 parserList.push(result.opts.syntax.parse)
35 }
36
37 // Parser support:
38 if (result.opts.parser) parserList.push(result.opts.parser)
39 // Try the default as a last resort:
40 parserList.push(null)
41
42 return runPostcss(postcss, content, filename, plugins, parserList)
43}
44
45function runPostcss(postcss, content, filename, plugins, parsers, index) {
46 if (!index) index = 0
47 return postcss(plugins)
48 .process(content, {
49 from: filename,
50 parser: parsers[index],
51 })
52 .catch(err => {
53 // If there's an error, try the next parser
54 index++
55 // If there are no parsers left, throw it
56 if (index === parsers.length) throw err
57 return runPostcss(postcss, content, filename, plugins, parsers, index)
58 })
59}
Note: See TracBrowser for help on using the repository browser.