Skip to content
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

Fixed babel plugin add extra name property #6282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

XHMM
Copy link

@XHMM XHMM commented Nov 26, 2023

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
  • 📝 Compatibility label 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
  • 💥 Breaking label has been applied or is not necessary

@XHMM
Copy link
Author

XHMM commented Nov 26, 2023

There is no doc for how to running test locally and I am not familier with wireit, so I skipped writing tests :(

@kraenhansen
Copy link
Member

@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 --recursive
  • npm install
  • npm test --workspace @realm/babel-plugin

@XHMM
Copy link
Author

XHMM commented Dec 21, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants