-
Notifications
You must be signed in to change notification settings - Fork 159
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 support for class components #299
Conversation
@lmiller1990 what do you think about this fix? |
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.
Nice job, logic seems fine (bit dirty, but 🤷♂️ I don't see a cleaner way right now).
Can you address the one comment I left? Thanks!
tempOutput.match(/\}\(.*.?Vue\);/) && | ||
tempOutput.includes('vue-class-component') | ||
) { | ||
node.add(';exports.default = {...exports.default.__vccBase};') |
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 think we will now end up with 2x node.add(';exports.default = {...exports.default};')
(added here and line 43).
Can you 1) check if that is the case and 2) make sure we only add it once? If we aren't careful, this can become really complex really fast!
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.
node now ends with
';exports.default = {...exports.default.__vccBase};',
';exports.default = {...exports.default, render};'
or
';exports.default = {...exports.default.__vccBase};',
';exports.default = {...exports.default};'
I think this is the desired behavoir because otherwise the code will be more complex.
Example:
if (
tempOutput.match(/\}\(.*.?Vue\);/) &&
tempOutput.includes('vue-class-component')
) {
if (tempOutput.includes('exports.render = render;')) {
node.add(';exports.default = {...exports.default.__vccBase, render};')
} else {
node.add(';exports.default = {...exports.default.__vccBase};')
}
} else {
if (tempOutput.includes('exports.render = render;')) {
node.add(';exports.default = {...exports.default, render};')
} else {
node.add(';exports.default = {...exports.default};')
}
}
this will have an output of
';exports.default = {...exports.default.__vccBase, render};'
or
';exports.default = {...exports.default.__vccBase};'
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.
Right, true, that is very complex. Fair enough.
I wonder if we should create a isClassComponent
function 🤔
Anyway, this will do for now, I will test it out a bit and if it's all good do a release. thanks!
Closes #297