bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
193 stars 91 forks source link

[Feature Request] Support other LanguageModes like ES5 again #246

Closed mhuebner closed 4 years ago

mhuebner commented 4 years ago

There was a siginficant change in ClosureCompilerProcessor.evaluateLanguageMode starting from version 3.0.2. This change leeds to huge problems if you don't want to use ES5 and don't want to transpile your JavaScript.

Let's say you want to have languageMode='ES5' and targetLanguage='ES5'. Currently you are not able to solve this without using babel. But this makes absolutely no sense because you don't want to transpile which leeds to a much higher build time (buildTime for assetCompile in our build is currently about 30 secs > with babel.js enabled it's about 4 mins).

Have a look at the changes:

ClosureCompilerProcessor 3.0.1:

    private LanguageMode evaluateLanguageMode(String mode) {
        switch(mode?.toUpperCase()) {
            case 'ES6':
                return LanguageMode.ECMASCRIPT6
            case 'ES6_STRICT':
                return LanguageMode.ECMASCRIPT6_STRICT
            case 'ES5_SCRIPT':
                return LanguageMode.ECMASCRIPT5_STRICT
            case 'ES3':
                return LanguageMode.ECMASCRIPT3
            case 'ES5':
            default:
                return LanguageMode.ECMASCRIPT5
        }
    }

ClosureCompilerProcessor > 3.0.2:

private LanguageMode evaluateLanguageMode(String mode) {
        switch(mode?.toUpperCase()) {
            case 'ECMASCRIPT_NEXT':
                return LanguageMode.ECMASCRIPT_NEXT
            default:
                return LanguageMode.ECMASCRIPT_NEXT
        }
    }

With the latest code you have no chance to switch to older ES. Why not just allow all options / flags of googles closure compiler? I think it would be a great improvement if we could just use all of the possible flags from language_in and language_out (see https://github.com/google/closure-compiler/wiki/Flags-and-Options):

--language_in VAL
Sets the language spec to which input sources should conform. Options: ECMASCRIPT3, ECMASCRIPT5, ECMASCRIPT5_STRICT, ECMASCRIPT6_TYPED (experimental), ECMASCRIPT_2015, ECMASCRIPT_2016, ECMASCRIPT_2017, ECMASCRIPT_2018, ECMASCRIPT_2019, STABLE, ECMASCRIPT_NEXT

--language_out VAL
Sets the language spec to which output should conform. Options: ECMASCRIPT3, ECMASCRIPT5, ECMASCRIPT5_STRICT, ECMASCRIPT_2015, ECMASCRIPT_2016, ECMASCRIPT_2017, ECMASCRIPT_2018, ECMASCRIPT_2019, STABLE

Or at least support all options which were removed in 3.0.1.

davydotcom commented 4 years ago

restored several of these with minifyOptions languageMode and targetLanguage. Added back ES5 , ES5_STRICT, and ES3. Also made ES5 the default again even with babel so it transpiles cleanly. The reason some of these were removed is closure likes to include a library javascript file now which duplicates itself repeatedly and gets in the way.