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

feat(ssr): compiler error location #5114

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Jan 8, 2025

Details

Partially addresses #5032

I borrowed some tests from babel-plugin-component to make sure the location matches.

Since it uses generateCompilerError from @lwc/errors, it should work with the LSP/VSCode extension. (relevant code).

TODO

  • Clean up tests / move to separate file

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

GUS work item

@cardoso cardoso requested a review from a team as a code owner January 8, 2025 20:42
Copy link
Contributor Author

@cardoso cardoso left a comment

Choose a reason for hiding this comment

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

This PR needs cleaning up, but I wanted to get some feedback on the approach

Comment on lines +255 to +257
loc: true,
source: filename,
ranges: true,
Copy link
Contributor Author

@cardoso cardoso Jan 8, 2025

Choose a reason for hiding this comment

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

A couple possible changes to avoid bloating AST:

  • It didn't look like ranges are used by the LSP/VSCode extension, I only included it in order to match babel-plugin-compiler.
  • Source/filename could be moved to the ComponentMetaState. That would make things a bit coupled, but it might be worth it and is what babel-plugin-compiler seems to do:
    function generateError(
    source: NodePath<types.Node>,
    { errorInfo, messageArgs }: DecoratorErrorOptions,
    state: LwcBabelPluginPass
    ) {
    const message = generateErrorMessage(errorInfo, messageArgs);
    const error = source.buildCodeFrameError(message);
    (error as any).filename = state.filename;
    (error as any).loc = normalizeLocation(source);
    (error as any).lwcCode = errorInfo && errorInfo.code;
    return error;
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Matching babel-plugin-component exactly here is not necessary IMO, unless it's fulfilling some function in VS Code... and I take it it's not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nolanlawson
Copy link
Collaborator

/nucleus test

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

This LGTM, I have no complaints, but I'd like for @wjhsf to take a look too. Thanks a bunch!

@cardoso
Copy link
Contributor Author

cardoso commented Jan 10, 2025

Thanks for the review @nolanlawson ! Is nucleus failing due to something unrelated? I'm not able to see the logs.

@wjhsf
Copy link
Contributor

wjhsf commented Jan 10, 2025

Nucleus failures just seem like a hiccup.

@nolanlawson nolanlawson merged commit a37c754 into salesforce:master Jan 10, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants