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: augments metadata gathering for @wire decorator #631
Changes from 2 commits
eedcd8e
378de88
d055683
875004e
4e0abbf
94b150b
d41f3a1
a5cfd96
890938d
f4ddcbf
8d8490e
ae4b1e0
25f7dfa
065d9cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,11 +74,13 @@ function buildWireConfigValue(t, wiredValues) { | |
})); | ||
} | ||
|
||
function getWiredStaticMetadata(properties) { | ||
const ret = {}; | ||
function getWiredStaticMetadata(properties, getReferenceByName) { | ||
const ret = {}; | ||
properties.forEach(s => { | ||
if (s.key.type === 'Identifier' && s.value.type === 'ArrayExpression') { | ||
ret[s.key.name] = s.value.elements.map(e => e.value); | ||
} else if (s.key.type === 'Identifier' && s.value.type === 'Identifier') { | ||
ret[s.key.name] = {reference: getReferenceByName(s.value.name)}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we still assign the value if getReferenceByName returned undefined? (in the event of a missing import) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as per conversation, return undefined explicitly, let me know if I misunderstood the conclusion, I can - not set it otherwise |
||
} | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
}); | ||
return ret; | ||
|
@@ -107,17 +109,19 @@ module.exports = function transform(t, klass, decorators) { | |
const wiredValue = { | ||
propertyName, | ||
isClassMethod | ||
} | ||
}; | ||
|
||
if (config) { | ||
wiredValue.static = getWiredStatic(config); | ||
wiredValue.params = getWiredParams(t, config); | ||
} | ||
|
||
const getReferenceByName = name => path.scope.getBinding(name).path.parentPath.node.source.value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add existence check to the output of getBinding(name) , as the import may not exist There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
However the traversal: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like path.scope.getBinding is null when import is missing, fixed & added test, also added some defensive checks but I'm not sure whether that's needed for module imports since I added a restriction to only resolve module imports, I'll need to revisit this. |
||
|
||
if (id.isIdentifier()) { | ||
wiredValue.adapter = { | ||
name: id.node.name, | ||
reference: path.scope.getBinding(id.node.name).path.parentPath.node.source.value | ||
reference: getReferenceByName(id.node.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could preserve id.node.name reference since its accessed twice here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
|
||
|
@@ -128,7 +132,7 @@ module.exports = function transform(t, klass, decorators) { | |
}; | ||
|
||
if (config) { | ||
wireMetadata.static = getWiredStaticMetadata(wiredValue.static); | ||
wireMetadata.static = getWiredStaticMetadata(wiredValue.static, getReferenceByName); | ||
wireMetadata.params = getWiredParamMetadata(wiredValue.params); | ||
} | ||
|
||
|
@@ -154,4 +158,4 @@ module.exports = function transform(t, klass, decorators) { | |
targets: metadata | ||
}; | ||
} | ||
} | ||
}; |
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.
we should test relative import
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 would love to have other tests a well:
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.
@apapko done
@pmdartus done