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

String with quotes are renamed #2682

Closed exotfboy closed 7 years ago

exotfboy commented 7 years ago

I am building an application, and use the Advanced compile mode, and find that the string with quote are renamed.

The compiled codes with debug throw errors like this:

image image

And this is the sources for if ($candidate$jscomp$1$$.$a$($rendererType$$)) { :

if (candidate['handles'](rendererType)) {

You can find the full codes here

Note the undefined $a is indeed ['handles'], but why it is renamed ?

BTW, I use closure-util with the following config:

{
  "lib": [
    "node_modules/openlayers/src/**/*.js",
    "node_modules/openlayers/build/ol.ext/**/*.js",
    "src/**/*.js"
  ],
  "compile": {
    "externs": [
      "node_modules/openlayers/externs/bingmaps.js",
      "node_modules/openlayers/externs/cartodb.js",
      "node_modules/openlayers/externs/closure-compiler.js",
      "node_modules/openlayers/externs/esrijson.js",
      "node_modules/openlayers/externs/geojson.js",
      "node_modules/openlayers/externs/proj4js.js",
      "node_modules/openlayers/externs/tilejson.js",
      "node_modules/openlayers/externs/topojson.js"
    ],
    "define": [
      "ol.ENABLE_WEBGL=false"
    ],
    "js": [
      "node_modules/openlayers/src/ol/typedefs.js",
      "node_modules/openlayers/externs/olx.js",
      "node_modules/openlayers/externs/oli.js"
    ],
    "extra_annotation_name": [
      "api", "observable"
    ],
    "rewrite_polyfills": "false",
    "compilation_level": "ADVANCED",
    "output_wrapper": "(function(){%output%})();",
    "manage_closure_dependencies": true,
    "use_types_for_optimization": true,
    "debug":true
  }
}
MatrixFrog commented 7 years ago

Hm yeah that definitely should not happen! Is it possible that closure-util is somehow compiling everything twice by accident, or running the code through some other tool first, before it invokes the closure compiler?

exotfboy commented 7 years ago

You mean this maybe caused by closure-util instead of closure-compiler itsefl? 😆

MatrixFrog commented 7 years ago

It is possible. I haven't looked at what closure-util does. If you can figure out a minimal reproduction with just the compiler itself that would be great.

exotfboy commented 7 years ago

I can not provide the reproduction at the moment (maybe later), but I tried to print the commands:

java -server -XX:+TieredCompilation -jar D:/ws/app-root/node_modules/closure-util/.deps/compiler/416a3e2f199e3b8ae5c051ece4b8ef57dc365ec0/closure-compiler-v20170910.jar --flagfile=C:\Users\xx\AppData\Local\Temp\compile-flags-117924-1692-12esseb.g5ylvaq0k9.txt

And the flagfile can be found here.

fredj commented 7 years ago

It was an issue in OpenLayers (fixed with https://github.com/openlayers/openlayers/pull/7333) not in closure-util or closure-compiler.

MatrixFrog commented 7 years ago

Cool, thanks.