public List<NodeHandler> GetHandlers(RuleAnalysisScope scope, TypeScript.Net.Types.SyntaxKind syntaxKind) { Contract.Requires(IsSingleCaseEnum(scope), "Scope should have just once bit enabled!"); Contract.Requires((int)syntaxKind >= 0 && (int)syntaxKind <= (int)TypeScript.Net.Types.SyntaxKind.Count); return m_handlersesRepository.GetHandlers(scope, (int)syntaxKind); }
public static IEnumerable <(int start, int end, TypeScript.Net.Types.SyntaxKind kind)> GetTokens(ISourceFile sourceFile, bool preserveTrivia, bool preserveComments) { var scanner = new Scanner(ScriptTarget.Latest, preserveTrivia: preserveTrivia, allowBackslashesInPathInterpolation: sourceFile.BackslashesAllowedInPathInterpolation, text: sourceFile.Text, preserveComments: preserveComments); TypeScript.Net.Types.SyntaxKind tokenKind = TypeScript.Net.Types.SyntaxKind.Unknown; TypeScript.Net.Types.SyntaxKind lastTokenKind = TypeScript.Net.Types.SyntaxKind.Unknown; bool backtickFound = false; bool backslashesAreAllowed = false; string previousIdentifierText = null; while ((tokenKind = scanner.Scan()) != TypeScript.Net.Types.SyntaxKind.EndOfFileToken) { if (tokenKind == TypeScript.Net.Types.SyntaxKind.CloseBraceToken && backtickFound) { yield return(scanner.TokenPos, scanner.TextPos, tokenKind); lastTokenKind = tokenKind; tokenKind = scanner.RescanTemplateToken(backslashesAreAllowed); } if (tokenKind == TypeScript.Net.Types.SyntaxKind.TemplateHead) { backtickFound = true; backslashesAreAllowed = sourceFile.BackslashesAllowedInPathInterpolation && Scanner.IsPathLikeInterpolationFactory(previousIdentifierText); } else if (tokenKind == TypeScript.Net.Types.SyntaxKind.TemplateTail) { backtickFound = false; } yield return(GetStartAndEndPositions(scanner, tokenKind, lastTokenKind)); if (tokenKind == TypeScript.Net.Types.SyntaxKind.Identifier) { previousIdentifierText = scanner.TokenValue; } else { previousIdentifierText = null; } } }
/// <nodoc /> public static void Register <T>(CompareHelper[] helpers, ushort relativeSortOrder, TypeScript.Net.Types.SyntaxKind syntaxKind, Comparison <T> comparable) where T : class, IExpression { var helper = new CompareHelper(syntaxKind, relativeSortOrder, (l, r) => { var left = l.As <T>(); var right = r.As <T>(); if (left == null) { return(right == null ? 0 : -1); } if (right == null) { return(1); } return(comparable(left.As <T>(), right.As <T>())); }); helpers[(int)syntaxKind] = helper; }
/// <nodoc /> private CompareHelper(TypeScript.Net.Types.SyntaxKind syntaxKind, ushort relativeSortOrder, Comparison <IExpression> comparison) { SyntaxKind = syntaxKind; RelativeSortOrder = relativeSortOrder; Comparison = comparison; }
/// <summary> /// Do a quick lookup for sorting information for the given SyntaxKind of the Node. /// </summary> private static CompareHelper TryGetCompareHelper(TypeScript.Net.Types.SyntaxKind syntaxKind) { return(s_compareHelpers[(int)syntaxKind]); }
private static (int start, int end, TypeScript.Net.Types.SyntaxKind tokenKind) GetStartAndEndPositions(Scanner scanner, TypeScript.Net.Types.SyntaxKind currentTokenKind, TypeScript.Net.Types.SyntaxKind lastTokenKind) { if (currentTokenKind == TypeScript.Net.Types.SyntaxKind.PublicKeyword) { if (lastTokenKind == TypeScript.Net.Types.SyntaxKind.AtToken) { return(start : scanner.TokenPos - 2, end : scanner.TextPos, currentTokenKind); } else { currentTokenKind = TypeScript.Net.Types.SyntaxKind.Identifier; } } return(start : scanner.TokenPos, end : scanner.TextPos, tokenKind : currentTokenKind); }