From e429de61e52574316dd3927ff5415fc2d3e20c9b Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Thu, 29 May 2014 07:04:42 +0200 Subject: [PATCH] Never add source mappings at the end of nodes It is completely useless and only makes the source map unnecessarily large. --- lib/compress.js | 18 +++++++++--------- lib/identity.js | 18 +++++++++--------- lib/source-map-support.js | 16 ---------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index bdd5f1f..60d7b53 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -56,7 +56,7 @@ Compiler.prototype.import = function(node){ */ Compiler.prototype.media = function(node){ - return this.emit('@media ' + node.media, node.position, true) + return this.emit('@media ' + node.media, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}'); @@ -69,7 +69,7 @@ Compiler.prototype.media = function(node){ Compiler.prototype.document = function(node){ var doc = '@' + (node.vendor || '') + 'document ' + node.document; - return this.emit(doc, node.position, true) + return this.emit(doc, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}'); @@ -96,7 +96,7 @@ Compiler.prototype.namespace = function(node){ */ Compiler.prototype.supports = function(node){ - return this.emit('@supports ' + node.supports, node.position, true) + return this.emit('@supports ' + node.supports, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}'); @@ -110,7 +110,7 @@ Compiler.prototype.keyframes = function(node){ return this.emit('@' + (node.vendor || '') + 'keyframes ' - + node.name, node.position, true) + + node.name, node.position) + this.emit('{') + this.mapVisit(node.keyframes) + this.emit('}'); @@ -123,7 +123,7 @@ Compiler.prototype.keyframes = function(node){ Compiler.prototype.keyframe = function(node){ var decls = node.declarations; - return this.emit(node.values.join(','), node.position, true) + return this.emit(node.values.join(','), node.position) + this.emit('{') + this.mapVisit(decls) + this.emit('}'); @@ -138,7 +138,7 @@ Compiler.prototype.page = function(node){ ? node.selectors.join(', ') : ''; - return this.emit('@page ' + sel, node.position, true) + return this.emit('@page ' + sel, node.position) + this.emit('{') + this.mapVisit(node.declarations) + this.emit('}'); @@ -149,7 +149,7 @@ Compiler.prototype.page = function(node){ */ Compiler.prototype['font-face'] = function(node){ - return this.emit('@font-face', node.position, true) + return this.emit('@font-face', node.position) + this.emit('{') + this.mapVisit(node.declarations) + this.emit('}'); @@ -160,7 +160,7 @@ Compiler.prototype['font-face'] = function(node){ */ Compiler.prototype.host = function(node){ - return this.emit('@host', node.position, true) + return this.emit('@host', node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}'); @@ -182,7 +182,7 @@ Compiler.prototype.rule = function(node){ var decls = node.declarations; if (!decls.length) return ''; - return this.emit(node.selectors.join(','), node.position, true) + return this.emit(node.selectors.join(','), node.position) + this.emit('{') + this.mapVisit(decls) + this.emit('}'); diff --git a/lib/identity.js b/lib/identity.js index 9c8d3c9..fe84676 100644 --- a/lib/identity.js +++ b/lib/identity.js @@ -64,7 +64,7 @@ Compiler.prototype.import = function(node){ */ Compiler.prototype.media = function(node){ - return this.emit('@media ' + node.media, node.position, true) + return this.emit('@media ' + node.media, node.position) + this.emit( ' {\n' + this.indent(1)) @@ -81,7 +81,7 @@ Compiler.prototype.media = function(node){ Compiler.prototype.document = function(node){ var doc = '@' + (node.vendor || '') + 'document ' + node.document; - return this.emit(doc, node.position, true) + return this.emit(doc, node.position) + this.emit( ' ' + ' {\n' @@ -113,7 +113,7 @@ Compiler.prototype.namespace = function(node){ */ Compiler.prototype.supports = function(node){ - return this.emit('@supports ' + node.supports, node.position, true) + return this.emit('@supports ' + node.supports, node.position) + this.emit( ' {\n' + this.indent(1)) @@ -128,7 +128,7 @@ Compiler.prototype.supports = function(node){ */ Compiler.prototype.keyframes = function(node){ - return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position, true) + return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position) + this.emit( ' {\n' + this.indent(1)) @@ -146,7 +146,7 @@ Compiler.prototype.keyframe = function(node){ var decls = node.declarations; return this.emit(this.indent()) - + this.emit(node.values.join(', '), node.position, true) + + this.emit(node.values.join(', '), node.position) + this.emit( ' {\n' + this.indent(1)) @@ -166,7 +166,7 @@ Compiler.prototype.page = function(node){ ? node.selectors.join(', ') + ' ' : ''; - return this.emit('@page ' + sel, node.position, true) + return this.emit('@page ' + sel, node.position) + this.emit('{\n') + this.emit(this.indent(1)) + this.mapVisit(node.declarations, '\n') @@ -179,7 +179,7 @@ Compiler.prototype.page = function(node){ */ Compiler.prototype['font-face'] = function(node){ - return this.emit('@font-face ', node.position, true) + return this.emit('@font-face ', node.position) + this.emit('{\n') + this.emit(this.indent(1)) + this.mapVisit(node.declarations, '\n') @@ -192,7 +192,7 @@ Compiler.prototype['font-face'] = function(node){ */ Compiler.prototype.host = function(node){ - return this.emit('@host', node.position, true) + return this.emit('@host', node.position) + this.emit( ' {\n' + this.indent(1)) @@ -219,7 +219,7 @@ Compiler.prototype.rule = function(node){ var decls = node.declarations; if (!decls.length) return ''; - return this.emit(node.selectors.map(function(s){ return indent + s }).join(',\n'), node.position, true) + return this.emit(node.selectors.map(function(s){ return indent + s }).join(',\n'), node.position) + this.emit(' {\n') + this.emit(this.indent(1)) + this.mapVisit(decls, '\n') diff --git a/lib/source-map-support.js b/lib/source-map-support.js index 8ae8c53..5d8fd81 100644 --- a/lib/source-map-support.js +++ b/lib/source-map-support.js @@ -75,22 +75,6 @@ exports.emit = function(str, pos, startOnly) { this.updatePosition(str); - if (!startOnly && pos && pos.end) { - this.map.addMapping({ - source: sourceFile, - generated: { - line: this.position.line, - column: Math.max(this.position.column - 1, 0) - }, - original: { - line: pos.end.line, - column: pos.end.column - 1 - } - }); - - this.addFile(pos); - } - return str; };