Socket
Socket
Sign inDemoInstall

webpack-sources

Package Overview
Dependencies
Maintainers
5
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-sources - npm Package Compare versions

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

lib/applySourceMap.js

54

lib/PrefixSource.js

@@ -13,23 +13,2 @@ /*

function cloneAndPrefix(node, prefix, append) {
if (typeof node === "string") {
let result = node.replace(REPLACE_REGEX, "\n" + prefix);
if (append.length > 0) result = append.pop() + result;
if (/\n$/.test(node)) append.push(prefix);
return result;
} else {
const newNode = new SourceNode(
node.line,
node.column,
node.source,
node.children.map(function(node) {
return cloneAndPrefix(node, prefix, append);
}),
node.name
);
newNode.sourceContents = node.sourceContents;
return newNode;
}
}
class PrefixSource extends Source {

@@ -59,6 +38,31 @@ constructor(prefix, source) {

const node = this._source.node(options);
const append = [this._prefix];
return new SourceNode(null, null, null, [
cloneAndPrefix(node, this._prefix, append)
]);
const prefix = this._prefix;
const output = [];
const result = new SourceNode();
node.walkSourceContents(function(source, content) {
result.setSourceContent(source, content);
});
let needPrefix = true;
node.walk(function(chunk, mapping) {
const parts = chunk.split("\n");
for (let i = 0; i < parts.length; i += 2) {
const nl = i + 1 < parts.length;
const part = parts[i] + (nl ? "\n" : "");
if (part && needPrefix) {
output.push(prefix);
}
output.push(
new SourceNode(
mapping.line,
mapping.column,
mapping.source,
chunk,
mapping.name
)
);
needPrefix = nl;
}
});
result.add(output);
return result;
}

@@ -65,0 +69,0 @@

@@ -8,12 +8,16 @@ /*

const Source = require("./Source");
const {
SourceNode,
SourceMapConsumer,
SourceMapGenerator
} = require("source-map");
const { SourceNode, SourceMapConsumer } = require("source-map");
const { SourceListMap, fromStringWithSourceMap } = require("source-list-map");
const { getSourceAndMap, getMap } = require("./helpers");
const applySourceMap = require("./applySourceMap");
class SourceMapSource extends Source {
constructor(value, name, sourceMap, originalSource, innerSourceMap) {
constructor(
value,
name,
sourceMap,
originalSource,
innerSourceMap,
removeOriginalSource
) {
super();

@@ -25,2 +29,3 @@ this._value = value;

this._innerSourceMap = innerSourceMap;
this._removeOriginalSource = removeOriginalSource;
}

@@ -55,18 +60,18 @@

node(options) {
const sourceMap = this._sourceMap;
let node = SourceNode.fromStringWithSourceMap(
this._value,
new SourceMapConsumer(sourceMap)
);
node.setSourceContent(this._name, this._originalSource);
const innerSourceMap = this._innerSourceMap;
let sourceMap = this._sourceMap;
if (innerSourceMap) {
const sourceMapGen = SourceMapGenerator.fromSourceMap(
new SourceMapConsumer(sourceMap)
node = applySourceMap(
node,
new SourceMapConsumer(innerSourceMap),
this._name,
this._removeOriginalSource
);
if (this._originalSource)
sourceMapGen.setSourceContent(this._name, this._originalSource);
const innerSourceMapConsumer = new SourceMapConsumer(innerSourceMap);
sourceMapGen.applySourceMap(innerSourceMapConsumer, this._name);
sourceMap = sourceMapGen.toJSON();
}
return SourceNode.fromStringWithSourceMap(
this._value,
new SourceMapConsumer(sourceMap)
);
return node;
}

@@ -73,0 +78,0 @@

{
"name": "webpack-sources",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "Source code handling classes for webpack",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -105,3 +105,4 @@ # webpack-sources

originalSource?: String,
innerSourceMap?: Object | String
innerSourceMap?: Object | String,
removeOriginalSource?: boolean
)

@@ -115,3 +116,8 @@ ```

- `innerSourceMap`: The SourceMap for the `originalSource`/`name`.
- `removeOriginalSource`: Removes the source code for `name` from the final map, keeping only the deeper mappings for that file.
The `SourceMapSource` supports "identity" mappings for the `innerSourceMap`.
When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to keep finer mappings from `sourceMap`.
## `CachedSource`

@@ -161,2 +167,5 @@

The `ReplaceSource` supports "identity" mappings for child source.
When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.
### Public methods

@@ -163,0 +172,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc