Polymer / tools

Polymer Tools Monorepo
BSD 3-Clause "New" or "Revised" License
430 stars 200 forks source link

Can't ignore part of file causing polymer-expression-parse-error #2530

Open jsilvermist opened 7 years ago

jsilvermist commented 7 years ago

I'm getting a [polymer-expression-parse-error] error I'm not really sure what to do about when trying to build with a file that looks like this:

<dom-module id="sl-backup-script">
  <template>
    <style include="prism-theme-default">...</style>

    <prism-highlighter></prism-highlighter>
    <marked-element>
      <div slot="markdown-html"></div>
      <script type="text/markdown">
        ...
        if [[ -n $last_backup ]]; then
          if [[ -z `find $file_output/* -maxdepth 0 -type d -mtime -7 -not -name "*-latest"` ]]; then
            file_date=`date -r $file_output/$last_backup $date_format`
            mv $file_output/$last_backup $file_output/$file_date
          else
            rm -rf $file_output/$last_backup
          fi
        fi
        ...
      </script>
    </marked-element>
  </template>
  <script>...</script>
</dom-module>

And when it gets to the part of:

if [[ -n $last_backup ]]; then
  if [[ -z `find $file_output/* -maxdepth 0 -type d -mtime -7 -not -name "*-latest"` ]]; then

It crashes with the error:

D:\Development\silverlinkz>polymer build
info:    Clearing build\ directory...
info:    (es6-unbundled) Building...

        if [[ -n $last_backup ]]; then
                 ~

src/code/backup-script/sl-backup-script.html(72,17) error [polymer-expression-parse-error] - Unexpected token $last_backup

          if [[ -z `find $file_output/* -maxdepth 0 -type d -mtime -7 -not -name "*-latest"` ]]; then
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/code/backup-script/sl-backup-script.html(74,16) warning [invalid-polymer-expression] - The - operator is only supported for writing negative numbers.
error:   Promise rejection: Error: 1 error(s) occurred during build.
error:   Error: 1 error(s) occurred during build.
    at BuildAnalyzer._done (C:\Users\Jason\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\polymer-build\lib\analyzer.js:265:36)
    at BuildAnalyzer.<anonymous> (C:\Users\Jason\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\polymer-build\lib\analyzer.js:225:26)
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\Jason\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\polymer-build\lib\analyzer.js:17:58)
    at <anonymous>

This all works fine except when trying to build, is there some way to ignore part of a file to prevent this parsing issue?

jsilvermist commented 7 years ago

@usergenic Shouldn't this not be parsed for bindings since it's inside a script (also style now too), and not be touched at all since it's a script with the type text/markdown?

TimvdLippe commented 7 years ago

For reference, a similar issue has recently been fixed in the Polymer core with bindings: https://github.com/Polymer/polymer/pull/4841

For here, the simplest check would be to check the type for text/javascript and ignore if it is not.

usergenic commented 7 years ago

Yeah this seems like something that needs work in PolymerAnalyzer, though it is unclear whether we want to ignore script tags or if a lower error severity would suffice. Thoughts, @rictic @justinfagnani ?

justinfagnani commented 7 years ago

The Analyzer needs to match the semantics of Polymer itself. If Polymer is interpreting the [[ ... ]] in the markdown above, then it's entirely correct for the Analyzer to complain about bad syntax.

Now that https://github.com/Polymer/polymer/pull/4841 is merged, the Analyzer needs to take that into account (though for what versions, or all versions, of Polymer is a good question).

An immediate workaround is to escape one of the left-square brackets as &lsqb;

jsilvermist commented 7 years ago

An immediate workaround is to escape one of the left-square brackets as &lsqb;

Doesn't work, it just shows up in the document as &lsqb; instead of [.

Current workaround is far from ideal, which is to add a space, and then run a gulp script after polymer build like so:

'use strict';

const gulp = require('gulp');
const replace = require('gulp-replace');

gulp.task('default', () => {
  // Transform backup-script post-build to bypass polymer-cli parse errors
  return gulp.src('build/**/sl*backup-script.html')
    .pipe(replace('if [ [', 'if [['))
    .pipe(gulp.dest('build/'));
});
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.