From d4a469df6b6eeae4c045faf7b6e63bdc765b0a15 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Wed, 8 Feb 2017 12:16:51 +0300 Subject: [PATCH] pkg: Fix bug #275 Bug: Node.js v4 does not support the ES6 syntax fully, thus we get the error: Block scoped declarations (let, const, function,class) not yet supported outside strict mode Fix: * Load transpiled code * Deprecate support for Node.js v4.x References: * Bug report: https://github.com/yagop/node-telegram-bot-api/issues/275 * PR: https://github.com/yagop/node-telegram-bot-api/pull/280 * Reported-by: @crazyabdul * PR-by: @crazyabdul --- index.js | 10 +++++----- test/telegram.js | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 6165386..8e0c99b 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,12 @@ /** - * If running on Nodejs 0.12, we load the transpiled code. + * If running on Nodejs 4.x and below, we load the transpiled code. * Otherwise, we use the ES6 code. - * We are deprecating support for Node.js v0.x + * We are deprecating support for Node.js v4.x and below. */ -const majorVersion = process.versions.node.split('.')[0]; -if (majorVersion === '0') { +const majorVersion = parseInt(process.versions.node.split('.')[0], 10); +if (majorVersion <= 4) { const deprecate = require('depd')('node-telegram-bot-api'); - deprecate('Node.js v0.12 and below will no longer be supported in the future'); + deprecate('Node.js v4.x and below will no longer be supported in the future'); module.exports = require('./lib/telegram'); } else { module.exports = require('./src/telegram'); diff --git a/test/telegram.js b/test/telegram.js index 9c390dc..6cd243c 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -44,12 +44,13 @@ before(function beforeAll() { describe('module.exports', function moduleExportsSuite() { - it('is loaded from src/ if NOT on Node.js 0.12', function test() { - if (process.versions.node.split('.')[0] === '0') this.skip(); // skip on Node.js v0.12 + const nodeVersion = parseInt(process.versions.node.split('.')[0], 10); + it('is loaded from src/ on Node.js v5+', function test() { + if (nodeVersion <= 4) this.skip(); // skip on Node.js v4 and below assert.equal(TelegramBot, require('../src/telegram')); }); - it('is loaded from lib/ if on Node.js 0.12', function test() { - if (process.versions.node.split('.')[0] !== '0') this.skip(); // skip on newer versions + it('is loaded from lib/ on Node.js v4 and below', function test() { + if (nodeVersion > 4) this.skip(); // skip on newer versions assert.equal(TelegramBot, require('../lib/telegram')); }); });