Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 401559

Summary: We should pass ES5 flag to Closure compiler
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: RelengAssignee: Mark Macdonald <mamacdon>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ken_walker, mamacdon
Version: 2.0   
Target Milestone: 3.0 M1   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2013-02-22 13:36:50 EST
In bug 378860, we started passing the "-version 180" option to Rhino, hoping it would make the build minification tolerate ES5 syntax. The goal was to fix the problem of the minification breaking when Orion code uses "char" as a variable name (among other things).

That change didn't fix the problem. I think the reason why is because our build script only invokes Rhino to run r.js. r.js then invokes the Closure compiler to parse and optimize the input JS files. It's the Closure compiler whose language mode we need to set, not the outer Rhino that invokes r.js.

So we need to try adding this option to our `orion.build.js` file:

{
    closure: {
      CompilerOptions: {
        languageIn: 'ECMASCRIPT5'
    }
}

The languageIn option defaults to ECMASCRIPT3.
Comment 1 Mark Macdonald CLA 2013-03-26 13:22:02 EDT
Made the change:
http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=8dbe7d608a1c8667acf54c8d

we'll see how the nightly build fares.
Comment 2 Mark Macdonald CLA 2013-03-27 09:40:06 EDT
It didn't work. The minification broke.

> updateHTML:
>      [copy] Copying 2 files to /shared/eclipse/e4/orion/I201303262230/plugins/org.eclipse.orion.client.ui/web/edit
>      [java] 
>      [java] Tracing dependencies for: compare/compare
>      [java] js: "/shared/eclipse/e4/orion/requirejs/dist/r.js", line 10871: exception from uncaught JavaScript throw: Error: Error evaluating module "undefined" at location "undefined":
>      [java] InternalError: Cannot convert ECMASCRIPT5 to com.google.javascript.jscomp.CompilerOptions$LanguageMode
>      [java] fileName:undefined
>      [java] lineNumber: undefined
>      [java] http://requirejs.org/docs/errors.html#defineerror
>      [java] 
>      [java] Minifying file: /opt/public/eclipse/e4/orion/I201303262230/optimization/./compare/built-compare.js
>      [java] Java Result: 3

The above trace and this thread [1] suggest that there's no way to set the closure compiler's language mode from a RequireJS build file. Reverted:

http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=c16aabaa6c2e7c96f2bf5e88

[1] https://groups.google.com/forum/#!msg/requirejs/9f4sgewYnAw/G-oSqCz2DSEJ
Comment 3 Mark Macdonald CLA 2013-03-27 09:41:00 EDT
WONTFIXing this bug.
Comment 4 Mark Macdonald CLA 2013-03-27 09:50:50 EDT
I clearly didn't read the last post in the discussion thread. There is a way to obtain the value of the enum constant needed by the closure compiler.

Trying another fix:
http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=c09aea6b298f89d5f4eada47
Comment 5 Mark Macdonald CLA 2013-03-28 09:40:13 EDT
Didn't work either.
> updateHTML:
>    [length] /shared/eclipse/e4/orion/I201303272230/optimization/built-index.js does not exist
>      [copy] Copying 1 file to /shared/eclipse/e4/orion/I201303272230/plugins/org.eclipse.orion.client.ui/web
>      [java] js: "/shared/eclipse/e4/orion/requirejs/dist/r.js", line 10871: exception from uncaught JavaScript throw: Error: Error evaluating module "undefined" at location "undefined":
>      [java] Error: Build file /opt/public/eclipse/e4/orion/I201303272230/optimization/./orion.build.js is malformed: InternalError: Can't find method java.lang.Enum.valueOf(string). (/shared/eclipse/e4/orion/requirejs/dist/r.js#11938(eval)#1)
>      [java] fileName:undefined
>      [java] lineNumber: undefined
>      [java] http://requirejs.org/docs/errors.html#defineerror
>      [java] 
>      [java] Java Result: 3

Let's try this again:
http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=3b008b7edeb61886c4fdde72
Comment 6 Mark Macdonald CLA 2013-03-28 23:22:52 EDT
I give up. Let's use Uglify. Closure compiler is a waste of time.

> updateHTML:
>    [length] /shared/eclipse/e4/orion/I201303282230/optimization/edit/built-edit.js does not exist
>      [copy] Copying 1 file to /shared/eclipse/e4/orion/I201303282230/plugins/org.eclipse.orion.client.ui/web/edit
>      [java] js: "/shared/eclipse/e4/orion/requirejs/dist/r.js", line 10871: exception from uncaught JavaScript throw: Error: Error evaluating module "undefined" at location "undefined":
>      [java] Error: Build file /opt/public/eclipse/e4/orion/I201303282230/optimization/./orion.build.js is malformed: InternalError: Java class "com.google.javascript.jscomp.CompilerOptions$LanguageMode" has no public instance field or method named "fromString". (/shared/eclipse/e4/orion/requirejs/dist/r.js#11938(eval)#1)
>      [java] fileName:undefined
>      [java] lineNumber: undefined
>      [java] http://requirejs.org/docs/errors.html#defineerror
>      [java] 
>      [java] Java Result: 3
Comment 7 Mark Macdonald CLA 2013-03-29 12:48:10 EDT
Trying again. Not sure why, but I can't seem to invoke the single-parameter enum #valueOf(String) method on the CompilerOptions enum, so trying the #valueOf(Class, String) version instead.

http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=c3731a32fd396e3bef5e553da96a42dd4e5748f5
Comment 8 Mark Macdonald CLA 2013-04-01 10:01:47 EDT
OK, I think that last change finally worked: minification succeeded in the most recent build.

Opened bug 404670 about removing the temporary changes made to the JS validator to work around the old behavior.
Comment 9 Mark Macdonald CLA 2013-04-01 23:50:12 EDT
Closure is apparently now set to "ES5" mode, but despite that, it's still choking on the use of ES3 "future reserved" words like `char` which should not be reserved in ES5.

>      [java] Tracing dependencies for: orion/editor/edit
>     [java] Minifying file: /shared/eclipse/e4/orion/I201304012230/built-js/built-editor-amd.min.js
>     [java] Apr 1, 2013 10:34:55 PM com.google.javascript.jscomp.LoggerErrorManager println
>     [java] SEVERE: /shared/eclipse/e4/orion/I201304012230/built-js/built-editor-amd.min.js:14024: ERROR - Parse error. missing variable name
>     [java] 			var char = buffer.charAt(offset--);
>     [java] 			         ^

I want to believe that [1] describes the problem and that we are simply using an outdated version of Closure. But that is probably too optimistic.
Comment 10 Mark Macdonald CLA 2013-04-01 23:51:01 EDT
(In reply to comment #9)

[1] http://code.google.com/p/closure-compiler/issues/detail?id=357
Comment 11 Mark Macdonald CLA 2013-04-03 14:50:59 EDT
I misread the Orion build logs. The Orion IDE *was* sucessfully compiled by Closure using the fix from Comment 7, even after I reintroduced `char` as a variable name in an input file.

However, the Closure compiler gets invoked by several different build tasks. The failures that remain are from the tasks that compile the standalone minified Orion Editor. Those tasks use different RequireJS build files, to which I neglected to add the "langageIn" flag. I just have to make the corresponding changes on those build files, and we should be done here.
Comment 12 Mark Macdonald CLA 2013-04-03 14:52:51 EDT
http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=6a4e330bf1c7cc9a5006f684

All build files changed. Closing this bug (hopefully forever).