mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #1777 from Microsoft/emitCleanup
Cleanup emit code for comments.
This commit is contained in:
+99
-73
@@ -2427,28 +2427,20 @@ module ts {
|
||||
}
|
||||
|
||||
function emitMethod(node: MethodDeclaration) {
|
||||
if (!isObjectLiteralMethod(node)) {
|
||||
return;
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
emit(node.name);
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
write(": function ");
|
||||
}
|
||||
emitSignatureAndBody(node);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitPropertyAssignment(node: PropertyDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
emit(node.name);
|
||||
write(": ");
|
||||
emit(node.initializer);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
|
||||
emitLeadingComments(node);
|
||||
emit(node.name);
|
||||
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
|
||||
// module m {
|
||||
@@ -2465,7 +2457,6 @@ module ts {
|
||||
// Short-hand, { x }, is equivalent of normal form { x: x }
|
||||
emitExpressionIdentifier(node.name);
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
|
||||
@@ -2685,14 +2676,11 @@ module ts {
|
||||
}
|
||||
|
||||
function emitExpressionStatement(node: ExpressionStatement) {
|
||||
emitLeadingComments(node);
|
||||
emitParenthesized(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitIfStatement(node: IfStatement) {
|
||||
emitLeadingComments(node);
|
||||
var endPos = emitToken(SyntaxKind.IfKeyword, node.pos);
|
||||
write(" ");
|
||||
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
|
||||
@@ -2710,7 +2698,6 @@ module ts {
|
||||
emitEmbeddedStatement(node.elseStatement);
|
||||
}
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitDoStatement(node: DoStatement) {
|
||||
@@ -2798,11 +2785,9 @@ module ts {
|
||||
}
|
||||
|
||||
function emitReturnStatement(node: ReturnStatement) {
|
||||
emitLeadingComments(node);
|
||||
emitToken(SyntaxKind.ReturnKeyword, node.pos);
|
||||
emitOptional(" ", node.expression);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitWithStatement(node: WhileStatement) {
|
||||
@@ -3126,7 +3111,6 @@ module ts {
|
||||
}
|
||||
|
||||
function emitVariableDeclaration(node: VariableDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
if (isBindingPattern(node.name)) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
emitDestructuring(node);
|
||||
@@ -3140,11 +3124,9 @@ module ts {
|
||||
emitModuleMemberName(node);
|
||||
emitOptional(" = ", node.initializer);
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
if (isLet(node.declarationList)) {
|
||||
write("let ");
|
||||
@@ -3158,11 +3140,9 @@ module ts {
|
||||
}
|
||||
emitCommaList(node.declarationList.declarations);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitParameter(node: ParameterDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (isBindingPattern(node.name)) {
|
||||
var name = createTempVariable(node);
|
||||
@@ -3183,7 +3163,6 @@ module ts {
|
||||
emit(node.name);
|
||||
emitOptional(" = ", node.initializer);
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitDefaultValueAssignments(node: FunctionLikeDeclaration) {
|
||||
@@ -3256,11 +3235,9 @@ module ts {
|
||||
}
|
||||
|
||||
function emitAccessor(node: AccessorDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
write(node.kind === SyntaxKind.GetAccessor ? "get " : "set ");
|
||||
emit(node.name);
|
||||
emitSignatureAndBody(node);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitFunctionDeclaration(node: FunctionLikeDeclaration) {
|
||||
@@ -3330,7 +3307,10 @@ module ts {
|
||||
write(" ");
|
||||
emitStart(node.body);
|
||||
write("return ");
|
||||
emitNode(node.body);
|
||||
|
||||
// Don't emit comments on this body. We'll have already taken care of it above
|
||||
// when we called emitDetachedComments.
|
||||
emitNode(node.body, /*disableComments:*/ true);
|
||||
emitEnd(node.body);
|
||||
write(";");
|
||||
emitTempDeclarations(/*newLine*/ false);
|
||||
@@ -3347,7 +3327,7 @@ module ts {
|
||||
writeLine();
|
||||
emitLeadingComments(node.body);
|
||||
write("return ");
|
||||
emit(node.body);
|
||||
emit(node.body, /*disableComments:*/ true);
|
||||
write(";");
|
||||
emitTrailingComments(node.body);
|
||||
}
|
||||
@@ -3528,7 +3508,6 @@ module ts {
|
||||
}
|
||||
|
||||
function emitClassDeclaration(node: ClassDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
write("var ");
|
||||
emit(node.name);
|
||||
write(" = (function (");
|
||||
@@ -3578,7 +3557,6 @@ module ts {
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
|
||||
function emitConstructorOfClass() {
|
||||
var saveTempCount = tempCount;
|
||||
@@ -3657,13 +3635,17 @@ module ts {
|
||||
emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
function shouldEmitEnumDeclaration(node: EnumDeclaration) {
|
||||
var isConstEnum = isConst(node);
|
||||
return !isConstEnum || compilerOptions.preserveConstEnums;
|
||||
}
|
||||
|
||||
function emitEnumDeclaration(node: EnumDeclaration) {
|
||||
// const enums are completely erased during compilation.
|
||||
var isConstEnum = isConst(node);
|
||||
if (isConstEnum && !compilerOptions.preserveConstEnums) {
|
||||
if (!shouldEmitEnumDeclaration(node)) {
|
||||
return;
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
emitStart(node);
|
||||
write("var ");
|
||||
@@ -3680,7 +3662,7 @@ module ts {
|
||||
write(") {");
|
||||
increaseIndent();
|
||||
scopeEmitStart(node);
|
||||
emitEnumMemberDeclarations(isConstEnum);
|
||||
emitLines(node.members);
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
|
||||
@@ -3701,32 +3683,27 @@ module ts {
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitEnumMemberDeclarations(isConstEnum: boolean) {
|
||||
forEach(node.members, member => {
|
||||
writeLine();
|
||||
emitLeadingComments(member);
|
||||
emitStart(member);
|
||||
write(resolver.getLocalNameOfContainer(node));
|
||||
write("[");
|
||||
write(resolver.getLocalNameOfContainer(node));
|
||||
write("[");
|
||||
emitExpressionForPropertyName(member.name);
|
||||
write("] = ");
|
||||
if (member.initializer && !isConstEnum) {
|
||||
emit(member.initializer);
|
||||
}
|
||||
else {
|
||||
write(resolver.getEnumMemberValue(member).toString());
|
||||
}
|
||||
write("] = ");
|
||||
emitExpressionForPropertyName(member.name);
|
||||
emitEnd(member);
|
||||
write(";");
|
||||
emitTrailingComments(member);
|
||||
});
|
||||
function emitEnumMember(node: EnumMember) {
|
||||
var enumParent = <EnumDeclaration>node.parent;
|
||||
emitStart(node);
|
||||
write(resolver.getLocalNameOfContainer(enumParent));
|
||||
write("[");
|
||||
write(resolver.getLocalNameOfContainer(enumParent));
|
||||
write("[");
|
||||
emitExpressionForPropertyName(node.name);
|
||||
write("] = ");
|
||||
if (node.initializer && !isConst(enumParent)) {
|
||||
emit(node.initializer);
|
||||
}
|
||||
else {
|
||||
write(resolver.getEnumMemberValue(node).toString());
|
||||
}
|
||||
write("] = ");
|
||||
emitExpressionForPropertyName(node.name);
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
|
||||
function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration {
|
||||
@@ -3736,14 +3713,18 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitModuleDeclaration(node: ModuleDeclaration) {
|
||||
return isInstantiatedModule(node, compilerOptions.preserveConstEnums);
|
||||
}
|
||||
|
||||
function emitModuleDeclaration(node: ModuleDeclaration) {
|
||||
// Emit only if this module is non-ambient.
|
||||
var shouldEmit = isInstantiatedModule(node, compilerOptions.preserveConstEnums);
|
||||
var shouldEmit = shouldEmitModuleDeclaration(node);
|
||||
|
||||
if (!shouldEmit) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
|
||||
emitStart(node);
|
||||
write("var ");
|
||||
emit(node.name);
|
||||
@@ -3788,7 +3769,6 @@ module ts {
|
||||
emitModuleMemberName(node);
|
||||
write(" = {}));");
|
||||
emitEnd(node);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitImportDeclaration(node: ImportDeclaration) {
|
||||
@@ -3978,7 +3958,7 @@ module ts {
|
||||
emitLeadingComments(node.endOfFileToken);
|
||||
}
|
||||
|
||||
function emitNode(node: Node): void {
|
||||
function emitNode(node: Node, disableComments?:boolean): void {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@@ -3986,6 +3966,46 @@ module ts {
|
||||
if (node.flags & NodeFlags.Ambient) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
var emitComments = !disableComments && shouldEmitLeadingAndTrailingComments(node);
|
||||
if (emitComments) {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
||||
emitJavaScriptWorker(node);
|
||||
|
||||
if (emitComments) {
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitLeadingAndTrailingComments(node: Node) {
|
||||
switch (node.kind) {
|
||||
// All of these entities are emitted in a specialized fashion. As such, we allow
|
||||
// the specilized methods for each to handle the comments on the nodes.
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return false;
|
||||
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
// Only emit the leading/trailing comments for a module if we're actually
|
||||
// emitting the module as well.
|
||||
return shouldEmitModuleDeclaration(<ModuleDeclaration>node);
|
||||
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
// Only emit the leading/trailing comments for an enum if we're actually
|
||||
// emitting the module as well.
|
||||
return shouldEmitEnumDeclaration(<EnumDeclaration>node);
|
||||
}
|
||||
|
||||
// Emit comments for everything else.
|
||||
return true;
|
||||
}
|
||||
|
||||
function emitJavaScriptWorker(node: Node) {
|
||||
// Check if the node can be emitted regardless of the ScriptTarget
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
@@ -4123,6 +4143,8 @@ module ts {
|
||||
return emitInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return emitEnumDeclaration(<EnumDeclaration>node);
|
||||
case SyntaxKind.EnumMember:
|
||||
return emitEnumMember(<EnumMember>node);
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return emitModuleDeclaration(<ModuleDeclaration>node);
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
@@ -4152,17 +4174,19 @@ module ts {
|
||||
|
||||
function getLeadingCommentsToEmit(node: Node) {
|
||||
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {
|
||||
var leadingComments: CommentRange[];
|
||||
if (hasDetachedComments(node.pos)) {
|
||||
// get comments without detached comments
|
||||
leadingComments = getLeadingCommentsWithoutDetachedComments();
|
||||
if (node.parent) {
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {
|
||||
var leadingComments: CommentRange[];
|
||||
if (hasDetachedComments(node.pos)) {
|
||||
// get comments without detached comments
|
||||
leadingComments = getLeadingCommentsWithoutDetachedComments();
|
||||
}
|
||||
else {
|
||||
// get the leading comments from the node
|
||||
leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile);
|
||||
}
|
||||
return leadingComments;
|
||||
}
|
||||
else {
|
||||
// get the leading comments from the node
|
||||
leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile);
|
||||
}
|
||||
return leadingComments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4175,10 +4199,12 @@ module ts {
|
||||
|
||||
function emitTrailingDeclarationComments(node: Node) {
|
||||
// Emit the trailing comments only if the parent's end doesn't match
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
|
||||
var trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end);
|
||||
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
|
||||
emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment);
|
||||
if (node.parent) {
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
|
||||
var trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end);
|
||||
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
|
||||
emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ var __extends = this.__extends || function (d, b) {
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
// Arrow function used in with statement
|
||||
with (window) {
|
||||
var p = function () { return this; };
|
||||
}
|
||||
@@ -142,6 +143,7 @@ var M;
|
||||
// Repeat above for module members that are functions? (necessary to redo all of them?)
|
||||
var M2;
|
||||
(function (M2) {
|
||||
// Arrow function used in with statement
|
||||
with (window) {
|
||||
var p = function () { return this; };
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ var e2;
|
||||
(function (e2) {
|
||||
e2[e2["One"] = 0] = "One";
|
||||
})(e2 || (e2 = {}));
|
||||
;
|
||||
; // error
|
||||
var e2 = (function () {
|
||||
function e2() {
|
||||
}
|
||||
|
||||
@@ -47,5 +47,5 @@ var i3;
|
||||
(function (i3) {
|
||||
i3[i3["One"] = 0] = "One";
|
||||
})(i3 || (i3 = {}));
|
||||
;
|
||||
; // error
|
||||
//import i4 = require(''); // error
|
||||
|
||||
@@ -124,21 +124,21 @@ var m1d;
|
||||
var m1d = 1; // error
|
||||
function m2() {
|
||||
}
|
||||
;
|
||||
; // ok since the module is not instantiated
|
||||
var m2a;
|
||||
(function (m2a) {
|
||||
var y = 2;
|
||||
})(m2a || (m2a = {}));
|
||||
function m2a() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
var m2b;
|
||||
(function (m2b) {
|
||||
m2b.y = 2;
|
||||
})(m2b || (m2b = {}));
|
||||
function m2b() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
// should be errors to have function first
|
||||
function m2c() {
|
||||
}
|
||||
|
||||
@@ -31,21 +31,21 @@ module m2g { export class C { foo() { } } }
|
||||
//// [augmentedTypesModules2.js]
|
||||
function m2() {
|
||||
}
|
||||
;
|
||||
; // ok since the module is not instantiated
|
||||
var m2a;
|
||||
(function (m2a) {
|
||||
var y = 2;
|
||||
})(m2a || (m2a = {}));
|
||||
function m2a() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
var m2b;
|
||||
(function (m2b) {
|
||||
m2b.y = 2;
|
||||
})(m2b || (m2b = {}));
|
||||
function m2b() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
function m2c() {
|
||||
}
|
||||
;
|
||||
@@ -59,7 +59,7 @@ var m2cc;
|
||||
})(m2cc || (m2cc = {}));
|
||||
function m2cc() {
|
||||
}
|
||||
;
|
||||
; // error to have module first
|
||||
function m2f() {
|
||||
}
|
||||
;
|
||||
|
||||
@@ -22,6 +22,7 @@ function foo1<T1, T2>()
|
||||
|
||||
|
||||
//// [commaOperatorOtherValidOperation.js]
|
||||
//Comma operator in for loop
|
||||
for (var i = 0, j = 10; i < j; i++, j--) {
|
||||
}
|
||||
//Comma operator in fuction arguments and return
|
||||
|
||||
@@ -8,4 +8,8 @@ var Person = makeClass(
|
||||
);
|
||||
|
||||
//// [commentsOnObjectLiteral1.js]
|
||||
var Person = makeClass({});
|
||||
var Person = makeClass(
|
||||
/**
|
||||
@scope Person
|
||||
*/
|
||||
{});
|
||||
|
||||
@@ -66,7 +66,9 @@ var n = 30;
|
||||
/** var deckaration with comment on type as well*/
|
||||
var y = 20;
|
||||
/// var deckaration with comment on type as well
|
||||
var yy = 20;
|
||||
var yy =
|
||||
/// value comment
|
||||
20;
|
||||
/** comment2 */
|
||||
var z = function (x, y) { return x + y; };
|
||||
var z2;
|
||||
|
||||
@@ -189,6 +189,7 @@ while (false) {
|
||||
label2: label3: label4: const c = 0;
|
||||
n = c;
|
||||
}
|
||||
// Try/catch/finally
|
||||
try {
|
||||
const c = 0;
|
||||
n = c;
|
||||
@@ -201,12 +202,14 @@ finally {
|
||||
const c = 0;
|
||||
n = c;
|
||||
}
|
||||
// Switch
|
||||
switch (0) {
|
||||
case 0:
|
||||
const c = 0;
|
||||
n = c;
|
||||
break;
|
||||
}
|
||||
// blocks
|
||||
{
|
||||
const c = 0;
|
||||
n = c;
|
||||
|
||||
@@ -20,6 +20,7 @@ for (const c = 0; c < 10; n = c ) {
|
||||
const c = "string";
|
||||
var n;
|
||||
var b;
|
||||
// for scope
|
||||
for (const c = 0; c < 10; n = c) {
|
||||
// for block
|
||||
const c = false;
|
||||
|
||||
@@ -153,6 +153,7 @@ if (true) {
|
||||
while (false) {
|
||||
label2: label3: label4: const c9 = 0;
|
||||
}
|
||||
// Try/catch/finally
|
||||
try {
|
||||
const c10 = 0;
|
||||
}
|
||||
@@ -162,6 +163,7 @@ catch (e) {
|
||||
finally {
|
||||
const c12 = 0;
|
||||
}
|
||||
// Switch
|
||||
switch (0) {
|
||||
case 0:
|
||||
const c13 = 0;
|
||||
@@ -170,6 +172,7 @@ switch (0) {
|
||||
const c14 = 0;
|
||||
break;
|
||||
}
|
||||
// blocks
|
||||
{
|
||||
const c15 = 0;
|
||||
{
|
||||
|
||||
@@ -204,19 +204,20 @@ constructorTestObject.arg\u0031 = 1;
|
||||
constructorTestObject.arg2 = 'string';
|
||||
constructorTestObject.arg\u0033 = true;
|
||||
constructorTestObject.arg4 = 2;
|
||||
// Lables
|
||||
l\u0061bel1: while (false) {
|
||||
while (false)
|
||||
continue label1;
|
||||
continue label1; // it will go to next iteration of outer loop
|
||||
}
|
||||
label2: while (false) {
|
||||
while (false)
|
||||
continue l\u0061bel2;
|
||||
continue l\u0061bel2; // it will go to next iteration of outer loop
|
||||
}
|
||||
label3: while (false) {
|
||||
while (false)
|
||||
continue label3;
|
||||
continue label3; // it will go to next iteration of outer loop
|
||||
}
|
||||
l\u0061bel4: while (false) {
|
||||
while (false)
|
||||
continue l\u0061bel4;
|
||||
continue l\u0061bel4; // it will go to next iteration of outer loop
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ var M;
|
||||
}
|
||||
M.F2 = F2;
|
||||
})(M || (M = {}));
|
||||
// all of these are errors
|
||||
for (var a;;) {
|
||||
}
|
||||
for (var a = 1;;) {
|
||||
|
||||
@@ -15,7 +15,8 @@ var s3 = s2.func(num => num.toString())
|
||||
|
||||
|
||||
//// [genericChainedCalls.js]
|
||||
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }).func(function (num) { return num.toString(); });
|
||||
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }) // error, number doesn't have a length
|
||||
.func(function (num) { return num.toString(); });
|
||||
var s1 = v1.func(function (num) { return num.toString(); });
|
||||
var s2 = s1.func(function (str) { return str.length; }); // should also error
|
||||
var s3 = s2.func(function (num) { return num.toString(); });
|
||||
|
||||
@@ -18,22 +18,22 @@ function foo(x) {
|
||||
;
|
||||
function bar(x, y) {
|
||||
}
|
||||
;
|
||||
; // error at "y"; no error at "x"
|
||||
function func2(a, b, c) {
|
||||
}
|
||||
;
|
||||
; // error at "a,b,c"
|
||||
function func3() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
}
|
||||
;
|
||||
; // error at "args"
|
||||
function func4(z, w) {
|
||||
if (z === void 0) { z = null; }
|
||||
if (w === void 0) { w = undefined; }
|
||||
}
|
||||
;
|
||||
; // error at "z,w"
|
||||
// these shouldn't be errors
|
||||
function noError1(x, y) {
|
||||
if (x === void 0) { x = 3; }
|
||||
|
||||
@@ -16,7 +16,7 @@ var x1: any; var y1 = new x1;
|
||||
var x; // error at "x"
|
||||
function func(k) {
|
||||
}
|
||||
;
|
||||
; //error at "k"
|
||||
func(x);
|
||||
// this shouldn't be an error
|
||||
var bar = 3;
|
||||
|
||||
@@ -15,6 +15,7 @@ class C {
|
||||
|
||||
|
||||
//// [implicitAnyInCatch.js]
|
||||
// this should not be an error
|
||||
try {
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -205,6 +205,7 @@ for (let l = 0; n = l; l++) {
|
||||
}
|
||||
for (let l in {}) {
|
||||
}
|
||||
// Try/catch/finally
|
||||
try {
|
||||
let l = 0;
|
||||
n = l;
|
||||
@@ -217,12 +218,14 @@ finally {
|
||||
let l = 0;
|
||||
n = l;
|
||||
}
|
||||
// Switch
|
||||
switch (0) {
|
||||
case 0:
|
||||
let l = 0;
|
||||
n = l;
|
||||
break;
|
||||
}
|
||||
// blocks
|
||||
{
|
||||
let l = 0;
|
||||
n = l;
|
||||
|
||||
@@ -173,6 +173,7 @@ if (true) {
|
||||
while (false) {
|
||||
label2: label3: label4: let l9 = 0;
|
||||
}
|
||||
// Try/catch/finally
|
||||
try {
|
||||
let l10 = 0;
|
||||
}
|
||||
@@ -182,6 +183,7 @@ catch (e) {
|
||||
finally {
|
||||
let l12 = 0;
|
||||
}
|
||||
// Switch
|
||||
switch (0) {
|
||||
case 0:
|
||||
let l13 = 0;
|
||||
@@ -190,6 +192,7 @@ switch (0) {
|
||||
let l14 = 0;
|
||||
break;
|
||||
}
|
||||
// blocks
|
||||
{
|
||||
let l15 = 0;
|
||||
{
|
||||
@@ -247,6 +250,7 @@ var o = {
|
||||
let l29 = 0;
|
||||
}
|
||||
};
|
||||
// labels
|
||||
label: let l30 = 0;
|
||||
{
|
||||
label2: let l31 = 0;
|
||||
|
||||
@@ -16,5 +16,7 @@ var r2: I1<number> = v1.func(num => num.toString()) // Correctly returns an I1<s
|
||||
|
||||
//// [overEagerReturnTypeSpecialization.js]
|
||||
//Note: Below simpler repro
|
||||
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }); // should error
|
||||
var r2 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }); // should be ok
|
||||
var r1 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1<string>
|
||||
.func(function (str) { return str.length; }); // should error
|
||||
var r2 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1<string>
|
||||
.func(function (str) { return str.length; }); // should be ok
|
||||
|
||||
@@ -19,6 +19,13 @@ do {
|
||||
//// [parserSbp_7.9_A9_T3.js]
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/**
|
||||
* Check Do-While Statement for automatic semicolon insertion
|
||||
*
|
||||
* @path bestPractice/Sbp_7.9_A9_T3.js
|
||||
* @description Execute do { \n ; \n }while(false) true
|
||||
*/
|
||||
//CHECK#1
|
||||
do {
|
||||
;
|
||||
} while (false);
|
||||
|
||||
@@ -19,7 +19,7 @@ var Chain = (function () {
|
||||
Chain.prototype.then = function (cb) {
|
||||
var result = cb(this.value);
|
||||
// should get a fresh type parameter which each then call
|
||||
var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // No error
|
||||
var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*string*/.then(function (x) { return x.length; }); // No error
|
||||
return new Chain(result);
|
||||
};
|
||||
return Chain;
|
||||
|
||||
@@ -19,7 +19,7 @@ var Chain2 = (function () {
|
||||
Chain2.prototype.then = function (cb) {
|
||||
var result = cb(this.value);
|
||||
// should get a fresh type parameter which each then call
|
||||
var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function
|
||||
var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*Function*/.then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function
|
||||
return new Chain2(result);
|
||||
};
|
||||
return Chain2;
|
||||
|
||||
@@ -23,10 +23,10 @@ var f = (x: string) => f(x);
|
||||
// number unless otherwise specified
|
||||
var n1 = n1++;
|
||||
var n2 = n2 + n2;
|
||||
var n3 = n3 + n3;
|
||||
var n3 /* any */ = n3 + n3;
|
||||
// string unless otherwise specified
|
||||
var s1 = s1 + '';
|
||||
var s2 = s2 + s2;
|
||||
var s2 /* any */ = s2 + s2;
|
||||
var s3 = s3 + s3;
|
||||
var s4 = '' + s4;
|
||||
// boolean unless otherwise specified
|
||||
|
||||
@@ -19,9 +19,9 @@ catch (ex1) {
|
||||
try {
|
||||
}
|
||||
catch (ex1) {
|
||||
}
|
||||
} // should not error
|
||||
try {
|
||||
}
|
||||
catch (ex1) {
|
||||
}
|
||||
} // should not error
|
||||
var x = ex1; // should error
|
||||
|
||||
@@ -57,9 +57,9 @@ var Foo;
|
||||
var greeter = new Greeter("Hello, world!");
|
||||
var str = greeter.greet();
|
||||
function foo2(greeting) {
|
||||
var restGreetings = [];
|
||||
var restGreetings /* more greeting */ = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
restGreetings[_i - 1] = arguments[_i];
|
||||
restGreetings /* more greeting */[_i - 1] = arguments[_i];
|
||||
}
|
||||
var greeters = []; /* inline block comment */
|
||||
greeters[0] = new Greeter(greeting);
|
||||
@@ -69,6 +69,7 @@ var Foo;
|
||||
return greeters;
|
||||
}
|
||||
var b = foo2("Hello", "World", "!");
|
||||
// This is simple signle line comment
|
||||
for (var j = 0; j < b.length; j++) {
|
||||
b[j].greet();
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
//// [sourceMapValidationClasses.js.map]
|
||||
{"version":3,"file":"sourceMapValidationClasses.js","sourceRoot":"","sources":["sourceMapValidationClasses.ts"],"names":["Foo","Foo.Bar","Foo.Bar.Greeter","Foo.Bar.Greeter.constructor","Foo.Bar.Greeter.greet","Foo.Bar.foo","Foo.Bar.foo2"],"mappings":"AAAA,IAAO,GAAG,CAmCT;AAnCD,WAAO,GAAG;IAACA,IAAAA,GAAGA,CAmCbA;IAnCUA,WAAAA,GAAGA,EAACA,CAACA;QACZC,YAAYA,CAACA;QAEbA,IAAMA,OAAOA;YACTC,SADEA,OAAOA,CACUA,QAAgBA;gBAAhBC,aAAQA,GAARA,QAAQA,CAAQA;YACnCA,CAACA;YAEDD,uBAAKA,GAALA;gBACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;YAC5CA,CAACA;YACLF,cAACA;QAADA,CAACA,AAPDD,IAOCA;QAGDA,SAASA,GAAGA,CAACA,QAAgBA;YACzBI,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;QACjCA,CAACA;QAEDJ,IAAIA,OAAOA,GAAGA,IAAIA,OAAOA,CAACA,eAAeA,CAACA,CAACA;QAC3CA,IAAIA,GAAGA,GAAGA,OAAOA,CAACA,KAAKA,EAAEA,CAACA;QAE1BA,SAASA,IAAIA,CAACA,QAAgBA;YAAEK,uBAA8CA;iBAA9CA,WAA8CA,CAA9CA,sBAA8CA,CAA9CA,IAA8CA;gBAA9CA,sCAA8CA;;YAC1EA,IAAIA,QAAQA,GAAcA,EAAEA,EAAEA,0BAA0BA,AAA3BA;YAC7BA,QAAQA,CAACA,CAACA,CAACA,GAAGA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;YACpCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,aAAaA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;gBAC5CA,QAAQA,CAACA,IAAIA,CAACA,IAAIA,OAAOA,CAACA,aAAaA,CAACA,CAACA,CAACA,CAACA,CAACA,CAACA;YACjDA,CAACA;YAEDA,MAAMA,CAACA,QAAQA,CAACA;QACpBA,CAACA;QAEDL,IAAIA,CAACA,GAAGA,IAAIA,CAACA,OAAOA,EAAEA,OAAOA,EAAEA,GAAGA,CAACA,CAACA;QAEpCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,CAACA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;YAChCA,CAACA,CAACA,CAACA,CAACA,CAACA,KAAKA,EAAEA,CAACA;QACjBA,CAACA;IACLA,CAACA,EAnCUD,GAAGA,GAAHA,OAAGA,KAAHA,OAAGA,QAmCbA;AAADA,CAACA,EAnCM,GAAG,KAAH,GAAG,QAmCT"}
|
||||
{"version":3,"file":"sourceMapValidationClasses.js","sourceRoot":"","sources":["sourceMapValidationClasses.ts"],"names":["Foo","Foo.Bar","Foo.Bar.Greeter","Foo.Bar.Greeter.constructor","Foo.Bar.Greeter.greet","Foo.Bar.foo","Foo.Bar.foo2"],"mappings":"AAAA,IAAO,GAAG,CAmCT;AAnCD,WAAO,GAAG;IAACA,IAAAA,GAAGA,CAmCbA;IAnCUA,WAAAA,GAAGA,EAACA,CAACA;QACZC,YAAYA,CAACA;QAEbA,IAAMA,OAAOA;YACTC,SADEA,OAAOA,CACUA,QAAgBA;gBAAhBC,aAAQA,GAARA,QAAQA,CAAQA;YACnCA,CAACA;YAEDD,uBAAKA,GAALA;gBACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;YAC5CA,CAACA;YACLF,cAACA;QAADA,CAACA,AAPDD,IAOCA;QAGDA,SAASA,GAAGA,CAACA,QAAgBA;YACzBI,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;QACjCA,CAACA;QAEDJ,IAAIA,OAAOA,GAAGA,IAAIA,OAAOA,CAACA,eAAeA,CAACA,CAACA;QAC3CA,IAAIA,GAAGA,GAAGA,OAAOA,CAACA,KAAKA,EAAEA,CAACA;QAE1BA,SAASA,IAAIA,CAACA,QAAgBA;YAAEK,kBAAiBA,mBAAmBA,MAAUA;iBAA9CA,WAA8CA,CAA9CA,sBAA8CA,CAA9CA,IAA8CA;gBAA9CA,cAAiBA,mBAAmBA,yBAAUA;;YAC1EA,IAAIA,QAAQA,GAAcA,EAAEA,EAAEA,0BAA0BA,AAA3BA;YAC7BA,QAAQA,CAACA,CAACA,CAACA,GAAGA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;YACpCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,aAAaA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;gBAC5CA,QAAQA,CAACA,IAAIA,CAACA,IAAIA,OAAOA,CAACA,aAAaA,CAACA,CAACA,CAACA,CAACA,CAACA,CAACA;YACjDA,CAACA;YAEDA,MAAMA,CAACA,QAAQA,CAACA;QACpBA,CAACA;QAEDL,IAAIA,CAACA,GAAGA,IAAIA,CAACA,OAAOA,EAAEA,OAAOA,EAAEA,GAAGA,CAACA,CAACA;QAEpCA,AADAA,qCAAqCA;QACrCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,CAACA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;YAChCA,CAACA,CAACA,CAACA,CAACA,CAACA,KAAKA,EAAEA,CAACA;QACjBA,CAACA;IACLA,CAACA,EAnCUD,GAAGA,GAAHA,OAAGA,KAAHA,OAAGA,QAmCbA;AAADA,CAACA,EAnCM,GAAG,KAAH,GAAG,QAmCT"}
|
||||
@@ -433,7 +433,7 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
3 > ^^^^
|
||||
4 > ^
|
||||
5 > ^^^^^^^^
|
||||
6 > ^^^^^^->
|
||||
6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >
|
||||
>
|
||||
>
|
||||
@@ -447,14 +447,20 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
4 >Emitted(20, 23) Source(21, 19) + SourceIndex(0) name (Foo.Bar)
|
||||
5 >Emitted(20, 31) Source(21, 35) + SourceIndex(0) name (Foo.Bar)
|
||||
---
|
||||
>>> var restGreetings = [];
|
||||
>>> var restGreetings /* more greeting */ = [];
|
||||
1->^^^^^^^^^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
2 > ^^^^^^^^^^^^^^^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^
|
||||
4 > ^^^^^^
|
||||
5 > ^^^^^->
|
||||
1->,
|
||||
2 > ...restGreetings /* more greeting */: string[]
|
||||
2 > ...restGreetings
|
||||
3 > /* more greeting */
|
||||
4 > : string[]
|
||||
1->Emitted(21, 13) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
2 >Emitted(21, 36) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
2 >Emitted(21, 31) Source(21, 54) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
3 >Emitted(21, 50) Source(21, 73) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
4 >Emitted(21, 56) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
---
|
||||
>>> for (var _i = 1; _i < arguments.length; _i++) {
|
||||
1->^^^^^^^^^^^^^^^^^
|
||||
@@ -463,6 +469,7 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
4 > ^^^^^^^^^^^^^^^^^^^^^^
|
||||
5 > ^
|
||||
6 > ^^^^
|
||||
7 > ^^^^^^^^^^^^^^^^^^^->
|
||||
1->
|
||||
2 > ...restGreetings /* more greeting */: string[]
|
||||
3 >
|
||||
@@ -476,13 +483,19 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
5 >Emitted(22, 53) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
6 >Emitted(22, 57) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
---
|
||||
>>> restGreetings[_i - 1] = arguments[_i];
|
||||
1 >^^^^^^^^^^^^^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
1 >
|
||||
2 > ...restGreetings /* more greeting */: string[]
|
||||
1 >Emitted(23, 17) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
2 >Emitted(23, 55) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
>>> restGreetings /* more greeting */[_i - 1] = arguments[_i];
|
||||
1->^^^^^^^^^^^^^^^^
|
||||
2 > ^^^^^^^^^^^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^
|
||||
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
1->
|
||||
2 > ...restGreetings
|
||||
3 > /* more greeting */
|
||||
4 > : string[]
|
||||
1->Emitted(23, 17) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
2 >Emitted(23, 31) Source(21, 54) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
3 >Emitted(23, 50) Source(21, 73) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
4 >Emitted(23, 75) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2)
|
||||
---
|
||||
>>> }
|
||||
>>> var greeters = []; /* inline block comment */
|
||||
@@ -717,7 +730,7 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
11> ^^^
|
||||
12> ^
|
||||
13> ^
|
||||
14> ^->
|
||||
14> ^^->
|
||||
1->
|
||||
>
|
||||
>
|
||||
@@ -747,8 +760,21 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
12>Emitted(32, 44) Source(31, 40) + SourceIndex(0) name (Foo.Bar)
|
||||
13>Emitted(32, 45) Source(31, 41) + SourceIndex(0) name (Foo.Bar)
|
||||
---
|
||||
>>> for (var j = 0; j < b.length; j++) {
|
||||
>>> // This is simple signle line comment
|
||||
1->^^^^^^^^
|
||||
2 >
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
1->
|
||||
> // This is simple signle line comment
|
||||
>
|
||||
2 >
|
||||
3 > // This is simple signle line comment
|
||||
1->Emitted(33, 9) Source(33, 5) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(33, 9) Source(32, 5) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(33, 46) Source(32, 42) + SourceIndex(0) name (Foo.Bar)
|
||||
---
|
||||
>>> for (var j = 0; j < b.length; j++) {
|
||||
1 >^^^^^^^^
|
||||
2 > ^^^
|
||||
3 > ^
|
||||
4 > ^
|
||||
@@ -768,8 +794,7 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
18> ^^
|
||||
19> ^^
|
||||
20> ^
|
||||
1->
|
||||
> // This is simple signle line comment
|
||||
1 >
|
||||
>
|
||||
2 > for
|
||||
3 >
|
||||
@@ -790,26 +815,26 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
18> ++
|
||||
19> )
|
||||
20> {
|
||||
1->Emitted(33, 9) Source(33, 5) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(33, 12) Source(33, 8) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(33, 13) Source(33, 9) + SourceIndex(0) name (Foo.Bar)
|
||||
4 >Emitted(33, 14) Source(33, 10) + SourceIndex(0) name (Foo.Bar)
|
||||
5 >Emitted(33, 17) Source(33, 13) + SourceIndex(0) name (Foo.Bar)
|
||||
6 >Emitted(33, 18) Source(33, 14) + SourceIndex(0) name (Foo.Bar)
|
||||
7 >Emitted(33, 19) Source(33, 15) + SourceIndex(0) name (Foo.Bar)
|
||||
8 >Emitted(33, 22) Source(33, 18) + SourceIndex(0) name (Foo.Bar)
|
||||
9 >Emitted(33, 23) Source(33, 19) + SourceIndex(0) name (Foo.Bar)
|
||||
10>Emitted(33, 25) Source(33, 21) + SourceIndex(0) name (Foo.Bar)
|
||||
11>Emitted(33, 26) Source(33, 22) + SourceIndex(0) name (Foo.Bar)
|
||||
12>Emitted(33, 29) Source(33, 25) + SourceIndex(0) name (Foo.Bar)
|
||||
13>Emitted(33, 30) Source(33, 26) + SourceIndex(0) name (Foo.Bar)
|
||||
14>Emitted(33, 31) Source(33, 27) + SourceIndex(0) name (Foo.Bar)
|
||||
15>Emitted(33, 37) Source(33, 33) + SourceIndex(0) name (Foo.Bar)
|
||||
16>Emitted(33, 39) Source(33, 35) + SourceIndex(0) name (Foo.Bar)
|
||||
17>Emitted(33, 40) Source(33, 36) + SourceIndex(0) name (Foo.Bar)
|
||||
18>Emitted(33, 42) Source(33, 38) + SourceIndex(0) name (Foo.Bar)
|
||||
19>Emitted(33, 44) Source(33, 40) + SourceIndex(0) name (Foo.Bar)
|
||||
20>Emitted(33, 45) Source(33, 41) + SourceIndex(0) name (Foo.Bar)
|
||||
1 >Emitted(34, 9) Source(33, 5) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(34, 12) Source(33, 8) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(34, 13) Source(33, 9) + SourceIndex(0) name (Foo.Bar)
|
||||
4 >Emitted(34, 14) Source(33, 10) + SourceIndex(0) name (Foo.Bar)
|
||||
5 >Emitted(34, 17) Source(33, 13) + SourceIndex(0) name (Foo.Bar)
|
||||
6 >Emitted(34, 18) Source(33, 14) + SourceIndex(0) name (Foo.Bar)
|
||||
7 >Emitted(34, 19) Source(33, 15) + SourceIndex(0) name (Foo.Bar)
|
||||
8 >Emitted(34, 22) Source(33, 18) + SourceIndex(0) name (Foo.Bar)
|
||||
9 >Emitted(34, 23) Source(33, 19) + SourceIndex(0) name (Foo.Bar)
|
||||
10>Emitted(34, 25) Source(33, 21) + SourceIndex(0) name (Foo.Bar)
|
||||
11>Emitted(34, 26) Source(33, 22) + SourceIndex(0) name (Foo.Bar)
|
||||
12>Emitted(34, 29) Source(33, 25) + SourceIndex(0) name (Foo.Bar)
|
||||
13>Emitted(34, 30) Source(33, 26) + SourceIndex(0) name (Foo.Bar)
|
||||
14>Emitted(34, 31) Source(33, 27) + SourceIndex(0) name (Foo.Bar)
|
||||
15>Emitted(34, 37) Source(33, 33) + SourceIndex(0) name (Foo.Bar)
|
||||
16>Emitted(34, 39) Source(33, 35) + SourceIndex(0) name (Foo.Bar)
|
||||
17>Emitted(34, 40) Source(33, 36) + SourceIndex(0) name (Foo.Bar)
|
||||
18>Emitted(34, 42) Source(33, 38) + SourceIndex(0) name (Foo.Bar)
|
||||
19>Emitted(34, 44) Source(33, 40) + SourceIndex(0) name (Foo.Bar)
|
||||
20>Emitted(34, 45) Source(33, 41) + SourceIndex(0) name (Foo.Bar)
|
||||
---
|
||||
>>> b[j].greet();
|
||||
1 >^^^^^^^^^^^^
|
||||
@@ -831,15 +856,15 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
7 > greet
|
||||
8 > ()
|
||||
9 > ;
|
||||
1 >Emitted(34, 13) Source(34, 9) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(34, 14) Source(34, 10) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(34, 15) Source(34, 11) + SourceIndex(0) name (Foo.Bar)
|
||||
4 >Emitted(34, 16) Source(34, 12) + SourceIndex(0) name (Foo.Bar)
|
||||
5 >Emitted(34, 17) Source(34, 13) + SourceIndex(0) name (Foo.Bar)
|
||||
6 >Emitted(34, 18) Source(34, 14) + SourceIndex(0) name (Foo.Bar)
|
||||
7 >Emitted(34, 23) Source(34, 19) + SourceIndex(0) name (Foo.Bar)
|
||||
8 >Emitted(34, 25) Source(34, 21) + SourceIndex(0) name (Foo.Bar)
|
||||
9 >Emitted(34, 26) Source(34, 22) + SourceIndex(0) name (Foo.Bar)
|
||||
1 >Emitted(35, 13) Source(34, 9) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(35, 14) Source(34, 10) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(35, 15) Source(34, 11) + SourceIndex(0) name (Foo.Bar)
|
||||
4 >Emitted(35, 16) Source(34, 12) + SourceIndex(0) name (Foo.Bar)
|
||||
5 >Emitted(35, 17) Source(34, 13) + SourceIndex(0) name (Foo.Bar)
|
||||
6 >Emitted(35, 18) Source(34, 14) + SourceIndex(0) name (Foo.Bar)
|
||||
7 >Emitted(35, 23) Source(34, 19) + SourceIndex(0) name (Foo.Bar)
|
||||
8 >Emitted(35, 25) Source(34, 21) + SourceIndex(0) name (Foo.Bar)
|
||||
9 >Emitted(35, 26) Source(34, 22) + SourceIndex(0) name (Foo.Bar)
|
||||
---
|
||||
>>> }
|
||||
1 >^^^^^^^^
|
||||
@@ -848,8 +873,8 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
1 >
|
||||
>
|
||||
2 > }
|
||||
1 >Emitted(35, 9) Source(35, 5) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(35, 10) Source(35, 6) + SourceIndex(0) name (Foo.Bar)
|
||||
1 >Emitted(36, 9) Source(35, 5) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(36, 10) Source(35, 6) + SourceIndex(0) name (Foo.Bar)
|
||||
---
|
||||
>>> })(Bar = Foo.Bar || (Foo.Bar = {}));
|
||||
1->^^^^
|
||||
@@ -906,15 +931,15 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
> b[j].greet();
|
||||
> }
|
||||
> }
|
||||
1->Emitted(36, 5) Source(36, 1) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(36, 6) Source(36, 2) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(36, 8) Source(1, 12) + SourceIndex(0) name (Foo)
|
||||
4 >Emitted(36, 11) Source(1, 15) + SourceIndex(0) name (Foo)
|
||||
5 >Emitted(36, 14) Source(1, 12) + SourceIndex(0) name (Foo)
|
||||
6 >Emitted(36, 21) Source(1, 15) + SourceIndex(0) name (Foo)
|
||||
7 >Emitted(36, 26) Source(1, 12) + SourceIndex(0) name (Foo)
|
||||
8 >Emitted(36, 33) Source(1, 15) + SourceIndex(0) name (Foo)
|
||||
9 >Emitted(36, 41) Source(36, 2) + SourceIndex(0) name (Foo)
|
||||
1->Emitted(37, 5) Source(36, 1) + SourceIndex(0) name (Foo.Bar)
|
||||
2 >Emitted(37, 6) Source(36, 2) + SourceIndex(0) name (Foo.Bar)
|
||||
3 >Emitted(37, 8) Source(1, 12) + SourceIndex(0) name (Foo)
|
||||
4 >Emitted(37, 11) Source(1, 15) + SourceIndex(0) name (Foo)
|
||||
5 >Emitted(37, 14) Source(1, 12) + SourceIndex(0) name (Foo)
|
||||
6 >Emitted(37, 21) Source(1, 15) + SourceIndex(0) name (Foo)
|
||||
7 >Emitted(37, 26) Source(1, 12) + SourceIndex(0) name (Foo)
|
||||
8 >Emitted(37, 33) Source(1, 15) + SourceIndex(0) name (Foo)
|
||||
9 >Emitted(37, 41) Source(36, 2) + SourceIndex(0) name (Foo)
|
||||
---
|
||||
>>>})(Foo || (Foo = {}));
|
||||
1 >
|
||||
@@ -967,12 +992,12 @@ sourceFile:sourceMapValidationClasses.ts
|
||||
> b[j].greet();
|
||||
> }
|
||||
> }
|
||||
1 >Emitted(37, 1) Source(36, 1) + SourceIndex(0) name (Foo)
|
||||
2 >Emitted(37, 2) Source(36, 2) + SourceIndex(0) name (Foo)
|
||||
3 >Emitted(37, 4) Source(1, 8) + SourceIndex(0)
|
||||
4 >Emitted(37, 7) Source(1, 11) + SourceIndex(0)
|
||||
5 >Emitted(37, 12) Source(1, 8) + SourceIndex(0)
|
||||
6 >Emitted(37, 15) Source(1, 11) + SourceIndex(0)
|
||||
7 >Emitted(37, 23) Source(36, 2) + SourceIndex(0)
|
||||
1 >Emitted(38, 1) Source(36, 1) + SourceIndex(0) name (Foo)
|
||||
2 >Emitted(38, 2) Source(36, 2) + SourceIndex(0) name (Foo)
|
||||
3 >Emitted(38, 4) Source(1, 8) + SourceIndex(0)
|
||||
4 >Emitted(38, 7) Source(1, 11) + SourceIndex(0)
|
||||
5 >Emitted(38, 12) Source(1, 8) + SourceIndex(0)
|
||||
6 >Emitted(38, 15) Source(1, 11) + SourceIndex(0)
|
||||
7 >Emitted(38, 23) Source(36, 2) + SourceIndex(0)
|
||||
---
|
||||
>>>//# sourceMappingURL=sourceMapValidationClasses.js.map
|
||||
@@ -1,2 +1,2 @@
|
||||
//// [sourceMapValidationEnums.js.map]
|
||||
{"version":3,"file":"sourceMapValidationEnums.js","sourceRoot":"","sources":["sourceMapValidationEnums.ts"],"names":["e","e2","e3"],"mappings":"AAAA,IAAK,CAIJ;AAJD,WAAK,CAAC;IACFA,mBAACA;IACDA,mBAACA;IACDA,mBAACA;AACLA,CAACA,EAJI,CAAC,KAAD,CAAC,QAIL;AACD,IAAK,EAKJ;AALD,WAAK,EAAE;IACHC,aAAIA,EAAEA,OAAAA;IACNA,aAAIA,EAAEA,OAAAA;IACNA,sBAACA;IACDA,wBAAEA;AACNA,CAACA,EALI,EAAE,KAAF,EAAE,QAKN;AACD,IAAK,EACJ;AADD,WAAK,EAAE;AACPC,CAACA,EADI,EAAE,KAAF,EAAE,QACN"}
|
||||
{"version":3,"file":"sourceMapValidationEnums.js","sourceRoot":"","sources":["sourceMapValidationEnums.ts"],"names":["e","e2","e3"],"mappings":"AAAA,IAAK,CAIJ;AAJD,WAAK,CAAC;IACFA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;AACLA,CAACA,EAJI,CAAC,KAAD,CAAC,QAIL;AACD,IAAK,EAKJ;AALD,WAAK,EAAE;IACHC,aAAIA,EAAEA,OAAAA,CAAAA;IACNA,aAAIA,EAAEA,OAAAA,CAAAA;IACNA,sBAACA,CAAAA;IACDA,wBAAEA,CAAAA;AACNA,CAACA,EALI,EAAE,KAAF,EAAE,QAKN;AACD,IAAK,EACJ;AADD,WAAK,EAAE;AACPC,CAACA,EADI,EAAE,KAAF,EAAE,QACN"}
|
||||
@@ -39,31 +39,40 @@ sourceFile:sourceMapValidationEnums.ts
|
||||
>>> e[e["x"] = 0] = "x";
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^
|
||||
3 > ^^->
|
||||
3 > ^
|
||||
4 > ^->
|
||||
1-> {
|
||||
>
|
||||
2 > x
|
||||
3 >
|
||||
1->Emitted(3, 5) Source(2, 5) + SourceIndex(0) name (e)
|
||||
2 >Emitted(3, 24) Source(2, 6) + SourceIndex(0) name (e)
|
||||
3 >Emitted(3, 25) Source(2, 6) + SourceIndex(0) name (e)
|
||||
---
|
||||
>>> e[e["y"] = 1] = "y";
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^
|
||||
3 > ^^->
|
||||
3 > ^
|
||||
4 > ^->
|
||||
1->,
|
||||
>
|
||||
2 > y
|
||||
3 >
|
||||
1->Emitted(4, 5) Source(3, 5) + SourceIndex(0) name (e)
|
||||
2 >Emitted(4, 24) Source(3, 6) + SourceIndex(0) name (e)
|
||||
3 >Emitted(4, 25) Source(3, 6) + SourceIndex(0) name (e)
|
||||
---
|
||||
>>> e[e["x"] = 2] = "x";
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^
|
||||
3 > ^
|
||||
1->,
|
||||
>
|
||||
2 > x
|
||||
3 >
|
||||
1->Emitted(5, 5) Source(4, 5) + SourceIndex(0) name (e)
|
||||
2 >Emitted(5, 24) Source(4, 6) + SourceIndex(0) name (e)
|
||||
3 >Emitted(5, 25) Source(4, 6) + SourceIndex(0) name (e)
|
||||
---
|
||||
>>>})(e || (e = {}));
|
||||
1 >
|
||||
@@ -128,51 +137,63 @@ sourceFile:sourceMapValidationEnums.ts
|
||||
2 > ^^^^^^^^^^^^^
|
||||
3 > ^^
|
||||
4 > ^^^^^^^
|
||||
5 > ^^->
|
||||
5 > ^
|
||||
6 > ^->
|
||||
1-> {
|
||||
>
|
||||
2 > x =
|
||||
3 > 10
|
||||
4 >
|
||||
5 >
|
||||
1->Emitted(9, 5) Source(7, 5) + SourceIndex(0) name (e2)
|
||||
2 >Emitted(9, 18) Source(7, 9) + SourceIndex(0) name (e2)
|
||||
3 >Emitted(9, 20) Source(7, 11) + SourceIndex(0) name (e2)
|
||||
4 >Emitted(9, 27) Source(7, 11) + SourceIndex(0) name (e2)
|
||||
5 >Emitted(9, 28) Source(7, 11) + SourceIndex(0) name (e2)
|
||||
---
|
||||
>>> e2[e2["y"] = 10] = "y";
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^^
|
||||
3 > ^^
|
||||
4 > ^^^^^^^
|
||||
5 > ^^->
|
||||
5 > ^
|
||||
6 > ^->
|
||||
1->,
|
||||
>
|
||||
2 > y =
|
||||
3 > 10
|
||||
4 >
|
||||
5 >
|
||||
1->Emitted(10, 5) Source(8, 5) + SourceIndex(0) name (e2)
|
||||
2 >Emitted(10, 18) Source(8, 9) + SourceIndex(0) name (e2)
|
||||
3 >Emitted(10, 20) Source(8, 11) + SourceIndex(0) name (e2)
|
||||
4 >Emitted(10, 27) Source(8, 11) + SourceIndex(0) name (e2)
|
||||
5 >Emitted(10, 28) Source(8, 11) + SourceIndex(0) name (e2)
|
||||
---
|
||||
>>> e2[e2["z"] = 11] = "z";
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^^^^
|
||||
3 > ^^^^->
|
||||
3 > ^
|
||||
4 > ^^^->
|
||||
1->,
|
||||
>
|
||||
2 > z
|
||||
3 >
|
||||
1->Emitted(11, 5) Source(9, 5) + SourceIndex(0) name (e2)
|
||||
2 >Emitted(11, 27) Source(9, 6) + SourceIndex(0) name (e2)
|
||||
3 >Emitted(11, 28) Source(9, 6) + SourceIndex(0) name (e2)
|
||||
---
|
||||
>>> e2[e2["x2"] = 12] = "x2";
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
3 > ^
|
||||
1->,
|
||||
>
|
||||
2 > x2
|
||||
3 >
|
||||
1->Emitted(12, 5) Source(10, 5) + SourceIndex(0) name (e2)
|
||||
2 >Emitted(12, 29) Source(10, 7) + SourceIndex(0) name (e2)
|
||||
3 >Emitted(12, 30) Source(10, 7) + SourceIndex(0) name (e2)
|
||||
---
|
||||
>>>})(e2 || (e2 = {}));
|
||||
1 >
|
||||
|
||||
@@ -13,5 +13,5 @@ var Foo = (function () {
|
||||
return Foo;
|
||||
})();
|
||||
switch (0) {
|
||||
case Foo: break;
|
||||
case Foo: break; // Error expected
|
||||
}
|
||||
|
||||
@@ -25,12 +25,13 @@ var Foo = (function () {
|
||||
return Foo;
|
||||
})();
|
||||
switch (0) {
|
||||
case Foo: break;
|
||||
case "sss": break;
|
||||
case 123: break;
|
||||
case true: break;
|
||||
case Foo: break; // Error
|
||||
case "sss": break; // Error
|
||||
case 123: break; // No Error
|
||||
case true: break; // Error
|
||||
}
|
||||
var s = 0;
|
||||
// No error for all
|
||||
switch (s) {
|
||||
case Foo: break;
|
||||
case "sss": break;
|
||||
|
||||
@@ -149,6 +149,7 @@ throw aFunctionInModule;
|
||||
// no initializer or annotation, so this is an 'any'
|
||||
var x;
|
||||
throw x;
|
||||
// literals
|
||||
throw 0.0;
|
||||
throw false;
|
||||
throw null;
|
||||
|
||||
@@ -105,56 +105,73 @@ function foo12(x: number | string | boolean) {
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when false,
|
||||
// provided the false expression contains no assignments to the variable or parameter.
|
||||
function foo(x) {
|
||||
return typeof x === "string" ? x.length : x++; // number
|
||||
return typeof x === "string" ? x.length // string
|
||||
: x++; // number
|
||||
}
|
||||
function foo2(x) {
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
return typeof x === "string" ? (x = 10 && x) : x; // string | number
|
||||
return typeof x === "string" ? (x = 10 && x) // string | number
|
||||
: x; // string | number
|
||||
}
|
||||
function foo3(x) {
|
||||
// x is assigned in the if false branch, the type is not narrowed
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string" ? (x = "Hello" && x) : x; // string | number
|
||||
return typeof x === "string" ? (x = "Hello" && x) // string | number
|
||||
: x; // string | number
|
||||
}
|
||||
function foo4(x) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string" ? x : (x = 10 && x); // string | number
|
||||
return typeof x === "string" ? x // string | number
|
||||
: (x = 10 && x); // string | number
|
||||
}
|
||||
function foo5(x) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
return typeof x === "string" ? x : (x = "hello" && x); // string | number
|
||||
return typeof x === "string" ? x // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
}
|
||||
function foo6(x) {
|
||||
// Modify in both branches
|
||||
return typeof x === "string" ? (x = 10 && x) : (x = "hello" && x); // string | number
|
||||
return typeof x === "string" ? (x = 10 && x) // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
}
|
||||
function foo7(x) {
|
||||
return typeof x === "string" ? x === "hello" : typeof x === "boolean" ? x : x == 10; // number
|
||||
return typeof x === "string" ? x === "hello" // string
|
||||
: typeof x === "boolean" ? x // boolean
|
||||
: x == 10; // number
|
||||
}
|
||||
function foo8(x) {
|
||||
var b;
|
||||
return typeof x === "string" ? x === "hello" : ((b = x) && (typeof x === "boolean" ? x : x == 10)); // number
|
||||
return typeof x === "string" ? x === "hello" : ((b = x) && (typeof x === "boolean" ? x // boolean
|
||||
: x == 10)); // number
|
||||
}
|
||||
function foo9(x) {
|
||||
var y = 10;
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
return typeof x === "string" ? ((y = x.length) && x === "hello") : x === 10; // number
|
||||
return typeof x === "string" ? ((y = x.length) && x === "hello") // string
|
||||
: x === 10; // number
|
||||
}
|
||||
function foo10(x) {
|
||||
// Mixing typeguards
|
||||
var b;
|
||||
return typeof x === "string" ? x : ((b = x) && typeof x === "number" && x.toString()); // x is number
|
||||
return typeof x === "string" ? x // string
|
||||
: ((b = x) // x is number | boolean
|
||||
&& typeof x === "number" && x.toString()); // x is number
|
||||
}
|
||||
function foo11(x) {
|
||||
// Mixing typeguards
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
var b;
|
||||
return typeof x === "string" ? x : ((b = x) && typeof x === "number" && (x = 10) && x); // x is number | boolean | string
|
||||
return typeof x === "string" ? x // number | boolean | string - changed in the false branch
|
||||
: ((b = x) // x is number | boolean | string - because the assignment changed it
|
||||
&& typeof x === "number" && (x = 10) // assignment to x
|
||||
&& x); // x is number | boolean | string
|
||||
}
|
||||
function foo12(x) {
|
||||
// Mixing typeguards
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
var b;
|
||||
return typeof x === "string" ? (x = 10 && x.toString().length) : ((b = x) && typeof x === "number" && x); // x is number
|
||||
return typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here
|
||||
: ((b = x) // x is number | boolean | string - changed in true branch
|
||||
&& typeof x === "number" && x); // x is number
|
||||
}
|
||||
|
||||
@@ -84,25 +84,29 @@ module m1 {
|
||||
function foo(x) {
|
||||
return typeof x === "string" ? x : function f() {
|
||||
var b = x; // number | boolean
|
||||
return typeof x === "boolean" ? x.toString() : x.toString(); // number
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}();
|
||||
}
|
||||
function foo2(x) {
|
||||
return typeof x === "string" ? x : function f(a) {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean" ? x.toString() : x.toString(); // number
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}(x); // x here is narrowed to number | boolean
|
||||
}
|
||||
function foo3(x) {
|
||||
return typeof x === "string" ? x : (function () {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean" ? x.toString() : x.toString(); // number
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
})();
|
||||
}
|
||||
function foo4(x) {
|
||||
return typeof x === "string" ? x : (function (a) {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean" ? x.toString() : x.toString(); // number
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
})(x); // x here is narrowed to number | boolean
|
||||
}
|
||||
// Type guards affect nested function expressions, but not nested function declarations
|
||||
@@ -125,7 +129,8 @@ var m;
|
||||
y = x; // string;
|
||||
}
|
||||
else {
|
||||
y = typeof x === "boolean" ? x.toString() : x.toString(); // number
|
||||
y = typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}
|
||||
})(m2 || (m2 = {}));
|
||||
})(m || (m = {}));
|
||||
@@ -142,7 +147,8 @@ var m1;
|
||||
y = x; // string;
|
||||
}
|
||||
else {
|
||||
y = typeof x === "boolean" ? x.toString() : x.toString(); // number
|
||||
y = typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}
|
||||
})(m3 = m2.m3 || (m2.m3 = {}));
|
||||
})(m2 || (m2 = {}));
|
||||
|
||||
@@ -258,7 +258,8 @@ function foo10(x) {
|
||||
else {
|
||||
var y;
|
||||
var b = x; // number | boolean
|
||||
return typeof x === "number" ? x === 10 : x; // x should be boolean
|
||||
return typeof x === "number" ? x === 10 // number
|
||||
: x; // x should be boolean
|
||||
}
|
||||
}
|
||||
function foo11(x) {
|
||||
@@ -270,7 +271,13 @@ function foo11(x) {
|
||||
else {
|
||||
var y;
|
||||
var b = x; // number | boolean | string - because below we are changing value of x in if statement
|
||||
return typeof x === "number" ? (x = 10 && x.toString()) : (y = x && x.toString());
|
||||
return typeof x === "number" ? (
|
||||
// change value of x
|
||||
x = 10 && x.toString() // number | boolean | string
|
||||
) : (
|
||||
// do not change value
|
||||
y = x && x.toString() // number | boolean | string
|
||||
);
|
||||
}
|
||||
}
|
||||
function foo12(x) {
|
||||
@@ -282,6 +289,7 @@ function foo12(x) {
|
||||
else {
|
||||
x = 10;
|
||||
var b = x; // number | boolean | string
|
||||
return typeof x === "number" ? x.toString() : x.toString(); // boolean | string
|
||||
return typeof x === "number" ? x.toString() // number
|
||||
: x.toString(); // boolean | string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,26 +71,37 @@ function foo3(x) {
|
||||
return typeof x === "string" && ((x = "hello") && x); // string | number
|
||||
}
|
||||
function foo4(x) {
|
||||
return typeof x !== "string" && typeof x !== "number" && x; // boolean
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& typeof x !== "number" // number | boolean
|
||||
&& x; // boolean
|
||||
}
|
||||
function foo5(x) {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b;
|
||||
return typeof x !== "string" && ((b = x) && (typeof x !== "number" && x)); // boolean
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& ((b = x) && (typeof x !== "number" // number | boolean
|
||||
&& x)); // boolean
|
||||
}
|
||||
function foo6(x) {
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
return typeof x !== "string" && (typeof x !== "number" ? x : x === 10); // number
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10); // number
|
||||
}
|
||||
function foo7(x) {
|
||||
var y;
|
||||
var z;
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x !== "string" && ((z = x) && (typeof x === "number" ? (x = 10 && x.toString()) : (y = x && x.toString()))); // number | boolean | string
|
||||
return typeof x !== "string" && ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
&& (typeof x === "number" ? (x = 10 && x.toString()) // number | boolean | string
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
}
|
||||
function foo8(x) {
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x !== "string" && (x = 10) && (typeof x === "number" ? x : x.length); // string
|
||||
return typeof x !== "string" && (x = 10) // change x - number| string
|
||||
&& (typeof x === "number" ? x // number
|
||||
: x.length); // string
|
||||
}
|
||||
|
||||
@@ -71,26 +71,37 @@ function foo3(x) {
|
||||
return typeof x !== "string" || ((x = "hello") || x); // string | number
|
||||
}
|
||||
function foo4(x) {
|
||||
return typeof x === "string" || typeof x === "number" || x; // boolean
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| typeof x === "number" // number | boolean
|
||||
|| x; // boolean
|
||||
}
|
||||
function foo5(x) {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b;
|
||||
return typeof x === "string" || ((b = x) || (typeof x === "number" || x)); // boolean
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| ((b = x) || (typeof x === "number" // number | boolean
|
||||
|| x)); // boolean
|
||||
}
|
||||
function foo6(x) {
|
||||
// Mixing typeguard
|
||||
return typeof x === "string" || (typeof x !== "number" ? x : x === 10); // number
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10); // number
|
||||
}
|
||||
function foo7(x) {
|
||||
var y;
|
||||
var z;
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x === "string" || ((z = x) || (typeof x === "number" ? (x = 10 && x.toString()) : (y = x && x.toString()))); // number | boolean | string
|
||||
return typeof x === "string" || ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
|| (typeof x === "number" ? (x = 10 && x.toString()) // number | boolean | string
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
}
|
||||
function foo8(x) {
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x === "string" || (x = 10) || (typeof x === "number" ? x : x.length); // string
|
||||
return typeof x === "string" || (x = 10) // change x - number| string
|
||||
|| (typeof x === "number" ? x // number
|
||||
: x.length); // string
|
||||
}
|
||||
|
||||
@@ -131,12 +131,12 @@ var WinJS;
|
||||
})(WinJS || (WinJS = {}));
|
||||
var Errors;
|
||||
(function (Errors) {
|
||||
var ConnectionError = (function () {
|
||||
function ConnectionError(request) {
|
||||
var ConnectionError /* extends Error */ = (function () {
|
||||
function ConnectionError /* extends Error */(request) {
|
||||
}
|
||||
return ConnectionError;
|
||||
return ConnectionError /* extends Error */;
|
||||
})();
|
||||
Errors.ConnectionError = ConnectionError;
|
||||
Errors.ConnectionError /* extends Error */ = ConnectionError /* extends Error */;
|
||||
})(Errors || (Errors = {}));
|
||||
var FileService = (function () {
|
||||
function FileService() {
|
||||
|
||||
Reference in New Issue
Block a user