From 587475aaa2b1f1ef5fe656a593350ac371bb39ae Mon Sep 17 00:00:00 2001 From: raivaibhav Date: Mon, 11 Oct 2021 14:13:21 +0530 Subject: [PATCH] Format space in node type value --- src/compiler/compile/css/Stylesheet.ts | 25 ++++++++++--------- .../samples/supports-font-face/expected.css | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/compiler/compile/css/Stylesheet.ts b/src/compiler/compile/css/Stylesheet.ts index 760dc1bf5d..a3a380da5d 100644 --- a/src/compiler/compile/css/Stylesheet.ts +++ b/src/compiler/compile/css/Stylesheet.ts @@ -1,5 +1,4 @@ import MagicString, { OverwriteOptions } from 'magic-string'; -import generate from 'css-tree/lib/generator/index.js'; import { walk } from 'estree-walker'; import Selector from './Selector'; import Element from '../nodes/Element'; @@ -528,19 +527,21 @@ export default class Stylesheet { walk(this.ast.css.children as any, { enter: (node: any, parent: any) => { if (node.children && node.type === 'Value') { - const abc = generate(parent); - console.log(abc); let c = node.start; node.children.forEach((child: any, i: number) => { - if (child.type !== 'WhiteSpace') { - if (i > 0) { - if (child.type === 'Operator') { - code.remove(c, child.start); - } else { - overwrite(code, c, child.start, format ? ' ' : ''); - } - } - c = child.end; + if (i > 0) { + if (child.type === 'WhiteSpace') { + !format && c++; + } else if (child.type === 'Operator') { + code.remove(c, child.start); + c = child.end; + } else { + format && overwrite(code, c, child.start, ' '); + !format && code.remove(c, child.start); + c = child.end; + } + } else { + c = child.end; } }); } diff --git a/test/css/samples/supports-font-face/expected.css b/test/css/samples/supports-font-face/expected.css index 652ecb1dc2..2ae43221b1 100644 --- a/test/css/samples/supports-font-face/expected.css +++ b/test/css/samples/supports-font-face/expected.css @@ -1 +1 @@ -@font-face{font-family:MyHelvetica;src:local('Helvetica Neue Bold'), local('HelveticaNeue-Bold'), url(MgOpenModernaBold.ttf);font-weight:bold} \ No newline at end of file +@font-face{font-family:MyHelvetica;src:local('Helvetica Neue Bold'),local('HelveticaNeue-Bold'),url(MgOpenModernaBold.ttf);font-weight:bold} \ No newline at end of file