Code Monkey home page Code Monkey logo

source-map's People

Contributors

ashaffer avatar bomsy avatar campd avatar dmurat avatar eemeli avatar ejpbruel avatar evanw avatar fitzgen avatar gerhobbelt avatar hibnico avatar hildjj avatar jgoz avatar jryans avatar loganfsmyth avatar lydell avatar michaelficarra avatar mishoo avatar ochameau avatar rinon avatar roblourens avatar rtsao avatar ryanseddon avatar samccone avatar simenb avatar sokra avatar takikawa avatar tromey avatar twolfson avatar usrbincc avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

source-map's Issues

`originalPositionFor(generatedPosition)` fails on string positions

I was sending in strings instead of numbers to the originalPositionFor function. This works unless the strings aren't exactly in the mappings. E.g. originalPositionFor({line:"8", column:"10"}) would work if the sourcemap contained that exact entry, but if it instead contained line 8, column 8 and line 8 column 12, it wouldn't find the sourcemap.

Please mention that line and column MUST be number (not strings) in the readme documentation.

Release new version

Hello,

could you please release a new version to NPM?

I'm trying to use SourceMapConsumer.prototype.generatedPositionFor as per published documentation, it's present in source code but not in currently published version.

Thanks.

Modifying SourceMapGenerator mappings after creation

I'm running into an issue where there is no way to modify a mapping after addMapping(). I would like to be able to prepend some code to my JS string, and update the entire mapping (shift down by X lines and/or shift the first line over by Y columns). There does not appear to be any way to do this. I can code up a little function that does that, if you think it would be useful for others.

Backward incompatible change in 0.1.33 breaks UglifyJS2 (and others?)

This commit causes this issue in UglifyJS2

Even the commit message says this is a backward-incompatible change. It breaks semantic versioning expectations such as UJS which depend on ~0.1.31 and assume no backward-incompatible changes.

Is it possible to revert this commit and release a 0.1.34, then start a new 0.2.0 with this commit?

(I'm not usually such a stickler for standards, but in the event that @mishoo neither fixes UJS to work with [email protected] nor fixes his dependency to [email protected], I'd like to be able to continue using UJS for my own project without having to resort to npm-shrinkwrap.)

SourceMapConsumer.originalPositionFor does not return correct value, unless at begining of mapping

SourceMapConsumer.originalPositionFor does not return the original position it returns the position of the start of the block in which that position is found.

i.e. (where x and y are constant)

SourceMapConsumer.originalPositionFor({line: y, column: x});

and

SourceMapConsumer.originalPositionFor({line: y, column: x + 1});

and

SourceMapConsumer.originalPositionFor({line: y, column: x + 2});

Will all yield the same result if the positions all fall inside the same mapping - the start position of the mapping, which is incorrect.

MIT license

Can you add an MIT license to this package.

Add check that URLs don't contain Windows path separators (`\`)

On widows file paths will include \ instead of / and source-map doesn’t convert slashes, but source map will work only with UNIX slashes.

We can fix it in app, but I think, that we need to fix it here, because every source-map node.js user must to repeat this fix.

Autoprefixer issue: nDmitry/grunt-autoprefixer#25

I can helps with PR, but how we should do this? Try to load path (it wil be in node.js and browserfy) and if path.sep == "\\" replace all \ to /?

merge dryice into source-map ?

Hello,

  • dryice is small
  • dryice hasn't changed in a year
  • dryice is only used by one active project: source-map
  • there are plenty of alternative bundling tools (browserify and so on)

so maybe it's a good idea to maintain dryice within source-map instead of having it separated.

Null check should be undefined check?

In source-node.js:

if (aChunks !== null) this.add(aChunks);

from

function SourceNode(aLine, aColumn, aSource, aChunks) {
this.children = [];
this.line = aLine;
this.column = aColumn;
this.source = aSource;
if (aChunks !== null) this.add(aChunks);
}

If we call this function thus:
var n = new SourceNode(l, c, s);
the code calls add with 'undefined'.

This causes test-source-node.js to fail.

run-tests-in-browser.html:86test-source-node.js: test .add()
run-tests-in-browser.html:87--------------------------------------------------------------------------------
run-tests-in-browser.html:88TypeError: Expected a SourceNode, string, or an array of SourceNodes and strings. Got undefined
at SourceNode.SourceNode_add as add
at new SourceNode (http://localhost:8080/file/c/lib/source-map/source-node.js:38:32)
at Object.test .add() (http://localhost:8080/file/c/test/test-source-node.js:61:16)
at run (http://localhost:8080/file/c/test/run-tests-in-browser.html:66:31)
at http://localhost:8080/file/c/test/run-tests-in-browser.html:123:10
at Function.execCb (http://requirejs.org/docs/release/1.0.6/minified/require.js:28:478)
at p (http://requirejs.org/docs/release/1.0.6/minified/require.js:11:3)
at http://requirejs.org/docs/release/1.0.6/minified/require.js:12:242
at p (http://requirejs.org/docs/release/1.0.6/minified/require.js:12:133)
at http://requirejs.org/docs/release/1.0.6/minified/require.js:12:242

Questions

Thanks for a very useful package.
How does one read the location data while walking the AST nodes. That info is scattered in a very unstructured way.
is it necessary to map each column in each line. what does the browser or debugger do when there is a gap?
Please, clear a little fog in the documentation. What does 'Applies a SourceMap for a source file to the SourceMap.' mean? Are you calling three different things by the same name?
Thanks for any time you can spare.

Only generate a mapping at a generated location for the most specific mapping

If we have the following mappings, should we generate them all in the source map or only the most specific mapping?

map.addMapping({
  generated: { line: 3, column: 5 }
});
map.addMapping({
  generated: { line: 3, column: 5 },
  original: { line: 6, column: 7 },
  source: 'foo.js'
});
map.addMapping({
  generated: { line: 3, column: 5 },
  original: { line: 6, column: 7 },
  source: 'foo.js',
  name: 'bar'
});

What should be the behavior if there is different original locations for the same generated position? Should we still use the most specific/detailed mapping and ignore the others?

Composing source maps

It should be easy to create source maps composed from other source maps.

For example, if we start out with a coffeescript file and compile it to readable js we get source map A. Then if we minify that js file, we get source map B. We should be able to take those source maps and compose them in to a single source map, mapping our coffee script file to the minified file.

Wrong sourceRoot handling?

From the spec:

Line 4: An optional source root, useful for relocating source files on a server or removing repeated values in the “sources” entry. This value is prepended to the individual entries in the “source” field.

The spec say that the sourceRoot is prepended, but mozilla/source-map concat it with an additional slash /.

Can you release a new version?

Hi,

I'm using source-map for my tool on node.js, but have a problem on "hasOwnProperty", which has been fixed on the repository.

Can you release a new version to npmjs.org?

Thanks,
gfx

Example on using sourcemaps

Am I missing something as I can't seem to understand from the README on how to use the module to generate sourcemaps.

Can someone point me on how to use this module to generate sourcemaps?

Build instructions fail

Any hints?

$ node Makefile.dryice.js

module.js:340
throw err;
^
Error: Cannot find module 'dryice'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/work/source-map/Makefile.dryice.js:9:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

Public interface to generated/source mappings

Is it possible to expose a public interface to the parsed mappings from SourceMapConsumer? I am working on a tool where I need to iterate over every mapping defined by a source map, and I would rather not deal with parsing myself, since it is already implemented in this project.

Error in array-set when producing source maps.

I created a repo to reproduce the issue here, but here is the stack trace, it basically breaks in ./lib/array-set.js.

/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/node_modules/source-map/lib/source-map/array-set.js:83
    throw new Error('No element indexed by ' + aIdx);
          ^
Error: No element indexed by 1
    at ArraySet_at [as at] (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/node_modules/source-map/lib/source-map/array-set.js:83:11)
    at SourceMapConsumer_parseMappings [as _parseMappings] (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/node_modules/source-map/lib/source-map/source-map-consumer.js:158:44)
    at new SourceMapConsumer (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/node_modules/source-map/lib/source-map/source-map-consumer.js:100:10)
    at module.exports (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/lib/mappings-from-map.js:10:18)
    at Combiner._addExistingMap (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/index.js:28:18)
    at Combiner.addFile (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/node_modules/combine-source-map/index.js:58:12)
    at Stream.write (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/browser-pack/index.js:42:23)
    at Stream.stream.write (/Users/thlorenz/dev/js/projects/es6ify/tmp/node_modules/browserify/node_modules/through/index.js:26:11)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:95:17)

Question: does this module allow any kind of browser-side usage?

I'm trying to see if there's a way to use sourcemap info programatically in javascript on the browser-side. Specifically, exceptions still come out with the unmapped files and lines of code in the trace. I'd like to be able to convert those. Does this module provide any way to do this browser-side?

Ignore duplicate mappings in SourceMapGenerator.prototype.addMapping

Quoting @mishoo:

Let's take this statement: a = 1, the AST
hierarchy for it is something like:

AST_SimpleStatement {
body: AST_Assign {
left: AST_SymbolRef (a)
operator: "="
right: AST_Number (1)
}
}

If I output mapping for all nodes, we'll have a duplicate because the
AST_SimpleStatement's start token is a, which is the same start
token in fact for the AST_Assign and for the AST_SymbolRef. So I'd
output, say, 0,0->0,0 (name: "a") three times.

Source Map version 3 support?

Just curious if source map version 3 support is on the roadmap? I ran across this error when trying to use source-map with a map that was generated using coffeescript 1.6.2:

Error: Unsupported version: 3
    at Object.SourceMapConsumer (/Users/smithclay/Dropbox/Code/sourcemap-proxy/node_modules/source-map/lib/source-map/source-map-consumer.js:62:13)
    at repl:1:35
    at REPLServer.self.eval (repl.js:111:21)
    at rli.on.e (repl.js:260:20)
    at REPLServer.self.eval (repl.js:118:5)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:88:17)
    at Interface._onLine (readline.js:199:10)
    at Interface._line (readline.js:517:8)
    at Interface._ttyWrite (readline.js:735:14)

Thanks!

Possible bug when parsing source maps

I'm getting an exception when parsing source map output by typescript, which was reported in typescript issue tracker here but I'm starting to consider this is a bug with this library since google chrome correctly parses the source map. To reproduce follow these steps:

install tsc and uglifyjs globally

npm install -g typescript uglifyjs

create two files, animal.ts:

module animals {

  export class Animal {
    private killed;

    kill() {
      this.killed = true;
    }
  }

}

and dog.ts:

module animals {

  class Dog extends Animal {
    bark() {
      console.log('bark');
    }
  }

}

then run these:

tsc -out all.js --sourcemap dog.ts animal.ts
uglifyjs --in-source-map all.js.map --source-map all.min.js.map -o all.min.js

An error is thrown on 'array-set.js' (No element indexed by 7)

It should create a minified js file that maps back to the two typescript files, but instead an exception is thrown in

Clarify the minimum node version

There is a bit of a disconnect between the npm minimum node version and the readme version, 0.8 and 0.4 respectively. This is causing issues with uglify2 that otherwise would have a lower than 0.8 supported version.

Ideally the npm version could be reduced to a version prior to 0.8 but otherwise it would be helpful to have the same version listed in both locations.

Is there an easy way to access the JS source map linked in a file as a JS object?

this is a question and not a bug, so please close as not relevant if you think so

In your example file, you show:

var smc = new SourceMapConsumer(rawSourceMap);

now, i have my source map file referenced in the js source as:

[js source code]
//@ sourceMappingURL=auth.js.map

is there a way to access the source map programatically, other than to

  1. load the js file with an xhr
  2. parse out the source url
  3. load the source url with xhr
  4. JSON.parse(sourceMap)

My question is if there's easier way, like an API myScriptTag.getSourceMap() or something other obvious i'm missing here?

Regression from 0.1.32 to 0.1.33: SourceMapConsumer doesn't work for TypeScript-generated source maps

Take a simple TypeScript source file named greeter.ts:

class Greeter {
    constructor(public greeting: string) { }
    greet() {
    return "<h1>" + this.greeting + "</h1>";
    }
};
var greeter = new Greeter("Hello, world!");
var str = greeter.greet();
document.body.innerHTML = str;

Compile with this command:

tsc --sourcemap greeter.ts

This creates greeter.js:

var Greeter = (function () {
    function Greeter(greeting) {
    this.greeting = greeting;
    }
    Greeter.prototype.greet = function () {
    return "<h1>" + this.greeting + "</h1>";
    };
    return Greeter;
})();
;
var greeter = new Greeter("Hello, world!");
var str = greeter.greet();
document.body.innerHTML = str;
//# sourceMappingURL=greeter.js.map

and greeter.js.map:

{"version":3,"file":"greeter.js","sourceRoot":"","sources":["greeter.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet"],"mappings":"AAAA;IACIA,iBAAYA,QAAuBA;QAAvBC,aAAeA,GAARA,QAAQA;AAAQA,IAAIA,CAACA;IACxCD,0BAAAA;QACIE,OAAOA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA;IAC3CA,CAACA;IACLF,eAACA;AAADA,CAACA,IAAA;AAAA,CAAC;AACF,IAAI,OAAO,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC;AAC1C,IAAI,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AACzB,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG"}

Install source-map v0.1.32:

npm install [email protected]

Then you can run this script in node.js:

var SourceMapConsumer = require('source-map').SourceMapConsumer;

require('fs').readFile("greeter.js.map", 'utf8', function (err, data) {
    if (err) {
    console.log('Error: ' + err);
    return;
    }

    var smc = new SourceMapConsumer(JSON.parse(data));

    console.log(smc.originalPositionFor({
    line: 5,
    column: 3
    }));
});

and get this output:

{ source: 'greeter.ts',
  line: 2,
  column: 44,
  name: 'Greeter.constructor' }

Great. Looks fine. Then upgrade to source-map v0.1.33:

npm install [email protected]

Rerun the exact same node.js script, and the output is:

{ source: null, line: null, column: null, name: null }

I observed this bug on Ubuntu 13.10 with node.js v0.10.15 installed from the repos.

I was only able to reproduce this bug for source maps generated by TypeScript. Source maps generated by UglifyJS seem to work fine in v0.1.33.

Dependencies issues

Hello,

The last registered version in NPM is 0.1.8 (https://npmjs.org/package/source-map), this version doesn't exist anymore as a tag in this git repository, which causes dependencies issues for every node modules using it.

Please, can you tag it back,

Regards

Add more strict checks for `_sourceRoot` in `SourceMapGenerator`

We should be using == null so that only null and undefined don't pass the check, because someone could have a directory "0" as the source root and that would fail as it is now.

Don't need to worry about _sourcesContents because it is either null or an object and so implicit coercion to bool is fine.

cc @lydell

Building for browser fails

node Makefile.dryice.js errors out:

fs.js:550
  return binding.mkdir(pathModule._makeLong(path),
                 ^
Error: ENOENT, no such file or directory 'dist/test'
    at Object.fs.mkdirSync (fs.js:550:18)
    at ensureDir (/home/mishoo/Projects/Node.js/source-map/Makefile.dryice.js:129:8)
    at Object.<anonymous> (/home/mishoo/Projects/Node.js/source-map/Makefile.dryice.js:133:1)
    at Module._compile (module.js:454:26)
    at Object.Module._extensions..js (module.js:472:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:497:10)
    at process._tickCallback (node.js:325:13)

I'm not a Dryice user myself, just installed it via NPM. Not sure how to workaround the error..

No change logs, nor git tags

Hello,

I use source-map and I've found its development is very active recently, but there are no change logs nor git tags so I cannot trace the changes. Can you employ them to the repo?

Cheers,

support `sourcesContent` section

From the spec:

An optional list of source content, useful when the “source” can’t be hosted. The contents are listed in the same order as the sources in line 5. “null” may be used of some original sources should be retrieved by name.

Question about source node 'name' field

If I understood correctly, the 'name' field should be used by a debugger to map mangled identifiers to their original name.

I have tried this in chrome but it still shows the mangled names, is there any browser that currently supports this feature?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.