Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Using importHelpers instead of noEmitHelpers (#368)
Browse files Browse the repository at this point in the history
* Using importHelpers instead of noEmitHelpers
  • Loading branch information
rorticus authored Nov 14, 2017
1 parent f02af8a commit 2b76265
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"peerDependencies": {
"@dojo/has": "~0.1.0",
"@dojo/shim": "~0.2.1"
"@dojo/shim": "~0.2.2"
},
"devDependencies": {
"@dojo/interfaces": "~0.1.0",
Expand Down
13 changes: 10 additions & 3 deletions src/List.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Iterable, IterableIterator, ShimIterator } from '@dojo/shim/iterator';
import { isArrayLike, isIterable, Iterable, IterableIterator, ShimIterator } from '@dojo/shim/iterator';
import WeakMap from '@dojo/shim/WeakMap';

const listItems: WeakMap<List<any>, any[]> = new WeakMap<List<any>, any[]>();
Expand All @@ -20,8 +20,15 @@ export default class List<T> {
listItems.set(this, []);

if (source) {
for (const item of source) {
this.add(item);
if (isArrayLike(source)) {
for (let i = 0; i < source.length; i++) {
this.add(source[i]);
}
}
else if (isIterable(source)) {
for (const item of source) {
this.add(item);
}
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/MultiMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@dojo/shim/Symbol';
import Map from '@dojo/shim/Map';
import { from as arrayFrom } from '@dojo/shim/array';
import { Iterable, IterableIterator, ShimIterator } from '@dojo/shim/iterator';
import { isArrayLike, isIterable, Iterable, IterableIterator, ShimIterator } from '@dojo/shim/iterator';
import Map from '@dojo/shim/Map';
import '@dojo/shim/Symbol';

/**
* A map implmentation that supports multiple keys for specific value.
Expand All @@ -21,8 +21,16 @@ export default class MultiMap<T> implements Map<any[], T> {
this._map = new Map<any, any>();
this._key = Symbol();
if (iterable) {
for (const value of iterable) {
this.set(value[0], value[1]);
if (isArrayLike(iterable)) {
for (let i = 0; i < iterable.length; i++) {
const value = iterable[i];
this.set(value[0], value[1]);
}
}
else if (isIterable(iterable)) {
for (const value of iterable) {
this.set(value[0], value[1]);
}
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/UrlSearchParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ export type ParamList = Hash<string | string[]>;
*/
function parseQueryString(input: string): ParamList {
const query: Hash<string[]> = {};
for (const entry of input.split('&')) {
const splits = input.split('&');

for (let i = 0; i < splits.length; i++) {
const entry = splits[i];
const indexOfFirstEquals = entry.indexOf('=');
let key: string;
let value = '';

if (indexOfFirstEquals >= 0) {
key = entry.slice(0, indexOfFirstEquals);
value = entry.slice(indexOfFirstEquals + 1);
} else {
}
else {
key = entry;
}

Expand All @@ -30,7 +34,7 @@ function parseQueryString(input: string): ParamList {
query[key].push(value);
}
else {
query[key] = [ value ];
query[key] = [value];
}
}
return query;
Expand Down Expand Up @@ -186,8 +190,8 @@ export default class UrlSearchParams {
const values = this._list[key];
if (values) {
const encodedKey = encodeURIComponent(key);
for (const value of values) {
query.push(encodedKey + (value ? ('=' + encodeURIComponent(value)) : ''));
for (let i = 0; i < values.length; i++) {
query.push(encodedKey + (values[i] ? ('=' + encodeURIComponent(values[i])) : ''));
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions src/async/ExtensiblePromise.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Iterable, isIterable, isArrayLike } from '@dojo/shim/iterator';
import Promise, { Executor } from '@dojo/shim/Promise';
import { Thenable } from '@dojo/shim/interfaces';
import { isArrayLike, isIterable, Iterable } from '@dojo/shim/iterator';
import Promise, { Executor } from '@dojo/shim/Promise';
import '@dojo/shim/Symbol';

/**
Expand All @@ -12,9 +12,19 @@ import '@dojo/shim/Symbol';
*/
export function unwrapPromises(iterable: Iterable<any> | any[]): any[] {
const unwrapped: any[] = [];
for (const item of iterable) {
unwrapped.push(item instanceof ExtensiblePromise ? item._promise : item);

if (isArrayLike(iterable)) {
for (let i = 0; i < iterable.length; i++) {
const item = iterable[i];
unwrapped.push(item instanceof ExtensiblePromise ? item._promise : item);
}
}
else {
for (const item of iterable) {
unwrapped.push(item instanceof ExtensiblePromise ? item._promise : item);
}
}

return unwrapped;
}

Expand Down
11 changes: 10 additions & 1 deletion src/async/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ export default class Task<T> extends ExtensiblePromise<T> {
return new Task((resolve, reject) => {
super.all(iterable).then(resolve, reject);
}, () => {
if (isIterable(iterable) || isArrayLike(iterable)) {
if (isArrayLike(iterable)) {
for (let i = 0; i < iterable.length; i++) {
const promiseLike = iterable[i];

if (isTask(promiseLike)) {
promiseLike.cancel();
}
}
}
else if (isIterable(iterable)) {
for (const promiseLike of iterable) {
if (isTask(promiseLike)) {
promiseLike.cancel();
Expand Down
11 changes: 7 additions & 4 deletions src/lang.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Handle } from '@dojo/interfaces/core';
import { assign } from '@dojo/shim/object';

export { assign } from '@dojo/shim/object';

const slice = Array.prototype.slice;
Expand All @@ -22,7 +23,7 @@ function shouldDeepCopyObject(value: any): value is Object {
function copyArray<T>(array: T[], inherited: boolean): T[] {
return array.map(function (item: T): T {
if (Array.isArray(item)) {
return <any> copyArray(<any> item, inherited);
return <any> copyArray(<any> item, inherited);
}

return !shouldDeepCopyObject(item) ?
Expand Down Expand Up @@ -51,7 +52,9 @@ function _mixin<T extends {}, U extends {}>(kwArgs: MixinArgs<T, U>): T&U {
const copied = kwArgs.copied || [];
const copiedClone = [ ...copied ];

for (let source of kwArgs.sources) {
for (let i = 0; i < kwArgs.sources.length; i++) {
const source = kwArgs.sources[i];

if (source === null || source === undefined) {
continue;
}
Expand Down Expand Up @@ -279,8 +282,8 @@ export function createHandle(destructor: () => void): Handle {
*/
export function createCompositeHandle(...handles: Handle[]): Handle {
return createHandle(function () {
for (let handle of handles) {
handle.destroy();
for (let i = 0; i < handles.length; i++) {
handles[i].destroy();
}
});
}
11 changes: 10 additions & 1 deletion src/load/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ export function isPlugin(value: any): value is LoadPlugin<any> {
export function useDefault(modules: any[]): any[];
export function useDefault(module: any): any;
export function useDefault(modules: any | any[]): any[] | any {
if (isIterable(modules) || isArrayLike(modules)) {
if (isArrayLike(modules)) {
let processedModules: any[] = [];

for (let i = 0; i < modules.length; i++) {
const module = modules[i];
processedModules.push((module.__esModule && module.default) ? module.default : module);
}

return processedModules;
} else if (isIterable(modules)) {
let processedModules: any[] = [];

for (const module of modules) {
Expand Down
10 changes: 6 additions & 4 deletions src/request/providers/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import global from '@dojo/shim/global';
import WeakMap from '@dojo/shim/WeakMap';
import Task, { State } from '../../async/Task';
import has from '../../has';
import Observable from '../../Observable';
import { createTimer } from '../../util';
import Headers from '../Headers';
import { RequestOptions, UploadObservableTask } from '../interfaces';
import Response, { getArrayBufferFromBlob, getTextFromBlob } from '../Response';
import SubscriptionPool from '../SubscriptionPool';
import TimeoutError from '../TimeoutError';
import { generateRequestUrl } from '../util';
import Observable from '../../Observable';
import SubscriptionPool from '../SubscriptionPool';

/**
* Request options specific to an XHR request
Expand Down Expand Up @@ -91,8 +91,10 @@ export class XhrResponse extends Response {

const responseHeaders = request.getAllResponseHeaders();
if (responseHeaders) {
for (let line of responseHeaders.split(/\r\n/g)) {
const match = line.match(/^(.*?): (.*)$/);
const lines = responseHeaders.split(/\r\n/g);

for (let i = 0; i < lines.length; i++) {
const match = lines[i].match(/^(.*?): (.*)$/);
if (match) {
headers.append(match[1], match[2]);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/List.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { registerSuite } = intern.getInterface('object');
const { assert } = intern.getPlugin('chai');
import List from '../../src/List';
import Set from '@dojo/shim/Set';
import List from '../../src/List';

registerSuite('List', function () {
function listWith<T>(...items: T[]): List<T> {
const list = new List<T>();

for (let item of items) {
list.add(item);
for (let i = 0; i < items.length; i++) {
list.add(items[i]);
}

return list;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"strictNullChecks": true,
"target": "es5",
"types": [ "intern" ],
"noEmitHelpers": true,
"importHelpers": true,
"downlevelIteration": true
},
"include": [
Expand Down

0 comments on commit 2b76265

Please sign in to comment.