-
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): collect default value metadata for @api properties #816
Conversation
Benchmark resultsBase commit: |
Benchmark resultsBase commit: lwc-engine-benchmark
|
` | ||
import { LightningElement, api } from 'lwc'; | ||
export default class Foo extends LightningElement { | ||
_privateTodo |
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.
missing ';'
type: "property", | ||
value: { | ||
type: "object", | ||
value: { |
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!
{ type: "string", value: "stringval" }, | ||
{ type: "number", value: 0 }, | ||
{ type: "null", value: null }, | ||
{ type: undefined, value: undefined }, |
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 wonder if type should be undefined vs "undefined", as for example null technically is also an undefined type... just something to ponder about
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.
my thinking was as follows:
@api nullProp = null;
since the null has its own type - NullLiteral, we can capture it explicitly as a 'null' type;
Versus absence of value,
@api novalue;
where we cannot deduce its type, in which case it is truly undefined.
Anyhow, i will be adding 'unresolved' for consistency
} | ||
|
||
if (type === 'property') { | ||
meta.value = extractValueMetadata(parentValue) |
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.
missed ';'
function extractStringValueMeta(valueNode) { | ||
return { | ||
type: 'string', | ||
value: valueNode && valueNode.value || undefined, |
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.
when would the undefined condition kick in ?
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.
absence of value in valueNode.value is returned as 'null'; therefore returning undefined instead.
} | ||
|
||
if (!valueNode || !Array.isArray(valueNode.elements)) { | ||
return arrayValueMeta; |
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.
when would this condition be hit?
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.
elements always have value of empty array, i'm just being paranoid :). Will remove the !Array.isArray(valueNode.elements) check.
|
||
const values = {}; | ||
|
||
// TODO: do we want this as an object with properties mapped to the value objects |
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.
probably a map (as is done here) is better, more in line with expectations
@@ -184,6 +184,93 @@ function generateError(source, { errorInfo, messageArgs } = {}) { | |||
return error; | |||
} | |||
|
|||
function extractValueMetadata(valueNode) { | |||
|
|||
// TODO: should we flag anything we can't resolve , such as expressions, as type: 'unresolved' instead of undefined? |
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 would probably be more consistent with the way wire decorator value metadata works, either way we do it, it's just best to keep it consistent types wise.
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.
What i'm currently doing is not collecting value metadata for expressions at all, since we cannot resolve their value; However, the absence of a default value on the static property is captured as undefined.
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.
Looks good, a few minor questions.
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
128a380
to
473f615
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
473f615
to
aaa86e1
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
fcdb8e5
to
b051f42
Compare
b051f42
to
3f8876b
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
Today, metadata object produced by the compiler does not contain default values for public properties.
In order for the component metadata consumers to detect default values of the public properties, the metadata object must send back the value object for both classMember and decorators metadata objects ( api properties only as it is the only public property, and no methods )
ex:
will produce :
Does this PR introduce a breaking change?
Any tests in lwc-platform and aura that validate metadata shape may need to be edited.