Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When saving JavaScript which may contain syntax errors Babel will return an error. Currently this error is just thrown causing the process to crash and no additional changes are watched/saved.
[07:27:09] Watching './**/*.es6.js' for changes.
[07:27:19] 'misc/ajax.es6.js' is being processed.
~/drupal/core/scripts/js/compile.js:21
throw new Error(err);
^
Error: SyntaxError: misc/ajax.es6.js: Unexpected token (13:10)
at babel.transformFile (~/drupal/core/scripts/js/compile.js:21:15)
at ~/drupal/core/node_modules/babel-core/lib/api/node.js:141:7
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:438:3)
error Command failed with exit code 1.
Proposed resolution
Catch and log the error, don't crash the watch process.
$ node ./scripts/js/babel-es6-watch.js
[07:26:13] Watching './**/*.es6.js' for changes.
[07:26:36] 'misc/ajax.es6.js' is being processed.
[07:26:37] SyntaxError: misc/ajax.es6.js: Unexpected token (13:10)
Comment | File | Size | Author |
---|---|---|---|
bumper.patch | 653 bytes | droplet | |
c20170613_103533.png | 27.57 KB | droplet |
Comments
Comment #2
Wim LeersCan you describe what the behavior before vs after is, in other words: what this fixes or improves?
Comment #3
GrandmaGlassesRopeManComment #4
Wim LeersAhhh! Yes! I've had this happen too! And because of this, I've posted patches where the ES5 transpiled file was out of sync with the ES6 file. Which can lead to all sorts of confusion.
Therefore bumping priority and tagging DX.
Comment #5
GrandmaGlassesRopeManComment #8
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedIf it makes everybody's life easier, let's do it.
Comment #9
cilefen CreditAttribution: cilefen at Institute for Advanced Study commented...and I made sure this preserves the non-zero exit code as needed for pre-commit scripts, which is appreciated (and needed).