Skip to content

Commit 9585d1b

Browse files
authored
More fixes (microsoft#729)
1 parent 0d751ea commit 9585d1b

File tree

90 files changed

+1749
-2416
lines changed

Some content is hidden

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

90 files changed

+1749
-2416
lines changed

internal/ast/ast.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,10 @@ func (node *IfStatement) computeSubtreeFacts() SubtreeFacts {
21642164
propagateSubtreeFacts(node.ElseStatement)
21652165
}
21662166

2167+
func IsIfStatement(node *Node) bool {
2168+
return node.Kind == KindIfStatement
2169+
}
2170+
21672171
// DoStatement
21682172

21692173
type DoStatement struct {

internal/ast/tokenflags.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ const (
2323
TokenFlagsSingleQuote TokenFlags = 1 << 16 // e.g. `'abc'`
2424
TokenFlagsBinaryOrOctalSpecifier TokenFlags = TokenFlagsBinarySpecifier | TokenFlagsOctalSpecifier
2525
TokenFlagsWithSpecifier TokenFlags = TokenFlagsHexSpecifier | TokenFlagsBinaryOrOctalSpecifier
26-
TokenFlagsStringLiteralFlags TokenFlags = TokenFlagsHexEscape | TokenFlagsUnicodeEscape | TokenFlagsExtendedUnicodeEscape | TokenFlagsContainsInvalidEscape | TokenFlagsSingleQuote
26+
TokenFlagsStringLiteralFlags TokenFlags = TokenFlagsUnterminated | TokenFlagsHexEscape | TokenFlagsUnicodeEscape | TokenFlagsExtendedUnicodeEscape | TokenFlagsContainsInvalidEscape | TokenFlagsSingleQuote
2727
TokenFlagsNumericLiteralFlags TokenFlags = TokenFlagsScientific | TokenFlagsOctal | TokenFlagsContainsLeadingZero | TokenFlagsWithSpecifier | TokenFlagsContainsSeparator | TokenFlagsContainsInvalidSeparator
28-
TokenFlagsTemplateLiteralLikeFlags TokenFlags = TokenFlagsHexEscape | TokenFlagsUnicodeEscape | TokenFlagsExtendedUnicodeEscape | TokenFlagsContainsInvalidEscape
28+
TokenFlagsTemplateLiteralLikeFlags TokenFlags = TokenFlagsUnterminated | TokenFlagsHexEscape | TokenFlagsUnicodeEscape | TokenFlagsExtendedUnicodeEscape | TokenFlagsContainsInvalidEscape
29+
TokenFlagsRegularExpressionLiteralFlags TokenFlags = TokenFlagsUnterminated
2930
TokenFlagsIsInvalid TokenFlags = TokenFlagsOctal | TokenFlagsContainsLeadingZero | TokenFlagsContainsInvalidSeparator | TokenFlagsContainsInvalidEscape
3031
)

internal/ast/utilities.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,3 +2571,7 @@ func IsRequireCall(node *Node, requireStringLiteralLikeArgument bool) bool {
25712571
}
25722572
return !requireStringLiteralLikeArgument || IsStringLiteralLike(call.Arguments.Nodes[0])
25732573
}
2574+
2575+
func IsUnterminatedLiteral(node *Node) bool {
2576+
return node.LiteralLikeData().TokenFlags&TokenFlagsUnterminated != 0
2577+
}

internal/binder/binder.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type Binder struct {
6666
hasFlowEffects bool
6767
inStrictMode bool
6868
inAssignmentPattern bool
69+
seenParseError bool
6970
symbolCount int
7071
classifiableNames core.Set[string]
7172
symbolPool core.Pool[ast.Symbol]
@@ -713,16 +714,23 @@ func (b *Binder) bind(node *ast.Node) bool {
713714
// the current 'container' node when it changes. This helps us know which symbol table
714715
// a local should go into for example. Since terminal nodes are known not to have
715716
// children, as an optimization we don't process those.
717+
thisNodeOrAnySubnodesHasError := node.Flags&ast.NodeFlagsThisNodeHasError != 0
716718
if node.Kind > ast.KindLastToken {
717719
saveParent := b.parent
720+
saveSeenParseError := b.seenParseError
718721
b.parent = node
722+
b.seenParseError = false
719723
containerFlags := GetContainerFlags(node)
720724
if containerFlags == ContainerFlagsNone {
721725
b.bindChildren(node)
722726
} else {
723727
b.bindContainer(node, containerFlags)
724728
}
729+
if b.seenParseError {
730+
thisNodeOrAnySubnodesHasError = true
731+
}
725732
b.parent = saveParent
733+
b.seenParseError = saveSeenParseError
726734
} else {
727735
saveParent := b.parent
728736
if node.Kind == ast.KindEndOfFile {
@@ -731,6 +739,10 @@ func (b *Binder) bind(node *ast.Node) bool {
731739
b.bindJSDoc(node)
732740
b.parent = saveParent
733741
}
742+
if thisNodeOrAnySubnodesHasError {
743+
node.Flags |= ast.NodeFlagsThisNodeOrAnySubNodesHasError
744+
b.seenParseError = true
745+
}
734746
b.inStrictMode = saveInStrictMode
735747
return false
736748
}

internal/binder/nameresolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func isTypeParameterSymbolDeclaredInContainer(symbol *ast.Symbol, container *ast
489489
func isSelfReferenceLocation(node *ast.Node, lastLocation *ast.Node) bool {
490490
switch node.Kind {
491491
case ast.KindParameter:
492-
return lastLocation != nil && lastLocation == node.AsParameterDeclaration().Name()
492+
return lastLocation != nil && lastLocation == node.Name()
493493
case ast.KindFunctionDeclaration, ast.KindClassDeclaration, ast.KindInterfaceDeclaration, ast.KindEnumDeclaration,
494494
ast.KindTypeAliasDeclaration, ast.KindModuleDeclaration: // For `namespace N { N; }`
495495
return true

internal/checker/checker.go

Lines changed: 71 additions & 53 deletions
Large diffs are not rendered by default.

internal/checker/flow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ func (c *Checker) isConstantReference(node *ast.Node) bool {
17851785
case ast.KindPropertyAccessExpression, ast.KindElementAccessExpression:
17861786
// The resolvedSymbol property is initialized by checkPropertyAccess or checkElementAccess before we get here.
17871787
if c.isConstantReference(node.Expression()) {
1788-
symbol := c.typeNodeLinks.Get(node).resolvedSymbol
1788+
symbol := c.getResolvedSymbolOrNil(node)
17891789
if symbol != nil {
17901790
return c.isReadonlySymbol(symbol)
17911791
}

internal/checker/types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,13 @@ type NodeLinks struct {
320320
hasReportedStatementInAmbientContext bool // Cache boolean if we report statements in ambient context
321321
}
322322

323+
type SymbolNodeLinks struct {
324+
resolvedSymbol *ast.Symbol // Resolved symbol associated with node
325+
}
326+
323327
type TypeNodeLinks struct {
324-
resolvedType *Type // Cached type of type node
325-
resolvedSymbol *ast.Symbol // Cached name resolution result
326-
outerTypeParameters []*Type // Outer type parameters of anonymous object type
328+
resolvedType *Type // Resolved type associated with node
329+
outerTypeParameters []*Type // Outer type parameters of anonymous object type
327330
}
328331

329332
// Links for enum members

internal/evaluator/evaluator.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,20 @@ func AnyToString(v any) string {
151151
case jsnum.PseudoBigInt:
152152
return v.String()
153153
}
154-
panic("Unhandled case in anyToString")
154+
panic("Unhandled case in AnyToString")
155+
}
156+
157+
func IsTruthy(v any) bool {
158+
// !!! This function should behave identically to the expression `!!v` in JS
159+
switch v := v.(type) {
160+
case string:
161+
return len(v) != 0
162+
case jsnum.Number:
163+
return v != 0 && !v.IsNaN()
164+
case bool:
165+
return v
166+
case jsnum.PseudoBigInt:
167+
return v != jsnum.PseudoBigInt{}
168+
}
169+
panic("Unhandled case in IsTruthy")
155170
}

internal/parser/jsdoc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullSta
125125
saveParsingMode := p.scanner.JSDocParsingMode
126126
saveScannerState := p.scanner.Mark()
127127
saveDiagnosticsLength := len(p.diagnostics)
128+
saveHasParseError := p.hasParseError
128129

129130
// initial indent is start+4 to account for leading `/** `
130131
// + 1 because \n is one character before the first character in the line and,
@@ -153,6 +154,7 @@ func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullSta
153154
p.scanner.JSDocParsingMode = saveParsingMode
154155
p.scanner.Rewind(saveScannerState)
155156
p.token = saveToken
157+
p.hasParseError = saveHasParseError
156158

157159
return comment
158160
}

0 commit comments

Comments
 (0)