-
Notifications
You must be signed in to change notification settings - Fork 392
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(compiler): detect unimported decorators #681
Conversation
e2c9a42
to
648b5b9
Compare
Benchmark resultsBase commit: |
2 similar comments
Benchmark resultsBase commit: |
Benchmark resultsBase commit: |
Benchmark resultsBase commit: |
9291d72
to
648b5b9
Compare
@@ -26,8 +28,22 @@ module.exports = function LwcClassTransform(api) { | |||
{ | |||
Program: { | |||
exit(path, state) { | |||
const visitors = mergeVisitors([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move the logic out of the file, we should not pollute the entry point.
const visitors = mergeVisitors([ | ||
classProperty(api, { loose: true }).visitor, | ||
{ | ||
Decorator(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add a comment here to explain why the Decorator visitor works here.
} | ||
}); | ||
|
||
pluginTest('compiler should throw when "track" decorator is used in the inner class but was not imported from lwc', ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do have this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was testing the decorator usage with inheritance, but with our new logic to check decorators on exit this no longer is needed.
648b5b9
to
5ee44d2
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: |
Benchmark resultsBase commit: lwc-engine-benchmark
|
} | ||
`, { | ||
error: { | ||
message: 'Invalid decorator usage. Supported decorators (api, wire, track) should be imported from "lwc"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be or must be?
Details
If babel-plugin-transform-lwc-class transform doesn't do early detection of a decorator usage that has not been imported from lwc, the issue is then caught by the babel with a bogus message. This PR adds validation earlier at the program visitor.
Fixes #601
Does this PR introduce a breaking change?