realm-js
realm-js copied to clipboard
Fixed babel plugin add extra name property
What, How & Why?
When defining schema using class with a custom static property name, the generated schema code containes two name fields: one is class name and another is the static property. The expected result should only contain one name field
☑️ ToDos
- [ ] 📝 Changelog entry
- [ ] 📝
Compatibilitylabel is updated or copied from previous entry - [ ] 📝 Update
COMPATIBILITY.md - [ ] 🚦 Tests
- [ ] 📦 Updated internal package version in consuming
package.jsons (if updating internal packages) - [ ] 📱 Check the React Native/other sample apps work if necessary
- [ ] 💥
Breakinglabel has been applied or is not necessary
There is no doc for how to running test locally and I am not familier with wireit, so I skipped writing tests :(
@XHMM can you share an example of code that would trigger this?
There is no doc for how to running test locally
It should be as simple as:
- Checking out your fork of the repo
git submodule update --init --recursivenpm installnpm test --workspace @realm/babel-plugin
Here is a code sample:
schema defination using ts:
export class RecordModel extends Realm.Object<RecordModel, "recordFrom"> {
// @ts-ignore
static name = "Record";
static primaryKey = "_id";
_id: Realm.Types.ObjectId = new Realm.BSON.ObjectId();
@Realm.index recordAt: Realm.Types.Date = new Date();
recordFrom!: string;
}
after babel transform with current plugin: (some unrelated code was omitted)
(0, _defineProperty2.default)(RecordModel, "name", "Record");
RecordModel.primaryKey = "_id";
RecordModel.schema = {
name: "RecordModel", // class name
properties: {
_id: {
type: "objectId",
default: function _default() {
return new _realm.default.BSON.ObjectId();
},
},
recordAt: {
type: "date",
default: function _default() {
return new Date();
},
indexed: true,
},
recordFrom: { type: "string" },
},
name: "Record", // custom static name
primaryKey: "_id",
};
As above showed , name property appeared twice, although this won't caused unexpected behavior due to how js language works.
This pull request just checked if user defined custom static name, it will remove the default class name