From 143611497f7ac6219826530f22da586530838189 Mon Sep 17 00:00:00 2001 From: Stanislav Panferov Date: Sun, 29 Jan 2017 16:47:16 +0300 Subject: [PATCH] feat: refactor tests, fix #349, #323, #335 --- .babelrc | 3 - .gitignore | 3 +- .node-version | 1 - .travis.yml | 7 +- index.js | 3 + package.json | 36 +- src/__test__/babel.ts | 58 + src/__test__/declaration.ts | 57 + src/__test__/error.ts | 31 + src/__test__/react.ts | 39 + src/__test__/remove.ts | 47 + src/__test__/simple.ts | 27 + src/__test__/utils.ts | 278 ++ src/__test__/watch.ts | 47 + src/cache.ts | 2 +- src/checker/checker.ts | 2 +- src/checker/protocol.ts | 1 + src/checker/runtime.ts | 63 +- src/index.ts | 26 +- src/instance.ts | 32 +- src/interfaces.ts | 1 + src/test/babel.ts | 57 - src/test/declaration.ts | 29 - src/test/fixtures/babel/babel.js | 4 - src/test/fixtures/babel/babel.ts | 5 - src/test/fixtures/basic/basic.js | 5 - src/test/fixtures/basic/basic.ts | 5 - src/test/fixtures/checker/to-check.ts | 1 - src/test/fixtures/declaration/basic.ts | 3 - src/test/fixtures/declaration/iface.ts | 4 - src/test/fixtures/errors/with-type-errors.ts | 7 - src/test/fixtures/react/index.tsx | 4 - src/test/fixtures/react/tsconfig.json | 13 - src/test/fixtures/salsa/index.js | 3 - src/test/fixtures/salsa/index.ts | 3 - src/test/fixtures/salsa/lib.js | 8 - src/test/fixtures/salsa/tsconfig.json | 9 - src/test/fixtures/tsx/basic.tsx | 7 - src/test/fixtures/tsx/package.json | 11 - src/test/fixtures/tsx/tsconfig.json | 11 - src/test/fixtures/typeRoots/index.ts | 4 - src/test/fixtures/typeRoots/tsconfig.json | 8 - src/test/index.ts | 66 - .../node_modules/@types/jasmine/README.md | 18 - .../node_modules/@types/jasmine/index.d.ts | 537 ---- .../node_modules/@types/jasmine/package.json | 79 - .../@types/jasmine/types-metadata.json | 40 - .../node_modules/@types/react-dom/README.md | 18 - .../node_modules/@types/react-dom/index.d.ts | 64 - .../@types/react-dom/package.json | 80 - .../@types/react-dom/react-dom.server.d.ts | 7 - .../@types/react-dom/types-metadata.json | 28 - src/test/node_modules/@types/react/README.md | 18 - src/test/node_modules/@types/react/index.d.ts | 2530 ----------------- .../node_modules/@types/react/package.json | 79 - .../@types/react/types-metadata.json | 23 - src/test/package.json | 15 - src/test/react.ts | 28 - src/test/salsa.ts | 30 - src/test/typeRoots.ts | 26 - src/test/utils.ts | 211 -- src/test/watch-type-errors.ts | 43 - src/test/without-sourcemap.ts | 26 - tsconfig.json | 8 +- tsd.json | 21 - webpack.backend.config.js | 70 - yarn.lock | 984 ++----- 67 files changed, 939 insertions(+), 5075 deletions(-) delete mode 100644 .babelrc delete mode 100644 .node-version create mode 100644 index.js create mode 100644 src/__test__/babel.ts create mode 100644 src/__test__/declaration.ts create mode 100644 src/__test__/error.ts create mode 100644 src/__test__/react.ts create mode 100644 src/__test__/remove.ts create mode 100644 src/__test__/simple.ts create mode 100644 src/__test__/utils.ts create mode 100644 src/__test__/watch.ts delete mode 100644 src/test/babel.ts delete mode 100644 src/test/declaration.ts delete mode 100644 src/test/fixtures/babel/babel.js delete mode 100644 src/test/fixtures/babel/babel.ts delete mode 100644 src/test/fixtures/basic/basic.js delete mode 100644 src/test/fixtures/basic/basic.ts delete mode 100644 src/test/fixtures/checker/to-check.ts delete mode 100644 src/test/fixtures/declaration/basic.ts delete mode 100644 src/test/fixtures/declaration/iface.ts delete mode 100644 src/test/fixtures/errors/with-type-errors.ts delete mode 100644 src/test/fixtures/react/index.tsx delete mode 100644 src/test/fixtures/react/tsconfig.json delete mode 100644 src/test/fixtures/salsa/index.js delete mode 100644 src/test/fixtures/salsa/index.ts delete mode 100644 src/test/fixtures/salsa/lib.js delete mode 100644 src/test/fixtures/salsa/tsconfig.json delete mode 100644 src/test/fixtures/tsx/basic.tsx delete mode 100644 src/test/fixtures/tsx/package.json delete mode 100644 src/test/fixtures/tsx/tsconfig.json delete mode 100644 src/test/fixtures/typeRoots/index.ts delete mode 100644 src/test/fixtures/typeRoots/tsconfig.json delete mode 100644 src/test/index.ts delete mode 100644 src/test/node_modules/@types/jasmine/README.md delete mode 100644 src/test/node_modules/@types/jasmine/index.d.ts delete mode 100644 src/test/node_modules/@types/jasmine/package.json delete mode 100644 src/test/node_modules/@types/jasmine/types-metadata.json delete mode 100644 src/test/node_modules/@types/react-dom/README.md delete mode 100644 src/test/node_modules/@types/react-dom/index.d.ts delete mode 100644 src/test/node_modules/@types/react-dom/package.json delete mode 100644 src/test/node_modules/@types/react-dom/react-dom.server.d.ts delete mode 100644 src/test/node_modules/@types/react-dom/types-metadata.json delete mode 100644 src/test/node_modules/@types/react/README.md delete mode 100644 src/test/node_modules/@types/react/index.d.ts delete mode 100644 src/test/node_modules/@types/react/package.json delete mode 100644 src/test/node_modules/@types/react/types-metadata.json delete mode 100644 src/test/package.json delete mode 100644 src/test/react.ts delete mode 100644 src/test/salsa.ts delete mode 100644 src/test/typeRoots.ts delete mode 100644 src/test/utils.ts delete mode 100644 src/test/watch-type-errors.ts delete mode 100644 src/test/without-sourcemap.ts delete mode 100644 tsd.json delete mode 100644 webpack.backend.config.js diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 341ac6d..0000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": [ "es2015" ] -} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1b2ad7c..ba2d967 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ src/test/output .vagrant Vagrantfile issues -.idea \ No newline at end of file +.idea +.test diff --git a/.node-version b/.node-version deleted file mode 100644 index 1e8b314..0000000 --- a/.node-version +++ /dev/null @@ -1 +0,0 @@ -6 diff --git a/.travis.yml b/.travis.yml index ae68fb1..e51f431 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ sudo: false language: node_js +before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH=$HOME/.yarn/bin:$PATH before_script: - - npm i - - npm run compile + - yarn i + - yarn run build node_js: - "7" diff --git a/index.js b/index.js new file mode 100644 index 0000000..8a47bdc --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +var loader = require('./dist'); + +module.exports = loader; \ No newline at end of file diff --git a/package.json b/package.json index b5b450c..38879eb 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,14 @@ "typings": "./dist/index.d.ts", "scripts": { "prepublish": "npm run build", - "test": "mocha dist/test --harmony-async-await", "watch": "npm run watch:ts", "watch:ts": "npm run build:ts -- --watch --diagnostics", "prebuild": "npm run lint", "compile": "tsc --pretty", - "build": "rm -rf dist && tsc -p prod --pretty", + "build": "rm -rf dist && tsc --pretty", "lint": "tslint src/*.ts", - "release": "standard-version" + "release": "standard-version", + "test": "mocha --timeout 10000 dist/__test__" }, "author": "Stanislav Panferov (http://panferov.me/)", "repository": { @@ -33,34 +33,32 @@ "homepage": "https://github.com/s-panferov/awesome-typescript-loader", "dependencies": { "colors": "^1.1.2", - "enhanced-resolve": "^2.3.0", + "enhanced-resolve": "^3.0.3", "loader-utils": "^0.2.16", - "lodash": "^4.13.1", - "object-assign": "^4.1.0", - "source-map-support": "^0.4.0" + "lodash": "^4.17.4", + "object-assign": "^4.1.1", + "source-map-support": "^0.4.11" }, "devDependencies": { "@types/chai": "^3.4.34", - "@types/colors": "^0.6.33", - "@types/lodash": "^4.14.43", - "@types/mocha": "^2.2.32", - "@types/node": "^6.0.46", - "@types/sinon": "^1.16.31", - "babel-core": "^6.20.0", - "babel-preset-es2015": "^6.18.0", - "bluebird": "^3.4.1", + "@types/colors": "^1.1.1", + "@types/lodash": "^4.14.51", + "@types/mocha": "^2.2.38", + "@types/node": "^7.0.4", + "@types/sinon": "^1.16.34", + "bluebird": "^3.4.7", "chai": "^3.5.0", "empty-module": "0.0.2", + "fs-extra": "^2.0.0", "git-hooks": "^1.0.2", "mkdirp": "^0.5.1", "mocha": "^3.2.0", "ps-node": "^0.1.1", "rimraf": "^2.5.0", - "sinon": "^1.17.4", "standard-version": "^4.0.0", "temp": "^0.8.3", - "tslint": "^4.0.2", - "typescript": "^2.1.4", - "webpack": "2.1.0-beta.25" + "tslint": "^4.4.2", + "typescript": "^2.1.5", + "webpack": "2.2.0" } } diff --git a/src/__test__/babel.ts b/src/__test__/babel.ts new file mode 100644 index 0000000..2382904 --- /dev/null +++ b/src/__test__/babel.ts @@ -0,0 +1,58 @@ +import { + clear, src, webpackConfig, tsconfig, install, + watch, checkOutput, expectErrors, query, run +} from './utils'; + +run(__filename, async function() { + clear(); + const index = src('index.ts', ` + class HiThere { + constructor(a: number, b: string) { + const t = a + b; + } + } + `); + + install('babel-core', 'babel-preset-es2015'); + tsconfig(); + + const watcher = await watch(webpackConfig(query({ + useBabel: true, + babelOptions: { + "presets": ["es2015"] + } + }))); + + await watcher.wait(); + + expectErrors(0); + checkOutput('index.js', ` + var HiThere = function HiThere(a, b) { + _classCallCheck(this, HiThere); + var t = a + b; + } + `); + + index.update(() => ` + function sum(...items: number[]) { + return items.reduce((a,b) => a + b, 0); + } + `); + + await watcher.wait(); + + expectErrors(0); + checkOutput('index.js', ` + function sum() { + for(var _len = arguments.length, + items = Array(_len), + _key = 0; + _key < _len; + _key++ + ) { + items[_key] = arguments[_key]; + } + return items.reduce(function(a,b){ return a + b; }, 0); + } + `); +}); diff --git a/src/__test__/declaration.ts b/src/__test__/declaration.ts new file mode 100644 index 0000000..03431e1 --- /dev/null +++ b/src/__test__/declaration.ts @@ -0,0 +1,57 @@ +import { + clear, src, webpackConfig, tsconfig, + watch, checkOutput, expectErrors, run +} from './utils'; + +run(__filename, async function() { + clear(); + const index = src('index.ts', ` + export { default as sum } from './utils/sum' + `); + + src('utils/sum.ts', ` + export default function sum(a: number, b: number) { + return a + b; + } + `); + + tsconfig({ + declaration: true + }); + + const watcher = watch(webpackConfig()); + + await watcher.wait(); + + expectErrors(0); + + checkOutput('src/index.d.ts', ` + export { default as sum } from './utils/sum' + `); + + checkOutput('src/utils/sum.d.ts', ` + export default function sum(a: number, b: number): number + `); + + src('utils/mul.ts', ` + export default function mul(a: number, b: number) { + return a * b; + } + `); + + index.update(() => ` + export { default as sum } from './utils/sum' + export { default as mul } from './utils/mul' + `); + + await watcher.wait(); + + checkOutput('src/utils/mul.d.ts', ` + export default function mul(a: number, b: number): number + `); + + checkOutput('src/index.d.ts', ` + export { default as sum } from './utils/sum'; + export { default as mul } from './utils/mul'; + `); +}); diff --git a/src/__test__/error.ts b/src/__test__/error.ts new file mode 100644 index 0000000..935783f --- /dev/null +++ b/src/__test__/error.ts @@ -0,0 +1,31 @@ +import { + clear, src, webpackConfig, tsconfig, + compile, checkOutput, expectErrors, run +} from './utils'; + +run(__filename, async function() { + clear(); + src('index.ts', ` + function sum(a: number, b: number) { + return a + b; + } + + sum('test', 1); + `); + + tsconfig(); + + await compile(webpackConfig()); + + expectErrors(1, [ + `Argument of type '"test"' is not assignable to parameter of type 'number'` + ]); + + checkOutput('index.js', ` + function sum(a, b) { + return a + b; + } + + sum('test', 1); + `); +}); diff --git a/src/__test__/react.ts b/src/__test__/react.ts new file mode 100644 index 0000000..e16138d --- /dev/null +++ b/src/__test__/react.ts @@ -0,0 +1,39 @@ +import { + clear, src, webpackConfig, expectErrors, + tsconfig, compile, install, entry, run +} from './utils'; + +run(__filename, async function() { + clear(); + install( + 'react', + 'react-dom', + '@types/react', + '@types/react-dom' + ); + + src('index.tsx', ` + import * as React from 'react' + import * as ReactDOM from 'react-dom' + import App from './app' + ReactDOM.render(, document.body) + `); + + src('app.tsx', ` + import * as React from 'react' + + export default class App extends React.Component<{title: string}, void> { + render() { + return
{ this.props.title }
+ } + } + `); + + tsconfig({ + jsx: 'react' + }); + + await compile(webpackConfig(entry('index.tsx'))); + + expectErrors(0); +}); diff --git a/src/__test__/remove.ts b/src/__test__/remove.ts new file mode 100644 index 0000000..204d54a --- /dev/null +++ b/src/__test__/remove.ts @@ -0,0 +1,47 @@ +import { + clear, src, webpackConfig, tsconfig, + watch, expectErrors, xrun +} from './utils'; + +xrun(__filename, async function() { + clear(); + const index = src('index.ts', ` + import sum from './sum' + import mul from './mul' + + sum(1, 1) + mul(1, 1) + `); + + src('sum.ts', ` + export default function sum(a: number, b: number) { + return a + b; + } + `); + + const mul = src('mul.ts', ` + // function with error + export default function mul(a: number, b: number) { + return a * c; + } + `); + + tsconfig(); + const watcher = await watch(webpackConfig()); + + await watcher.wait(); + + expectErrors(1, [ + `Cannot find name 'c'` + ]); + + index.update(() => ` + import sum from './sum' + sum(1, 1) + `); + + mul.remove(); + + await watcher.wait(); + expectErrors(0); +}); diff --git a/src/__test__/simple.ts b/src/__test__/simple.ts new file mode 100644 index 0000000..eaaa705 --- /dev/null +++ b/src/__test__/simple.ts @@ -0,0 +1,27 @@ +import { + clear, src, webpackConfig, tsconfig, + compile, checkOutput, expectErrors, run +} from './utils'; + +run(__filename, async function() { + clear(); + src('index.ts', ` + class HiThere { + constructor(a: number, b: string) { + const t = a + b; + } + } + `); + + tsconfig(); + await compile(webpackConfig()); + + expectErrors(0); + checkOutput('index.js', ` + class HiThere { + constructor(a, b) { + const t = a + b; + } + } + `); +}); diff --git a/src/__test__/utils.ts b/src/__test__/utils.ts new file mode 100644 index 0000000..216ef6b --- /dev/null +++ b/src/__test__/utils.ts @@ -0,0 +1,278 @@ +import * as path from 'path'; +import * as fs from 'fs'; +import * as _ from 'lodash'; +import * as child from 'child_process'; + +import { LoaderConfig } from '../interfaces'; + +require('source-map-support').install(); + +import { expect } from 'chai'; +export { expect }; + +const webpack = require('webpack'); +const BPromise = require('bluebird'); + +const mkdirp = BPromise.promisify(require('mkdirp')); +const rimraf = BPromise.promisify(require('rimraf')); +const readFile = BPromise.promisify(fs.readFile); +const writeFile = BPromise.promisify(fs.writeFile); + +export const defaultOutputDir = path.join(process.cwd(), '.test'); +export const defaultFixturesDir = path.join(process.cwd(), 'fixtures'); + +export interface ConfigOptions { + loaderQuery?: LoaderConfig; + watch?: boolean; + include?: (string | RegExp)[]; + exclude?: (string | RegExp)[]; +} + +const TEST_DIR = path.join(process.cwd(), '.test'); +const SRC_DIR = path.join(TEST_DIR, 'src'); +const OUT_DIR = path.join(TEST_DIR, 'out'); + +mkdirp.sync(TEST_DIR); +mkdirp.sync(SRC_DIR); +mkdirp.sync(OUT_DIR); + +const LOADER = path.join(process.cwd(), 'index.js'); + +export function entry(file: string) { + return config => { + config.entry.index = path.join(SRC_DIR, file) + }; +} + +export function query(q: any) { + return config => { + config.module.loaders.find(loader => loader.loader === LOADER).query = q; + }; +} + +export function webpackConfig(...enchance: any[]) { + const config = _.merge({ + entry: { index: path.join(SRC_DIR, 'index.ts') }, + output: { + path: path.join(OUT_DIR), + filename: '[name].js' + }, + resolve: { + extensions: ['.ts', '.tsx', '.js', '.jsx'], + }, + module: { + loaders: [ + { + test: /\.(tsx?|jsx?)/, + loader: LOADER, + include: [ SRC_DIR ] + } + ] + } + }); + + enchance.forEach(e => e(config)); + return config; +} + +export function expectErrors(count: number, errors: string[] = []) { + LAST_STATS.compilation.errors.every(err => { + const str = err.toString(); + expect(errors.some(e => str.indexOf(e) !== -1), 'Error is not covered: \n' + str).true; + }); + + expect(LAST_STATS.compilation.errors.length).eq(count); +} + +export function error(text: string) { + expect(LAST_STATS.compilation.errors.some(err => err.toString().indexOf(text) !== 0)).true; +} + +export function tsconfig(compilerOptions?: any, config?: any) { + const res = _.merge({ + compilerOptions: _.merge({ + target: 'es6' + }, compilerOptions) + }, config); + return file('tsconfig.json', json(res)); +} + +export function install(...name: string[]) { + chroot(TEST_DIR, () => { + return child.execSync(`yarn add ${name.join(' ')}`); + }); +} + +export async function chroot(root: string, foo: () => R): Promise { + let cwd = process.cwd(); + process.chdir(root); + let result = foo(); + + if ((result as any).then) { + await result; + } + + process.chdir(cwd); + return result; +} + +export function json(obj) { + return JSON.stringify(obj, null, 4); +} + +export function checkOutput(fileName: string, fragment: string) { + const source = readOutput(fileName); + expect(source.replace(/\s/g, '')).include(fragment.replace(/\s/g, '')); +} + +export function readOutput(fileName: string) { + return fs.readFileSync(path.join(OUT_DIR, fileName || 'index.js')).toString(); +} + +export function touchFile(fileName: string): Promise { + return readFile(fileName) + .then(buf => buf.toString()) + .then(source => writeFile(fileName, source)); +} + +let LAST_STATS: any; + +export function compile(config?): Promise { + return chroot(TEST_DIR, () => { + return new Promise((resolve, reject) => { + const compiler = webpack(config); + + LAST_STATS = undefined; + compiler.run((err, stats) => { + if (err) { + reject(err); + } else { + LAST_STATS = stats; + resolve(stats); + } + }); + }); + }); +} + +export function run(name: string, cb: () => Promise, disable = false) { + const runner = () => { + let cwd = process.cwd(); + process.chdir(TEST_DIR); + const promise = cb(); + return promise + .then(a => { + process.chdir(cwd); + return a; + }) + .catch(e => { + process.chdir(cwd); + throw e; + }); + }; + + if (disable) { + xit(name, runner); + } else { + it(name, runner); + } +} + +export function xrun(name: string, cb: () => Promise) { + return run(name, cb, true); +} + +export function watch(config, cb?: (err, stats) => void): Watch { + let compiler = webpack(config); + let watch = new Watch(); + let webpackWatcher = compiler.watch({}, (err, stats) => { + LAST_STATS = stats; + watch.invoke(err, stats); + if (cb) { + cb(err, stats); + } + }); + + watch.close = webpackWatcher.close; + return watch; +} + +export class Watch { + close: () => void; + + private resolves: ((arg: any[]) => void)[] = []; + + invoke(err, stats) { + this.resolves.forEach(resolver => { + resolver([err, stats]); + }); + this.resolves = []; + } + + wait(): Promise { + return new Promise((resolve, reject) => { + this.resolves.push(resolve); + }); + } +} + +export function project() { + clear(); + return { + file, + ts, + webpack: webpackConfig + }; +} + +export function clear() { + rimraf.sync(TEST_DIR); + mkdirp.sync(TEST_DIR); + file('package.json', ` + { + "name": "test", + "license": "MIT" + } + `); +} + +export function src(fileName: string, text: string) { + return new Fixture(path.join(SRC_DIR, fileName), text); +} + +export function file(fileName: string, text: string) { + return new Fixture(path.join(TEST_DIR, fileName), text); +} + +export class Fixture { + private text: string; + private fileName: string; + constructor(fileName: string, text: string) { + this.text = text; + this.fileName = fileName; + mkdirp.sync(path.dirname(this.fileName)); + fs.writeFileSync(this.fileName, text); + } + + path() { + return this.fileName; + } + + toString() { + return this.path(); + } + + touch() { + touchFile(this.fileName); + } + + update(updater: (text: string) => string) { + let newText = updater(this.text); + this.text = newText; + fs.writeFileSync(this.fileName, newText); + } + + remove() { + fs.unlinkSync(this.fileName); + } +} diff --git a/src/__test__/watch.ts b/src/__test__/watch.ts new file mode 100644 index 0000000..c7d4906 --- /dev/null +++ b/src/__test__/watch.ts @@ -0,0 +1,47 @@ +import { + clear, src, webpackConfig, tsconfig, + watch, expectErrors, run +} from './utils'; + +run(__filename, async function() { + clear(); + + const sum = src('sum.ts', ` + export default function sum(a: number, b: number) { + return a + b; + } + `); + + const index = src('index.ts', ` + import sum from './sum' + sum(1, 1); + `); + + tsconfig(); + + const watcher = watch(webpackConfig()); + + await watcher.wait(); + expectErrors(0); + + sum.update(() => ` + export default function sum(a: number, b: string) { + return a + b; + } + `); + + await watcher.wait(); + + expectErrors(1, [ + `Argument of type '1' is not assignable to parameter of type 'string'` + ]); + + index.update(() => ` + import sum from './sum' + sum(1, '1'); + `); + + await watcher.wait(); + + expectErrors(0); +}); diff --git a/src/cache.ts b/src/cache.ts index 7615b40..eb63954 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -40,7 +40,7 @@ export function findCompiledModule(fileName: string): CompiledModule { function read(filename: string) { let content = fs.readFileSync(filename); let jsonString = zlib.gunzipSync(content); - return JSON.parse(jsonString); + return JSON.parse(jsonString.toString()); } /** diff --git a/src/checker/checker.ts b/src/checker/checker.ts index 9cebfca..5cc3f7a 100644 --- a/src/checker/checker.ts +++ b/src/checker/checker.ts @@ -44,7 +44,7 @@ export class Checker { const execArgv = getExecArgv(); const checker: childProcess.ChildProcess = fork ? childProcess.fork(path.join(__dirname, 'runtime.js'), [], { execArgv }) - : require('./runtime'); + : require('./runtime').run(); this.sender = fork ? createQueuedSender(checker) diff --git a/src/checker/protocol.ts b/src/checker/protocol.ts index 4b69a70..b7f67f2 100644 --- a/src/checker/protocol.ts +++ b/src/checker/protocol.ts @@ -100,6 +100,7 @@ export namespace EmitFile { emitResult: { text: string; sourceMap: string; + declaration: { name: string, text: string }; }; deps: string[]; } diff --git a/src/checker/runtime.ts b/src/checker/runtime.ts index cfc2f58..c941ae8 100644 --- a/src/checker/runtime.ts +++ b/src/checker/runtime.ts @@ -8,32 +8,38 @@ if (!module.parent) { process.exit(); }); + process.on('exit', () => { + console.log('EXIT RUNTIME'); + }); + createChecker( process.on.bind(process, 'message'), process.send.bind(process) ); } else { - let send: (msg: Req, cb: (err?: Error) => void) => void; - let receive = (msg) => {}; - - const checker = createChecker( - (receive: (msg: Req) => void) => { - send = (msg: Req, cb: (err?: Error) => void) => { - receive(msg); - if (cb) { cb(); } - }; - }, - (msg) => receive(msg) - ); + module.exports.run = function run() { + let send: (msg: Req, cb: (err?: Error) => void) => void; + let receive = (msg) => {}; + + createChecker( + (receive: (msg: Req) => void) => { + send = (msg: Req, cb: (err?: Error) => void) => { + receive(msg); + if (cb) { cb(); } + }; + }, + (msg) => receive(msg) + ); - module.exports = { - on: (type: string, cb) => { - if (type === 'message') { - receive = cb; - } - }, - send, - kill: () => {} + return { + on: (type: string, cb) => { + if (type === 'message') { + receive = cb; + } + }, + send, + kill: () => {} + }; }; } @@ -235,7 +241,11 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re instanceName = loaderConfig.instance || 'at-loader'; - host = new Host(compilerOptions.allowJs ? TS_AND_JS_FILES : TS_FILES); + host = new Host(compilerOptions.allowJs + ? TS_AND_JS_FILES + : TS_FILES + ); + service = compiler.createLanguageService(host); compilerConfig.fileNames.forEach(fileName => { @@ -269,12 +279,10 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re function updateFile(fileName: string, text: string) { const file = files[fileName]; if (file) { - if (file.text !== text) { - projectVersion++; - file.version++; - file.text = text; - file.snapshot = compiler.ScriptSnapshot.fromString(text); - } + projectVersion++; + file.version++; + file.text = text; + file.snapshot = compiler.ScriptSnapshot.fromString(text); } else { projectVersion++; files[fileName] = { @@ -300,6 +308,7 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re if (output.outputFiles.length > 0) { return findResultFor(fileName, output); } else { + // Use fast emit in case of errors return fastEmit(fileName); } } diff --git a/src/index.ts b/src/index.ts index 12089b7..95a130b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import { QueryOptions, Loader, ensureInstance, Instance } from './instance'; import { PathsPlugin } from './paths-plugin'; import { CheckerPlugin as _CheckerPlugin } from './watch-mode'; -let loaderUtils = require('loader-utils'); +const loaderUtils = require('loader-utils'); function loader(text) { try { @@ -35,11 +35,11 @@ function compiler(loader: Loader, text: string): void { loader.cacheable(); } - let options = loaderUtils.parseQuery(loader.query); - let instanceName = options.instance || 'at-loader'; - let instance = ensureInstance(loader, options, instanceName); - let callback = loader.async(); - let fileName = helpers.toUnix(loader.resourcePath); + const options = loaderUtils.parseQuery(loader.query); + const instanceName = options.instance || 'at-loader'; + const instance = ensureInstance(loader, options, instanceName); + const callback = loader.async(); + const fileName = helpers.toUnix(loader.resourcePath); instance.compiledFiles[fileName] = true; @@ -58,7 +58,7 @@ function compiler(loader: Loader, text: string): void { : null }).then(result => ({cached: true, result})); } else { - let transformationFunction = () => transform( + const transformationFunction = () => transform( loader, instance, fileName, @@ -147,6 +147,18 @@ function transform(webpack: Loader, instance: Instance, fileName: string, text: resultSourceMap.sourcesContent = [ text ]; } + if (emitResult.declaration) { + const declPath = path.relative( + process.cwd(), + emitResult.declaration.name + ); + + webpack.emitFile( + declPath, + emitResult.declaration.text + ); + } + return { text: resultText, map: resultSourceMap, diff --git a/src/instance.ts b/src/instance.ts index 06f0a1a..9df3101 100644 --- a/src/instance.ts +++ b/src/instance.ts @@ -54,24 +54,11 @@ function getRootCompiler(compiler) { } } -function getInstanceStore(compiler): { [key: string]: Instance } { - let store = getRootCompiler(compiler)._tsInstances; - if (store) { - return store; - } else { - throw new Error('Can not resolve instance store'); - } -} - -function ensureInstanceStore(compiler) { - let rootCompiler = getRootCompiler(compiler); - if (!rootCompiler._tsInstances) { - rootCompiler._tsInstances = {}; - } -} - function resolveInstance(compiler, instanceName) { - return getInstanceStore(compiler)[instanceName]; + if (!compiler._tsInstances) { + compiler._tsInstances = {}; + } + return compiler._tsInstances[instanceName]; } const COMPILER_ERROR = colors.red(`\n\nTypescript compiler cannot be found, please add it to your package.json file: @@ -82,13 +69,8 @@ const BABEL_ERROR = colors.red(`\n\nBabel compiler cannot be found, please add i npm install --save-dev babel-core `); -/** - * Creates compiler instance - */ let id = 0; export function ensureInstance(webpack: Loader, query: QueryOptions, instanceName: string): Instance { - ensureInstanceStore(webpack._compiler); - const rootCompiler = getRootCompiler(webpack._compiler); const watching = isWatching(rootCompiler); @@ -126,7 +108,7 @@ export function ensureInstance(webpack: Loader, query: QueryOptions, instanceNam watching === WatchMode.Enabled ); - return getInstanceStore(webpack._compiler)[instanceName] = { + return rootCompiler._tsInstances[instanceName] = { id: ++id, babelImpl, compiledFiles: {}, @@ -300,7 +282,9 @@ function setupWatchRun(compiler, instanceName: string) { compiler.plugin('watch-run', function (watching, callback) { const instance = resolveInstance(watching.compiler, instanceName); const checker = instance.checker; - const watcher = watching.compiler.watchFileSystem.watcher || watching.compiler.watchFileSystem.wfs.watcher; + const watcher = watching.compiler.watchFileSystem.watcher + || watching.compiler.watchFileSystem.wfs.watcher; + const mtimes = watcher.mtimes; const changedFiles = Object.keys(mtimes).map(toUnix); const updates = changedFiles diff --git a/src/interfaces.ts b/src/interfaces.ts index 97bc473..27dcae7 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -20,6 +20,7 @@ export interface LoaderConfig { silent?: boolean; useCache?: boolean; cacheDirectory?: string; + entryFileIsJs?: boolean; } export interface OutputFile { diff --git a/src/test/babel.ts b/src/test/babel.ts deleted file mode 100644 index 630ac31..0000000 --- a/src/test/babel.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { - cleanAndCompile, expect, readOutputFile, - fixturePath, readFixture, expectSource, createConfig -} from './utils'; - -describe('main test', function() { - - it('should transpile file with babel', async function() { - // babel need some time to init - this.timeout(10000); - - let config = { - entry: fixturePath(['babel', 'babel.ts']) - }; - - let loaderQuery = { - useBabel: true, - babelOptions: { - "presets": ["es2015"] - } - }; - - let stats = await cleanAndCompile(createConfig(config, { loaderQuery })); - expect(stats.compilation.errors.length).eq(0); - - let result = await readOutputFile(); - let expectation = await readFixture(['babel', 'babel.js']); - - expectSource(result, expectation); - }); - - it('should use options from query', async function() { - // babel need some time to init - this.timeout(10000); - - let config = { - entry: fixturePath(['babel', 'babel.ts']) - }; - - let loaderQuery = { - useBabel: true, - babelOptions: { - "presets": ["unknown-preset"] - } - }; - - let throws = false; - try { - let stats = await cleanAndCompile(createConfig(config, { loaderQuery })); - expect(stats.compilation.errors.length).eq(0); - } catch (e) { - throws = true; - } - - expect(throws).to.true; - }); -}); diff --git a/src/test/declaration.ts b/src/test/declaration.ts deleted file mode 100644 index b3ac61e..0000000 --- a/src/test/declaration.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { - cleanAndCompile, expect, readOutputFile, - fixturePath, readFixture, expectSource, createConfig -} from './utils'; - -describe('main test', function() { - - xit('should emit declaration files', async function() { - // babel need some time to init - this.timeout(10000); - - let config = { - entry: fixturePath(['declaration', 'basic.ts']) - }; - - let loaderQuery = { - declaration: true - }; - - let stats = await cleanAndCompile(createConfig(config, { loaderQuery })); - expect(stats.compilation.errors.length).eq(0); - let assets = Object.keys(stats.compilation.assets); - - expect(assets).to.include('src/test/fixtures/declaration/basic.d.ts'); - - // elided import - expect(assets).to.include('src/test/fixtures/declaration/iface.d.ts'); - }); -}); diff --git a/src/test/fixtures/babel/babel.js b/src/test/fixtures/babel/babel.js deleted file mode 100644 index c34f798..0000000 --- a/src/test/fixtures/babel/babel.js +++ /dev/null @@ -1,4 +0,0 @@ -var HiThere = function HiThere(a, b) { - _classCallCheck(this, HiThere); - var t = a + b; -} \ No newline at end of file diff --git a/src/test/fixtures/babel/babel.ts b/src/test/fixtures/babel/babel.ts deleted file mode 100644 index 254c1fe..0000000 --- a/src/test/fixtures/babel/babel.ts +++ /dev/null @@ -1,5 +0,0 @@ -class HiThere { - constructor(a: number, b: string) { - let t = a + b; - } -} diff --git a/src/test/fixtures/basic/basic.js b/src/test/fixtures/basic/basic.js deleted file mode 100644 index 35265c6..0000000 --- a/src/test/fixtures/basic/basic.js +++ /dev/null @@ -1,5 +0,0 @@ -class HiThere { - constructor(a, b) { - let t = a + b; - } -} diff --git a/src/test/fixtures/basic/basic.ts b/src/test/fixtures/basic/basic.ts deleted file mode 100644 index 254c1fe..0000000 --- a/src/test/fixtures/basic/basic.ts +++ /dev/null @@ -1,5 +0,0 @@ -class HiThere { - constructor(a: number, b: string) { - let t = a + b; - } -} diff --git a/src/test/fixtures/checker/to-check.ts b/src/test/fixtures/checker/to-check.ts deleted file mode 100644 index 76b8d70..0000000 --- a/src/test/fixtures/checker/to-check.ts +++ /dev/null @@ -1 +0,0 @@ -1453065049802 \ No newline at end of file diff --git a/src/test/fixtures/declaration/basic.ts b/src/test/fixtures/declaration/basic.ts deleted file mode 100644 index 3d82143..0000000 --- a/src/test/fixtures/declaration/basic.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Iface } from './iface'; - -export function foo(iface: Iface): Iface { return iface; } diff --git a/src/test/fixtures/declaration/iface.ts b/src/test/fixtures/declaration/iface.ts deleted file mode 100644 index 7ec69b3..0000000 --- a/src/test/fixtures/declaration/iface.ts +++ /dev/null @@ -1,4 +0,0 @@ - -export interface Iface { - name: string; -} diff --git a/src/test/fixtures/errors/with-type-errors.ts b/src/test/fixtures/errors/with-type-errors.ts deleted file mode 100644 index e2aaaff..0000000 --- a/src/test/fixtures/errors/with-type-errors.ts +++ /dev/null @@ -1,7 +0,0 @@ -class IamAClass { - constructor(a: number) { - this.doSomething(a); - } - - doSomething(c: boolean) {} -} diff --git a/src/test/fixtures/react/index.tsx b/src/test/fixtures/react/index.tsx deleted file mode 100644 index 96d26fe..0000000 --- a/src/test/fixtures/react/index.tsx +++ /dev/null @@ -1,4 +0,0 @@ -import * as React from 'react' -import { renderToString } from 'react-dom/server' - -renderToString(
) \ No newline at end of file diff --git a/src/test/fixtures/react/tsconfig.json b/src/test/fixtures/react/tsconfig.json deleted file mode 100644 index 5ca957d..0000000 --- a/src/test/fixtures/react/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "moduleResolution": "node", - "noImplicitAny": false, - "sourceMap": false, - "jsx": "react", - "types": [ - "react", - "react-dom" - ] - } -} \ No newline at end of file diff --git a/src/test/fixtures/salsa/index.js b/src/test/fixtures/salsa/index.js deleted file mode 100644 index 7220390..0000000 --- a/src/test/fixtures/salsa/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import { sum } from './lib'; - -sum('asdf', /asdf/); diff --git a/src/test/fixtures/salsa/index.ts b/src/test/fixtures/salsa/index.ts deleted file mode 100644 index 7220390..0000000 --- a/src/test/fixtures/salsa/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { sum } from './lib'; - -sum('asdf', /asdf/); diff --git a/src/test/fixtures/salsa/lib.js b/src/test/fixtures/salsa/lib.js deleted file mode 100644 index ccae695..0000000 --- a/src/test/fixtures/salsa/lib.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @param {number} a - a - * @param {number} b - b - * @return {number} - */ -export function sum(a, b) { - return a + b; -} diff --git a/src/test/fixtures/salsa/tsconfig.json b/src/test/fixtures/salsa/tsconfig.json deleted file mode 100644 index 067add9..0000000 --- a/src/test/fixtures/salsa/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "moduleResolution": "node", - "declaration": false, - "allowJs": true, - "types": [] - } -} diff --git a/src/test/fixtures/tsx/basic.tsx b/src/test/fixtures/tsx/basic.tsx deleted file mode 100644 index 7cf3649..0000000 --- a/src/test/fixtures/tsx/basic.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import * as React from 'react'; - -class Component { - render() { - return
hi there
; - } -} diff --git a/src/test/fixtures/tsx/package.json b/src/test/fixtures/tsx/package.json deleted file mode 100644 index aca48f3..0000000 --- a/src/test/fixtures/tsx/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "tsx", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC" -} diff --git a/src/test/fixtures/tsx/tsconfig.json b/src/test/fixtures/tsx/tsconfig.json deleted file mode 100644 index 0369b98..0000000 --- a/src/test/fixtures/tsx/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "jsx": "react", - "moduleResolution": "node", - "types": ["react"] - }, - "include": [ - "./basic.tsx" - ] -} diff --git a/src/test/fixtures/typeRoots/index.ts b/src/test/fixtures/typeRoots/index.ts deleted file mode 100644 index 9e44d2e..0000000 --- a/src/test/fixtures/typeRoots/index.ts +++ /dev/null @@ -1,4 +0,0 @@ - -describe('test', () => { - -}); \ No newline at end of file diff --git a/src/test/fixtures/typeRoots/tsconfig.json b/src/test/fixtures/typeRoots/tsconfig.json deleted file mode 100644 index 6ed67a0..0000000 --- a/src/test/fixtures/typeRoots/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "moduleResolution": "node", - "types": [ - "jasmine" - ] - } -} \ No newline at end of file diff --git a/src/test/index.ts b/src/test/index.ts deleted file mode 100644 index 77c617b..0000000 --- a/src/test/index.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { - cleanAndCompile, expect, readOutputFile, - fixturePath, readFixture, expectSource, createConfig -} from './utils'; - -describe('main test', function() { - - it('should compile simple file', async function() { - let config = { - entry: fixturePath(['basic', 'basic.ts']) - }; - - let stats = await cleanAndCompile(createConfig(config)); - console.log(stats.compilation.errors) - expect(stats.compilation.errors.length).eq(0); - - let result = await readOutputFile(); - let expectation = await readFixture(['basic', 'basic.js']); - - expectSource(result, expectation); - }); - - it('should check typing', async function() { - let config = { - entry: fixturePath(['errors', 'with-type-errors.ts']) - }; - - let stats = await cleanAndCompile(createConfig(config)); - expect(stats.compilation.errors.length).eq(1); - }); - - it('should ignore diagnostics', async function() { - let config = { - entry: fixturePath(['errors', 'with-type-errors.ts']) - }; - - let loaderQuery = { ignoreDiagnostics: [2345] }; - - let stats = await cleanAndCompile(createConfig(config, { loaderQuery })); - expect(stats.compilation.errors.length).eq(0); - }); - - it('should load tsx files and use tsconfig', async function() { - let configFileName = fixturePath(['tsx', 'tsconfig.json']); - let config = { - entry: fixturePath(['tsx', 'basic.tsx']), - resolve: { - alias: { - react: 'empty-module' - } - } - }; - - let loaderQuery = { configFileName, configFileContent: null }; - - let stats = await cleanAndCompile(createConfig(config, { loaderQuery })); - console.log(stats.compilation.errors); - - expect(stats.compilation.errors.length).eq(0); - - let result = await readOutputFile(); - let expectation = '("div", null, "hi there");'; - - expectSource(result, expectation); - }); -}); diff --git a/src/test/node_modules/@types/jasmine/README.md b/src/test/node_modules/@types/jasmine/README.md deleted file mode 100644 index ea5e6e5..0000000 --- a/src/test/node_modules/@types/jasmine/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Installation -> `npm install --save @types/jasmine` - -# Summary -This package contains type definitions for Jasmine 2.5 (http://jasmine.github.io/). - -# Details -Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/jasmine - -Additional Details - * Last updated: Tue, 01 Nov 2016 12:57:25 GMT - * File structure: Global - * Library Dependencies: none - * Module Dependencies: none - * Global values: afterAll, afterEach, beforeAll, beforeEach, describe, expect, fail, fdescribe, fit, it, jasmine, pending, runs, spyOn, waits, waitsFor, xdescribe, xit - -# Credits -These definitions were written by Boris Yankov , Theodore Brown , David Pärsson . diff --git a/src/test/node_modules/@types/jasmine/index.d.ts b/src/test/node_modules/@types/jasmine/index.d.ts deleted file mode 100644 index 56b5073..0000000 --- a/src/test/node_modules/@types/jasmine/index.d.ts +++ /dev/null @@ -1,537 +0,0 @@ -// Type definitions for Jasmine 2.5 -// Project: http://jasmine.github.io/ -// Definitions by: Boris Yankov , Theodore Brown , David Pärsson -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - -// For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts - -declare function describe(description: string, specDefinitions: () => void): void; -declare function fdescribe(description: string, specDefinitions: () => void): void; -declare function xdescribe(description: string, specDefinitions: () => void): void; - -declare function it(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; -declare function fit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; -declare function xit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; - -/** If you call the function pending anywhere in the spec body, no matter the expectations, the spec will be marked pending. */ -declare function pending(reason?: string): void; - -declare function beforeEach(action: (done: DoneFn) => void, timeout?: number): void; -declare function afterEach(action: (done: DoneFn) => void, timeout?: number): void; - -declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): void; -declare function afterAll(action: (done: DoneFn) => void, timeout?: number): void; - -declare function expect(spy: Function): jasmine.Matchers; -declare function expect(actual: any): jasmine.Matchers; - -declare function fail(e?: any): void; -/** Action method that should be called when the async work is complete */ -interface DoneFn extends Function { - (): void; - - /** fails the spec and indicates that it has completed. If the message is an Error, Error.message is used */ - fail: (message?: Error|string) => void; -} - -declare function spyOn(object: any, method: string): jasmine.Spy; - -declare function runs(asyncMethod: Function): void; -declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, timeout?: number): void; -declare function waits(timeout?: number): void; - -declare namespace jasmine { - - var clock: () => Clock; - - function any(aclass: any): Any; - function anything(): Any; - function arrayContaining(sample: any[]): ArrayContaining; - function objectContaining(sample: any): ObjectContaining; - function createSpy(name: string, originalFn?: Function): Spy; - function createSpyObj(baseName: string, methodNames: any[]): any; - function createSpyObj(baseName: string, methodNames: any[]): T; - function pp(value: any): string; - function getEnv(): Env; - function addCustomEqualityTester(equalityTester: CustomEqualityTester): void; - function addMatchers(matchers: CustomMatcherFactories): void; - function stringMatching(str: string): Any; - function stringMatching(str: RegExp): Any; - function formatErrorMsg(domain: string, usage: string) : (msg: string) => string - - interface Any { - - new (expectedClass: any): any; - - jasmineMatches(other: any): boolean; - jasmineToString(): string; - } - - // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains() - interface ArrayLike { - length: number; - [n: number]: T; - } - - interface ArrayContaining { - new (sample: any[]): any; - - asymmetricMatch(other: any): boolean; - jasmineToString(): string; - } - - interface ObjectContaining { - new (sample: any): any; - - jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean; - jasmineToString(): string; - } - - interface Block { - - new (env: Env, func: SpecFunction, spec: Spec): any; - - execute(onComplete: () => void): void; - } - - interface WaitsBlock extends Block { - new (env: Env, timeout: number, spec: Spec): any; - } - - interface WaitsForBlock extends Block { - new (env: Env, timeout: number, latchFunction: SpecFunction, message: string, spec: Spec): any; - } - - interface Clock { - install(): void; - uninstall(): void; - /** Calls to any registered callback are triggered when the clock is ticked forward via the jasmine.clock().tick function, which takes a number of milliseconds. */ - tick(ms: number): void; - mockDate(date?: Date): void; - withMock(func: () => void): void; - } - - interface CustomEqualityTester { - (first: any, second: any): boolean; - } - - interface CustomMatcher { - compare(actual: T, expected: T): CustomMatcherResult; - compare(actual: any, expected: any): CustomMatcherResult; - } - - interface CustomMatcherFactory { - (util: MatchersUtil, customEqualityTesters: Array): CustomMatcher; - } - - interface CustomMatcherFactories { - [index: string]: CustomMatcherFactory; - } - - interface CustomMatcherResult { - pass: boolean; - message?: string; - } - - interface MatchersUtil { - equals(a: any, b: any, customTesters?: Array): boolean; - contains(haystack: ArrayLike | string, needle: any, customTesters?: Array): boolean; - buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: Array): string; - } - - interface Env { - setTimeout: any; - clearTimeout: void; - setInterval: any; - clearInterval: void; - updateInterval: number; - - currentSpec: Spec; - - matchersClass: Matchers; - - version(): any; - versionString(): string; - nextSpecId(): number; - addReporter(reporter: Reporter): void; - execute(): void; - describe(description: string, specDefinitions: () => void): Suite; - // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these - beforeEach(beforeEachFunction: () => void): void; - beforeAll(beforeAllFunction: () => void): void; - currentRunner(): Runner; - afterEach(afterEachFunction: () => void): void; - afterAll(afterAllFunction: () => void): void; - xdescribe(desc: string, specDefinitions: () => void): XSuite; - it(description: string, func: () => void): Spec; - // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these - xit(desc: string, func: () => void): XSpec; - compareRegExps_(a: RegExp, b: RegExp, mismatchKeys: string[], mismatchValues: string[]): boolean; - compareObjects_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean; - equals_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean; - contains_(haystack: any, needle: any): boolean; - addCustomEqualityTester(equalityTester: CustomEqualityTester): void; - addMatchers(matchers: CustomMatcherFactories): void; - specFilter(spec: Spec): boolean; - throwOnExpectationFailure(value: boolean): void; - seed(seed: string | number): string | number; - provideFallbackReporter(reporter: Reporter): void; - throwingExpectationFailures(): boolean; - allowRespy(allow: boolean): void; - randomTests(): boolean; - randomizeTests(b: boolean): void; - } - - interface FakeTimer { - - new (): any; - - reset(): void; - tick(millis: number): void; - runFunctionsWithinRange(oldMillis: number, nowMillis: number): void; - scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void; - } - - interface HtmlReporter { - new (): any; - } - - interface HtmlSpecFilter { - new (): any; - } - - interface Result { - type: string; - } - - interface NestedResults extends Result { - description: string; - - totalCount: number; - passedCount: number; - failedCount: number; - - skipped: boolean; - - rollupCounts(result: NestedResults): void; - log(values: any): void; - getItems(): Result[]; - addResult(result: Result): void; - passed(): boolean; - } - - interface MessageResult extends Result { - values: any; - trace: Trace; - } - - interface ExpectationResult extends Result { - matcherName: string; - passed(): boolean; - expected: any; - actual: any; - message: string; - trace: Trace; - } - - interface Order { - new (options: {random: boolean, seed: string}): any; - random: boolean; - seed: string; - sort(items: T[]) : T[]; - } - - namespace errors { - class ExpectationFailed extends Error { - constructor(); - stack: any; - } - } - - interface TreeProcessor { - new (attrs: any): any; - execute: (done: Function) => void; - processTree() : any; - } - - interface Trace { - name: string; - message: string; - stack: any; - } - - interface PrettyPrinter { - - new (): any; - - format(value: any): void; - iterateObject(obj: any, fn: (property: string, isGetter: boolean) => void): void; - emitScalar(value: any): void; - emitString(value: string): void; - emitArray(array: any[]): void; - emitObject(obj: any): void; - append(value: any): void; - } - - interface StringPrettyPrinter extends PrettyPrinter { - } - - interface Queue { - - new (env: any): any; - - env: Env; - ensured: boolean[]; - blocks: Block[]; - running: boolean; - index: number; - offset: number; - abort: boolean; - - addBefore(block: Block, ensure?: boolean): void; - add(block: any, ensure?: boolean): void; - insertNext(block: any, ensure?: boolean): void; - start(onComplete?: () => void): void; - isRunning(): boolean; - next_(): void; - results(): NestedResults; - } - - interface Matchers { - - new (env: Env, actual: any, spec: Env, isNot?: boolean): any; - - env: Env; - actual: any; - spec: Env; - isNot?: boolean; - message(): any; - - toBe(expected: any, expectationFailOutput?: any): boolean; - toEqual(expected: any, expectationFailOutput?: any): boolean; - toMatch(expected: string | RegExp, expectationFailOutput?: any): boolean; - toBeDefined(expectationFailOutput?: any): boolean; - toBeUndefined(expectationFailOutput?: any): boolean; - toBeNull(expectationFailOutput?: any): boolean; - toBeNaN(): boolean; - toBeTruthy(expectationFailOutput?: any): boolean; - toBeFalsy(expectationFailOutput?: any): boolean; - toHaveBeenCalled(): boolean; - toHaveBeenCalledWith(...params: any[]): boolean; - toHaveBeenCalledTimes(expected: number): boolean; - toContain(expected: any, expectationFailOutput?: any): boolean; - toBeLessThan(expected: number, expectationFailOutput?: any): boolean; - toBeLessThanOrEqual(expected: number, expectationFailOutput?: any): boolean; - toBeGreaterThan(expected: number, expectationFailOutput?: any): boolean; - toBeGreaterThanOrEqual(expected: number, expectationFailOutput?: any): boolean; - toBeCloseTo(expected: number, precision?: any, expectationFailOutput?: any): boolean; - toThrow(expected?: any): boolean; - toThrowError(message?: string | RegExp): boolean; - toThrowError(expected?: new (...args: any[]) => Error, message?: string | RegExp): boolean; - not: Matchers; - - Any: Any; - } - - interface Reporter { - reportRunnerStarting(runner: Runner): void; - reportRunnerResults(runner: Runner): void; - reportSuiteResults(suite: Suite): void; - reportSpecStarting(spec: Spec): void; - reportSpecResults(spec: Spec): void; - log(str: string): void; - } - - interface MultiReporter extends Reporter { - addReporter(reporter: Reporter): void; - } - - interface Runner { - - new (env: Env): any; - - execute(): void; - beforeEach(beforeEachFunction: SpecFunction): void; - afterEach(afterEachFunction: SpecFunction): void; - beforeAll(beforeAllFunction: SpecFunction): void; - afterAll(afterAllFunction: SpecFunction): void; - finishCallback(): void; - addSuite(suite: Suite): void; - add(block: Block): void; - specs(): Spec[]; - suites(): Suite[]; - topLevelSuites(): Suite[]; - results(): NestedResults; - } - - interface SpecFunction { - (spec?: Spec): void; - } - - interface SuiteOrSpec { - id: number; - env: Env; - description: string; - queue: Queue; - } - - interface Spec extends SuiteOrSpec { - - new (env: Env, suite: Suite, description: string): any; - - suite: Suite; - - afterCallbacks: SpecFunction[]; - spies_: Spy[]; - - results_: NestedResults; - matchersClass: Matchers; - - getFullName(): string; - results(): NestedResults; - log(arguments: any): any; - runs(func: SpecFunction): Spec; - addToQueue(block: Block): void; - addMatcherResult(result: Result): void; - getResult(): any; - expect(actual: any): any; - waits(timeout: number): Spec; - waitsFor(latchFunction: SpecFunction, timeoutMessage?: string, timeout?: number): Spec; - fail(e?: any): void; - getMatchersClass_(): Matchers; - addMatchers(matchersPrototype: CustomMatcherFactories): void; - finishCallback(): void; - finish(onComplete?: () => void): void; - after(doAfter: SpecFunction): void; - execute(onComplete?: () => void, enabled?: boolean): any; - addBeforesAndAftersToQueue(): void; - explodes(): void; - spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy; - removeAllSpies(): void; - throwOnExpectationFailure: boolean; - } - - interface XSpec { - id: number; - runs(): void; - } - - interface Suite extends SuiteOrSpec { - - new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any; - - parentSuite: Suite; - - getFullName(): string; - finish(onComplete?: () => void): void; - beforeEach(beforeEachFunction: SpecFunction): void; - afterEach(afterEachFunction: SpecFunction): void; - beforeAll(beforeAllFunction: SpecFunction): void; - afterAll(afterAllFunction: SpecFunction): void; - results(): NestedResults; - add(suiteOrSpec: SuiteOrSpec): void; - specs(): Spec[]; - suites(): Suite[]; - children(): any[]; - execute(onComplete?: () => void): void; - } - - interface XSuite { - execute(): void; - } - - interface Spy { - (...params: any[]): any; - - identity: string; - and: SpyAnd; - calls: Calls; - mostRecentCall: { args: any[]; }; - argsForCall: any[]; - wasCalled: boolean; - } - - interface SpyAnd { - /** By chaining the spy with and.callThrough, the spy will still track all calls to it but in addition it will delegate to the actual implementation. */ - callThrough(): Spy; - /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */ - returnValue(val: any): Spy; - /** By chaining the spy with and.returnValues, all calls to the function will return specific values in order until it reaches the end of the return values list. */ - returnValues(...values: any[]): Spy; - /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */ - callFake(fn: Function): Spy; - /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */ - throwError(msg: string): Spy; - /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */ - stub(): Spy; - } - - interface Calls { - /** By chaining the spy with calls.any(), will return false if the spy has not been called at all, and then true once at least one call happens. **/ - any(): boolean; - /** By chaining the spy with calls.count(), will return the number of times the spy was called **/ - count(): number; - /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index **/ - argsFor(index: number): any[]; - /** By chaining the spy with calls.allArgs(), will return the arguments to all calls **/ - allArgs(): any[]; - /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls **/ - all(): CallInfo[]; - /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call **/ - mostRecent(): CallInfo; - /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call **/ - first(): CallInfo; - /** By chaining the spy with calls.reset(), will clears all tracking for a spy **/ - reset(): void; - } - - interface CallInfo { - /** The context (the this) for the call */ - object: any; - /** All arguments passed to the call */ - args: any[]; - /** The return value of the call */ - returnValue: any; - } - - interface Util { - inherit(childClass: Function, parentClass: Function): any; - formatException(e: any): any; - htmlEscape(str: string): string; - argsToArray(args: any): any; - extend(destination: any, source: any): any; - } - - interface JsApiReporter extends Reporter { - - started: boolean; - finished: boolean; - result: any; - messages: any; - runDetails: { - failedExpectations: ExpectationResult[]; - order: jasmine.Order - } - - new (): any; - - suites(): Suite[]; - summarize_(suiteOrSpec: SuiteOrSpec): any; - results(): any; - resultsForSpec(specId: any): any; - log(str: any): any; - resultsForSpecs(specIds: any): any; - summarizeResult_(result: any): any; - } - - interface Jasmine { - Spec: Spec; - clock: Clock; - util: Util; - } - - export var HtmlReporter: HtmlReporter; - export var HtmlSpecFilter: HtmlSpecFilter; - export var DEFAULT_TIMEOUT_INTERVAL: number; -} diff --git a/src/test/node_modules/@types/jasmine/package.json b/src/test/node_modules/@types/jasmine/package.json deleted file mode 100644 index 1ccf4cc..0000000 --- a/src/test/node_modules/@types/jasmine/package.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "_args": [ - [ - { - "raw": "@types/jasmine", - "scope": "@types", - "escapedName": "@types%2fjasmine", - "name": "@types/jasmine", - "rawSpec": "", - "spec": "latest", - "type": "tag" - }, - "/Users/panferov/Workspace/my/awesome-typescript-loader/src/test" - ] - ], - "_from": "@types/jasmine@latest", - "_id": "@types/jasmine@2.5.37", - "_inCache": true, - "_location": "/@types/jasmine", - "_npmOperationalInternal": { - "host": "packages-12-west.internal.npmjs.com", - "tmp": "tmp/jasmine-2.5.37.tgz_1478005079042_0.7982070264406502" - }, - "_npmUser": { - "name": "types", - "email": "ts-npm-types@microsoft.com" - }, - "_phantomChildren": {}, - "_requested": { - "raw": "@types/jasmine", - "scope": "@types", - "escapedName": "@types%2fjasmine", - "name": "@types/jasmine", - "rawSpec": "", - "spec": "latest", - "type": "tag" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.37.tgz", - "_shasum": "15f16040b1106941ec4aeefa3cd9c55342a0dcbb", - "_shrinkwrap": null, - "_spec": "@types/jasmine", - "_where": "/Users/panferov/Workspace/my/awesome-typescript-loader/src/test", - "author": { - "name": "Boris Yankov", - "email": "https://github.com/borisyankov/" - }, - "dependencies": {}, - "description": "TypeScript definitions for Jasmine 2.5", - "devDependencies": {}, - "directories": {}, - "dist": { - "shasum": "15f16040b1106941ec4aeefa3cd9c55342a0dcbb", - "tarball": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.37.tgz" - }, - "license": "MIT", - "main": "", - "maintainers": [ - { - "name": "types", - "email": "ryan.cavanaugh@microsoft.com" - } - ], - "name": "@types/jasmine", - "optionalDependencies": {}, - "peerDependencies": {}, - "readme": "ERROR: No README data found!", - "repository": { - "type": "git", - "url": "https://www.github.com/DefinitelyTyped/DefinitelyTyped.git" - }, - "scripts": {}, - "typesPublisherContentHash": "342ad787ae1d9085f9cb2f352460449c601a7fbda833a19bb87aa2787dbc9ec3", - "typings": "index.d.ts", - "version": "2.5.37" -} diff --git a/src/test/node_modules/@types/jasmine/types-metadata.json b/src/test/node_modules/@types/jasmine/types-metadata.json deleted file mode 100644 index 8c99580..0000000 --- a/src/test/node_modules/@types/jasmine/types-metadata.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "authors": "Boris Yankov , Theodore Brown , David Pärsson ", - "definitionFilename": "index.d.ts", - "libraryDependencies": [], - "moduleDependencies": [], - "libraryMajorVersion": "2", - "libraryMinorVersion": "5", - "libraryName": "Jasmine 2.5", - "typingsPackageName": "jasmine", - "projectName": "http://jasmine.github.io/", - "sourceRepoURL": "https://www.github.com/DefinitelyTyped/DefinitelyTyped", - "sourceBranch": "types-2.0", - "kind": "Global", - "globals": [ - "afterAll", - "afterEach", - "beforeAll", - "beforeEach", - "describe", - "expect", - "fail", - "fdescribe", - "fit", - "it", - "jasmine", - "pending", - "runs", - "spyOn", - "waits", - "waitsFor", - "xdescribe", - "xit" - ], - "declaredModules": [], - "files": [ - "index.d.ts" - ], - "hasPackageJson": false, - "contentHash": "342ad787ae1d9085f9cb2f352460449c601a7fbda833a19bb87aa2787dbc9ec3" -} \ No newline at end of file diff --git a/src/test/node_modules/@types/react-dom/README.md b/src/test/node_modules/@types/react-dom/README.md deleted file mode 100644 index 891f37a..0000000 --- a/src/test/node_modules/@types/react-dom/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Installation -> `npm install --save @types/react-dom` - -# Summary -This package contains type definitions for React v0.14 (react-dom) (http://facebook.github.io/react/). - -# Details -Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/react-dom - -Additional Details - * Last updated: Thu, 25 Aug 2016 16:56:09 GMT - * File structure: UMD - * Library Dependencies: none - * Module Dependencies: react - * Global values: ReactDOM - -# Credits -These definitions were written by Asana , AssureSign , Microsoft . diff --git a/src/test/node_modules/@types/react-dom/index.d.ts b/src/test/node_modules/@types/react-dom/index.d.ts deleted file mode 100644 index a6c6c07..0000000 --- a/src/test/node_modules/@types/react-dom/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -// Type definitions for React v0.14 (react-dom) -// Project: http://facebook.github.io/react/ -// Definitions by: Asana , AssureSign , Microsoft -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -export as namespace ReactDOM; -export = ReactDOM; - -import { ReactInstance, Component, ComponentState, - ReactElement, SFCElement, CElement, - DOMAttributes, DOMElement } from 'react'; - -declare namespace ReactDOM { - function findDOMNode(instance: ReactInstance): E; - function findDOMNode(instance: ReactInstance): Element; - - function render

, T extends Element>( - element: DOMElement, - container: Element | null, - callback?: (element: T) => any): T; - function render

( - element: SFCElement

, - container: Element | null, - callback?: () => any): void; - function render>( - element: CElement, - container: Element | null, - callback?: (component: T) => any): T; - function render

( - element: ReactElement

, - container: Element | null, - callback?: (component?: Component | Element) => any): Component | Element | void; - - function unmountComponentAtNode(container: Element): boolean; - - var version: string; - - function unstable_batchedUpdates(callback: (a: A, b: B) => any, a: A, b: B): void; - function unstable_batchedUpdates(callback: (a: A) => any, a: A): void; - function unstable_batchedUpdates(callback: () => any): void; - - function unstable_renderSubtreeIntoContainer

, T extends Element>( - parentComponent: Component, - element: DOMElement, - container: Element, - callback?: (element: T) => any): T; - function unstable_renderSubtreeIntoContainer>( - parentComponent: Component, - element: CElement, - container: Element, - callback?: (component: T) => any): T; - function render

( - parentComponent: Component, - element: SFCElement

, - container: Element, - callback?: () => any): void; - function unstable_renderSubtreeIntoContainer

( - parentComponent: Component, - element: ReactElement

, - container: Element, - callback?: (component?: Component | Element) => any): Component | Element | void; -} diff --git a/src/test/node_modules/@types/react-dom/package.json b/src/test/node_modules/@types/react-dom/package.json deleted file mode 100644 index d76a95e..0000000 --- a/src/test/node_modules/@types/react-dom/package.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "_args": [ - [ - { - "raw": "@types/react-dom", - "scope": "@types", - "escapedName": "@types%2freact-dom", - "name": "@types/react-dom", - "rawSpec": "", - "spec": "latest", - "type": "tag" - }, - "/Users/panferov/Workspace/my/awesome-typescript-loader/src/test/fixtures/react" - ] - ], - "_from": "@types/react-dom@latest", - "_id": "@types/react-dom@0.14.16", - "_inCache": true, - "_installable": true, - "_location": "/@types/react-dom", - "_npmOperationalInternal": { - "host": "packages-12-west.internal.npmjs.com", - "tmp": "tmp/react-dom-0.14.16.tgz_1472151292236_0.2212693092878908" - }, - "_npmUser": { - "name": "types", - "email": "ts-npm-types@microsoft.com" - }, - "_phantomChildren": {}, - "_requested": { - "raw": "@types/react-dom", - "scope": "@types", - "escapedName": "@types%2freact-dom", - "name": "@types/react-dom", - "rawSpec": "", - "spec": "latest", - "type": "tag" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-0.14.16.tgz", - "_shasum": "13a948c4ff40b6da1014e07a34c204238e461c6f", - "_shrinkwrap": null, - "_spec": "@types/react-dom", - "_where": "/Users/panferov/Workspace/my/awesome-typescript-loader/src/test/fixtures/react", - "author": { - "name": "Asana", - "email": "https://asana.com" - }, - "dependencies": { - "@types/react": "0.14.*" - }, - "description": "TypeScript definitions for React v0.14 (react-dom)", - "devDependencies": {}, - "directories": {}, - "dist": { - "shasum": "13a948c4ff40b6da1014e07a34c204238e461c6f", - "tarball": "https://registry.npmjs.org/@types/react-dom/-/react-dom-0.14.16.tgz" - }, - "license": "MIT", - "main": "", - "maintainers": [ - { - "name": "types", - "email": "ryan.cavanaugh@microsoft.com" - } - ], - "name": "@types/react-dom", - "optionalDependencies": {}, - "readme": "ERROR: No README data found!", - "repository": { - "type": "git", - "url": "https://www.github.com/DefinitelyTyped/DefinitelyTyped.git" - }, - "scripts": {}, - "typings": "index.d.ts", - "version": "0.14.16" -} diff --git a/src/test/node_modules/@types/react-dom/react-dom.server.d.ts b/src/test/node_modules/@types/react-dom/react-dom.server.d.ts deleted file mode 100644 index 82561db..0000000 --- a/src/test/node_modules/@types/react-dom/react-dom.server.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module "react-dom/server" { - import { ReactElement } from 'react'; - - function renderToString(element: ReactElement): string; - function renderToStaticMarkup(element: ReactElement): string; - var version: string; -} diff --git a/src/test/node_modules/@types/react-dom/types-metadata.json b/src/test/node_modules/@types/react-dom/types-metadata.json deleted file mode 100644 index 48a0095..0000000 --- a/src/test/node_modules/@types/react-dom/types-metadata.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "authors": "Asana , AssureSign , Microsoft ", - "definitionFilename": "index.d.ts", - "libraryDependencies": [], - "moduleDependencies": [ - "react" - ], - "libraryMajorVersion": "0", - "libraryMinorVersion": "14", - "libraryName": "React v0.14 (react-dom)", - "typingsPackageName": "react-dom", - "projectName": "http://facebook.github.io/react/", - "sourceRepoURL": "https://www.github.com/DefinitelyTyped/DefinitelyTyped", - "sourceBranch": "types-2.0", - "kind": "UMD", - "globals": [ - "ReactDOM" - ], - "declaredModules": [ - "react-dom/server" - ], - "files": [ - "index.d.ts", - "react-dom.server.d.ts" - ], - "hasPackageJson": false, - "contentHash": "98810b5828ba36d3526817944f4f174177c39737c2f7f6ee6e18f977fbd64b92" -} \ No newline at end of file diff --git a/src/test/node_modules/@types/react/README.md b/src/test/node_modules/@types/react/README.md deleted file mode 100644 index 93e5b73..0000000 --- a/src/test/node_modules/@types/react/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Installation -> `npm install --save @types/react` - -# Summary -This package contains type definitions for React v0.14 (http://facebook.github.io/react/). - -# Details -Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/react - -Additional Details - * Last updated: Thu, 25 Aug 2016 16:56:09 GMT - * File structure: UMD - * Library Dependencies: none - * Module Dependencies: none - * Global values: React - -# Credits -These definitions were written by Asana , AssureSign , Microsoft . diff --git a/src/test/node_modules/@types/react/index.d.ts b/src/test/node_modules/@types/react/index.d.ts deleted file mode 100644 index cf545a6..0000000 --- a/src/test/node_modules/@types/react/index.d.ts +++ /dev/null @@ -1,2530 +0,0 @@ -// Type definitions for React v0.14 -// Project: http://facebook.github.io/react/ -// Definitions by: Asana , AssureSign , Microsoft -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -export = React; -export as namespace React; - -declare namespace React { - - // - // React Elements - // ---------------------------------------------------------------------- - - type ReactType = string | ComponentClass | StatelessComponent; - - type Key = string | number; - type Ref = string | ((instance: T) => any); - type ComponentState = {} | void; - - interface Attributes { - key?: Key; - } - interface ClassAttributes extends Attributes { - ref?: Ref; - } - - interface ReactElement

{ - type: string | ComponentClass

| SFC

; - props: P; - key?: Key; - } - - interface SFCElement

extends ReactElement

{ - type: SFC

; - } - - type CElement> = ComponentElement; - interface ComponentElement> extends ReactElement

{ - type: ComponentClass

; - ref?: Ref; - } - - type ClassicElement

= CElement>; - - interface DOMElement

, T extends Element> extends ReactElement

{ - type: string; - ref: Ref; - } - - interface ReactHTMLElement extends DOMElement, T> { - } - - interface ReactSVGElement extends DOMElement, SVGElement> { - } - - // - // Factories - // ---------------------------------------------------------------------- - - interface Factory

{ - (props?: P & Attributes, ...children: ReactNode[]): ReactElement

; - } - - interface SFCFactory

{ - (props?: P & Attributes, ...children: ReactNode[]): SFCElement

; - } - - interface ComponentFactory> { - (props?: P & ClassAttributes, ...children: ReactNode[]): CElement; - } - - type CFactory> = ComponentFactory; - type ClassicFactory

= CFactory>; - - interface DOMFactory

, T extends Element> { - (props?: P & ClassAttributes, ...children: ReactNode[]): DOMElement; - } - - interface HTMLFactory extends DOMFactory, T> { - } - - interface SVGFactory extends DOMFactory, SVGElement> { - } - - // - // React Nodes - // http://facebook.github.io/react/docs/glossary.html - // ---------------------------------------------------------------------- - - type ReactText = string | number; - type ReactChild = ReactElement | ReactText; - - // Should be Array but type aliases cannot be recursive - type ReactFragment = {} | Array; - type ReactNode = ReactChild | ReactFragment | boolean; - - // - // Top Level API - // ---------------------------------------------------------------------- - - function createClass(spec: ComponentSpec): ClassicComponentClass

; - - function createFactory

, T extends Element>( - type: string): DOMFactory; - function createFactory

(type: SFC

): SFCFactory

; - function createFactory

( - type: ClassType, ClassicComponentClass

>): CFactory>; - function createFactory, C extends ComponentClass

>( - type: ClassType): CFactory; - function createFactory

(type: ComponentClass

| SFC

): Factory

; - - function createElement

, T extends Element>( - type: string, - props?: P & ClassAttributes, - ...children: ReactNode[]): DOMElement; - function createElement

( - type: SFC

, - props?: P & Attributes, - ...children: ReactNode[]): SFCElement

; - function createElement

( - type: ClassType, ClassicComponentClass

>, - props?: P & ClassAttributes>, - ...children: ReactNode[]): CElement>; - function createElement, C extends ComponentClass

>( - type: ClassType, - props?: P & ClassAttributes, - ...children: ReactNode[]): CElement; - function createElement

( - type: ComponentClass

| SFC

, - props?: P & Attributes, - ...children: ReactNode[]): ReactElement

; - - function cloneElement

, T extends Element>( - element: DOMElement, - props?: P & ClassAttributes, - ...children: ReactNode[]): DOMElement; - function cloneElement

( - element: SFCElement

, - props?: Q, // should be Q & Attributes, but then Q is inferred as {} - ...children: ReactNode[]): SFCElement

; - function cloneElement

>( - element: CElement, - props?: Q, // should be Q & ClassAttributes - ...children: ReactNode[]): CElement; - function cloneElement

( - element: ReactElement

, - props?: Q, // should be Q & Attributes - ...children: ReactNode[]): ReactElement

; - - function isValidElement

(object: {}): object is ReactElement

; - - var DOM: ReactDOM; - var PropTypes: ReactPropTypes; - var Children: ReactChildren; - var version: string; - - // - // Component API - // ---------------------------------------------------------------------- - - type ReactInstance = Component | Element; - - // Base component for plain JS classes - class Component implements ComponentLifecycle { - constructor(props?: P, context?: any); - setState(f: (prevState: S, props: P) => S, callback?: () => any): void; - setState(state: S, callback?: () => any): void; - forceUpdate(callBack?: () => any): void; - render(): JSX.Element | null; - - // React.Props is now deprecated, which means that the `children` - // property is not available on `P` by default, even though you can - // always pass children as variadic arguments to `createElement`. - // In the future, if we can define its call signature conditionally - // on the existence of `children` in `P`, then we should remove this. - props: P & { children?: ReactNode }; - state: S; - context: {}; - refs: { - [key: string]: ReactInstance - }; - } - - class PureComponent extends Component {} - - interface ClassicComponent extends Component { - replaceState(nextState: S, callback?: () => any): void; - isMounted(): boolean; - getInitialState?(): S; - } - - interface ChildContextProvider { - getChildContext(): CC; - } - - // - // Class Interfaces - // ---------------------------------------------------------------------- - - type SFC

= StatelessComponent

; - interface StatelessComponent

{ - (props: P, context?: any): ReactElement; - propTypes?: ValidationMap

; - contextTypes?: ValidationMap; - defaultProps?: P; - displayName?: string; - } - - interface ComponentClass

{ - new(props?: P, context?: any): Component; - propTypes?: ValidationMap

; - contextTypes?: ValidationMap; - childContextTypes?: ValidationMap; - defaultProps?: P; - displayName?: string; - } - - interface ClassicComponentClass

extends ComponentClass

{ - new(props?: P, context?: any): ClassicComponent; - getDefaultProps?(): P; - } - - /** - * We use an intersection type to infer multiple type parameters from - * a single argument, which is useful for many top-level API defs. - * See https://github.com/Microsoft/TypeScript/issues/7234 for more info. - */ - type ClassType, C extends ComponentClass

> = - C & - (new() => T) & - (new() => { props: P }); - - // - // Component Specs and Lifecycle - // ---------------------------------------------------------------------- - - interface ComponentLifecycle { - componentWillMount?(): void; - componentDidMount?(): void; - componentWillReceiveProps?(nextProps: P, nextContext: any): void; - shouldComponentUpdate?(nextProps: P, nextState: S, nextContext: any): boolean; - componentWillUpdate?(nextProps: P, nextState: S, nextContext: any): void; - componentDidUpdate?(prevProps: P, prevState: S, prevContext: any): void; - componentWillUnmount?(): void; - } - - interface Mixin extends ComponentLifecycle { - mixins?: Mixin; - statics?: { - [key: string]: any; - }; - - displayName?: string; - propTypes?: ValidationMap; - contextTypes?: ValidationMap; - childContextTypes?: ValidationMap; - - getDefaultProps?(): P; - getInitialState?(): S; - } - - interface ComponentSpec extends Mixin { - render(): ReactElement; - - [propertyName: string]: any; - } - - // - // Event System - // ---------------------------------------------------------------------- - - interface SyntheticEvent { - bubbles: boolean; - currentTarget: EventTarget; - cancelable: boolean; - defaultPrevented: boolean; - eventPhase: number; - isTrusted: boolean; - nativeEvent: Event; - preventDefault(): void; - isDefaultPrevented(): boolean; - stopPropagation(): void; - isPropagationStopped(): boolean; - persist(): void; - target: EventTarget; - timeStamp: Date; - type: string; - } - - interface ClipboardEvent extends SyntheticEvent { - clipboardData: DataTransfer; - } - - interface CompositionEvent extends SyntheticEvent { - data: string; - } - - interface DragEvent extends MouseEvent { - dataTransfer: DataTransfer; - } - - interface FocusEvent extends SyntheticEvent { - relatedTarget: EventTarget; - } - - interface FormEvent extends SyntheticEvent { - } - - interface KeyboardEvent extends SyntheticEvent { - altKey: boolean; - charCode: number; - ctrlKey: boolean; - getModifierState(key: string): boolean; - key: string; - keyCode: number; - locale: string; - location: number; - metaKey: boolean; - repeat: boolean; - shiftKey: boolean; - which: number; - } - - interface MouseEvent extends SyntheticEvent { - altKey: boolean; - button: number; - buttons: number; - clientX: number; - clientY: number; - ctrlKey: boolean; - getModifierState(key: string): boolean; - metaKey: boolean; - pageX: number; - pageY: number; - relatedTarget: EventTarget; - screenX: number; - screenY: number; - shiftKey: boolean; - } - - interface TouchEvent extends SyntheticEvent { - altKey: boolean; - changedTouches: TouchList; - ctrlKey: boolean; - getModifierState(key: string): boolean; - metaKey: boolean; - shiftKey: boolean; - targetTouches: TouchList; - touches: TouchList; - } - - interface UIEvent extends SyntheticEvent { - detail: number; - view: AbstractView; - } - - interface WheelEvent extends MouseEvent { - deltaMode: number; - deltaX: number; - deltaY: number; - deltaZ: number; - } - - interface AnimationEvent extends SyntheticEvent<{}> { - animationName: string; - pseudoElement: string; - elapsedTime: number; - } - - interface TransitionEvent extends SyntheticEvent<{}> { - propertyName: string; - pseudoElement: string; - elapsedTime: number; - } - - // - // Event Handler Types - // ---------------------------------------------------------------------- - - interface EventHandler> { - (event: E): void; - } - - type ReactEventHandler = EventHandler>; - - type ClipboardEventHandler = EventHandler>; - type CompositionEventHandler = EventHandler>; - type DragEventHandler = EventHandler>; - type FocusEventHandler = EventHandler>; - type FormEventHandler = EventHandler>; - type KeyboardEventHandler = EventHandler>; - type MouseEventHandler = EventHandler>; - type TouchEventHandler = EventHandler>; - type UIEventHandler = EventHandler>; - type WheelEventHandler = EventHandler>; - type AnimationEventHandler = EventHandler; - type TransitionEventHandler = EventHandler; - - // - // Props / DOM Attributes - // ---------------------------------------------------------------------- - - /** - * @deprecated. This was used to allow clients to pass `ref` and `key` - * to `createElement`, which is no longer necessary due to intersection - * types. If you need to declare a props object before passing it to - * `createElement` or a factory, use `ClassAttributes`: - * - * ```ts - * var b: Button; - * var props: ButtonProps & ClassAttributes