MCPcopy Create free account
hub / github.com/microsoft/typescript-go / isValidBigIntString

Function isValidBigIntString

internal/checker/utilities.go:912–936  ·  view source on GitHub ↗
(s string, roundTripOnly bool)

Source from the content-addressed store, hash-verified

910}
911
912func isValidBigIntString(s string, roundTripOnly bool) bool {
913 if s == "" {
914 return false
915 }
916 scanner := scanner.NewScanner()
917 scanner.SetSkipTrivia(false)
918 success := true
919 scanner.SetOnError(func(diagnostic *diagnostics.Message, start, length int, args ...any) {
920 success = false
921 })
922 scanner.SetText(s + "n")
923 result := scanner.Scan()
924 negative := result == ast.KindMinusToken
925 if negative {
926 result = scanner.Scan()
927 }
928 flags := scanner.TokenFlags()
929 // validate that
930 // * scanning proceeded without error
931 // * a bigint can be scanned, and that when it is scanned, it is
932 // * the full length of the input string (so the scanner is one character beyond the augmented input length)
933 // * it does not contain a numeric separator (the `BigInt` constructor does not accept a numeric separator in its input)
934 return success && result == ast.KindBigIntLiteral && scanner.TokenEnd() == len(s)+1 && flags&ast.TokenFlagsContainsSeparator == 0 &&
935 (!roundTripOnly || s == pseudoBigIntToString(jsnum.NewPseudoBigInt(jsnum.ParsePseudoBigInt(scanner.TokenValue()), negative)))
936}
937
938func isValidESSymbolDeclaration(node *ast.Node) bool {
939 if ast.IsVariableDeclaration(node) {

Calls 11

SetSkipTriviaMethod · 0.95
SetOnErrorMethod · 0.95
SetTextMethod · 0.95
ScanMethod · 0.95
TokenFlagsMethod · 0.95
TokenEndMethod · 0.95
TokenValueMethod · 0.95
NewPseudoBigIntFunction · 0.92
ParsePseudoBigIntFunction · 0.92
lenFunction · 0.85
pseudoBigIntToStringFunction · 0.85

Tested by

no test coverage detected