Unverified Commit d1b1171c authored by Hong Minhee's avatar Hong Minhee
Browse files

Fixed bug where calling super.fromJsonLd expands

parent 12b4c80c
Loading
Loading
Loading
Loading
+154 −198

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -295,8 +295,7 @@ export async function* generateDecoder(
  for (const subtypeUri of subtypes) {
    yield `
    if (values["@type"].includes(${JSON.stringify(subtypeUri)})) {
      delete values["@type"];
      return await ${types[subtypeUri].name}.fromJsonLd(values, options);
      return await ${types[subtypeUri].name}.fromJsonLd(json, options);
    }
    `;
  }
@@ -315,6 +314,7 @@ export async function* generateDecoder(
    `;
  } else {
    yield `
    delete values["@type"];
    const instance = await super.fromJsonLd(values, {
      ...options,
      // @ts-ignore: an internal option
+7 −2
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ test("Object.fromJsonLd()", async () => {
    new LanguageString("你好", "zh"),
  ]);

  const create = await Object.fromJsonLd({
  const createJsonLd = {
    "@context": "https://www.w3.org/ns/activitystreams",
    "type": "Create",
    "name": "Test",
@@ -156,13 +156,18 @@ test("Object.fromJsonLd()", async () => {
      "type": "Note",
      "content": "Content",
    },
  }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader });
  };
  const create = await Object.fromJsonLd(
    createJsonLd,
    { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader },
  );
  assertInstanceOf(create, Create);
  assertEquals(create.name, "Test");
  assertEquals(create.contents, [
    new LanguageString("Hello", "en"),
    new LanguageString("你好", "zh"),
  ]);
  assertEquals(await create.toJsonLd(), createJsonLd);
  const note = await create.getObject();
  assertInstanceOf(note, Note);
  assertEquals(note.content, "Content");