Skip to content

Commit 79b9856

Browse files
committed
Merge pull request #283 from TypeStrong/ImplementTypeScript1.6
[WIP] Implement TypeScript 1.6
2 parents 15b315e + b141f1d commit 79b9856

37 files changed

+731
-202
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Releases
22

33
## Next
4+
* Upgraded to TypeScript 1.6.2 (thanks to @vp2177 and @JoshuaKGoldberg for sending early PRs, and for @awjreynolds, @Zjaaspoer, @DrColossos, @ravishivt, @logankd, and @Gouigouix for early encouragement.)
45

56
## v5.0.1 (2015-10-08)
67
* FIX: 'htmlOutputTemplate' was not handled. Thanks for the PR, @rolego (#291).

Gruntfile.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,50 @@ module.exports = function (grunt) {
794794
fast: 'never',
795795
additionalFlags: '--version'
796796
}
797+
},
798+
test_jsx: {
799+
test: true,
800+
testExecute: commandLineAssertions.test_jsx,
801+
src: 'test/simple/ts/zoo.ts',
802+
options: {
803+
jsx: 'preserve'
804+
}
805+
},
806+
test_moduleResolution: {
807+
test: true,
808+
testExecute: commandLineAssertions.test_moduleResolution,
809+
src: 'test/simple/ts/zoo.ts',
810+
options: {
811+
moduleResolution: 'classic'
812+
}
813+
},
814+
test_experimentalAsyncFunctions: {
815+
test: true,
816+
testExecute: commandLineAssertions.test_experimentalAsyncFunctions,
817+
src: 'test/simple/ts/zoo.ts',
818+
options: {
819+
experimentalAsyncFunctions: true
820+
}
821+
},
822+
test_rootDir: {
823+
test: true,
824+
testExecute: commandLineAssertions.test_rootDir,
825+
src: 'test/simple/ts/zoo.ts',
826+
outDir: 'test/simple/js/test_rootDir',
827+
options: {
828+
rootDir: 'test/simple'
829+
}
830+
},
831+
test_directoriesWithSpaces: {
832+
test: true,
833+
testExecute: commandLineAssertions.test_directoriesWithSpaces,
834+
src: 'test/simple/ts/zoo.ts',
835+
outDir: 'test/outDir with spaces',
836+
options: {
837+
rootDir: 'test/rootDir with spaces',
838+
sourceRoot: 'test/sourceRoot with spaces',
839+
mapRoot: 'test/mapRoot with spaces'
840+
}
797841
}
798842
}
799843
});
@@ -948,7 +992,8 @@ module.exports = function (grunt) {
948992

949993
grunt.registerTask('report-time-elapsed','Reports the time elapsed since gruntStartedTimestamp', function() {
950994
var seconds = ((new Date().getTime()) - gruntStartedTimestamp) / 1000;
951-
console.log(('Your "Grunt work" took ' + seconds.toFixed(2) + ' seconds.').green);
995+
console.log(('Your "Grunt work" took ' + seconds.toFixed(2) + ' seconds and finished at ' +
996+
(new Date().toLocaleString()) + '.').green);
952997
return true;
953998
});
954999

README.md

Lines changed: 131 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Grunt-ts is an npm package that handles TypeScript compilation work in GruntJS b
88

99
### Latest Changes
1010
Latest release is `5.0.1`, which includes `tsconfig.json` support and TypeScript 1.5, among many other improvements.
11+
Current beta release is `5.1.0-beta.1`, which includes TypeScript 1.6 support and some bug fixes.
1112

1213
[Full changelog is here](CHANGELOG.md).
1314

@@ -61,22 +62,26 @@ Grunt-ts provides explicit support for most `tsc` switches. Any arbitrary switc
6162
|:----:|:----:|:-----|
6263
|--declaration|[declaration](#declaration)|Generates a `.d.ts` definitions file for compiled TypeScript files|
6364
|--emitDecoratorMetadata|[emitDecoratorMetadata](#emitdecoratormetadata)|Emit metadata for type/parameter decorators.|
65+
|--experimentalAsyncFunctions|[experimentalAsyncFunctions](#experimentalasyncfunctions)|Enables experimental support for ES7 async functions|
6466
|--experimentalDecorators|[experimentalDecorators](#experimentaldecorators)|Enables experimental support for ES7 decorators|
6567
|--inlineSourceMap|[inlineSourceMap](#inlinesourcemap)|Emit a single file that includes source maps instead of emitting a separate `.js.map` file.|
6668
|--inlineSources|[inlineSources](#inlinesources)|Emit the TypeScript source alongside the sourcemaps within a single file; requires `--inlineSourceMap` to be set.|
6769
|--isolatedModules|[isolatedModules](#isolatedmodules)|Ensures that the output is safe to only emit single files by making cases that break single-file transpilation an error|
70+
|--jsx|[jsx](#jsx)|Specifies the JSX code generation style: 'preserve' or 'react'|
6871
|--mapRoot LOCATION|[mapRoot](#maproot)|Specifies the location where debugger should locate map files instead of generated locations.|
6972
|--module KIND|[module](#module)|Specify module style for code generation|
73+
|--moduleResolution KIND|[moduleResolution](#moduleresolution)|Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6).|
7074
|--newLine|[newLine](#newline)|Explicitly specify newline character (`CRLF` or `LF`); if omitted, uses OS default.|
7175
|--noEmit|[noEmit](#noemit)|Check, but do not emit JS, even in the absence of errors.|
7276
|--noEmitHelpers|[noEmitHelpers](#noemithelpers)|Do not generate custom helper functions like `__extends` in compiled output.|
73-
|--noEmitOnError|[noEmitOnError](#noemitonerror)|Do no emit any javascript if there is a type error.|
77+
|--noEmitOnError|[noEmitOnError](#noemitonerror)|Do not emit JavaScript if there is a compilation error|
7478
|--noImplicitAny|[noImplicitAny](#noimplicitany)|Warn on expressions and declarations with an implied `any` type.|
7579
|--noResolve|[noResolve](#noresolve)|Do not add triple-slash references or module import targets to the compilation context.|
7680
|--out FILE|[out](#out)|Concatenate and emit output to a single file.|
7781
|--outDir DIRECTORY|[outDir](#outdir)|Redirect output structure to the directory.|
7882
|--preserveConstEnums|[preserveConstEnums](#preserveconstenums)|Const enums will be kept as enums in the emitted JS.|
7983
|--removeComments|[removeComments](#removecomments)|Configures if comments should be included in the output|
84+
|--rootDir|[rootDir](#rootdir)|Allows override of common root folder calculated by `--outDir`.|
8085
|--sourceMap|[sourceMap](#sourcemap)|Generates corresponding `.map` file|
8186
|--sourceRoot LOCATION|[sourceRoot](#sourceroot)|Specifies the location where debugger should locate TypeScript files instead of source locations.|
8287
|--suppressImplicitAnyIndexErrors|[suppressImplicitAnyIndexErrors](#suppressimplicitanyindexerrors)|Specifies the location where debugger should locate TypeScript files instead of source locations.|
@@ -87,29 +92,35 @@ For file ordering, look at [JavaScript Generation](#javascript-generation).
8792

8893
## grunt-ts gruntfile.js options
8994

90-
|property|where to define|description|
95+
|grunt-ts property|where to define|description|
9196
|:----|:----|:-----|
9297
|[additionalFlags](#additionalflags)|option|`string` - allows passing arbitrary strings to the compiler. This is intended to enable compatibility with features not supported directly by grunt-ts.|
9398
|[comments](#comments)|option|`true`, `false` (default) - include comments in emitted JS.|
9499
|[compile](#compile)|option|`true` (default), `false` - compile TypeScript code.|
95100
|[compiler](#compiler)|option|`string` - path to custom compiler|
96101
|[declaration](#declaration)|option|`true`, `false` (default) - indicates that definition files should be emitted.|
97102
|[emitDecoratorMetadata](#emitdecoratormetadata)|option|`true`, `false` (default) - set to true to emit metadata for ES7 decorators (will enable experimentalDecorators)|
103+
|[experimentalAsyncFunctions](#experimentalasyncfunctions)|option|`true`, `false` (default) - set to true to enable support for ES7 async functions (in ES6 mode only)|
98104
|[experimentalDecorators](#experimentaldecorators)|option|`true`, `false` (default) - set to true to enable support for ES7 decorators|
99-
|[failOnTypeErrors](#failontypeerrors)|option|`true` (default), `false` - fail Grunt pipeline if there is a type error|
105+
|[failOnTypeErrors](#failontypeerrors)|option|`true` (default), `false` - fail Grunt pipeline if there is a type error. (See also [noEmitOnError](#noemithelpers))|
100106
|[fast](#fast)|option|`'watch'` (default), `'always'`, `'never'` - how to decide on a "fast" grunt-ts compile.|
101107
|[files](#files)|target|Sets of files to compile and optional output destination|
102108
|[html](#html)|target|`string` or `string[]` - glob to HTML templates|
103109
|[htmlModuleTemplate](#htmlmoduletemplate)|option|`string` - HTML template namespace|
110+
|[htmlOutDir](#htmloutdir)|option|`string` - Sets a root for output of transformed-to-TypeScript HTML files|
111+
|[htmlOutDirFlatten](#htmloutdirflatten)|option|`true`, `false` (default) - Will flatten the transformed HTML files to a single folder|
104112
|[htmlVarTemplate](#htmlvartemplate)|option|`string` - HTML property name|
105113
|[inlineSourceMap](#inlinesourcemap)|option|`true`, `false` (default) Emit a single file that includes source maps instead of emitting a separate `.js.map` file; If enabled, will automatically enable `sourceMap`.|
106114
|[inlineSources](#inlinesources)|option|`true`, `false` (default) Emit the TypeScript source alongside the sourcemaps within a single file; If enabled, will automatically enable `inlineSourceMap` and `sourceMap`.|
107115
|[isolatedModules](#isolatedmodules)|option|`true`, `false` (default) Ensures that the output is safe to only emit single files by making cases that break single-file transpilation an error.|
116+
|[jsx](#jsx)|option|`'preserve'`, `'react'`, (TypeScript default is `'react'`). If `'preserve'`, TypeScript will emit `.jsx`; if `'react'`, TypeScript will transpile and emit `.js` files.|
108117
|[mapRoot](#maproot)|option|`string` - root for referencing `.js.map` files in JS|
109118
|[module](#module)|option|default to be nothing, If you want to set it you set it to either `'amd'` or `'commonjs'`|
119+
|[moduleResolution](#moduleresolution)|option|`'classic'` or `'node'`. This was introduced in TypeScript 1.6. The default is `'node'` if not passed. [More details here](https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#adjustments-in-module-resolution-logic).|
110120
|[newLine](#newline)|option|`CRLF`, `LF`, `` (default) - If passed with a value, TypeScript will use the specified line endings. Also affects grunt-ts transforms.|
111121
|[noEmit](#noemit)|option|`true`, `false` (default) - If passed as `true`, TypeScript will not emit even if it compiles cleanly|
112122
|[noEmitHelpers](#noemithelpers)|option|`true`, `false` (default) - If passed as `true`, TypeScript will not generate custom helper functions like `__extends` in compiled output|
123+
|[noEmitOnError](#noemithelpers)|option|`true`, `false` (default) - If passed as `true`, TypeScript will not emit JS if there is an error (see also [failOnTypeErrors](#failontypeerrors))|
113124
|[noImplicitAny](#noimplicitany)|option|`true`, `false` (default) - enable for stricter type checking|
114125
|[noResolve](#noresolve)|option|`true`, `false` (default) - for deprecated version of TypeScript|
115126
|[options](#grunt-ts-target-options)|target||
@@ -118,6 +129,7 @@ For file ordering, look at [JavaScript Generation](#javascript-generation).
118129
|[preserveConstEnums](#preserveconstenums)|option|`true`, `false` (default) - If true, const enums will be kept as enums in the emitted JS.|
119130
|[reference](#reference)|target|`string` - tells grunt-ts which file to use for maintaining references|
120131
|[removeComments](#removecomments)|option|`true` (default), `false` - removes comments in emitted JS|
132+
|[rootDir](#rootdir)|option|`string` - Allows override of common root folder calculated by `--outDir`.|
121133
|[sourceRoot](#sourceroot)|option|`string` - root for referencing TS files in `.js.map`|
122134
|[sourceMap](#sourcemap)|option|`true` (default), `false` - indicates if source maps should be generated (`.js.map`)|
123135
|[suppressImplicitAnyIndexErrors](#suppressimplicitanyindexerrors)|option|`false` (default), `true` - indicates if TypeScript should allow access to properties of an object by string indexer when `--noImplicitAny` is active, even if TypeScript doesn't know about them.|
@@ -127,6 +139,7 @@ For file ordering, look at [JavaScript Generation](#javascript-generation).
127139
|[verbose](#verbose)|option|`true`, `false` (default) - logs `tsc` command-line options to console|
128140
|[vs](#vs)|target|`string` referencing a `.csproj` or `.vbproj` file or, `{}` (object) (see [Visual Studio Projects](#vs) for details)|
129141
|[watch](#watch)|target|`string` - will watch for changes in the specified directory or below|
142+
|**something else**||Don't see the switch you're looking for? Check out [additionalFlags](#additionalflags)|
130143

131144
Note: In the above chart, if "where to define" is "target", the property must be defined on a target or on the `ts` object directly. If "where to define" is "options", then the property must be defined on an `options` object on `ts` or on a target under `ts`.
132145

@@ -507,6 +520,25 @@ grunt.initConfig({
507520
});
508521
````
509522

523+
#### experimentalAsyncFunctions
524+
525+
````javascript
526+
true | false (default)
527+
````
528+
529+
Enable support for experimental ES7 async functionality. This is only available in TypeScript 1.6 and higher in 'es6' mode.
530+
531+
````javascript
532+
grunt.initConfig({
533+
ts: {
534+
options: {
535+
experimentalAsyncFunctions: true,
536+
target: 'es6'
537+
}
538+
}
539+
});
540+
````
541+
510542
#### experimentalDecorators
511543

512544
````javascript
@@ -606,15 +638,51 @@ grunt.initConfig({
606638
});
607639
````
608640

641+
#### htmlOutDir
642+
643+
Sets a root for output of transformed-to-TypeScript HTML files. See detailed explanation of [grunt-ts HTML template support](/docs/html2ts.md).
644+
645+
````javascript
646+
//Note: incomplete - combine with html and src/files/etc.
647+
grunt.initConfig({
648+
ts: {
649+
default: {
650+
options: {
651+
htmlOutDir: 'generatedHtml'
652+
}
653+
}
654+
}
655+
});
656+
````
657+
658+
### htmlOutDirFlatten
659+
660+
Will flatten the transformed HTML files to a single folder. See detailed explanation of [grunt-ts HTML template support](/docs/html2ts.md).
661+
662+
````javascript
663+
//Note: incomplete - combine with html and src/files/etc.
664+
grunt.initConfig({
665+
ts: {
666+
default: {
667+
options: {
668+
htmlOutDir: 'generatedHtml',
669+
htmlOutDirFlatten: true
670+
}
671+
}
672+
}
673+
});
674+
````
675+
676+
609677
#### htmlOutputTemplate
610678

611679
Grunt-ts supports compilation of `.html` file content to TypeScript variables which is explained in detail [here](/docs/html2ts.md). The `htmlOutputTemplate` target property allows the developer to override the internally defined output template to a custom one, useful if one would like to define the HTML output as an external modules, for example.
612-
Three variables can be used in this template, namely:
613680

681+
Three variables can be used in the template, namely:
614682

615-
* "<%= modulename %>" - This variable will be interpolated with the value of the htmlModuleTemplate option
616-
* "<%= varname %>" - This variable will be interpolated with the value of the htmlVarTemplate option
617-
* "<%= content %>" - This variable will be interpolated with the content of the HTML file
683+
* "<%= modulename %>" - This variable will be replaced with the value of the `htmlModuleTemplate` option.
684+
* "<%= varname %>" - This variable will be replaced with the value of the `htmlVarTemplate` option.
685+
* "<%= content %>" - This variable will be replaced with the content of the HTML file.
618686

619687
````javascript
620688
//Note: Outputs an external module
@@ -630,7 +698,6 @@ grunt.initConfig({
630698
export var <%= varname %> = \'<%= content %>\';\n\
631699
}\n'
632700
}
633-
634701
}
635702
}
636703
});
@@ -697,6 +764,24 @@ grunt.initConfig({
697764
});
698765
````
699766

767+
#### jsx
768+
769+
````javascript
770+
`'react'` (default) | `'preserve'`
771+
````
772+
773+
Specify the JSX code generation style. Documentation is here: [TypeScript Wiki - JSX](https://github.com/Microsoft/TypeScript/wiki/JSX).
774+
775+
````javascript
776+
grunt.initConfig({
777+
ts: {
778+
options: {
779+
jsx: 'preserve'
780+
}
781+
}
782+
});
783+
````
784+
700785

701786
#### mapRoot
702787

@@ -735,6 +820,26 @@ grunt.initConfig({
735820
});
736821
````
737822

823+
#### moduleResolution
824+
825+
````javascript
826+
"node" (default) | "classic"
827+
````
828+
829+
New in TypeScript 1.6. TypeScript is gaining support for resolving definition files using rules similar to common JavaScript module loaders. The first new one is support for CommonJS used by NodeJS, which is why this parameter is called `"node"` The `"node"` setting performs an extra check to see if a definition file exists in the `node_modules/modulename` folder if a TypeScript definition can't be found for an imported module. if this is not desired, set this setting to "classic".
830+
831+
````javascript
832+
grunt.initConfig({
833+
ts: {
834+
default: {
835+
options: {
836+
moduleResolution: "classic"
837+
}
838+
}
839+
}
840+
});
841+
````
842+
738843
#### newLine
739844

740845
````javascript
@@ -891,6 +996,24 @@ grunt.initConfig({
891996
});
892997
````
893998

999+
#### rootDir
1000+
1001+
````javascript
1002+
string
1003+
````
1004+
1005+
Affects the creation of folders inside the `outDir` location. `rootDir` allows manually specifying the desired common root folder when used in combination with `outDir`. Otherwise, TypeScript attempts to calculate this automatically.
1006+
1007+
````javascript
1008+
grunt.initConfig({
1009+
ts: {
1010+
options: {
1011+
rootDir: "src/app"
1012+
}
1013+
}
1014+
});
1015+
````
1016+
8941017
#### sourceMap
8951018

8961019
````javascript

defs/csproj2ts/csproj2ts.d.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

defs/tsd.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
/// <reference path="underscore.string/underscore.string.d.ts" />
33
/// <reference path="lodash/lodash.d.ts" />
44
/// <reference path="gruntjs/gruntjs.d.ts" />
5-
/// <reference path="csproj2ts/csproj2ts.d.ts" />
65
/// <reference path="nodeunit/nodeunit.d.ts" />
76
/// <reference path="es6-promise/es6-promise.d.ts" />

0 commit comments

Comments
 (0)