From c3e6366dfb1d0dff7a766ac1139de8de88ae5455 Mon Sep 17 00:00:00 2001 From: Luke Sheard Date: Mon, 19 Dec 2016 00:01:47 +0000 Subject: [PATCH] Refactor typings --- package.json | 10 +- packages/inferno/src/index.js | 2 +- src/DOM/__tests__/columnrender.spec.tsx | 2 +- src/DOM/devtools.ts | 2 +- src/DOM/hydration.ts | 2 +- src/DOM/mounting.ts | 2 +- src/DOM/patching.ts | 2 +- src/DOM/recycling.ts | 2 +- src/DOM/rendering.ts | 2 +- src/DOM/unmounting.ts | 2 +- src/DOM/utils.ts | 2 +- src/DOM/wrappers/InputWrapper.ts | 2 +- src/DOM/wrappers/SelectWrapper.ts | 2 +- src/DOM/wrappers/TextareaWrapper.ts | 2 +- src/component/createClass.ts | 2 +- src/component/es2015.ts | 2 +- src/core/shapes.ts | 2 +- src/factories/cloneVNode.ts | 2 +- src/factories/createElement.ts | 2 +- src/factories/hyperscript.ts | 2 +- src/factories/isValidElement.ts | 2 +- src/inferno.d.ts | 137 --------------- src/mobx/Provider.ts | 2 +- src/mobx/__tests__/makeReactive.spec.tsx | 6 +- src/mobx/connect.ts | 2 +- src/mobx/makeReactive.ts | 2 +- src/redux/Provider.ts | 2 +- src/redux/__tests__/provider.spec.tsx | 6 +- src/redux/connect.ts | 2 +- src/router/__tests__/components.spec.tsx | 2 +- src/router/__tests__/router.spec.tsx | 2 +- src/router/__tests__/transition.spec.tsx | 2 +- src/router/match.ts | 4 +- src/router/utils.ts | 2 +- .../__tests__/creation-stream.spec.browser.ts | 2 +- src/server/__tests__/creation-stream.spec.ts | 2 +- src/server/prop-renderers.ts | 2 +- src/server/renderToString.stream.ts | 2 +- src/server/renderToString.ts | 2 +- src/{ => tools}/shared.ts | 2 +- src/tools/utils.ts | 2 +- src/typings/globals.d.ts | 37 +++++ src/typings/inferno.d.ts | 47 ++++++ test/inferno/inferno.ts | 2 +- test/karma/karma.base.conf.js | 3 + tsconfig.json | 5 +- yarn.lock | 156 +++--------------- 47 files changed, 166 insertions(+), 319 deletions(-) delete mode 100644 src/inferno.d.ts rename src/{ => tools}/shared.ts (97%) create mode 100644 src/typings/globals.d.ts create mode 100644 src/typings/inferno.d.ts diff --git a/package.json b/package.json index 0b0175c69..5c7dbd5b1 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,10 @@ "url": "https://github.com/trueadm/inferno/issues" }, "devDependencies": { - "@types/benchmark": "^1.0.30", "@types/chai": "^3.4.34", - "@types/core-js": "^0.9.35", "@types/mocha": "^2.2.33", "@types/node": "^6.0.51", + "@types/path-to-regexp": "^1.0.29", "@types/sinon": "^1.16.33", "babel-cli": "^6.18.0", "babel-core": "^6.20.0", @@ -37,7 +36,7 @@ "babel-register": "^6.18.0", "buble": "^0.14.3", "chai": "^3.5.0", - "concat-stream-es6": "0.0.1", + "concat-stream": "^1.5.2", "convert-source-map": "^1.3.0", "coveralls": "^2.11.15", "cross-env": "^3.1.3", @@ -130,9 +129,8 @@ "exclude": [ "packages", "src/DOM/devtools.ts", - "src/inferno.d.ts", - "src/**/*__tests__*/**", - "typings" + "src/typings/*.d.ts", + "src/**/*__tests__*/**" ], "extension": [ ".ts" diff --git a/packages/inferno/src/index.js b/packages/inferno/src/index.js index b899b8429..313a179f2 100644 --- a/packages/inferno/src/index.js +++ b/packages/inferno/src/index.js @@ -2,7 +2,7 @@ import { createVNode } from '../../../build/core/shapes'; import cloneVNode from '../../../build/factories/cloneVNode'; -import { warning, NO_OP, isBrowser, EMPTY_OBJ } from '../../../build/shared'; +import { warning, NO_OP, isBrowser, EMPTY_OBJ } from '../../../build/tools/shared'; import { render, findDOMNode, createRenderer, enableFindDOMNode } from '../../../build/DOM/rendering'; import { disableRecycling } from '../../../build/DOM/recycling'; import { initDevToolsHooks } from '../../../build/DOM/devtools'; diff --git a/src/DOM/__tests__/columnrender.spec.tsx b/src/DOM/__tests__/columnrender.spec.tsx index 82eec8903..67b8a1a0a 100644 --- a/src/DOM/__tests__/columnrender.spec.tsx +++ b/src/DOM/__tests__/columnrender.spec.tsx @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { spy } from 'sinon'; import Component from 'inferno-component'; -import { isNullOrUndef } from '../../shared'; +import { isNullOrUndef } from '../../tools/shared'; import Inferno, { render } from 'inferno'; Inferno; // suppress ts 'never used' error diff --git a/src/DOM/devtools.ts b/src/DOM/devtools.ts index 388b91f6f..95e8be60e 100644 --- a/src/DOM/devtools.ts +++ b/src/DOM/devtools.ts @@ -1,4 +1,4 @@ -import { isFunction, isNull, isUndefined } from '../shared'; +import { isFunction, isNull, isUndefined } from '../tools/shared'; import { render, roots } from './rendering'; export const devToolsStatus = { diff --git a/src/DOM/hydration.ts b/src/DOM/hydration.ts index df41fb0d9..4f39e3570 100644 --- a/src/DOM/hydration.ts +++ b/src/DOM/hydration.ts @@ -11,7 +11,7 @@ import { isUndefined, throwError, EMPTY_OBJ, -} from '../shared'; +} from '../tools/shared'; import { mountElement, mountStatefulComponentCallbacks, diff --git a/src/DOM/mounting.ts b/src/DOM/mounting.ts index 3e58a11b0..a663bb455 100644 --- a/src/DOM/mounting.ts +++ b/src/DOM/mounting.ts @@ -8,7 +8,7 @@ import { isUndefined, throwError, EMPTY_OBJ, -} from '../shared'; +} from '../tools/shared'; import { VNodeFlags, isVNode, copyPropsTo } from '../core/shapes'; import { appendChild, diff --git a/src/DOM/patching.ts b/src/DOM/patching.ts index 898c5bb2b..0068ecdc0 100644 --- a/src/DOM/patching.ts +++ b/src/DOM/patching.ts @@ -13,7 +13,7 @@ import { isStringOrNumber, isUndefined, throwError, -} from '../shared'; +} from '../tools/shared'; import { VNode, VNodeFlags, diff --git a/src/DOM/recycling.ts b/src/DOM/recycling.ts index 2769dc5f1..72472fc65 100644 --- a/src/DOM/recycling.ts +++ b/src/DOM/recycling.ts @@ -2,7 +2,7 @@ import { VNode, VNodeFlags } from '../core/shapes'; import { isNull, isUndefined, -} from '../shared'; +} from '../tools/shared'; import { patchComponent, patchElement, diff --git a/src/DOM/rendering.ts b/src/DOM/rendering.ts index bbc500dd3..282070288 100644 --- a/src/DOM/rendering.ts +++ b/src/DOM/rendering.ts @@ -6,7 +6,7 @@ import { isNull, isNullOrUndef, throwError, -} from '../shared'; +} from '../tools/shared'; import { devToolsStatus, sendRoots, diff --git a/src/DOM/unmounting.ts b/src/DOM/unmounting.ts index 935f49ae1..58977afa7 100644 --- a/src/DOM/unmounting.ts +++ b/src/DOM/unmounting.ts @@ -6,7 +6,7 @@ import { isObject, throwError, isNull, -} from '../shared'; +} from '../tools/shared'; import { poolComponent, poolElement, diff --git a/src/DOM/utils.ts b/src/DOM/utils.ts index 6a0b8bc8a..1c2cb2255 100644 --- a/src/DOM/utils.ts +++ b/src/DOM/utils.ts @@ -9,7 +9,7 @@ import { isUndefined, throwError, EMPTY_OBJ -} from '../shared'; +} from '../tools/shared'; import cloneVNode from '../factories/cloneVNode'; import { componentToDOMNodeMap, findDOMNodeEnabled } from './rendering'; diff --git a/src/DOM/wrappers/InputWrapper.ts b/src/DOM/wrappers/InputWrapper.ts index 6af750127..d6584c317 100644 --- a/src/DOM/wrappers/InputWrapper.ts +++ b/src/DOM/wrappers/InputWrapper.ts @@ -1,7 +1,7 @@ import { EMPTY_OBJ, isNullOrUndef -} from '../../shared'; +} from '../../tools/shared'; import { wrappers } from './processElement'; function isCheckedType(type) { diff --git a/src/DOM/wrappers/SelectWrapper.ts b/src/DOM/wrappers/SelectWrapper.ts index 37528c88e..a74024a7b 100644 --- a/src/DOM/wrappers/SelectWrapper.ts +++ b/src/DOM/wrappers/SelectWrapper.ts @@ -2,7 +2,7 @@ import { isArray, EMPTY_OBJ, isNullOrUndef -} from '../../shared'; +} from '../../tools/shared'; import { wrappers } from './processElement'; import { isVNode } from '../../core/shapes'; diff --git a/src/DOM/wrappers/TextareaWrapper.ts b/src/DOM/wrappers/TextareaWrapper.ts index 535ae95d1..4926f6629 100644 --- a/src/DOM/wrappers/TextareaWrapper.ts +++ b/src/DOM/wrappers/TextareaWrapper.ts @@ -1,7 +1,7 @@ import { EMPTY_OBJ, isNullOrUndef -} from '../../shared'; +} from '../../tools/shared'; import { wrappers } from './processElement'; function isControlled(props) { diff --git a/src/component/createClass.ts b/src/component/createClass.ts index 79a92d444..b3b42b52e 100644 --- a/src/component/createClass.ts +++ b/src/component/createClass.ts @@ -1,4 +1,4 @@ -import { isFunction, isNullOrUndef, isUndefined } from '../shared'; +import { isFunction, isNullOrUndef, isUndefined } from '../tools/shared'; import Component from 'inferno-component'; import { ComponentSpec } from './es2015'; diff --git a/src/component/es2015.ts b/src/component/es2015.ts index d90d498df..a910b8418 100644 --- a/src/component/es2015.ts +++ b/src/component/es2015.ts @@ -6,7 +6,7 @@ import { isNullOrUndef, throwError, ERROR_MSG -} from '../shared'; +} from '../tools/shared'; import { Props, VNode, diff --git a/src/core/shapes.ts b/src/core/shapes.ts index 7afed4089..99da54d4a 100644 --- a/src/core/shapes.ts +++ b/src/core/shapes.ts @@ -7,7 +7,7 @@ import { isUndefined, isString, isNull -} from '../shared'; +} from '../tools/shared'; import cloneVNode from '../factories/cloneVNode'; diff --git a/src/factories/cloneVNode.ts b/src/factories/cloneVNode.ts index 06b9db2d6..26e6e22aa 100644 --- a/src/factories/cloneVNode.ts +++ b/src/factories/cloneVNode.ts @@ -12,7 +12,7 @@ import { isNullOrUndef, isUndefined, isInvalid -} from '../shared'; +} from '../tools/shared'; export default function cloneVNode(vNodeToClone: VNode, props?: Props, ..._children: InfernoChildren[]): VNode { let children: any = _children; diff --git a/src/factories/createElement.ts b/src/factories/createElement.ts index bc05f494a..687601401 100644 --- a/src/factories/createElement.ts +++ b/src/factories/createElement.ts @@ -12,7 +12,7 @@ import { isUndefined, isObject, isStatefulComponent -} from '../shared'; +} from '../tools/shared'; const componentHooks = { onComponentWillMount: true, diff --git a/src/factories/hyperscript.ts b/src/factories/hyperscript.ts index c1ef0feee..92e4fa7d1 100644 --- a/src/factories/hyperscript.ts +++ b/src/factories/hyperscript.ts @@ -10,7 +10,7 @@ import { isString, isStringOrNumber, isUndefined, -} from '../shared'; +} from '../tools/shared'; const classIdSplit = /([.#]?[a-zA-Z0-9_:-]+)/; const notClassId = /^\.|#/; diff --git a/src/factories/isValidElement.ts b/src/factories/isValidElement.ts index e9da85f7c..7d386622a 100644 --- a/src/factories/isValidElement.ts +++ b/src/factories/isValidElement.ts @@ -5,7 +5,7 @@ import { import { isNull, isObject -} from '../shared'; +} from '../tools/shared'; export default function isValidElement(obj: VNode): boolean { const isNotANullObject = isObject(obj) && isNull(obj) === false; diff --git a/src/inferno.d.ts b/src/inferno.d.ts deleted file mode 100644 index 08209c0d1..000000000 --- a/src/inferno.d.ts +++ /dev/null @@ -1,137 +0,0 @@ -declare module 'inferno' { - export function createVNode(flags, type?, props?, children?, events?, key?, ref?, noNormalise?: boolean): any; - export function cloneVNode(node, props?, ...children); - export function render(...rest); - export function findDOMNode(node: any): any; - export function createRenderer(...rest); - export function disableRecycling(...rest); - export function linkEvent(data, event: Function); - export function enableFindDOMNode(); - export const NO_OP; - export const ERROR_MSG; - export const EMPTY_OBJ; -} - -declare module 'inferno-component' { - class Component { - refs?: any; - state?: any; - props?: P; - context?: C; - _unmounted?: boolean; - constructor (props?: P, context?: C); - componentWillReact(); - componentWillReceiveProps? (nextProps: P, nextContext: C): void; - forceUpdate (): void; - setState (v: Object, cb?: () => {}): boolean; - isPrototypeOf (v: Object): void; - } - export default Component; -} - -declare module 'inferno-server' { - export function renderToStaticMarkup(...rest); - export default function renderToString(...rest); -} - -declare module 'inferno-create-class' { - export default function createClass(component: any): any; -} - -declare module 'inferno-create-element' { - export default function createElement(component: any, props: any, ...children): any; -} - -declare module 'inferno-hyperscript' { - export default function hyperscript(tag: any, props?: any, ...children): any; -} - -declare module 'lodash/isPlainObject' { - function isPlainObject(value: any): boolean; - export = isPlainObject; -} - -declare module 'invariant' { - function invariant(condition: any, message: string): void; - export = invariant; -} - -declare module 'hoist-non-inferno-statics' { - function hoistStatics(connectClass: any, wrappedComponent: any): {[index: string]: any}; - export = hoistStatics; -} - -declare module 'path-to-regexp-es6' { - function pathToRegExp(routePath: any, keys: any, end: any); - export default pathToRegExp; -} - -declare module 'concat-stream-es6' { - function concatStream(func?: any); - export default concatStream; -} - -declare module 'history/createBrowserHistory' { - function createBrowserHistory(options?: any); - export = createBrowserHistory; -} - -declare module 'history/createMemoryHistory' { - function createMemoryHistory(options?: any); - export = createMemoryHistory; -} - -declare module 'mobx' { - export function toJS(value: any): any; - export function observable(value: any): any; - export function isObservable(value: any, property?: string): boolean; - export function extendObservable(...rest): any; - export class Reaction { - constructor(name?: string, onInvalidate?: any); - track(param: any): void; - runReaction(); - dispose(); - getDisposer(): any; - } - export const extras: any; -} - -declare module 'redux' { - export function createStore(callback: any): any; - export function bindActionCreators(actionCreators: any, dispatch: any): any; -} - -declare module 'sinon' { - export function spy(obj: any, event: string): any; - export function stub(obj: any, event: string, callback: any): any; - export const assert; -} - -declare module 'most' { - export function map(f?: any, stream?: any): any; - export function reduce(f?: any, intitial?: any, stream?: any): any; - export function scan(f?: any, initial?: any, stream?: any): any; -} - -declare module 'most-subject' { - export function hold(bufferSize?: number, subject?: any): any; - export function sync(): void; -} - -declare module 'lodash/fp' { - export function curry(obj: any): any; -} - -declare module 'union-type-es' { - export default function (obj: any): any; -} - -interface Window { process: any; __karma__: any; mocha: any; } - -//noinspection TsLint -declare namespace process { - //noinspection TsLint - export interface env { - NODE_ENV: any; - } -} diff --git a/src/mobx/Provider.ts b/src/mobx/Provider.ts index d8ae68b62..367786046 100644 --- a/src/mobx/Provider.ts +++ b/src/mobx/Provider.ts @@ -1,5 +1,5 @@ import Component from 'inferno-component'; -import { warning } from '../shared'; +import { warning } from '../tools/shared'; const specialKeys = { children: true, diff --git a/src/mobx/__tests__/makeReactive.spec.tsx b/src/mobx/__tests__/makeReactive.spec.tsx index 23384a201..3b7011ef2 100644 --- a/src/mobx/__tests__/makeReactive.spec.tsx +++ b/src/mobx/__tests__/makeReactive.spec.tsx @@ -10,7 +10,7 @@ describe('MobX Observer', () => { let container; let store = { todos: observable(['one', 'two']), - extra: observable({ test: 'observable!' }) + extra: observable({ test: 'observable!' }) as any // TOOD: {LukeSheard} Fix this hack }; beforeEach(() => { @@ -65,7 +65,9 @@ describe('MobX Observer', () => { }); render(, container); - store.extra = toJS({ test: 'XXX' }); + store.extra = toJS({ + test: 'XXX' + }); render(, container); extendObservable(store, { test: 'new entry' diff --git a/src/mobx/connect.ts b/src/mobx/connect.ts index b6c531b93..b61f745f3 100644 --- a/src/mobx/connect.ts +++ b/src/mobx/connect.ts @@ -2,7 +2,7 @@ import Component from 'inferno-component'; import createClass from 'inferno-create-class'; import inject from './inject'; import makeReactive from './makeReactive'; -import { throwError } from '../shared'; +import { throwError } from '../tools/shared'; /** * Wraps a component and provides stores as props diff --git a/src/mobx/makeReactive.ts b/src/mobx/makeReactive.ts index 8e897a2dd..7bcc3d794 100644 --- a/src/mobx/makeReactive.ts +++ b/src/mobx/makeReactive.ts @@ -2,7 +2,7 @@ import { Reaction, extras, isObservable } from 'mobx'; import Component from 'inferno-component'; import EventEmitter from './EventEmitter'; -import { throwError } from '../shared'; +import { throwError } from '../tools/shared'; /** * Dev tools support diff --git a/src/redux/Provider.ts b/src/redux/Provider.ts index 175039631..c969783c5 100644 --- a/src/redux/Provider.ts +++ b/src/redux/Provider.ts @@ -3,7 +3,7 @@ import { warning } from './utils'; import { isNullOrUndef, toArray -} from '../shared'; +} from '../tools/shared'; let didWarnAboutReceivingStore = false; function warnAboutReceivingStore() { diff --git a/src/redux/__tests__/provider.spec.tsx b/src/redux/__tests__/provider.spec.tsx index e34580e3b..c350d4360 100644 --- a/src/redux/__tests__/provider.spec.tsx +++ b/src/redux/__tests__/provider.spec.tsx @@ -2,8 +2,10 @@ import IndexRoute from '../../router/IndexRoute'; import Provider from '../Provider'; import Route from '../../router/Route'; import Router from '../../router/Router'; -import createBrowserHistory from 'history/createBrowserHistory'; -import createMemoryHistory from 'history/createMemoryHistory'; +import { + createBrowserHistory, + createMemoryHistory + } from 'history'; import { innerHTML } from '../../tools/utils'; import { createStore } from 'redux'; import { expect } from 'chai'; diff --git a/src/redux/connect.ts b/src/redux/connect.ts index fca665106..978d50e45 100644 --- a/src/redux/connect.ts +++ b/src/redux/connect.ts @@ -1,4 +1,4 @@ -import { isFunction, throwError } from '../shared'; +import { isFunction, throwError } from '../tools/shared'; import { shallowEqual, warning, diff --git a/src/router/__tests__/components.spec.tsx b/src/router/__tests__/components.spec.tsx index 25181c49d..42a1e5f33 100644 --- a/src/router/__tests__/components.spec.tsx +++ b/src/router/__tests__/components.spec.tsx @@ -5,7 +5,7 @@ import Router from '../Router'; import IndexLink from '../IndexLink'; import Link from '../Link'; import { innerHTML } from '../../tools/utils'; -import createMemoryHistory from 'history/createMemoryHistory'; +import { createMemoryHistory } from 'history'; import { expect } from 'chai'; diff --git a/src/router/__tests__/router.spec.tsx b/src/router/__tests__/router.spec.tsx index 821772e5e..efc3fe7da 100644 --- a/src/router/__tests__/router.spec.tsx +++ b/src/router/__tests__/router.spec.tsx @@ -4,7 +4,7 @@ import { innerHTML } from '../../tools/utils'; import Route from '../Route'; import Router from '../Router'; import RouterContext from '../RouterContext'; -import createBrowserHistory from 'history/createBrowserHistory'; +import { createBrowserHistory } from 'history'; import { expect, } from 'chai'; diff --git a/src/router/__tests__/transition.spec.tsx b/src/router/__tests__/transition.spec.tsx index 9b76ae6f8..48d7c838b 100644 --- a/src/router/__tests__/transition.spec.tsx +++ b/src/router/__tests__/transition.spec.tsx @@ -5,7 +5,7 @@ import { innerHTML } from '../../tools/utils'; import Router from '../Router'; import Route from '../Route'; import IndexRoute from '../IndexRoute'; -import createMemoryHistory from 'history/createMemoryHistory'; +import { createMemoryHistory } from 'history'; Inferno; // suppress ts 'never used' error const browserHistory = createMemoryHistory(); diff --git a/src/router/match.ts b/src/router/match.ts index df8f42a52..8bb56608a 100644 --- a/src/router/match.ts +++ b/src/router/match.ts @@ -1,7 +1,7 @@ import Inferno from 'inferno'; -import pathToRegExp from 'path-to-regexp-es6'; +import pathToRegExp from 'path-to-regexp'; import { decode, flatten, getURLString, isEmpty, mapSearchParams, pathRankSort, toPartialURL } from './utils'; -import { isArray, toArray } from '../shared'; +import { isArray, toArray } from '../tools/shared'; const cache: Map = new Map(); diff --git a/src/router/utils.ts b/src/router/utils.ts index 7c62a02b4..cb53c920e 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -1,4 +1,4 @@ -import { isArray, isString } from '../shared'; +import { isArray, isString } from '../tools/shared'; const emptyObject = Object.create(null); diff --git a/src/server/__tests__/creation-stream.spec.browser.ts b/src/server/__tests__/creation-stream.spec.browser.ts index 40fe3d4a8..1fedc9a24 100644 --- a/src/server/__tests__/creation-stream.spec.browser.ts +++ b/src/server/__tests__/creation-stream.spec.browser.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import streamAsString from '../renderToString.stream'; -import concatStream from 'concat-stream-es6'; +import concatStream from 'concat-stream'; import Component from 'inferno-component'; import createElement from 'inferno-create-element'; diff --git a/src/server/__tests__/creation-stream.spec.ts b/src/server/__tests__/creation-stream.spec.ts index fb7c67b2f..115aeb61b 100644 --- a/src/server/__tests__/creation-stream.spec.ts +++ b/src/server/__tests__/creation-stream.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { streamAsStaticMarkup } from '../renderToString.stream'; -import concatStream from 'concat-stream-es6'; +import concatStream from 'concat-stream'; import createElement from 'inferno-create-element'; import createClass from 'inferno-create-class'; diff --git a/src/server/prop-renderers.ts b/src/server/prop-renderers.ts index db1333f08..497943ce2 100644 --- a/src/server/prop-renderers.ts +++ b/src/server/prop-renderers.ts @@ -7,7 +7,7 @@ import { isNumber, isStringOrNumber, isTrue, -} from '../shared'; +} from '../tools/shared'; import { isUnitlessNumber } from '../DOM/constants'; diff --git a/src/server/renderToString.stream.ts b/src/server/renderToString.stream.ts index 3e9097da0..5e56fd0ea 100644 --- a/src/server/renderToString.stream.ts +++ b/src/server/renderToString.stream.ts @@ -7,7 +7,7 @@ import { isInvalid, isNullOrUndef, isStringOrNumber, -} from '../shared'; +} from '../tools/shared'; import { renderAttributes, renderStyleToString, diff --git a/src/server/renderToString.ts b/src/server/renderToString.ts index ea45d1062..134857110 100644 --- a/src/server/renderToString.ts +++ b/src/server/renderToString.ts @@ -14,7 +14,7 @@ import { isTrue, isFunction, throwError, -} from '../shared'; +} from '../tools/shared'; import { VNodeFlags, diff --git a/src/shared.ts b/src/tools/shared.ts similarity index 97% rename from src/shared.ts rename to src/tools/shared.ts index 5674ade41..a3694d5cd 100644 --- a/src/shared.ts +++ b/src/tools/shared.ts @@ -3,7 +3,7 @@ export const ERROR_MSG = 'a runtime error occured! Use Inferno in development en export const isBrowser = typeof window !== 'undefined' && window.document; -export function toArray(children): Array { +export function toArray(children): any[] { return isArray(children) ? children : (children ? [children] : children); } diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 79f203c6a..17157ab34 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -2,7 +2,7 @@ import { isArray, isNullOrUndef, isStringOrNumber, -} from '../shared'; +} from '../tools/shared'; import { VNodeFlags } from '../core/shapes'; diff --git a/src/typings/globals.d.ts b/src/typings/globals.d.ts new file mode 100644 index 000000000..7baf7c6be --- /dev/null +++ b/src/typings/globals.d.ts @@ -0,0 +1,37 @@ +/* tslint:disable */ +declare module 'hoist-non-inferno-statics' { + function hoistStatics(connectClass: any, wrappedComponent: any): {[index: string]: any}; + export = hoistStatics; +} + +declare module 'concat-stream' { + function concatStream(func?: any); + export default concatStream; +} + +declare module 'history' { + export function createBrowserHistory(): any; + export function createMemoryHistory(): any; +} + +declare module 'lodash/fp' { + export function curry(obj: any): any; +} + +declare module 'union-type-es' { + export default function (obj: any): any; +} + +interface Window { + process: any; + __karma__: any; + mocha: any; +} + +//noinspection TsLint +declare namespace process { + //noinspection TsLint + export interface env { + NODE_ENV: any; + } +} diff --git a/src/typings/inferno.d.ts b/src/typings/inferno.d.ts new file mode 100644 index 000000000..29ebc7800 --- /dev/null +++ b/src/typings/inferno.d.ts @@ -0,0 +1,47 @@ +declare module 'inferno' { + export function createVNode(flags, type?, props?, children?, events?, key?, ref?, noNormalise?: boolean): any; + export function cloneVNode(node, props?, ...children); + export function render(...rest); + export function findDOMNode(node: any): any; + export function createRenderer(...rest); + export function disableRecycling(...rest); + export function linkEvent(data, event: Function); + export function enableFindDOMNode(); + export const NO_OP; + export const ERROR_MSG; + export const EMPTY_OBJ; +} + +declare module 'inferno-component' { + class Component { + refs?: any; + state?: any; + props?: P; + context?: C; + _unmounted?: boolean; + constructor (props?: P, context?: C); + componentWillReact(); + componentWillReceiveProps? (nextProps: P, nextContext: C): void; + forceUpdate (): void; + setState (v: Object, cb?: () => {}): boolean; + isPrototypeOf (v: Object): void; + } + export default Component; +} + +declare module 'inferno-server' { + export function renderToStaticMarkup(...rest); + export default function renderToString(...rest); +} + +declare module 'inferno-create-class' { + export default function createClass(component: any): any; +} + +declare module 'inferno-create-element' { + export default function createElement(component: any, props: any, ...children): any; +} + +declare module 'inferno-hyperscript' { + export default function hyperscript(tag: any, props?: any, ...children): any; +} diff --git a/test/inferno/inferno.ts b/test/inferno/inferno.ts index 49f7f47bf..ba25ea317 100644 --- a/test/inferno/inferno.ts +++ b/test/inferno/inferno.ts @@ -14,7 +14,7 @@ import { import { EMPTY_OBJ, NO_OP -} from '../../src/shared'; +} from '../../src/tools/shared'; import linkEvent from '../../src/DOM/events/linkEvent'; export { diff --git a/test/karma/karma.base.conf.js b/test/karma/karma.base.conf.js index 0039ab937..0d380a64e 100644 --- a/test/karma/karma.base.conf.js +++ b/test/karma/karma.base.conf.js @@ -25,6 +25,9 @@ module.exports = function (config) { }, resolve: { extensions: [ '.js', '.jsx', '.ts', '.tsx' ] + }, + performance: { + hints: false } }, webpackMiddleware: { diff --git a/tsconfig.json b/tsconfig.json index f22d8a2fa..3d2cfc317 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "version": "2.1.4", "compilerOptions": { + "moduleResolution": "node", "target": "es6", "module": "es6", "allowJs": false, @@ -15,7 +16,9 @@ "node", "mocha", "sinon", - "chai" + "chai", + "mobx", + "path-to-regexp" ], "jsx": "preserve", "noUnusedLocals": true, diff --git a/yarn.lock b/yarn.lock index 8bcf3d8b6..bc19c97af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,18 +12,10 @@ version "1.4.1" resolved "https://registry.yarnpkg.com/@most/prelude/-/prelude-1.4.1.tgz#b940b5563096f27637401618a5351f42466ea8f3" -"@types/benchmark@^1.0.30": - version "1.0.30" - resolved "https://registry.yarnpkg.com/@types/benchmark/-/benchmark-1.0.30.tgz#f6bea0baceb178155968b9984f94546f63677592" - "@types/chai@^3.4.34": version "3.4.34" resolved "https://registry.yarnpkg.com/@types/chai/-/chai-3.4.34.tgz#d5335792823bb09cddd5e38c3d211b709183854d" -"@types/core-js@^0.9.35": - version "0.9.35" - resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-0.9.35.tgz#444064e63711cdcc62ea844d27642f6efc2285f2" - "@types/mocha@^2.2.33": version "2.2.33" resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.33.tgz#d79a0061ec270379f4d9e225f4096fb436669def" @@ -355,15 +347,7 @@ babel-cli@^6.18.0: optionalDependencies: chokidar "^1.0.0" -babel-code-frame@^6.16.0: - version "6.16.0" - resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.16.0.tgz#f90e60da0862909d3ce098733b5d3987c97cb8de" - dependencies: - chalk "^1.1.0" - esutils "^2.0.2" - js-tokens "^2.0.0" - -babel-code-frame@^6.20.0: +babel-code-frame@^6.16.0, babel-code-frame@^6.20.0: version "6.20.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.20.0.tgz#b968f839090f9a8bc6d41938fb96cb84f7387b26" dependencies: @@ -371,31 +355,7 @@ babel-code-frame@^6.20.0: esutils "^2.0.2" js-tokens "^2.0.0" -babel-core@6, babel-core@^6.18.0: - version "6.18.2" - resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.18.2.tgz#d8bb14dd6986fa4f3566a26ceda3964fa0e04e5b" - dependencies: - babel-code-frame "^6.16.0" - babel-generator "^6.18.0" - babel-helpers "^6.16.0" - babel-messages "^6.8.0" - babel-register "^6.18.0" - babel-runtime "^6.9.1" - babel-template "^6.16.0" - babel-traverse "^6.18.0" - babel-types "^6.18.0" - babylon "^6.11.0" - convert-source-map "^1.1.0" - debug "^2.1.1" - json5 "^0.5.0" - lodash "^4.2.0" - minimatch "^3.0.2" - path-is-absolute "^1.0.0" - private "^0.1.6" - slash "^1.0.0" - source-map "^0.5.0" - -babel-core@^6.20.0: +babel-core@6, babel-core@^6.18.0, babel-core@^6.20.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.21.0.tgz#75525480c21c803f826ef3867d22c19f080a3724" dependencies: @@ -429,19 +389,7 @@ babel-eslint@^7.1.1: babylon "^6.13.0" lodash.pickby "^4.6.0" -babel-generator@^6.18.0: - version "6.19.0" - resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.19.0.tgz#9b2f244204777a3d6810ec127c673c87b349fac5" - dependencies: - babel-messages "^6.8.0" - babel-runtime "^6.9.0" - babel-types "^6.19.0" - detect-indent "^4.0.0" - jsesc "^1.3.0" - lodash "^4.2.0" - source-map "^0.5.0" - -babel-generator@^6.21.0: +babel-generator@^6.18.0, babel-generator@^6.21.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.21.0.tgz#605f1269c489a1c75deeca7ea16d43d4656c8494" dependencies: @@ -867,14 +815,7 @@ babel-plugin-transform-object-assign@^6.8.0: dependencies: babel-runtime "^6.0.0" -babel-plugin-transform-object-rest-spread@^6.16.0: - version "6.19.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.19.0.tgz#f6ac428ee3cb4c6aa00943ed1422ce813603b34c" - dependencies: - babel-plugin-syntax-object-rest-spread "^6.8.0" - babel-runtime "^6.0.0" - -babel-plugin-transform-object-rest-spread@^6.20.2: +babel-plugin-transform-object-rest-spread@^6.16.0, babel-plugin-transform-object-rest-spread@^6.20.2: version "6.20.2" resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.20.2.tgz#e816c55bba77b14c16365d87e2ae48c8fd18fc2e" dependencies: @@ -902,15 +843,7 @@ babel-plugin-transform-undefined-to-void@^6.8.0: dependencies: babel-runtime "^6.0.0" -babel-polyfill@^6.16.0: - version "6.16.0" - resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.16.0.tgz#2d45021df87e26a374b6d4d1a9c65964d17f2422" - dependencies: - babel-runtime "^6.9.1" - core-js "^2.4.0" - regenerator-runtime "^0.9.5" - -babel-polyfill@^6.20.0: +babel-polyfill@^6.16.0, babel-polyfill@^6.20.0: version "6.20.0" resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.20.0.tgz#de4a371006139e20990aac0be367d398331204e7" dependencies: @@ -978,20 +911,20 @@ babel-register@^6.18.0: mkdirp "^0.5.1" source-map-support "^0.4.2" -babel-runtime@^6.0.0, babel-runtime@^6.11.6, babel-runtime@^6.9.0, babel-runtime@^6.9.1: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.18.0.tgz#0f4177ffd98492ef13b9f823e9994a02584c9078" - dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.9.5" - -babel-runtime@^6.20.0: +babel-runtime@^6.0.0, babel-runtime@^6.11.6, babel-runtime@^6.20.0, babel-runtime@^6.9.1: version "6.20.0" resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.20.0.tgz#87300bdcf4cd770f09bf0048c64204e17806d16f" dependencies: core-js "^2.4.0" regenerator-runtime "^0.10.0" +babel-runtime@^6.9.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.18.0.tgz#0f4177ffd98492ef13b9f823e9994a02584c9078" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.9.5" + babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-template@^6.8.0: version "6.16.0" resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.16.0.tgz#e149dd1a9f03a35f817ddbc4d0481988e7ebc8ca" @@ -1002,7 +935,7 @@ babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-te babylon "^6.11.0" lodash "^4.2.0" -babel-traverse@^6.15.0, babel-traverse@^6.21.0: +babel-traverse@^6.15.0, babel-traverse@^6.16.0, babel-traverse@^6.18.0, babel-traverse@^6.21.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.21.0.tgz#69c6365804f1a4f69eb1213f85b00a818b8c21ad" dependencies: @@ -1016,30 +949,7 @@ babel-traverse@^6.15.0, babel-traverse@^6.21.0: invariant "^2.2.0" lodash "^4.2.0" -babel-traverse@^6.16.0, babel-traverse@^6.18.0: - version "6.19.0" - resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.19.0.tgz#68363fb821e26247d52a519a84b2ceab8df4f55a" - dependencies: - babel-code-frame "^6.16.0" - babel-messages "^6.8.0" - babel-runtime "^6.9.0" - babel-types "^6.19.0" - babylon "^6.11.0" - debug "^2.2.0" - globals "^9.0.0" - invariant "^2.2.0" - lodash "^4.2.0" - -babel-types@^6.13.0, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.8.0, babel-types@^6.9.0: - version "6.19.0" - resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.19.0.tgz#8db2972dbed01f1192a8b602ba1e1e4c516240b9" - dependencies: - babel-runtime "^6.9.1" - esutils "^2.0.2" - lodash "^4.2.0" - to-fast-properties "^1.0.1" - -babel-types@^6.15.0, babel-types@^6.21.0: +babel-types@^6.13.0, babel-types@^6.15.0, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.21.0, babel-types@^6.8.0, babel-types@^6.9.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.21.0.tgz#314b92168891ef6d3806b7f7a917fdf87c11a4b2" dependencies: @@ -1263,19 +1173,7 @@ browserify-zlib@^0.1.4: dependencies: pako "~0.2.0" -buble@^0.14.0: - version "0.14.2" - resolved "https://registry.yarnpkg.com/buble/-/buble-0.14.2.tgz#5e2ffd5469693068731d77c9c98909aee61e5e6f" - dependencies: - acorn "^3.3.0" - acorn-jsx "^3.0.1" - acorn-object-spread "^1.0.0" - chalk "^1.1.3" - magic-string "^0.14.0" - minimist "^1.2.0" - os-homedir "^1.0.1" - -buble@^0.14.3: +buble@^0.14.0, buble@^0.14.3: version "0.14.3" resolved "https://registry.yarnpkg.com/buble/-/buble-0.14.3.tgz#678cb1fc24dc90e5ada047deaa5ddc6f6da8983e" dependencies: @@ -1529,13 +1427,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -concat-stream-es6@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-stream-es6/-/concat-stream-es6-0.0.1.tgz#bedbcf06c4e7cde08d6c5921265e977d4bdc5875" - dependencies: - concat-stream "*" - -concat-stream@*, concat-stream@^1.4.6, concat-stream@^1.4.7: +concat-stream@^1.4.6, concat-stream@^1.4.7, concat-stream@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266" dependencies: @@ -4260,11 +4152,10 @@ read-pkg@^1.0.0: normalize-package-data "^2.3.2" path-type "^1.0.0" -readable-stream@^2.0.0, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.5, readable-stream@^2.1.0, readable-stream@~2.1.4: - version "2.1.5" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.1.5.tgz#66fa8b720e1438b364681f2ad1a63c618448c9d0" +readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@~2.0.0, readable-stream@~2.0.5: + version "2.0.6" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e" dependencies: - buffer-shims "^1.0.0" core-util-is "~1.0.0" inherits "~2.0.1" isarray "~1.0.0" @@ -4272,10 +4163,11 @@ readable-stream@^2.0.0, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2. string_decoder "~0.10.x" util-deprecate "~1.0.1" -readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@~2.0.0, readable-stream@~2.0.5: - version "2.0.6" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e" +"readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.1.0, readable-stream@~2.1.4: + version "2.1.5" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.1.5.tgz#66fa8b720e1438b364681f2ad1a63c618448c9d0" dependencies: + buffer-shims "^1.0.0" core-util-is "~1.0.0" inherits "~2.0.1" isarray "~1.0.0"