shama/stylus-loader — pull request #15 by DaQuirm (2014-08-16 18:21:25+00:00)
Title: Fix/import mixin call

Stylus-loader misplaces blocks resulting from mixin calls inside imported stylesheets' roots (see test).
This happens because all imported root blocks are first created by the `listImports` function with no block context and are cached by the Stylus parser. They resurface again when the actual parsing/evaluation occurs and, having no parent blocks, may cause context-related errors.

For instance, a block's visit method is determined by its constructor function name. When `listImports` uses the `Parser` class, it creates a `Root` block because `listImports` doesn't pass any parent block:

`Parser` constructor
```js
this.root = options.root || new nodes.Root;
```

`Parser.parse` method
```
parse: function(){
var block = this.parent = this.root;
...
return block;
},
```

while normally a `Block` block is created for imported stylesheet root scope. The difference is crucial because when visited, a `Block` block is pushed to the stack whereas `Root` blocks have another kind of adventure. Therefore the stack doesn't contain a frame for the imported stylesheet and when mixins are invoked in the root scope of this stylesheets their resulting body blocks are provided with a wrong context. In the test due to a context issue `.rule` gets overwritten because mixin "target" block is the whole imported file, not the mixin call placeholder.

The proposed solution is to disable parser caching altogether in `listImports`. Passing `{ cache: false }` makes the parser use "null" cache that doesn't actually store anything (see parser & cache Stylus modules).

Phew, that was quite a Saturday! :smile_cat: