source: trip-planner-front/node_modules/webpack-sources/lib/OriginalSource.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7var SourceNode = require("source-map").SourceNode;
8var SourceMapConsumer = require("source-map").SourceMapConsumer;
9var SourceListMap = require("source-list-map").SourceListMap;
10var Source = require("./Source");
11
12var SPLIT_REGEX = /(?!$)[^\n\r;{}]*[\n\r;{}]*/g;
13
14function _splitCode(code) {
15 return code.match(SPLIT_REGEX) || [];
16}
17
18class OriginalSource extends Source {
19 constructor(value, name) {
20 super();
21 this._value = value;
22 this._name = name;
23 }
24
25 source() {
26 return this._value;
27 }
28
29 node(options) {
30 options = options || {};
31 var sourceMap = this._sourceMap;
32 var value = this._value;
33 var name = this._name;
34 var lines = value.split("\n");
35 var node = new SourceNode(null, null, null,
36 lines.map(function(line, idx) {
37 var pos = 0;
38 if(options.columns === false) {
39 var content = line + (idx != lines.length - 1 ? "\n" : "");
40 return new SourceNode(idx + 1, 0, name, content);
41 }
42 return new SourceNode(null, null, null,
43 _splitCode(line + (idx != lines.length - 1 ? "\n" : "")).map(function(item) {
44 if(/^\s*$/.test(item)) {
45 pos += item.length;
46 return item;
47 }
48 var res = new SourceNode(idx + 1, pos, name, item);
49 pos += item.length;
50 return res;
51 })
52 );
53 })
54 );
55 node.setSourceContent(name, value);
56 return node;
57 }
58
59 listMap(options) {
60 return new SourceListMap(this._value, this._name, this._value)
61 }
62
63 updateHash(hash) {
64 hash.update(this._value);
65 }
66}
67
68require("./SourceAndMapMixin")(OriginalSource.prototype);
69
70module.exports = OriginalSource;
Note: See TracBrowser for help on using the repository browser.