Skip to content

Commit e2138e8

Browse files
committed
Check regular expression grammar once through a memo set
The grammar check of a regular expression literal ran once because of a TypeChecked flag on the node, set by a plain write. Discarding the results of a cycle does not undo such a write, so if the check ran while results were later discarded, it would not run again. Use a memo set instead, like the other checks whose only results are diagnostics, and drop the memo field that guarded nothing.
1 parent 6ab3813 commit e2138e8

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

‎tsc/internal/checker/checker.go‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ type memoStore struct {
10241024
ambientModulesOnce sync.Once
10251025
ambientModules []*ast.Symbol
10261026
reportedUnreachableNodes memoSet[*ast.Node]
1027+
checkedRegularExpressions memoSet[*ast.Node]
10271028
nonExistentProperties collections.Set[NonExistentPropertyKey]
10281029
deferredDiagnosticCallbacks []func(c *Checker)
10291030
memoStates map[memoKey]*memoState // Memo state of results computed by queries; see memo.go
@@ -8401,18 +8402,9 @@ func (c *Checker) isTemplateLiteralContextualType(t *Type) bool {
84018402
}
84028403

84038404
func (c *Checker) checkRegularExpressionLiteral(node *ast.Node) *Type {
8404-
c.beginMemo(memoKeyOf(node, memoRegularExpression))
8405-
result := c.checkRegularExpressionLiteralUncached(node)
8406-
c.endMemo()
8407-
return result
8408-
}
8409-
8410-
func (c *Checker) checkRegularExpressionLiteralUncached(node *ast.Node) *Type {
8411-
nodeLinks := c.nodeLinks.Get(node)
8412-
if nodeLinks.flags&NodeCheckFlagsTypeChecked == 0 {
8413-
nodeLinks.flags |= NodeCheckFlagsTypeChecked
8405+
c.checkedRegularExpressions.once(c, node, func() {
84148406
c.checkGrammarRegularExpressionLiteral(node.AsRegularExpressionLiteral())
8415-
}
8407+
})
84168408
return c.globalRegExpType
84178409
}
84188410

‎tsc/internal/checker/memo.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const (
4848
memoEnumMemberValue
4949
memoBaseConstraint
5050
memoAccessorType
51-
memoRegularExpression
5251
memoContextualParameters
5352
memoContextChecked
5453
memoInitializerIsUndefined

0 commit comments

Comments
 (0)