google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.4k stars 1.15k forks source link

The generated SourceMap contains "class com.google.javascript.jscomp.FunctionRewriter$EmptyFunctionReducer:helper" as a source #256

Open blickly opened 10 years ago

blickly commented 10 years ago

This issue was imported from Closure Compiler's previous home at http://closure-compiler.googlecode.com

The original discussion is archived at: http://blickly.github.io/closure-compiler-issues/#898

jeancornic commented 9 years ago

I would like to know if this one has been fixed recently or not. I encounter the issue with an older version, and related code does not seem to have changed since.

In Compiler.java :

@Override
  Node parseSyntheticCode(String js) {
    CompilerInput input = new CompilerInput(
        SourceFile.fromCode(" [synthetic:" + (++syntheticCodeId) + "] ", js));
    putCompilerInput(input.getInputId(), input);
    return input.getAstRoot(this);
  }

In FunctionRewriter.java :

  public Node parseHelperCode(Reducer reducer) {
    Node root = compiler.parseSyntheticCode(
        reducer.getClass().toString() + ":helper", reducer.getHelperSource());
    return (root != null) ? root.removeFirstChild() : null;
  }

If anyone can give me an update, I would appreciate it. Thanks!

MatrixFrog commented 9 years ago

I'm still slightly unclear on why this is a problem. It is admittedly strange, and it will bloat the size of your sourcemap file slightly, but (I would guess) not very much. But your browser's devtools should still be able to map code to its correct source location, no?

jeancornic commented 9 years ago

Thanks for your reply! Yes indeed, it doesn't affect the browser, and the sourcemap size is not increased much. The thing is other sourcemap-related tools can have issues dealing with these.

For my part, I have an issue with an installation of sentry. It tries to collect those sources with a request like this GET class com.google.javascript.jscomp.FunctionRewriter$IdentityReducer:helper HTTP/1.1, which is undesirable.

The question is whether it's a closure-compiler issue or a sentry one, or both.

MatrixFrog commented 9 years ago

Cool, thanks. To be honest, it might be easiest to write a simple post-processing tool that strips those unwanted entries from the source map. Source maps are of course just JSON so you can probably do it with a few lines of whatever your favorite scripting language is.

jeancornic commented 9 years ago

I tried that, and it was not so simple. Removing a file from the sources implies removing blocks from the mappings string, which requires a strong understanding of the format...

Or I could just disable the option rewriteFunctionExpressions. Anyway I'll figure it out.

Thanks for your help!