Skip to content

Some fixes to tokenize#3942

Merged
DmitrySharabin merged 3 commits intosimplifyfrom
tokenize
May 25, 2025
Merged

Some fixes to tokenize#3942
DmitrySharabin merged 3 commits intosimplifyfrom
tokenize

Conversation

@DmitrySharabin
Copy link
Member

Summary

  • Don’t choke on patterns that are not instances of RegExp
  • In resolve() return resolvedGrammar and delete $rest after it is properly resolved

@github-actions
Copy link

No JS Changes

Generated by 🚫 dangerJS against 41093b8


if (typeof ret === 'string') {
ret = prism.languageRegistry.getLanguage(ret)?.grammar;
ret = prism.languageRegistry.getLanguage(ret)?.resolvedGrammar;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not fully resolving cases like:

{
  id: "foo",
  require: bar
  grammar: {
    token: {
      ...
      inside: "bar"
    }
  }
}

The bar language is imported and can be accessed via the languages array associated with the foo language. However, languages["bar"] is evaluated lazily. Until it's accessed for the first time, the bar language won't be added to the languageRegistry, and resolve(prism, "bar") will always return undefined.

Honestly, I don't know how to solve it without providing some extra info on the grammar we resolve. 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to traverse the grammar for resolvedGrammar and resolve anything that can be resolved without context. That will help with many things, e.g. self as well. It won't help with optional languages though. But we can replace it with a getter that overwrites itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan 👍

@DmitrySharabin DmitrySharabin merged commit a1112bc into simplify May 25, 2025
2 checks passed
@DmitrySharabin DmitrySharabin deleted the tokenize branch May 25, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants