Skip to content

Commit fa0d37d

Browse files
committed
Merge remote-tracking branch 'origin/main' into port/import-defer
2 parents c62a410 + 5595106 commit fa0d37d

File tree

7 files changed

+90
-181
lines changed

7 files changed

+90
-181
lines changed

internal/binder/binder.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ func (b *Binder) declareSymbolAndAddToSymbolTable(node *ast.Node, symbolFlags as
443443
return b.declareClassMember(node, symbolFlags, symbolExcludes)
444444
case ast.KindEnumDeclaration:
445445
return b.declareSymbol(ast.GetExports(b.container.Symbol()), b.container.Symbol(), node, symbolFlags, symbolExcludes)
446-
case ast.KindTypeLiteral, ast.KindJSDocTypeLiteral, ast.KindObjectLiteralExpression, ast.KindInterfaceDeclaration, ast.KindJsxAttributes:
446+
case ast.KindTypeLiteral, ast.KindObjectLiteralExpression, ast.KindInterfaceDeclaration, ast.KindJsxAttributes:
447447
return b.declareSymbol(ast.GetMembers(b.container.Symbol()), b.container.Symbol(), node, symbolFlags, symbolExcludes)
448-
case ast.KindFunctionType, ast.KindConstructorType, ast.KindCallSignature, ast.KindConstructSignature, ast.KindJSDocSignature,
448+
case ast.KindFunctionType, ast.KindConstructorType, ast.KindCallSignature, ast.KindConstructSignature,
449449
ast.KindIndexSignature, ast.KindMethodDeclaration, ast.KindMethodSignature, ast.KindConstructor, ast.KindGetAccessor,
450450
ast.KindSetAccessor, ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction,
451451
ast.KindClassStaticBlockDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindMappedType:
@@ -672,10 +672,8 @@ func (b *Binder) bind(node *ast.Node) bool {
672672
case ast.KindSetAccessor:
673673
b.bindPropertyOrMethodOrAccessor(node, ast.SymbolFlagsSetAccessor, ast.SymbolFlagsSetAccessorExcludes)
674674
case ast.KindFunctionType, ast.KindConstructorType:
675-
// !!! KindJSDocSignature
676675
b.bindFunctionOrConstructorType(node)
677676
case ast.KindTypeLiteral, ast.KindMappedType:
678-
// !!! KindJSDocTypeLiteral
679677
b.bindAnonymousDeclaration(node, ast.SymbolFlagsTypeLiteral, ast.InternalSymbolNameType)
680678
case ast.KindObjectLiteralExpression:
681679
b.bindAnonymousDeclaration(node, ast.SymbolFlagsObjectLiteral, ast.InternalSymbolNameObject)
@@ -1121,10 +1119,6 @@ func (b *Binder) bindVariableDeclarationOrBindingElement(node *ast.Node) {
11211119
}
11221120

11231121
func (b *Binder) bindParameter(node *ast.Node) {
1124-
// !!!
1125-
// if node.kind == KindJSDocParameterTag && b.container.kind != KindJSDocSignature {
1126-
// return
1127-
// }
11281122
decl := node.AsParameterDeclaration()
11291123
if b.inStrictMode && node.Flags&ast.NodeFlagsAmbient == 0 {
11301124
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
@@ -1190,17 +1184,6 @@ func (b *Binder) bindBlockScopedDeclaration(node *ast.Node, symbolFlags ast.Symb
11901184
}
11911185

11921186
func (b *Binder) bindTypeParameter(node *ast.Node) {
1193-
// !!!
1194-
// if isJSDocTemplateTag(node.parent) {
1195-
// var container *HasLocals = getEffectiveContainerForJSDocTemplateTag(node.parent)
1196-
// if container {
1197-
// Debug.assertNode(container, canHaveLocals)
1198-
// /* TODO(TS-TO-GO) QuestionQuestionEqualsToken BinaryExpression: container.locals ??= createSymbolTable() */ TODO
1199-
// b.declareSymbol(container.locals /*parent*/, nil, node, SymbolFlagsTypeParameter, SymbolFlagsTypeParameterExcludes)
1200-
// } else {
1201-
// b.declareSymbolAndAddToSymbolTable(node, SymbolFlagsTypeParameter, SymbolFlagsTypeParameterExcludes)
1202-
// }
1203-
// }
12041187
if node.Parent.Kind == ast.KindInferType {
12051188
container := b.getInferTypeContainer(node.Parent)
12061189
if container != nil {
@@ -1633,10 +1616,6 @@ func (b *Binder) bindChildren(node *ast.Node) {
16331616
b.bindCallExpressionFlow(node)
16341617
case ast.KindNonNullExpression:
16351618
b.bindNonNullExpressionFlow(node)
1636-
// case *JSDocTypedefTag, *JSDocCallbackTag, *JSDocEnumTag:
1637-
// b.bindJSDocTypeAlias(node)
1638-
// case *JSDocImportTag:
1639-
// b.bindJSDocImportTag(node)
16401619
case ast.KindSourceFile:
16411620
sourceFile := node.AsSourceFile()
16421621
b.bindEachStatementFunctionsFirst(sourceFile.Statements)
@@ -2565,7 +2544,7 @@ func SetValueDeclaration(symbol *ast.Symbol, node *ast.Node) {
25652544
func GetContainerFlags(node *ast.Node) ContainerFlags {
25662545
switch node.Kind {
25672546
case ast.KindClassExpression, ast.KindClassDeclaration, ast.KindEnumDeclaration, ast.KindObjectLiteralExpression, ast.KindTypeLiteral,
2568-
ast.KindJSDocTypeLiteral, ast.KindJsxAttributes:
2547+
ast.KindJsxAttributes:
25692548
return ContainerFlagsIsContainer
25702549
case ast.KindInterfaceDeclaration:
25712550
return ContainerFlagsIsContainer | ContainerFlagsIsInterface
@@ -2580,7 +2559,7 @@ func GetContainerFlags(node *ast.Node) ContainerFlags {
25802559
fallthrough
25812560
case ast.KindConstructor, ast.KindClassStaticBlockDeclaration:
25822561
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals | ContainerFlagsIsFunctionLike | ContainerFlagsIsThisContainer
2583-
case ast.KindMethodSignature, ast.KindCallSignature, ast.KindJSDocSignature, ast.KindFunctionType, ast.KindConstructSignature, ast.KindConstructorType:
2562+
case ast.KindMethodSignature, ast.KindCallSignature, ast.KindFunctionType, ast.KindConstructSignature, ast.KindConstructorType:
25842563
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals | ContainerFlagsIsFunctionLike
25852564
case ast.KindFunctionDeclaration:
25862565
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals | ContainerFlagsIsFunctionLike | ContainerFlagsIsThisContainer
@@ -2617,9 +2596,6 @@ func isNarrowingExpression(expr *ast.Node) bool {
26172596
case ast.KindCallExpression:
26182597
return hasNarrowableArgument(expr)
26192598
case ast.KindParenthesizedExpression:
2620-
// if isJSDocTypeAssertion(expr) {
2621-
// return false
2622-
// }
26232599
return isNarrowingExpression(expr.AsParenthesizedExpression().Expression)
26242600
case ast.KindNonNullExpression:
26252601
return isNarrowingExpression(expr.AsNonNullExpression().Expression)

internal/checker/checker.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12410,17 +12410,32 @@ func (c *Checker) checkNullishCoalesceOperands(left *ast.Node, right *ast.Node)
1241012410
if ast.IsBinaryExpression(right) && ast.IsLogicalBinaryOperator(right.AsBinaryExpression().OperatorToken.Kind) {
1241112411
c.grammarErrorOnNode(right, diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses, scanner.TokenToString(right.AsBinaryExpression().OperatorToken.Kind), scanner.TokenToString(ast.KindQuestionQuestionToken))
1241212412
}
12413+
c.checkNullishCoalesceOperandLeft(left)
12414+
c.checkNullishCoalesceOperandRight(right)
12415+
}
12416+
12417+
func (c *Checker) checkNullishCoalesceOperandLeft(left *ast.Node) {
1241312418
leftTarget := ast.SkipOuterExpressions(left, ast.OEKAll)
1241412419
nullishSemantics := c.getSyntacticNullishnessSemantics(leftTarget)
1241512420
if nullishSemantics != PredicateSemanticsSometimes {
12416-
if left.Parent.Parent.Kind == ast.KindBinaryExpression {
12417-
c.error(leftTarget, diagnostics.This_binary_expression_is_never_nullish_Are_you_missing_parentheses)
12421+
if nullishSemantics == PredicateSemanticsAlways {
12422+
c.error(leftTarget, diagnostics.This_expression_is_always_nullish)
1241812423
} else {
12419-
if nullishSemantics == PredicateSemanticsAlways {
12420-
c.error(leftTarget, diagnostics.This_expression_is_always_nullish)
12421-
} else {
12422-
c.error(leftTarget, diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish)
12423-
}
12424+
c.error(leftTarget, diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish)
12425+
}
12426+
}
12427+
}
12428+
12429+
func (c *Checker) checkNullishCoalesceOperandRight(right *ast.Node) {
12430+
binaryExpression := right.Parent
12431+
if binaryExpression.Parent != nil && ast.IsBinaryExpression(binaryExpression.Parent) && binaryExpression.Parent.AsBinaryExpression().OperatorToken.Kind == ast.KindQuestionQuestionToken {
12432+
rightTarget := ast.SkipOuterExpressions(right, ast.OEKAll)
12433+
nullishSemantics := c.getSyntacticNullishnessSemantics(rightTarget)
12434+
switch nullishSemantics {
12435+
case PredicateSemanticsAlways:
12436+
c.error(rightTarget, diagnostics.This_expression_is_always_nullish)
12437+
case PredicateSemanticsNever:
12438+
c.error(rightTarget, diagnostics.This_expression_is_never_nullish)
1242412439
}
1242512440
}
1242612441
}

internal/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,7 @@ func (p *Parser) parseArrowFunctionExpressionBody(isAsync bool, allowReturnTypeI
43384338
}
43394339
saveContextFlags := p.contextFlags
43404340
p.setContextFlags(ast.NodeFlagsAwaitContext, isAsync)
4341+
p.setContextFlags(ast.NodeFlagsYieldContext, false)
43414342
node := p.parseAssignmentExpressionOrHigherWorker(allowReturnTypeInArrowFunction)
43424343
p.contextFlags = saveContextFlags
43434344
return node

testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@ predicateSemantics.ts(28,13): error TS2871: This expression is always nullish.
66
predicateSemantics.ts(29,13): error TS2871: This expression is always nullish.
77
predicateSemantics.ts(30,13): error TS2872: This kind of expression is always truthy.
88
predicateSemantics.ts(31,13): error TS2872: This kind of expression is always truthy.
9-
predicateSemantics.ts(32,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
10-
predicateSemantics.ts(33,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
11-
predicateSemantics.ts(34,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
9+
predicateSemantics.ts(32,13): error TS2871: This expression is always nullish.
10+
predicateSemantics.ts(32,21): error TS2871: This expression is always nullish.
11+
predicateSemantics.ts(33,13): error TS2871: This expression is always nullish.
12+
predicateSemantics.ts(34,13): error TS2871: This expression is always nullish.
13+
predicateSemantics.ts(34,22): error TS2871: This expression is always nullish.
14+
predicateSemantics.ts(36,20): error TS2871: This expression is always nullish.
15+
predicateSemantics.ts(37,20): error TS2871: This expression is always nullish.
1216
predicateSemantics.ts(38,21): error TS2871: This expression is always nullish.
1317
predicateSemantics.ts(39,21): error TS2871: This expression is always nullish.
14-
predicateSemantics.ts(40,21): error TS2870: This binary expression is never nullish. Are you missing parentheses?
15-
predicateSemantics.ts(45,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
16-
predicateSemantics.ts(46,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
17-
predicateSemantics.ts(47,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
18+
predicateSemantics.ts(40,21): error TS2871: This expression is always nullish.
19+
predicateSemantics.ts(40,29): error TS2871: This expression is always nullish.
20+
predicateSemantics.ts(41,21): error TS2871: This expression is always nullish.
21+
predicateSemantics.ts(42,20): error TS2881: This expression is never nullish.
22+
predicateSemantics.ts(43,21): error TS2881: This expression is never nullish.
23+
predicateSemantics.ts(45,13): error TS2871: This expression is always nullish.
24+
predicateSemantics.ts(45,21): error TS2871: This expression is always nullish.
25+
predicateSemantics.ts(45,29): error TS2871: This expression is always nullish.
26+
predicateSemantics.ts(46,13): error TS2871: This expression is always nullish.
27+
predicateSemantics.ts(46,21): error TS2881: This expression is never nullish.
28+
predicateSemantics.ts(47,13): error TS2871: This expression is always nullish.
29+
predicateSemantics.ts(47,22): error TS2881: This expression is never nullish.
1830
predicateSemantics.ts(50,8): error TS2872: This kind of expression is always truthy.
1931
predicateSemantics.ts(51,11): error TS2872: This kind of expression is always truthy.
2032
predicateSemantics.ts(52,8): error TS2872: This kind of expression is always truthy.
@@ -26,7 +38,7 @@ predicateSemantics.ts(89,1): error TS2869: Right operand of ?? is unreachable be
2638
predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
2739

2840

29-
==== predicateSemantics.ts (26 errors) ====
41+
==== predicateSemantics.ts (38 errors) ====
3042
declare let opt: number | undefined;
3143

3244
// OK: One or other operand is possibly nullish
@@ -76,16 +88,24 @@ predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable be
7688
!!! error TS2872: This kind of expression is always truthy.
7789
const p07 = null ?? null ?? null;
7890
~~~~
79-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
91+
!!! error TS2871: This expression is always nullish.
92+
~~~~
93+
!!! error TS2871: This expression is always nullish.
8094
const p08 = null ?? opt ?? null;
8195
~~~~
82-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
96+
!!! error TS2871: This expression is always nullish.
8397
const p09 = null ?? (opt ? null : undefined) ?? null;
8498
~~~~
85-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
99+
!!! error TS2871: This expression is always nullish.
100+
~~~~~~~~~~~~~~~~~~~~~~
101+
!!! error TS2871: This expression is always nullish.
86102

87103
const p10 = opt ?? null ?? 1;
104+
~~~~
105+
!!! error TS2871: This expression is always nullish.
88106
const p11 = opt ?? null ?? null;
107+
~~~~
108+
!!! error TS2871: This expression is always nullish.
89109
const p12 = opt ?? (null ?? 1);
90110
~~~~
91111
!!! error TS2871: This expression is always nullish.
@@ -94,20 +114,36 @@ predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable be
94114
!!! error TS2871: This expression is always nullish.
95115
const p14 = opt ?? (null ?? null ?? null);
96116
~~~~
97-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
117+
!!! error TS2871: This expression is always nullish.
118+
~~~~
119+
!!! error TS2871: This expression is always nullish.
98120
const p15 = opt ?? (opt ? null : undefined) ?? null;
121+
~~~~~~~~~~~~~~~~~~~~~~
122+
!!! error TS2871: This expression is always nullish.
99123
const p16 = opt ?? 1 ?? 2;
124+
~
125+
!!! error TS2881: This expression is never nullish.
100126
const p17 = opt ?? (opt ? 1 : 2) ?? 3;
127+
~~~~~~~~~~~
128+
!!! error TS2881: This expression is never nullish.
101129

102130
const p21 = null ?? null ?? null ?? null;
103131
~~~~
104-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
132+
!!! error TS2871: This expression is always nullish.
133+
~~~~
134+
!!! error TS2871: This expression is always nullish.
135+
~~~~
136+
!!! error TS2871: This expression is always nullish.
105137
const p22 = null ?? 1 ?? 1;
106138
~~~~
107-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
139+
!!! error TS2871: This expression is always nullish.
140+
~
141+
!!! error TS2881: This expression is never nullish.
108142
const p23 = null ?? (opt ? 1 : 2) ?? 1;
109143
~~~~
110-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
144+
!!! error TS2871: This expression is always nullish.
145+
~~~~~~~~~~~
146+
!!! error TS2881: This expression is never nullish.
111147

112148
// Outer expression tests
113149
while ({} as any) { }

0 commit comments

Comments
 (0)