bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
192 stars 90 forks source link

Asset pipeline doesn't uderstand static fields #334

Open rlconst opened 2 months ago

rlconst commented 2 months ago
class Foo {
    static myField = "bar"
}

error reported about expected ( after myField

Mozilla

gsartori commented 2 weeks ago

We are experiencing the same issue trying to minify the chart.js library (https://www.chartjs.org) with Grails 6.2.0 / Asset Pileline 4.4.0

elements-extra.unminified.js:568:17: ERROR - [JSC_PARSE_ERROR] Parse error. '(' expected
  568|  static defaults = {};
                        ^

1 error(s), 0 warning(s)
Closure uglify JS Exception
asset.pipeline.processors.MinifyException: [JSC_PARSE_ERROR. Parse error. '(' expected at elements-extra.unminified.js line 568 : 17]
    at asset.pipeline.processors.ClosureCompilerProcessor.process(ClosureCompilerProcessor.groovy:81)
    at asset.pipeline.processors.ClosureCompilerProcessor$process$2.call(Unknown Source)
    at asset.pipeline.AssetCompiler$_compile_closure4.doCall(AssetCompiler.groovy:171)
    at jdk.internal.reflect.GeneratedMethodAccessor284.invoke(Unknown Source)
    at java.base@17/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base@17/java.lang.reflect.Method.invoke(Method.java:568)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035)
    at groovy.lang.Closure.call(Closure.java:412)
    at groovy.lang.Closure.call(Closure.java:406)
    at java.base@17/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base@17/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base@17/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base@17/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base@17/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base@17/java.lang.Thread.run(Thread.java:833)
> Task :app-test:assetCompile FAILED
lamon commented 2 weeks ago

@gsartori I had the same issue with chartjs, and until the problem is fixed, I excluded the js from the minify process:

assets {

    minifyJs = true
    minifyCss = true

    minifyOptions = [
        excludes: [
            '**/chart.umd.js'
        ]
    ]

}
gsartori commented 2 weeks ago

@lamon thank you for the workaround, unfortnuately we are including the .js file in a //= require directive so the exclusion is not working.

I'd love to be able to avoid files from being processed independently whether they are used in a require or not.