I found several unexpected behaviors while writing Lightning web components.
- Cannot have local name on imported decorator
import { LightningElement, api as a } from "lwc";
export default class MyComp1 extends LightningElement {
@a
prop1;
}
// => bad result: TypeError: Cannot read property 'referencePaths' of undefined
- Cannot re-assign the imported wiring function to variable
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name';
// re-assign the reference to another var
const getRec = getRecord;
export default class Record extends LightningElement {
@api
recordId;
@wire(getRec, { recordId: '$recordId', fields: [ACCOUNT_NAME_FIELD] })
record;
}
// => SyntaxError: /home/sfdc/tools/lwc/1.1.13-224.8/myComp1.js: LWC1098: @wire expects a function identifier to be imported as first parameter.
When considering ECMA standard, both cases should behave identical to the officially provided examples.
Maybe the platform compiler needs this restriction to detect dependency in static analysis, but is there any document that clearly says the LWC JS has the part against the spec ?
It may seems subtle and can be easily avoided, but many tools are assuming the output would be compliant to the ECMA standard so these simple renaming may happen when doing pre-processing the source code.