Skip to content

Commit

Permalink
fix(compiler): handle symbol properties for dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
seckardt committed Dec 17, 2023
1 parent 8b6fd77 commit d779ef8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { wire, LightningElement } from "lwc";
import { getFoo } from "data-service";
const key1 = Symbol.for("key");
export default class Test extends LightningElement {
@wire(getFoo, { [key1]: "$prop1", key2: ["fixed", "array"] })
wiredProp;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { registerDecorators as _registerDecorators, registerComponent as _registerComponent, LightningElement } from "lwc";
import _tmpl from "./test.html";
import { getFoo } from "data-service";
const key1 = Symbol.for("key");
class Test extends LightningElement {
wiredProp;
/*LWC compiler vX.X.X*/
}
_registerDecorators(Test, {
wire: {
wiredProp: {
adapter: getFoo,
dynamic: [key1],
config: function ($cmp) {
return {
key2: ["fixed", "array"],
[key1]: $cmp.prop1
};
}
}
}
});
export default _registerComponent(Test, {
tmpl: _tmpl,
sel: "lwc-test",
apiVersion: 9999999
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { wire, LightningElement } from "lwc";
import { getFoo } from "data-service";
export default class Test extends LightningElement {
// eslint-disable-next-line no-useless-computed-key
@wire(getFoo, { ["key1"]: "$prop1", key2: ["fixed", "array"] })
wiredProp;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { registerDecorators as _registerDecorators, registerComponent as _registerComponent, LightningElement } from "lwc";
import _tmpl from "./test.html";
import { getFoo } from "data-service";
class Test extends LightningElement {
// eslint-disable-next-line no-useless-computed-key
wiredProp;
/*LWC compiler vX.X.X*/
}
_registerDecorators(Test, {
wire: {
wiredProp: {
adapter: getFoo,
dynamic: ["key1"],
config: function ($cmp) {
return {
key2: ["fixed", "array"],
["key1"]: $cmp.prop1
};
}
}
}
});
export default _registerComponent(Test, {
tmpl: _tmpl,
sel: "lwc-test",
apiVersion: 9999999
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getWiredParams(
.filter((property) => isObservedProperty(property as NodePath<types.ObjectProperty>))
.map((path) => {
// Need to clone deep the observed property to remove the param prefix
const clonedProperty = t.cloneDeep(path.node) as types.ObjectProperty;
const clonedProperty = t.cloneNode(path.node) as types.ObjectProperty;
(clonedProperty.value as types.StringLiteral).value = (
clonedProperty.value as types.StringLiteral
).value.slice(1);
Expand Down Expand Up @@ -141,7 +141,8 @@ function getGeneratedConfig(t: BabelTypes, wiredValue: WiredValue) {
configProps.push(
t.objectProperty(
(param as types.ObjectProperty).key,
paramConfigValue.configValueExpression
paramConfigValue.configValueExpression,
param.computed
)
);

Expand Down Expand Up @@ -174,9 +175,12 @@ function buildWireConfigValue(t: BabelTypes, wiredValues: WiredValue[]) {

if (wiredValue.params) {
const dynamicParamNames = wiredValue.params.map((p) => {
return t.stringLiteral(
t.isIdentifier(p.key) ? p.key.name : (p.key as types.StringLiteral).value
);
const value = t.isIdentifier(p.key)
? p.key.name
: (p.key as types.StringLiteral).value;
return p.computed && t.isIdentifier(p.key)
? t.identifier(value)
: t.stringLiteral(value);
});
wireConfig.push(
t.objectProperty(t.identifier('dynamic'), t.arrayExpression(dynamicParamNames))
Expand Down

0 comments on commit d779ef8

Please sign in to comment.