DEV Community

Peter Mekhaeil
Peter Mekhaeil

Posted on • Edited on

Svelte components have file location meta data

Svelte nodes have a __svelte_meta object in development mode that contains the file location of the component that rendered that node.

{
    "loc": {
        "file": "src/routes/index.svelte",
        "line": 18,
        "column": 4,
        "char": 358
    }
}
Enter fullscreen mode Exit fullscreen mode

You an try it out on StackBlitz. Inspect an element using the Chrome Dev Tools and use the console:

$0.__svelte_meta
Enter fullscreen mode Exit fullscreen mode

Screenshot 2022-05-07 at 9 25 47 AM

($0 references the last selected DOM element. It is part of the DevTool's Console API)

Learn more about __svelte_meta:

Today I Learned
I share what I learn on Today I Learned.

Top comments (0)