Procházet zdrojové kódy

Add failing test for nested mixins

master
Dylan Baker před 5 roky
rodič
revize
325d70fc5e
2 změnil soubory, kde provedl 26 přidání a 5 odebrání
  1. 5
    5
      src/moss.ts
  2. 21
    0
      src/tests/compiler.test.ts

+ 5
- 5
src/moss.ts Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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
+});

Načítá se…
Zrušit
Uložit