Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using with_prototype in syntax causes infinite recursion on Linux #6610

Open
nwoltman opened this issue Jan 30, 2025 · 5 comments
Open

Using with_prototype in syntax causes infinite recursion on Linux #6610

nwoltman opened this issue Jan 30, 2025 · 5 comments

Comments

@nwoltman
Copy link

Description of the bug

I am the creator of the EJS 2 syntax. The syntax definition I created for EJS uses with_prototype to embed JS into HTML. As of ST version 4186, the syntax definition can no longer load only on Linux due to an "Apparent recursion within a with_prototype action".

Steps to reproduce

  1. Using Ubuntu (or other Linux distro I assume, I only tried Ubuntu), install ST from scratch
  2. Install Package Control
  3. Install EJS 2 package
  4. Open a file and try to set the syntax to EJS 2 -> (any in the list)

Expected behavior

No error should occur and the syntax should work just like it does on Windows and MacOS

Actual behavior

The following error happens:

image

Sublime Text build number

4192

Operating system & version

Ubuntu 24.10

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information


@TerminalFi
Copy link

I think the most correct way is to now use extends.

#6555

@nwoltman
Copy link
Author

nwoltman commented Feb 6, 2025

How is it possible to do the same thing with extends?

I tried it by extending HTML and creating a prototype context with what I previously had in with_prototype. This almost works, but many contexts in the HTML syntax have meta_include_prototype: false, so my prototype is ignored in a lot of cases when I need it to work anywhere in HTML.

Is there a way to force a prototype to bypass meta_include_prototype: false? I assume not, but then how would you write something like a prototype that actually works in all contexts?.

Also, I don't see why with_prototype should cause an infinite recursion. It seems like this bug is happening because HTML syntax was added to JS template strings, but if HTML doesn't already have an infinite recursion, why would creating a syntax that starts in an HTML context "with a prototype" that embeds JS in an additional way cause an infinite recursion with an empty file?

@TerminalFi
Copy link

@deathaxe would probably have the best answer

@deathaxe
Copy link
Collaborator

deathaxe commented Feb 6, 2025

The lazy answer is: Have a look at packages like Astro, Laravel Blade, Liquid, Rails, Svelte, Vue, all of which using this technology to extend HTML and inject custom tags or interpolation.

It requires a bit of boilerplate code in HTML and some work to also extend CSS,JS,JSON (used by HTML) to add templating support.

This is also the only way to avoid extending unwanted/undesired HTML/CSS/JS contexts and keep their meta scopes intact. with_prototype can't do that.

@deathaxe
Copy link
Collaborator

deathaxe commented Feb 6, 2025

nwoltman/sublime-ejs#8 outlines least required changes to replace `with_prototype.

Compiled syntax cache size of EJS package is reduced from about 28MB to 380kB.

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

No branches or pull requests

3 participants