Skip to content

Commit f0f5a0d

Browse files
committed
updated command line options, accepted baselines
1 parent ca0d580 commit f0f5a0d

227 files changed

Lines changed: 3047 additions & 15217 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/binder.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,11 @@ namespace ts {
557557
function bindBreakOrContinueStatement(n: BreakOrContinueStatement): boolean {
558558
// call bind on label (don't affect reachability)
559559
bind(n.label);
560-
if (n.kind === SyntaxKind.BreakStatement) {
561-
jumpToLabel(n.label, currentReachabilityState);
560+
// for continue case touch label so it will be marked a used
561+
const isValidJump = jumpToLabel(n.label, n.kind === SyntaxKind.BreakStatement ? currentReachabilityState : Reachability.Unreachable);
562+
if (isValidJump) {
563+
currentReachabilityState = Reachability.Unreachable;
562564
}
563-
else {
564-
jumpToLabel(n.label, Reachability.Unreachable); // touch label so it will be marked a used
565-
}
566-
currentReachabilityState = Reachability.Unreachable;
567-
568565
return true;
569566
}
570567

@@ -1406,7 +1403,7 @@ namespace ts {
14061403
initializeReachabilityStateIfNecessary();
14071404

14081405
if (innerMergedState === Reachability.Unintialized) {
1409-
if (label && options.noUnusedLabels) {
1406+
if (label && !options.allowUnusedLabels) {
14101407
file.bindDiagnostics.push(createDiagnosticForNode(label, Diagnostics.Unused_label));
14111408
}
14121409
currentReachabilityState = outerState;
@@ -1416,17 +1413,18 @@ namespace ts {
14161413
}
14171414
}
14181415

1419-
function jumpToLabel(label: Identifier, outerState: Reachability): void {
1416+
function jumpToLabel(label: Identifier, outerState: Reachability): boolean {
14201417
initializeReachabilityStateIfNecessary();
14211418

14221419
const index = label ? labelIndexMap[label.text] : lastOrUndefined(implicitLabels);
14231420
if (index === undefined) {
14241421
// reference to unknown label or
14251422
// break/continue used outside of loops
1426-
return;
1423+
return false;
14271424
}
14281425
const stateAtLabel = labelStack[index];
14291426
labelStack[index] = stateAtLabel === Reachability.Unintialized ? outerState : or(stateAtLabel, outerState);
1427+
return true;
14301428
}
14311429

14321430
function checkUnreachable(node: Node): boolean {
@@ -1455,7 +1453,7 @@ namespace ts {
14551453
// Rationale: we don't want to report errors on non-initialized var's since they are hoisted
14561454
// On the other side we do want to report errors on non-initialized 'lets' because of TDZ
14571455
const reportUnreachableCode =
1458-
options.noUnreachableCode &&
1456+
!options.allowUnreachableCode &&
14591457
!isInAmbientContext(node) &&
14601458
(
14611459
node.kind !== SyntaxKind.VariableStatement ||
@@ -1464,7 +1462,7 @@ namespace ts {
14641462
);
14651463

14661464
if (reportUnreachableCode) {
1467-
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Unreachable_code_detected));
1465+
errorOnFirstToken(node, Diagnostics.Unreachable_code_detected);
14681466
}
14691467
}
14701468
case Reachability.ReportedUnreachable:

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ namespace ts {
248248
error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic,
249249
},
250250
{
251-
name: "noUnusedLabels",
251+
name: "allowUnusedLabels",
252252
type: "boolean",
253-
description: Diagnostics.Report_error_on_unused_labels
253+
description: Diagnostics.Do_not_report_errors_on_unused_labels
254254
},
255255
{
256256
name: "noImplicitReturns",
@@ -263,9 +263,9 @@ namespace ts {
263263
description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement
264264
},
265265
{
266-
name: "noUnreachableCode",
266+
name: "allowUnreachableCode",
267267
type: "boolean",
268-
description: Diagnostics.Report_errors_on_unreachable_code
268+
description: Diagnostics.Do_not_report_errors_on_unreachable_code
269269
}
270270
];
271271

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@
23022302
"category": "Message",
23032303
"code": 6072
23042304
},
2305-
"Report error on unused labels.": {
2305+
"Do not report errors on unused labels.": {
23062306
"category": "Message",
23072307
"code": 6073
23082308
},
@@ -2314,7 +2314,7 @@
23142314
"category": "Message",
23152315
"code": 6075
23162316
},
2317-
"Report errors on unreachable code.": {
2317+
"Do not report errors on unreachable code.": {
23182318
"category": "Message",
23192319
"code": 6076
23202320
},

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,10 +2075,10 @@ namespace ts {
20752075
experimentalAsyncFunctions?: boolean;
20762076
emitDecoratorMetadata?: boolean;
20772077
moduleResolution?: ModuleResolutionKind;
2078-
noUnusedLabels?: boolean;
2078+
allowUnusedLabels?: boolean;
2079+
allowUnreachableCode?: boolean;
20792080
noImplicitReturns?: boolean;
20802081
noFallthroughCasesInSwitch?: boolean;
2081-
noUnreachableCode?: boolean;
20822082
/* @internal */ stripInternal?: boolean;
20832083

20842084
// Skip checking lib.d.ts to help speed up tests.

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ namespace ts {
12031203
case SyntaxKind.LabeledStatement:
12041204
case SyntaxKind.ReturnStatement:
12051205
case SyntaxKind.SwitchStatement:
1206-
case SyntaxKind.ThrowKeyword:
1206+
case SyntaxKind.ThrowStatement:
12071207
case SyntaxKind.TryStatement:
12081208
case SyntaxKind.VariableStatement:
12091209
case SyntaxKind.WhileStatement:

tests/baselines/reference/assignmentLHSIsValue.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(2
1313
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: Invalid left-hand side of assignment expression.
1414
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression.
1515
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression.
16+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,3): error TS7028: Unused label.
1617
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,9): error TS1128: Declaration or statement expected.
1718
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: Invalid left-hand side of assignment expression.
1819
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: Invalid left-hand side of assignment expression.
@@ -38,7 +39,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6
3839
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression.
3940

4041

41-
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (38 errors) ====
42+
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ====
4243
// expected error for all the LHS of assignments
4344
var value;
4445

@@ -104,6 +105,8 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
104105

105106
// object literals
106107
{ a: 0} = value;
108+
~
109+
!!! error TS7028: Unused label.
107110
~
108111
!!! error TS1128: Declaration or statement expected.
109112

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests/cases/compiler/bestCommonTypeReturnStatement.ts(7,5): error TS7027: Unreachable code detected.
2+
3+
4+
==== tests/cases/compiler/bestCommonTypeReturnStatement.ts (1 errors) ====
5+
interface IPromise<T> {
6+
then(successCallback: (promiseValue: T) => any, errorCallback?: (reason: any) => any): IPromise<any>;
7+
}
8+
9+
function f() {
10+
if (true) return b();
11+
return d();
12+
~~~~~~
13+
!!! error TS7027: Unreachable code detected.
14+
}
15+
16+
17+
function b(): IPromise<void> { return null; }
18+
function d(): IPromise<any> { return null; }

tests/baselines/reference/bestCommonTypeReturnStatement.symbols

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/baselines/reference/bestCommonTypeReturnStatement.types

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/breakTarget3.ts(2,1): error TS7028: Unused label.
2+
3+
4+
==== tests/cases/compiler/breakTarget3.ts (1 errors) ====
5+
target1:
6+
target2:
7+
~~~~~~~
8+
!!! error TS7028: Unused label.
9+
while (true) {
10+
break target1;
11+
}

0 commit comments

Comments
 (0)