Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
40ee30b
wip
jakebailey Nov 5, 2025
1af4d7c
wip
jakebailey Nov 5, 2025
1cef046
wip
jakebailey Nov 5, 2025
3110ac6
wip
jakebailey Nov 5, 2025
b648805
wip
jakebailey Nov 5, 2025
0470fb4
wip
jakebailey Nov 5, 2025
899ad1d
wip
jakebailey Nov 5, 2025
a5a1597
wip
jakebailey Nov 5, 2025
9a4c582
move code
jakebailey Nov 5, 2025
918571e
wip
jakebailey Nov 5, 2025
9c50cd8
wip
jakebailey Nov 5, 2025
9cade06
Validate extended Unicode escape values in regexp scanner and add bas…
jakebailey Nov 5, 2025
2ab00a3
Include pending low surrogate in character class range error
jakebailey Nov 5, 2025
6b788d2
Simplify
jakebailey Nov 5, 2025
e1c3215
Simplify
jakebailey Nov 5, 2025
1831e7b
Simplify
jakebailey Nov 5, 2025
e944385
Delete temp test
jakebailey Nov 5, 2025
2d4159c
Remove helper
jakebailey Nov 5, 2025
d6a8a5c
refactor
jakebailey Nov 5, 2025
b36d027
refactor
jakebailey Nov 5, 2025
d878c54
Simplify
jakebailey Nov 5, 2025
24e7ea1
more refactors
jakebailey Nov 5, 2025
6e230fb
move code around
jakebailey Nov 5, 2025
1ab893a
use a set
jakebailey Nov 5, 2025
fd90e1b
Small simplifications
jakebailey Nov 5, 2025
0c95bf0
Rename func
jakebailey Nov 5, 2025
3450dae
cleanups
jakebailey Nov 5, 2025
fdb5b71
Move utf16 junk out
jakebailey Nov 5, 2025
cb08daf
Defer to utf16 package where possible
jakebailey Nov 5, 2025
b63d61b
Remove unused method
jakebailey Nov 5, 2025
0604d23
Fix named capture group stuff
jakebailey Nov 5, 2025
082cbcc
Fix porting difference
jakebailey Nov 5, 2025
320e435
fix escaping
jakebailey Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 24 additions & 36 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/jsnum"
"github.com/microsoft/typescript-go/internal/regexpchecker"
"github.com/microsoft/typescript-go/internal/scanner"
"github.com/microsoft/typescript-go/internal/tspath"
)
Expand Down Expand Up @@ -54,43 +55,30 @@ func (c *Checker) grammarErrorOnNodeSkippedOnNoEmit(node *ast.Node, message *dia
return false
}

func (c *Checker) checkGrammarRegularExpressionLiteral(_ *ast.RegularExpressionLiteral) bool {
// !!!
// Unclear if this is needed until regular expression parsing is more thoroughly implemented.
func (c *Checker) checkGrammarRegularExpressionLiteral(node *ast.RegularExpressionLiteral) bool {
sourceFile := ast.GetSourceFileOfNode(node.AsNode())
if !c.hasParseDiagnostics(sourceFile) && node.TokenFlags&ast.TokenFlagsUnterminated == 0 {
var lastError *ast.Diagnostic

nodeStart := scanner.GetTokenPosOfNode(node.AsNode(), sourceFile, false)
onError := func(message *diagnostics.Message, start int, length int, args ...any) {
start += nodeStart

if message.Category() == diagnostics.CategoryMessage && lastError != nil &&
start == lastError.Pos() && length == lastError.Len() {
err := ast.NewDiagnostic(nil, core.NewTextRange(start, start+length), message, args...)
lastError.AddRelatedInfo(err)
} else if lastError == nil || start != lastError.Pos() {
lastError = ast.NewDiagnostic(sourceFile, core.NewTextRange(start, start+length), message, args...)
c.diagnostics.Add(lastError)
}
}

regexpchecker.Check(node, sourceFile, c.languageVersion, onError)

return lastError != nil
}
return false
// sourceFile := ast.GetSourceFileOfNode(node.AsNode())
// if !c.hasParseDiagnostics(sourceFile) && !node.IsUnterminated {
// var lastError *ast.Diagnostic
// scanner := NewScanner()
// scanner.skipTrivia = true
// scanner.SetScriptTarget(sourceFile.LanguageVersion)
// scanner.SetLanguageVariant(sourceFile.LanguageVariant)
// scanner.SetOnError(func(message *diagnostics.Message, start int, length int, args ...any) {
// // !!!
// // Original uses `tokenEnd()` - unclear if this is the same as the `start` passed in here.
// // const start = scanner.TokenEnd()

// // The scanner is operating on a slice of the original source text, so we need to adjust the start
// // for error reporting.
// start = start + node.Pos()

// // For providing spelling suggestions
// if message.Category() == diagnostics.CategoryMessage && lastError != nil && start == lastError.Pos() && length == lastError.Len() {
// err := ast.NewDiagnostic(sourceFile, core.NewTextRange(start, start+length), message, args)
// lastError.AddRelatedInfo(err)
// } else if !(lastError != nil) || start != lastError.Pos() {
// lastError = ast.NewDiagnostic(sourceFile, core.NewTextRange(start, start+length), message, args)
// c.diagnostics.Add(lastError)
// }
// })
// scanner.SetText(sourceFile.Text[node.Pos():node.Loc.Len()])
// scanner.Scan()
// if scanner.ReScanSlashToken() != ast.KindRegularExpressionLiteral {
// panic("Expected to rescan RegularExpressionLiteral")
// }
// return lastError != nil
// }
// return false
}

func (c *Checker) checkGrammarPrivateIdentifierExpression(privId *ast.PrivateIdentifier) bool {
Expand Down
11 changes: 9 additions & 2 deletions internal/collections/set.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package collections

import "maps"
import (
"maps"
"slices"
)

type Set[T comparable] struct {
M map[T]struct{}
Expand Down Expand Up @@ -37,6 +40,10 @@ func (s *Set[T]) Keys() map[T]struct{} {
return s.M
}

func (s *Set[T]) KeysSlice() []T {
return slices.AppendSeq(make([]T, 0, len(s.M)), maps.Keys(s.M))
}

func (s *Set[T]) Clear() {
clear(s.M)
}
Expand Down Expand Up @@ -69,7 +76,7 @@ func (s *Set[T]) Equals(other *Set[T]) bool {
}

func NewSetFromItems[T comparable](items ...T) *Set[T] {
s := &Set[T]{}
s := NewSetWithSizeHint[T](len(items))
for _, item := range items {
s.Add(item)
}
Expand Down
Loading