Skip to content

Support some options from TypeScript 2.0 #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,16 @@ module.exports = function (grunt) {
noImplicitUseStrict: true
}
},
new_TypeScript_2_0_Features: {
test: true,
testExecute: commandLineAssertions.new_TypeScript_2_0_Features,
src: 'test/simple/ts/**/*.ts',
options: {
strictNullChecks: true,
noImplicitThis: true,
lib: ['es2017']
}
},
allowJs_CompileWorks: {
test: true,
src: ['test/allowJs/allowJsConsumer.ts',
Expand Down
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Grunt-ts provides explicit support for most `tsc` switches. Any arbitrary switc
|--inlineSources|[inlineSources](#inlinesources)|Emit the TypeScript source alongside the sourcemaps within a single file; requires `--inlineSourceMap` to be set.|
|--isolatedModules|[isolatedModules](#isolatedmodules)|Ensures that the output is safe to only emit single files by making cases that break single-file transpilation an error|
|--jsx|[jsx](#jsx)|Specifies the JSX code generation style: 'preserve' or 'react'|
|--lib|[lib](#lib)|List of library files to be included in the compilation.|
|--locale|[locale](#locale)|Specify locale for error messages.|
|--mapRoot LOCATION|[mapRoot](#maproot)|Specifies the location where debugger should locate map files instead of generated locations.|
|--module KIND|[module](#module)|Specify module style for code generation|
Expand All @@ -86,6 +87,7 @@ Grunt-ts provides explicit support for most `tsc` switches. Any arbitrary switc
|--noImplicitAny|[noImplicitAny](#noimplicitany)|Warn on expressions and declarations with an implied `any` type.|
|--noImplicitUseStrict|[noImplicitUseStrict](#noimplicitusestrict)|Warn on expressions and declarations with an implied `any` type.|
|--noImplicitReturns|[noImplicitReturns](#noimplicitreturns)|Report error when not all code paths in function return a value.|
|--noImplicitThis|[noImplicitThis](#noImplicitThis)|Raise error on `this` expressions with an implied `any` type.|
|--noLib|[noLib](#nolib)|Do not automatically include lib.d.ts is compilation context.|
|--noResolve|[noResolve](#noresolve)|Do not add triple-slash references or module import targets to the compilation context.|
|--out FILE|[out](#out)|Concatenate and emit output to a single file.|
Expand All @@ -96,6 +98,7 @@ Grunt-ts provides explicit support for most `tsc` switches. Any arbitrary switc
|--removeComments|[removeComments](#removecomments)|Configures if comments should be included in the output|
|--rootDir|[rootDir](#rootdir)|Allows override of common root folder calculated by `--outDir`.|
|--skipDefaultLibCheck|[skipDefaultLibCheck](#skipdefaultlibcheck)|Don't check a user-defined default lib file's validity.|
|--strictNullChecks|[strictNullChecks](#strictNullChecks)|Enables strict null checking mode.|
|--sourceMap|[sourceMap](#sourcemap)|Generates corresponding `.map` file|
|--sourceRoot LOCATION|[sourceRoot](#sourceroot)|Specifies the location where debugger should locate TypeScript files instead of source locations.|
|--stripInternal|[stripInternal](#stripinternal)|does not emit members marked as @internal.|
Expand Down Expand Up @@ -137,6 +140,7 @@ For file ordering, look at [JavaScript Generation](#javascript-generation).
|[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`.|
|[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.|
|[jsx](#jsx)|option|`'preserve'`, `'react'`, (TypeScript default is `'react'`). If `'preserve'`, TypeScript will emit `.jsx`; if `'react'`, TypeScript will transpile and emit `.js` files.|
|[lib](#lib)|option|`string[]`. List of library files to be included in the compilation. If `--lib` is not specified a default library is injected.|
|[locale](#locale)|option|`string` - specify locale for error messages|
|[mapRoot](#maproot)|option|`string` - root for referencing `.js.map` files in JS|
|[module](#module)|option|default is none (`''`), but can be set to `'amd'`, `'commonjs'`, `'system'`, or other values.|
Expand All @@ -148,6 +152,7 @@ For file ordering, look at [JavaScript Generation](#javascript-generation).
|[noFallthroughCasesInSwitch](#nofallthroughcasesinswitch)|option|`true`, `false` (default) - Report errors for fallthrough cases in switch statement.|
|[noImplicitAny](#noimplicitany)|option|`true`, `false` (default) - enable for stricter type checking|
|[noImplicitReturns](#noimplicitreturns)|option|`true`, `false` (default) - Report error when not all code paths in function return a value.|
|[noImplicitThis](#noImplicitThis)|option|`true`, `false` (default) - Raise error on this expressions with an implied `any` type.|
|[noLib](#nolib)|option|`true`, `false` (default) - do not automatically include lib.d.ts in compilation context|
|[noResolve](#noresolve)|option|`true`, `false` (default) - for deprecated version of TypeScript|
|[options](#grunt-ts-target-options)|target||
Expand All @@ -162,6 +167,7 @@ For file ordering, look at [JavaScript Generation](#javascript-generation).
|[skipDefaultLibCheck](#skipdefaultlibcheck)|option|`true`, `false` (default) - Don't check a user-defined default lib file's validity.|
|[sourceRoot](#sourceroot)|option|`string` - root for referencing TS files in `.js.map`|
|[sourceMap](#sourcemap)|option|`true` (default), `false` - indicates if source maps should be generated (`.js.map`)|
|[strictNullChecks](#strictNullChecks)|option|`true`, `false` (default) - Enables strict null checking mode.|
|[stripInternal](#stripinternal)|option|`true`, `false` (default) - does not emit members marked as @internal.|
|[suppressExcessPropertyErrors](#suppressexcesspropertyerrors)|option|`false` (default), `true` - indicates if TypeScript should disable strict object literal assignment checking (experimental)|
|[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.|
Expand Down Expand Up @@ -941,6 +947,20 @@ grunt.initConfig({
});
````

#### lib

List of library files to be included in the compilation. If `--lib` is not specified a default library is injected.

````javascript
grunt.initConfig({
ts: {
options: {
lib: ['es2015']
}
}
});
````

#### locale

Specify culture string for error messages - will pass the `--locale` switch. Requires appropriate TypeScript error messages file to be present (see TypeScript documentation for more details).
Expand Down Expand Up @@ -1158,6 +1178,26 @@ grunt.initConfig({
});
````

#### noImplicitThis

````javascript
true | false (default)
````

Set to true to pass `--noImplicitThis` to the compiler. Requires more strict type checking. Raise error on `this` expressions with an implied `any` type.

````javascript
grunt.initConfig({
ts: {
default: {
options: {
noImplicitThis: true
}
}
}
});
````

#### noLib

````javascript
Expand Down Expand Up @@ -1310,6 +1350,26 @@ grunt.initConfig({
});
````

#### strictNullChecks

````javascript
true | false (default)
````

In strict null checking mode, the `null` and `undefined` values are not in the domain of every type and are only assignable to themselves and `any` (the one exception being that `undefined` is also assignable to `void`).

````javascript
grunt.initConfig({
ts: {
default: {
options: {
strictNullChecks: true
}
}
}
});
````

#### sourceMap

````javascript
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"peerDependencies": {
"grunt": ">=0.4.0",
"typescript": "^1.8.0 || 2.x.x-dev.0"
"typescript": ">=1.8.0"
},
"devDependencies": {
"grunt": "~0.4.0",
Expand Down
37 changes: 37 additions & 0 deletions tasks/modules/compile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions tasks/modules/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,44 @@ export function compileAllFiles(options: IGruntTSOptions, compilationInfo: IGrun
if (options.noImplicitUseStrict) {
args.push('--noImplicitUseStrict');
}
if (options.strictNullChecks) {
args.push('--strictNullChecks');
}
if (options.noImplicitThis) {
args.push('--noImplicitThis');
}
if (options.lib) {
let possibleOptions = [
'es5',
'es6',
'es2015',
'es7',
'es2016',
'es2017',
'dom',
'webworker',
'scripthost',
'es2015.core',
'es2015.collection',
'es2015.generator',
'es2015.iterable',
'es2015.promise',
'es2015.proxy',
'es2015.reflect',
'es2015.symbol',
'es2015.symbol.wellknown',
'es2016.array.include',
'es2017.object',
'es2017.sharedmemory'
];

options.lib.forEach(function(option) {
if (possibleOptions.indexOf(option) === -1) {
console.warn(`WARNING: Option "lib" does not support ${option} `.magenta);
}
});
args.push('--lib', options.lib.join(','));
}

args.push('--target', options.target.toUpperCase());

Expand Down
3 changes: 3 additions & 0 deletions tasks/modules/defaults.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tasks/modules/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const TypeScriptDefaults: IGruntTSOptions = {
forceConsistentCasingInFileNames: false,
allowJs: false,
noImplicitUseStrict: false,
strictNullChecks: false,
noImplicitThis: false,
lib: null,
rootDir: null,
warnings: [],
errors: []
Expand Down
6 changes: 6 additions & 0 deletions tasks/modules/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ interface ITaskOptions {
allowJs: boolean;
/** Do not emit "use strict" directives in module output. */
noImplicitUseStrict: boolean;
/** Enables strict null checking mode */
strictNullChecks: boolean;
/** Raise error on this expressions with an implied 'any' type. */
noImplicitThis: boolean;
/** List of library files to be included in the compilation */
lib: Array<string>;
}

interface IVisualStudioProjectSupport {
Expand Down
3 changes: 2 additions & 1 deletion tasks/modules/optionsResolver.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tasks/modules/optionsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const propertiesFromTarget = ['amdloader', 'baseDir', 'html', 'htmlOutDir', 'htm
'preserveConstEnums', 'removeComments', 'sourceRoot', 'sourceMap', 'stripInternal', 'suppressExcessPropertyErrors',
'suppressImplicitAnyIndexErrors', 'target', 'verbose', 'jsx', 'moduleResolution', 'experimentalAsyncFunctions', 'rootDir',
'emitGruntEvents', 'reactNamespace', 'skipDefaultLibCheck', 'pretty', 'allowUnusedLabels', 'noImplicitReturns',
'noFallthroughCasesInSwitch', 'allowUnreachableCode', 'forceConsistentCasingInFileNames', 'allowJs', 'noImplicitUseStrict'],
'noFallthroughCasesInSwitch', 'allowUnreachableCode', 'forceConsistentCasingInFileNames', 'allowJs', 'noImplicitUseStrict',
'strictNullChecks', 'noImplicitThis', 'lib'],
delayTemplateExpansion = ['htmlModuleTemplate', 'htmlVarTemplate', 'htmlOutputTemplate'];

let templateProcessor: (templateString: string, options: any) => string = null;
Expand Down
3 changes: 3 additions & 0 deletions tasks/modules/tsconfig.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tasks/modules/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function applyCompilerOptions(applyTo: IGruntTSOptions, projectSpec: ITSConfigFi
'inlineSources',
'jsx',
// we do not support listFiles.
'lib',
'locale',
'mapRoot',
'module',
Expand All @@ -252,6 +253,7 @@ function applyCompilerOptions(applyTo: IGruntTSOptions, projectSpec: ITSConfigFi
'noFallthroughCasesInSwitch',
'noImplicitAny',
'noImplicitReturns',
'noImplicitThis',
'noImplicitUseStrict',
'noLib',
'noResolve',
Expand All @@ -264,6 +266,7 @@ function applyCompilerOptions(applyTo: IGruntTSOptions, projectSpec: ITSConfigFi
'removeComments',
'rootDir',
'skipDefaultLibCheck',
'strictNullChecks',
'sourceMap',
'sourceRoot',
'stripInternal',
Expand Down
14 changes: 14 additions & 0 deletions test/commandLineAssertions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/commandLineAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,22 @@ export const new_TypeScript_1_8_Features: ICompilePromise = (strings, options) =
});
};

export const new_TypeScript_2_0_Features: ICompilePromise = (strings, options) => {
return new Promise(function(resolve, reject) {

const command = strings[1].replace(/\\/g,'/');

if (command.indexOf(`--strictNullChecks`) > -1 &&
command.indexOf(`--noImplicitThis`) > -1 &&
command.indexOf(`--lib es2017`) > -1) {
resolve({
code: 0,
output: ""
});
}
throw `expected to see all of the new TypeScript 2.0 values in the command line and didn't. Got this: ${command}`;
});
};

export const test_noLib = simpleCommandLineCheck("--noLib");
export const test_emitBOM = simpleCommandLineCheck("--emitBOM");
Expand Down