Git Product home page Git Product logo

Comments (7)

bathos avatar bathos commented on June 1, 2024 1

@bensmithett It turned out solving for both cases was possible without the kind of ‘correctness’ concessions I thought would be necessary. I’m gonna wait for a sign off on the PR from Blake since he knows the tagged template stuff much better than I do, but I think it’s likely gonna work.

BTW, for html you can omit the /* syntax: html */ now if the name of the tag is html.

from ecmascript-sublime.

bathos avatar bathos commented on June 1, 2024

For most template tag language modes, yes, we just delegate to existing definitions. But iirc, HTML may be one of the exceptional cases where we’re baking in a customized version, so this may be addressable.

The problem you’re running into appears to specifically be about attribute quotation marks. When we get past the interpolated segment, we’re still expecting opening quotation marks for an HTML attribute. The nature of the problem can be seen more clearly if we add quotation marks after — it resumes correctly, then:

image

A bit tangential, but maybe interesting: You mentioned that the lit-html extension for VSCode handles their absence okay. That surprised me slightly since lit-html discourages omitting the quotation marks, normally included because lit-html templates get parsed as real HTML by the browser. It’s a bit of a footgun in that context to omit them (it’s often fine, but may lead to avoidable surprises), so I haven’t noticed the issue myself as a lit-html user:

image

I will take a look at whether we’re baking in our own HTML def here or not and see if this is fixable from there.

from ecmascript-sublime.

bathos avatar bathos commented on June 1, 2024

I missed the second item in your screenshot on the first read, the use of interpolated segments in place of tag names. That’s a bit trickier since the assumption we need to make is weaker. That is, attr=${} is a strong signal because we know the sequence must begin with an attribute value (even if it’s the empty string), and we couldn’t possibly be expected to recover if someone did things like attr=${"'foo'>"} or attr="${ 'foo"' }. In contrast, <${x} is a fairly good indicator of a tag start, but there are many other possible continuations there in HTML, some of which even leave the < as chardata. I’ll look into it though.

from ecmascript-sublime.

bensmithett avatar bensmithett commented on June 1, 2024

@bathos amazing, thanks!

from ecmascript-sublime.

blake-regalia avatar blake-regalia commented on June 1, 2024

it is possible - i can do some black magic and have the embedded HTML syntax explicitly allow interpolated elements to act as unquoted attribute values. This opens up pandora's box a tiny bit since we would also want to consider all embedded contexts that should recover from interpolated elements, but i definitely see the value in making this work for markup languages. We wouldn't try to recover from the situations @bathos describes but we can at least cover all the cases you would want to interpolate a word, tag attribute or value.

from ecmascript-sublime.

blake-regalia avatar blake-regalia commented on June 1, 2024

Update just saw the two prev posts and the PR. Will check it out now.

from ecmascript-sublime.

blake-regalia avatar blake-regalia commented on June 1, 2024

Fixed in v2.1.2. Interpolation now supports tag names, attribute names, attribute values, and text node values.

from ecmascript-sublime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.