Skip to content

Add node location info in dev mode #1499

@Rich-Harris

Description

@Rich-Harris

I'm working on an Electron app called Sapper Studio, which is sort of a specialised IDE for building Sapper apps. Currently, while you're navigating around in the in-app browser, you can click an 'edit' icon and it will open that page in the editor (e.g. if you're on /blog/some-post it will open routes/blog/[slug].html), and you can do the same by clicking on filenames in the diagnostics panel to locate the sources of errors and warnings. It's pretty slick!

What would be even slicker is if you could target individual elements. In order to do this, the compiler would need to decorate elements with location info. Something like this:

const file = "components/Foo.html";
function addLoc(node, line, column) {
  node.__source = { file, line, column };
}

then later...

function create_main_fragment(component, ctx) {
  var h1, text, text_1, text_2;

  return {
    c: function create() {
      h1 = createElement("h1");
+     addLoc(h1, 0, 0);
      text = createText("Hello ");
      text_1 = createText(ctx.name);
      text_2 = createText("!");
    },

This would allow dev tooling like Sapper Studio (but also in-browser dev tools, when we get round to it) to present a UI for targeting nodes that were created by Svelte. (This is sort of what we were exploring in #973.)

Any thoughts before I go ahead and implement this? Is __source the right property, or do we need to bikeshed that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions