diff --git a/package.json b/package.json index 1c869784..4f3be352 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "javascript-obfuscator": "./bin/javascript-obfuscator.js" }, "dependencies": { + "babel-polyfill": "^6.20.0", "babel-runtime": "^6.20.0", "chance": "1.0.4", "class-validator": "0.6.6", diff --git a/src/JavaScriptObfuscator.ts b/src/JavaScriptObfuscator.ts index dfae1fdb..fa02ed81 100644 --- a/src/JavaScriptObfuscator.ts +++ b/src/JavaScriptObfuscator.ts @@ -1,5 +1,11 @@ +require("babel-core/external-helpers"); + import 'reflect-metadata'; +if (!(global)._babelPolyfill) { + require('babel-polyfill'); +} + import { ServiceIdentifiers } from './container/ServiceIdentifiers'; import { Chance } from 'chance'; diff --git a/test/dev/dev-compile-performance.ts b/test/dev/dev-compile-performance.ts index c87cfb10..9b75f874 100644 --- a/test/dev/dev-compile-performance.ts +++ b/test/dev/dev-compile-performance.ts @@ -2,6 +2,10 @@ import * as fs from 'fs'; +if (!(global)._babelPolyfill) { + require('babel-polyfill'); +} + (function () { const JavaScriptObfuscator: any = require("../../index"); diff --git a/test/dev/dev-runtime-performance.ts b/test/dev/dev-runtime-performance.ts index dbd45639..271b9c5b 100644 --- a/test/dev/dev-runtime-performance.ts +++ b/test/dev/dev-runtime-performance.ts @@ -1,5 +1,9 @@ 'use strict'; +if (!(global)._babelPolyfill) { + require('babel-polyfill'); +} + (function () { const JavaScriptObfuscator: any = require("../../index"); diff --git a/test/dev/dev.ts b/test/dev/dev.ts index e44e814c..5307d3d8 100644 --- a/test/dev/dev.ts +++ b/test/dev/dev.ts @@ -1,5 +1,9 @@ 'use strict'; +if (!(global)._babelPolyfill) { + require('babel-polyfill'); +} + (function () { const JavaScriptObfuscator: any = require("../../index"); diff --git a/test/index.spec.ts b/test/index.spec.ts index 0cb7889f..2fb109c8 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -1,6 +1,8 @@ +import { BabelPolyfill } from './polyfills/BabelPolyfill'; import 'reflect-metadata'; require('source-map-support').install(); +BabelPolyfill.append(); /** * Unit tests diff --git a/test/polyfills/BabelPolyfill.ts b/test/polyfills/BabelPolyfill.ts new file mode 100644 index 00000000..f7a50747 --- /dev/null +++ b/test/polyfills/BabelPolyfill.ts @@ -0,0 +1,7 @@ +export class BabelPolyfill { + public static append (): void { + if (!(global)._babelPolyfill) { + require('babel-polyfill'); + } + } +}