wallet-core/node_modules/webpack-sources/lib/ConcatSource.js

92 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-05-03 15:35:00 +02:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2017-08-14 05:01:11 +02:00
"use strict";
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
const SourceNode = require("source-map").SourceNode;
const SourceListMap = require("source-list-map").SourceListMap;
const Source = require("./Source");
class ConcatSource extends Source {
constructor() {
super();
2017-12-10 21:51:33 +01:00
this.children = [];
for(var i = 0; i < arguments.length; i++) {
var item = arguments[i];
if(item instanceof ConcatSource) {
var children = item.children;
for(var j = 0; j < children.length; j++)
this.children.push(children[j]);
} else {
this.children.push(item);
}
}
2017-08-14 05:01:11 +02:00
}
add(item) {
2017-12-10 21:51:33 +01:00
if(item instanceof ConcatSource) {
var children = item.children;
for(var j = 0; j < children.length; j++)
this.children.push(children[j]);
} else {
this.children.push(item);
}
2017-08-14 05:01:11 +02:00
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
source() {
2017-12-10 21:51:33 +01:00
let source = "";
const children = this.children;
for(let i = 0; i < children.length; i++) {
const child = children[i];
source += typeof child === "string" ? child : child.source();
}
return source;
2017-08-14 05:01:11 +02:00
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
size() {
2017-12-10 21:51:33 +01:00
let size = 0;
const children = this.children;
for(let i = 0; i < children.length; i++) {
const child = children[i];
size += typeof child === "string" ? child.length : child.size();
}
return size;
2017-08-14 05:01:11 +02:00
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
node(options) {
const node = new SourceNode(null, null, null, this.children.map(function(item) {
return typeof item === "string" ? item : item.node(options);
}));
return node;
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
listMap(options) {
const map = new SourceListMap();
2017-12-10 21:51:33 +01:00
var children = this.children;
for(var i = 0; i < children.length; i++) {
var item = children[i];
2017-08-14 05:01:11 +02:00
if(typeof item === "string")
map.add(item);
else
map.add(item.listMap(options));
2017-12-10 21:51:33 +01:00
}
2017-08-14 05:01:11 +02:00
return map;
}
updateHash(hash) {
2017-12-10 21:51:33 +01:00
var children = this.children;
for(var i = 0; i < children.length; i++) {
var item = children[i];
2017-08-14 05:01:11 +02:00
if(typeof item === "string")
hash.update(item);
else
item.updateHash(hash);
2017-12-10 21:51:33 +01:00
}
2017-08-14 05:01:11 +02:00
}
}
2017-05-03 15:35:00 +02:00
require("./SourceAndMapMixin")(ConcatSource.prototype);
2017-08-14 05:01:11 +02:00
module.exports = ConcatSource;