├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .npmignore ├── .tav.yml ├── .travis.yml ├── CONTRIBUTING.md ├── README.md ├── examples ├── babelify │ ├── .babelrc │ ├── .gitignore │ ├── README.md │ ├── build.js │ ├── package.json │ ├── public │ │ └── index.html │ ├── src │ │ ├── Greeter.ts │ │ └── main.ts │ └── tsconfig.json ├── greeter │ ├── .gitignore │ ├── README.md │ ├── build.js │ ├── package.json │ ├── public │ │ └── index.html │ └── src │ │ ├── Greeter.ts │ │ └── main.ts ├── js │ ├── .gitignore │ ├── README.md │ ├── build.js │ ├── package.json │ ├── public │ │ └── index.html │ └── src │ │ ├── Greeter.ts │ │ └── main.js ├── jsx │ ├── .gitignore │ ├── README.md │ ├── build.js │ ├── package.json │ ├── public │ │ └── index.html │ ├── src │ │ ├── Greeter.tsx │ │ └── main.tsx │ ├── tsconfig.json │ ├── tsd.json │ └── typings │ │ ├── react │ │ ├── react-dom.d.ts │ │ └── react.d.ts │ │ └── tsd.d.ts └── proxyquireify │ ├── .gitignore │ ├── README.md │ ├── build.js │ ├── package.json │ ├── src │ ├── bar.ts │ ├── baz.ts │ ├── foo-spec.ts │ └── foo.ts │ ├── tsconfig.json │ └── typings.json ├── index.d.ts ├── index.js ├── lib ├── CompileError.js ├── Host.js ├── Tsifier.js └── time.js ├── package-lock.json ├── package.json └── test ├── allowJs ├── x.ts ├── y.js └── z.js ├── declarationFile ├── interface.d.ts ├── tsconfig.custom.json └── x.ts ├── emptyOutput ├── tsconfig.json └── x.ts ├── externalDeps ├── node-foo.d.ts └── x.ts ├── filesOutsideCwd ├── cwd │ └── x.ts └── shared │ ├── y.ts │ └── z.ts ├── globalTransform ├── a.ts └── node_modules │ └── b.ts ├── multipleConfigs ├── nested │ ├── tsconfig.json │ └── x.ts ├── tsconfig.custom.json └── tsconfig.json ├── multipleEntryPoints ├── x1.ts ├── x2.ts ├── y.ts └── z.ts ├── noArguments ├── x.ts ├── y.ts └── z.ts ├── sharedTsconfig ├── project │ └── x.ts ├── shared │ └── interface.d.ts └── tsconfig.json ├── syntaxError └── x.ts ├── test.js ├── tsconfig ├── tsconfig.json └── x.ts ├── tsconfigExclude ├── broken.d.ts ├── interface.d.ts ├── tsconfig.json └── x.ts ├── tsx ├── CoolComponent.tsx ├── React.ts └── main.ts ├── typeError ├── x.ts ├── y.ts └── z.ts ├── watchify ├── interface.d.ts ├── main.ts ├── ok.ts ├── syntaxError.ts ├── tmp.ts ├── tsconfig.json └── typeError.ts ├── withAdjacentCompiledFiles ├── x.js ├── x.ts ├── y.js ├── y.ts ├── z.js └── z.ts ├── withFileOverrides ├── bar-exam.ts ├── bar-tender.ts ├── bar.ts ├── foo.ts ├── index.ts └── tsconfig.json ├── withJsRoot ├── x.js ├── y.ts └── z.ts ├── withJsRootAndNestedDeps ├── nested │ ├── twice │ │ └── z.ts │ └── y.ts ├── tsconfig.json └── x.js ├── withNestedDeps ├── nested │ ├── twice │ │ └── z.ts │ └── y.ts └── x.ts └── withRequiredStream └── x.ts /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = tab 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | examples/**/*.js 3 | test/**/*.js 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true, 4 | "es6": true 5 | }, 6 | "extends": "eslint:recommended" 7 | } 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | **/.tmp* 4 | !test/globalTransform/node_modules 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | **/.* 2 | examples/ 3 | test/ 4 | -------------------------------------------------------------------------------- /.tav.yml: -------------------------------------------------------------------------------- 1 | # https://semver.npmjs.com/ 2 | browserify: 3 | versions: 13.3.0 || 14.5.0 || 15.2.0 || 16.2.3 4 | commands: node test/test.js 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | sudo: false 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Making a new release 2 | 3 | Write release notes in `README.md`. Then, 4 | 5 | ``` 6 | npm version 7 | git push --follow-tags 8 | npm publish 9 | ``` 10 | 11 | Enjoy life :heart: :rose: 12 | 13 | 14 | # Debugging 15 | 16 | Debug logging is enabled using the built in node `util`. We setup the `log` function as 17 | 18 | ``` 19 | var log = require('util').debuglog(require('./package').name); 20 | ``` 21 | 22 | If you want this function to actually do something just set the environment variable `NODE_DEBUG=tsify` e.g. 23 | 24 | ``` 25 | NODE_DEBUG=tsify browserify ... etc. 26 | ``` 27 | 28 | 29 | # Internals and processing flow 30 | 31 | `tsify` is a implemented as a Browserify [plugin](https://github.com/substack/browserify-handbook#plugins) - not as a [transform](https://github.com/substack/browserify-handbook#writing-your-own) - because it needs access to the Browserify bundler - which is passed to plugins, but not to transforms. Access to the bundler is required so that `tsify` can include the TypeScript extensions in the `_extensions` array used by Browserify when resolving modules and so that `tsify` can listen to events associated with the Browserify pipeline. That's not possible with a transform, as a transform receives only a file path and a stream of content. 32 | 33 | However, `tsify` does implement a transform that is wired up internally. 34 | 35 | ## `index.js` - the plugin 36 | 37 | * It wires up internal transform. 38 | * It wires up the `file` and `reset` events. (Note that the `file` is [informational nicety](https://github.com/substack/node-browserify#events); it's not a core part of the Browserify process.) 39 | * It places `.ts(x)` extensions at the *head* of Browserify's extensions array. 40 | * It gathers the Browserify entry point files. 41 | 42 | ## `lib/Tsifier.js` - the transform 43 | 44 | * The `Tsifer` is a Browserify transform. 45 | * It returns compiled content to Browserify. 46 | * It parses the `tsconfig.json` for options and files. 47 | * It configures the TypeScipt `rootDir` and `outDir` options to use an imaginary `/__tsify__` directory. 48 | * It creates the `Host`, passing it to the TypeScript Compiler API to compile the program and check the syntax, semantics and output. 49 | 50 | ## `lib/Host.js` - the TypeScript host 51 | 52 | * The `Host` is a TypeScript Compiler API host. 53 | * It abstracts the reading and writing of files, etc. 54 | * It parses and caches the parsed source files, reading them from disk. 55 | * It caches the compiled files when the TypeScript Compiler API writes compiled content. 56 | 57 | ## Processing flow 58 | 59 | * When Browserify's pipeline is prepared, the initial list of files to be compiled is obtained from the `tsconfig.json` and from the Browserify entry points. 60 | * With the pipeline prepared, Browserify starts processing its entry points, passing their content through the `Tsifier` transform. 61 | * To obtain the transformed content, the `Tsifier` transform looks in a cache for the compiled content. 62 | * If the cache look up results in a miss, the transformed file is added to the list of files (if it's missing from the list) and a compilation of the list of files is performed. 63 | * Note that with TypeScript using the same module resolution mechanism as Browserify (`"moduleResolution": "node"`) only a single compilation is required. 64 | * Browserify then locates any `require` calls in the transformed content and passes the content for these dependencies through the `Tsifier` transform. 65 | * This continues until all dependencies have been processed. 66 | 67 | ## Caveats 68 | 69 | * The `Host` reads the source from disk; the content passed into the `Tsifier` transform is ignored. That means that any transforms added before the `tsify` plugin will be ineffectual. 70 | * If `grunt-browserify` is used, declarative configurations will see transforms will be loaded before plugins. To avoid that, an imperative configuration that uses the [configure](https://github.com/jmreidy/grunt-browserify#configure) function would be necessary. 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tsify 2 | 3 | [Browserify](http://browserify.org/) plugin for compiling [TypeScript](http://www.typescriptlang.org/) 4 | 5 | [![NPM version](https://img.shields.io/npm/v/tsify.svg)](https://www.npmjs.com/package/tsify) 6 | [![Downloads](http://img.shields.io/npm/dm/tsify.svg)](https://npmjs.org/package/tsify) 7 | [![Build status](https://img.shields.io/travis/TypeStrong/tsify.svg)](http://travis-ci.org/TypeStrong/tsify) 8 | [![Dependency status](https://img.shields.io/david/TypeStrong/tsify.svg)](https://david-dm.org/TypeStrong/tsify) 9 | [![devDependency Status](https://img.shields.io/david/dev/TypeStrong/tsify.svg)](https://david-dm.org/TypeStrong/tsify#info=devDependencies) 10 | [![peerDependency Status](https://img.shields.io/david/peer/TypeStrong/tsify.svg)](https://david-dm.org/TypeStrong/tsify#info=peerDependencies) 11 | 12 | # Example Usage 13 | 14 | ### Browserify API: 15 | 16 | ``` js 17 | var browserify = require('browserify'); 18 | var tsify = require('tsify'); 19 | 20 | browserify() 21 | .add('main.ts') 22 | .plugin(tsify, { noImplicitAny: true }) 23 | .bundle() 24 | .on('error', function (error) { console.error(error.toString()); }) 25 | .pipe(process.stdout); 26 | ``` 27 | 28 | ### Command line: 29 | 30 | ``` sh 31 | $ browserify main.ts -p [ tsify --noImplicitAny ] > bundle.js 32 | ``` 33 | 34 | Note that when using the Browserify CLI, compilation will always halt on the first error encountered, unlike the regular TypeScript CLI. This behavior can be overridden in the API, as shown in the API example. 35 | 36 | Also note that the square brackets `[ ]` in the example above are *required* if you want to pass parameters to tsify; they don't denote an optional part of the command. 37 | 38 | # Installation 39 | 40 | Just plain ol' [npm](https://npmjs.org/) installation: 41 | 42 | ### 1. Install browserify 43 | ```sh 44 | npm install browserify 45 | ``` 46 | 47 | ### 2. Install typescript 48 | 49 | ``` sh 50 | npm install typescript 51 | ``` 52 | 53 | ### 3. Install tsify 54 | ``` sh 55 | npm install tsify 56 | ``` 57 | 58 | For use on the command line, use the flag `npm install -g`. 59 | 60 | # Options 61 | 62 | * **tsify** will generate inline sourcemaps if the `--debug` option is set on Browserify, regardless of the flag status in `tsconfig.json`. 63 | * **tsify** supports almost all options from the TypeScript compiler. Notable exceptions: 64 | * `-d, --declaration` - See [tsify#15](https://github.com/TypeStrong/tsify/issues/15) 65 | * `--out, --outDir` - Use Browserify's file output options instead. These options are overridden because **tsify** writes to an internal memory store before bundling, instead of to the filesystem. 66 | * **tsify** supports the TypeScript compiler's `-p, --project` option which allows you to specify the path that will be used when searching for the `tsconfig.json` file. You can pass either the path to a directory or to the `tsconfig.json` file itself. (When using the API, the `project` option can specify either a path to a directory or file, or the JSON content of a `tsconfig.json` file.) 67 | * **tsify** supports overriding the `files`, `exclude` and `include` options. In particular, if `"files": []` is specified, only the Browserify entry points (and their dependencies) are passed to TypeScript for compilation. 68 | * **tsify** supports the following extra options: 69 | * `--global` - This will set up **tsify** as a global transform. See the [Browserify docs](https://github.com/substack/node-browserify#btransformtr-opts) for the implications of this flag. 70 | * `--typescript` - By default we just do `require('typescript')` to pickup whichever version you installed. However, this option allows you to pass in a different TypeScript compiler, such as [NTypeScript](https://github.com/TypeStrong/ntypescript). Note that when using the API, you can pass either the name of the alternative compiler or a reference to it: 71 | * `{ typescript: 'ntypescript' }` 72 | * `{ typescript: require('ntypescript') }` 73 | 74 | # Does this work with... 75 | 76 | ### tsconfig.json? 77 | 78 | tsify will automatically read options from `tsconfig.json`. However, some options from this file will be ignored: 79 | 80 | * `compilerOptions.declaration` - See [tsify#15](https://github.com/TypeStrong/tsify/issues/15) 81 | * `compilerOptions.out`, `compilerOptions.outDir`, and `compilerOptions.noEmit` - Use Browserify's file output options instead. These options are overridden because **tsify** writes its intermediate JavaScript output to an internal memory store instead of to the filesystem. 82 | * `files` - Use Browserify's file input options instead. This is necessary because Browserify needs to know which file(s) are the entry points to your program. 83 | * `compilerOptions.sourceMaps` - Source maps are only generated if the `--debug` option is set on Browserify. 84 | * `compilerOptions.inlineSourceMaps` - Generated source maps are always inline. 85 | 86 | ### Watchify? 87 | 88 | Yes! **tsify** can do incremental compilation using [watchify](//github.com/substack/watchify), resulting in much faster incremental build times. Just follow the Watchify documentation, and add **tsify** as a plugin as indicated in the documentation above. 89 | 90 | ### Gulp? 91 | 92 | No problem. See the Gulp recipes on using [browserify](https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-uglify-sourcemap.md) and [watchify](https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md), and add **tsify** as a plugin as indicated in the documentation above. 93 | 94 | ### Grunt? 95 | 96 | Use [grunt-browserify](https://github.com/jmreidy/grunt-browserify) and you should be good! Just add **tsify** as a plugin in your Grunt configuration. 97 | 98 | ### IE 11? 99 | 100 | The inlined sourcemaps that Browserify generates [may not be readable by IE 11](//github.com/TypeStrong/tsify/issues/19) for debugging purposes. This is easy to fix by adding [exorcist](//github.com/thlorenz/exorcist) to your build workflow after Browserify. 101 | 102 | ### ES2015? *(formerly known as ES6)* 103 | 104 | TypeScript's ES2015 output mode should work without too much additional setup. Browserify does not support ES2015 modules, so if you want to use ES2015 you still need some transpilation step. Make sure to add [babelify](//github.com/babel/babelify) to your list of transforms. Note that if you are using the API, you need to set up **tsify** before babelify: 105 | 106 | ``` js 107 | browserify() 108 | .plugin(tsify, { target: 'es6' }) 109 | .transform(babelify, { extensions: [ '.tsx', '.ts' ] }) 110 | ``` 111 | 112 | # FAQ / Common issues 113 | 114 | ### SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' 115 | 116 | This error occurs when a TypeScript file is not compiled to JavaScript before being run through the Browserify bundler. There are a couple known reasons you might run into this. 117 | 118 | * If you are trying to output in ES6 mode, then you have to use an additional transpilation step such as [babelify](//github.com/babel/babelify) because Browserify does not support bundling ES6 modules. 119 | * Make sure that if you're using the API, your setup `.plugin('tsify')` is done *before* any transforms such as `.transform('babelify')`. **tsify** needs to run first! 120 | * There is a known issue in Browserify regarding including files with `expose` set to the name of the included file. More details and a workaround are available in [#60](//github.com/TypeStrong/tsify/issues/60). 121 | 122 | # Why a plugin? 123 | 124 | There are several TypeScript compilation transforms available on npm, all with various issues. The TypeScript compiler automatically performs dependency resolution on module imports, much like Browserify itself. Browserify transforms are not flexible enough to deal with multiple file outputs given a single file input, which means that any working TypeScript compilation transform either skips the resolution step (which is necessary for complete type checking) or performs multiple compilations of source files further down the dependency graph. 125 | 126 | **tsify** avoids this problem by using the power of plugins to perform a single compilation of the TypeScript source up-front, using Browserify to glue together the resulting files. 127 | 128 | # License 129 | 130 | MIT 131 | 132 | # Changelog 133 | 134 | * 5.0.4 - Fix export in `d.ts` file. 135 | * 5.0.3 - Improve detection of case-sensitive file systems. 136 | * 5.0.2 - Remove `@types/browserify` and incorrect/undocumented use of TypeScript types in `tsify` signature. 137 | * 5.0.1 - Remove default import from `index.d.ts` and add `@types/browserify` dependency. 138 | * 5.0.0 - **Breaking**: Fix type declarations for TypeScript 4 compatibility. With this fix, the TypeScript version must be 2.8 or above. 139 | * 4.0.2 - Add `types` to `package.json`. 140 | * 4.0.1 - Fix so that `watchify` does not stop listening. 141 | * 4.0.0 - Re-applied changes from 3.0.2: added support for the `forceConsistentCasingInFilenames` compiler option. 142 | * 3.0.4 - Added support for overriding the `files`, `exclude` and `include` options. 143 | * 3.0.3 - Reverted 3.0.2. 144 | * 3.0.2 - Added support for the `forceConsistentCasingInFilenames` compiler option. 145 | * 3.0.1 - Fixed an error with file system case sensitivity detection. 146 | * 3.0.0 - **Breaking**: Dropped support for Browserify < 10.x. Re-instated changes from 2.0.4 to 2.0.7. 147 | * 2.0.8 - Reverted to 2.0.3. Changes introduced from 2.0.4 to 2.0.7 have issues with early versions of Browserify. 148 | * 2.0.7 - Tracked files for filtered stream and module-name 'rows'. Using `allowJs` no longer causes problems with streams. 149 | * 2.0.6 - Filtered module-name 'rows', too, as filtering only source 'rows' re-broke Browserify's [require](https://github.com/substack/node-browserify#brequirefile-opts) option. 150 | * 2.0.5 - The fix in 2.0.4 was too aggressive, as it filtered too many Browserify 'rows'. Now, only 'rows' from stream sources are filtered. 151 | * 2.0.4 - Fixed a bug that broke Browserify's [require](https://github.com/substack/node-browserify#brequirefile-opts) option. 152 | * 2.0.3 - Fixed a bug related to case-sensitive paths and normalized more path parameters. 153 | * 2.0.2 - Added support for specifying the `project` option using the JSON content of a `tsconfig.json` file. 154 | * 2.0.1 - Fixed a bug in which the `include` option was broken if `tsconfig.json` was not in the current directory. 155 | * 2.0.0 - **Breaking**: updated to the latest `tsconfig`, so `filesGlob` is no longer supported. Use TypeScript 2's `exclude` and `include` options instead. 156 | * 1.0.9 - Implemented additional compiler host methods to support the default inclusion of visible `@types` modules. 157 | * 1.0.8 - Implemented file system case-sensitivity detection, fixing [#200](//github.com/TypeStrong/tsify/issues/200). 158 | * 1.0.7 - Replaced `Object.assign` with [`object-assign`](https://github.com/sindresorhus/object-assign) for Node 0.12 compatibility. 159 | * 1.0.6 - Fixed a bug in which TypeScript 2 libraries (specified using the `lib` option) were left out of the compilation when bundling on Windows. 160 | * 1.0.5 - Fixed a bug where empty output resulted in an error. 161 | * 1.0.4 - Fixed numerous bugs: 162 | * Refactored to use canonical file names, fixing [#122](//github.com/TypeStrong/tsify/issues/122), [#135](//github.com/TypeStrong/tsify/issues/135), [#148](//github.com/TypeStrong/tsify/issues/148), [#150](//github.com/TypeStrong/tsify/issues/150) and [#161](//github.com/TypeStrong/tsify/issues/161). 163 | * Refactored to avoid having to infer the TypeScript root, fixing [#152](//github.com/TypeStrong/tsify/issues/152). 164 | * Misconfiguration of `tsify` as a transform now results in an explicit error. 165 | * Internal errors that previously went unreported are now emitted to Browserify. 166 | * 1.0.3 - Fixed a bug introduced in 1.0.2 (that resulted in the `target` being set to `ES3`). 167 | * 1.0.2 - Added support for the TypeScript compiler's short-name, command-line options (e.g. `-p`). 168 | * 1.0.1 - On Windows, sometimes, the Browserify `basedir` contains backslashes that need normalization for findConfigFile to work correctly. 169 | * 1.0.0 - **Breaking**: TypeScript is now a `devDependency` so we don't install one for you. Please run `npm install typescript --save-dev` in your project to use whatever version you want. 170 | * 0.16.0 - Reinstated changes from 0.15.5. 171 | * 0.15.6 - Reverted 0.15.5 because of breaking changes. 172 | * 0.15.5 - Used `TypeStrong/tsconfig` for parsing `tsconfig.json` to add support for `exclude` and more. 173 | * 0.15.4 - Fixed some compilation failures introduced by v0.14.3. 174 | * 0.15.3 - Added support for the `--global` flag to use **tsify** as a global transform. 175 | * 0.15.2 - Added support for the `files` property of `tsconfig.json`. 176 | * 0.15.1 - Added support for `--project` flag to use a custom location for `tsconfig.json`. 177 | * 0.15.0 - Removed `debuglog` dependency. 178 | * 0.14.8 - Reverted removal of `debuglog` dependency for compatibility with old versions of Node 0.12. 179 | * 0.14.7 - Only generate sourcemap information in the compiler when `--debug` is set, for potential speed improvements when not using sourcemaps. 180 | * 0.14.6 - Fixed output when `--jsx=preserve` is set. 181 | * 0.14.5 - Removed `lodash` and `debuglog` dependencies. 182 | * 0.14.4 - Fixed sourcemap paths when using Browserify's `basedir` option. 183 | * 0.14.3 - Fixed `allowJs` option to enable transpiling ES6+ JS to ES5 or lower. 184 | * 0.14.2 - Fixed `findConfigFile` for TypeScript 1.9 dev. 185 | * 0.14.1 - Removed module mode override for ES6 mode (because CommonJS mode is now supported by TS 1.8). 186 | * 0.14.0 - Updated to TypeScript 1.8 (thanks @joelday!) 187 | * 0.13.2 - Fixed `findConfigFile` for use with the TypeScript 1.8 dev version. 188 | * 0.13.1 - Fixed bug where `*.tsx` was not included in Browserify's list of extensions if the `jsx` option was set via `tsconfig.json`. 189 | * 0.13.0 - Updated to TypeScript 1.7. 190 | * 0.12.2 - Fixed resolution of entries outside of `process.cwd()` (thanks @pnlybubbles!) 191 | * 0.12.1 - Updated `typescript` dependency to lock it down to version 1.6.x 192 | * 0.12.0 - Updated to TypeScript 1.6. 193 | * 0.11.16 - Updated `typescript` dependency to lock it down to version 1.5.x 194 | * 0.11.15 - Added `*.tsx` to Browserify's list of extensions if `--jsx` is set (with priority *.ts > *.tsx > *.js). 195 | * 0.11.14 - Override sourcemap settings with `--inlineSourceMap` and `--inlineSources` (because that's what Browserify expects). 196 | * 0.11.13 - Fixed bug introduced in last change where non-entry point files were erroneously being excluded from the build. 197 | * 0.11.12 - Fixed compilation when the current working directory is a symlink. 198 | * 0.11.11 - Updated compiler host to support current TypeScript nightly. 199 | * 0.11.10 - Updated resolution of `lib.d.ts` to support TypeScript 1.6 and to work with the `--typescript` option. 200 | * 0.11.9 - Fixed dumb error. 201 | * 0.11.8 - Handled JSX output from the TypeScript compiler to support `preserve`. 202 | * 0.11.7 - Added `*.tsx` to the regex determining whether to run a file through the TypeScript compiler. 203 | * 0.11.6 - Updated dependencies and devDependencies to latest. 204 | * 0.11.5 - Fixed emit of `file` event to trigger watchify even when there are fatal compilation errors. 205 | * 0.11.4 - Added `--typescript` option. 206 | * 0.11.3 - Updated to TypeScript 1.5. 207 | * 0.11.2 - Blacklisted `--out` and `--outDir` compiler options. 208 | * 0.11.1 - Added `tsconfig.json` support. 209 | * 0.11.0 - Altered behavior to pass through all compiler options to tsc by default. 210 | * 0.10.2 - Fixed output of global error messages. Fixed code generation in ES6 mode. 211 | * 0.10.1 - Fixed display of nested error messages, e.g. many typing errors. 212 | * 0.10.0 - Added `stopOnError` option and changed default behavior to continue building when there are typing errors. 213 | * 0.9.0 - Updated to use TypeScript from npm (thanks @hexaglow!) 214 | * 0.8.2 - Updated peerDependency for Browserify to allow any version >= 6.x. 215 | * 0.8.1 - Updated peerDependency for Browserify 9.x. 216 | * 0.8.0 - Updated to TypeScript 1.4.1. 217 | * 0.7.1 - Updated peerDependency for Browserify 8.x. 218 | * 0.7.0 - Updated error handling for compatibility with Watchify. 219 | * 0.6.5 - Updated peerDependency for Browserify 7.x. 220 | * 0.6.4 - Included richer file position information in syntax error messages. 221 | * 0.6.3 - Updated to TypeScript 1.3. 222 | * 0.6.2 - Included empty *.d.ts compiled files in bundle for Karma compatibility. 223 | * 0.6.1 - Fixed compilation cache miss when given absolute filenames. 224 | * 0.6.0 - Updated to TypeScript 1.1. 225 | * 0.5.2 - Bugfix for 0.5.1 for files not included with expose. 226 | * 0.5.1 - Handled *.d.ts files passed as entries. Fix for files included with expose. 227 | * 0.5.0 - Updated to Browserify 6.x. 228 | * 0.4.1 - Added npmignore to clean up published package. 229 | * 0.4.0 - Dropped Browserify 4.x support. Fixed race condition causing pathological performance with some usage patterns, e.g. when used with [karma-browserify](https://github.com/Nikku/karma-browserify). 230 | * 0.3.1 - Supported adding files with `bundler.add()`. 231 | * 0.3.0 - Added Browserify 5.x support. 232 | * 0.2.1 - Fixed paths for sources in sourcemaps. 233 | * 0.2.0 - Made Browserify prioritize *.ts files over *.js files in dependency resolution. 234 | * 0.1.4 - Handled case where the entry point is not a TypeScript file. 235 | * 0.1.3 - Automatically added *.ts to Browserify's list of file extensions to resolve. 236 | * 0.1.2 - Added sourcemap support. 237 | * 0.1.1 - Fixed issue where intermediate *.js files were being written to disk when using `watchify`. 238 | * 0.1.0 - Initial version. 239 | -------------------------------------------------------------------------------- /examples/babelify/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } 4 | -------------------------------------------------------------------------------- /examples/babelify/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | public/bundle.js 3 | -------------------------------------------------------------------------------- /examples/babelify/README.md: -------------------------------------------------------------------------------- 1 | # tsify Sample: babelify 2 | 3 | A trivial TypeScript project building with tsify and babelify. 4 | 5 | Based on the [TypeScript sample](https://github.com/Microsoft/TypeScriptSamples/tree/master/greeter). 6 | 7 | ## Building 8 | 9 | Check out the scripts in `package.json` for examples on how to run a build with either the CLI or the API. 10 | 11 | ```sh 12 | npm run build-cli 13 | npm run build-script 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/babelify/build.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const tsify = require('tsify'); 3 | const babelify = require('babelify'); 4 | 5 | browserify() 6 | .add('src/main.ts') 7 | .plugin(tsify) 8 | .transform(babelify, { extensions: ['.ts'] }) 9 | .bundle() 10 | .on('error', function (error) { console.error(error.toString()); }) 11 | .pipe(process.stdout); 12 | -------------------------------------------------------------------------------- /examples/babelify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsify-babelify", 3 | "version": "0.0.0", 4 | "description": "tsify Sample: babelify", 5 | "scripts": { 6 | "build-cli": "browserify -p tsify -t [ babelify --extensions .ts ] src/main.ts > public/bundle.js", 7 | "build-script": "node ./build.js > public/bundle.js" 8 | }, 9 | "author": "Nicholas Jamieson (http://github.com/cartant)", 10 | "license": "MIT", 11 | "private": true, 12 | "devDependencies": { 13 | "babel-preset-es2015": "^6.13.2", 14 | "babelify": "^7.3.0", 15 | "browserify": "^13.0.0", 16 | "tsify": "^2.0.2", 17 | "typescript": "^2.0.3" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/babelify/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TypeScript and tsify 5 | 6 | 7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/babelify/src/Greeter.ts: -------------------------------------------------------------------------------- 1 | export default class Greeter { 2 | constructor(public greeting: string) { } 3 | greet() { 4 | return "

" + this.greeting + "

"; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /examples/babelify/src/main.ts: -------------------------------------------------------------------------------- 1 | import Greeter from './Greeter'; 2 | 3 | const greeter = new Greeter("Hello, world!"); 4 | document.body.innerHTML = greeter.greet(); 5 | -------------------------------------------------------------------------------- /examples/babelify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "build", 4 | "module": "es6", 5 | "moduleResolution": "node", 6 | "target": "es6" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/greeter/.gitignore: -------------------------------------------------------------------------------- 1 | public/bundle.js 2 | -------------------------------------------------------------------------------- /examples/greeter/README.md: -------------------------------------------------------------------------------- 1 | # tsify Sample: Greeter 2 | 3 | A trivial TypeScript project building with tsify. 4 | 5 | Based on the [TypeScript sample](https://github.com/Microsoft/TypeScriptSamples/tree/master/greeter). 6 | 7 | ## Building 8 | 9 | Check out the scripts in `package.json` for examples on how to run a build with either the CLI or the API. 10 | 11 | ```sh 12 | npm run build-cli 13 | npm run build-script 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/greeter/build.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const tsify = require('tsify'); 3 | 4 | browserify() 5 | .add('src/main.ts') 6 | .plugin(tsify) 7 | .bundle() 8 | .on('error', function (error) { console.error(error.toString()); }) 9 | .pipe(process.stdout); 10 | -------------------------------------------------------------------------------- /examples/greeter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsify-greeter", 3 | "version": "0.0.0", 4 | "description": "tsify Sample: Greeter", 5 | "scripts": { 6 | "build-cli": "browserify -p tsify src/main.ts > public/bundle.js", 7 | "build-script": "node ./build.js > public/bundle.js" 8 | }, 9 | "author": "Greg Smith (http://github.com/smrq)", 10 | "license": "MIT", 11 | "private": true, 12 | "dependencies": { 13 | "browserify": "^12.0.1", 14 | "tsify": "*", 15 | "typescript": "~1.8.7" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/greeter/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TypeScript and tsify 5 | 6 | 7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/greeter/src/Greeter.ts: -------------------------------------------------------------------------------- 1 | export default class Greeter { 2 | constructor(public greeting: string) { } 3 | greet() { 4 | return "

" + this.greeting + "

"; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /examples/greeter/src/main.ts: -------------------------------------------------------------------------------- 1 | import Greeter from './Greeter'; 2 | 3 | const greeter = new Greeter("Hello, world!"); 4 | document.body.innerHTML = greeter.greet(); 5 | -------------------------------------------------------------------------------- /examples/js/.gitignore: -------------------------------------------------------------------------------- 1 | public/bundle.js 2 | -------------------------------------------------------------------------------- /examples/js/README.md: -------------------------------------------------------------------------------- 1 | # tsify Sample: JS 2 | 3 | A trivial TypeScript project building with tsify. 4 | 5 | Based on the [TypeScript sample](https://github.com/Microsoft/TypeScriptSamples/tree/master/greeter). 6 | 7 | ## Building 8 | 9 | Check out the scripts in `package.json` for examples on how to run a build with either the CLI or the API. 10 | 11 | ```sh 12 | npm run build-cli 13 | npm run build-script 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/js/build.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const tsify = require('tsify'); 3 | 4 | browserify() 5 | .add('src/main.js') 6 | .plugin(tsify, { allowJs: true }) 7 | .bundle() 8 | .on('error', function (error) { console.error(error.toString()); }) 9 | .pipe(process.stdout); 10 | -------------------------------------------------------------------------------- /examples/js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsify-js", 3 | "version": "0.0.0", 4 | "description": "tsify Sample: JS", 5 | "scripts": { 6 | "build-cli": "browserify -p [ tsify --allowJs ] src/main.js > public/bundle.js", 7 | "build-script": "node ./build.js > public/bundle.js" 8 | }, 9 | "author": "Greg Smith (http://github.com/smrq)", 10 | "license": "MIT", 11 | "private": true, 12 | "dependencies": { 13 | "browserify": "^12.0.1", 14 | "tsify": "*", 15 | "typescript": "~1.8.7" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/js/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JS, TypeScript, and tsify 5 | 6 | 7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/js/src/Greeter.ts: -------------------------------------------------------------------------------- 1 | export default class Greeter { 2 | constructor(public greeting: string) { } 3 | greet() { 4 | return "

" + this.greeting + "

"; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /examples/js/src/main.js: -------------------------------------------------------------------------------- 1 | import Greeter from './Greeter'; 2 | 3 | const greeter = new Greeter("Hello, world!"); 4 | document.body.innerHTML = greeter.greet(); 5 | -------------------------------------------------------------------------------- /examples/jsx/.gitignore: -------------------------------------------------------------------------------- 1 | public/bundle.js 2 | -------------------------------------------------------------------------------- /examples/jsx/README.md: -------------------------------------------------------------------------------- 1 | # tsify Sample: JSX 2 | 3 | A trivial TypeScript React project building with tsify. 4 | 5 | Based on the [TypeScript sample](https://github.com/Microsoft/TypeScriptSamples/tree/master/jsx). 6 | 7 | ## Building 8 | 9 | Check out the scripts in `package.json` for examples on how to run a build with either the CLI or the API. 10 | 11 | ```sh 12 | npm run build-cli 13 | npm run build-script 14 | ``` 15 | 16 | ## Running 17 | 18 | ```sh 19 | npm start 20 | ``` 21 | -------------------------------------------------------------------------------- /examples/jsx/build.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const tsify = require('tsify'); 3 | 4 | browserify() 5 | .add('src/main.tsx') 6 | .add('typings/tsd.d.ts') 7 | .plugin(tsify) 8 | .bundle() 9 | .on('error', function (error) { console.error(error.toString()); }) 10 | .pipe(process.stdout); 11 | -------------------------------------------------------------------------------- /examples/jsx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsify-jsx", 3 | "version": "0.0.0", 4 | "description": "tsify Sample: JSX", 5 | "scripts": { 6 | "build-cli": "browserify -p tsify src/main.tsx typings/tsd.d.ts > public/bundle.js", 7 | "build-script": "node ./build.js > public/bundle.js", 8 | "start": "http-server public -o" 9 | }, 10 | "author": "Greg Smith (http://github.com/smrq)", 11 | "license": "MIT", 12 | "private": true, 13 | "devDependencies": { 14 | "browserify": "^12.0.1", 15 | "http-server": "^0.8.5", 16 | "tsify": "*", 17 | "typescript": "~1.8.7" 18 | }, 19 | "dependencies": { 20 | "react": "^0.14.3", 21 | "react-dom": "^0.14.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/jsx/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JSX, TypeScript, and tsify 5 | 6 | 7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/jsx/src/Greeter.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | export interface IGreeterProps { 4 | greeting: string; 5 | } 6 | 7 | export default class Greeter extends React.Component { 8 | render() { 9 | const { greeting } = this.props; 10 | return ( 11 |

{ greeting }

12 | ); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /examples/jsx/src/main.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { render } from 'react-dom'; 3 | 4 | import Greeter from './Greeter'; 5 | 6 | render(( 7 | 8 | ), document.getElementById('app')); 9 | -------------------------------------------------------------------------------- /examples/jsx/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "jsx": "react" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/jsx/tsd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v4", 3 | "repo": "borisyankov/DefinitelyTyped", 4 | "ref": "master", 5 | "path": "typings", 6 | "bundle": "typings/tsd.d.ts", 7 | "installed": { 8 | "react/react.d.ts": { 9 | "commit": "7a3d6944036902996b87981e6150900952b35628" 10 | }, 11 | "react/react-dom.d.ts": { 12 | "commit": "7a3d6944036902996b87981e6150900952b35628" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/jsx/typings/react/react-dom.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for React v0.14 (react-dom) 2 | // Project: http://facebook.github.io/react/ 3 | // Definitions by: Asana , AssureSign , Microsoft 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /// 7 | 8 | declare namespace __React { 9 | namespace __DOM { 10 | function findDOMNode(instance: ReactInstance): E; 11 | function findDOMNode(instance: ReactInstance): Element; 12 | 13 | function render

( 14 | element: DOMElement

, 15 | container: Element, 16 | callback?: (element: Element) => any): Element; 17 | function render( 18 | element: ClassicElement

, 19 | container: Element, 20 | callback?: (component: ClassicComponent) => any): ClassicComponent; 21 | function render( 22 | element: ReactElement

, 23 | container: Element, 24 | callback?: (component: Component) => any): Component; 25 | 26 | function unmountComponentAtNode(container: Element): boolean; 27 | 28 | var version: string; 29 | 30 | function unstable_batchedUpdates(callback: (a: A, b: B) => any, a: A, b: B): void; 31 | function unstable_batchedUpdates(callback: (a: A) => any, a: A): void; 32 | function unstable_batchedUpdates(callback: () => any): void; 33 | 34 | function unstable_renderSubtreeIntoContainer

( 35 | parentComponent: Component, 36 | nextElement: DOMElement

, 37 | container: Element, 38 | callback?: (element: Element) => any): Element; 39 | function unstable_renderSubtreeIntoContainer( 40 | parentComponent: Component, 41 | nextElement: ClassicElement

, 42 | container: Element, 43 | callback?: (component: ClassicComponent) => any): ClassicComponent; 44 | function unstable_renderSubtreeIntoContainer( 45 | parentComponent: Component, 46 | nextElement: ReactElement

, 47 | container: Element, 48 | callback?: (component: Component) => any): Component; 49 | } 50 | 51 | namespace __DOMServer { 52 | function renderToString(element: ReactElement): string; 53 | function renderToStaticMarkup(element: ReactElement): string; 54 | var version: string; 55 | } 56 | } 57 | 58 | declare module "react-dom" { 59 | import DOM = __React.__DOM; 60 | export = DOM; 61 | } 62 | 63 | declare module "react-dom/server" { 64 | import DOMServer = __React.__DOMServer; 65 | export = DOMServer; 66 | } 67 | -------------------------------------------------------------------------------- /examples/jsx/typings/react/react.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for React v0.14 2 | // Project: http://facebook.github.io/react/ 3 | // Definitions by: Asana , AssureSign , Microsoft 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | declare namespace __React { 7 | // 8 | // React Elements 9 | // ---------------------------------------------------------------------- 10 | 11 | type ReactType = string | ComponentClass | StatelessComponent; 12 | 13 | interface ReactElement

> { 14 | type: string | ComponentClass

| StatelessComponent

; 15 | props: P; 16 | key: string | number; 17 | ref: string | ((component: Component | Element) => any); 18 | } 19 | 20 | interface ClassicElement

extends ReactElement

{ 21 | type: ClassicComponentClass

; 22 | ref: string | ((component: ClassicComponent) => any); 23 | } 24 | 25 | interface DOMElement

> extends ReactElement

{ 26 | type: string; 27 | ref: string | ((element: Element) => any); 28 | } 29 | 30 | interface ReactHTMLElement extends DOMElement { 31 | ref: string | ((element: HTMLElement) => any); 32 | } 33 | 34 | interface ReactSVGElement extends DOMElement { 35 | ref: string | ((element: SVGElement) => any); 36 | } 37 | 38 | // 39 | // Factories 40 | // ---------------------------------------------------------------------- 41 | 42 | interface Factory

{ 43 | (props?: P, ...children: ReactNode[]): ReactElement

; 44 | } 45 | 46 | interface ClassicFactory

extends Factory

{ 47 | (props?: P, ...children: ReactNode[]): ClassicElement

; 48 | } 49 | 50 | interface DOMFactory

> extends Factory

{ 51 | (props?: P, ...children: ReactNode[]): DOMElement

; 52 | } 53 | 54 | type HTMLFactory = DOMFactory; 55 | type SVGFactory = DOMFactory; 56 | 57 | // 58 | // React Nodes 59 | // http://facebook.github.io/react/docs/glossary.html 60 | // ---------------------------------------------------------------------- 61 | 62 | type ReactText = string | number; 63 | type ReactChild = ReactElement | ReactText; 64 | 65 | // Should be Array but type aliases cannot be recursive 66 | type ReactFragment = {} | Array; 67 | type ReactNode = ReactChild | ReactFragment | boolean; 68 | 69 | // 70 | // Top Level API 71 | // ---------------------------------------------------------------------- 72 | 73 | function createClass(spec: ComponentSpec): ClassicComponentClass

; 74 | 75 | function createFactory

(type: string): DOMFactory

; 76 | function createFactory

(type: ClassicComponentClass

): ClassicFactory

; 77 | function createFactory

(type: ComponentClass

| StatelessComponent

): Factory

; 78 | 79 | function createElement

( 80 | type: string, 81 | props?: P, 82 | ...children: ReactNode[]): DOMElement

; 83 | function createElement

( 84 | type: ClassicComponentClass

, 85 | props?: P, 86 | ...children: ReactNode[]): ClassicElement

; 87 | function createElement

( 88 | type: ComponentClass

| StatelessComponent

, 89 | props?: P, 90 | ...children: ReactNode[]): ReactElement

; 91 | 92 | function cloneElement

( 93 | element: DOMElement

, 94 | props?: P, 95 | ...children: ReactNode[]): DOMElement

; 96 | function cloneElement

( 97 | element: ClassicElement

, 98 | props?: P, 99 | ...children: ReactNode[]): ClassicElement

; 100 | function cloneElement

( 101 | element: ReactElement

, 102 | props?: P, 103 | ...children: ReactNode[]): ReactElement

; 104 | 105 | function isValidElement(object: {}): boolean; 106 | 107 | var DOM: ReactDOM; 108 | var PropTypes: ReactPropTypes; 109 | var Children: ReactChildren; 110 | 111 | // 112 | // Component API 113 | // ---------------------------------------------------------------------- 114 | 115 | type ReactInstance = Component | Element; 116 | 117 | // Base component for plain JS classes 118 | class Component implements ComponentLifecycle { 119 | constructor(props?: P, context?: any); 120 | setState(f: (prevState: S, props: P) => S, callback?: () => any): void; 121 | setState(state: S, callback?: () => any): void; 122 | forceUpdate(callBack?: () => any): void; 123 | render(): JSX.Element; 124 | props: P; 125 | state: S; 126 | context: {}; 127 | refs: { 128 | [key: string]: ReactInstance 129 | }; 130 | } 131 | 132 | interface ClassicComponent extends Component { 133 | replaceState(nextState: S, callback?: () => any): void; 134 | isMounted(): boolean; 135 | getInitialState?(): S; 136 | } 137 | 138 | interface ChildContextProvider { 139 | getChildContext(): CC; 140 | } 141 | 142 | // 143 | // Class Interfaces 144 | // ---------------------------------------------------------------------- 145 | 146 | interface StatelessComponent

{ 147 | (props?: P, context?: any): ReactElement; 148 | propTypes?: ValidationMap

; 149 | contextTypes?: ValidationMap; 150 | defaultProps?: P; 151 | } 152 | 153 | interface ComponentClass

{ 154 | new(props?: P, context?: any): Component; 155 | propTypes?: ValidationMap

; 156 | contextTypes?: ValidationMap; 157 | childContextTypes?: ValidationMap; 158 | defaultProps?: P; 159 | } 160 | 161 | interface ClassicComponentClass

extends ComponentClass

{ 162 | new(props?: P, context?: any): ClassicComponent; 163 | getDefaultProps?(): P; 164 | displayName?: string; 165 | } 166 | 167 | // 168 | // Component Specs and Lifecycle 169 | // ---------------------------------------------------------------------- 170 | 171 | interface ComponentLifecycle { 172 | componentWillMount?(): void; 173 | componentDidMount?(): void; 174 | componentWillReceiveProps?(nextProps: P, nextContext: any): void; 175 | shouldComponentUpdate?(nextProps: P, nextState: S, nextContext: any): boolean; 176 | componentWillUpdate?(nextProps: P, nextState: S, nextContext: any): void; 177 | componentDidUpdate?(prevProps: P, prevState: S, prevContext: any): void; 178 | componentWillUnmount?(): void; 179 | } 180 | 181 | interface Mixin extends ComponentLifecycle { 182 | mixins?: Mixin; 183 | statics?: { 184 | [key: string]: any; 185 | }; 186 | 187 | displayName?: string; 188 | propTypes?: ValidationMap; 189 | contextTypes?: ValidationMap; 190 | childContextTypes?: ValidationMap; 191 | 192 | getDefaultProps?(): P; 193 | getInitialState?(): S; 194 | } 195 | 196 | interface ComponentSpec extends Mixin { 197 | render(): ReactElement; 198 | 199 | [propertyName: string]: any; 200 | } 201 | 202 | // 203 | // Event System 204 | // ---------------------------------------------------------------------- 205 | 206 | interface SyntheticEvent { 207 | bubbles: boolean; 208 | cancelable: boolean; 209 | currentTarget: EventTarget; 210 | defaultPrevented: boolean; 211 | eventPhase: number; 212 | isTrusted: boolean; 213 | nativeEvent: Event; 214 | preventDefault(): void; 215 | stopPropagation(): void; 216 | target: EventTarget; 217 | timeStamp: Date; 218 | type: string; 219 | } 220 | 221 | interface ClipboardEvent extends SyntheticEvent { 222 | clipboardData: DataTransfer; 223 | } 224 | 225 | interface CompositionEvent extends SyntheticEvent { 226 | data: string; 227 | } 228 | 229 | interface DragEvent extends SyntheticEvent { 230 | dataTransfer: DataTransfer; 231 | } 232 | 233 | interface FocusEvent extends SyntheticEvent { 234 | relatedTarget: EventTarget; 235 | } 236 | 237 | interface FormEvent extends SyntheticEvent { 238 | } 239 | 240 | interface KeyboardEvent extends SyntheticEvent { 241 | altKey: boolean; 242 | charCode: number; 243 | ctrlKey: boolean; 244 | getModifierState(key: string): boolean; 245 | key: string; 246 | keyCode: number; 247 | locale: string; 248 | location: number; 249 | metaKey: boolean; 250 | repeat: boolean; 251 | shiftKey: boolean; 252 | which: number; 253 | } 254 | 255 | interface MouseEvent extends SyntheticEvent { 256 | altKey: boolean; 257 | button: number; 258 | buttons: number; 259 | clientX: number; 260 | clientY: number; 261 | ctrlKey: boolean; 262 | getModifierState(key: string): boolean; 263 | metaKey: boolean; 264 | pageX: number; 265 | pageY: number; 266 | relatedTarget: EventTarget; 267 | screenX: number; 268 | screenY: number; 269 | shiftKey: boolean; 270 | } 271 | 272 | interface TouchEvent extends SyntheticEvent { 273 | altKey: boolean; 274 | changedTouches: TouchList; 275 | ctrlKey: boolean; 276 | getModifierState(key: string): boolean; 277 | metaKey: boolean; 278 | shiftKey: boolean; 279 | targetTouches: TouchList; 280 | touches: TouchList; 281 | } 282 | 283 | interface UIEvent extends SyntheticEvent { 284 | detail: number; 285 | view: AbstractView; 286 | } 287 | 288 | interface WheelEvent extends SyntheticEvent { 289 | deltaMode: number; 290 | deltaX: number; 291 | deltaY: number; 292 | deltaZ: number; 293 | } 294 | 295 | // 296 | // Event Handler Types 297 | // ---------------------------------------------------------------------- 298 | 299 | interface EventHandler { 300 | (event: E): void; 301 | } 302 | 303 | type ReactEventHandler = EventHandler; 304 | 305 | type ClipboardEventHandler = EventHandler; 306 | type CompositionEventHandler = EventHandler; 307 | type DragEventHandler = EventHandler; 308 | type FocusEventHandler = EventHandler; 309 | type FormEventHandler = EventHandler; 310 | type KeyboardEventHandler = EventHandler; 311 | type MouseEventHandler = EventHandler; 312 | type TouchEventHandler = EventHandler; 313 | type UIEventHandler = EventHandler; 314 | type WheelEventHandler = EventHandler; 315 | 316 | // 317 | // Props / DOM Attributes 318 | // ---------------------------------------------------------------------- 319 | 320 | interface Props { 321 | children?: ReactNode; 322 | key?: string | number; 323 | ref?: string | ((component: T) => any); 324 | } 325 | 326 | interface HTMLProps extends HTMLAttributes, Props { 327 | } 328 | 329 | interface SVGProps extends SVGAttributes, Props { 330 | } 331 | 332 | interface DOMAttributes { 333 | dangerouslySetInnerHTML?: { 334 | __html: string; 335 | }; 336 | 337 | // Clipboard Events 338 | onCopy?: ClipboardEventHandler; 339 | onCut?: ClipboardEventHandler; 340 | onPaste?: ClipboardEventHandler; 341 | 342 | // Composition Events 343 | onCompositionEnd?: CompositionEventHandler; 344 | onCompositionStart?: CompositionEventHandler; 345 | onCompositionUpdate?: CompositionEventHandler; 346 | 347 | // Focus Events 348 | onFocus?: FocusEventHandler; 349 | onBlur?: FocusEventHandler; 350 | 351 | // Form Events 352 | onChange?: FormEventHandler; 353 | onInput?: FormEventHandler; 354 | onSubmit?: FormEventHandler; 355 | 356 | // Image Events 357 | onLoad?: ReactEventHandler; 358 | onError?: ReactEventHandler; // also a Media Event 359 | 360 | // Keyboard Events 361 | onKeyDown?: KeyboardEventHandler; 362 | onKeyPress?: KeyboardEventHandler; 363 | onKeyUp?: KeyboardEventHandler; 364 | 365 | // Media Events 366 | onAbort?: ReactEventHandler; 367 | onCanPlay?: ReactEventHandler; 368 | onCanPlayThrough?: ReactEventHandler; 369 | onDurationChange?: ReactEventHandler; 370 | onEmptied?: ReactEventHandler; 371 | onEncrypted?: ReactEventHandler; 372 | onEnded?: ReactEventHandler; 373 | onLoadedData?: ReactEventHandler; 374 | onLoadedMetadata?: ReactEventHandler; 375 | onLoadStart?: ReactEventHandler; 376 | onPause?: ReactEventHandler; 377 | onPlay?: ReactEventHandler; 378 | onPlaying?: ReactEventHandler; 379 | onProgress?: ReactEventHandler; 380 | onRateChange?: ReactEventHandler; 381 | onSeeked?: ReactEventHandler; 382 | onSeeking?: ReactEventHandler; 383 | onStalled?: ReactEventHandler; 384 | onSuspend?: ReactEventHandler; 385 | onTimeUpdate?: ReactEventHandler; 386 | onVolumeChange?: ReactEventHandler; 387 | onWaiting?: ReactEventHandler; 388 | 389 | // MouseEvents 390 | onClick?: MouseEventHandler; 391 | onContextMenu?: MouseEventHandler; 392 | onDoubleClick?: MouseEventHandler; 393 | onDrag?: DragEventHandler; 394 | onDragEnd?: DragEventHandler; 395 | onDragEnter?: DragEventHandler; 396 | onDragExit?: DragEventHandler; 397 | onDragLeave?: DragEventHandler; 398 | onDragOver?: DragEventHandler; 399 | onDragStart?: DragEventHandler; 400 | onDrop?: DragEventHandler; 401 | onMouseDown?: MouseEventHandler; 402 | onMouseEnter?: MouseEventHandler; 403 | onMouseLeave?: MouseEventHandler; 404 | onMouseMove?: MouseEventHandler; 405 | onMouseOut?: MouseEventHandler; 406 | onMouseOver?: MouseEventHandler; 407 | onMouseUp?: MouseEventHandler; 408 | 409 | // Selection Events 410 | onSelect?: ReactEventHandler; 411 | 412 | // Touch Events 413 | onTouchCancel?: TouchEventHandler; 414 | onTouchEnd?: TouchEventHandler; 415 | onTouchMove?: TouchEventHandler; 416 | onTouchStart?: TouchEventHandler; 417 | 418 | // UI Events 419 | onScroll?: UIEventHandler; 420 | 421 | // Wheel Events 422 | onWheel?: WheelEventHandler; 423 | } 424 | 425 | // This interface is not complete. Only properties accepting 426 | // unitless numbers are listed here (see CSSProperty.js in React) 427 | interface CSSProperties { 428 | boxFlex?: number; 429 | boxFlexGroup?: number; 430 | columnCount?: number; 431 | flex?: number | string; 432 | flexGrow?: number; 433 | flexShrink?: number; 434 | fontWeight?: number | string; 435 | lineClamp?: number; 436 | lineHeight?: number | string; 437 | opacity?: number; 438 | order?: number; 439 | orphans?: number; 440 | widows?: number; 441 | zIndex?: number; 442 | zoom?: number; 443 | 444 | fontSize?: number | string; 445 | 446 | // SVG-related properties 447 | fillOpacity?: number; 448 | strokeOpacity?: number; 449 | strokeWidth?: number; 450 | 451 | // Remaining properties auto-extracted from http://docs.webplatform.org. 452 | // License: http://docs.webplatform.org/wiki/Template:CC-by-3.0 453 | /** 454 | * Aligns a flex container's lines within the flex container when there is extra space in the cross-axis, similar to how justify-content aligns individual items within the main-axis. 455 | */ 456 | alignContent?: any; 457 | 458 | /** 459 | * Sets the default alignment in the cross axis for all of the flex container's items, including anonymous flex items, similarly to how justify-content aligns items along the main axis. 460 | */ 461 | alignItems?: any; 462 | 463 | /** 464 | * Allows the default alignment to be overridden for individual flex items. 465 | */ 466 | alignSelf?: any; 467 | 468 | /** 469 | * This property allows precise alignment of elements, such as graphics, that do not have a baseline-table or lack the desired baseline in their baseline-table. With the alignment-adjust property, the position of the baseline identified by the alignment-baseline can be explicitly determined. It also determines precisely the alignment point for each glyph within a textual element. 470 | */ 471 | alignmentAdjust?: any; 472 | 473 | alignmentBaseline?: any; 474 | 475 | /** 476 | * Defines a length of time to elapse before an animation starts, allowing an animation to begin execution some time after it is applied. 477 | */ 478 | animationDelay?: any; 479 | 480 | /** 481 | * Defines whether an animation should run in reverse on some or all cycles. 482 | */ 483 | animationDirection?: any; 484 | 485 | /** 486 | * Specifies how many times an animation cycle should play. 487 | */ 488 | animationIterationCount?: any; 489 | 490 | /** 491 | * Defines the list of animations that apply to the element. 492 | */ 493 | animationName?: any; 494 | 495 | /** 496 | * Defines whether an animation is running or paused. 497 | */ 498 | animationPlayState?: any; 499 | 500 | /** 501 | * Allows changing the style of any element to platform-based interface elements or vice versa. 502 | */ 503 | appearance?: any; 504 | 505 | /** 506 | * Determines whether or not the “back” side of a transformed element is visible when facing the viewer. 507 | */ 508 | backfaceVisibility?: any; 509 | 510 | /** 511 | * This property describes how the element's background images should blend with each other and the element's background color. 512 | * The value is a list of blend modes that corresponds to each background image. Each element in the list will apply to the corresponding element of background-image. If a property doesn’t have enough comma-separated values to match the number of layers, the UA must calculate its used value by repeating the list of values until there are enough. 513 | */ 514 | backgroundBlendMode?: any; 515 | 516 | backgroundComposite?: any; 517 | 518 | /** 519 | * Applies one or more background images to an element. These can be any valid CSS image, including url() paths to image files or CSS gradients. 520 | */ 521 | backgroundImage?: any; 522 | 523 | /** 524 | * Specifies what the background-position property is relative to. 525 | */ 526 | backgroundOrigin?: any; 527 | 528 | /** 529 | * Sets the horizontal position of a background image. 530 | */ 531 | backgroundPositionX?: any; 532 | 533 | /** 534 | * Background-repeat defines if and how background images will be repeated after they have been sized and positioned 535 | */ 536 | backgroundRepeat?: any; 537 | 538 | /** 539 | * Obsolete - spec retired, not implemented. 540 | */ 541 | baselineShift?: any; 542 | 543 | /** 544 | * Non standard. Sets or retrieves the location of the Dynamic HTML (DHTML) behavior. 545 | */ 546 | behavior?: any; 547 | 548 | /** 549 | * Shorthand property that defines the different properties of all four sides of an element's border in a single declaration. It can be used to set border-width, border-style and border-color, or a subset of these. 550 | */ 551 | border?: any; 552 | 553 | /** 554 | * Defines the shape of the border of the bottom-left corner. 555 | */ 556 | borderBottomLeftRadius?: any; 557 | 558 | /** 559 | * Defines the shape of the border of the bottom-right corner. 560 | */ 561 | borderBottomRightRadius?: any; 562 | 563 | /** 564 | * Sets the width of an element's bottom border. To set all four borders, use the border-width shorthand property which sets the values simultaneously for border-top-width, border-right-width, border-bottom-width, and border-left-width. 565 | */ 566 | borderBottomWidth?: any; 567 | 568 | /** 569 | * Border-collapse can be used for collapsing the borders between table cells 570 | */ 571 | borderCollapse?: any; 572 | 573 | /** 574 | * The CSS border-color property sets the color of an element's four borders. This property can have from one to four values, made up of the elementary properties: • border-top-color 575 | * • border-right-color 576 | * • border-bottom-color 577 | * • border-left-color The default color is the currentColor of each of these values. 578 | * If you provide one value, it sets the color for the element. Two values set the horizontal and vertical values, respectively. Providing three values sets the top, vertical, and bottom values, in that order. Four values set all for sides: top, right, bottom, and left, in that order. 579 | */ 580 | borderColor?: any; 581 | 582 | /** 583 | * Specifies different corner clipping effects, such as scoop (inner curves), bevel (straight cuts) or notch (cut-off rectangles). Works along with border-radius to specify the size of each corner effect. 584 | */ 585 | borderCornerShape?: any; 586 | 587 | /** 588 | * The property border-image-source is used to set the image to be used instead of the border style. If this is set to none the border-style is used instead. 589 | */ 590 | borderImageSource?: any; 591 | 592 | /** 593 | * The border-image-width CSS property defines the offset to use for dividing the border image in nine parts, the top-left corner, central top edge, top-right-corner, central right edge, bottom-right corner, central bottom edge, bottom-left corner, and central right edge. They represent inward distance from the top, right, bottom, and left edges. 594 | */ 595 | borderImageWidth?: any; 596 | 597 | /** 598 | * Shorthand property that defines the border-width, border-style and border-color of an element's left border in a single declaration. Note that you can use the corresponding longhand properties to set specific individual properties of the left border — border-left-width, border-left-style and border-left-color. 599 | */ 600 | borderLeft?: any; 601 | 602 | /** 603 | * The CSS border-left-color property sets the color of an element's left border. This page explains the border-left-color value, but often you will find it more convenient to fix the border's left color as part of a shorthand set, either border-left or border-color. 604 | * Colors can be defined several ways. For more information, see Usage. 605 | */ 606 | borderLeftColor?: any; 607 | 608 | /** 609 | * Sets the style of an element's left border. To set all four borders, use the shorthand property, border-style. Otherwise, you can set the borders individually with border-top-style, border-right-style, border-bottom-style, border-left-style. 610 | */ 611 | borderLeftStyle?: any; 612 | 613 | /** 614 | * Sets the width of an element's left border. To set all four borders, use the border-width shorthand property which sets the values simultaneously for border-top-width, border-right-width, border-bottom-width, and border-left-width. 615 | */ 616 | borderLeftWidth?: any; 617 | 618 | /** 619 | * Shorthand property that defines the border-width, border-style and border-color of an element's right border in a single declaration. Note that you can use the corresponding longhand properties to set specific individual properties of the right border — border-right-width, border-right-style and border-right-color. 620 | */ 621 | borderRight?: any; 622 | 623 | /** 624 | * Sets the color of an element's right border. This page explains the border-right-color value, but often you will find it more convenient to fix the border's right color as part of a shorthand set, either border-right or border-color. 625 | * Colors can be defined several ways. For more information, see Usage. 626 | */ 627 | borderRightColor?: any; 628 | 629 | /** 630 | * Sets the style of an element's right border. To set all four borders, use the shorthand property, border-style. Otherwise, you can set the borders individually with border-top-style, border-right-style, border-bottom-style, border-left-style. 631 | */ 632 | borderRightStyle?: any; 633 | 634 | /** 635 | * Sets the width of an element's right border. To set all four borders, use the border-width shorthand property which sets the values simultaneously for border-top-width, border-right-width, border-bottom-width, and border-left-width. 636 | */ 637 | borderRightWidth?: any; 638 | 639 | /** 640 | * Specifies the distance between the borders of adjacent cells. 641 | */ 642 | borderSpacing?: any; 643 | 644 | /** 645 | * Sets the style of an element's four borders. This property can have from one to four values. With only one value, the value will be applied to all four borders; otherwise, this works as a shorthand property for each of border-top-style, border-right-style, border-bottom-style, border-left-style, where each border style may be assigned a separate value. 646 | */ 647 | borderStyle?: any; 648 | 649 | /** 650 | * Shorthand property that defines the border-width, border-style and border-color of an element's top border in a single declaration. Note that you can use the corresponding longhand properties to set specific individual properties of the top border — border-top-width, border-top-style and border-top-color. 651 | */ 652 | borderTop?: any; 653 | 654 | /** 655 | * Sets the color of an element's top border. This page explains the border-top-color value, but often you will find it more convenient to fix the border's top color as part of a shorthand set, either border-top or border-color. 656 | * Colors can be defined several ways. For more information, see Usage. 657 | */ 658 | borderTopColor?: any; 659 | 660 | /** 661 | * Sets the rounding of the top-left corner of the element. 662 | */ 663 | borderTopLeftRadius?: any; 664 | 665 | /** 666 | * Sets the rounding of the top-right corner of the element. 667 | */ 668 | borderTopRightRadius?: any; 669 | 670 | /** 671 | * Sets the style of an element's top border. To set all four borders, use the shorthand property, border-style. Otherwise, you can set the borders individually with border-top-style, border-right-style, border-bottom-style, border-left-style. 672 | */ 673 | borderTopStyle?: any; 674 | 675 | /** 676 | * Sets the width of an element's top border. To set all four borders, use the border-width shorthand property which sets the values simultaneously for border-top-width, border-right-width, border-bottom-width, and border-left-width. 677 | */ 678 | borderTopWidth?: any; 679 | 680 | /** 681 | * Sets the width of an element's four borders. This property can have from one to four values. This is a shorthand property for setting values simultaneously for border-top-width, border-right-width, border-bottom-width, and border-left-width. 682 | */ 683 | borderWidth?: any; 684 | 685 | /** 686 | * Obsolete. 687 | */ 688 | boxAlign?: any; 689 | 690 | /** 691 | * Breaks a box into fragments creating new borders, padding and repeating backgrounds or lets it stay as a continuous box on a page break, column break, or, for inline elements, at a line break. 692 | */ 693 | boxDecorationBreak?: any; 694 | 695 | /** 696 | * Deprecated 697 | */ 698 | boxDirection?: any; 699 | 700 | /** 701 | * Do not use. This property has been replaced by the flex-wrap property. 702 | * Gets or sets a value that specifies the direction to add successive rows or columns when the value of box-lines is set to multiple. 703 | */ 704 | boxLineProgression?: any; 705 | 706 | /** 707 | * Do not use. This property has been replaced by the flex-wrap property. 708 | * Gets or sets a value that specifies whether child elements wrap onto multiple lines or columns based on the space available in the object. 709 | */ 710 | boxLines?: any; 711 | 712 | /** 713 | * Do not use. This property has been replaced by flex-order. 714 | * Specifies the ordinal group that a child element of the object belongs to. This ordinal value identifies the display order (along the axis defined by the box-orient property) for the group. 715 | */ 716 | boxOrdinalGroup?: any; 717 | 718 | /** 719 | * The CSS break-after property allows you to force a break on multi-column layouts. More specifically, it allows you to force a break after an element. It allows you to determine if a break should occur, and what type of break it should be. The break-after CSS property describes how the page, column or region break behaves after the generated box. If there is no generated box, the property is ignored. 720 | */ 721 | breakAfter?: any; 722 | 723 | /** 724 | * Control page/column/region breaks that fall above a block of content 725 | */ 726 | breakBefore?: any; 727 | 728 | /** 729 | * Control page/column/region breaks that fall within a block of content 730 | */ 731 | breakInside?: any; 732 | 733 | /** 734 | * The clear CSS property specifies if an element can be positioned next to or must be positioned below the floating elements that precede it in the markup. 735 | */ 736 | clear?: any; 737 | 738 | /** 739 | * Deprecated; see clip-path. 740 | * Lets you specify the dimensions of an absolutely positioned element that should be visible, and the element is clipped into this shape, and displayed. 741 | */ 742 | clip?: any; 743 | 744 | /** 745 | * Clipping crops an graphic, so that only a portion of the graphic is rendered, or filled. This clip-rule property, when used with the clip-path property, defines which clip rule, or algorithm, to use when filling the different parts of a graphics. 746 | */ 747 | clipRule?: any; 748 | 749 | /** 750 | * The color property sets the color of an element's foreground content (usually text), accepting any standard CSS color from keywords and hex values to RGB(a) and HSL(a). 751 | */ 752 | color?: any; 753 | 754 | /** 755 | * Specifies how to fill columns (balanced or sequential). 756 | */ 757 | columnFill?: any; 758 | 759 | /** 760 | * The column-gap property controls the width of the gap between columns in multi-column elements. 761 | */ 762 | columnGap?: any; 763 | 764 | /** 765 | * Sets the width, style, and color of the rule between columns. 766 | */ 767 | columnRule?: any; 768 | 769 | /** 770 | * Specifies the color of the rule between columns. 771 | */ 772 | columnRuleColor?: any; 773 | 774 | /** 775 | * Specifies the width of the rule between columns. 776 | */ 777 | columnRuleWidth?: any; 778 | 779 | /** 780 | * The column-span CSS property makes it possible for an element to span across all columns when its value is set to all. An element that spans more than one column is called a spanning element. 781 | */ 782 | columnSpan?: any; 783 | 784 | /** 785 | * Specifies the width of columns in multi-column elements. 786 | */ 787 | columnWidth?: any; 788 | 789 | /** 790 | * This property is a shorthand property for setting column-width and/or column-count. 791 | */ 792 | columns?: any; 793 | 794 | /** 795 | * The counter-increment property accepts one or more names of counters (identifiers), each one optionally followed by an integer which specifies the value by which the counter should be incremented (e.g. if the value is 2, the counter increases by 2 each time it is invoked). 796 | */ 797 | counterIncrement?: any; 798 | 799 | /** 800 | * The counter-reset property contains a list of one or more names of counters, each one optionally followed by an integer (otherwise, the integer defaults to 0.) Each time the given element is invoked, the counters specified by the property are set to the given integer. 801 | */ 802 | counterReset?: any; 803 | 804 | /** 805 | * The cue property specifies sound files (known as an "auditory icon") to be played by speech media agents before and after presenting an element's content; if only one file is specified, it is played both before and after. The volume at which the file(s) should be played, relative to the volume of the main element, may also be specified. The icon files may also be set separately with the cue-before and cue-after properties. 806 | */ 807 | cue?: any; 808 | 809 | /** 810 | * The cue-after property specifies a sound file (known as an "auditory icon") to be played by speech media agents after presenting an element's content; the volume at which the file should be played may also be specified. The shorthand property cue sets cue sounds for both before and after the element is presented. 811 | */ 812 | cueAfter?: any; 813 | 814 | /** 815 | * The direction CSS property specifies the text direction/writing direction. The rtl is used for Hebrew or Arabic text, the ltr is for other languages. 816 | */ 817 | direction?: any; 818 | 819 | /** 820 | * This property specifies the type of rendering box used for an element. It is a shorthand property for many other display properties. 821 | */ 822 | display?: any; 823 | 824 | /** 825 | * The ‘fill’ property paints the interior of the given graphical element. The area to be painted consists of any areas inside the outline of the shape. To determine the inside of the shape, all subpaths are considered, and the interior is determined according to the rules associated with the current value of the ‘fill-rule’ property. The zero-width geometric outline of a shape is included in the area to be painted. 826 | */ 827 | fill?: any; 828 | 829 | /** 830 | * The ‘fill-rule’ property indicates the algorithm which is to be used to determine what parts of the canvas are included inside the shape. For a simple, non-intersecting path, it is intuitively clear what region lies "inside"; however, for a more complex path, such as a path that intersects itself or where one subpath encloses another, the interpretation of "inside" is not so obvious. 831 | * The ‘fill-rule’ property provides two options for how the inside of a shape is determined: 832 | */ 833 | fillRule?: any; 834 | 835 | /** 836 | * Applies various image processing effects. This property is largely unsupported. See Compatibility section for more information. 837 | */ 838 | filter?: any; 839 | 840 | /** 841 | * Obsolete, do not use. This property has been renamed to align-items. 842 | * Specifies the alignment (perpendicular to the layout axis defined by the flex-direction property) of child elements of the object. 843 | */ 844 | flexAlign?: any; 845 | 846 | /** 847 | * The flex-basis CSS property describes the initial main size of the flex item before any free space is distributed according to the flex factors described in the flex property (flex-grow and flex-shrink). 848 | */ 849 | flexBasis?: any; 850 | 851 | /** 852 | * The flex-direction CSS property describes how flex items are placed in the flex container, by setting the direction of the flex container's main axis. 853 | */ 854 | flexDirection?: any; 855 | 856 | /** 857 | * The flex-flow CSS property defines the flex container's main and cross axis. It is a shorthand property for the flex-direction and flex-wrap properties. 858 | */ 859 | flexFlow?: any; 860 | 861 | /** 862 | * Do not use. This property has been renamed to align-self 863 | * Specifies the alignment (perpendicular to the layout axis defined by flex-direction) of child elements of the object. 864 | */ 865 | flexItemAlign?: any; 866 | 867 | /** 868 | * Do not use. This property has been renamed to align-content. 869 | * Specifies how a flexbox's lines align within the flexbox when there is extra space along the axis that is perpendicular to the axis defined by the flex-direction property. 870 | */ 871 | flexLinePack?: any; 872 | 873 | /** 874 | * Gets or sets a value that specifies the ordinal group that a flexbox element belongs to. This ordinal value identifies the display order for the group. 875 | */ 876 | flexOrder?: any; 877 | 878 | /** 879 | * Elements which have the style float are floated horizontally. These elements can move as far to the left or right of the containing element. All elements after the floating element will flow around it, but elements before the floating element are not impacted. If several floating elements are placed after each other, they will float next to each other as long as there is room. 880 | */ 881 | float?: any; 882 | 883 | /** 884 | * Flows content from a named flow (specified by a corresponding flow-into) through selected elements to form a dynamic chain of layout regions. 885 | */ 886 | flowFrom?: any; 887 | 888 | /** 889 | * The font property is shorthand that allows you to do one of two things: you can either set up six of the most mature font properties in one line, or you can set one of a choice of keywords to adopt a system font setting. 890 | */ 891 | font?: any; 892 | 893 | /** 894 | * The font-family property allows one or more font family names and/or generic family names to be specified for usage on the selected element(s)' text. The browser then goes through the list; for each character in the selection it applies the first font family that has an available glyph for that character. 895 | */ 896 | fontFamily?: any; 897 | 898 | /** 899 | * The font-kerning property allows contextual adjustment of inter-glyph spacing, i.e. the spaces between the characters in text. This property controls metric kerning - that utilizes adjustment data contained in the font. Optical Kerning is not supported as yet. 900 | */ 901 | fontKerning?: any; 902 | 903 | /** 904 | * The font-size-adjust property adjusts the font-size of the fallback fonts defined with font-family, so that the x-height is the same no matter what font is used. This preserves the readability of the text when fallback happens. 905 | */ 906 | fontSizeAdjust?: any; 907 | 908 | /** 909 | * Allows you to expand or condense the widths for a normal, condensed, or expanded font face. 910 | */ 911 | fontStretch?: any; 912 | 913 | /** 914 | * The font-style property allows normal, italic, or oblique faces to be selected. Italic forms are generally cursive in nature while oblique faces are typically sloped versions of the regular face. Oblique faces can be simulated by artificially sloping the glyphs of the regular face. 915 | */ 916 | fontStyle?: any; 917 | 918 | /** 919 | * This value specifies whether the user agent is allowed to synthesize bold or oblique font faces when a font family lacks bold or italic faces. 920 | */ 921 | fontSynthesis?: any; 922 | 923 | /** 924 | * The font-variant property enables you to select the small-caps font within a font family. 925 | */ 926 | fontVariant?: any; 927 | 928 | /** 929 | * Fonts can provide alternate glyphs in addition to default glyph for a character. This property provides control over the selection of these alternate glyphs. 930 | */ 931 | fontVariantAlternates?: any; 932 | 933 | /** 934 | * Lays out one or more grid items bound by 4 grid lines. Shorthand for setting grid-column-start, grid-column-end, grid-row-start, and grid-row-end in a single declaration. 935 | */ 936 | gridArea?: any; 937 | 938 | /** 939 | * Controls a grid item's placement in a grid area, particularly grid position and a grid span. Shorthand for setting grid-column-start and grid-column-end in a single declaration. 940 | */ 941 | gridColumn?: any; 942 | 943 | /** 944 | * Controls a grid item's placement in a grid area as well as grid position and a grid span. The grid-column-end property (with grid-row-start, grid-row-end, and grid-column-start) determines a grid item's placement by specifying the grid lines of a grid item's grid area. 945 | */ 946 | gridColumnEnd?: any; 947 | 948 | /** 949 | * Determines a grid item's placement by specifying the starting grid lines of a grid item's grid area . A grid item's placement in a grid area consists of a grid position and a grid span. See also ( grid-row-start, grid-row-end, and grid-column-end) 950 | */ 951 | gridColumnStart?: any; 952 | 953 | /** 954 | * Gets or sets a value that indicates which row an element within a Grid should appear in. Shorthand for setting grid-row-start and grid-row-end in a single declaration. 955 | */ 956 | gridRow?: any; 957 | 958 | /** 959 | * Determines a grid item’s placement by specifying the block-end. A grid item's placement in a grid area consists of a grid position and a grid span. The grid-row-end property (with grid-row-start, grid-column-start, and grid-column-end) determines a grid item's placement by specifying the grid lines of a grid item's grid area. 960 | */ 961 | gridRowEnd?: any; 962 | 963 | /** 964 | * Specifies a row position based upon an integer location, string value, or desired row size. 965 | * css/properties/grid-row is used as short-hand for grid-row-position and grid-row-position 966 | */ 967 | gridRowPosition?: any; 968 | 969 | gridRowSpan?: any; 970 | 971 | /** 972 | * Specifies named grid areas which are not associated with any particular grid item, but can be referenced from the grid-placement properties. The syntax of the grid-template-areas property also provides a visualization of the structure of the grid, making the overall layout of the grid container easier to understand. 973 | */ 974 | gridTemplateAreas?: any; 975 | 976 | /** 977 | * Specifies (with grid-template-rows) the line names and track sizing functions of the grid. Each sizing function can be specified as a length, a percentage of the grid container’s size, a measurement of the contents occupying the column or row, or a fraction of the free space in the grid. 978 | */ 979 | gridTemplateColumns?: any; 980 | 981 | /** 982 | * Specifies (with grid-template-columns) the line names and track sizing functions of the grid. Each sizing function can be specified as a length, a percentage of the grid container’s size, a measurement of the contents occupying the column or row, or a fraction of the free space in the grid. 983 | */ 984 | gridTemplateRows?: any; 985 | 986 | /** 987 | * Sets the height of an element. The content area of the element height does not include the padding, border, and margin of the element. 988 | */ 989 | height?: any; 990 | 991 | /** 992 | * Specifies the minimum number of characters in a hyphenated word 993 | */ 994 | hyphenateLimitChars?: any; 995 | 996 | /** 997 | * Indicates the maximum number of successive hyphenated lines in an element. The ‘no-limit’ value means that there is no limit. 998 | */ 999 | hyphenateLimitLines?: any; 1000 | 1001 | /** 1002 | * Specifies the maximum amount of trailing whitespace (before justification) that may be left in a line before hyphenation is triggered to pull part of a word from the next line back up into the current one. 1003 | */ 1004 | hyphenateLimitZone?: any; 1005 | 1006 | /** 1007 | * Specifies whether or not words in a sentence can be split by the use of a manual or automatic hyphenation mechanism. 1008 | */ 1009 | hyphens?: any; 1010 | 1011 | imeMode?: any; 1012 | 1013 | layoutGrid?: any; 1014 | 1015 | layoutGridChar?: any; 1016 | 1017 | layoutGridLine?: any; 1018 | 1019 | layoutGridMode?: any; 1020 | 1021 | layoutGridType?: any; 1022 | 1023 | /** 1024 | * Sets the left edge of an element 1025 | */ 1026 | left?: any; 1027 | 1028 | /** 1029 | * The letter-spacing CSS property specifies the spacing behavior between text characters. 1030 | */ 1031 | letterSpacing?: any; 1032 | 1033 | /** 1034 | * Deprecated. Gets or sets line-breaking rules for text in selected languages such as Japanese, Chinese, and Korean. 1035 | */ 1036 | lineBreak?: any; 1037 | 1038 | /** 1039 | * Shorthand property that sets the list-style-type, list-style-position and list-style-image properties in one declaration. 1040 | */ 1041 | listStyle?: any; 1042 | 1043 | /** 1044 | * This property sets the image that will be used as the list item marker. When the image is available, it will replace the marker set with the 'list-style-type' marker. That also means that if the image is not available, it will show the style specified by list-style-property 1045 | */ 1046 | listStyleImage?: any; 1047 | 1048 | /** 1049 | * Specifies if the list-item markers should appear inside or outside the content flow. 1050 | */ 1051 | listStylePosition?: any; 1052 | 1053 | /** 1054 | * Specifies the type of list-item marker in a list. 1055 | */ 1056 | listStyleType?: any; 1057 | 1058 | /** 1059 | * The margin property is shorthand to allow you to set all four margins of an element at once. Its equivalent longhand properties are margin-top, margin-right, margin-bottom and margin-left. Negative values are also allowed. 1060 | */ 1061 | margin?: any; 1062 | 1063 | /** 1064 | * margin-bottom sets the bottom margin of an element. 1065 | */ 1066 | marginBottom?: any; 1067 | 1068 | /** 1069 | * margin-left sets the left margin of an element. 1070 | */ 1071 | marginLeft?: any; 1072 | 1073 | /** 1074 | * margin-right sets the right margin of an element. 1075 | */ 1076 | marginRight?: any; 1077 | 1078 | /** 1079 | * margin-top sets the top margin of an element. 1080 | */ 1081 | marginTop?: any; 1082 | 1083 | /** 1084 | * The marquee-direction determines the initial direction in which the marquee content moves. 1085 | */ 1086 | marqueeDirection?: any; 1087 | 1088 | /** 1089 | * The 'marquee-style' property determines a marquee's scrolling behavior. 1090 | */ 1091 | marqueeStyle?: any; 1092 | 1093 | /** 1094 | * This property is shorthand for setting mask-image, mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-composite and mask-size. Omitted values are set to their original properties' initial values. 1095 | */ 1096 | mask?: any; 1097 | 1098 | /** 1099 | * This property is shorthand for setting mask-border-source, mask-border-slice, mask-border-width, mask-border-outset, and mask-border-repeat. Omitted values are set to their original properties' initial values. 1100 | */ 1101 | maskBorder?: any; 1102 | 1103 | /** 1104 | * This property specifies how the images for the sides and the middle part of the mask image are scaled and tiled. The first keyword applies to the horizontal sides, the second one applies to the vertical ones. If the second keyword is absent, it is assumed to be the same as the first, similar to the CSS border-image-repeat property. 1105 | */ 1106 | maskBorderRepeat?: any; 1107 | 1108 | /** 1109 | * This property specifies inward offsets from the top, right, bottom, and left edges of the mask image, dividing it into nine regions: four corners, four edges, and a middle. The middle image part is discarded and treated as fully transparent black unless the fill keyword is present. The four values set the top, right, bottom and left offsets in that order, similar to the CSS border-image-slice property. 1110 | */ 1111 | maskBorderSlice?: any; 1112 | 1113 | /** 1114 | * Specifies an image to be used as a mask. An image that is empty, fails to download, is non-existent, or cannot be displayed is ignored and does not mask the element. 1115 | */ 1116 | maskBorderSource?: any; 1117 | 1118 | /** 1119 | * This property sets the width of the mask box image, similar to the CSS border-image-width property. 1120 | */ 1121 | maskBorderWidth?: any; 1122 | 1123 | /** 1124 | * Determines the mask painting area, which defines the area that is affected by the mask. The painted content of an element may be restricted to this area. 1125 | */ 1126 | maskClip?: any; 1127 | 1128 | /** 1129 | * For elements rendered as a single box, specifies the mask positioning area. For elements rendered as multiple boxes (e.g., inline boxes on several lines, boxes on several pages) specifies which boxes box-decoration-break operates on to determine the mask positioning area(s). 1130 | */ 1131 | maskOrigin?: any; 1132 | 1133 | /** 1134 | * This property must not be used. It is no longer included in any standard or standard track specification, nor is it implemented in any browser. It is only used when the text-align-last property is set to size. It controls allowed adjustments of font-size to fit line content. 1135 | */ 1136 | maxFontSize?: any; 1137 | 1138 | /** 1139 | * Sets the maximum height for an element. It prevents the height of the element to exceed the specified value. If min-height is specified and is greater than max-height, max-height is overridden. 1140 | */ 1141 | maxHeight?: any; 1142 | 1143 | /** 1144 | * Sets the maximum width for an element. It limits the width property to be larger than the value specified in max-width. 1145 | */ 1146 | maxWidth?: any; 1147 | 1148 | /** 1149 | * Sets the minimum width of an element. It limits the width property to be not smaller than the value specified in min-width. 1150 | */ 1151 | minWidth?: any; 1152 | 1153 | /** 1154 | * The CSS outline property is a shorthand property for setting one or more of the individual outline properties outline-style, outline-width and outline-color in a single rule. In most cases the use of this shortcut is preferable and more convenient. 1155 | * Outlines differ from borders in the following ways: • Outlines do not take up space, they are drawn above the content. 1156 | * • Outlines may be non-rectangular. They are rectangular in Gecko/Firefox. Internet Explorer attempts to place the smallest contiguous outline around all elements or shapes that are indicated to have an outline. Opera draws a non-rectangular shape around a construct. 1157 | */ 1158 | outline?: any; 1159 | 1160 | /** 1161 | * The outline-color property sets the color of the outline of an element. An outline is a line that is drawn around elements, outside the border edge, to make the element stand out. 1162 | */ 1163 | outlineColor?: any; 1164 | 1165 | /** 1166 | * The outline-offset property offsets the outline and draw it beyond the border edge. 1167 | */ 1168 | outlineOffset?: any; 1169 | 1170 | /** 1171 | * The overflow property controls how extra content exceeding the bounding box of an element is rendered. It can be used in conjunction with an element that has a fixed width and height, to eliminate text-induced page distortion. 1172 | */ 1173 | overflow?: any; 1174 | 1175 | /** 1176 | * Specifies the preferred scrolling methods for elements that overflow. 1177 | */ 1178 | overflowStyle?: any; 1179 | 1180 | /** 1181 | * The overflow-x property is a specific case of the generic overflow property. It controls how extra content exceeding the x-axis of the bounding box of an element is rendered. 1182 | */ 1183 | overflowX?: any; 1184 | 1185 | /** 1186 | * The padding optional CSS property sets the required padding space on one to four sides of an element. The padding area is the space between an element and its border. Negative values are not allowed but decimal values are permitted. The element size is treated as fixed, and the content of the element shifts toward the center as padding is increased. 1187 | * The padding property is a shorthand to avoid setting each side separately (padding-top, padding-right, padding-bottom, padding-left). 1188 | */ 1189 | padding?: any; 1190 | 1191 | /** 1192 | * The padding-bottom CSS property of an element sets the padding space required on the bottom of an element. The padding area is the space between the content of the element and its border. Contrary to margin-bottom values, negative values of padding-bottom are invalid. 1193 | */ 1194 | paddingBottom?: any; 1195 | 1196 | /** 1197 | * The padding-left CSS property of an element sets the padding space required on the left side of an element. The padding area is the space between the content of the element and its border. Contrary to margin-left values, negative values of padding-left are invalid. 1198 | */ 1199 | paddingLeft?: any; 1200 | 1201 | /** 1202 | * The padding-right CSS property of an element sets the padding space required on the right side of an element. The padding area is the space between the content of the element and its border. Contrary to margin-right values, negative values of padding-right are invalid. 1203 | */ 1204 | paddingRight?: any; 1205 | 1206 | /** 1207 | * The padding-top CSS property of an element sets the padding space required on the top of an element. The padding area is the space between the content of the element and its border. Contrary to margin-top values, negative values of padding-top are invalid. 1208 | */ 1209 | paddingTop?: any; 1210 | 1211 | /** 1212 | * The page-break-after property is supported in all major browsers. With CSS3, page-break-* properties are only aliases of the break-* properties. The CSS3 Fragmentation spec defines breaks for all CSS box fragmentation. 1213 | */ 1214 | pageBreakAfter?: any; 1215 | 1216 | /** 1217 | * The page-break-before property sets the page-breaking behavior before an element. With CSS3, page-break-* properties are only aliases of the break-* properties. The CSS3 Fragmentation spec defines breaks for all CSS box fragmentation. 1218 | */ 1219 | pageBreakBefore?: any; 1220 | 1221 | /** 1222 | * Sets the page-breaking behavior inside an element. With CSS3, page-break-* properties are only aliases of the break-* properties. The CSS3 Fragmentation spec defines breaks for all CSS box fragmentation. 1223 | */ 1224 | pageBreakInside?: any; 1225 | 1226 | /** 1227 | * The pause property determines how long a speech media agent should pause before and after presenting an element. It is a shorthand for the pause-before and pause-after properties. 1228 | */ 1229 | pause?: any; 1230 | 1231 | /** 1232 | * The pause-after property determines how long a speech media agent should pause after presenting an element. It may be replaced by the shorthand property pause, which sets pause time before and after. 1233 | */ 1234 | pauseAfter?: any; 1235 | 1236 | /** 1237 | * The pause-before property determines how long a speech media agent should pause before presenting an element. It may be replaced by the shorthand property pause, which sets pause time before and after. 1238 | */ 1239 | pauseBefore?: any; 1240 | 1241 | /** 1242 | * The perspective property defines how far an element is placed from the view on the z-axis, from the screen to the viewer. 1243 | * Perspective defines how an object is viewed. In graphic arts, perspective is the representation on a flat surface of what the viewer's eye would see in a 3D space. (See Wikipedia for more information about graphical perspective and for related illustrations.) 1244 | * The illusion of perspective on a flat surface, such as a computer screen, is created by projecting points on the flat surface as they would appear if the flat surface were a window through which the viewer was looking at the object. In discussion of virtual environments, this flat surface is called a projection plane. 1245 | */ 1246 | perspective?: any; 1247 | 1248 | /** 1249 | * The perspective-origin property establishes the origin for the perspective property. It effectively sets the X and Y position at which the viewer appears to be looking at the children of the element. 1250 | * When used with perspective, perspective-origin changes the appearance of an object, as if a viewer were looking at it from a different origin. An object appears differently if a viewer is looking directly at it versus looking at it from below, above, or from the side. Thus, the perspective-origin is like a vanishing point. 1251 | * The default value of perspective-origin is 50% 50%. This displays an object as if the viewer's eye were positioned directly at the center of the screen, both top-to-bottom and left-to-right. A value of 0% 0% changes the object as if the viewer was looking toward the top left angle. A value of 100% 100% changes the appearance as if viewed toward the bottom right angle. 1252 | */ 1253 | perspectiveOrigin?: any; 1254 | 1255 | /** 1256 | * The pointer-events property allows you to control whether an element can be the target for the pointing device (e.g, mouse, pen) events. 1257 | */ 1258 | pointerEvents?: any; 1259 | 1260 | /** 1261 | * The position property controls the type of positioning used by an element within its parent elements. The effect of the position property depends on a lot of factors, for example the position property of parent elements. 1262 | */ 1263 | position?: any; 1264 | 1265 | /** 1266 | * Obsolete: unsupported. 1267 | * This property determines whether or not a full-width punctuation mark character should be trimmed if it appears at the beginning of a line, so that its "ink" lines up with the first glyph in the line above and below. 1268 | */ 1269 | punctuationTrim?: any; 1270 | 1271 | /** 1272 | * Sets the type of quotation marks for embedded quotations. 1273 | */ 1274 | quotes?: any; 1275 | 1276 | /** 1277 | * Controls whether the last region in a chain displays additional 'overset' content according its default overflow property, or if it displays a fragment of content as if it were flowing into a subsequent region. 1278 | */ 1279 | regionFragment?: any; 1280 | 1281 | /** 1282 | * The rest-after property determines how long a speech media agent should pause after presenting an element's main content, before presenting that element's exit cue sound. It may be replaced by the shorthand property rest, which sets rest time before and after. 1283 | */ 1284 | restAfter?: any; 1285 | 1286 | /** 1287 | * The rest-before property determines how long a speech media agent should pause after presenting an intro cue sound for an element, before presenting that element's main content. It may be replaced by the shorthand property rest, which sets rest time before and after. 1288 | */ 1289 | restBefore?: any; 1290 | 1291 | /** 1292 | * Specifies the position an element in relation to the right side of the containing element. 1293 | */ 1294 | right?: any; 1295 | 1296 | rubyAlign?: any; 1297 | 1298 | rubyPosition?: any; 1299 | 1300 | /** 1301 | * Defines the alpha channel threshold used to extract a shape from an image. Can be thought of as a "minimum opacity" threshold; that is, a value of 0.5 means that the shape will enclose all the pixels that are more than 50% opaque. 1302 | */ 1303 | shapeImageThreshold?: any; 1304 | 1305 | /** 1306 | * A future level of CSS Shapes will define a shape-inside property, which will define a shape to wrap content within the element. See Editor's Draft and CSSWG wiki page on next-level plans 1307 | */ 1308 | shapeInside?: any; 1309 | 1310 | /** 1311 | * Adds a margin to a shape-outside. In effect, defines a new shape that is the smallest contour around all the points that are the shape-margin distance outward perpendicular to each point on the underlying shape. For points where a perpendicular direction is not defined (e.g., a triangle corner), takes all points on a circle centered at the point and with a radius of the shape-margin distance. This property accepts only non-negative values. 1312 | */ 1313 | shapeMargin?: any; 1314 | 1315 | /** 1316 | * Declares a shape around which text should be wrapped, with possible modifications from the shape-margin property. The shape defined by shape-outside and shape-margin changes the geometry of a float element's float area. 1317 | */ 1318 | shapeOutside?: any; 1319 | 1320 | /** 1321 | * The speak property determines whether or not a speech synthesizer will read aloud the contents of an element. 1322 | */ 1323 | speak?: any; 1324 | 1325 | /** 1326 | * The speak-as property determines how the speech synthesizer interprets the content: words as whole words or as a sequence of letters, numbers as a numerical value or a sequence of digits, punctuation as pauses in speech or named punctuation characters. 1327 | */ 1328 | speakAs?: any; 1329 | 1330 | /** 1331 | * The tab-size CSS property is used to customise the width of a tab (U+0009) character. 1332 | */ 1333 | tabSize?: any; 1334 | 1335 | /** 1336 | * The 'table-layout' property controls the algorithm used to lay out the table cells, rows, and columns. 1337 | */ 1338 | tableLayout?: any; 1339 | 1340 | /** 1341 | * The text-align CSS property describes how inline content like text is aligned in its parent block element. text-align does not control the alignment of block elements itself, only their inline content. 1342 | */ 1343 | textAlign?: any; 1344 | 1345 | /** 1346 | * The text-align-last CSS property describes how the last line of a block element or a line before line break is aligned in its parent block element. 1347 | */ 1348 | textAlignLast?: any; 1349 | 1350 | /** 1351 | * The text-decoration CSS property is used to set the text formatting to underline, overline, line-through or blink. 1352 | * underline and overline decorations are positioned under the text, line-through over it. 1353 | */ 1354 | textDecoration?: any; 1355 | 1356 | /** 1357 | * Sets the color of any text decoration, such as underlines, overlines, and strike throughs. 1358 | */ 1359 | textDecorationColor?: any; 1360 | 1361 | /** 1362 | * Sets what kind of line decorations are added to an element, such as underlines, overlines, etc. 1363 | */ 1364 | textDecorationLine?: any; 1365 | 1366 | textDecorationLineThrough?: any; 1367 | 1368 | textDecorationNone?: any; 1369 | 1370 | textDecorationOverline?: any; 1371 | 1372 | /** 1373 | * Specifies what parts of an element’s content are skipped over when applying any text decoration. 1374 | */ 1375 | textDecorationSkip?: any; 1376 | 1377 | /** 1378 | * This property specifies the style of the text decoration line drawn on the specified element. The intended meaning for the values are the same as those of the border-style-properties. 1379 | */ 1380 | textDecorationStyle?: any; 1381 | 1382 | textDecorationUnderline?: any; 1383 | 1384 | /** 1385 | * The text-emphasis property will apply special emphasis marks to the elements text. Slightly similar to the text-decoration property only that this property can have affect on the line-height. It also is noted that this is shorthand for text-emphasis-style and for text-emphasis-color. 1386 | */ 1387 | textEmphasis?: any; 1388 | 1389 | /** 1390 | * The text-emphasis-color property specifies the foreground color of the emphasis marks. 1391 | */ 1392 | textEmphasisColor?: any; 1393 | 1394 | /** 1395 | * The text-emphasis-style property applies special emphasis marks to an element's text. 1396 | */ 1397 | textEmphasisStyle?: any; 1398 | 1399 | /** 1400 | * This property helps determine an inline box's block-progression dimension, derived from the text-height and font-size properties for non-replaced elements, the height or the width for replaced elements, and the stacked block-progression dimension for inline-block elements. The block-progression dimension determines the position of the padding, border and margin for the element. 1401 | */ 1402 | textHeight?: any; 1403 | 1404 | /** 1405 | * Specifies the amount of space horizontally that should be left on the first line of the text of an element. This horizontal spacing is at the beginning of the first line and is in respect to the left edge of the containing block box. 1406 | */ 1407 | textIndent?: any; 1408 | 1409 | textJustifyTrim?: any; 1410 | 1411 | textKashidaSpace?: any; 1412 | 1413 | /** 1414 | * The text-line-through property is a shorthand property for text-line-through-style, text-line-through-color and text-line-through-mode. (Considered obsolete; use text-decoration instead.) 1415 | */ 1416 | textLineThrough?: any; 1417 | 1418 | /** 1419 | * Specifies the line colors for the line-through text decoration. 1420 | * (Considered obsolete; use text-decoration-color instead.) 1421 | */ 1422 | textLineThroughColor?: any; 1423 | 1424 | /** 1425 | * Sets the mode for the line-through text decoration, determining whether the text decoration affects the space characters or not. 1426 | * (Considered obsolete; use text-decoration-skip instead.) 1427 | */ 1428 | textLineThroughMode?: any; 1429 | 1430 | /** 1431 | * Specifies the line style for line-through text decoration. 1432 | * (Considered obsolete; use text-decoration-style instead.) 1433 | */ 1434 | textLineThroughStyle?: any; 1435 | 1436 | /** 1437 | * Specifies the line width for the line-through text decoration. 1438 | */ 1439 | textLineThroughWidth?: any; 1440 | 1441 | /** 1442 | * The text-overflow shorthand CSS property determines how overflowed content that is not displayed is signaled to the users. It can be clipped, display an ellipsis ('…', U+2026 HORIZONTAL ELLIPSIS) or a Web author-defined string. It covers the two long-hand properties text-overflow-mode and text-overflow-ellipsis 1443 | */ 1444 | textOverflow?: any; 1445 | 1446 | /** 1447 | * The text-overline property is the shorthand for the text-overline-style, text-overline-width, text-overline-color, and text-overline-mode properties. 1448 | */ 1449 | textOverline?: any; 1450 | 1451 | /** 1452 | * Specifies the line color for the overline text decoration. 1453 | */ 1454 | textOverlineColor?: any; 1455 | 1456 | /** 1457 | * Sets the mode for the overline text decoration, determining whether the text decoration affects the space characters or not. 1458 | */ 1459 | textOverlineMode?: any; 1460 | 1461 | /** 1462 | * Specifies the line style for overline text decoration. 1463 | */ 1464 | textOverlineStyle?: any; 1465 | 1466 | /** 1467 | * Specifies the line width for the overline text decoration. 1468 | */ 1469 | textOverlineWidth?: any; 1470 | 1471 | /** 1472 | * The text-rendering CSS property provides information to the browser about how to optimize when rendering text. Options are: legibility, speed or geometric precision. 1473 | */ 1474 | textRendering?: any; 1475 | 1476 | /** 1477 | * Obsolete: unsupported. 1478 | */ 1479 | textScript?: any; 1480 | 1481 | /** 1482 | * The CSS text-shadow property applies one or more drop shadows to the text and of an element. Each shadow is specified as an offset from the text, along with optional color and blur radius values. 1483 | */ 1484 | textShadow?: any; 1485 | 1486 | /** 1487 | * This property transforms text for styling purposes. (It has no effect on the underlying content.) 1488 | */ 1489 | textTransform?: any; 1490 | 1491 | /** 1492 | * Unsupported. 1493 | * This property will add a underline position value to the element that has an underline defined. 1494 | */ 1495 | textUnderlinePosition?: any; 1496 | 1497 | /** 1498 | * After review this should be replaced by text-decoration should it not? 1499 | * This property will set the underline style for text with a line value for underline, overline, and line-through. 1500 | */ 1501 | textUnderlineStyle?: any; 1502 | 1503 | /** 1504 | * This property specifies how far an absolutely positioned box's top margin edge is offset below the top edge of the box's containing block. For relatively positioned boxes, the offset is with respect to the top edges of the box itself (i.e., the box is given a position in the normal flow, then offset from that position according to these properties). 1505 | */ 1506 | top?: any; 1507 | 1508 | /** 1509 | * Determines whether touch input may trigger default behavior supplied by the user agent, such as panning or zooming. 1510 | */ 1511 | touchAction?: any; 1512 | 1513 | /** 1514 | * CSS transforms allow elements styled with CSS to be transformed in two-dimensional or three-dimensional space. Using this property, elements can be translated, rotated, scaled, and skewed. The value list may consist of 2D and/or 3D transform values. 1515 | */ 1516 | transform?: any; 1517 | 1518 | /** 1519 | * This property defines the origin of the transformation axes relative to the element to which the transformation is applied. 1520 | */ 1521 | transformOrigin?: any; 1522 | 1523 | /** 1524 | * This property allows you to define the relative position of the origin of the transformation grid along the z-axis. 1525 | */ 1526 | transformOriginZ?: any; 1527 | 1528 | /** 1529 | * This property specifies how nested elements are rendered in 3D space relative to their parent. 1530 | */ 1531 | transformStyle?: any; 1532 | 1533 | /** 1534 | * The transition CSS property is a shorthand property for transition-property, transition-duration, transition-timing-function, and transition-delay. It allows to define the transition between two states of an element. 1535 | */ 1536 | transition?: any; 1537 | 1538 | /** 1539 | * Defines when the transition will start. A value of ‘0s’ means the transition will execute as soon as the property is changed. Otherwise, the value specifies an offset from the moment the property is changed, and the transition will delay execution by that offset. 1540 | */ 1541 | transitionDelay?: any; 1542 | 1543 | /** 1544 | * The 'transition-duration' property specifies the length of time a transition animation takes to complete. 1545 | */ 1546 | transitionDuration?: any; 1547 | 1548 | /** 1549 | * The 'transition-property' property specifies the name of the CSS property to which the transition is applied. 1550 | */ 1551 | transitionProperty?: any; 1552 | 1553 | /** 1554 | * Sets the pace of action within a transition 1555 | */ 1556 | transitionTimingFunction?: any; 1557 | 1558 | /** 1559 | * The unicode-bidi CSS property specifies the level of embedding with respect to the bidirectional algorithm. 1560 | */ 1561 | unicodeBidi?: any; 1562 | 1563 | /** 1564 | * unicode-range allows you to set a specific range of characters to be downloaded from a font (embedded using @font-face) and made available for use on the current page. 1565 | */ 1566 | unicodeRange?: any; 1567 | 1568 | /** 1569 | * This is for all the high level UX stuff. 1570 | */ 1571 | userFocus?: any; 1572 | 1573 | /** 1574 | * For inputing user content 1575 | */ 1576 | userInput?: any; 1577 | 1578 | /** 1579 | * The vertical-align property controls how inline elements or text are vertically aligned compared to the baseline. If this property is used on table-cells it controls the vertical alignment of content of the table cell. 1580 | */ 1581 | verticalAlign?: any; 1582 | 1583 | /** 1584 | * The visibility property specifies whether the boxes generated by an element are rendered. 1585 | */ 1586 | visibility?: any; 1587 | 1588 | /** 1589 | * The voice-balance property sets the apparent position (in stereo sound) of the synthesized voice for spoken media. 1590 | */ 1591 | voiceBalance?: any; 1592 | 1593 | /** 1594 | * The voice-duration property allows the author to explicitly set the amount of time it should take a speech synthesizer to read an element's content, for example to allow the speech to be synchronized with other media. With a value of auto (the default) the length of time it takes to read the content is determined by the content itself and the voice-rate property. 1595 | */ 1596 | voiceDuration?: any; 1597 | 1598 | /** 1599 | * The voice-family property sets the speaker's voice used by a speech media agent to read an element. The speaker may be specified as a named character (to match a voice option in the speech reading software) or as a generic description of the age and gender of the voice. Similar to the font-family property for visual media, a comma-separated list of fallback options may be given in case the speech reader does not recognize the character name or cannot synthesize the requested combination of generic properties. 1600 | */ 1601 | voiceFamily?: any; 1602 | 1603 | /** 1604 | * The voice-pitch property sets pitch or tone (high or low) for the synthesized speech when reading an element; the pitch may be specified absolutely or relative to the normal pitch for the voice-family used to read the text. 1605 | */ 1606 | voicePitch?: any; 1607 | 1608 | /** 1609 | * The voice-range property determines how much variation in pitch or tone will be created by the speech synthesize when reading an element. Emphasized text, grammatical structures and punctuation may all be rendered as changes in pitch, this property determines how strong or obvious those changes are; large ranges are associated with enthusiastic or emotional speech, while small ranges are associated with flat or mechanical speech. 1610 | */ 1611 | voiceRange?: any; 1612 | 1613 | /** 1614 | * The voice-rate property sets the speed at which the voice synthesized by a speech media agent will read content. 1615 | */ 1616 | voiceRate?: any; 1617 | 1618 | /** 1619 | * The voice-stress property sets the level of vocal emphasis to be used for synthesized speech reading the element. 1620 | */ 1621 | voiceStress?: any; 1622 | 1623 | /** 1624 | * The voice-volume property sets the volume for spoken content in speech media. It replaces the deprecated volume property. 1625 | */ 1626 | voiceVolume?: any; 1627 | 1628 | /** 1629 | * The white-space property controls whether and how white space inside the element is collapsed, and whether lines may wrap at unforced "soft wrap" opportunities. 1630 | */ 1631 | whiteSpace?: any; 1632 | 1633 | /** 1634 | * Obsolete: unsupported. 1635 | */ 1636 | whiteSpaceTreatment?: any; 1637 | 1638 | /** 1639 | * Specifies the width of the content area of an element. The content area of the element width does not include the padding, border, and margin of the element. 1640 | */ 1641 | width?: any; 1642 | 1643 | /** 1644 | * The word-break property is often used when there is long generated content that is strung together without and spaces or hyphens to beak apart. A common case of this is when there is a long URL that does not have any hyphens. This case could potentially cause the breaking of the layout as it could extend past the parent element. 1645 | */ 1646 | wordBreak?: any; 1647 | 1648 | /** 1649 | * The word-spacing CSS property specifies the spacing behavior between "words". 1650 | */ 1651 | wordSpacing?: any; 1652 | 1653 | /** 1654 | * An alias of css/properties/overflow-wrap, word-wrap defines whether to break words when the content exceeds the boundaries of its container. 1655 | */ 1656 | wordWrap?: any; 1657 | 1658 | /** 1659 | * Specifies how exclusions affect inline content within block-level elements. Elements lay out their inline content in their content area but wrap around exclusion areas. 1660 | */ 1661 | wrapFlow?: any; 1662 | 1663 | /** 1664 | * Set the value that is used to offset the inner wrap shape from other shapes. Inline content that intersects a shape with this property will be pushed by this shape's margin. 1665 | */ 1666 | wrapMargin?: any; 1667 | 1668 | /** 1669 | * Obsolete and unsupported. Do not use. 1670 | * This CSS property controls the text when it reaches the end of the block in which it is enclosed. 1671 | */ 1672 | wrapOption?: any; 1673 | 1674 | /** 1675 | * writing-mode specifies if lines of text are laid out horizontally or vertically, and the direction which lines of text and blocks progress. 1676 | */ 1677 | writingMode?: any; 1678 | 1679 | 1680 | [propertyName: string]: any; 1681 | } 1682 | 1683 | interface HTMLAttributes extends DOMAttributes { 1684 | // React-specific Attributes 1685 | defaultChecked?: boolean; 1686 | defaultValue?: string | string[]; 1687 | 1688 | // Standard HTML Attributes 1689 | accept?: string; 1690 | acceptCharset?: string; 1691 | accessKey?: string; 1692 | action?: string; 1693 | allowFullScreen?: boolean; 1694 | allowTransparency?: boolean; 1695 | alt?: string; 1696 | async?: boolean; 1697 | autoComplete?: string; 1698 | autoFocus?: boolean; 1699 | autoPlay?: boolean; 1700 | capture?: boolean; 1701 | cellPadding?: number | string; 1702 | cellSpacing?: number | string; 1703 | charSet?: string; 1704 | challenge?: string; 1705 | checked?: boolean; 1706 | classID?: string; 1707 | className?: string; 1708 | cols?: number; 1709 | colSpan?: number; 1710 | content?: string; 1711 | contentEditable?: boolean; 1712 | contextMenu?: string; 1713 | controls?: boolean; 1714 | coords?: string; 1715 | crossOrigin?: string; 1716 | data?: string; 1717 | dateTime?: string; 1718 | default?: boolean; 1719 | defer?: boolean; 1720 | dir?: string; 1721 | disabled?: boolean; 1722 | download?: any; 1723 | draggable?: boolean; 1724 | encType?: string; 1725 | form?: string; 1726 | formAction?: string; 1727 | formEncType?: string; 1728 | formMethod?: string; 1729 | formNoValidate?: boolean; 1730 | formTarget?: string; 1731 | frameBorder?: number | string; 1732 | headers?: string; 1733 | height?: number | string; 1734 | hidden?: boolean; 1735 | high?: number; 1736 | href?: string; 1737 | hrefLang?: string; 1738 | htmlFor?: string; 1739 | httpEquiv?: string; 1740 | icon?: string; 1741 | id?: string; 1742 | inputMode?: string; 1743 | integrity?: string; 1744 | is?: string; 1745 | keyParams?: string; 1746 | keyType?: string; 1747 | kind?: string; 1748 | label?: string; 1749 | lang?: string; 1750 | list?: string; 1751 | loop?: boolean; 1752 | low?: number; 1753 | manifest?: string; 1754 | marginHeight?: number; 1755 | marginWidth?: number; 1756 | max?: number | string; 1757 | maxLength?: number; 1758 | media?: string; 1759 | mediaGroup?: string; 1760 | method?: string; 1761 | min?: number | string; 1762 | minLength?: number; 1763 | multiple?: boolean; 1764 | muted?: boolean; 1765 | name?: string; 1766 | noValidate?: boolean; 1767 | open?: boolean; 1768 | optimum?: number; 1769 | pattern?: string; 1770 | placeholder?: string; 1771 | poster?: string; 1772 | preload?: string; 1773 | radioGroup?: string; 1774 | readOnly?: boolean; 1775 | rel?: string; 1776 | required?: boolean; 1777 | role?: string; 1778 | rows?: number; 1779 | rowSpan?: number; 1780 | sandbox?: string; 1781 | scope?: string; 1782 | scoped?: boolean; 1783 | scrolling?: string; 1784 | seamless?: boolean; 1785 | selected?: boolean; 1786 | shape?: string; 1787 | size?: number; 1788 | sizes?: string; 1789 | span?: number; 1790 | spellCheck?: boolean; 1791 | src?: string; 1792 | srcDoc?: string; 1793 | srcLang?: string; 1794 | srcSet?: string; 1795 | start?: number; 1796 | step?: number | string; 1797 | style?: CSSProperties; 1798 | summary?: string; 1799 | tabIndex?: number; 1800 | target?: string; 1801 | title?: string; 1802 | type?: string; 1803 | useMap?: string; 1804 | value?: string | string[]; 1805 | width?: number | string; 1806 | wmode?: string; 1807 | wrap?: string; 1808 | 1809 | // RDFa Attributes 1810 | about?: string; 1811 | datatype?: string; 1812 | inlist?: any; 1813 | prefix?: string; 1814 | property?: string; 1815 | resource?: string; 1816 | typeof?: string; 1817 | vocab?: string; 1818 | 1819 | // Non-standard Attributes 1820 | autoCapitalize?: boolean; 1821 | autoCorrect?: string; 1822 | autoSave?: string; 1823 | color?: string; 1824 | itemProp?: string; 1825 | itemScope?: boolean; 1826 | itemType?: string; 1827 | itemID?: string; 1828 | itemRef?: string; 1829 | results?: number; 1830 | security?: string; 1831 | unselectable?: boolean; 1832 | } 1833 | 1834 | interface SVGAttributes extends HTMLAttributes { 1835 | clipPath?: string; 1836 | cx?: number | string; 1837 | cy?: number | string; 1838 | d?: string; 1839 | dx?: number | string; 1840 | dy?: number | string; 1841 | fill?: string; 1842 | fillOpacity?: number | string; 1843 | fontFamily?: string; 1844 | fontSize?: number | string; 1845 | fx?: number | string; 1846 | fy?: number | string; 1847 | gradientTransform?: string; 1848 | gradientUnits?: string; 1849 | markerEnd?: string; 1850 | markerMid?: string; 1851 | markerStart?: string; 1852 | offset?: number | string; 1853 | opacity?: number | string; 1854 | patternContentUnits?: string; 1855 | patternUnits?: string; 1856 | points?: string; 1857 | preserveAspectRatio?: string; 1858 | r?: number | string; 1859 | rx?: number | string; 1860 | ry?: number | string; 1861 | spreadMethod?: string; 1862 | stopColor?: string; 1863 | stopOpacity?: number | string; 1864 | stroke?: string; 1865 | strokeDasharray?: string; 1866 | strokeLinecap?: string; 1867 | strokeOpacity?: number | string; 1868 | strokeWidth?: number | string; 1869 | textAnchor?: string; 1870 | transform?: string; 1871 | version?: string; 1872 | viewBox?: string; 1873 | x1?: number | string; 1874 | x2?: number | string; 1875 | x?: number | string; 1876 | xlinkActuate?: string; 1877 | xlinkArcrole?: string; 1878 | xlinkHref?: string; 1879 | xlinkRole?: string; 1880 | xlinkShow?: string; 1881 | xlinkTitle?: string; 1882 | xlinkType?: string; 1883 | xmlBase?: string; 1884 | xmlLang?: string; 1885 | xmlSpace?: string; 1886 | y1?: number | string; 1887 | y2?: number | string; 1888 | y?: number | string; 1889 | } 1890 | 1891 | // 1892 | // React.DOM 1893 | // ---------------------------------------------------------------------- 1894 | 1895 | interface ReactDOM { 1896 | // HTML 1897 | a: HTMLFactory; 1898 | abbr: HTMLFactory; 1899 | address: HTMLFactory; 1900 | area: HTMLFactory; 1901 | article: HTMLFactory; 1902 | aside: HTMLFactory; 1903 | audio: HTMLFactory; 1904 | b: HTMLFactory; 1905 | base: HTMLFactory; 1906 | bdi: HTMLFactory; 1907 | bdo: HTMLFactory; 1908 | big: HTMLFactory; 1909 | blockquote: HTMLFactory; 1910 | body: HTMLFactory; 1911 | br: HTMLFactory; 1912 | button: HTMLFactory; 1913 | canvas: HTMLFactory; 1914 | caption: HTMLFactory; 1915 | cite: HTMLFactory; 1916 | code: HTMLFactory; 1917 | col: HTMLFactory; 1918 | colgroup: HTMLFactory; 1919 | data: HTMLFactory; 1920 | datalist: HTMLFactory; 1921 | dd: HTMLFactory; 1922 | del: HTMLFactory; 1923 | details: HTMLFactory; 1924 | dfn: HTMLFactory; 1925 | dialog: HTMLFactory; 1926 | div: HTMLFactory; 1927 | dl: HTMLFactory; 1928 | dt: HTMLFactory; 1929 | em: HTMLFactory; 1930 | embed: HTMLFactory; 1931 | fieldset: HTMLFactory; 1932 | figcaption: HTMLFactory; 1933 | figure: HTMLFactory; 1934 | footer: HTMLFactory; 1935 | form: HTMLFactory; 1936 | h1: HTMLFactory; 1937 | h2: HTMLFactory; 1938 | h3: HTMLFactory; 1939 | h4: HTMLFactory; 1940 | h5: HTMLFactory; 1941 | h6: HTMLFactory; 1942 | head: HTMLFactory; 1943 | header: HTMLFactory; 1944 | hr: HTMLFactory; 1945 | html: HTMLFactory; 1946 | i: HTMLFactory; 1947 | iframe: HTMLFactory; 1948 | img: HTMLFactory; 1949 | input: HTMLFactory; 1950 | ins: HTMLFactory; 1951 | kbd: HTMLFactory; 1952 | keygen: HTMLFactory; 1953 | label: HTMLFactory; 1954 | legend: HTMLFactory; 1955 | li: HTMLFactory; 1956 | link: HTMLFactory; 1957 | main: HTMLFactory; 1958 | map: HTMLFactory; 1959 | mark: HTMLFactory; 1960 | menu: HTMLFactory; 1961 | menuitem: HTMLFactory; 1962 | meta: HTMLFactory; 1963 | meter: HTMLFactory; 1964 | nav: HTMLFactory; 1965 | noscript: HTMLFactory; 1966 | object: HTMLFactory; 1967 | ol: HTMLFactory; 1968 | optgroup: HTMLFactory; 1969 | option: HTMLFactory; 1970 | output: HTMLFactory; 1971 | p: HTMLFactory; 1972 | param: HTMLFactory; 1973 | picture: HTMLFactory; 1974 | pre: HTMLFactory; 1975 | progress: HTMLFactory; 1976 | q: HTMLFactory; 1977 | rp: HTMLFactory; 1978 | rt: HTMLFactory; 1979 | ruby: HTMLFactory; 1980 | s: HTMLFactory; 1981 | samp: HTMLFactory; 1982 | script: HTMLFactory; 1983 | section: HTMLFactory; 1984 | select: HTMLFactory; 1985 | small: HTMLFactory; 1986 | source: HTMLFactory; 1987 | span: HTMLFactory; 1988 | strong: HTMLFactory; 1989 | style: HTMLFactory; 1990 | sub: HTMLFactory; 1991 | summary: HTMLFactory; 1992 | sup: HTMLFactory; 1993 | table: HTMLFactory; 1994 | tbody: HTMLFactory; 1995 | td: HTMLFactory; 1996 | textarea: HTMLFactory; 1997 | tfoot: HTMLFactory; 1998 | th: HTMLFactory; 1999 | thead: HTMLFactory; 2000 | time: HTMLFactory; 2001 | title: HTMLFactory; 2002 | tr: HTMLFactory; 2003 | track: HTMLFactory; 2004 | u: HTMLFactory; 2005 | ul: HTMLFactory; 2006 | "var": HTMLFactory; 2007 | video: HTMLFactory; 2008 | wbr: HTMLFactory; 2009 | 2010 | // SVG 2011 | svg: SVGFactory; 2012 | circle: SVGFactory; 2013 | defs: SVGFactory; 2014 | ellipse: SVGFactory; 2015 | g: SVGFactory; 2016 | image: SVGFactory; 2017 | line: SVGFactory; 2018 | linearGradient: SVGFactory; 2019 | mask: SVGFactory; 2020 | path: SVGFactory; 2021 | pattern: SVGFactory; 2022 | polygon: SVGFactory; 2023 | polyline: SVGFactory; 2024 | radialGradient: SVGFactory; 2025 | rect: SVGFactory; 2026 | stop: SVGFactory; 2027 | text: SVGFactory; 2028 | tspan: SVGFactory; 2029 | } 2030 | 2031 | // 2032 | // React.PropTypes 2033 | // ---------------------------------------------------------------------- 2034 | 2035 | interface Validator { 2036 | (object: T, key: string, componentName: string): Error; 2037 | } 2038 | 2039 | interface Requireable extends Validator { 2040 | isRequired: Validator; 2041 | } 2042 | 2043 | interface ValidationMap { 2044 | [key: string]: Validator; 2045 | } 2046 | 2047 | interface ReactPropTypes { 2048 | any: Requireable; 2049 | array: Requireable; 2050 | bool: Requireable; 2051 | func: Requireable; 2052 | number: Requireable; 2053 | object: Requireable; 2054 | string: Requireable; 2055 | node: Requireable; 2056 | element: Requireable; 2057 | instanceOf(expectedClass: {}): Requireable; 2058 | oneOf(types: any[]): Requireable; 2059 | oneOfType(types: Validator[]): Requireable; 2060 | arrayOf(type: Validator): Requireable; 2061 | objectOf(type: Validator): Requireable; 2062 | shape(type: ValidationMap): Requireable; 2063 | } 2064 | 2065 | // 2066 | // React.Children 2067 | // ---------------------------------------------------------------------- 2068 | 2069 | interface ReactChildren { 2070 | map(children: ReactNode, fn: (child: ReactChild, index: number) => T): T[]; 2071 | forEach(children: ReactNode, fn: (child: ReactChild, index: number) => any): void; 2072 | count(children: ReactNode): number; 2073 | only(children: ReactNode): ReactChild; 2074 | toArray(children: ReactNode): ReactChild[]; 2075 | } 2076 | 2077 | // 2078 | // Browser Interfaces 2079 | // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts 2080 | // ---------------------------------------------------------------------- 2081 | 2082 | interface AbstractView { 2083 | styleMedia: StyleMedia; 2084 | document: Document; 2085 | } 2086 | 2087 | interface Touch { 2088 | identifier: number; 2089 | target: EventTarget; 2090 | screenX: number; 2091 | screenY: number; 2092 | clientX: number; 2093 | clientY: number; 2094 | pageX: number; 2095 | pageY: number; 2096 | } 2097 | 2098 | interface TouchList { 2099 | [index: number]: Touch; 2100 | length: number; 2101 | item(index: number): Touch; 2102 | identifiedTouch(identifier: number): Touch; 2103 | } 2104 | } 2105 | 2106 | declare module "react" { 2107 | export = __React; 2108 | } 2109 | 2110 | declare namespace JSX { 2111 | import React = __React; 2112 | 2113 | interface Element extends React.ReactElement { } 2114 | interface ElementClass extends React.Component { 2115 | render(): JSX.Element; 2116 | } 2117 | interface ElementAttributesProperty { props: {}; } 2118 | 2119 | interface IntrinsicElements { 2120 | // HTML 2121 | a: React.HTMLProps; 2122 | abbr: React.HTMLProps; 2123 | address: React.HTMLProps; 2124 | area: React.HTMLProps; 2125 | article: React.HTMLProps; 2126 | aside: React.HTMLProps; 2127 | audio: React.HTMLProps; 2128 | b: React.HTMLProps; 2129 | base: React.HTMLProps; 2130 | bdi: React.HTMLProps; 2131 | bdo: React.HTMLProps; 2132 | big: React.HTMLProps; 2133 | blockquote: React.HTMLProps; 2134 | body: React.HTMLProps; 2135 | br: React.HTMLProps; 2136 | button: React.HTMLProps; 2137 | canvas: React.HTMLProps; 2138 | caption: React.HTMLProps; 2139 | cite: React.HTMLProps; 2140 | code: React.HTMLProps; 2141 | col: React.HTMLProps; 2142 | colgroup: React.HTMLProps; 2143 | data: React.HTMLProps; 2144 | datalist: React.HTMLProps; 2145 | dd: React.HTMLProps; 2146 | del: React.HTMLProps; 2147 | details: React.HTMLProps; 2148 | dfn: React.HTMLProps; 2149 | dialog: React.HTMLProps; 2150 | div: React.HTMLProps; 2151 | dl: React.HTMLProps; 2152 | dt: React.HTMLProps; 2153 | em: React.HTMLProps; 2154 | embed: React.HTMLProps; 2155 | fieldset: React.HTMLProps; 2156 | figcaption: React.HTMLProps; 2157 | figure: React.HTMLProps; 2158 | footer: React.HTMLProps; 2159 | form: React.HTMLProps; 2160 | h1: React.HTMLProps; 2161 | h2: React.HTMLProps; 2162 | h3: React.HTMLProps; 2163 | h4: React.HTMLProps; 2164 | h5: React.HTMLProps; 2165 | h6: React.HTMLProps; 2166 | head: React.HTMLProps; 2167 | header: React.HTMLProps; 2168 | hr: React.HTMLProps; 2169 | html: React.HTMLProps; 2170 | i: React.HTMLProps; 2171 | iframe: React.HTMLProps; 2172 | img: React.HTMLProps; 2173 | input: React.HTMLProps; 2174 | ins: React.HTMLProps; 2175 | kbd: React.HTMLProps; 2176 | keygen: React.HTMLProps; 2177 | label: React.HTMLProps; 2178 | legend: React.HTMLProps; 2179 | li: React.HTMLProps; 2180 | link: React.HTMLProps; 2181 | main: React.HTMLProps; 2182 | map: React.HTMLProps; 2183 | mark: React.HTMLProps; 2184 | menu: React.HTMLProps; 2185 | menuitem: React.HTMLProps; 2186 | meta: React.HTMLProps; 2187 | meter: React.HTMLProps; 2188 | nav: React.HTMLProps; 2189 | noscript: React.HTMLProps; 2190 | object: React.HTMLProps; 2191 | ol: React.HTMLProps; 2192 | optgroup: React.HTMLProps; 2193 | option: React.HTMLProps; 2194 | output: React.HTMLProps; 2195 | p: React.HTMLProps; 2196 | param: React.HTMLProps; 2197 | picture: React.HTMLProps; 2198 | pre: React.HTMLProps; 2199 | progress: React.HTMLProps; 2200 | q: React.HTMLProps; 2201 | rp: React.HTMLProps; 2202 | rt: React.HTMLProps; 2203 | ruby: React.HTMLProps; 2204 | s: React.HTMLProps; 2205 | samp: React.HTMLProps; 2206 | script: React.HTMLProps; 2207 | section: React.HTMLProps; 2208 | select: React.HTMLProps; 2209 | small: React.HTMLProps; 2210 | source: React.HTMLProps; 2211 | span: React.HTMLProps; 2212 | strong: React.HTMLProps; 2213 | style: React.HTMLProps; 2214 | sub: React.HTMLProps; 2215 | summary: React.HTMLProps; 2216 | sup: React.HTMLProps; 2217 | table: React.HTMLProps; 2218 | tbody: React.HTMLProps; 2219 | td: React.HTMLProps; 2220 | textarea: React.HTMLProps; 2221 | tfoot: React.HTMLProps; 2222 | th: React.HTMLProps; 2223 | thead: React.HTMLProps; 2224 | time: React.HTMLProps; 2225 | title: React.HTMLProps; 2226 | tr: React.HTMLProps; 2227 | track: React.HTMLProps; 2228 | u: React.HTMLProps; 2229 | ul: React.HTMLProps; 2230 | "var": React.HTMLProps; 2231 | video: React.HTMLProps; 2232 | wbr: React.HTMLProps; 2233 | 2234 | // SVG 2235 | circle: React.SVGProps; 2236 | defs: React.SVGProps; 2237 | ellipse: React.SVGProps; 2238 | g: React.SVGProps; 2239 | image: React.SVGProps; 2240 | line: React.SVGProps; 2241 | linearGradient: React.SVGProps; 2242 | mask: React.SVGProps; 2243 | path: React.SVGProps; 2244 | pattern: React.SVGProps; 2245 | polygon: React.SVGProps; 2246 | polyline: React.SVGProps; 2247 | radialGradient: React.SVGProps; 2248 | rect: React.SVGProps; 2249 | stop: React.SVGProps; 2250 | svg: React.SVGProps; 2251 | text: React.SVGProps; 2252 | tspan: React.SVGProps; 2253 | } 2254 | } 2255 | -------------------------------------------------------------------------------- /examples/jsx/typings/tsd.d.ts: -------------------------------------------------------------------------------- 1 | 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /examples/proxyquireify/.gitignore: -------------------------------------------------------------------------------- 1 | typings 2 | -------------------------------------------------------------------------------- /examples/proxyquireify/README.md: -------------------------------------------------------------------------------- 1 | # tsify Sample: proxyquireify 2 | 3 | A trivial TypeScript project that uses proxyquireify to stub a module. 4 | 5 | Based on the [proxyquireify example](https://github.com/thlorenz/proxyquireify#example). 6 | 7 | ## Building 8 | 9 | Check out the scripts in `package.json` for an example on how to run a build with the API. 10 | 11 | ```sh 12 | npm run build-script 13 | ``` 14 | 15 | ## Running 16 | 17 | Run the bundle under Node.js: 18 | 19 | ```sh 20 | node bundle 21 | ``` 22 | 23 | You should see the results from the stubbed `bar.js` module's functions written to the console. 24 | -------------------------------------------------------------------------------- /examples/proxyquireify/build.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const proxyquire = require('proxyquireify'); 3 | const tsify = require('tsify'); 4 | 5 | browserify() 6 | .plugin(tsify) 7 | .plugin(proxyquire.plugin) 8 | .require(require.resolve('./src/foo-spec.ts'), { entry: true }) 9 | .bundle() 10 | .pipe(process.stdout); 11 | -------------------------------------------------------------------------------- /examples/proxyquireify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsify-proxyquireify", 3 | "version": "0.0.0", 4 | "description": "tsify Sample: proxyquireify", 5 | "scripts": { 6 | "build-script": "node ./build.js > bundle.js" 7 | }, 8 | "author": "Nicholas Jamieson (http://github.com/cartant)", 9 | "license": "MIT", 10 | "private": true, 11 | "dependencies": { 12 | "browserify": "^12.0.1", 13 | "proxyquireify": "^3.2.1", 14 | "tsify": "*", 15 | "typescript": "~1.8.7" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/proxyquireify/src/bar.ts: -------------------------------------------------------------------------------- 1 | export function kinder(): string { return 'kinder'; } 2 | export function wunder(): string { return 'wunder'; } 3 | -------------------------------------------------------------------------------- /examples/proxyquireify/src/baz.ts: -------------------------------------------------------------------------------- 1 | export function wurst(): string { return 'wurst'; } 2 | -------------------------------------------------------------------------------- /examples/proxyquireify/src/foo-spec.ts: -------------------------------------------------------------------------------- 1 | const proxyquire = require('proxyquireify')(require); 2 | require = function (name) { 3 | const stubs = { 4 | './bar': { 5 | kinder: function () { return 'schokolade'; }, 6 | wunder: function () { return 'wirklich wunderbar'; } 7 | } 8 | }; 9 | return proxyquire(name, stubs); 10 | } as NodeRequire; 11 | 12 | import foo from './foo'; 13 | import { wurst } from './baz'; 14 | 15 | console.log(foo()); 16 | console.log(wurst()); 17 | -------------------------------------------------------------------------------- /examples/proxyquireify/src/foo.ts: -------------------------------------------------------------------------------- 1 | import * as bar from './bar'; 2 | 3 | export default function (): string { 4 | return bar.kinder() + ' ist ' + bar.wunder(); 5 | } 6 | -------------------------------------------------------------------------------- /examples/proxyquireify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "src/bar.ts", 4 | "src/baz.ts", 5 | "src/foo.ts", 6 | "src/foo-spec.ts", 7 | "typings/index.d.ts" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /examples/proxyquireify/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "globalDependencies": { 3 | "node": "registry:dt/node#6.0.0+20160621231320" 4 | }, 5 | "dependencies": { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | // Note that @types/browserify is not used for a reason: 2 | // https://github.com/TypeStrong/tsify/issues/267 3 | 4 | import * as typescript from "typescript"; 5 | 6 | interface Options { 7 | exclude?: string[]; 8 | files?: string[]; 9 | global?: boolean; 10 | include?: string[]; 11 | m?: string; 12 | p?: string | Record; 13 | project?: string | Record; 14 | t?: string; 15 | typescript?: string | typeof typescript; 16 | } 17 | 18 | declare function tsify(b: any, opts: Options): any; 19 | export = tsify; 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var realpath = require('fs.realpath'); 4 | var log = require('util').debuglog(require('./package').name); 5 | var through = require('through2'); 6 | var path = require('path'); 7 | 8 | function tsify(b, opts) { 9 | 10 | if (typeof b === 'string') { 11 | throw new Error('tsify appears to have been configured as a transform; it must be configured as a plugin.'); 12 | } 13 | var ts = opts.typescript || require('typescript'); 14 | if (typeof ts === 'string' || ts instanceof String) { 15 | ts = require(ts); 16 | } 17 | 18 | var Tsifier = require('./lib/Tsifier')(ts); 19 | var tsifier = new Tsifier(opts, b._options); 20 | 21 | tsifier.on('error', function (error) { 22 | b.pipeline.emit('error', error); 23 | }); 24 | tsifier.on('file', function (file, id) { 25 | b.emit('file', file, id); 26 | }); 27 | 28 | setupPipeline(); 29 | 30 | var transformOpts = { 31 | global: opts.global 32 | }; 33 | b.transform(tsifier.transform.bind(tsifier), transformOpts); 34 | 35 | b.on('reset', function () { 36 | setupPipeline(); 37 | }); 38 | 39 | function setupPipeline() { 40 | if (tsifier.opts.jsx && b._extensions.indexOf('.tsx') === -1) 41 | b._extensions.unshift('.tsx'); 42 | 43 | if (b._extensions.indexOf('.ts') === -1) 44 | b._extensions.unshift('.ts'); 45 | 46 | b.pipeline.get('record').push(gatherEntryPoints()); 47 | } 48 | 49 | function gatherEntryPoints() { 50 | var rows = []; 51 | return through.obj(transform, flush); 52 | 53 | function transform(row, enc, next) { 54 | rows.push(row); 55 | next(); 56 | } 57 | 58 | function flush(next) { 59 | var self = this; 60 | var ignoredFiles = []; 61 | var entryFiles = rows 62 | .map(function (row) { 63 | var file = row.file || row.id; 64 | if (file) { 65 | if (row.source !== undefined) { 66 | ignoredFiles.push(file); 67 | } else if (row.basedir) { 68 | return path.resolve(row.basedir, file); 69 | } else if (path.isAbsolute(file)) { 70 | return file; 71 | } else { 72 | ignoredFiles.push(file); 73 | } 74 | } 75 | return null; 76 | }) 77 | .filter(function (file) { return file; }) 78 | .map(function (file) { return realpath.realpathSync(file); }); 79 | if (entryFiles.length) { 80 | log('Files from browserify entry points:'); 81 | entryFiles.forEach(function (file) { log(' %s', file); }); 82 | } 83 | if (ignoredFiles.length) { 84 | log('Ignored browserify entry points:'); 85 | ignoredFiles.forEach(function (file) { log(' %s', file); }); 86 | } 87 | tsifier.reset(); 88 | tsifier.generateCache(entryFiles, ignoredFiles); 89 | rows.forEach(function (row) { self.push(row); }); 90 | self.push(null); 91 | next(); 92 | } 93 | } 94 | } 95 | 96 | module.exports = tsify; 97 | -------------------------------------------------------------------------------- /lib/CompileError.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var os = require('os'); 4 | 5 | module.exports = function (ts) { 6 | function CompileError(diagnostic) { 7 | SyntaxError.call(this); 8 | 9 | this.message = ''; 10 | 11 | if (diagnostic.file) { 12 | var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); 13 | this.fileName = diagnostic.file.fileName; 14 | this.line = loc.line + 1; 15 | this.column = loc.character + 1; 16 | this.message += this.fileName + '(' + this.line + ',' + this.column + '): '; 17 | } 18 | 19 | var category = ts.DiagnosticCategory[diagnostic.category]; 20 | this.name = 'TypeScript error'; 21 | this.message += category + ' TS' + diagnostic.code + ': ' + 22 | ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL); 23 | } 24 | 25 | CompileError.prototype = Object.create(SyntaxError.prototype); 26 | 27 | return CompileError; 28 | }; 29 | -------------------------------------------------------------------------------- /lib/Host.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var events = require('events'); 4 | var fs = require('fs'); 5 | var realpath = require('fs.realpath'); 6 | var log = require('util').debuglog(require('../package').name); 7 | var trace = require('util').debuglog(require('../package').name + '-trace'); 8 | var os = require('os'); 9 | var path = require('path'); 10 | var util = require('util'); 11 | var semver = require('semver'); 12 | 13 | module.exports = function (ts) { 14 | 15 | var isCaseSensitiveFileSystem; 16 | 17 | try { 18 | fs.accessSync(path.join(__dirname, path.basename(__filename)).toUpperCase(), fs.constants.R_OK); 19 | isCaseSensitiveFileSystem = false; 20 | } catch (error) { 21 | trace('Case sensitive detection error: %s', error); 22 | isCaseSensitiveFileSystem = true; 23 | } 24 | log('Detected case %s file system', isCaseSensitiveFileSystem ? 'sensitive' : 'insensitive'); 25 | 26 | function Host(currentDirectory, opts) { 27 | this.isCaseSensitive = !!opts.forceConsistentCasingInFileNames || isCaseSensitiveFileSystem; 28 | this.currentDirectory = this.getCanonicalFileName(path.resolve(currentDirectory)); 29 | this.outputDirectory = this.getCanonicalFileName(path.resolve(opts.outDir)); 30 | this.rootDirectory = this.getCanonicalFileName(path.resolve(opts.rootDir)); 31 | this.languageVersion = opts.target; 32 | this.files = {}; 33 | this.previousFiles = {}; 34 | this.output = {}; 35 | this.version = 0; 36 | this.error = false; 37 | } 38 | 39 | util.inherits(Host, events.EventEmitter); 40 | 41 | Host.prototype._reset = function () { 42 | this.previousFiles = this.files; 43 | this.files = {}; 44 | this.output = {}; 45 | this.error = false; 46 | ++this.version; 47 | 48 | log('Resetting (version %d)', this.version); 49 | }; 50 | 51 | Host.prototype._addFile = function (filename, root) { 52 | 53 | // Ensure that the relative file name is what's passed to 54 | // 'createSourceFile', as that's the name that will be used in error 55 | // messages, etc. 56 | 57 | var relative = ts.normalizeSlashes(path.relative( 58 | this.currentDirectory, 59 | this.getCanonicalFileName(path.resolve(this.currentDirectory, filename)) 60 | )); 61 | var canonical = this._canonical(filename); 62 | trace('Parsing %s', canonical); 63 | 64 | var text; 65 | try { 66 | text = fs.readFileSync(filename, 'utf-8'); 67 | } catch (ex) { 68 | return; 69 | } 70 | 71 | var file; 72 | var current = this.files[canonical]; 73 | var previous = this.previousFiles[canonical]; 74 | var version; 75 | 76 | if (current && current.contents === text) { 77 | file = current.ts; 78 | version = current.version; 79 | trace('Reused current file %s (version %d)', canonical, version); 80 | } else if (previous && previous.contents === text) { 81 | file = previous.ts; 82 | version = previous.version; 83 | trace('Reused previous file %s (version %d)', canonical, version); 84 | } else { 85 | file = ts.createSourceFile(relative, text, this.languageVersion, true); 86 | version = this.version; 87 | trace('New version of source file %s (version %d)', canonical, version); 88 | } 89 | 90 | this.files[canonical] = { 91 | filename: relative, 92 | contents: text, 93 | ts: file, 94 | root: root, 95 | version: version, 96 | nodeModule: /\/node_modules\//i.test(canonical) && !/\.d\.ts$/i.test(canonical) 97 | }; 98 | this.emit('file', canonical, relative); 99 | 100 | return file; 101 | }; 102 | 103 | Host.prototype.getSourceFile = function (filename) { 104 | if (filename === '__lib.d.ts') { 105 | return this.libDefault; 106 | } 107 | var canonical = this._canonical(filename); 108 | if (this.files[canonical]) { 109 | return this.files[canonical].ts; 110 | } 111 | return this._addFile(filename, false); 112 | }; 113 | 114 | Host.prototype.getDefaultLibFileName = function () { 115 | var libPath = path.dirname(ts.sys.getExecutingFilePath()); 116 | var libFile = ts.getDefaultLibFileName({ target: this.languageVersion }); 117 | return ts.normalizeSlashes(path.join(libPath, libFile)); 118 | }; 119 | 120 | Host.prototype.writeFile = function (filename, data) { 121 | 122 | var outputCanonical = this._canonical(filename); 123 | log('Cache write %s', outputCanonical); 124 | this.output[outputCanonical] = data; 125 | 126 | var sourceCanonical = this._inferSourceCanonical(outputCanonical); 127 | var sourceFollowed = this._follow(path.dirname(sourceCanonical)) + '/' + path.basename(sourceCanonical); 128 | 129 | if (sourceFollowed !== sourceCanonical) { 130 | outputCanonical = this._inferOutputCanonical(sourceFollowed); 131 | log('Cache write (followed) %s', outputCanonical); 132 | this.output[outputCanonical] = data; 133 | } 134 | }; 135 | 136 | Host.prototype.getCurrentDirectory = function () { 137 | return this.currentDirectory; 138 | }; 139 | 140 | Host._getCanonicalFileName = function (filename) { 141 | return ts.normalizeSlashes(isCaseSensitiveFileSystem ? filename : filename.toLowerCase()); 142 | } 143 | 144 | Host.prototype.getCanonicalFileName = function (filename) { 145 | return ts.normalizeSlashes(this.isCaseSensitive ? filename : filename.toLowerCase()); 146 | }; 147 | 148 | Host.prototype.useCaseSensitiveFileNames = function () { 149 | return this.isCaseSensitive; 150 | }; 151 | 152 | Host.prototype.getNewLine = function () { 153 | return os.EOL; 154 | }; 155 | 156 | Host.prototype.fileExists = function (filename) { 157 | return ts.sys.fileExists(filename); 158 | }; 159 | 160 | Host.prototype.readFile = function (filename) { 161 | return ts.sys.readFile(filename); 162 | }; 163 | 164 | Host.prototype.directoryExists = function (dirname) { 165 | return ts.sys.directoryExists(dirname); 166 | }; 167 | 168 | Host.prototype.getDirectories = function (dirname) { 169 | return ts.sys.getDirectories(dirname); 170 | }; 171 | 172 | Host.prototype.getEnvironmentVariable = function (name) { 173 | return ts.sys.getEnvironmentVariable(name); 174 | }; 175 | 176 | Host.prototype.realpath = function (name) { 177 | return realpath.realpathSync(name); 178 | }; 179 | 180 | Host.prototype.trace = function (message) { 181 | ts.sys.write(message + this.getNewLine()); 182 | }; 183 | 184 | Host.prototype._rootFilenames = function () { 185 | 186 | var rootFilenames = []; 187 | 188 | for (var filename in this.files) { 189 | if (!Object.hasOwnProperty.call(this.files, filename)) continue; 190 | if (!this.files[filename].root) continue; 191 | rootFilenames.push(filename); 192 | } 193 | return rootFilenames; 194 | } 195 | 196 | Host.prototype._nodeModuleFilenames = function () { 197 | 198 | var nodeModuleFilenames = []; 199 | 200 | for (var filename in this.files) { 201 | if (!Object.hasOwnProperty.call(this.files, filename)) continue; 202 | if (!this.files[filename].nodeModule) continue; 203 | nodeModuleFilenames.push(filename); 204 | } 205 | return nodeModuleFilenames; 206 | } 207 | 208 | Host.prototype._compile = function (opts) { 209 | 210 | var rootFilenames = this._rootFilenames(); 211 | var nodeModuleFilenames = []; 212 | 213 | log('Compiling files:'); 214 | rootFilenames.forEach(function (file) { log(' %s', file); }); 215 | 216 | if (semver.gte(ts.version, '2.0.0')) { 217 | ts.createProgram(rootFilenames, opts, this); 218 | nodeModuleFilenames = this._nodeModuleFilenames(); 219 | log(' + %d file(s) found in node_modules', nodeModuleFilenames.length); 220 | } 221 | return ts.createProgram(rootFilenames.concat(nodeModuleFilenames), opts, this); 222 | } 223 | 224 | Host.prototype._output = function (filename) { 225 | 226 | var outputCanonical = this._inferOutputCanonical(filename); 227 | log('Cache read %s', outputCanonical); 228 | 229 | var output = this.output[outputCanonical]; 230 | if (!output) { 231 | log('Cache miss on %s', outputCanonical); 232 | } 233 | return output; 234 | } 235 | 236 | Host.prototype._canonical = function (filename) { 237 | return this.getCanonicalFileName(path.resolve( 238 | this.currentDirectory, 239 | filename 240 | )); 241 | } 242 | 243 | Host.prototype._inferOutputCanonical = function (filename) { 244 | 245 | var sourceCanonical = this._canonical(filename); 246 | var outputRelative = path.relative( 247 | this.rootDirectory, 248 | sourceCanonical 249 | ); 250 | var outputCanonical = this.getCanonicalFileName(path.resolve( 251 | this.outputDirectory, 252 | outputRelative 253 | )); 254 | return outputCanonical; 255 | } 256 | 257 | Host.prototype._inferSourceCanonical = function (filename) { 258 | 259 | var outputCanonical = this._canonical(filename); 260 | var outputRelative = path.relative( 261 | this.outputDirectory, 262 | outputCanonical 263 | ); 264 | var sourceCanonical = this.getCanonicalFileName(path.resolve( 265 | this.rootDirectory, 266 | outputRelative 267 | )); 268 | return sourceCanonical; 269 | } 270 | 271 | Host.prototype._follow = function (filename) { 272 | 273 | filename = this._canonical(filename); 274 | var basename; 275 | var parts = []; 276 | 277 | do { 278 | var stats = fs.lstatSync(filename); 279 | if (stats.isSymbolicLink()) { 280 | filename = realpath.realpathSync(filename); 281 | } else { 282 | basename = path.basename(filename); 283 | if (basename) { 284 | parts.unshift(basename); 285 | filename = path.dirname(filename); 286 | } 287 | } 288 | } while (basename); 289 | 290 | return ts.normalizeSlashes(filename + parts.join('/')); 291 | }; 292 | 293 | return Host; 294 | }; 295 | -------------------------------------------------------------------------------- /lib/Tsifier.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var convert = require('convert-source-map'); 4 | var events = require('events'); 5 | var extend = require('util')._extend; 6 | var fs = require('fs'); 7 | var realpath = require('fs.realpath'); 8 | var log = require('util').debuglog(require('../package').name); 9 | var trace = require('util').debuglog(require('../package').name + '-trace'); 10 | var path = require('path'); 11 | var through = require('through2'); 12 | var time = require('./time'); 13 | var tsconfig = require('tsconfig'); 14 | var util = require('util'); 15 | var assign = require('object-assign'); 16 | 17 | module.exports = function (ts) { 18 | var CompileError = require('./CompileError')(ts); 19 | var Host = require('./Host')(ts); 20 | var currentDirectory = ts.normalizeSlashes(realpath.realpathSync(process.cwd())); 21 | 22 | var parseJsonConfigFileContent = ts.parseJsonConfigFileContent || ts.parseConfigFile; 23 | 24 | function isTypescript(file) { 25 | return (/\.tsx?$/i).test(file); 26 | } 27 | 28 | function isTsx(file) { 29 | return (/\.tsx$/i).test(file); 30 | } 31 | 32 | function isJavascript(file) { 33 | return (/\.jsx?$/i).test(file); 34 | } 35 | 36 | function isTypescriptDeclaration(file) { 37 | return (/\.d\.ts$/i).test(file); 38 | } 39 | 40 | function replaceFileExtension(file, extension) { 41 | return file.replace(/\.\w+$/i, extension); 42 | } 43 | 44 | function fileExists(file) { 45 | try { 46 | var stats = fs.lstatSync(file); 47 | return stats.isFile(); 48 | } catch (e) { 49 | return false; 50 | } 51 | } 52 | 53 | function parseOptions(opts, bopts) { 54 | 55 | // Expand any short-name, command-line options 56 | var expanded = {}; 57 | if (opts.m) { expanded.module = opts.m; } 58 | if (opts.p) { expanded.project = opts.p; } 59 | if (opts.t) { expanded.target = opts.t; } 60 | opts = assign(expanded, opts); 61 | 62 | var config; 63 | var configFile; 64 | if (typeof opts.project === "object"){ 65 | log('Using inline tsconfig'); 66 | config = JSON.parse(JSON.stringify(opts.project)); 67 | config.compilerOptions = config.compilerOptions || {}; 68 | extend(config.compilerOptions, opts); 69 | } else { 70 | if (fileExists(opts.project)) { 71 | configFile = opts.project; 72 | } else { 73 | configFile = ts.findConfigFile( 74 | ts.normalizeSlashes(opts.project || bopts.basedir || currentDirectory), 75 | fileExists 76 | ); 77 | } 78 | if (configFile) { 79 | log('Using tsconfig file at %s', configFile); 80 | config = tsconfig.readFileSync(configFile); 81 | config.compilerOptions = config.compilerOptions || {}; 82 | extend(config.compilerOptions, opts); 83 | } else { 84 | config = { 85 | files: [], 86 | compilerOptions: opts 87 | }; 88 | } 89 | } 90 | 91 | // Note that subarg parses command line arrays in its own peculiar way: 92 | // https://github.com/substack/subarg 93 | 94 | if (opts.exclude) { 95 | config.exclude = opts.exclude._ || opts.exclude; 96 | } 97 | if (opts.files) { 98 | config.files = opts.files._ || opts.files; 99 | } 100 | if (opts.include) { 101 | config.include = opts.include._ || opts.include; 102 | } 103 | 104 | var parsed = parseJsonConfigFileContent( 105 | config, 106 | ts.sys, 107 | configFile ? ts.normalizeSlashes(path.resolve(path.dirname(configFile))) : currentDirectory, 108 | null, 109 | configFile ? ts.normalizeSlashes(path.resolve(configFile)) : undefined 110 | ); 111 | 112 | // Generate inline sourcemaps if Browserify's --debug option is set 113 | parsed.options.sourceMap = false; 114 | parsed.options.inlineSourceMap = bopts.debug; 115 | parsed.options.inlineSources = bopts.debug; 116 | 117 | // Default to CommonJS module mode 118 | parsed.options.module = parsed.options.module || ts.ModuleKind.CommonJS; 119 | 120 | // Blacklist --out/--outFile/--noEmit; these should definitely not be set, since we are doing 121 | // concatenation with Browserify instead 122 | delete parsed.options.out; 123 | delete parsed.options.outFile; 124 | delete parsed.options.noEmit; 125 | 126 | // Set rootDir and outDir so we know exactly where the TS compiler will be trying to 127 | // write files; the filenames will end up being the keys into our in-memory store. 128 | // The output directory needs to be distinct from the input directory to prevent the TS 129 | // compiler from thinking that it might accidentally overwrite source files, which would 130 | // prevent it from outputting e.g. the results of transpiling ES6 JS files with --allowJs. 131 | parsed.options.rootDir = path.relative('.', '/'); 132 | parsed.options.outDir = ts.normalizeSlashes(path.resolve('/__tsify__')); 133 | 134 | log('Files from tsconfig parse:'); 135 | parsed.fileNames.forEach(function (filename) { log(' %s', filename); }); 136 | 137 | var result = { 138 | options: parsed.options, 139 | fileNames: parsed.fileNames 140 | }; 141 | 142 | return result; 143 | } 144 | 145 | function Tsifier(opts, bopts) { 146 | var self = this; 147 | 148 | var parsedOptions = parseOptions(opts, bopts); 149 | self.opts = parsedOptions.options; 150 | self.files = parsedOptions.fileNames; 151 | self.ignoredFiles = []; 152 | self.bopts = bopts; 153 | self.host = new Host(currentDirectory, self.opts); 154 | 155 | self.host.on('file', function (file, id) { 156 | self.emit('file', file, id); 157 | }); 158 | } 159 | 160 | util.inherits(Tsifier, events.EventEmitter); 161 | 162 | Tsifier.prototype.reset = function () { 163 | var self = this; 164 | self.ignoredFiles = []; 165 | self.host._reset(); 166 | self.addFiles(self.files); 167 | }; 168 | 169 | Tsifier.prototype.generateCache = function (files, ignoredFiles) { 170 | if (ignoredFiles) { 171 | this.ignoredFiles = ignoredFiles; 172 | } 173 | this.addFiles(files); 174 | this.compile(); 175 | }; 176 | 177 | Tsifier.prototype.addFiles = function (files) { 178 | var self = this; 179 | files.forEach(function (file) { 180 | self.host._addFile(file, true); 181 | }); 182 | }; 183 | 184 | Tsifier.prototype.compile = function () { 185 | var self = this; 186 | 187 | var createProgram_t0 = time.start(); 188 | var program = self.host._compile(self.opts); 189 | time.stop(createProgram_t0, 'createProgram'); 190 | 191 | var syntaxDiagnostics = self.checkSyntax(program); 192 | if (syntaxDiagnostics.length) { 193 | log('Compilation encountered fatal syntax errors'); 194 | return; 195 | } 196 | 197 | var semanticDiagnostics = self.checkSemantics(program); 198 | if (semanticDiagnostics.length && self.opts.noEmitOnError) { 199 | log('Compilation encountered fatal semantic errors'); 200 | return; 201 | } 202 | 203 | var emit_t0 = time.start(); 204 | var emitOutput = program.emit(); 205 | time.stop(emit_t0, 'emit program'); 206 | 207 | var emittedDiagnostics = self.checkEmittedOutput(emitOutput); 208 | if (emittedDiagnostics.length && self.opts.noEmitOnError) { 209 | log('Compilation encountered fatal errors during emit'); 210 | return; 211 | } 212 | 213 | log('Compilation completed without errors'); 214 | }; 215 | 216 | Tsifier.prototype.checkSyntax = function (program) { 217 | var self = this; 218 | 219 | var syntaxCheck_t0 = time.start(); 220 | var syntaxDiagnostics = program.getSyntacticDiagnostics(); 221 | time.stop(syntaxCheck_t0, 'syntax checking'); 222 | 223 | syntaxDiagnostics.forEach(function (error) { 224 | self.emit('error', new CompileError(error)); 225 | }); 226 | 227 | if (syntaxDiagnostics.length) { 228 | self.host.error = true; 229 | } 230 | return syntaxDiagnostics; 231 | }; 232 | 233 | Tsifier.prototype.checkSemantics = function (program) { 234 | var self = this; 235 | 236 | var semanticDiagnostics_t0 = time.start(); 237 | var semanticDiagnostics = program.getGlobalDiagnostics(); 238 | if (semanticDiagnostics.length === 0) { 239 | semanticDiagnostics = program.getSemanticDiagnostics(); 240 | } 241 | time.stop(semanticDiagnostics_t0, 'semantic checking'); 242 | 243 | semanticDiagnostics.forEach(function (error) { 244 | self.emit('error', new CompileError(error)); 245 | }); 246 | 247 | if (semanticDiagnostics.length && self.opts.noEmitOnError) { 248 | self.host.error = true; 249 | } 250 | 251 | return semanticDiagnostics; 252 | }; 253 | 254 | Tsifier.prototype.checkEmittedOutput = function (emitOutput) { 255 | var self = this; 256 | 257 | var emittedDiagnostics = emitOutput.diagnostics; 258 | emittedDiagnostics.forEach(function (error) { 259 | self.emit('error', new CompileError(error)); 260 | }); 261 | 262 | if (emittedDiagnostics.length && self.opts.noEmitOnError) { 263 | self.host.error = true; 264 | } 265 | 266 | return emittedDiagnostics; 267 | }; 268 | 269 | Tsifier.prototype.transform = function (file) { 270 | var self = this; 271 | 272 | trace('Transforming %s', file); 273 | 274 | if (self.ignoredFiles.indexOf(file) !== -1) { 275 | return through(); 276 | } 277 | 278 | if (isTypescriptDeclaration(file)) { 279 | return through(transform); 280 | } 281 | 282 | if (isTypescript(file) || (isJavascript(file) && self.opts.allowJs)) { 283 | return through(transform, flush); 284 | } 285 | 286 | return through(); 287 | 288 | function transform(chunk, enc, next) { 289 | next(); 290 | } 291 | function flush(next) { 292 | if (self.host.error) { 293 | next(); 294 | return; 295 | } 296 | 297 | var compiled = self.getCompiledFile(file); 298 | if (compiled) { 299 | this.push(compiled); 300 | } 301 | this.push(null); 302 | next(); 303 | } 304 | }; 305 | 306 | Tsifier.prototype.getCompiledFile = function (inputFile, alreadyMissedCache) { 307 | var self = this; 308 | var outputExtension = (ts.JsxEmit && self.opts.jsx === ts.JsxEmit.Preserve && isTsx(inputFile)) ? '.jsx' : '.js'; 309 | var output = self.host._output(replaceFileExtension(inputFile, outputExtension)); 310 | 311 | if (output === undefined) { 312 | if (alreadyMissedCache) { 313 | self.emit('error', new Error('tsify: no compiled file for ' + inputFile)); 314 | return; 315 | } 316 | self.generateCache([inputFile]); 317 | if (self.host.error) 318 | return; 319 | return self.getCompiledFile(inputFile, true); 320 | } 321 | 322 | if (self.opts.inlineSourceMap) { 323 | output = self.setSourcePathInSourcemap(output, inputFile); 324 | } 325 | return output; 326 | }; 327 | 328 | Tsifier.prototype.setSourcePathInSourcemap = function (output, inputFile) { 329 | var self = this; 330 | var normalized = ts.normalizePath(path.relative( 331 | self.bopts.basedir || currentDirectory, 332 | inputFile 333 | )); 334 | 335 | var sourcemap = convert.fromComment(output); 336 | sourcemap.setProperty('sources', [normalized]); 337 | return output.replace(convert.commentRegex, sourcemap.toComment()); 338 | } 339 | 340 | var result = Tsifier; 341 | result.isTypescript = isTypescript; 342 | result.isTypescriptDeclaration = isTypescriptDeclaration; 343 | return result; 344 | }; 345 | -------------------------------------------------------------------------------- /lib/time.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var log = require('util').debuglog(require('../package').name); 4 | 5 | function start() { 6 | return process.hrtime(); 7 | } 8 | function stop(t0, message) { 9 | var tDiff = process.hrtime(t0); 10 | log('%d sec -- %s', (tDiff[0] + (tDiff[1] / 1000000000)).toFixed(4), message); 11 | } 12 | 13 | module.exports = { start: start, stop: stop }; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsify", 3 | "version": "5.0.4", 4 | "description": "Browserify plugin for compiling Typescript", 5 | "main": "index.js", 6 | "types": "index.d.ts", 7 | "scripts": { 8 | "lint": "eslint .", 9 | "test-latest": "node test/test.js", 10 | "test": "tav" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com/TypeStrong/tsify" 15 | }, 16 | "keywords": [ 17 | "browserify", 18 | "browserify-plugin", 19 | "typescript" 20 | ], 21 | "author": "Greg Smith", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/TypeStrong/tsify/issues" 25 | }, 26 | "homepage": "https://github.com/TypeStrong/tsify", 27 | "engines": { 28 | "node": ">=0.12" 29 | }, 30 | "dependencies": { 31 | "convert-source-map": "^1.1.0", 32 | "fs.realpath": "^1.0.0", 33 | "object-assign": "^4.1.0", 34 | "semver": "^6.1.0", 35 | "through2": "^2.0.0", 36 | "tsconfig": "^5.0.3" 37 | }, 38 | "devDependencies": { 39 | "babel-core": "^6.26.3", 40 | "babel-preset-react": "^6.5.0", 41 | "babelify": "^8.0.0", 42 | "browserify": "^16.2.3", 43 | "eslint": "^4.6.1", 44 | "event-stream": "^3.3.1", 45 | "fs-extra": "^5.0.0", 46 | "node-foo": "^0.2.3", 47 | "source-map": "^0.5.3", 48 | "string-to-stream": "^1.1.1", 49 | "tape": "^4.10.1", 50 | "test-all-versions": "^3.3.3", 51 | "typescript": "~2.0.3", 52 | "watchify": "^3.11.1" 53 | }, 54 | "peerDependencies": { 55 | "browserify": ">= 10.x", 56 | "typescript": ">= 2.8" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/allowJs/x.ts: -------------------------------------------------------------------------------- 1 | import y from './y'; 2 | import z from './z'; 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/allowJs/y.js: -------------------------------------------------------------------------------- 1 | export default function fn(message) { 2 | console.log(message); 3 | } 4 | -------------------------------------------------------------------------------- /test/allowJs/z.js: -------------------------------------------------------------------------------- 1 | export default function fn(n) { 2 | return n * 111; 3 | } 4 | -------------------------------------------------------------------------------- /test/declarationFile/interface.d.ts: -------------------------------------------------------------------------------- 1 | interface IThing { 2 | thing1: string; 3 | thing2: string; 4 | } 5 | -------------------------------------------------------------------------------- /test/declarationFile/tsconfig.custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": ["interface.d.ts"] 3 | } 4 | -------------------------------------------------------------------------------- /test/declarationFile/x.ts: -------------------------------------------------------------------------------- 1 | var x: IThing = { thing1: 'Doctor', thing2: 'Seuss' }; 2 | console.log(x.thing1); 3 | console.log(x.thing2); 4 | -------------------------------------------------------------------------------- /test/emptyOutput/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "noImplicitUseStrict": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/emptyOutput/x.ts: -------------------------------------------------------------------------------- 1 | export interface X {} 2 | -------------------------------------------------------------------------------- /test/externalDeps/node-foo.d.ts: -------------------------------------------------------------------------------- 1 | declare module "node-foo" { 2 | export function foo_aaa(str: string): string; 3 | export function foo_bbb(str: string): string; 4 | export function foo_ccc(str: string): string; 5 | } 6 | -------------------------------------------------------------------------------- /test/externalDeps/x.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import foo = require('node-foo'); 4 | console.log(foo.foo_aaa('this')); 5 | console.log(foo.foo_bbb('is a')); 6 | console.log(foo.foo_ccc('test')); 7 | -------------------------------------------------------------------------------- /test/filesOutsideCwd/cwd/x.ts: -------------------------------------------------------------------------------- 1 | import y from '../shared/y'; 2 | import z from '../shared/z'; 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/filesOutsideCwd/shared/y.ts: -------------------------------------------------------------------------------- 1 | export default function fn(message: string) { 2 | console.log(message); 3 | } 4 | -------------------------------------------------------------------------------- /test/filesOutsideCwd/shared/z.ts: -------------------------------------------------------------------------------- 1 | export default function fn(n: number) { 2 | return n*111; 3 | } 4 | -------------------------------------------------------------------------------- /test/globalTransform/a.ts: -------------------------------------------------------------------------------- 1 | import b from "b"; 2 | console.log(b); 3 | -------------------------------------------------------------------------------- /test/globalTransform/node_modules/b.ts: -------------------------------------------------------------------------------- 1 | const b = 'Hello from B!' 2 | export default b; 3 | -------------------------------------------------------------------------------- /test/multipleConfigs/nested/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "noEmitOnError": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/multipleConfigs/nested/x.ts: -------------------------------------------------------------------------------- 1 | var x; 2 | x = 3; 3 | console.log(x); 4 | -------------------------------------------------------------------------------- /test/multipleConfigs/tsconfig.custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "noEmitOnError": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/multipleConfigs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": false, 4 | "noEmitOnError": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/multipleEntryPoints/x1.ts: -------------------------------------------------------------------------------- 1 | import y = require('./y'); 2 | import z = require('./z'); 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/multipleEntryPoints/x2.ts: -------------------------------------------------------------------------------- 1 | import y = require('./y'); 2 | import z = require('./z'); 3 | y('goodbye world'); 4 | y(z(5).toString()); 5 | -------------------------------------------------------------------------------- /test/multipleEntryPoints/y.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(message: string) { 3 | console.log(message); 4 | } -------------------------------------------------------------------------------- /test/multipleEntryPoints/z.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(n: number) { 3 | return n*111; 4 | } -------------------------------------------------------------------------------- /test/noArguments/x.ts: -------------------------------------------------------------------------------- 1 | import y from './y'; 2 | import z from './z'; 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/noArguments/y.ts: -------------------------------------------------------------------------------- 1 | export default function fn(message: string) { 2 | console.log(message); 3 | } 4 | -------------------------------------------------------------------------------- /test/noArguments/z.ts: -------------------------------------------------------------------------------- 1 | export default function fn(n: number) { 2 | return n*111; 3 | } 4 | -------------------------------------------------------------------------------- /test/sharedTsconfig/project/x.ts: -------------------------------------------------------------------------------- 1 | var x: IThing = { thing1: 'Doctor', thing2: 'Seuss' }; 2 | console.log(x.thing1); 3 | console.log(x.thing2); 4 | -------------------------------------------------------------------------------- /test/sharedTsconfig/shared/interface.d.ts: -------------------------------------------------------------------------------- 1 | interface IThing { 2 | thing1: string; 3 | thing2: string; 4 | } 5 | -------------------------------------------------------------------------------- /test/sharedTsconfig/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": ["shared/interface.d.ts"] 3 | } 4 | -------------------------------------------------------------------------------- /test/syntaxError/x.ts: -------------------------------------------------------------------------------- 1 | import y; 2 | import z; 3 | y('hello world'); 4 | y(z(2).toString()); -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | 5 | var browserify = require('browserify'); 6 | var convert = require('convert-source-map'); 7 | var es = require('event-stream'); 8 | var extend = require('util')._extend; 9 | var EventEmitter = require('events').EventEmitter; 10 | var fs = require('fs-extra'); 11 | var os = require('os'); 12 | var path = require('path'); 13 | var semver = require('semver'); 14 | var sm = require('source-map'); 15 | var stringToStream = require('string-to-stream'); 16 | var typescript = require('typescript'); 17 | var vm = require('vm'); 18 | var watchify = require('watchify'); 19 | 20 | var tsify = require('..'); 21 | var Host = require('../lib/Host')(typescript); 22 | 23 | var buildTimeout = 8000; 24 | 25 | // Tests 26 | 27 | test('host', function (t) { 28 | 29 | var compilerHost = typescript.createCompilerHost({}); 30 | var methods = Object.keys(compilerHost).filter(function (method) { 31 | return typeof compilerHost[method] === "function"; 32 | }); 33 | 34 | var ignore = ['getDefaultLibLocation']; 35 | methods.forEach(function (method) { 36 | if (ignore.indexOf(method) === -1) { 37 | t.assert(Host.prototype[method], 'implements ' + method); 38 | } 39 | }); 40 | t.end(); 41 | }); 42 | 43 | test('no arguments', function (t) { 44 | run({ 45 | bOpts: { entries: ['./test/noArguments/x.ts'] } 46 | }, function (errors, actual) { 47 | expectNoErrors(t, errors); 48 | expectConsoleOutputFromScript(t, actual, [ 49 | 'hello world', 50 | '222' 51 | ]); 52 | expectMappedToken(t, 'test/noArguments/x.ts', actual, '\'hello world\''); 53 | expectMappedToken(t, 'test/noArguments/y.ts', actual, 'console.log(message)'); 54 | expectMappedToken(t, 'test/noArguments/z.ts', actual, '111'); 55 | t.end(); 56 | }); 57 | }); 58 | 59 | test('basedir', function (t) { 60 | run({ 61 | bOpts: { basedir: 'test', entries: ['./noArguments/x.ts'] } 62 | }, function (errors, actual) { 63 | expectNoErrors(t, errors); 64 | expectConsoleOutputFromScript(t, actual, [ 65 | 'hello world', 66 | '222' 67 | ]); 68 | expectMappedToken(t, 'test/noArguments/x.ts', 'noArguments/x.ts', actual, '\'hello world\''); 69 | expectMappedToken(t, 'test/noArguments/y.ts', 'noArguments/y.ts', actual, 'console.log(message)'); 70 | expectMappedToken(t, 'test/noArguments/z.ts', 'noArguments/z.ts', actual, '111'); 71 | t.end(); 72 | }); 73 | }); 74 | 75 | test('late added entries', function (t) { 76 | run({ 77 | beforeBundle: function (b) { b.add('./test/noArguments/x.ts'); } 78 | }, function (errors, actual) { 79 | expectNoErrors(t, errors); 80 | expectConsoleOutputFromScript(t, actual, [ 81 | 'hello world', 82 | '222' 83 | ]); 84 | expectMappedToken(t, 'test/noArguments/x.ts', actual, '\'hello world\''); 85 | expectMappedToken(t, 'test/noArguments/y.ts', actual, 'console.log(message)'); 86 | expectMappedToken(t, 'test/noArguments/z.ts', actual, '111'); 87 | t.end(); 88 | }); 89 | }); 90 | 91 | test('full path includes', function (t) { 92 | run({ 93 | bOpts: { entries: [path.resolve('./test/noArguments/x.ts')] } 94 | }, function (errors, actual) { 95 | expectNoErrors(t, errors); 96 | expectConsoleOutputFromScript(t, actual, [ 97 | 'hello world', 98 | '222' 99 | ]); 100 | expectMappedToken(t, 'test/noArguments/x.ts', actual, '\'hello world\''); 101 | expectMappedToken(t, 'test/noArguments/y.ts', actual, 'console.log(message)'); 102 | expectMappedToken(t, 'test/noArguments/z.ts', actual, '111'); 103 | t.end(); 104 | }); 105 | }); 106 | 107 | test('non-TS main file', function (t) { 108 | run({ 109 | bOpts: { entries: ['./test/withJsRoot/x.js'] } 110 | }, function (errors, actual) { 111 | expectNoErrors(t, errors); 112 | expectConsoleOutputFromScript(t, actual, [ 113 | 'hello world', 114 | '222' 115 | ]); 116 | expectMappedToken(t, 'test/withJsRoot/x.js', actual, 'y(\'hello world\')'); 117 | expectMappedToken(t, 'test/withJsRoot/y.ts', actual, 'console.log(message)'); 118 | expectMappedToken(t, 'test/withJsRoot/z.ts', actual, '111'); 119 | t.end(); 120 | }); 121 | }); 122 | 123 | test('non-TS main file and nested dependencies', function (t) { 124 | 125 | // The workaround mentioned in issue #148 - an empty TS file in the root - 126 | // is no longer required. 127 | 128 | process.chdir('./test/withJsRootAndNestedDeps'); 129 | run({ 130 | bOpts: { entries: ['./x.js'] } 131 | }, function (errors, actual) { 132 | expectNoErrors(t, errors); 133 | expectConsoleOutputFromScript(t, actual, [ 134 | 'hello world', 135 | '222' 136 | ]); 137 | expectMappedToken(t, 'nested/y.ts', actual, 'console.log(message)'); 138 | expectMappedToken(t, 'nested/twice/z.ts', actual, '111'); 139 | process.chdir('../..'); 140 | t.end(); 141 | }); 142 | }); 143 | 144 | test('with adjacent compiled files', function (t) { 145 | run({ 146 | bOpts: { entries: ['./test/withAdjacentCompiledFiles/x.ts'] } 147 | }, function (errors, actual) { 148 | expectNoErrors(t, errors); 149 | expectConsoleOutputFromScript(t, actual, [ 150 | 'hello world', 151 | '222' 152 | ]); 153 | expectMappedToken(t, 'test/withAdjacentCompiledFiles/x.ts', actual, '\'hello world\''); 154 | expectMappedToken(t, 'test/withAdjacentCompiledFiles/y.ts', actual, 'console.log(message)'); 155 | expectMappedToken(t, 'test/withAdjacentCompiledFiles/z.ts', actual, '111'); 156 | t.end(); 157 | }); 158 | }); 159 | 160 | test('with tsconfig.json', function (t) { 161 | process.chdir('./test/tsconfig'); 162 | run({ 163 | bOpts: { entries: ['./x.ts'] }, 164 | tsifyOpts: { noEmitOnError: false } 165 | }, function (errors, actual) { 166 | expectErrors(t, errors, [{ name: 'TS7005', line: 1, column: 5, file: 'x.ts' }]); 167 | expectConsoleOutputFromScript(t, actual, [3]); 168 | process.chdir('../..'); 169 | t.end(); 170 | }); 171 | }); 172 | 173 | test('with tsconfig via project option', function (t) { 174 | process.chdir('./test/tsconfig'); 175 | var project = { 176 | compilerOptions: { 177 | noImplicitAny: false 178 | } 179 | }; 180 | run({ 181 | bOpts: { entries: ['./x.ts'] }, 182 | tsifyOpts: { project: project } 183 | }, function (errors, actual) { 184 | expectNoErrors(t, errors); 185 | expectConsoleOutputFromScript(t, actual, [3]); 186 | process.chdir('../..'); 187 | t.end(); 188 | }); 189 | }); 190 | 191 | test('exclude setting in tsconfig.json', function (t) { 192 | process.chdir('./test/tsconfigExclude'); 193 | run({ 194 | bOpts: { entries: ['./x.ts'] } 195 | }, function (errors, actual) { 196 | expectNoErrors(t, errors); 197 | expectConsoleOutputFromScript(t, actual, [ 198 | 'Doctor', 199 | 'Seuss' 200 | ]); 201 | expectMappedToken(t, 'x.ts', actual, 'x.thing1'); 202 | process.chdir('../..'); 203 | t.end(); 204 | }); 205 | }); 206 | 207 | test('with multiple tsconfig.jsons (or is it tsconfigs.json?), finding default config', function (t) { 208 | process.chdir('./test/multipleConfigs'); 209 | run({ 210 | bOpts: { entries: ['./nested/x.ts'] }, 211 | tsifyOpts: { noEmitOnError: false } 212 | }, function (errors, actual) { 213 | expectNoErrors(t, errors); 214 | expectConsoleOutputFromScript(t, actual, [3]); 215 | process.chdir('../..'); 216 | t.end(); 217 | }); 218 | }); 219 | 220 | test('with multiple tsconfig.jsons (or is it tsconfigs.json?) using project file', function (t) { 221 | process.chdir('./test/multipleConfigs'); 222 | run({ 223 | bOpts: { entries: ['./nested/x.ts'] }, 224 | tsifyOpts: { noEmitOnError: false, project: 'tsconfig.custom.json' } 225 | }, function (errors, actual) { 226 | expectErrors(t, errors, [{ name: 'TS7005', line: 1, column: 5, file: 'nested/x.ts' }]); 227 | expectConsoleOutputFromScript(t, actual, [3]); 228 | process.chdir('../..'); 229 | t.end(); 230 | }); 231 | }); 232 | 233 | // This behavior relies on the fix in Microsoft/Typescript#2965 to work correctly 234 | if (semver.gte(require('typescript').version, '1.9.0-dev')) { 235 | test('with multiple tsconfig.jsons (or is it tsconfigs.json?) using project dir', function (t) { 236 | process.chdir('./test/multipleConfigs'); 237 | run({ 238 | bOpts: { entries: ['./nested/x.ts'] }, 239 | tsifyOpts: { noEmitOnError: false, project: 'nested' } 240 | }, function (errors, actual) { 241 | expectErrors(t, errors, [{ name: 'TS7005', line: 1, column: 5, file: 'nested/x.ts' }]); 242 | expectConsoleOutputFromScript(t, actual, [3]); 243 | process.chdir('../..'); 244 | t.end(); 245 | }); 246 | }); 247 | 248 | test('with multiple tsconfig.jsons (or is it tsconfigs.json?) using basedir', function (t) { 249 | process.chdir('./test/multipleConfigs'); 250 | run({ 251 | bOpts: { basedir: 'nested', entries: ['./x.ts'] }, 252 | tsifyOpts: { noEmitOnError: false } 253 | }, function (errors, actual) { 254 | expectErrors(t, errors, [{ name: 'TS7005', line: 1, column: 5, file: 'nested/x.ts' }]); 255 | expectConsoleOutputFromScript(t, actual, [3]); 256 | process.chdir('../..'); 257 | t.end(); 258 | }); 259 | }); 260 | } 261 | 262 | test('allowJs', function (t) { 263 | run({ 264 | bOpts: { entries: ['./test/allowJs/x.ts'] }, 265 | tsifyOpts: { allowJs: true } 266 | }, function (errors, actual) { 267 | expectNoErrors(t, errors); 268 | expectConsoleOutputFromScript(t, actual, [ 269 | 'hello world', 270 | '222' 271 | ]); 272 | expectMappedToken(t, 'test/allowJs/x.ts', actual, '\'hello world\''); 273 | expectMappedToken(t, 'test/allowJs/y.js', actual, 'console.log(message)'); 274 | expectMappedToken(t, 'test/allowJs/z.js', actual, '111'); 275 | t.end(); 276 | }); 277 | }); 278 | 279 | test('with nested dependencies', function (t) { 280 | run({ 281 | bOpts: { entries: ['./test/withNestedDeps/x.ts'] } 282 | }, function (errors, actual) { 283 | expectNoErrors(t, errors); 284 | expectConsoleOutputFromScript(t, actual, [ 285 | 'hello world', 286 | '222' 287 | ]); 288 | expectMappedToken(t, 'test/withNestedDeps/x.ts', actual, '\'hello world\''); 289 | expectMappedToken(t, 'test/withNestedDeps/nested/y.ts', actual, 'console.log(message)'); 290 | expectMappedToken(t, 'test/withNestedDeps/nested/twice/z.ts', actual, '111'); 291 | t.end(); 292 | }); 293 | }); 294 | 295 | test('syntax error', function (t) { 296 | run({ 297 | bOpts: { entries: ['./test/syntaxError/x.ts'] } 298 | }, function (errors, actual) { 299 | var fileName = Host._getCanonicalFileName('test/syntaxError/x.ts'); 300 | expectErrors(t, errors, [ 301 | { name: 'TS1005', line: 1, column: 9, file: fileName }, 302 | { name: 'TS1005', line: 2, column: 9, file: fileName } 303 | ]); 304 | t.end(); 305 | }); 306 | }); 307 | 308 | test('type error', function (t) { 309 | run({ 310 | bOpts: { entries: ['./test/typeError/x.ts'] } 311 | }, function (errors, actual) { 312 | var fileName = Host._getCanonicalFileName('test/typeError/x.ts'); 313 | expectErrors(t, errors, [ 314 | { name: 'TS2345', line: 4, column: 3, file: fileName } 315 | ]); 316 | expectConsoleOutputFromScript(t, actual, [ 317 | 'hello world', 318 | 222 319 | ]); 320 | expectMappedToken(t, 'test/typeError/x.ts', actual, '\'hello world\''); 321 | expectMappedToken(t, 'test/typeError/y.ts', actual, 'console.log(message)'); 322 | expectMappedToken(t, 'test/typeError/z.ts', actual, '111'); 323 | t.end(); 324 | }); 325 | }); 326 | 327 | test('type error with noEmitOnError', function (t) { 328 | run({ 329 | bOpts: { entries: ['./test/typeError/x.ts'] }, 330 | tsifyOpts: { noEmitOnError: true } 331 | }, function (errors, actual) { 332 | var fileName = Host._getCanonicalFileName('test/typeError/x.ts'); 333 | expectErrors(t, errors, [ 334 | { name: 'TS2345', line: 4, column: 3, file: fileName } 335 | ]); 336 | t.end(); 337 | }); 338 | }); 339 | 340 | test('multiple entry points', function (t) { 341 | run({ 342 | bOpts: { entries: ['./test/multipleEntryPoints/x1.ts', './test/multipleEntryPoints/x2.ts'] } 343 | }, function (errors, actual) { 344 | expectNoErrors(t, errors); 345 | expectConsoleOutputFromScript(t, actual, [ 346 | 'hello world', 347 | '222', 348 | 'goodbye world', 349 | '555' 350 | ]); 351 | expectMappedToken(t, 'test/multipleEntryPoints/x1.ts', actual, '\'hello world\''); 352 | expectMappedToken(t, 'test/multipleEntryPoints/x2.ts', actual, '\'goodbye world\''); 353 | expectMappedToken(t, 'test/multipleEntryPoints/y.ts', actual, 'console.log(message)'); 354 | expectMappedToken(t, 'test/multipleEntryPoints/z.ts', actual, '111'); 355 | t.end(); 356 | }); 357 | }); 358 | 359 | test('late added entries with multiple entry points', function (t) { 360 | run({ 361 | beforeBundle: function (b) { 362 | b.add('./test/multipleEntryPoints/x1.ts'); 363 | b.add('./test/multipleEntryPoints/x2.ts'); 364 | } 365 | }, function (errors, actual) { 366 | expectNoErrors(t, errors); 367 | expectConsoleOutputFromScript(t, actual, [ 368 | 'hello world', 369 | '222', 370 | 'goodbye world', 371 | '555' 372 | ]); 373 | expectMappedToken(t, 'test/multipleEntryPoints/x1.ts', actual, '\'hello world\''); 374 | expectMappedToken(t, 'test/multipleEntryPoints/x2.ts', actual, '\'goodbye world\''); 375 | expectMappedToken(t, 'test/multipleEntryPoints/y.ts', actual, 'console.log(message)'); 376 | expectMappedToken(t, 'test/multipleEntryPoints/z.ts', actual, '111'); 377 | t.end(); 378 | }); 379 | }); 380 | 381 | test('including .d.ts file', function (t) { 382 | run({ 383 | bOpts: { entries: ['./test/declarationFile/x.ts', './test/declarationFile/interface.d.ts'] } 384 | }, function (errors, actual) { 385 | expectNoErrors(t, errors); 386 | expectConsoleOutputFromScript(t, actual, [ 387 | 'Doctor', 388 | 'Seuss' 389 | ]); 390 | expectMappedToken(t, 'test/declarationFile/x.ts', actual, 'x.thing1'); 391 | t.end(); 392 | }); 393 | }); 394 | 395 | test('including .d.ts file via tsconfig', function (t) { 396 | run({ 397 | bOpts: { entries: ['./test/declarationFile/x.ts'] }, 398 | tsifyOpts: { project: './test/declarationFile/tsconfig.custom.json' } 399 | }, function (errors, actual) { 400 | expectNoErrors(t, errors); 401 | expectConsoleOutputFromScript(t, actual, [ 402 | 'Doctor', 403 | 'Seuss' 404 | ]); 405 | expectMappedToken(t, 'test/declarationFile/x.ts', actual, 'x.thing1'); 406 | t.end(); 407 | }); 408 | }); 409 | 410 | test('with shared tsconfig.json in higher directory', function (t) { 411 | process.chdir('./test/sharedTsconfig/project'); 412 | run({ 413 | bOpts: { entries: ['./x.ts'] } 414 | }, function (errors, actual) { 415 | expectNoErrors(t, errors); 416 | expectConsoleOutputFromScript(t, actual, [ 417 | 'Doctor', 418 | 'Seuss' 419 | ]); 420 | expectMappedToken(t, 'x.ts', actual, 'x.thing1'); 421 | process.chdir('../../..'); 422 | t.end(); 423 | }); 424 | }); 425 | 426 | test('with files outside cwd', function (t) { 427 | process.chdir('./test/filesOutsideCwd/cwd'); 428 | run({ 429 | bOpts: { entries: ['./x.ts'] } 430 | }, function (errors, actual) { 431 | expectNoErrors(t, errors); 432 | expectConsoleOutputFromScript(t, actual, [ 433 | 'hello world', 434 | '222' 435 | ]); 436 | expectMappedToken(t, 'x.ts', actual, '\'hello world\''); 437 | expectMappedToken(t, '../shared/y.ts', actual, 'console.log(message)'); 438 | expectMappedToken(t, '../shared/z.ts', actual, '111'); 439 | process.chdir('../../..'); 440 | t.end(); 441 | }); 442 | }); 443 | 444 | test('including external dependencies', function (t) { 445 | run({ 446 | bOpts: { entries: ['./test/externalDeps/x.ts'] } 447 | }, function (errors, actual) { 448 | expectNoErrors(t, errors); 449 | expectConsoleOutputFromScript(t, actual, [ 450 | 'node-foo aaa:this', 451 | 'node-foo bbb:is a', 452 | 'node-foo ccc:test' 453 | ]); 454 | expectMappedToken(t, 'test/externalDeps/x.ts', actual, '\'is a\''); 455 | t.end(); 456 | }); 457 | }); 458 | 459 | test('jsx: react', function (t) { 460 | run({ 461 | bOpts: { entries: './test/tsx/main.ts' }, 462 | tsifyOpts: { jsx: 'react' } 463 | }, function (errors, actual) { 464 | expectNoErrors(t, errors); 465 | expectConsoleOutputFromScript(t, actual, [ 466 | 'div with contents: This is a cool component' 467 | ]); 468 | expectMappedToken(t, 'test/tsx/CoolComponent.tsx', actual, 'div'); 469 | t.end(); 470 | }); 471 | }); 472 | 473 | test('jsx: preserve with babelify', function (t) { 474 | run({ 475 | bOpts: { entries: ['./test/tsx/main.ts'] }, 476 | tsifyOpts: { jsx: 'preserve' }, 477 | beforeBundle: function (b) { b.transform('babelify', { presets: ['react'], extensions: ['.tsx'] }) } 478 | }, function (errors, actual) { 479 | expectNoErrors(t, errors); 480 | expectConsoleOutputFromScript(t, actual, [ 481 | 'div with contents: This is a cool component' 482 | ]); 483 | t.end(); 484 | }); 485 | }); 486 | 487 | test('global transform', function (t) { 488 | run({ 489 | bOpts: { entries: ['./test/globalTransform/a.ts'] }, 490 | tsifyOpts: { global: true } 491 | }, function (errors, actual) { 492 | expectNoErrors(t, errors); 493 | expectConsoleOutputFromScript(t, actual, [ 494 | 'Hello from B!' 495 | ]); 496 | t.end(); 497 | }); 498 | }); 499 | 500 | test('watchify', function (t) { 501 | process.chdir('./test/watchify'); 502 | fs.copySync('./ok.ts', './.tmp.ts'); 503 | runWatchify({ 504 | beforeBundle: function (b) { b.add('./main.ts') } 505 | }, [ 506 | function (errors, actual, triggerChange) { 507 | t.deepEqual(errors, [], 'Should have no compilation errors'); 508 | fs.copySync('./typeError.ts', './.tmp.ts'); 509 | triggerChange(); 510 | }, 511 | function (errors, actual, triggerChange) { 512 | t.ok(errors.length > 0, 'Should have type errors'); 513 | fs.copySync('./syntaxError.ts', './tmp.ts'); 514 | triggerChange(); 515 | }, 516 | function (errors, actual, triggerChange) { 517 | t.ok(errors.length > 0, 'Should have syntax errors'); 518 | fs.copySync('./ok.ts', './.tmp.ts'); 519 | triggerChange(); 520 | }, 521 | function (errors, actual, triggerChange, b) { 522 | t.deepEqual(errors, [], 'Should have no compilation errors'); 523 | b.close(); 524 | process.chdir('../..'); 525 | t.end(); 526 | } 527 | ]); 528 | }); 529 | 530 | test('with custom compiler', function (t) { 531 | var ts = extend({}, require('typescript')); 532 | var oldCreateSourceFile = ts.createSourceFile; 533 | ts.createSourceFile = function (filename, text, languageVersion, version) { 534 | if (/x\.ts/.test(filename)) { 535 | text = 'console.log("Custom compiler was used");' + os.EOL + text; 536 | } 537 | return oldCreateSourceFile.call(ts, filename, text, languageVersion, version); 538 | } 539 | 540 | run({ 541 | bOpts: { entries: ['./test/noArguments/x.ts'] }, 542 | tsifyOpts: { typescript: ts } 543 | }, function (errors, actual) { 544 | expectNoErrors(t, errors); 545 | expectConsoleOutputFromScript(t, actual, [ 546 | 'Custom compiler was used', 547 | 'hello world', 548 | '222' 549 | ]); 550 | t.end(); 551 | }); 552 | }); 553 | 554 | test('with empty output', function (t) { 555 | process.chdir('./test/emptyOutput'); 556 | run({ 557 | bOpts: { debug: false, entries: ['./x.ts'] }, 558 | tsifyOpts: {} 559 | }, function (errors) { 560 | expectNoErrors(t, errors); 561 | process.chdir('../..'); 562 | t.end(); 563 | }); 564 | }); 565 | 566 | test('with overriden excludes', function (t) { 567 | process.chdir('./test/withFileOverrides'); 568 | run({ 569 | bOpts: { entries: ['./index.ts'] }, 570 | tsifyOpts: { exclude: [] } 571 | }, function (errors, actual, files) { 572 | expectNoErrors(t, errors); 573 | expectFiles(t, files, { 574 | 'foo.ts': true, 575 | 'bar.ts': true, 576 | 'bar-exam.ts': true, 577 | 'bar-tender.ts': true, 578 | 'index.ts': true 579 | }); 580 | process.chdir('../..'); 581 | t.end(); 582 | }); 583 | }); 584 | 585 | test('with overriden files', function (t) { 586 | process.chdir('./test/withFileOverrides'); 587 | run({ 588 | bOpts: { entries: ['./index.ts'] }, 589 | tsifyOpts: { files: [] } 590 | }, function (errors, actual, files) { 591 | expectNoErrors(t, errors); 592 | expectFiles(t, files, { 593 | 'foo.ts': false, 594 | 'bar.ts': false, 595 | 'bar-exam.ts': false, 596 | 'bar-tender.ts': true, 597 | 'index.ts': true 598 | }); 599 | process.chdir('../..'); 600 | t.end(); 601 | }); 602 | }); 603 | 604 | test('with overriden includes', function (t) { 605 | process.chdir('./test/withFileOverrides'); 606 | run({ 607 | bOpts: { entries: ['./index.ts'] }, 608 | tsifyOpts: { include: [] } 609 | }, function (errors, actual, files) { 610 | expectNoErrors(t, errors); 611 | expectFiles(t, files, { 612 | 'foo.ts': true, 613 | 'bar.ts': true, 614 | 'bar-exam.ts': false, 615 | 'bar-tender.ts': false, 616 | 'index.ts': true 617 | }); 618 | process.chdir('../..'); 619 | t.end(); 620 | }); 621 | }); 622 | 623 | test('with required stream', function (t) { 624 | process.chdir('./test/withRequiredStream'); 625 | run({ 626 | bOpts: { debug: false, entries: ['./x.ts'] }, 627 | tsifyOpts: { allowJs: true }, 628 | beforeBundle: function (b) { 629 | b.exclude('streamed'); 630 | b.require(stringToStream('exports.name = "streamed";'), { expose: 'streamed', basedir: './' }); 631 | } 632 | }, function (errors, actual) { 633 | expectNoErrors(t, errors); 634 | expectConsoleOutputFromScript(t, actual, [ 635 | 'streamed' 636 | ]); 637 | process.chdir('../..'); 638 | t.end(); 639 | }); 640 | }); 641 | 642 | // Test helpers 643 | 644 | function run(config, cb) { 645 | var bOpts = config.bOpts || {}; 646 | if (bOpts.debug === undefined) { 647 | bOpts.debug = true; 648 | } 649 | 650 | var tsifyOpts = config.tsifyOpts || {}; 651 | var beforeBundle = config.beforeBundle || function() {}; 652 | 653 | var files = [] 654 | var b = browserify(bOpts) 655 | .on('file', function (file) { 656 | files.push(file); 657 | }) 658 | .plugin(tsify, tsifyOpts); 659 | beforeBundle(b); 660 | 661 | var calledBack = false; 662 | var errors = []; 663 | b.bundle() 664 | .on('error', function (error) { 665 | errors.push(error); 666 | }) 667 | .pipe(es.wait(function (err, actual) { 668 | if (calledBack) 669 | throw new Error('Bundling completed after build timeout expired'); 670 | calledBack = true; 671 | cb(errors, actual.toString(), files); 672 | })); 673 | 674 | setTimeout(function () { 675 | if (calledBack) 676 | return; 677 | calledBack = true; 678 | cb(errors, null, null); 679 | }, buildTimeout); 680 | } 681 | 682 | function runWatchify(config, handlers) { 683 | var bOpts = config.bOpts || {}; 684 | bOpts.debug = true; 685 | 686 | var tsifyOpts = config.tsifyOpts || {}; 687 | var beforeBundle = config.beforeBundle || function() {}; 688 | 689 | var watcher = new EventEmitter(); 690 | watcher.close = function () {}; 691 | 692 | var b = watchify(browserify(watchify.args)); 693 | b._watcher = function () { return watcher; }; 694 | b.plugin(tsify, tsifyOpts); 695 | beforeBundle(b); 696 | 697 | b.on('update', rebundle); 698 | rebundle(); 699 | 700 | function rebundle() { 701 | var calledBack = false; 702 | var errors = []; 703 | 704 | b.bundle() 705 | .on('error', function (error) { 706 | errors.push(error); 707 | }) 708 | .pipe(es.wait(function (err, actual) { 709 | if (calledBack) 710 | throw new Error('Bundling completed after build timeout expired'); 711 | calledBack = true; 712 | callNextCallback(errors, actual.toString()); 713 | })); 714 | 715 | setTimeout(function () { 716 | if (calledBack) 717 | return; 718 | calledBack = true; 719 | callNextCallback(errors, null); 720 | }, buildTimeout); 721 | } 722 | 723 | function callNextCallback(errors, actual) { 724 | // hack to wait for Watchify to finish adding any outstanding watchers 725 | setTimeout(function () { 726 | var cb = handlers.shift(); 727 | cb(errors, actual, triggerChange, b); 728 | }, 100); 729 | } 730 | 731 | function triggerChange() { 732 | watcher.emit('change'); 733 | } 734 | } 735 | 736 | function expectNoErrors(t, errors) { 737 | t.deepEqual(errors, [], 'Should have no compilation errors'); 738 | } 739 | 740 | function expectErrors(t, actual, expected) { 741 | t.equal(actual.length, expected.length, 'Should have the correct error count'); 742 | for (var i = 0; i < actual.length && i < expected.length; ++i) { 743 | t.equal(actual[i].fileName, expected[i].file, 'Error #' + i + ' should have filename ' + expected[i].name); 744 | t.equal(actual[i].line, expected[i].line, 'Error #' + i + ' should be on line ' + expected[i].line); 745 | t.equal(actual[i].column, expected[i].column, 'Error #' + i + ' should be on column ' + expected[i].column); 746 | t.ok(actual[i].message.indexOf(expected[i].file) > -1, 747 | 'Error #' + i + ' message should contain file info'); 748 | t.ok(actual[i].message.indexOf('(' + expected[i].line + ',' + expected[i].column + ')') > -1, 749 | 'Error #' + i + ' message should contain position info'); 750 | t.ok(actual[i].message.indexOf(expected[i].name) > -1, 751 | 'Error #' + i + ' message should contain error info'); 752 | } 753 | } 754 | 755 | function expectConsoleOutputFromScript(t, src, expected) { 756 | t.notEqual(src, null, 'Should have compiled output'); 757 | 758 | var actual = []; 759 | var sandbox = { console: { log: function (str) { actual.push(str); }}}; 760 | try { 761 | vm.runInNewContext(src, sandbox); 762 | t.deepEqual(actual, expected, 'Should have expected console.log output'); 763 | } catch (err) { 764 | t.fail(err); 765 | } 766 | } 767 | 768 | function expectMappedToken(t, srcFile, mapSourceFile, compiled, token) { 769 | if (!token) { 770 | token = compiled; 771 | compiled = mapSourceFile; 772 | mapSourceFile = srcFile; 773 | } 774 | 775 | var src = fs.readFileSync(srcFile, 'utf-8'); 776 | var compiledPosition = indexToLineAndColumn(compiled, compiled.indexOf(token)); 777 | var expectedSrcPosition = indexToLineAndColumn(src, src.indexOf(token)); 778 | expectedSrcPosition.name = null; 779 | expectedSrcPosition.source = mapSourceFile; 780 | 781 | if (expectedSrcPosition.column === -1) { 782 | t.fail('Token "' + token + '" should be in expected code'); 783 | } 784 | if (compiledPosition.column === -1) { 785 | t.fail('Token "' + token + '" should be in compiled code'); 786 | } 787 | 788 | if (expectedSrcPosition.column !== -1 && compiledPosition.column !== -1) { 789 | var map = convert.fromSource(compiled).toObject(); 790 | var smc = new sm.SourceMapConsumer(map); 791 | var actualSrcPosition = smc.originalPositionFor(compiledPosition); 792 | 793 | t.deepEqual(actualSrcPosition, expectedSrcPosition, 'Token "' + token + '" should be mapped correctly'); 794 | } 795 | } 796 | 797 | function countLinesUntil(str, index) { 798 | var count = 1; 799 | while ((index = str.lastIndexOf('\n', index)) !== -1) { 800 | ++count; 801 | --index; 802 | } 803 | return count; 804 | } 805 | 806 | function indexToLineAndColumn(src, index) { 807 | var indexOfLine = src.lastIndexOf('\n', index-1) + 1; 808 | return { line: countLinesUntil(src, indexOfLine), column: index - indexOfLine }; 809 | } 810 | 811 | function expectFiles(t, emitted, expected) { 812 | 813 | Object.keys(expected).forEach(function (key) { 814 | var index = findIndex(key); 815 | if (expected[key]) { 816 | t.notEqual(index, -1, 'Should emit ' + key); 817 | } else { 818 | t.equal(index, -1, 'Should not emit ' + key); 819 | } 820 | }); 821 | 822 | function findIndex(file) { 823 | for (var i = 0; i < emitted.length; ++i) { 824 | if (new RegExp(file + '$').test(emitted[i])) { 825 | return i; 826 | } 827 | } 828 | return -1; 829 | } 830 | } 831 | -------------------------------------------------------------------------------- /test/tsconfig/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "noEmitOnError": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/tsconfig/x.ts: -------------------------------------------------------------------------------- 1 | var x; 2 | x = 3; 3 | console.log(x); 4 | -------------------------------------------------------------------------------- /test/tsconfigExclude/broken.d.ts: -------------------------------------------------------------------------------- 1 | interface IBroken 2 | thing1: string; 3 | thing2: string 4 | -------------------------------------------------------------------------------- /test/tsconfigExclude/interface.d.ts: -------------------------------------------------------------------------------- 1 | interface IThing { 2 | thing1: string; 3 | thing2: string; 4 | } 5 | -------------------------------------------------------------------------------- /test/tsconfigExclude/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "exclude": ["broken.d.ts"] 3 | } 4 | -------------------------------------------------------------------------------- /test/tsconfigExclude/x.ts: -------------------------------------------------------------------------------- 1 | var x: IThing = { thing1: 'Doctor', thing2: 'Seuss' }; 2 | console.log(x.thing1); 3 | console.log(x.thing2); 4 | -------------------------------------------------------------------------------- /test/tsx/CoolComponent.tsx: -------------------------------------------------------------------------------- 1 | import * as React from './React'; 2 | 3 | export class CoolComponent { 4 | render() { 5 | return ( 6 |

7 | ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/tsx/React.ts: -------------------------------------------------------------------------------- 1 | // simplified test implementation of React.createElement 2 | export function createElement(type: string, props: any, child: string[]) { 3 | return type + ' with contents: ' + child; 4 | } 5 | -------------------------------------------------------------------------------- /test/tsx/main.ts: -------------------------------------------------------------------------------- 1 | import { CoolComponent } from './CoolComponent'; 2 | 3 | let instance = new CoolComponent(); 4 | console.log(instance.render()); 5 | -------------------------------------------------------------------------------- /test/typeError/x.ts: -------------------------------------------------------------------------------- 1 | import y = require('./y'); 2 | import z = require('./z'); 3 | y('hello world'); 4 | y(z(2)); -------------------------------------------------------------------------------- /test/typeError/y.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(message: string) { 3 | console.log(message); 4 | } -------------------------------------------------------------------------------- /test/typeError/z.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(n: number) { 3 | return n*111; 4 | } -------------------------------------------------------------------------------- /test/watchify/interface.d.ts: -------------------------------------------------------------------------------- 1 | interface IThing { 2 | thing1: string; 3 | thing2: string; 4 | } 5 | -------------------------------------------------------------------------------- /test/watchify/main.ts: -------------------------------------------------------------------------------- 1 | import dep = require('./.tmp'); 2 | dep({ thing1: '5', thing2: '6' }); 3 | -------------------------------------------------------------------------------- /test/watchify/ok.ts: -------------------------------------------------------------------------------- 1 | function dep(thing: IThing) { console.log(thing.thing1); } 2 | export = dep; 3 | -------------------------------------------------------------------------------- /test/watchify/syntaxError.ts: -------------------------------------------------------------------------------- 1 | function dep(thing: IThing) { console.log(thing.thing1); } 2 | export = 3 | -------------------------------------------------------------------------------- /test/watchify/tmp.ts: -------------------------------------------------------------------------------- 1 | function dep(thing: IThing) { console.log(thing.thing1); } 2 | export = 3 | -------------------------------------------------------------------------------- /test/watchify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": ["interface.d.ts"] 3 | } 4 | -------------------------------------------------------------------------------- /test/watchify/typeError.ts: -------------------------------------------------------------------------------- 1 | function dep(n: string) { console.log(n); } 2 | export = dep; 3 | -------------------------------------------------------------------------------- /test/withAdjacentCompiledFiles/x.js: -------------------------------------------------------------------------------- 1 | var y = require('./y'); 2 | var z = require('./z'); 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/withAdjacentCompiledFiles/x.ts: -------------------------------------------------------------------------------- 1 | import y = require('./y'); 2 | import z = require('./z'); 3 | y('hello world'); 4 | y(z(2).toString()); -------------------------------------------------------------------------------- /test/withAdjacentCompiledFiles/y.js: -------------------------------------------------------------------------------- 1 | function fn(message) { 2 | console.log(message); 3 | } 4 | module.exports = fn; 5 | -------------------------------------------------------------------------------- /test/withAdjacentCompiledFiles/y.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(message: string) { 3 | console.log(message); 4 | } -------------------------------------------------------------------------------- /test/withAdjacentCompiledFiles/z.js: -------------------------------------------------------------------------------- 1 | function fn(n) { 2 | return n * 111; 3 | } 4 | module.exports = fn; 5 | -------------------------------------------------------------------------------- /test/withAdjacentCompiledFiles/z.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(n: number) { 3 | return n*111; 4 | } -------------------------------------------------------------------------------- /test/withFileOverrides/bar-exam.ts: -------------------------------------------------------------------------------- 1 | export const name: string = 'bar-exam'; 2 | -------------------------------------------------------------------------------- /test/withFileOverrides/bar-tender.ts: -------------------------------------------------------------------------------- 1 | export const name: string = 'bar-tender'; 2 | -------------------------------------------------------------------------------- /test/withFileOverrides/bar.ts: -------------------------------------------------------------------------------- 1 | export const name: string = 'bar'; 2 | -------------------------------------------------------------------------------- /test/withFileOverrides/foo.ts: -------------------------------------------------------------------------------- 1 | export const name: string = 'foo'; 2 | -------------------------------------------------------------------------------- /test/withFileOverrides/index.ts: -------------------------------------------------------------------------------- 1 | console.log("index"); 2 | -------------------------------------------------------------------------------- /test/withFileOverrides/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noEmitOnError": false 4 | }, 5 | "exclude": ["bar-exam.ts"], 6 | "files": ["foo.ts", "bar.ts"], 7 | "include": ["bar-*.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /test/withJsRoot/x.js: -------------------------------------------------------------------------------- 1 | var y = require('./y'); 2 | var z = require('./z'); 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/withJsRoot/y.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(message: string) { 3 | console.log(message); 4 | } -------------------------------------------------------------------------------- /test/withJsRoot/z.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(n: number) { 3 | return n*111; 4 | } -------------------------------------------------------------------------------- /test/withJsRootAndNestedDeps/nested/twice/z.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(n: number) { 3 | return n*111; 4 | } 5 | -------------------------------------------------------------------------------- /test/withJsRootAndNestedDeps/nested/y.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(message: string) { 3 | console.log(message); 4 | } 5 | -------------------------------------------------------------------------------- /test/withJsRootAndNestedDeps/tsconfig.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/withJsRootAndNestedDeps/x.js: -------------------------------------------------------------------------------- 1 | var y = require('./nested/y'); 2 | var z = require('./nested/twice/z'); 3 | y('hello world'); 4 | y(z(2).toString()); 5 | -------------------------------------------------------------------------------- /test/withNestedDeps/nested/twice/z.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(n: number) { 3 | return n*111; 4 | } -------------------------------------------------------------------------------- /test/withNestedDeps/nested/y.ts: -------------------------------------------------------------------------------- 1 | export = fn; 2 | function fn(message: string) { 3 | console.log(message); 4 | } -------------------------------------------------------------------------------- /test/withNestedDeps/x.ts: -------------------------------------------------------------------------------- 1 | import y = require('./nested/y'); 2 | import z = require('./nested/twice/z'); 3 | y('hello world'); 4 | y(z(2).toString()); -------------------------------------------------------------------------------- /test/withRequiredStream/x.ts: -------------------------------------------------------------------------------- 1 | declare const require: Function; 2 | const streamed = require('streamed'); 3 | console.log(streamed.name); 4 | --------------------------------------------------------------------------------