Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

recast

Package Overview
Dependencies
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recast - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

40

lib/lines.js

@@ -141,21 +141,35 @@ var assert = require("assert");

Lp.getSourceMap = function(sourceMapName) {
isString.assert(sourceMapName);
Lp.getSourceMap = function(sourceMapName, sourceRoot) {
if (!sourceMapName) {
// Although we could make up a name or generate an anonymous
// source map, instead we assume that any consumer who does not
// provide a name does not actually want a source map.
return null;
}
var targetLines = this;
var secret = getSecret(targetLines);
if (secret.cachedSourceMap) {
// Since Lines objects are immutable, we can reuse any source map
// that was previously generated.
var json = secret.cachedSourceMap.toJSON();
function updateJSON(json) {
json = json || {};
// In case the name of the requested source map is different from
// what was previously cached, update the JSON.
isString.assert(sourceMapName);
json.file = sourceMapName;
// Return a new JSON object to protect the cached source map from
// outside modification.
if (sourceRoot) {
isString.assert(sourceRoot);
json.sourceRoot = sourceRoot;
}
return json;
}
var secret = getSecret(targetLines);
if (secret.cachedSourceMap) {
// Since Lines objects are immutable, we can reuse any source map
// that was previously generated. Nevertheless, we return a new
// JSON object here to protect the cached source map from outside
// modification.
return updateJSON(secret.cachedSourceMap.toJSON());
}
assert.ok(

@@ -167,5 +181,3 @@ secret.mappings.length > 0,

var smg = new sourceMap.SourceMapGenerator({
file: sourceMapName
});
var smg = new sourceMap.SourceMapGenerator(updateJSON());

@@ -172,0 +184,0 @@ secret.mappings.forEach(function(mapping) {

@@ -8,2 +8,3 @@ var defaults = {

sourceMapName: null,
sourceRoot: null,
esprima: require("esprima"),

@@ -31,2 +32,3 @@ range: false,

sourceMapName: get("sourceMapName"),
sourceRoot: get("sourceRoot"),
esprima: get("esprima"),

@@ -33,0 +35,0 @@ range: get("range"),

@@ -86,6 +86,8 @@ var assert = require("assert");

var lines = print(new NodePath(ast), true);
var mapName = options.sourceMapName;
return new PrintResult(
lines.toString(options),
mapName && lines.getSourceMap(mapName)
lines.getSourceMap(
options.sourceMapName,
options.sourceRoot
)
);

@@ -92,0 +94,0 @@ };

@@ -15,3 +15,3 @@ {

],
"version": "0.5.2",
"version": "0.5.3",
"homepage": "http://github.com/benjamn/recast",

@@ -18,0 +18,0 @@ "repository": {

@@ -33,4 +33,6 @@ var sourceMap = require("source-map");

var sourceRoot = "path/to/source/root";
var printed = new Printer({
sourceMapName: "source.map.json"
sourceMapName: "source.map.json",
sourceRoot: sourceRoot
}).print(ast);

@@ -45,2 +47,7 @@

assert.strictEqual(
printed.map.sourceRoot,
sourceRoot
);
var smc = new sourceMap.SourceMapConsumer(printed.map);

@@ -53,3 +60,3 @@

}), {
source: "source.js",
source: sourceRoot + "/source.js",
line: origLine,

@@ -64,3 +71,3 @@ column: origCol,

assert.deepEqual(smc.generatedPositionFor({
source: "source.js",
source: sourceRoot + "/source.js",
line: origLine,

@@ -67,0 +74,0 @@ column: origCol

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