Remove nulls from the syntax layer.

This commit is contained in:
Cyrus Najmabadi 2014-10-29 22:29:48 -07:00
parent 5ce3baf339
commit cd1a1dbfc5
27 changed files with 328 additions and 326 deletions

View File

@ -7,7 +7,7 @@ module TypeScript {
return true;
}
if (array1 === null || array2 === null) {
if (!array1 || !array2) {
return false;
}
@ -71,7 +71,7 @@ module TypeScript {
}
}
return null;
return undefined;
}
public static firstOrDefault<T>(array: T[], func: (v: T, index: number) => boolean): T {
@ -82,7 +82,7 @@ module TypeScript {
}
}
return null;
return undefined;
}
public static first<T>(array: T[], func?: (v: T, index: number) => boolean): T {

View File

@ -14,13 +14,14 @@ module TypeScript {
return this.currentAssertionLevel >= level;
}
public static assert(expression: any, message: string = "", verboseDebugInfo: () => string = null): void {
public static assert(expression: any, message?: string, verboseDebugInfo?: () => string): void {
if (!expression) {
var verboseDebugString = "";
if (verboseDebugInfo) {
verboseDebugString = "\r\nVerbose Debug Information:" + verboseDebugInfo();
}
message = message || "";
throw new Error("Debug Failure. False expression: " + message + verboseDebugString);
}
}

View File

@ -50,11 +50,11 @@ module TypeScript {
private _arguments: any[];
private _additionalLocations: Location[];
constructor(fileName: string, lineMap: LineMap, start: number, length: number, diagnosticKey: string, _arguments: any[]= null, additionalLocations: Location[] = null) {
constructor(fileName: string, lineMap: LineMap, start: number, length: number, diagnosticKey: string, _arguments?: any[], additionalLocations?: Location[]) {
super(fileName, lineMap, start, length);
this._diagnosticKey = diagnosticKey;
this._arguments = (_arguments && _arguments.length > 0) ? _arguments : null;
this._additionalLocations = (additionalLocations && additionalLocations.length > 0) ? additionalLocations : null;
this._arguments = (_arguments && _arguments.length > 0) ? _arguments : undefined;
this._additionalLocations = (additionalLocations && additionalLocations.length > 0) ? additionalLocations : undefined;
}
public toJSON(key: any): any {

View File

@ -3,7 +3,7 @@
module TypeScript {
export class LineMap {
public static empty = new LineMap(() => [0], 0);
private _lineStarts: number[] = null;
private _lineStarts: number[] = undefined;
constructor(private _computeLineStarts: () => number[], private length: number) {
}
@ -18,7 +18,7 @@ module TypeScript {
}
public lineStarts(): number[] {
if (this._lineStarts === null) {
if (!this._lineStarts) {
this._lineStarts = this._computeLineStarts();
}

View File

@ -3,7 +3,7 @@
module TypeScript {
export class SyntaxVisitor implements ISyntaxVisitor {
public defaultVisit(node: ISyntaxNodeOrToken): any {
return null;
return undefined;
}
public visitToken(token: ISyntaxToken): any {

View File

@ -88,8 +88,8 @@ module TypeScript.IncrementalParser {
function release() {
_scannerParserSource.release();
_scannerParserSource = null;
_oldSourceUnitCursor = null;
_scannerParserSource = undefined;
_oldSourceUnitCursor = undefined;
_outstandingRewindPointCount = 0;
}
@ -177,13 +177,13 @@ module TypeScript.IncrementalParser {
// Null out the cursor that the rewind point points to. This way we don't try
// to return it in 'releaseRewindPoint'.
rewindPoint.oldSourceUnitCursor = null;
rewindPoint.oldSourceUnitCursor = undefined;
_scannerParserSource.rewind(rewindPoint);
}
function releaseRewindPoint(rewindPoint: IParserRewindPoint): void {
if (rewindPoint.oldSourceUnitCursor !== null) {
if (rewindPoint.oldSourceUnitCursor) {
returnSyntaxCursor(rewindPoint.oldSourceUnitCursor);
}
@ -220,7 +220,7 @@ module TypeScript.IncrementalParser {
// If our current absolute position is in the middle of the changed range in the new text
// then we definitely can't read from the old source unit right now.
if (_changeRange !== null && _changeRangeNewSpan.intersectsWithPosition(absolutePosition())) {
if (_changeRange && _changeRangeNewSpan.intersectsWithPosition(absolutePosition())) {
return false;
}
@ -258,7 +258,7 @@ module TypeScript.IncrementalParser {
// Try to read a node. If we can't then our caller will call back in and just try
// to get a token.
var node = tryGetNodeFromOldSourceUnit();
if (node !== null) {
if (node) {
// Make sure the positions for the tokens in this node are correct.
updateTokens(node);
return node;
@ -266,13 +266,13 @@ module TypeScript.IncrementalParser {
}
// Either we were ahead of the old text, or we were pinned. No node can be read here.
return null;
return undefined;
}
function currentToken(): ISyntaxToken {
if (canReadFromOldSourceUnit()) {
var token = tryGetTokenFromOldSourceUnit();
if (token !== null) {
if (token) {
// Make sure the token's position/text is correct.
updateTokens(token);
return token;
@ -354,9 +354,9 @@ module TypeScript.IncrementalParser {
// e) we are still in the same strict or non-strict state that the node was originally parsed in.
while (true) {
var node = _oldSourceUnitCursor.currentNode();
if (node === null) {
if (node === undefined) {
// Couldn't even read a node, nothing to return.
return null;
return undefined;
}
if (!intersectsWithChangeRangeSpanInOriginalText(absolutePosition(), fullWidth(node))) {
@ -395,7 +395,7 @@ module TypeScript.IncrementalParser {
// need to make sure that if that the parser asks for a *token* we don't return it.
// Converted identifiers can't ever be created by the scanner, and as such, should not
// be returned by this source.
if (token !== null) {
if (token) {
if (!intersectsWithChangeRangeSpanInOriginalText(position, token.fullWidth())) {
// Didn't intersect with the change range.
if (!token.isIncrementallyUnusable() && !Scanner.isContextualToken(token)) {
@ -417,13 +417,13 @@ module TypeScript.IncrementalParser {
var token = _oldSourceUnitCursor.currentToken();
return canReuseTokenFromOldSourceUnit(absolutePosition(), token)
? token : null;
? token : undefined;
}
function peekToken(n: number): ISyntaxToken {
if (canReadFromOldSourceUnit()) {
var token = tryPeekTokenFromOldSourceUnit(n);
if (token !== null) {
if (token) {
return token;
}
}
@ -462,7 +462,7 @@ module TypeScript.IncrementalParser {
var interimToken = _oldSourceUnitCursor.currentToken();
if (!canReuseTokenFromOldSourceUnit(currentPosition, interimToken)) {
return null;
return undefined;
}
currentPosition += interimToken.fullWidth();
@ -471,7 +471,7 @@ module TypeScript.IncrementalParser {
var token = _oldSourceUnitCursor.currentToken();
return canReuseTokenFromOldSourceUnit(currentPosition, token)
? token : null;
? token : undefined;
}
function consumeNode(node: ISyntaxNode): void {
@ -486,7 +486,7 @@ module TypeScript.IncrementalParser {
var _absolutePosition = absolutePosition() + fullWidth(node);
_scannerParserSource.resetToPosition(_absolutePosition);
// Debug.assert(previousToken !== null);
// Debug.assert(previousToken !== undefined);
// Debug.assert(previousToken.width() > 0);
//if (!isPastChangeRange()) {
@ -515,7 +515,7 @@ module TypeScript.IncrementalParser {
var _absolutePosition = absolutePosition() + currentToken.fullWidth();
_scannerParserSource.resetToPosition(_absolutePosition);
// Debug.assert(previousToken !== null);
// Debug.assert(previousToken !== undefined);
// Debug.assert(previousToken.width() > 0);
//if (!isPastChangeRange()) {
@ -543,15 +543,15 @@ module TypeScript.IncrementalParser {
// Once we're past the change range, we no longer need it. Null it out.
// From now on we can check if we're past the change range just by seeing
// if this is null.
_changeRange = null;
// if this is undefined.
_changeRange = undefined;
}
}
}
}
function isPastChangeRange(): boolean {
return _changeRange === null;
return _changeRange === undefined;
}
return {
@ -605,7 +605,7 @@ module TypeScript.IncrementalParser {
if (syntaxCursorPoolCount > 0) {
// If we reused an existing cursor, take it out of the pool so no one else uses it.
syntaxCursorPoolCount--;
syntaxCursorPool[syntaxCursorPoolCount] = null;
syntaxCursorPool[syntaxCursorPoolCount] = undefined;
}
return cursor;
@ -652,11 +652,11 @@ module TypeScript.IncrementalParser {
for (var i = 0, n = pieces.length; i < n; i++) {
var piece = pieces[i];
if (piece.element === null) {
if (piece.element === undefined) {
break;
}
piece.element = null;
piece.element = undefined;
piece.indexInParent = -1;
}
@ -669,7 +669,7 @@ module TypeScript.IncrementalParser {
for (var i = 0, n = other.pieces.length; i < n; i++) {
var piece = other.pieces[i];
if (piece.element === null) {
if (piece.element === undefined) {
break;
}
@ -685,13 +685,13 @@ module TypeScript.IncrementalParser {
function currentNodeOrToken(): ISyntaxNodeOrToken {
if (isFinished()) {
return null;
return undefined;
}
var result = pieces[currentPieceIndex].element;
// The current element must always be a node or a token.
// Debug.assert(result !== null);
// Debug.assert(result !== undefined);
// Debug.assert(result.isNode() || result.isToken());
return <ISyntaxNodeOrToken>result;
@ -699,12 +699,12 @@ module TypeScript.IncrementalParser {
function currentNode(): ISyntaxNode {
var element = currentNodeOrToken();
return isNode(element) ? <ISyntaxNode>element : null;
return isNode(element) ? <ISyntaxNode>element : undefined;
}
function moveToFirstChild() {
var nodeOrToken = currentNodeOrToken();
if (nodeOrToken === null) {
if (nodeOrToken === undefined) {
return;
}
@ -721,7 +721,7 @@ module TypeScript.IncrementalParser {
// next sibling of the empty node.
for (var i = 0, n = childCount(nodeOrToken); i < n; i++) {
var child = childAt(nodeOrToken, i);
if (child !== null && !isShared(child)) {
if (child && !isShared(child)) {
// Great, we found a real child. Push that.
pushElement(child, /*indexInParent:*/ i);
@ -749,7 +749,7 @@ module TypeScript.IncrementalParser {
for (var i = currentPiece.indexInParent + 1, n = childCount(parent); i < n; i++) {
var sibling = childAt(parent, i);
if (sibling !== null && !isShared(sibling)) {
if (sibling && !isShared(sibling)) {
// We found a good sibling that we can move to. Just reuse our existing piece
// so we don't have to push/pop.
currentPiece.element = sibling;
@ -766,7 +766,7 @@ module TypeScript.IncrementalParser {
// Clear the data from the old piece. We don't want to keep any elements around
// unintentionally.
currentPiece.element = null;
currentPiece.element = undefined;
currentPiece.indexInParent = -1;
// Point at the parent. if we move past the top of the path, then we're finished.
@ -787,7 +787,7 @@ module TypeScript.IncrementalParser {
}
function pushElement(element: ISyntaxElement, indexInParent: number): void {
// Debug.assert(element !== null);
// Debug.assert(element !== undefined);
// Debug.assert(indexInParent >= 0);
currentPieceIndex++;
@ -819,8 +819,8 @@ module TypeScript.IncrementalParser {
moveToFirstToken();
var element = currentNodeOrToken();
// Debug.assert(element === null || element.isToken());
return element === null ? null : <ISyntaxToken>element;
// Debug.assert(element === undefined || element.isToken());
return <ISyntaxToken>element;
}
return {

View File

@ -130,7 +130,7 @@ module TypeScript.Parser {
arrayPoolCount--;
var result = arrayPool[arrayPoolCount];
arrayPool[arrayPoolCount] = null;
arrayPool[arrayPoolCount] = undefined;
return result;
}
@ -212,9 +212,10 @@ module TypeScript.Parser {
// Now, clear out our state so that our singleton parser doesn't keep things alive.
diagnostics = [];
parseNodeData = SyntaxConstants.None;
fileName = null;
fileName = undefined;
source.release();
source = null; _source = null;
source = undefined;
_source = undefined;
return result;
}
@ -265,8 +266,8 @@ module TypeScript.Parser {
// Note: we *can* reuse tokens when the strict mode changes. That's because tokens
// are unaffected by strict mode. It's just the parser will decide what to do with it
// differently depending on what mode it is in.
if (node === null || parsedInStrictMode(node) !== isInStrictMode) {
return null;
if (!node || parsedInStrictMode(node) !== isInStrictMode) {
return undefined;
}
return node;
@ -314,7 +315,7 @@ module TypeScript.Parser {
return consumeToken(_currentToken);
}
return null;
return undefined;
}
// An identifier is basically any word, unless it is a reserved keyword. so 'foo' is an
@ -367,7 +368,7 @@ module TypeScript.Parser {
}
function eatOptionalIdentifierToken(): ISyntaxToken {
return isIdentifier(currentToken()) ? eatIdentifierToken() : null;
return isIdentifier(currentToken()) ? eatIdentifierToken() : undefined;
}
// This method should be called when the grammar calls for an *Identifier* and not an
@ -448,10 +449,10 @@ module TypeScript.Parser {
}
// Check if an automatic semicolon could go here. If so, then there's no problem and
// we can proceed without error. Return 'null' as there's no actual token for this
// we can proceed without error. Return 'undefined' as there's no actual token for this
// position.
if (canEatAutomaticSemicolon(allowWithoutNewline)) {
return null;
return undefined;
}
// No semicolon could be consumed here at all. Just call the standard eating function
@ -471,7 +472,7 @@ module TypeScript.Parser {
function getExpectedTokenDiagnostic(expectedKind: SyntaxKind, actual: ISyntaxToken, diagnosticCode: string): Diagnostic {
var token = currentToken();
var args: any[] = null;
var args: any[] = undefined;
// If a specialized diagnostic message was provided, just use that.
if (!diagnosticCode) {
// They wanted something specific, just report that that token was missing.
@ -483,7 +484,7 @@ module TypeScript.Parser {
// They wanted an identifier.
// If the user supplied a keyword, give them a specialized message.
if (actual !== null && SyntaxFacts.isAnyKeyword(actual.kind())) {
if (actual && SyntaxFacts.isAnyKeyword(actual.kind())) {
diagnosticCode = DiagnosticCode.Identifier_expected_0_is_a_keyword;
args = [SyntaxFacts.getText(actual.kind())];
}
@ -860,7 +861,7 @@ module TypeScript.Parser {
function tryParseTypeArgumentList(inExpression: boolean): TypeArgumentListSyntax {
var _currentToken = currentToken();
if (_currentToken.kind() !== SyntaxKind.LessThanToken) {
return null;
return undefined;
}
if (!inExpression) {
@ -895,7 +896,7 @@ module TypeScript.Parser {
if (greaterThanToken.fullWidth() === 0 || !canFollowTypeArgumentListInExpression(currentToken().kind())) {
rewind(rewindPoint);
releaseRewindPoint(rewindPoint);
return null;
return undefined;
}
else {
releaseRewindPoint(rewindPoint);
@ -982,7 +983,7 @@ module TypeScript.Parser {
var token0 = currentToken();
var shouldContinue = isIdentifier(token0);
if (!shouldContinue) {
return null;
return undefined;
}
// Call eatIdentifierName to convert the token to an identifier if it is as keyword.
@ -1018,7 +1019,7 @@ module TypeScript.Parser {
function isEnumElement(inErrorRecovery: boolean): boolean {
var node = currentNode();
if (node !== null && node.kind() === SyntaxKind.EnumElement) {
if (node && node.kind() === SyntaxKind.EnumElement) {
return true;
}
@ -1026,18 +1027,18 @@ module TypeScript.Parser {
}
function tryParseEnumElementEqualsValueClause(): EqualsValueClauseSyntax {
return isEqualsValueClause(/*inParameter*/ false) ? parseEqualsValueClause(/*allowIn:*/ true) : null;
return isEqualsValueClause(/*inParameter*/ false) ? parseEqualsValueClause(/*allowIn:*/ true) : undefined;
}
function tryParseEnumElement(inErrorRecovery: boolean): EnumElementSyntax {
var node = currentNode();
if (node !== null && node.kind() === SyntaxKind.EnumElement) {
if (node && node.kind() === SyntaxKind.EnumElement) {
consumeNode(node);
return <EnumElementSyntax>node;
}
if (!isPropertyName(currentToken(), inErrorRecovery)) {
return null;
return undefined;
}
return new syntaxFactory.EnumElementSyntax(parseNodeData, eatPropertyName(), tryParseEnumElementEqualsValueClause());
@ -1115,17 +1116,17 @@ module TypeScript.Parser {
var heritageClauses = Syntax.emptyList<HeritageClauseSyntax>();
if (isHeritageClause()) {
// NOTE: we can pass "null" for the skipped tokens here as we know we can't get
// NOTE: we can pass "undefined" for the skipped tokens here as we know we can't get
// any leading skipped tokens. We have an 'extends' or 'implements' keyword, so
// any skipped tokeds will get attached to that instead.
heritageClauses= parseSyntaxList<HeritageClauseSyntax>(ListParsingState.ClassOrInterfaceDeclaration_HeritageClauses, null);
heritageClauses = parseSyntaxList<HeritageClauseSyntax>(ListParsingState.ClassOrInterfaceDeclaration_HeritageClauses, undefined);
}
return heritageClauses;
}
function tryParseHeritageClauseTypeName(): ITypeSyntax {
return isHeritageClauseTypeName() ? tryParseNameOrGenericType() : null;
return isHeritageClauseTypeName() ? tryParseNameOrGenericType() : undefined;
}
function parseClassDeclaration(): ClassDeclarationSyntax {
@ -1226,7 +1227,7 @@ module TypeScript.Parser {
return parseIndexMemberDeclaration();
}
else {
return null;
return undefined;
}
}
@ -1243,8 +1244,8 @@ module TypeScript.Parser {
var constructorKeyword = eatToken(SyntaxKind.ConstructorKeyword);
var callSignature = parseCallSignature(/*requireCompleteTypeParameterList:*/ false);
var semicolonToken: ISyntaxToken = null;
var block: BlockSyntax = null;
var semicolonToken: ISyntaxToken = undefined;
var block: BlockSyntax = undefined;
if (isBlock()) {
block = parseBlock(/*parseStatementsEvenWithNoOpenBrace:*/ false, /*checkForStrictMode:*/ true);
@ -1269,8 +1270,8 @@ module TypeScript.Parser {
// open brace.
var parseBlockEvenWithNoOpenBrace = tryAddUnexpectedEqualsGreaterThanToken(callSignature);
var block: BlockSyntax = null;
var semicolon: ISyntaxToken = null;
var block: BlockSyntax = undefined;
var semicolon: ISyntaxToken = undefined;
if (parseBlockEvenWithNoOpenBrace || isBlock()) {
block = parseBlock(parseBlockEvenWithNoOpenBrace, /*checkForStrictMode:*/ true);
@ -1375,8 +1376,8 @@ module TypeScript.Parser {
// open brace.
var parseBlockEvenWithNoOpenBrace = tryAddUnexpectedEqualsGreaterThanToken(callSignature);
var semicolonToken: ISyntaxToken = null;
var block: BlockSyntax = null;
var semicolonToken: ISyntaxToken = undefined;
var block: BlockSyntax = undefined;
// Parse a block if we're on a bock, or if we saw a '=>'
if (parseBlockEvenWithNoOpenBrace || isBlock()) {
@ -1393,8 +1394,8 @@ module TypeScript.Parser {
var modifiers = parseModifiers();
var moduleKeyword = eatToken(SyntaxKind.ModuleKeyword);
var moduleName: INameSyntax = null;
var stringLiteral: ISyntaxToken = null;
var moduleName: INameSyntax = undefined;
var stringLiteral: ISyntaxToken = undefined;
if (currentToken().kind() === SyntaxKind.StringLiteral) {
stringLiteral = eatToken(SyntaxKind.StringLiteral);
@ -1485,7 +1486,7 @@ module TypeScript.Parser {
return parsePropertySignature();
}
else {
return null;
return undefined;
}
}
@ -1606,7 +1607,7 @@ module TypeScript.Parser {
var extendsOrImplementsKeyword = currentToken();
var tokenKind = extendsOrImplementsKeyword.kind();
if (tokenKind !== SyntaxKind.ExtendsKeyword && tokenKind !== SyntaxKind.ImplementsKeyword) {
return null;
return undefined;
}
consumeToken(extendsOrImplementsKeyword);
@ -1754,7 +1755,7 @@ module TypeScript.Parser {
// and we should not parse it out here.
if (SyntaxFacts.isIdentifierNameOrAnyKeyword(peekToken(1))) {
// Definitely not a statement.
return null;
return undefined;
}
else {
break;
@ -1780,7 +1781,7 @@ module TypeScript.Parser {
// existing block properly. We don't want to accidently consume these as expression
// below.
if (isInterfaceEnumClassModuleImportOrExport(modifierCount)) {
return null;
return undefined;
}
else if (isVariableStatement(modifierCount)) {
return parseVariableStatement();
@ -1798,7 +1799,7 @@ module TypeScript.Parser {
return parseExpressionStatement();
}
else {
return null;
return undefined;
}
}
@ -1833,15 +1834,15 @@ module TypeScript.Parser {
var block = parseBlock(/*parseStatementsEvenWithNoOpenBrace:*/ false, /*checkForStrictMode:*/ false);
listParsingState = savedListParsingState;
var catchClause: CatchClauseSyntax = null;
var catchClause: CatchClauseSyntax = undefined;
if (currentToken().kind() === SyntaxKind.CatchKeyword) {
catchClause = parseCatchClause();
}
// If we don't have a catch clause, then we must have a finally clause. Try to parse
// one out no matter what.
var finallyClause: FinallyClauseSyntax = null;
if (catchClause === null || currentToken().kind() === SyntaxKind.FinallyKeyword) {
var finallyClause: FinallyClauseSyntax = undefined;
if (!catchClause || currentToken().kind() === SyntaxKind.FinallyKeyword) {
finallyClause = parseFinallyClause();
}
@ -1929,8 +1930,8 @@ module TypeScript.Parser {
var variableDeclaration = parseVariableDeclaration(/*allowIn:*/ false);
return currentToken().kind() === SyntaxKind.InKeyword
? parseForInStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, variableDeclaration, null)
: parseForStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, variableDeclaration, null);
? parseForInStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, variableDeclaration, undefined)
: parseForStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, variableDeclaration, undefined);
}
function parseForInStatementWithVariableDeclarationOrInitializer(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax): ForInStatementSyntax {
@ -1949,8 +1950,8 @@ module TypeScript.Parser {
var initializer = parseExpression(/*allowIn:*/ false);
return currentToken().kind() === SyntaxKind.InKeyword
? parseForInStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, null, initializer)
: parseForStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, null, initializer);
? parseForInStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, undefined, initializer)
: parseForStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, undefined, initializer);
}
function parseForStatementWithNoVariableDeclarationOrInitializer(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken): ForStatementSyntax {
@ -1958,7 +1959,7 @@ module TypeScript.Parser {
// Debug.assert(currentToken().kind() === SyntaxKind.SemicolonToken);
// for ( ; Expressionopt ; Expressionopt ) Statement
return parseForStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, /*variableDeclaration:*/ null, /*initializer:*/ null);
return parseForStatementWithVariableDeclarationOrInitializer(forKeyword, openParenToken, /*variableDeclaration:*/ undefined, /*initializer:*/ undefined);
}
function tryParseForStatementCondition(): IExpressionSyntax {
@ -1969,7 +1970,7 @@ module TypeScript.Parser {
return parseExpression(/*allowIn:*/ true);
}
return null;
return undefined;
}
function tryParseForStatementIncrementor(): IExpressionSyntax {
@ -1979,7 +1980,7 @@ module TypeScript.Parser {
return parseExpression(/*allowIn:*/ true);
}
return null;
return undefined;
}
function parseForStatementWithVariableDeclarationOrInitializer(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax): ForStatementSyntax {
@ -1997,14 +1998,14 @@ module TypeScript.Parser {
function tryEatBreakOrContinueLabel(): ISyntaxToken {
// If there is no newline after the break keyword, then we can consume an optional
// identifier.
var identifier: ISyntaxToken = null;
var identifier: ISyntaxToken = undefined;
if (!canEatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false)) {
if (isIdentifier(currentToken())) {
return eatIdentifierToken();
}
}
return null;
return undefined;
}
function parseBreakStatement(breakKeyword: ISyntaxToken): BreakStatementSyntax {
@ -2062,7 +2063,7 @@ module TypeScript.Parser {
return parseDefaultSwitchClause(_currentToken);
}
else {
return null;
return undefined;
}
}
@ -2108,7 +2109,7 @@ module TypeScript.Parser {
// throw could be terminated with a semicolon. Note: we can't call 'parseExpression'
// directly as that might consume an expression on the following line.
return canEatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false)
? createMissingToken(SyntaxKind.IdentifierName, null)
? createMissingToken(SyntaxKind.IdentifierName, undefined)
: parseExpression(/*allowIn:*/ true);
}
@ -2118,7 +2119,7 @@ module TypeScript.Parser {
}
function tryParseReturnStatementExpression(): IExpressionSyntax {
return !canEatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false) ? parseExpression(/*allowIn:*/ true) : null;
return !canEatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false) ? parseExpression(/*allowIn:*/ true) : undefined;
}
function parseReturnStatement(returnKeyword: ISyntaxToken): ReturnStatementSyntax {
@ -2225,7 +2226,7 @@ module TypeScript.Parser {
}
function parseOptionalElseClause(): ElseClauseSyntax {
return currentToken().kind() === SyntaxKind.ElseKeyword ? parseElseClause() : null;
return currentToken().kind() === SyntaxKind.ElseKeyword ? parseElseClause() : undefined;
}
function parseElseClause(): ElseClauseSyntax {
@ -2260,7 +2261,7 @@ module TypeScript.Parser {
function isVariableDeclarator(): boolean {
var node = currentNode();
if (node !== null && node.kind() === SyntaxKind.VariableDeclarator) {
if (node && node.kind() === SyntaxKind.VariableDeclarator) {
return true;
}
@ -2268,7 +2269,7 @@ module TypeScript.Parser {
}
function canReuseVariableDeclaratorNode(node: ISyntaxNode) {
if (node === null || node.kind() !== SyntaxKind.VariableDeclarator) {
if (!node || node.kind() !== SyntaxKind.VariableDeclarator) {
return false;
}
@ -2287,7 +2288,7 @@ module TypeScript.Parser {
// In order to prevent this, we do not allow a variable declarator to be reused if it
// has an initializer.
var variableDeclarator = <VariableDeclaratorSyntax>node;
return variableDeclarator.equalsValueClause === null;
return variableDeclarator.equalsValueClause === undefined;
}
function tryParseVariableDeclarator(allowIn: boolean, allowPropertyName: boolean): VariableDeclaratorSyntax {
@ -2308,12 +2309,12 @@ module TypeScript.Parser {
}
if (!allowPropertyName && !isIdentifier(currentToken())) {
return null;
return undefined;
}
var propertyName = allowPropertyName ? eatPropertyName() : eatIdentifierToken();
var equalsValueClause: EqualsValueClauseSyntax = null;
var typeAnnotation: TypeAnnotationSyntax = null;
var equalsValueClause: EqualsValueClauseSyntax = undefined;
var typeAnnotation: TypeAnnotationSyntax = undefined;
if (propertyName.fullWidth() > 0) {
typeAnnotation = parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false);
@ -2419,7 +2420,7 @@ module TypeScript.Parser {
// with AssignmentExpression if we see one.
var _currentToken = currentToken();
var arrowFunction = tryParseAnyArrowFunctionExpression(_currentToken);
if (arrowFunction !== null) {
if (arrowFunction) {
return arrowFunction;
}
@ -2433,8 +2434,8 @@ module TypeScript.Parser {
// binary expression here, so we pass in the 'lowest' precedence here so that it matches
// and consumes anything.
var leftOperand = tryParseBinaryExpressionOrHigher(_currentToken, force, BinaryExpressionPrecedence.Lowest, allowIn);
if (leftOperand === null) {
return null;
if (leftOperand === undefined) {
return undefined;
}
if (SyntaxUtilities.isLeftHandSizeExpression(leftOperand)) {
@ -2488,8 +2489,8 @@ module TypeScript.Parser {
// MultiplicativeExpression: See 11.5
// UnaryExpression
var leftOperand = tryParseUnaryExpressionOrHigher(_currentToken, force);
if (leftOperand === null) {
return null;
if (leftOperand === undefined) {
return undefined;
}
// We then pop up the stack consuming the other side of the binary exprssion if it exists.
@ -2622,8 +2623,8 @@ module TypeScript.Parser {
// Because CallExpression and MemberExpression are left recursive, we need to bottom out
// of the recursion immediately. So we parse out a primary expression to start with.
var expression: IMemberExpressionSyntax = tryParsePrimaryExpression(_currentToken, force);
if (expression === null) {
return null;
if (expression === undefined) {
return undefined;
}
return parseMemberExpressionRest(expression, inObjectCreation);
@ -2636,7 +2637,7 @@ module TypeScript.Parser {
switch (currentTokenKind) {
case SyntaxKind.OpenParenToken:
expression = new syntaxFactory.InvocationExpressionSyntax(parseNodeData, expression, parseArgumentList(/*typeArgumentList:*/ null));
expression = new syntaxFactory.InvocationExpressionSyntax(parseNodeData, expression, parseArgumentList(/*typeArgumentList:*/ undefined));
continue;
case SyntaxKind.LessThanToken:
@ -2645,7 +2646,7 @@ module TypeScript.Parser {
// part of an arithmetic expression. Break out so we consume it higher in the
// stack.
var argumentList = tryParseArgumentList();
if (argumentList === null) {
if (argumentList === undefined) {
break;
}
@ -2716,14 +2717,14 @@ module TypeScript.Parser {
// completes the LeftHandSideExpression, or starts the beginning of the first four
// CallExpression productions.
var expression: ILeftHandSideExpressionSyntax = null;
var expression: ILeftHandSideExpressionSyntax = undefined;
if (_currentToken.kind() === SyntaxKind.SuperKeyword) {
expression = parseSuperExpression(_currentToken);
}
else {
expression = tryParseMemberExpressionOrHigher(_currentToken, force, /*inObjectCreation:*/ false);
if (expression === null) {
return null;
if (expression === undefined) {
return undefined;
}
}
@ -2745,8 +2746,8 @@ module TypeScript.Parser {
function tryParsePostfixExpressionOrHigher(_currentToken: ISyntaxToken, force: boolean): IPostfixExpressionSyntax {
var expression = tryParseLeftHandSideExpressionOrHigher(_currentToken, force);
if (expression === null) {
return null;
if (expression === undefined) {
return undefined;
}
var _currentToken = currentToken();
@ -2781,13 +2782,13 @@ module TypeScript.Parser {
var isDot = tokenKind === SyntaxKind.DotToken;
var isOpenParenOrDot = isOpenParen || isDot;
var argumentList: ArgumentListSyntax = null;
if (typeArgumentList === null || !isOpenParenOrDot) {
var argumentList: ArgumentListSyntax = undefined;
if (!typeArgumentList || !isOpenParenOrDot) {
// Wasn't generic. Rewind to where we started so this can be parsed as an
// arithmetic expression.
rewind(rewindPoint);
releaseRewindPoint(rewindPoint);
return null;
return undefined;
}
else {
releaseRewindPoint(rewindPoint);
@ -2800,7 +2801,7 @@ module TypeScript.Parser {
if (isDot) {
// A parameter list must follow a generic type argument list.
var diagnostic = new Diagnostic(fileName, source.text.lineMap(), start(token0, source.text), width(token0),
DiagnosticCode.A_parameter_list_must_follow_a_generic_type_argument_list_expected, null);
DiagnosticCode.A_parameter_list_must_follow_a_generic_type_argument_list_expected, undefined);
addDiagnostic(diagnostic);
return new syntaxFactory.ArgumentListSyntax(parseNodeData, typeArgumentList,
@ -2819,10 +2820,10 @@ module TypeScript.Parser {
}
if (tokenKind === SyntaxKind.OpenParenToken) {
return parseArgumentList(null);
return parseArgumentList(undefined);
}
return null;
return undefined;
}
function parseArgumentList(typeArgumentList: TypeArgumentListSyntax): ArgumentListSyntax {
@ -2859,7 +2860,7 @@ module TypeScript.Parser {
var errorStart = start(openBracketToken, source.text);
var errorEnd = end(currentToken(), source.text);
var diagnostic = new Diagnostic(fileName, source.text.lineMap(), errorStart, errorEnd - errorStart,
DiagnosticCode.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead, null);
DiagnosticCode.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead, undefined);
addDiagnostic(diagnostic);
return Syntax.emptyToken(SyntaxKind.IdentifierName);
@ -2911,7 +2912,7 @@ module TypeScript.Parser {
}
if (!force) {
return null;
return undefined;
}
// Nothing else worked, report an error and produce a missing token.
@ -2937,7 +2938,7 @@ module TypeScript.Parser {
var tokenKind = currentToken.kind();
if (tokenKind === SyntaxKind.SlashToken || tokenKind === SyntaxKind.SlashEqualsToken) {
// Still came back as a / or /=. This is not a regular expression literal.
return null;
return undefined;
}
else if (tokenKind === SyntaxKind.RegularExpressionLiteral) {
return consumeToken(currentToken);
@ -2995,7 +2996,7 @@ module TypeScript.Parser {
function tryParseParenthesizedArrowFunctionExpression(): ParenthesizedArrowFunctionExpressionSyntax {
var tokenKind = currentToken().kind();
if (tokenKind !== SyntaxKind.OpenParenToken && tokenKind !== SyntaxKind.LessThanToken) {
return null;
return undefined;
}
// Because arrow functions and parenthesized expressions look similar, we have to check far
@ -3016,14 +3017,14 @@ module TypeScript.Parser {
// Now, look for cases where we're sure it's not an arrow function. This will help save us
// a costly parse.
if (!isPossiblyArrowFunctionExpression()) {
return null;
return undefined;
}
// Then, try to actually parse it as a arrow function, and only return if we see an =>
var rewindPoint = getRewindPoint();
var arrowFunction = tryParseParenthesizedArrowFunctionExpressionWorker(/*requiresArrow:*/ true);
if (arrowFunction === null) {
if (arrowFunction === undefined) {
rewind(rewindPoint);
}
@ -3038,14 +3039,14 @@ module TypeScript.Parser {
var callSignature = parseCallSignature(/*requireCompleteTypeParameterList:*/ true);
if (requireArrow && currentToken().kind() !== SyntaxKind.EqualsGreaterThanToken) {
return null;
return undefined;
}
var equalsGreaterThanToken = eatToken(SyntaxKind.EqualsGreaterThanToken);
var block = tryParseArrowFunctionBlock();
var expression: IExpressionSyntax = null;
if (block === null) {
var expression: IExpressionSyntax = undefined;
if (block === undefined) {
expression = tryParseAssignmentExpressionOrHigher(/*force:*/ true, /*allowIn:*/ true);
}
@ -3076,7 +3077,7 @@ module TypeScript.Parser {
return parseBlock(/*parseStatementsEvenWithNoOpenBrace:*/ true, /*checkForStrictMode:*/ false);
}
else {
return null;
return undefined;
}
}
}
@ -3100,8 +3101,8 @@ module TypeScript.Parser {
var equalsGreaterThanToken = eatToken(SyntaxKind.EqualsGreaterThanToken);
var block = tryParseArrowFunctionBlock();
var expression: IExpressionSyntax = null;
if (block === null) {
var expression: IExpressionSyntax = undefined;
if (block === undefined) {
expression = tryParseAssignmentExpressionOrHigher(/*force:*/ true, /*allowIn:*/ true);
}
@ -3297,7 +3298,7 @@ module TypeScript.Parser {
return parseSimplePropertyAssignment();
}
else {
return null;
return undefined;
}
}
@ -3376,7 +3377,7 @@ module TypeScript.Parser {
if (parseBlockEvenWithNoOpenBrace || openBraceToken.fullWidth() > 0) {
var savedIsInStrictMode = isInStrictMode;
var processItems = checkForStrictMode ? updateStrictModeState : null;
var processItems = checkForStrictMode ? updateStrictModeState : undefined;
var skippedTokens: ISyntaxToken[] = getArray();
var statements = parseSyntaxList<IStatementSyntax>(ListParsingState.Block_Statements, skippedTokens, processItems);
openBraceToken = addSkippedTokensAfterToken(openBraceToken, skippedTokens);
@ -3395,7 +3396,7 @@ module TypeScript.Parser {
function tryParseTypeParameterList(requireCompleteTypeParameterList: boolean): TypeParameterListSyntax {
var _currentToken = currentToken();
if (_currentToken.kind() !== SyntaxKind.LessThanToken) {
return null;
return undefined;
}
var rewindPoint = getRewindPoint();
@ -3408,11 +3409,11 @@ module TypeScript.Parser {
var greaterThanToken = eatToken(SyntaxKind.GreaterThanToken);
// return null if we were required to have a '>' token and we did not have one.
// return undefined if we were required to have a '>' token and we did not have one.
if (requireCompleteTypeParameterList && greaterThanToken.fullWidth() === 0) {
rewind(rewindPoint);
releaseRewindPoint(rewindPoint);
return null;
return undefined;
}
else {
releaseRewindPoint(rewindPoint);
@ -3427,7 +3428,7 @@ module TypeScript.Parser {
function tryParseTypeParameter(): TypeParameterSyntax {
// Debug.assert(isTypeParameter());
if (!isIdentifier(currentToken())) {
return null;
return undefined;
}
return new syntaxFactory.TypeParameterSyntax(parseNodeData, eatIdentifierToken(), tryParseConstraint());
@ -3435,7 +3436,7 @@ module TypeScript.Parser {
function tryParseConstraint(): ConstraintSyntax {
if (currentToken().kind() !== SyntaxKind.ExtendsKeyword) {
return null;
return undefined;
}
return new syntaxFactory.ConstraintSyntax(parseNodeData, eatToken(SyntaxKind.ExtendsKeyword), parseTypeOrExpression());
@ -3450,7 +3451,7 @@ module TypeScript.Parser {
}
}
return null;
return undefined;
}
function parseParameterList(): ParameterListSyntax {
@ -3467,7 +3468,7 @@ module TypeScript.Parser {
}
function parseOptionalTypeAnnotation(allowStringLiteral: boolean): TypeAnnotationSyntax {
return currentToken().kind() === SyntaxKind.ColonToken ? parseTypeAnnotation(allowStringLiteral) : null;
return currentToken().kind() === SyntaxKind.ColonToken ? parseTypeAnnotation(allowStringLiteral) : undefined;
}
function parseTypeAnnotationType(allowStringLiteral: boolean): ITypeSyntax {
@ -3586,8 +3587,8 @@ module TypeScript.Parser {
function tryParseNameOrGenericType(): ITypeSyntax {
var name = tryParseName(/*allowIdentifierNames*/ false);
if (name === null) {
return null;
if (name === undefined) {
return undefined;
}
// TypeReference:
@ -3599,18 +3600,18 @@ module TypeScript.Parser {
}
var typeArgumentList = tryParseTypeArgumentList(/*inExpression:*/ false);
return typeArgumentList === null
return !typeArgumentList
? name
: new syntaxFactory.GenericTypeSyntax(parseNodeData, name, typeArgumentList);
}
function tryParseFunctionType(): FunctionTypeSyntax {
var typeParameterList = tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false);
var parameterList: ParameterListSyntax = null;
if (typeParameterList === null) {
var parameterList: ParameterListSyntax = undefined;
if (typeParameterList === undefined) {
parameterList = tryParseParameterList();
if (parameterList === null) {
return null;
if (parameterList === undefined) {
return undefined;
}
}
else {
@ -3628,7 +3629,7 @@ module TypeScript.Parser {
}
function isParameter(): boolean {
if (currentNode() !== null && currentNode().kind() === SyntaxKind.Parameter) {
if (currentNode() && currentNode().kind() === SyntaxKind.Parameter) {
return true;
}
@ -3644,13 +3645,13 @@ module TypeScript.Parser {
function eatSimpleParameter() {
return new syntaxFactory.ParameterSyntax(parseNodeData,
/*dotDotDotToken:*/ null, /*modifiers:*/ Syntax.emptyList<ISyntaxToken>(), eatIdentifierToken(),
/*questionToken:*/ null, /*typeAnnotation:*/ null, /*equalsValueClause:*/ null);
/*dotDotDotToken:*/ undefined, /*modifiers:*/ Syntax.emptyList<ISyntaxToken>(), eatIdentifierToken(),
/*questionToken:*/ undefined, /*typeAnnotation:*/ undefined, /*equalsValueClause:*/ undefined);
}
function tryParseParameter(): ParameterSyntax {
var node = currentNode();
if (node !== null && node.kind() === SyntaxKind.Parameter) {
if (node && node.kind() === SyntaxKind.Parameter) {
consumeNode(node);
return <ParameterSyntax>node;
}
@ -3661,7 +3662,7 @@ module TypeScript.Parser {
// If we're not forcing, and we don't see anything to indicate this is a parameter, then
// bail out.
var _currentToken = currentToken();
if (!isIdentifier(_currentToken) && dotDotDotToken === null && modifiers.length === 0) {
if (!isIdentifier(_currentToken) && !dotDotDotToken && modifiers.length === 0) {
// ERROR RECOVERY:
// If we see a modifier alone in a parameter list, like: foo(static)
//
@ -3670,7 +3671,7 @@ module TypeScript.Parser {
modifiers = Syntax.list([consumeToken(_currentToken)]);
}
else {
return null;
return undefined;
}
}
@ -3678,7 +3679,7 @@ module TypeScript.Parser {
var questionToken = tryEatToken(SyntaxKind.QuestionToken);
var typeAnnotation = parseOptionalTypeAnnotation(/*allowStringLiteral:*/ true);
var equalsValueClause: EqualsValueClauseSyntax = null;
var equalsValueClause: EqualsValueClauseSyntax = undefined;
if (isEqualsValueClause(/*inParameter*/ true)) {
equalsValueClause = parseEqualsValueClause(/*allowIn:*/ true);
}
@ -3687,7 +3688,7 @@ module TypeScript.Parser {
}
function parseSyntaxList<T extends ISyntaxNodeOrToken>(
currentListType: ListParsingState, skippedTokens: ISyntaxToken[], processItems: (items: any[]) => void = null): T[] {
currentListType: ListParsingState, skippedTokens: ISyntaxToken[], processItems?: (items: any[]) => void): T[] {
var savedListParsingState = listParsingState;
listParsingState |= (1 << currentListType);
@ -3769,14 +3770,14 @@ module TypeScript.Parser {
currentListType: ListParsingState, inErrorRecovery: boolean, items: ISyntaxElement[], processItems: (items: any[]) => void): boolean {
var item = tryParseExpectedListItemWorker(currentListType, inErrorRecovery);
if (item === null) {
if (item === undefined) {
return false;
}
// Debug.assert(item !== null);
// Debug.assert(item !== undefined);
items.push(item);
if (processItems !== null) {
if (processItems) {
processItems(items);
}
@ -3807,7 +3808,7 @@ module TypeScript.Parser {
// List wasn't complete and we didn't get an item. Figure out if we should bail out
// or skip a token and continue.
var abort = abortParsingListOrMoveToNextToken(currentListType, items, null, skippedTokens);
var abort = abortParsingListOrMoveToNextToken(currentListType, items, /*separators:*/ undefined, skippedTokens);
if (abort) {
break;
}
@ -3846,11 +3847,11 @@ module TypeScript.Parser {
// continue parsing.
// Debug.assert(oldItemsCount % 2 === 0);
var succeeded = tryParseExpectedListItem(currentListType, inErrorRecovery, nodes, null);
var succeeded = tryParseExpectedListItem(currentListType, inErrorRecovery, nodes, /*processItems:*/ undefined);
if (!succeeded) {
// We weren't able to parse out a list element.
// Debug.assert(items === null || items.length % 2 === 0);
// Debug.assert(items === undefined || items.length % 2 === 0);
// That may have been because the list is complete. In that case, break out
// and return the items we were able parse.
@ -4267,26 +4268,26 @@ module TypeScript.Parser {
function getExpectedListElementType(currentListType: ListParsingState): string {
switch (currentListType) {
case ListParsingState.SourceUnit_ModuleElements: return getLocalizedText(DiagnosticCode.module_class_interface_enum_import_or_statement, null);
case ListParsingState.SourceUnit_ModuleElements: return getLocalizedText(DiagnosticCode.module_class_interface_enum_import_or_statement, undefined);
case ListParsingState.ClassOrInterfaceDeclaration_HeritageClauses: return '{';
case ListParsingState.ClassDeclaration_ClassElements: return getLocalizedText(DiagnosticCode.constructor_function_accessor_or_variable, null);
case ListParsingState.ModuleDeclaration_ModuleElements: return getLocalizedText(DiagnosticCode.module_class_interface_enum_import_or_statement, null);
case ListParsingState.SwitchStatement_SwitchClauses: return getLocalizedText(DiagnosticCode.case_or_default_clause, null);
case ListParsingState.SwitchClause_Statements: return getLocalizedText(DiagnosticCode.statement, null);
case ListParsingState.Block_Statements: return getLocalizedText(DiagnosticCode.statement, null);
case ListParsingState.VariableDeclaration_VariableDeclarators_AllowIn: return getLocalizedText(DiagnosticCode.identifier, null);
case ListParsingState.VariableDeclaration_VariableDeclarators_DisallowIn: return getLocalizedText(DiagnosticCode.identifier, null);
case ListParsingState.EnumDeclaration_EnumElements: return getLocalizedText(DiagnosticCode.identifier, null);
case ListParsingState.ObjectType_TypeMembers: return getLocalizedText(DiagnosticCode.call_construct_index_property_or_function_signature, null);
case ListParsingState.ArgumentList_AssignmentExpressions: return getLocalizedText(DiagnosticCode.expression, null);
case ListParsingState.HeritageClause_TypeNameList: return getLocalizedText(DiagnosticCode.type_name, null);
case ListParsingState.ObjectLiteralExpression_PropertyAssignments: return getLocalizedText(DiagnosticCode.property_or_accessor, null);
case ListParsingState.ParameterList_Parameters: return getLocalizedText(DiagnosticCode.parameter, null);
case ListParsingState.IndexSignature_Parameters: return getLocalizedText(DiagnosticCode.parameter, null);
case ListParsingState.TypeArgumentList_Types: return getLocalizedText(DiagnosticCode.type, null);
case ListParsingState.TypeParameterList_TypeParameters: return getLocalizedText(DiagnosticCode.type_parameter, null);
case ListParsingState.TupleType_Types: return getLocalizedText(DiagnosticCode.type, null);
case ListParsingState.ArrayLiteralExpression_AssignmentExpressions: return getLocalizedText(DiagnosticCode.expression, null);
case ListParsingState.ClassDeclaration_ClassElements: return getLocalizedText(DiagnosticCode.constructor_function_accessor_or_variable, undefined);
case ListParsingState.ModuleDeclaration_ModuleElements: return getLocalizedText(DiagnosticCode.module_class_interface_enum_import_or_statement, undefined);
case ListParsingState.SwitchStatement_SwitchClauses: return getLocalizedText(DiagnosticCode.case_or_default_clause, undefined);
case ListParsingState.SwitchClause_Statements: return getLocalizedText(DiagnosticCode.statement, undefined);
case ListParsingState.Block_Statements: return getLocalizedText(DiagnosticCode.statement, undefined);
case ListParsingState.VariableDeclaration_VariableDeclarators_AllowIn: return getLocalizedText(DiagnosticCode.identifier, undefined);
case ListParsingState.VariableDeclaration_VariableDeclarators_DisallowIn: return getLocalizedText(DiagnosticCode.identifier, undefined);
case ListParsingState.EnumDeclaration_EnumElements: return getLocalizedText(DiagnosticCode.identifier, undefined);
case ListParsingState.ObjectType_TypeMembers: return getLocalizedText(DiagnosticCode.call_construct_index_property_or_function_signature, undefined);
case ListParsingState.ArgumentList_AssignmentExpressions: return getLocalizedText(DiagnosticCode.expression, undefined);
case ListParsingState.HeritageClause_TypeNameList: return getLocalizedText(DiagnosticCode.type_name, undefined);
case ListParsingState.ObjectLiteralExpression_PropertyAssignments: return getLocalizedText(DiagnosticCode.property_or_accessor, undefined);
case ListParsingState.ParameterList_Parameters: return getLocalizedText(DiagnosticCode.parameter, undefined);
case ListParsingState.IndexSignature_Parameters: return getLocalizedText(DiagnosticCode.parameter, undefined);
case ListParsingState.TypeArgumentList_Types: return getLocalizedText(DiagnosticCode.type, undefined);
case ListParsingState.TypeParameterList_TypeParameters: return getLocalizedText(DiagnosticCode.type_parameter, undefined);
case ListParsingState.TupleType_Types: return getLocalizedText(DiagnosticCode.type, undefined);
case ListParsingState.ArrayLiteralExpression_AssignmentExpressions: return getLocalizedText(DiagnosticCode.expression, undefined);
default: throw Errors.invalidOperation();
}
}

View File

@ -16,7 +16,7 @@ module TypeScript.PrettyPrinter {
}
private newLineCountBetweenModuleElements(element1: IModuleElementSyntax, element2: IModuleElementSyntax): number {
if (element1 === null || element2 === null) {
if (!element1 || !element2) {
return 0;
}
@ -28,7 +28,7 @@ module TypeScript.PrettyPrinter {
}
private newLineCountBetweenClassElements(element1: IClassElementSyntax, element2: IClassElementSyntax): number {
if (element1 === null || element2 === null) {
if (!element1 || !element2) {
return 0;
}
@ -36,7 +36,7 @@ module TypeScript.PrettyPrinter {
}
private newLineCountBetweenStatements(element1: IClassElementSyntax, element2: IClassElementSyntax): number {
if (element1 === null || element2 === null) {
if (!element1 || !element2) {
return 0;
}
@ -48,7 +48,7 @@ module TypeScript.PrettyPrinter {
}
private newLineCountBetweenSwitchClauses(element1: ISwitchClauseSyntax, element2: ISwitchClauseSyntax): number {
if (element1 === null || element2 === null) {
if (!element1 || !element2) {
return 0;
}
@ -120,7 +120,7 @@ module TypeScript.PrettyPrinter {
}
private appendToken(token: ISyntaxToken): void {
if (token !== null && token.fullWidth() > 0) {
if (token && token.fullWidth() > 0) {
this.appendIndentationIfAfterNewLine();
this.appendText(token.text());
}
@ -174,7 +174,7 @@ module TypeScript.PrettyPrinter {
}
private appendModuleElements(list: IModuleElementSyntax[]): void {
var lastModuleElement: IModuleElementSyntax = null;
var lastModuleElement: IModuleElementSyntax = undefined;
for (var i = 0, n = list.length; i < n; i++) {
var moduleElement = list[i];
var newLineCount = this.newLineCountBetweenModuleElements(lastModuleElement, moduleElement);
@ -236,7 +236,7 @@ module TypeScript.PrettyPrinter {
this.indentation++;
var lastClassElement: IClassElementSyntax = null;
var lastClassElement: IClassElementSyntax = undefined;
for (var i = 0, n = node.classElements.length; i < n; i++) {
var classElement = node.classElements[i];
var newLineCount = this.newLineCountBetweenClassElements(lastClassElement, classElement);
@ -472,7 +472,7 @@ module TypeScript.PrettyPrinter {
}
private appendStatements(statements: IStatementSyntax[]): void {
var lastStatement: IStatementSyntax = null;
var lastStatement: IStatementSyntax = undefined;
for (var i = 0, n = statements.length; i < n; i++) {
var statement = statements[i];
@ -743,7 +743,7 @@ module TypeScript.PrettyPrinter {
this.appendToken(node.openBraceToken);
this.ensureNewLine();
var lastSwitchClause: ISwitchClauseSyntax = null;
var lastSwitchClause: ISwitchClauseSyntax = undefined;
for (var i = 0, n = node.switchClauses.length; i < n; i++) {
var switchClause = node.switchClauses[i];

View File

@ -700,7 +700,7 @@ module TypeScript.Scanner {
while (true) {
if (index === end) {
reportDiagnostic(end, 0, DiagnosticCode.AsteriskSlash_expected, null);
reportDiagnostic(end, 0, DiagnosticCode.AsteriskSlash_expected, undefined);
return;
}
@ -916,7 +916,7 @@ module TypeScript.Scanner {
if (languageVersion >= ts.ScriptTarget.ES5) {
reportDiagnostic(
start, index - start, DiagnosticCode.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher, null);
start, index - start, DiagnosticCode.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher, undefined);
}
}
@ -1223,7 +1223,7 @@ module TypeScript.Scanner {
switch (ch) {
case CharacterCodes.backslash:
// We're now in an escape. Consume the next character we see (unless it's
// a newline or null.
// a newline or undefined.
inEscape = true;
continue;
@ -1364,7 +1364,7 @@ module TypeScript.Scanner {
break;
}
else if (isNaN(ch) || isNewLineCharacter(ch)) {
reportDiagnostic(Math.min(index, end), 1, DiagnosticCode.Missing_close_quote_character, null);
reportDiagnostic(Math.min(index, end), 1, DiagnosticCode.Missing_close_quote_character, undefined);
break;
}
else {
@ -1431,7 +1431,7 @@ module TypeScript.Scanner {
var ch2 = str.charCodeAt(index);
if (!CharacterInfo.isHexDigit(ch2)) {
if (report) {
reportDiagnostic(start, index - start, DiagnosticCode.Unrecognized_escape_sequence, null)
reportDiagnostic(start, index - start, DiagnosticCode.Unrecognized_escape_sequence, undefined)
}
break;
@ -1511,30 +1511,30 @@ module TypeScript.Scanner {
var rewindPointPool: IScannerRewindPoint[] = [];
var rewindPointPoolCount = 0;
var lastDiagnostic: Diagnostic = null;
var lastDiagnostic: Diagnostic = undefined;
var reportDiagnostic = (position: number, fullWidth: number, diagnosticKey: string, args: any[]) => {
lastDiagnostic = new Diagnostic(fileName, text.lineMap(), position, fullWidth, diagnosticKey, args);
};
// The sliding window that we store tokens in.
var slidingWindow = new SlidingWindow(fetchNextItem, ArrayUtilities.createArray(/*defaultWindowSize:*/ 1024, null), null);
var slidingWindow = new SlidingWindow(fetchNextItem, ArrayUtilities.createArray(/*defaultWindowSize:*/ 1024, undefined), undefined);
// The scanner we're pulling tokens from.
var scanner = createScanner(languageVersion, text, reportDiagnostic);
function release() {
slidingWindow = null;
scanner = null;
slidingWindow = undefined;
scanner = undefined;
_tokenDiagnostics = [];
rewindPointPool = [];
lastDiagnostic = null;
reportDiagnostic = null;
lastDiagnostic = undefined;
reportDiagnostic = undefined;
}
function currentNode(): ISyntaxNode {
// The normal parser source never returns nodes. They're only returned by the
// incremental parser source.
return null;
return undefined;
}
function consumeNode(node: ISyntaxNode): void {
@ -1557,7 +1557,7 @@ module TypeScript.Scanner {
rewindPointPoolCount--;
var result = rewindPointPool[rewindPointPoolCount];
rewindPointPool[rewindPointPoolCount] = null;
rewindPointPool[rewindPointPoolCount] = undefined;
return result;
}
@ -1593,7 +1593,7 @@ module TypeScript.Scanner {
// Debug.assert(spaceAvailable > 0);
var token = scanner.scan(allowContextualToken);
if (lastDiagnostic === null) {
if (lastDiagnostic === undefined) {
return token;
}
@ -1601,7 +1601,7 @@ module TypeScript.Scanner {
// it won't be reused in incremental scenarios.
_tokenDiagnostics.push(lastDiagnostic);
lastDiagnostic = null;
lastDiagnostic = undefined;
return Syntax.realizeToken(token, text);
}

View File

@ -167,7 +167,7 @@ module TypeScript {
// Assert disabled because it is actually expensive enugh to affect perf.
// Debug.assert(n >= 0);
while (this.currentRelativeItemIndex + n >= this.windowCount) {
if (!this.addMoreItemsToWindow(/*argument:*/ null)) {
if (!this.addMoreItemsToWindow(/*argument:*/ undefined)) {
return this.defaultValue;
}
}

View File

@ -63,8 +63,8 @@ module TypeScript.Syntax {
export function isEntirelyInsideComment(sourceUnit: SourceUnitSyntax, position: number): boolean {
var positionedToken = findToken(sourceUnit, position);
var fullStart = positionedToken.fullStart();
var triviaList: ISyntaxTriviaList = null;
var lastTriviaBeforeToken: ISyntaxTrivia = null;
var triviaList: ISyntaxTriviaList = undefined;
var lastTriviaBeforeToken: ISyntaxTrivia = undefined;
if (positionedToken.kind() === SyntaxKind.EndOfFileToken) {
// Check if the trivia is leading on the EndOfFile token
@ -133,7 +133,7 @@ module TypeScript.Syntax {
}
function findSkippedTokenOnLeftInTriviaList(positionedToken: ISyntaxToken, position: number, lookInLeadingTriviaList: boolean): ISyntaxToken {
var triviaList: TypeScript.ISyntaxTriviaList = null;
var triviaList: TypeScript.ISyntaxTriviaList = undefined;
var fullEnd: number;
if (lookInLeadingTriviaList) {
@ -158,7 +158,7 @@ module TypeScript.Syntax {
}
}
return null;
return undefined;
}
export function findSkippedTokenOnLeft(positionedToken: ISyntaxToken, position: number): ISyntaxToken {
@ -175,11 +175,11 @@ module TypeScript.Syntax {
positionedToken = positionedToken.parent;
}
return null;
return undefined;
}
export function hasAncestorOfKind(positionedToken: ISyntaxElement, kind: SyntaxKind): boolean {
return getAncestorOfKind(positionedToken, kind) !== null;
return !!getAncestorOfKind(positionedToken, kind);
}
export function isIntegerLiteral(expression: IExpressionSyntax): boolean {
@ -207,7 +207,7 @@ module TypeScript.Syntax {
export function containingNode(element: ISyntaxElement): ISyntaxNode {
var current = element.parent;
while (current !== null && !isNode(current)) {
while (current && !isNode(current)) {
current = current.parent;
}
@ -234,7 +234,7 @@ module TypeScript.Syntax {
// we're in the trivia before the start of the token. Need to return the previous token.
if (positionedToken.fullStart() === 0) {
// Already on the first token. Nothing before us.
return null;
return undefined;
}
return previousToken(positionedToken, includeSkippedTokens);
@ -274,7 +274,7 @@ module TypeScript.Syntax {
function isFirstTokenInLine(token: ISyntaxToken, lineMap: LineMap): boolean {
var _previousToken = previousToken(token);
if (_previousToken === null) {
if (_previousToken === undefined) {
return true;
}

View File

@ -54,7 +54,7 @@ module TypeScript {
}
}
return null;
return undefined;
}
export function parsedInStrictMode(node: ISyntaxNode): boolean {
@ -84,7 +84,7 @@ module TypeScript {
var start = token.fullStart();
if (start === 0) {
return null;
return undefined;
}
return findToken(syntaxTree(token).sourceUnit(), start - 1, includeSkippedTokens);
@ -105,7 +105,7 @@ module TypeScript {
*/
export function findToken(element: ISyntaxElement, position: number, includeSkippedTokens: boolean = false): ISyntaxToken {
var endOfFileToken = tryGetEndOfFileAt(element, position);
if (endOfFileToken !== null) {
if (endOfFileToken) {
return endOfFileToken;
}
@ -137,7 +137,7 @@ module TypeScript {
}
function findSkippedTokenInTriviaList(positionedToken: ISyntaxToken, position: number, lookInLeadingTriviaList: boolean): ISyntaxToken {
var triviaList: TypeScript.ISyntaxTriviaList = null;
var triviaList: TypeScript.ISyntaxTriviaList = undefined;
var fullStart: number;
if (lookInLeadingTriviaList) {
@ -162,7 +162,7 @@ module TypeScript {
}
}
return null;
return undefined;
}
function findTokenWorker(element: ISyntaxElement, position: number): ISyntaxToken {
@ -182,7 +182,7 @@ module TypeScript {
for (var i = 0, n = childCount(element); i < n; i++) {
var child = childAt(element, i);
if (child !== null) {
if (child) {
var childFullWidth = fullWidth(child);
if (childFullWidth > 0) {
var childFullStart = fullStart(child);
@ -207,12 +207,12 @@ module TypeScript {
return sourceUnit.endOfFileToken;
}
return null;
return undefined;
}
export function nextToken(token: ISyntaxToken, text?: ISimpleText, includeSkippedTokens: boolean = false): ISyntaxToken {
if (token.kind() === SyntaxKind.EndOfFileToken) {
return null;
return undefined;
}
if (includeSkippedTokens) {
@ -231,7 +231,7 @@ module TypeScript {
}
export function isNode(element: ISyntaxElement): boolean {
if (element !== null) {
if (element) {
var kind = element.kind();
return kind >= SyntaxKind.FirstNode && kind <= SyntaxKind.LastNode;
}
@ -244,7 +244,7 @@ module TypeScript {
}
export function isToken(element: ISyntaxElement): boolean {
if (element !== null) {
if (element) {
return isTokenKind(element.kind());
}
@ -252,11 +252,11 @@ module TypeScript {
}
export function isList(element: ISyntaxElement): boolean {
return element !== null && element.kind() === SyntaxKind.List;
return element && element.kind() === SyntaxKind.List;
}
export function isSeparatedList(element: ISyntaxElement): boolean {
return element !== null && element.kind() === SyntaxKind.SeparatedList;
return element && element.kind() === SyntaxKind.SeparatedList;
}
export function syntaxID(element: ISyntaxElement): number {
@ -311,7 +311,7 @@ module TypeScript {
var kind = element.kind();
if (isTokenKind(kind)) {
return fullWidth(element) > 0 || element.kind() === SyntaxKind.EndOfFileToken ? <ISyntaxToken>element : null;
return fullWidth(element) > 0 || element.kind() === SyntaxKind.EndOfFileToken ? <ISyntaxToken>element : undefined;
}
if (kind === SyntaxKind.List) {
@ -349,12 +349,12 @@ module TypeScript {
}
}
return null;
return undefined;
}
export function lastToken(element: ISyntaxElement): ISyntaxToken {
if (isToken(element)) {
return fullWidth(element) > 0 || element.kind() === SyntaxKind.EndOfFileToken ? <ISyntaxToken>element : null;
return fullWidth(element) > 0 || element.kind() === SyntaxKind.EndOfFileToken ? <ISyntaxToken>element : undefined;
}
if (element.kind() === SyntaxKind.SourceUnit) {
@ -363,7 +363,7 @@ module TypeScript {
for (var i = childCount(element) - 1; i >= 0; i--) {
var child = childAt(element, i);
if (child !== null) {
if (child) {
var token = lastToken(child);
if (token) {
return token;
@ -371,7 +371,7 @@ module TypeScript {
}
}
return null;
return undefined;
}
export function fullStart(element: ISyntaxElement): number {
@ -474,7 +474,7 @@ module TypeScript {
return false;
}
if (token1 === null || token2 === null) {
if (!token1 || !token2) {
return true;
}

View File

@ -134,7 +134,7 @@ module TypeScript.SyntaxFacts {
export function getText(kind: SyntaxKind): string {
var result = kindToText[kind];
return result !== undefined ? result : null;
return result;// !== undefined ? result : undefined;
}
export function isAnyKeyword(kind: SyntaxKind): boolean {

View File

@ -1065,7 +1065,7 @@ function generateProperties(definition: ITypeDefinition): string {
var result = "";
if (definition.name === "SourceUnitSyntax") {
result += " public syntaxTree: SyntaxTree = null;\r\n";
result += " public syntaxTree: SyntaxTree = undefined;\r\n";
}
var newLine = false;
@ -1097,7 +1097,7 @@ function generateNullChecks(definition: ITypeDefinition): string {
var child = definition.children[i];
if (!child.isOptional && !child.isToken) {
result += " if (" + child.name + " === null) { throw Errors.argumentNull('" + child.name + "'); }\r\n";
result += " if (!" + child.name + ") { throw Errors.argumentNull('" + child.name + "'); }\r\n";
}
}
@ -1211,7 +1211,7 @@ function generateKindCheck(child: IMemberDefinition): string {
if (child.isOptional) {
indent = " ";
result += " if (" + child.name + " !== null) {\r\n";
result += " if (" + child.name + ") {\r\n";
}
var kinds = tokenKinds(child);
@ -1268,7 +1268,7 @@ function generateConstructor(definition: ITypeDefinition): string {
result += " constructor("
var children = definition.children;
var kindChild: IMemberDefinition = null;
var kindChild: IMemberDefinition = undefined;
for (i = 0; i < children.length; i++) {
child = children[i];
@ -1385,7 +1385,7 @@ function generateFactory1Method(definition: ITypeDefinition): string {
result += "Syntax.emptySeparatedList<" + child.elementType + ">()";
}
else {
result += "null";
result += "undefined";
}
result += ", ";
@ -1412,7 +1412,7 @@ function isKeywordOrPunctuation(kind: string): boolean {
}
function isDefaultConstructable(definition: ITypeDefinition): boolean {
if (definition === null) {
if (!definition) {
return false;
}
@ -1489,7 +1489,7 @@ function generateFactory2Method(definition: ITypeDefinition): string {
result += "Syntax.emptySeparatedList<" + child.elementType + ">()";
}
else if (isOptional(child)) {
result += "null";
result += "undefined";
}
else if (child.isToken) {
result += "Syntax.token(SyntaxKind." + tokenKinds(child)[0] + ")";
@ -1615,7 +1615,7 @@ function generateFirstTokenMethod(definition: ITypeDefinition): string {
result += "\r\n";
result += " public firstToken(): ISyntaxToken {\r\n";
result += " var token = null;\r\n";
result += " var token: ISyntaxToken = undefined;\r\n";
for (var i = 0; i < definition.children.length; i++) {
var child = definition.children[i];
@ -1631,7 +1631,7 @@ function generateFirstTokenMethod(definition: ITypeDefinition): string {
result += " if (";
if (child.isOptional) {
result += getPropertyAccess(child) + " !== null && ";
result += getPropertyAccess(child) + " && ";
}
if (child.isToken) {
@ -1639,7 +1639,7 @@ function generateFirstTokenMethod(definition: ITypeDefinition): string {
result += ") { return " + getPropertyAccess(child) + "; }\r\n";
}
else {
result += "(token = " + getPropertyAccess(child) + ".firstToken()) !== null";
result += "(token = " + getPropertyAccess(child) + ".firstToken())";
result += ") { return token; }\r\n";
}
}
@ -1648,7 +1648,7 @@ function generateFirstTokenMethod(definition: ITypeDefinition): string {
result += " return this._endOfFileToken;\r\n";
}
else {
result += " return null;\r\n";
result += " return undefined;\r\n";
}
result += " }\r\n";
@ -1668,7 +1668,7 @@ function generateLastTokenMethod(definition: ITypeDefinition): string {
result += " return this._endOfFileToken;\r\n";
}
else {
result += " var token = null;\r\n";
result += " var token: ISyntaxToken = undefined;\r\n";
for (var i = definition.children.length - 1; i >= 0; i--) {
var child = definition.children[i];
@ -1684,7 +1684,7 @@ function generateLastTokenMethod(definition: ITypeDefinition): string {
result += " if (";
if (child.isOptional) {
result += getPropertyAccess(child) + " !== null && ";
result += getPropertyAccess(child) + " && ";
}
if (child.isToken) {
@ -1692,12 +1692,12 @@ function generateLastTokenMethod(definition: ITypeDefinition): string {
result += ") { return " + getPropertyAccess(child) + "; }\r\n";
}
else {
result += "(token = " + getPropertyAccess(child) + ".lastToken()) !== null";
result += "(token = " + getPropertyAccess(child) + ".lastToken())";
result += ") { return token; }\r\n";
}
}
result += " return null;\r\n";
result += " return undefined;\r\n";
}
result += " }\r\n";
@ -1716,7 +1716,7 @@ function memberDefinitionType(child: IMemberDefinition): ITypeDefinition {
function derivesFrom(def1: ITypeDefinition, def2: ITypeDefinition): boolean {
var current = def1;
while (current !== null) {
while (current) {
var base = baseType(current);
if (base === def2) {
return true;
@ -1909,7 +1909,7 @@ function generateNode(definition: ITypeDefinition, abstract: boolean): string {
result += " {\r\n";
if (definition.name === "SourceUnitSyntax") {
result += " public syntaxTree: SyntaxTree = null;\r\n";
result += " public syntaxTree: SyntaxTree = undefined;\r\n";
}
for (var i = 0; i < definition.children.length; i++) {
@ -1930,7 +1930,7 @@ function generateNode(definition: ITypeDefinition, abstract: boolean): string {
result += " super(data);\r\n";
if (definition.name === "SourceUnitSyntax") {
result += " this.parent = null,\r\n";
result += " this.parent = undefined,\r\n";
}
if (definition.children) {
@ -2173,13 +2173,13 @@ function generateRewriter(): string {
" }\r\n" +
"\r\n" +
" public visitList<T extends ISyntaxNodeOrToken>(list: T[]): T[] {\r\n" +
" var newItems: T[] = null;\r\n" +
" var newItems: T[] = undefined;\r\n" +
"\r\n" +
" for (var i = 0, n = list.length; i < n; i++) {\r\n" +
" var item = list[i];\r\n" +
" var newItem = <T>this.visitNodeOrToken(item);\r\n" +
"\r\n" +
" if (item !== newItem && newItems === null) {\r\n" +
" if (item !== newItem && !newItems) {\r\n" +
" newItems = [];\r\n" +
" for (var j = 0; j < i; j++) {\r\n" +
" newItems.push(list[j]);\r\n" +
@ -2191,18 +2191,18 @@ function generateRewriter(): string {
" }\r\n" +
" }\r\n" +
"\r\n" +
" // Debug.assert(newItems === null || newItems.length === childCount(list));\r\n" +
" return newItems === null ? list : Syntax.list<T>(newItems);\r\n" +
" // Debug.assert(!newItems || newItems.length === childCount(list));\r\n" +
" return !newItems ? list : Syntax.list<T>(newItems);\r\n" +
" }\r\n" +
"\r\n" +
" public visitSeparatedList<T extends ISyntaxNodeOrToken>(list: T[]): T[] {\r\n" +
" var newItems: ISyntaxNodeOrToken[] = null;\r\n" +
" var newItems: ISyntaxNodeOrToken[] = undefined;\r\n" +
"\r\n" +
" for (var i = 0, n = childCount(list); i < n; i++) {\r\n" +
" var item = childAt(list, i);\r\n" +
" var newItem = isToken(item) ? <ISyntaxNodeOrToken>this.visitToken(<ISyntaxToken>item) : this.visitNode(<ISyntaxNode>item);\r\n" +
"\r\n" +
" if (item !== newItem && newItems === null) {\r\n" +
" if (item !== newItem && !newItems) {\r\n" +
" newItems = [];\r\n" +
" for (var j = 0; j < i; j++) {\r\n" +
" newItems.push(childAt(list, j));\r\n" +
@ -2214,8 +2214,8 @@ function generateRewriter(): string {
" }\r\n" +
" }\r\n" +
"\r\n" +
" // Debug.assert(newItems === null || newItems.length === childCount(list));\r\n" +
" return newItems === null ? list : Syntax.separatedList<T>(newItems);\r\n" +
" // Debug.assert(newItems === undefined || newItems.length === childCount(list));\r\n" +
" return !newItems ? list : Syntax.separatedList<T>(newItems);\r\n" +
" }\r\n";
for (var i = 0; i < definitions.length; i++) {
@ -2242,7 +2242,7 @@ function generateRewriter(): string {
result += " ";
if (child.isOptional) {
result += "node." + child.name + " === null ? null : ";
result += "!node." + child.name + " ? undefined : ";
}
if (child.isToken) {
@ -2303,7 +2303,7 @@ function generateWalker(): string {
" }\r\n" +
"\r\n" +
" private visitOptionalToken(token: ISyntaxToken): void {\r\n" +
" if (token === null) {\r\n" +
" if (token === undefined) {\r\n" +
" return;\r\n" +
" }\r\n" +
"\r\n" +
@ -2311,7 +2311,7 @@ function generateWalker(): string {
" }\r\n" +
"\r\n" +
" public visitOptionalNode(node: ISyntaxNode): void {\r\n" +
" if (node === null) {\r\n" +
" if (node === undefined) {\r\n" +
" return;\r\n" +
" }\r\n" +
"\r\n" +
@ -2319,7 +2319,7 @@ function generateWalker(): string {
" }\r\n" +
"\r\n" +
" public visitOptionalNodeOrToken(nodeOrToken: ISyntaxNodeOrToken): void {\r\n" +
" if (nodeOrToken === null) {\r\n" +
" if (nodeOrToken === undefined) {\r\n" +
" return;\r\n" +
" }\r\n" +
"\r\n" +
@ -2535,7 +2535,7 @@ function generateVisitor(): string {
result += "module TypeScript {\r\n";
result += " export function visitNodeOrToken(visitor: ISyntaxVisitor, element: ISyntaxNodeOrToken): any {\r\n";
result += " if (element === null) { return null; }\r\n";
result += " if (element === undefined) { return undefined; }\r\n";
result += " if (isToken(element)) { return visitor.visitToken(<ISyntaxToken>element); }\r\n";
result += " switch (element.kind()) {\r\n";
@ -2584,7 +2584,7 @@ function generateDefaultVisitor(): string {
if (!forPrettyPrinter) {
result += " export class SyntaxVisitor implements ISyntaxVisitor {\r\n";
result += " public defaultVisit(node: ISyntaxNodeOrToken): any {\r\n";
result += " return null;\r\n";
result += " return undefined;\r\n";
result += " }\r\n";
result += "\r\n";
result += " public visitToken(token: ISyntaxToken): any {\r\n";
@ -2738,7 +2738,7 @@ function generateIsTypeScriptSpecific(): string {
result += " }\r\n\r\n";
result += " export function isTypeScriptSpecific(element: ISyntaxElement): boolean {\r\n"
result += " if (element === null) { return false; }\r\n";
result += " if (!element) { return false; }\r\n";
result += " if (isToken(element)) { return false; }\r\n";
result += " if (isList(element)) { return isListTypeScriptSpecific(<ISyntaxNodeOrToken[]>element); }\r\n";
result += " if (isSeparatedList(element)) { return isSeparatedListTypeScriptSpecific(<ISyntaxNodeOrToken[]>element); }\r\n\r\n";
@ -2855,7 +2855,7 @@ function generateIsTypeScriptSpecificMethod(definition: ITypeDefinition): string
result += getPropertyAccess(child, "node") + ".childCount() > 0";
}
else {
result += getPropertyAccess(child, "node") + " !== null";
result += "!!" + getPropertyAccess(child, "node");
}
}
else {

View File

@ -51,7 +51,7 @@ module TypeScript.Syntax {
}
export function list<T extends ISyntaxNodeOrToken>(nodes: T[]): T[] {
if (nodes === undefined || nodes === null || nodes.length === 0) {
if (!nodes || nodes.length === 0) {
return emptyList<T>();
}
@ -63,7 +63,7 @@ module TypeScript.Syntax {
}
export function separatedList<T extends ISyntaxNodeOrToken>(nodes: T[], separators: ISyntaxToken[]): T[] {
if (nodes === undefined || nodes === null || nodes.length === 0) {
if (!nodes || nodes.length === 0) {
return emptySeparatedList<T>();
}

View File

@ -6,12 +6,12 @@ module TypeScript.Syntax.Abstract {
export var isConcrete: boolean = false;
export class SourceUnitSyntax extends SyntaxNode {
public syntaxTree: SyntaxTree = null;
public syntaxTree: SyntaxTree = undefined;
public moduleElements: IModuleElementSyntax[];
public endOfFileToken: ISyntaxToken;
constructor(data: number, moduleElements: IModuleElementSyntax[], endOfFileToken: ISyntaxToken) {
super(data);
this.parent = null,
this.parent = undefined,
this.moduleElements = moduleElements,
this.endOfFileToken = endOfFileToken,
!isShared(moduleElements) && (moduleElements.parent = this),

View File

@ -6,12 +6,12 @@ module TypeScript.Syntax.Concrete {
export var isConcrete: boolean = true;
export class SourceUnitSyntax extends SyntaxNode {
public syntaxTree: SyntaxTree = null;
public syntaxTree: SyntaxTree = undefined;
public moduleElements: IModuleElementSyntax[];
public endOfFileToken: ISyntaxToken;
constructor(data: number, moduleElements: IModuleElementSyntax[], endOfFileToken: ISyntaxToken) {
super(data);
this.parent = null,
this.parent = undefined,
this.moduleElements = moduleElements,
this.endOfFileToken = endOfFileToken,
!isShared(moduleElements) && (moduleElements.parent = this),

View File

@ -71,7 +71,7 @@ module TypeScript {
module TypeScript {
export function tokenValue(token: ISyntaxToken): any {
if (token.fullWidth() === 0) {
return null;
return undefined;
}
var kind = token.kind();
@ -87,7 +87,7 @@ module TypeScript {
case SyntaxKind.FalseKeyword:
return false;
case SyntaxKind.NullKeyword:
return null;
return undefined;
}
if (SyntaxFacts.isAnyKeyword(kind) || SyntaxFacts.isAnyPunctuation(kind)) {
@ -112,7 +112,7 @@ module TypeScript {
return regularExpressionValue(text);
}
else if (kind === SyntaxKind.EndOfFileToken || kind === SyntaxKind.ErrorToken) {
return null;
return undefined;
}
else {
throw Errors.invalidOperation();
@ -121,7 +121,7 @@ module TypeScript {
export function tokenValueText(token: ISyntaxToken): string {
var value = tokenValue(token);
return value === null ? "" : massageDisallowedIdentifiers(value.toString());
return value === undefined ? "" : massageDisallowedIdentifiers(value.toString());
}
export function massageEscapes(text: string): string {
@ -136,7 +136,7 @@ module TypeScript {
return new RegExp(body, flags);
}
catch (e) {
return null;
return undefined;
}
}
@ -235,13 +235,13 @@ module TypeScript {
characterArray.push(ch);
if (i && !(i % 1024)) {
result = result.concat(String.fromCharCode.apply(null, characterArray));
result = result.concat(String.fromCharCode.apply(undefined, characterArray));
characterArray.length = 0;
}
}
if (characterArray.length) {
result = result.concat(String.fromCharCode.apply(null, characterArray));
result = result.concat(String.fromCharCode.apply(undefined, characterArray));
}
return result;
@ -330,14 +330,14 @@ module TypeScript.Syntax {
// the full-start of this token to be at the full-end of that element.
var previousElement = this.previousNonZeroWidthElement();
return previousElement === null ? 0 : fullStart(previousElement) + fullWidth(previousElement);
return !previousElement ? 0 : fullStart(previousElement) + fullWidth(previousElement);
}
private previousNonZeroWidthElement(): ISyntaxElement {
var current: ISyntaxElement = this;
while (true) {
var parent = current.parent;
if (parent === null) {
if (parent === undefined) {
Debug.assert(current.kind() === SyntaxKind.SourceUnit, "We had a node without a parent that was not the root node!");
// We walked all the way to the top, and never found a previous element. This
@ -346,9 +346,9 @@ module TypeScript.Syntax {
// / b;
//
// We will have an empty identifier token as the first token in the tree. In
// this case, return null so that the position of the empty token will be
// this case, return undefined so that the position of the empty token will be
// considered to be 0.
return null;
return undefined;
}
// Ok. We have a parent. First, find out which slot we're at in the parent.

View File

@ -8,7 +8,7 @@ module TypeScript {
private _sourceUnit: SourceUnitSyntax;
private _isDeclaration: boolean;
private _parserDiagnostics: Diagnostic[];
private _allDiagnostics: Diagnostic[] = null;
private _allDiagnostics: Diagnostic[] = undefined;
private _fileName: string;
private _lineMap: LineMap;
private _languageVersion: ts.ScriptTarget;
@ -60,7 +60,7 @@ module TypeScript {
}
public diagnostics(): Diagnostic[] {
if (this._allDiagnostics === null) {
if (!this._allDiagnostics) {
var start = new Date().getTime();
this._allDiagnostics = this.computeDiagnostics();
syntaxDiagnosticsTime += new Date().getTime() - start;
@ -87,7 +87,7 @@ module TypeScript {
var firstToken = firstSyntaxTreeToken(this);
var leadingTrivia = firstToken.leadingTrivia(this.text);
this._isExternalModule = externalModuleIndicatorSpanWorker(this, firstToken) !== null;
this._isExternalModule = !!externalModuleIndicatorSpanWorker(this, firstToken);
var amdDependencies: string[] = [];
for (var i = 0, n = leadingTrivia.count(); i < n; i++) {
@ -106,7 +106,7 @@ module TypeScript {
private getAmdDependency(comment: string): string {
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s+path=('|")(.+?)\1/gim;
var match = amdDependencyRegEx.exec(comment);
return match ? match[2] : null;
return match ? match[2] : undefined;
}
public isExternalModule(): boolean {
@ -144,7 +144,7 @@ module TypeScript {
this.text = syntaxTree.text;
}
private pushDiagnostic(element: ISyntaxElement, diagnosticKey: string, args: any[] = null): void {
private pushDiagnostic(element: ISyntaxElement, diagnosticKey: string, args?: any[]): void {
this.diagnostics.push(new Diagnostic(
this.syntaxTree.fileName(), this.syntaxTree.lineMap(), start(element, this.text), width(element), diagnosticKey, args));
}
@ -303,7 +303,7 @@ module TypeScript {
}
public visitVariableDeclaration(node: VariableDeclarationSyntax): void {
if (this.checkForAtLeastOneElement(node, node.variableDeclarators, node.varKeyword, getLocalizedText(DiagnosticCode.variable_declaration, null)) ||
if (this.checkForAtLeastOneElement(node, node.variableDeclarators, node.varKeyword, getLocalizedText(DiagnosticCode.variable_declaration, undefined)) ||
this.checkForTrailingComma(node.variableDeclarators)) {
return;
}
@ -313,7 +313,7 @@ module TypeScript {
public visitTypeArgumentList(node: TypeArgumentListSyntax): void {
if (this.checkForTrailingComma(node.typeArguments) ||
this.checkForAtLeastOneElement(node, node.typeArguments, node.lessThanToken, getLocalizedText(DiagnosticCode.type_argument, null))) {
this.checkForAtLeastOneElement(node, node.typeArguments, node.lessThanToken, getLocalizedText(DiagnosticCode.type_argument, undefined))) {
return;
}
@ -322,7 +322,7 @@ module TypeScript {
public visitTupleType(node: TupleTypeSyntax): void {
if (this.checkForTrailingComma(node.types) ||
this.checkForAtLeastOneElement(node, node.types, node.openBracketToken, getLocalizedText(DiagnosticCode.type, null))) {
this.checkForAtLeastOneElement(node, node.types, node.openBracketToken, getLocalizedText(DiagnosticCode.type, undefined))) {
return
}
@ -331,7 +331,7 @@ module TypeScript {
public visitTypeParameterList(node: TypeParameterListSyntax): void {
if (this.checkForTrailingComma(node.typeParameters) ||
this.checkForAtLeastOneElement(node, node.typeParameters, node.lessThanToken, getLocalizedText(DiagnosticCode.type_parameter, null))) {
this.checkForAtLeastOneElement(node, node.typeParameters, node.lessThanToken, getLocalizedText(DiagnosticCode.type_parameter, undefined))) {
return;
}
@ -635,7 +635,7 @@ module TypeScript {
}
private checkForDisallowedAccessorTypeParameters(callSignature: CallSignatureSyntax): boolean {
if (callSignature.typeParameterList !== null) {
if (callSignature.typeParameterList) {
this.pushDiagnostic(callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_an_accessor);
return true;
}
@ -745,7 +745,7 @@ module TypeScript {
public visitInvocationExpression(node: InvocationExpressionSyntax): void {
if (node.expression.kind() === SyntaxKind.SuperKeyword &&
node.argumentList.typeArgumentList !== null) {
node.argumentList.typeArgumentList) {
this.pushDiagnostic(node, DiagnosticCode.super_invocation_cannot_have_type_arguments);
}
@ -1529,11 +1529,11 @@ module TypeScript {
}
}
return null;
return undefined;
}
private isEvalOrArguments(expr: IExpressionSyntax): boolean {
return this.getEvalOrArguments(expr) !== null;
return !!this.getEvalOrArguments(expr);
}
public visitConstraint(node: ConstraintSyntax): void {
@ -1583,7 +1583,7 @@ module TypeScript {
}
}
return null;
return undefined;
}
function implicitImportSpanWorker(trivia: ISyntaxTrivia): TextSpan {
@ -1594,7 +1594,7 @@ module TypeScript {
return new TextSpan(trivia.fullStart(), trivia.fullWidth());
}
return null;
return undefined;
}
function topLevelImportOrExportSpan(node: SourceUnitSyntax): TextSpan {
@ -1602,7 +1602,7 @@ module TypeScript {
var moduleElement = node.moduleElements[i];
var _firstToken = firstToken(moduleElement);
if (_firstToken !== null && _firstToken.kind() === SyntaxKind.ExportKeyword) {
if (_firstToken && _firstToken.kind() === SyntaxKind.ExportKeyword) {
return new TextSpan(start(_firstToken), width(_firstToken));
}
@ -1615,6 +1615,6 @@ module TypeScript {
}
}
return null;
return undefined;
}
}

View File

@ -233,7 +233,7 @@ module TypeScript.Syntax {
}
export function triviaList(trivia: ISyntaxTrivia[]): ISyntaxTriviaList {
if (trivia === undefined || trivia === null || trivia.length === 0) {
if (!trivia || trivia.length === 0) {
return Syntax.emptyTriviaList;
}

View File

@ -21,7 +21,7 @@ module TypeScript {
public static isLastTokenOnLine(token: ISyntaxToken, text: ISimpleText): boolean {
var _nextToken = nextToken(token, text);
if (_nextToken === null) {
if (_nextToken === undefined) {
return true;
}
@ -252,7 +252,7 @@ module TypeScript {
public static isAngleBracket(positionedElement: ISyntaxElement): boolean {
var element = positionedElement;
var parent = positionedElement.parent;
if (parent !== null && (element.kind() === SyntaxKind.LessThanToken || element.kind() === SyntaxKind.GreaterThanToken)) {
if (parent && (element.kind() === SyntaxKind.LessThanToken || element.kind() === SyntaxKind.GreaterThanToken)) {
switch (parent.kind()) {
case SyntaxKind.TypeArgumentList:
case SyntaxKind.TypeParameterList:
@ -272,15 +272,15 @@ module TypeScript {
}
}
return null;
return undefined;
}
public static containsToken(list: ISyntaxToken[], kind: SyntaxKind): boolean {
return SyntaxUtilities.getToken(list, kind) !== null;
return !!SyntaxUtilities.getToken(list, kind);
}
public static hasExportKeyword(moduleElement: IModuleElementSyntax): boolean {
return SyntaxUtilities.getExportKeyword(moduleElement) !== null;
return !!SyntaxUtilities.getExportKeyword(moduleElement);
}
public static getExportKeyword(moduleElement: IModuleElementSyntax): ISyntaxToken {
@ -294,7 +294,7 @@ module TypeScript {
case SyntaxKind.ImportDeclaration:
return SyntaxUtilities.getToken((<any>moduleElement).modifiers, SyntaxKind.ExportKeyword);
default:
return null;
return undefined;
}
}

View File

@ -2,7 +2,7 @@
module TypeScript {
export function visitNodeOrToken(visitor: ISyntaxVisitor, element: ISyntaxNodeOrToken): any {
if (element === null) { return null; }
if (element === undefined) { return undefined; }
if (isToken(element)) { return visitor.visitToken(<ISyntaxToken>element); }
switch (element.kind()) {
case SyntaxKind.SourceUnit: return visitor.visitSourceUnit(<SourceUnitSyntax>element);

View File

@ -19,7 +19,7 @@ module TypeScript {
}
private visitOptionalToken(token: ISyntaxToken): void {
if (token === null) {
if (token === undefined) {
return;
}
@ -27,7 +27,7 @@ module TypeScript {
}
public visitOptionalNode(node: ISyntaxNode): void {
if (node === null) {
if (node === undefined) {
return;
}
@ -35,7 +35,7 @@ module TypeScript {
}
public visitOptionalNodeOrToken(nodeOrToken: ISyntaxNodeOrToken): void {
if (nodeOrToken === null) {
if (nodeOrToken === undefined) {
return;
}

View File

@ -7,7 +7,7 @@ module TypeScript {
export function nodeStructuralEquals(node1: TypeScript.ISyntaxNode, node2: TypeScript.ISyntaxNode, checkParents: boolean, text1: ISimpleText, text2: ISimpleText): boolean {
if (node1 === node2) { return true; }
if (node1 === null || node2 === null) { return false; }
if (!node1 || !node2) { return false; }
Debug.assert(node1.kind() === TypeScript.SyntaxKind.SourceUnit || node1.parent);
Debug.assert(node2.kind() === TypeScript.SyntaxKind.SourceUnit || node2.parent);
@ -37,7 +37,7 @@ module TypeScript {
return true;
}
if (node1 === null || node2 === null) {
if (!node1 || !node2) {
return false;
}
@ -56,7 +56,7 @@ module TypeScript {
return true;
}
if (token1 === null || token2 === null) {
if (!token1 || !token2) {
return false;
}
@ -156,7 +156,7 @@ module TypeScript {
return true;
}
if (element1 === null || element2 === null) {
if (!element1 || !element2) {
return false;
}

View File

@ -32,7 +32,7 @@ module TypeScript {
export module ScriptSnapshot {
class StringScriptSnapshot implements IScriptSnapshot {
private _lineStartPositions: number[] = null;
private _lineStartPositions: number[] = undefined;
constructor(private text: string) {
}

View File

@ -2,7 +2,7 @@
module TypeScript.SimpleText {
class SimpleStringText implements ISimpleText {
private _lineMap: LineMap = null;
private _lineMap: LineMap = undefined;
constructor(private value: string) {
}
@ -30,7 +30,7 @@ module TypeScript.SimpleText {
// Class which wraps a host IScriptSnapshot and exposes an ISimpleText for newer compiler code.
class SimpleScriptSnapshotText implements ISimpleText {
private _lineMap: LineMap = null;
private _lineMap: LineMap = undefined;
constructor(public scriptSnapshot: IScriptSnapshot) {
}
@ -48,7 +48,7 @@ module TypeScript.SimpleText {
}
public lineMap(): LineMap {
if (this._lineMap === null) {
if (!this._lineMap) {
this._lineMap = new LineMap(() => this.scriptSnapshot.getLineStartPositions(), this.length());
}

View File

@ -79,7 +79,7 @@ module TypeScript {
}
/**
* Returns the overlap with the given span, or null if there is no overlap.
* Returns the overlap with the given span, or undefined if there is no overlap.
* @param span The span to check.
*/
public overlap(span: TextSpan): TextSpan {
@ -90,7 +90,7 @@ module TypeScript {
return TextSpan.fromBounds(overlapStart, overlapEnd);
}
return null;
return undefined;
}
/**
@ -119,7 +119,7 @@ module TypeScript {
}
/**
* Returns the intersection with the given span, or null if there is no intersection.
* Returns the intersection with the given span, or undefined if there is no intersection.
* @param span The span to check.
*/
public intersection(span: TextSpan): TextSpan {
@ -130,7 +130,7 @@ module TypeScript {
return TextSpan.fromBounds(intersectStart, intersectEnd);
}
return null;
return undefined;
}
/**