From 1c9dbbf3b3dabd07a585585ac9e060ffa6ea3ead Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 25 Feb 2015 09:24:18 -0800 Subject: [PATCH] Craft manual deprecation to get around stack depth limit This allows the deprecation to be properly associated with the package it originates from. --- src/babel.coffee | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/babel.coffee b/src/babel.coffee index d4b53c204..01214fa1a 100644 --- a/src/babel.coffee +++ b/src/babel.coffee @@ -140,19 +140,25 @@ loadFile = (module, filePath) -> if sourceCode.startsWith('"use babel"') or sourceCode.startsWith("'use babel'") # Continue. else if sourceCode.startsWith('"use 6to5"') or sourceCode.startsWith("'use 6to5'") - packageName - directory = filePath - until packageName - directory = path.dirname(directory) - manifest = path.join(directory, 'package.json') - if fs.existsSync(manifest) - json = JSON.parse(fs.readFileSync(manifest)) - packageName = json.name - else if isRoot(directory) - break - + # Create a manual deprecation since the stack is too deep to use Grim + # which limits the depth to 3 Grim ?= require 'grim' - Grim.deprecate("Use the 'use babel' pragma instead of 'use 6to5' in #{filePath}", {packageName}) + stack = [ + { + fileName: __filename + functionName: 'loadFile' + location: "#{__filename}:161:5" + } + { + fileName: filePath + functionName: '' + location: "#{filePath}:1:1" + } + ] + deprecation = + message: "Use the 'use babel' pragma instead of 'use 6to5'" + stacks: [stack] + Grim.addSerializedDeprecation(deprecation) else return module._compile(sourceCode, filePath)