mozilla / source-map Goto Github PK
View Code? Open in Web Editor NEWConsume and generate source maps.
License: Other
Consume and generate source maps.
License: Other
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.
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.
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.
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 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.
Can you add an MIT license to this package.
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 /
?
Hello,
so maybe it's a good idea to maintain dryice within source-map instead of having it separated.
According to the spec, the "file" property of source maps is optional, so the following should work:
new SourceMapGenerator({})
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
example:
{
...
sourceRoot: "http://example.com/",
sources: ["http://foobar.com/some.js"]
...
}
will currently spit out http://example.com/http://foobar.com/some.js as a source, which is wrong
I see a 0.1.22 in npm, but I do not see a tag in this repo for it.
path.existsSync is now called fs.existsSync
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.
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?
I have javascript files that get "compiled" into one by brunch.
The sourcemaps point to the incorrect file.
Saw this post:
http://stackoverflow.com/questions/24384141/coffeescript-sourcemaps-points-to-wrong-files
Have anyone encountered this before ?
Test case: https://gist.github.com/int3/5769221
Nightly gets stuck permanently on 'Loading' when I try to open foo.html
in the above gist. This test case was derived from my work on integrating source maps with Emscripten: emscripten-core/emscripten#1267
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.
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 /
.
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
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?
It is O(n) and its inside a loop for each mapping :( very sad. Instead we should just advance an index through the array of remaining lines.
Depends on #103 because that changes the fromStringWithSourceMap
code, but we will still be using shift
.
Over on https://github.com/google/traceur-compiler we've been using 0.1.30. Today I tried 0.1.34 and my test fails:
https://github.com/google/traceur-compiler/blob/master/test/unit/codegeneration/SourceMap.js#L48
Any hints on what changed that might affect us?
Looks like __proto__
can't be added, because mishoo/UglifyJS#30 (comment)
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)
@sokra because you wrote fromSourceMap
, can you also write this documentation?
As per the spec, it is an optional prefix, and if it is present we need to remove it to properly parse the JSON.
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.
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)
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?
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.
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!
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
Need to give examples on how to consume and generate source maps. API reference isn't enough.
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.
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
My question is if there's easier way, like an API myScriptTag.getSourceMap()
or something other obvious i'm missing here?
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.
The source map spec v3 uses zero based lines:
the zero-based starting line in the original source
The readme here does not say but evidently this library uses one-based lines:
https://github.com/mozilla/source-map/blob/master/lib/source-map/source-map-consumer.js#L277
It would be helpful if the readme was clear on this point.
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
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
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..
See #67 (comment)
With the last release my use of the library broke and all calls to originalPositionFor
return null
. With 0.1.32 it behaves fine.
Here is the source: https://github.com/mantoni/phantomic/blob/master/lib/phantomic.js#L39
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,
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.
I got a ReferenceError
regarding define
when I tried to update. Need to come back to this.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.