mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Revert part of catch clause PR which broke other declarations (#52403)
This commit is contained in:
parent
022516e24d
commit
be488fa075
@ -27211,7 +27211,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
isFunctionLike(node) && !getImmediatelyInvokedFunctionExpression(node) ||
|
||||
node.kind === SyntaxKind.ModuleBlock ||
|
||||
node.kind === SyntaxKind.SourceFile ||
|
||||
node.kind === SyntaxKind.CatchClause ||
|
||||
node.kind === SyntaxKind.PropertyDeclaration)!;
|
||||
}
|
||||
|
||||
@ -27587,7 +27586,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
|
||||
const declarationContainer = getControlFlowContainer(declaration);
|
||||
let flowContainer = getControlFlowContainer(node);
|
||||
const isCatch = flowContainer.kind === SyntaxKind.CatchClause;
|
||||
const isOuterVariable = flowContainer !== declarationContainer;
|
||||
const isSpreadDestructuringAssignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
|
||||
const isModuleExports = symbol.flags & SymbolFlags.ModuleExports;
|
||||
@ -27602,7 +27600,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
|
||||
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
|
||||
// declaration container are the same).
|
||||
const assumeInitialized = isParameter || isCatch || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
|
||||
const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
|
||||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 ||
|
||||
isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
|
||||
node.parent.kind === SyntaxKind.NonNullExpression ||
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
//// [potentiallyUnassignedVariableInCatch.ts]
|
||||
let foo;
|
||||
try {
|
||||
if (Math.random() > 0.5) {
|
||||
foo = 1234;
|
||||
}
|
||||
} catch {
|
||||
foo;
|
||||
}
|
||||
|
||||
|
||||
//// [potentiallyUnassignedVariableInCatch.js]
|
||||
"use strict";
|
||||
var foo;
|
||||
try {
|
||||
if (Math.random() > 0.5) {
|
||||
foo = 1234;
|
||||
}
|
||||
}
|
||||
catch (_a) {
|
||||
foo;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
=== tests/cases/compiler/potentiallyUnassignedVariableInCatch.ts ===
|
||||
let foo;
|
||||
>foo : Symbol(foo, Decl(potentiallyUnassignedVariableInCatch.ts, 0, 3))
|
||||
|
||||
try {
|
||||
if (Math.random() > 0.5) {
|
||||
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
|
||||
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
foo = 1234;
|
||||
>foo : Symbol(foo, Decl(potentiallyUnassignedVariableInCatch.ts, 0, 3))
|
||||
}
|
||||
} catch {
|
||||
foo;
|
||||
>foo : Symbol(foo, Decl(potentiallyUnassignedVariableInCatch.ts, 0, 3))
|
||||
}
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/potentiallyUnassignedVariableInCatch.ts ===
|
||||
let foo;
|
||||
>foo : any
|
||||
|
||||
try {
|
||||
if (Math.random() > 0.5) {
|
||||
>Math.random() > 0.5 : boolean
|
||||
>Math.random() : number
|
||||
>Math.random : () => number
|
||||
>Math : Math
|
||||
>random : () => number
|
||||
>0.5 : 0.5
|
||||
|
||||
foo = 1234;
|
||||
>foo = 1234 : 1234
|
||||
>foo : any
|
||||
>1234 : 1234
|
||||
}
|
||||
} catch {
|
||||
foo;
|
||||
>foo : number | undefined
|
||||
}
|
||||
|
||||
10
tests/cases/compiler/potentiallyUnassignedVariableInCatch.ts
Normal file
10
tests/cases/compiler/potentiallyUnassignedVariableInCatch.ts
Normal file
@ -0,0 +1,10 @@
|
||||
// @strict: true
|
||||
|
||||
let foo;
|
||||
try {
|
||||
if (Math.random() > 0.5) {
|
||||
foo = 1234;
|
||||
}
|
||||
} catch {
|
||||
foo;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user