Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 6 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 56 additions and 2 deletions.
  1. +8 −0 lib/visitor/compiler.js
  2. +41 −1 lib/visitor/evaluator.js
  3. +7 −1 lib/visitor/normalizer.js
View
8 lib/visitor/compiler.js
@@ -30,6 +30,7 @@ var Compiler = module.exports = function Compiler(root, options) {
this.compress = options.compress;
this.firebug = options.firebug;
this.linenos = options.linenos;
+ this._info = options._info;
this.spaces = options['indent spaces'] || 2;
this.includeCSS = options['include css'];
this.indents = 1;
@@ -337,6 +338,13 @@ Compiler.prototype.visitGroup = function(group){
// selectors
if (group.block.hasProperties) {
var selectors = this.compileSelectors(stack);
+ if (this._info) {
+ this._info.emit('selector',
+ selectors,
+ group.filename,
+ group.lineno || 1
+ );
+ }
this.buf += (this.selector = selectors.join(this.compress ? ',' : ',\n'));
}
View
42 lib/visitor/evaluator.js
@@ -262,10 +262,34 @@ Evaluator.prototype.visitFunction = function(fn){
var bif = bifs[fn.name];
if (bif) this.warn('built-in function "' + fn.name + '" is already defined');
+ var _info = this.options._info;
+ if (_info && this.options.filename === fn.filename) {
+ this._logInnerCalls(fn);
+ }
+
return fn;
};
/**
+ * Makes a sourcemap of inner calls inside (uncalled) function.
+ */
+
+Evaluator.prototype._logInnerCalls = function (node) {
+ var nodes = node.nodes || node.block && node.block.nodes;
+ if (!nodes) return;
+ var self = this;
+ return nodes.forEach(function (n) {
+ if (n.nodeName === 'call') {
+ var fn = self.lookup(n.name);
+ if (fn) {
+ self.options._info.emit('call', n.lineno - 1 || 0, n.name, fn.filename, fn.lineno);
+ }
+ }
+ self._logInnerCalls(n);
+ });
+}
+
+/**
* Visit Each.
*/
@@ -353,7 +377,18 @@ Evaluator.prototype.visitCall = function(call){
// User-defined
} else if ('function' == fn.nodeName) {
debug('%s is user-defined', call);
+ var _info = this.options._info;
+ if (_info && call.filename === this.filename) {
+ _info.emit('call', call.lineno - 1 || 0, call.name, fn.filename, fn.lineno);
+ }
+ // Mark arguments so they won't be logged.
+ args.nodes.forEach(function(n) {
+ n._inCall = true;
+ })
ret = this.invokeFunction(fn, args);
+ args.nodes.forEach(function(n) {
+ n._inCall = null;
+ })
}
// restore kwargs
@@ -381,6 +416,11 @@ Evaluator.prototype.visitIdent = function(ident){
// Lookup
} else if (ident.val.isNull) {
var val = this.lookup(ident.name);
+ if(val) {
+ if (this.options._info && ident.filename == this.options.filename && !val._inCall) {
+ this.options._info.emit('ident', ident.lineno, ident.name, val.filename, val.lineno);
+ }
+ }
return val ? this.visit(val) : ident;
// Assign
} else {
@@ -619,7 +659,7 @@ Evaluator.prototype.visitIf = function(node){
Evaluator.prototype.visitExtend = function(extend){
var selector = extend.selector;
var block = !this.currentBlock.node.extends && this.targetBlock.node.extends ? this.targetBlock : this.currentBlock;
- block.node.extends.push(selector);
+ block.node.extends.push(extend);
return nodes.null;
};
View
8 lib/visitor/normalizer.js
@@ -34,6 +34,7 @@ var Normalizer = module.exports = function Normalizer(root, options) {
this.stack = [];
this.extends = {};
this.map = {};
+ this.options = options;
};
/**
@@ -208,13 +209,18 @@ Normalizer.prototype.extend = function(group, selectors){
, self = this;
group.extends.forEach(function(extend){
- var groups = map[extend];
+ var groups = map[extend.selector];
if (!groups) throw new Error('Failed to @extend "' + extend + '"');
+
selectors.forEach(function(selector){
var node = new nodes.Selector;
node.val = selector;
node.inherits = false;
groups.forEach(function(group){
+ if (self.options._info && extend.filename === self.options.filename) {
+ self.options._info.emit('extend', extend.lineno, extend.selector,
+ group.filename, group.lineno);
+ }
self.extend(group, selectors);
group.push(node);
});

No commit comments for this range

Something went wrong with that request. Please try again.