Browse Source

Add failing test for nested mixins

master
Dylan Baker 3 years ago
parent
commit
325d70fc5e
2 changed files with 26 additions and 5 deletions
  1. 5
    5
      src/moss.ts
  2. 21
    0
      src/tests/compiler.test.ts

+ 5
- 5
src/moss.ts View File

@@ -9,10 +9,10 @@ import { EnvError } from './env';
9 9
 import Lexer, { LexerError } from './lexer';
10 10
 import Parser, { ParserError } from './parser';
11 11
 
12
-import { inspect } from 'util';
13
-const print = (obj: any) => {
14
-  console.log(inspect(obj, { depth: null }));
15
-};
12
+// import { inspect } from 'util';
13
+// const print = (obj: any) => {
14
+//   console.log(inspect(obj, { depth: null }));
15
+// };
16 16
 
17 17
 const rawArgs = minimist(process.argv.slice(2));
18 18
 
@@ -42,7 +42,7 @@ const moss = (
42 42
   } else {
43 43
     const parser = new Parser(tokens);
44 44
     const tree = parser.parse();
45
-    print(tree);
45
+    // print(tree);
46 46
     if (tree instanceof ParserError) {
47 47
       return tree;
48 48
     } else {

+ 21
- 0
src/tests/compiler.test.ts View File

@@ -181,3 +181,24 @@ test('compiles mixin application with children', (t) => {
181 181
   const result = compile('(@mixin heading-color ($color) (h1 :color $color))(div (@heading-color blue))');
182 182
   t.equal(result, 'div h1{color:blue;}');
183 183
 });
184
+
185
+test('compiles nested mixins', (t) => {
186
+  t.plan(1);
187
+  const result = compile(`
188
+    (@mixin v-gutters ($v)
189
+      :margin-top $v
190
+      :margin-bottom $v)
191
+
192
+    (@mixin h-gutters ($h)
193
+      :margin-left $h
194
+      :margin-right $h)
195
+
196
+    (@mixin gutters ($v $h)
197
+      (@v-gutters $v)
198
+      (@h-gutters $h))
199
+
200
+    (.container
201
+      (@gutters 50px 100px))
202
+  `);
203
+  t.equal(result, '.container{margin-top:50px;margin-bottom:50px;margin-left:100px;margin-right:100px;}');
204
+});

Loading…
Cancel
Save