Unverified Commit 0aadf31b authored by Hong Minhee's avatar Hong Minhee
Browse files

Fix clone() bug where it does not copy id

parent cf6392ea
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ Version 0.9.1

To be released.

 -  Fixed a bug of Activity Vocabulary API that `clone()` method of Vocabulary
    classes had not cloned the `id` property from the source object.


Version 0.9.0
-------------
+20 −5
Original line number Diff line number Diff line
@@ -449,7 +449,10 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
  ): Object {
  
    // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
    const clone: Object = new this.constructor({ id: values.id }, options);
    const clone: Object = new this.constructor(
      { id: values.id ?? this.id },
      options
    );
    clone.#_49BipA5dq9eoH8LX8xdsVumveTca = this.#_49BipA5dq9eoH8LX8xdsVumveTca;
        if (\\"attachments\\" in values &&             values.attachments != null) {
      
@@ -4292,7 +4295,10 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;}
  ): PropertyValue {
  
    // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
    const clone: PropertyValue = new this.constructor({ id: values.id }, options);
    const clone: PropertyValue = new this.constructor(
      { id: values.id ?? this.id },
      options
    );
    clone.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav = this.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav;
        if (\\"name\\" in values &&             values.name != null) {
          clone.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav = [values.name];
@@ -4609,7 +4615,10 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi
  ): CryptographicKey {
  
    // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
    const clone: CryptographicKey = new this.constructor({ id: values.id }, options);
    const clone: CryptographicKey = new this.constructor(
      { id: values.id ?? this.id },
      options
    );
    clone.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2 = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2;
        if (\\"owner\\" in values &&             values.owner != null) {
          clone.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2 = [values.owner];
@@ -10935,7 +10944,10 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint
  ): Endpoints {
  
    // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
    const clone: Endpoints = new this.constructor({ id: values.id }, options);
    const clone: Endpoints = new this.constructor(
      { id: values.id ?? this.id },
      options
    );
    clone.#_2JCYDbSxEHCCLdBYed33cCETfGyR = this.#_2JCYDbSxEHCCLdBYed33cCETfGyR;
        if (\\"proxyUrl\\" in values &&             values.proxyUrl != null) {
          clone.#_2JCYDbSxEHCCLdBYed33cCETfGyR = [values.proxyUrl];
@@ -13609,7 +13621,10 @@ names?: (string | LanguageString)[];language?: LanguageTag | null;height?: numbe
  ): Link {
  
    // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
    const clone: Link = new this.constructor({ id: values.id }, options);
    const clone: Link = new this.constructor(
      { id: values.id ?? this.id },
      options
    );
    clone.#_pVjLsybKQdmkjuU7MHjiVmNnuj7 = this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7;
        if (\\"href\\" in values &&             values.href != null) {
          clone.#_pVjLsybKQdmkjuU7MHjiVmNnuj7 = [values.href];
+4 −1
Original line number Diff line number Diff line
@@ -154,7 +154,10 @@ export async function* generateCloner(
  if (type.extends == null) {
    yield `
    // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
    const clone: ${type.name} = new this.constructor({ id: values.id }, options);
    const clone: ${type.name} = new this.constructor(
      { id: values.id ?? this.id },
      options
    );
    `;
  } else {
    yield `const clone = super.clone(values, options) as unknown as ${type.name};`;
+92 −2

File changed.

Preview size limit exceeded, changes collapsed.

+26 −0
Original line number Diff line number Diff line
@@ -52,6 +52,32 @@ Deno.test("new Object()", () => {
  );
});

Deno.test("Object.clone()", () => {
  const obj = new Object({
    id: new URL("https://example.com/"),
    name: "Test",
    contents: [
      new LanguageString("Hello", "en"),
      new LanguageString("你好", "zh"),
    ],
  });

  const clone = obj.clone({ content: "Modified" });
  assertInstanceOf(clone, Object);
  assertEquals(clone.id, new URL("https://example.com/"));
  assertEquals(clone.name, "Test");
  assertEquals(clone.content, "Modified");

  const cloned2 = obj.clone({ id: new URL("https://example.com/modified") });
  assertInstanceOf(cloned2, Object);
  assertEquals(cloned2.id, new URL("https://example.com/modified"));
  assertEquals(cloned2.name, "Test");
  assertEquals(cloned2.contents, [
    new LanguageString("Hello", "en"),
    new LanguageString("你好", "zh"),
  ]);
});

Deno.test("Object.fromJsonLd()", async () => {
  const obj = await Object.fromJsonLd({
    "@context": "https://www.w3.org/ns/activitystreams",