shawnbot / sast

Parse CSS, Sass, SCSS, and Less into a unist syntax tree
The Unlicense
50 stars 5 forks source link

.stringify() parses curly braces for SASS #8

Open GavinRay97 opened 5 years ago

GavinRay97 commented 5 years ago

In stringify.js, mods.block is hardcoded to curlies.

If the argument signature is changed to:

const stringify = (node, options = { depth: 0, syntax: 'css' }) => {

and the mod declaration moved inside of the stringify closure, with one additional change made to buffer = node.children.reduce() so that it is

buffer = node.children.reduce(
  (buff, child) =>
    buff.concat(
      stringify(child, { depth: options.depth + 1, syntax: options.syntax }), // <-- PASSING OPTS HERE
    ),
  [],
)

Then we change mods.block

const mods = {
  'block': (options.syntax != 'sass') && curlies,
  // etc
}

The issue is resolved.

const sassAST = sast.parse(mockSASS, {syntax: 'sass'})
sast.stringify(sassAST, {syntax: 'sass'})

I can submit PR for this tomorrow.