question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'index' and 'input' property on return type for custom token pattern

See original GitHub issue

The return type for a CustomPatternMatcherFunc is a RegExpExecArray (or null), which is defined as:

interface RegExpExecArray extends Array<string> {
    index: number;
    input: string;
}

The documentation doesn’t mention these properties. Are they actually required? If so, what should their value be? If not, perhaps RegExpMatchArray would be a better return type? It’s the same as RegExpExecArray but with the index and input properties marked as optional:

interface RegExpMatchArray extends Array<string> {
    index?: number;
    input?: string;
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
bd82commented, Aug 29, 2019

That’s really clever… Does it hurt maintainability like at all? The performance benefits are obviously worth it but I’m curious how such a thing impacts debugging/maintenance.

I think I’ve read about this “NOOP” pattern in a performance guide related to BlueBird promises library…

It can hurt maintainability by adding complexity and even some partially duplicated code, also sometimes there are performance regressions in V8 that need to be tracked down and mitigated. e.g: https://github.com/SAP/chevrotain/issues/942

Basically Performance is a feature and every feature has its costs 😦

0reactions
HoldYourWafflecommented, Aug 29, 2019

Whoops I completely missed your other comment…

Basically this.attemptInRepetitionRecovery method is defined either as NOOP (empty function) or the “real” function with the logic, depending if the parser uses the recovery feature. So if the recovery feature is not used, an empty function would get in-lined when V8 optimizes the hotspot and the result of in-lining an empty function is “nothing” so there is no runtime cost for the optional feature… Does this make sense?

That’s really clever… Does it hurt maintainability like at all? The performance benefits are obviously worth it but I’m curious how such a thing impacts debugging/maintenance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tokenizer - Marked Documentation
A function that returns the index of the next potential start of the custom token. The index can be the result of a...
Read more >
Add custom analyzers to string fields - Azure Cognitive Search
Configure text tokenizers and character filters to perform text analysis on strings during indexing and queries.
Read more >
Property 'fName' comes from an index signature, so it must be ...
We are talking about a template-driven form validation. You need to validate something, let's say to ensure that a field is required (call ......
Read more >
Array of tokenized documents for text analysis - MathWorks
The custom tokens have token type "custom" . View the token details. The column Type contains the token types. tdetails = tokenDetails(documents).
Read more >
Rule-based matching · spaCy Usage Documentation
If spaCy's tokenization doesn't match the tokens defined in a pattern, the pattern ... IS_SUBSET, Attribute value (for MORPH or custom list attributes)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found