-
Notifications
You must be signed in to change notification settings - Fork 402
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(babel-plugin-transform-lwc-class): Transform imported decorators #49
Conversation
Benchmark comparisonBase commit:
|
|
||
transformTest('throws if a decorator is dereferenced', ` | ||
import { track } from 'engine'; | ||
const trok = track; |
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.
const trock = track;
} | ||
`, { | ||
error: { | ||
message: 'test.js: "track" can only be used as a class decorator', |
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.
the error message is confusing, can we say something regarding the fact that track has been referenced by trock and that's not supported
?
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.
This one is tricky to implement. There are many ways to use track
we can't create customize messages for each cases.
}); | ||
|
||
test('decorator expects an oject as second parameter', ` | ||
transformTest('decorator expects an oject as second parameter', ` |
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.
as @kevinv11n would notice, oject
is missing a b
}); | ||
|
||
test('throws when using 2 wired decorators', ` | ||
transformTest('throws when using 2 wired decorators', ` | ||
import { wire } from 'engine'; | ||
export default class Test { | ||
@wire('record', { recordId: '$recordId', fields: ['Address'] }) | ||
@wire('record', { recordId: '$recordId', fields: ['Name'] }) | ||
wiredWithTrack |
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.
nitpick - wiredWithTrack
is a bad name for this test case
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.
some minor changes are needed
class Test1 extends Element {} | ||
|
||
export default class Test2 extends Element { | ||
render() { |
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.
nitpick, fix the indention for render() {...}
@@ -1,162 +1,188 @@ | |||
const test = require('./utils/test-transform').test( | |||
const transformTest = require('./utils/test-transform').transformTest( |
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.
i actually think it would be less confusing if you do
const test = require('./utils/test-transform').transformTest(require('../index'));
test
is really transformTester
, yet you name it transformTest
so when I read between util/test-transform.js
and this test file, i got confused.
just my 2 cents, i am okay if you don't want to change it
Benchmark comparisonBase commit:
|
should we wait for @diervo to finish the work on decorators in general to make this change? |
What is the decorator work @diervo is working on? |
are you referring to @context? I think that's independent to this PR (it might even benefit from this PR implementation wise) |
I don't know, maybe we should chat with @diervo. My understand is that we could move out wire and context once he finishes the changes. |
Details
Currently, the compiler assumes that decorators like
api
,track
andwire
are globally available. This PR updates the compiler to only transform decorators that are imported by fromengine
.A component previously written like ...
... should be updated into.
Does this PR introduce a breaking change?
If yes, please describe the impact and migration path for existing applications:
The compiler will now throw if it find a decorator which is not imported from
engine
. A codemod has been developed on the side to help developers migrate to the new syntax.