Merge pull request #8845 from Microsoft/Fix8834

Fix #8834: exclude paramters and variables from flag checks
This commit is contained in:
Mohamed Hegazy 2016-05-26 14:35:50 -07:00
commit b70d07954c
8 changed files with 91 additions and 0 deletions

View file

@ -14528,6 +14528,12 @@ namespace ts {
}
function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) {
if ((left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) ||
(left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter)) {
// Differences in optionality between parameters and variables are allowed.
return true;
}
if (hasQuestionToken(left) !== hasQuestionToken(right)) {
return false;
}

View file

@ -0,0 +1,15 @@
//// [optionalParamterAndVariableDeclaration.ts]
class C {
constructor(options?: number) {
var options = (options || 0);
}
}
//// [optionalParamterAndVariableDeclaration.js]
var C = (function () {
function C(options) {
var options = (options || 0);
}
return C;
}());

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/optionalParamterAndVariableDeclaration.ts ===
class C {
>C : Symbol(C, Decl(optionalParamterAndVariableDeclaration.ts, 0, 0))
constructor(options?: number) {
>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11))
var options = (options || 0);
>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11))
>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11))
}
}

View file

@ -0,0 +1,16 @@
=== tests/cases/compiler/optionalParamterAndVariableDeclaration.ts ===
class C {
>C : C
constructor(options?: number) {
>options : number
var options = (options || 0);
>options : number
>(options || 0) : number
>options || 0 : number
>options : number
>0 : number
}
}

View file

@ -0,0 +1,13 @@
tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts(4,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'.
==== tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts (1 errors) ====
class C {
constructor(options?: number) {
var options = (options || 0);
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'.
}
}

View file

@ -0,0 +1,16 @@
//// [optionalParamterAndVariableDeclaration2.ts]
class C {
constructor(options?: number) {
var options = (options || 0);
}
}
//// [optionalParamterAndVariableDeclaration2.js]
var C = (function () {
function C(options) {
var options = (options || 0);
}
return C;
}());

View file

@ -0,0 +1,5 @@
class C {
constructor(options?: number) {
var options = (options || 0);
}
}

View file

@ -0,0 +1,7 @@
// @strictNullChecks: true
class C {
constructor(options?: number) {
var options = (options || 0);
}
}