Skip to content

Commit

Permalink
fix(cli-38): catch syntax errors and recover
Browse files Browse the repository at this point in the history
Catch exceptions thrown by the Babel transpilation function to allow the
developer to gracefully recover to any mistakes in source files.
  • Loading branch information
varl committed Dec 7, 2021
1 parent ecc8d55 commit 5f9c5bb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cli/src/lib/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,19 @@ const compile = async ({
}
const compileFile = async (source, destination) => {
if (source.match(extensionPattern)) {
const result = await babel.transformFileAsync(source, babelConfig)
await fs.writeFile(destination, result.code)
try {
const result = await babel.transformFileAsync(
source,
babelConfig
)
await fs.writeFile(destination, result.code)
console.info(`Compiling ${source}: OK.`)
} catch (err) {
console.error(err)
console.info(
`Compiling ${source}: ERROR. Fix the problem and save the file to automatically reload.`
)
}
} else {
await copyFile(source, destination)
}
Expand Down

0 comments on commit 5f9c5bb

Please sign in to comment.