From 3e72e05965917a74ef0537005879d6d631a6b44e Mon Sep 17 00:00:00 2001 From: rorticus Date: Thu, 7 Sep 2017 13:46:48 -0400 Subject: [PATCH] Adding polyfills, issue #106 --- package.json | 1 + src/main.ts | 12 +++++++++ src/util/amd.ts | 39 +++++++++++++++++++++++++++ tests/functional/asyncAwait.html | 14 +++++----- tests/functional/asyncAwait.ts | 6 ++--- tests/functional/bluebird.html | 9 +++++-- tests/functional/bluebirdAndDojo.html | 14 +++++----- tests/intern.ts | 20 +++----------- tests/loader.ts | 16 +++++++++++ tests/unit/array.ts | 2 +- tests/unit/object.ts | 2 +- tsconfig.json | 1 - 12 files changed, 98 insertions(+), 38 deletions(-) create mode 100644 src/util/amd.ts create mode 100644 tests/loader.ts diff --git a/package.json b/package.json index 98f4923..90b256d 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "typescript": "~2.4.1" }, "dependencies": { + "pepjs": "^0.4.2", "tslib": "^1.7.1" } } diff --git a/src/main.ts b/src/main.ts index c4d78e3..d41c278 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,18 @@ import * as string from './string'; import Symbol from './Symbol'; import WeakMap from './WeakMap'; +`!has('es6-promise')`; +import './Promise'; + +`!has('es6-symbol')`; +import './Symbol'; +import has from '@dojo/has/has'; + +if (has('host-browser')) { + require('pepjs'); + require('intersection-observer'); +} + export { array, iterator, diff --git a/src/util/amd.ts b/src/util/amd.ts new file mode 100644 index 0000000..c6ec632 --- /dev/null +++ b/src/util/amd.ts @@ -0,0 +1,39 @@ +function addIfNotPresent(packages: any[], newPackage: any) { + if (packages.some((pack) => pack.name === newPackage.name)) { + return; + } + + packages.push(newPackage); +} + +// tslint:disable-next-line +function shimAmdDependencies(config: any) { + let packages = config.packages || []; + + addIfNotPresent(packages, { + name: 'tslib', + location: 'node_modules/tslib', + main: 'tslib' + }); + + addIfNotPresent(packages, { + name: 'pepjs', + location: 'node_modules/pepjs/dist', + main: 'pep' + }); + + addIfNotPresent(packages, { + name: 'intersection-observer', + location: 'node_modules/intersection-observer', + main: 'intersection-observer' + }); + + addIfNotPresent(packages, { + name: '@dojo', + location: 'node_modules/@dojo' + }); + + config.packages = packages; + + return config; +} diff --git a/tests/functional/asyncAwait.html b/tests/functional/asyncAwait.html index 3100628..eb2b70f 100644 --- a/tests/functional/asyncAwait.html +++ b/tests/functional/asyncAwait.html @@ -6,16 +6,16 @@ +