Skip to content

Commit

Permalink
Add tsconfig.strictNullChecks.json
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
mjbvz committed Oct 10, 2018
1 parent 7e742e1 commit 104275c
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 62 deletions.
26 changes: 17 additions & 9 deletions build/lib/compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions build/lib/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
26 changes: 2 additions & 24 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 14 additions & 0 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
39 changes: 19 additions & 20 deletions src/vs/base/common/iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!) };
}
};
}
Expand All @@ -64,7 +64,7 @@ export module Iterator {
return { done, value: undefined };
}

if (fn(value)) {
if (fn(value!)) {
return { done, value };
}
}
Expand All @@ -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!);
}
}

Expand All @@ -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> {
Expand All @@ -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;
}
Expand All @@ -138,47 +138,46 @@ 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
}

next() { return this.fn(this.iterator.next()); }
}

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> {
Expand Down

0 comments on commit 104275c

Please sign in to comment.