Comparing version 2.1.0-rc.1 to 2.1.0-rc.2
@@ -22,3 +22,3 @@ var inherit = require('inherit'); | ||
/** | ||
* @callback readWhileCallback | ||
* @callback whileCallback | ||
* @param {Mapping} mapping | ||
@@ -28,3 +28,19 @@ * @return {Boolean} | ||
/** | ||
* @param {readWhileCallback} fn | ||
* @param {whileCallback} fn | ||
*/ | ||
skipWhile: function(fn) { | ||
var mappings = this.mappings; | ||
var len = mappings.length; | ||
while (this.position < len) { | ||
var mapping = mappings[this.position]; | ||
if (!fn(mapping)) { | ||
break; | ||
} | ||
++this.position; | ||
} | ||
}, | ||
/** | ||
* @param {whileCallback} fn | ||
* @returns {Mapping[]} | ||
@@ -31,0 +47,0 @@ */ |
var path = require('path'); | ||
var inherit = require('inherit'); | ||
var Concater = require('./concater'); | ||
var Builder = require('./builder'); | ||
var SourceMapRegistry = require('./source-map-registry'); | ||
@@ -28,3 +28,3 @@ var nodes = require('./nodes'); | ||
this.concater = new Concater({ | ||
this.builder = new Builder({ | ||
generateSourceMap: !!options.sourceMap, | ||
@@ -48,3 +48,3 @@ sourceMapFilename: options.sourceMapFilename, | ||
/** | ||
* @returns {Concater} | ||
* @returns {Builder} | ||
*/ | ||
@@ -54,12 +54,13 @@ serialize: function() { | ||
var options = this.options; | ||
var concater = this.concater; | ||
var builder = this.builder; | ||
var inputSourceMap = options.sourceMap && options.inputSourceMap; | ||
this.nodes.forEach(function addToConcater(node) { | ||
if (node instanceof nodes.IncludeNode) { | ||
node.eachChild(addToConcater); | ||
this.nodes.forEach(function append(node, i) { | ||
if (node.hasChildren()) { | ||
node.eachChild(append); | ||
} else { | ||
var resetFile = i === 0; | ||
var mappings = inputSourceMap ? self.getMappingsForNode(node) : null; | ||
concater.concat(path.relative(options.sourceMapRoot, node.path), node, mappings); | ||
builder.append(path.relative(options.sourceMapRoot, node.path), node, mappings, resetFile); | ||
} | ||
@@ -74,3 +75,3 @@ | ||
return concater; | ||
return builder; | ||
}, | ||
@@ -97,3 +98,3 @@ | ||
var lastLine = firstLine + linesCount - 1; | ||
// First column starts after borschik's directives, if any. | ||
// First column starts after borschik's directive. | ||
var firstColumn = mappingsIterator.lastColumn + (passedDirective ? passedDirective.length : 0); | ||
@@ -103,3 +104,3 @@ // One-liners should add the start offset to the end offset. -1 since columns are 0-based; | ||
mappingsIterator.readWhile(function(m) { | ||
mappingsIterator.skipWhile(function(m) { | ||
return m.generatedLine === firstLine && m.generatedColumn < firstColumn; | ||
@@ -111,4 +112,3 @@ }); | ||
// Correct mappings – treat every node as a separate file, | ||
// so mappings should starts from the [1, 0] (line, column). | ||
// Correct offsets. | ||
mappings.forEach(function(m) { | ||
@@ -120,3 +120,3 @@ m.generatedColumn = m.generatedColumn - (m.generatedLine === firstLine ? firstColumn : 0); | ||
mappingsIterator.lastLine = lastLine; | ||
mappingsIterator.lastColumn = node instanceof nodes.LinkURLNode ? firstColumn : (lastColumn + 1); | ||
mappingsIterator.lastColumn = node.ignoreMappings() ? firstColumn : (lastColumn + 1); | ||
@@ -123,0 +123,0 @@ return mappings; |
@@ -38,2 +38,9 @@ var inherit = require('inherit'); | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
hasChildren: function() { | ||
return false; | ||
}, | ||
/** | ||
* @returns {String} | ||
@@ -50,2 +57,11 @@ */ | ||
return this._lines || (this._lines = this.getContent().split(/\r?\n/)); | ||
}, | ||
/** | ||
* Whether node should be excluded from mappings. | ||
* | ||
* @returns {Boolean} | ||
*/ | ||
ignoreMappings: function() { | ||
return false; | ||
} | ||
@@ -58,5 +74,19 @@ }, { | ||
var LinkURLNode = BaseNode.inherit(); | ||
var CommentNode = StringNode.inherit({ | ||
ignoreMappings: function() { | ||
return true; | ||
} | ||
}); | ||
var LinkURLNode = BaseNode.inherit({ | ||
ignoreMappings: function() { | ||
return true; | ||
} | ||
}); | ||
var IncludeNode = BaseNode.inherit({ | ||
hasChildren: function() { | ||
return true; | ||
}, | ||
getContent: function() { | ||
@@ -85,3 +115,3 @@ if (this._serialized !== undefined) { | ||
if (this.commentsWrap) { | ||
fn(new StringNode(commentsWrapBegin(this.commentsWrap), this.path)); | ||
fn(new CommentNode(commentsWrapBegin(this.commentsWrap), this.path)); | ||
} | ||
@@ -92,3 +122,3 @@ | ||
if (this.commentsWrap) { | ||
fn(new StringNode(commentsWrapEnd(this.commentsWrap), this.path)); | ||
fn(new CommentNode(commentsWrapEnd(this.commentsWrap), this.path)); | ||
} | ||
@@ -118,2 +148,3 @@ }, | ||
StringNode: StringNode, | ||
CommentNode: CommentNode, | ||
LinkURLNode: LinkURLNode, | ||
@@ -120,0 +151,0 @@ IncludeNode: IncludeNode, |
{ | ||
"name": "borschik", | ||
"description": "Extendable builder for text-based file formats", | ||
"version": "2.1.0-rc.1", | ||
"version": "2.1.0-rc.2", | ||
"homepage": "http://github.com/borschik/borschik", | ||
@@ -6,0 +6,0 @@ "author": "Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
88953
1977