syntax.js 683 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. const postcssParse = require("postcss/lib/parse");
  3. const TemplateParser = require("./template-parser");
  4. const TemplateSafeParser = require("./template-safe-parser");
  5. const Input = require("postcss/lib/input");
  6. function templateParse(css, opts, Parser) {
  7. const input = new Input(css, opts);
  8. const parser = new Parser(input);
  9. parser.parse();
  10. return parser.root;
  11. }
  12. module.exports = function buildTemplateSyntax(baseSyntax) {
  13. return {
  14. parse(css, opts) {
  15. return templateParse(
  16. css,
  17. opts,
  18. baseSyntax.parse === postcssParse ? TemplateParser : TemplateSafeParser
  19. );
  20. },
  21. stringify(...args) {
  22. return baseSyntax.stringify(...args);
  23. },
  24. };
  25. };