From 85c0381540c2a44f6e8ed502d642349514bbbf79 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 15 Dec 2016 12:26:21 -0500 Subject: [PATCH] intercept parse errors with options.onerror --- src/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 173f532037..4c424e77ba 100644 --- a/src/index.js +++ b/src/index.js @@ -16,13 +16,25 @@ function normalizeOptions ( options ) { } else { console.warn( warning.message ); // eslint-disable-line no-console } + }, + + onerror: error => { + throw error; } }, options ); } export function compile ( source, _options ) { const options = normalizeOptions( _options ); - const parsed = parse( source, options ); + + let parsed; + + try { + parsed = parse( source ); + } catch ( err ) { + options.onerror( err ); + return; + } const { names } = validate( parsed, source, options );