SourceMaps

Sundararajan Athijegannathan sundararajan.athijegannathan at oracle.com
Thu Dec 1 06:31:39 UTC 2016


This is a feature request. For jdk9, except for jigsaw, we're not adding 
any new feature at this point. It *may* be considered for a release 
beyond jdk9. Please do file rfe if you think this is an important feature.

Thanks,
-Sundar

On 01/12/16, 4:35 AM, Art Fiedler wrote:
> Would be nice to provide SourceMaps to the ScriptEngine... I've seen here...
>
>      http://stackoverflow.com/questions/35137455/nashorn-use-of-source-maps
>
> That nashorn doesn't support source maps, and I'm sure there is a library
> out there that
> is catching the exception and formatting it before it would come to my
> code. Also note
> new Error() doesn't seem to provide the columnNumber to do my own
> source map conversion.
>
> I would propose supporting inline source maps in the js code... or
> implementing in java by starting out with
> something like a SourceMapProvider  interface...
>
> public interface SourceMapProvider {
>      public SourceMapConsumer getConsumer(String filename);
>      public SourceMapConsumer putConsumer(String filename, SourceMapConsumer
> consumer);
>
>      public SourcePosition getOriginalPosition(String filename, int line,
> int column);
>      public SourcePosition getOriginalPosition(String filename, int offset);
>      public SourcePosition getGeneratedPosition(String filename, int line,
> int column);
>      public SourcePosition getGeneratedPosition(String filename, int offset);
> }
> public interface SourceMapConsumer {
>      public String getFilename();
>      public SourcePosition getOriginalPosition(int line, int column);
>      public SourcePosition getOriginalPosition(int offset);
>      public SourcePosition getGeneratedPosition(int line, int column);
>      public SourcePosition getGeneratedPosition(int offset);
> }
> public interface SourcePosition {
>      public String getFilename();
>      public int getOriginalLine();
>      public int getOriginalColumn();
>      public int getOriginalOffset();
>      public String getOriginalName(); // Original Identifier, I believe this
> would be used for replaced variable names etc
>      public int getGeneratedLine();
>      public int getGeneratedColumn();
>      public int getGeneratedOffset();
> }
>
> scriptEngine.setSourceMapProvider(mySourceMaps);
> scriptEngine.eval("//@sourceURL=myfile.js\n... minified or transformed code
> ...");
> scriptEngine.eval("//@sourceURL=myotherfile.js\n... minified or transformed
> code ...");
>
> The idea would be that the CodeGenerator, etc... would query the provider
> for line/column info
> passed to an error if a SourceMapProvider was specified and a
> SourceMapConsumer exists for that the file.
>
> -Arthur Fiedler


More information about the nashorn-dev mailing list