From af4271a262248a5b6891e015f99d1d0591c6e395 Mon Sep 17 00:00:00 2001 From: hon2a Date: Tue, 24 Nov 2015 13:54:49 +0100 Subject: [PATCH] `babel-template` no longer crashes in IE attempting to access unpopulated error stack. --- packages/babel-template/src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/babel-template/src/index.js b/packages/babel-template/src/index.js index 2007507a9a..33b205bc26 100644 --- a/packages/babel-template/src/index.js +++ b/packages/babel-template/src/index.js @@ -10,7 +10,13 @@ let TEMPLATE_SKIP = Symbol(); export default function (code: string): Function { // since we lazy parse the template, we get the current stack so we have the // original stack to append if it errors when parsing - let stack = new Error().stack.split("\n").slice(1).join("\n"); + let stack; + try { + // error stack gets populated in IE only on throw (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx) + throw new Error(); + } catch (error) { + stack = error.stack.split("\n").slice(1).join("\n") + } let getAst = function () { let ast;