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

add location info to nodes #1501

Merged
merged 4 commits into from
May 28, 2018
Merged

add location info to nodes #1501

merged 4 commits into from
May 28, 2018

Conversation

Rich-Harris
Copy link
Member

Fixes #1499.

Here's a short clip of this feature being used in Sapper Studio. The App pane has an edit icon, which takes you to the current page, and a crosshairs icon which lets you select a specific element.

@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte v2.6.6 */
Copy link
Member

Choose a reason for hiding this comment

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

I thought we updated the CLI tests before they were merged in to replace the version number with x.y.z - when did that go away?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think we just changed the tests so that it would replace the version numbers when it compared the actual vs expected. would probably be better if it did that when the file is written, to avoid cluttering diffs

}

export function addLoc(element, file, line, column, char) {
element.__svelte_meta = { file, line, column, char };
Copy link
Member

Choose a reason for hiding this comment

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

I guess I was imagining that the loc data would live down inside an object under some key under __svelte_meta, to keep it conceptually separated from other future non-loc data.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yeah, that probably makes sense

@@ -100,6 +100,10 @@ export default function dom(
builder.addBlock(compiler.javascript);
}

if (compiler.options.dev) {
builder.addLine(`const __file = ${JSON.stringify(compiler.file)};`);
Copy link
Member

Choose a reason for hiding this comment

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

It's of course very unlikely that anyone would use a variable called __file, but it seems unwise to knowingly introduce potential conflicts, and I don't really see what this provides over simply including ${JSON.stringify(this.compiler.file)} over when you generate code calling addLoc from Element.ts

Copy link
Member Author

Choose a reason for hiding this comment

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

was just thinking it'd look less cluttered than having the filename repeated throughout the component. i guess we have the tools to pick a name that's guaranteed not to conflict, i was just being lazy

@Rich-Harris Rich-Harris merged commit 5375af5 into master May 28, 2018
@Rich-Harris Rich-Harris deleted the gh-1499 branch May 28, 2018 23:40
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