helen's blog

ずっとおもしろいことしてたいな。

予約語が原因でjenkinsが激おこぷんぷん丸だった件

jenkinsさんが見たことないエラーで激おこしてました

[ERROR] hoge.js:line 52:column 8:invalid property id
			float: 'left'
[ERROR] hoge.js:line 52:column 9:syntax error
			float: 'left'
[ERROR] hoge.js:line 53:column 3:syntax error
		});
[ERROR] hoge.js:line 1:column 0:Compilation produced 3 syntax errors.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.588s
[INFO] Finished at: Tue Jan 12 14:33:39 JST 2016
[INFO] Final Memory: 27M/198M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:yuicompressor-maven-plugin:1.1:compress (default) on project : Execution default of goal net.alchim31.maven:yuicompressor-maven-plugin:1.1:compress failed: Compilation produced 3 syntax errors. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

なんだこれ

私 < ちょっとこれやばくない
私 < 今回追加したJSが原因で死んでる
XXXX < これはあかんやつやな

XXXX < floatが予約語だから怒られてるっぽいw
XXXX < javascript - Compression issues with JQuery file in YUI Compressor - Stack Overflow

というわけで

#  変更前
float: 'left'

# 変更後
'float': 'left'

シングルクオート追加しました
JSの挙動としては問題ありません

予約語参考:yuicompressor/JavaScriptCompressor.java at master · yui/yuicompressor · GitHub

おまけ

YUI Compressorとは

JSやCSSを圧縮してデータ転送良を減らしてくれる

mavenにyuicompressorを入れる
     <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compress</goal>
            </goals>
          </execution>
        </executions>        
        <configuration>
          <nosuffix>true</nosuffix>
          <aggregations>
            <aggregation>
              <!-- remove files after aggregation (default: false)
              <removeIncluded>true</removeIncluded>
              -->
              <!-- insert new line after each concatenation (default: false) -->
              <insertNewLine>true</insertNewLine>
              <output>${project.build.directory}/${project.build.finalName}/static/all.js</output>
              <!-- files to include, path relative to output's directory or absolute path-->
              <!--inputDir>base directory for non absolute includes, default to parent dir of output</inputDir-->
              <includes>
                <include>${basedir}/src/licenses/license.js</include>
                <include>**/*.js</include>
              </includes>
              <!-- 圧縮済みファイルは除外 -->
              <excludes>
                <exclude>**/*.pack.js</exclude>
                <exclude>**/compressed.css</exclude>
              </excludes>
            </aggregation>
          </aggregations>
        </configuration>
      </plugin>

pom.xmlにこんな感じで
参考:YUI Compressor Maven Mojo -