Add tsconfig.strictNullChecks.json

Part of #60565

Adds a new `tsconfig.strictNullChecks.json` project that does not emit anything and is only used for enabling strict null checks on a subset of the vscode codebase.

Opt `iterator.ts` into strict null checking.

Fix our build scripts to properly handle `extends`
This commit is contained in:
Matt Bierner 2018-10-10 14:54:59 -07:00
parent 7e742e1f31
commit 104275cb9f
6 changed files with 102 additions and 62 deletions

View file

@ -4,23 +4,31 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var gulp = require("gulp");
var tsb = require("gulp-tsb");
var es = require("event-stream");
var watch = require('./watch');
var nls = require("./nls");
var util = require("./util");
var reporter_1 = require("./reporter");
var path = require("path");
var fs = require("fs");
var gulp = require("gulp");
var bom = require("gulp-bom");
var sourcemaps = require("gulp-sourcemaps");
var tsb = require("gulp-tsb");
var path = require("path");
var _ = require("underscore");
var monacodts = require("../monaco/api");
var fs = require("fs");
var nls = require("./nls");
var reporter_1 = require("./reporter");
var util = require("./util");
var watch = require('./watch');
var assign = require("object-assign");
var reporter = reporter_1.createReporter();
function getTypeScriptCompilerOptions(src) {
var rootDir = path.join(__dirname, "../../" + src);
var options = require("../../" + src + "/tsconfig.json").compilerOptions;
var tsconfig = require("../../" + src + "/tsconfig.json");
var options;
if (tsconfig.extends) {
options = assign({}, require(path.join(rootDir, tsconfig.extends)).compilerOptions, tsconfig.compilerOptions);
}
else {
options = tsconfig.compilerOptions;
}
options.verbose = false;
options.sourceMap = true;
if (process.env['VSCODE_NO_SOURCEMAP']) { // To be used by developers in a hurry

View file

@ -5,25 +5,32 @@
'use strict';
import * as gulp from 'gulp';
import * as tsb from 'gulp-tsb';
import * as es from 'event-stream';
const watch = require('./watch');
import * as nls from './nls';
import * as util from './util';
import { createReporter } from './reporter';
import * as path from 'path';
import * as fs from 'fs';
import * as gulp from 'gulp';
import * as bom from 'gulp-bom';
import * as sourcemaps from 'gulp-sourcemaps';
import * as tsb from 'gulp-tsb';
import * as path from 'path';
import * as _ from 'underscore';
import * as monacodts from '../monaco/api';
import * as fs from 'fs';
import * as nls from './nls';
import { createReporter } from './reporter';
import * as util from './util';
const watch = require('./watch');
import assign = require('object-assign');
const reporter = createReporter();
function getTypeScriptCompilerOptions(src: string) {
const rootDir = path.join(__dirname, `../../${src}`);
const options = require(`../../${src}/tsconfig.json`).compilerOptions;
const tsconfig = require(`../../${src}/tsconfig.json`);
let options: { [key: string]: any };
if (tsconfig.extends) {
options = assign({}, require(path.join(rootDir, tsconfig.extends)).compilerOptions, tsconfig.compilerOptions);
} else {
options = tsconfig.compilerOptions;
}
options.verbose = false;
options.sourceMap = true;
if (process.env['VSCODE_NO_SOURCEMAP']) { // To be used by developers in a hurry

34
src/tsconfig.base.json Normal file
View file

@ -0,0 +1,34 @@
{
"compilerOptions": {
"module": "amd",
"moduleResolution": "node",
"noImplicitAny": false,
"target": "es5",
"experimentalDecorators": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noImplicitThis": true,
"alwaysStrict": true,
"baseUrl": ".",
"paths": {
"vs/*": [
"./vs/*"
]
},
"types": [
"keytar",
"minimist",
"mocha",
"semver",
"sinon",
"winreg"
]
},
"include": [
"./typings",
"./vs"
],
"exclude": [
"./typings/require-monaco.d.ts"
]
}

View file

@ -1,33 +1,11 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "amd",
"moduleResolution": "node",
"noImplicitAny": false,
"removeComments": false,
"preserveConstEnums": true,
"target": "es5",
"sourceMap": false,
"experimentalDecorators": true,
"declaration": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noImplicitThis": true,
"alwaysStrict": true,
"baseUrl": ".",
"outDir": "../out",
"paths": {
"vs/*": [
"./vs/*"
]
},
"types": [
"keytar",
"minimist",
"mocha",
"semver",
"sinon",
"winreg"
]
"outDir": "../out"
},
"include": [
"./typings",

View file

@ -0,0 +1,14 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"strictNullChecks": true
},
"include": [
"./typings",
"./vs/base/common/iterator.ts"
],
"exclude": [
"./typings/require-monaco.d.ts"
]
}

View file

@ -49,7 +49,7 @@ export module Iterator {
return {
next() {
const { done, value } = iterator.next();
return { done, value: done ? undefined : fn(value) };
return { done, value: done ? undefined : fn(value!) };
}
};
}
@ -64,7 +64,7 @@ export module Iterator {
return { done, value: undefined };
}
if (fn(value)) {
if (fn(value!)) {
return { done, value };
}
}
@ -74,7 +74,7 @@ export module Iterator {
export function forEach<T>(iterator: Iterator<T>, fn: (t: T) => void): void {
for (let next = iterator.next(); !next.done; next = iterator.next()) {
fn(next.value);
fn(next.value!);
}
}
@ -96,7 +96,7 @@ export function getSequenceIterator<T>(arg: Iterator<T> | T[]): Iterator<T> {
}
export interface INextIterator<T> {
next(): T;
next(): T | null;
}
export class ArrayIterator<T> implements INextIterator<T> {
@ -113,17 +113,17 @@ export class ArrayIterator<T> implements INextIterator<T> {
this.index = index;
}
public first(): T {
public first(): T | null {
this.index = this.start;
return this.current();
}
public next(): T {
public next(): T | null {
this.index = Math.min(this.index + 1, this.end);
return this.current();
}
protected current(): T {
protected current(): T | null {
if (this.index === this.start - 1 || this.index === this.end) {
return null;
}
@ -138,34 +138,33 @@ export class ArrayNavigator<T> extends ArrayIterator<T> implements INavigator<T>
super(items, start, end, index);
}
public current(): T {
public current(): T | null {
return super.current();
}
public previous(): T {
public previous(): T | null {
this.index = Math.max(this.index - 1, this.start - 1);
return this.current();
}
public first(): T {
public first(): T | null {
this.index = this.start;
return this.current();
}
public last(): T {
public last(): T | null {
this.index = this.end - 1;
return this.current();
}
public parent(): T {
public parent(): T | null {
return null;
}
}
export class MappedIterator<T, R> implements INextIterator<R> {
constructor(protected iterator: INextIterator<T>, protected fn: (item: T) => R) {
constructor(protected iterator: INextIterator<T>, protected fn: (item: T | null) => R) {
// noop
}
@ -173,12 +172,12 @@ export class MappedIterator<T, R> implements INextIterator<R> {
}
export interface INavigator<T> extends INextIterator<T> {
current(): T;
previous(): T;
parent(): T;
first(): T;
last(): T;
next(): T;
current(): T | null;
previous(): T | null;
parent(): T | null;
first(): T | null;
last(): T | null;
next(): T | null;
}
export class MappedNavigator<T, R> extends MappedIterator<T, R> implements INavigator<R> {