jgm / djot.js

JavaScript implementation of djot
MIT License
146 stars 16 forks source link

Footnote #2

Closed mandolyte closed 1 year ago

mandolyte commented 1 year ago

Looks like a bug related to backlinks snuck into the main branch:

$ yarn test
yarn run v1.22.19
$ jest
 PASS  src/find.spec.ts
 PASS  src/filter.spec.ts
 PASS  src/inline.spec.ts
 PASS  src/block.spec.ts
 PASS  src/ast.spec.ts
 PASS  src/pathological.spec.ts
 PASS  src/html.spec.ts
 PASS  src/attributes.spec.ts
 FAIL  src/functional.spec.ts
  ● test/footnotes.test › line 1

    ReferenceError: structuredClone is not defined

      108 |
      109 |   addBacklink(orignote: Footnote, ident: number): Footnote {
    > 110 |     const note = structuredClone(orignote); // we modify a deep copy
          |                  ^
      111 |     const backlink: Link = {
      112 |       tag: "link",
      113 |       destination: `#fnref${ident}`,

      at HTMLRenderer.addBacklink (src/html.ts:110:18)
      at HTMLRenderer.render (src/html.ts:481:27)
      at renderHTML (src/html.ts:494:19)
      at Object.<anonymous> (src/functional.spec.ts:128:30)

Test Suites: 1 failed, 8 passed, 9 total
Tests:       1 failed, 309 passed, 310 total
Snapshots:   0 total
Time:        3.961 s, estimated 4 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ 

Edit: after rebuilding from scratch, I get different failures.

jgm commented 1 year ago

Looks like structuredClone is only available on node >= 17. You can upgrade node and then it should work.

I'm not sure whether this is a reason to avoid using structuredClone, which seems to be supported in all major browsers.

mandolyte commented 1 year ago

Thanks @jgm - that worked. Maybe specify this in the readme for those using command line.

jgm commented 1 year ago

I added a restriction in package.json and .npmrc.