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

ReferenceError: Cannot access 'c3x' before initialization #282

Closed
fstrube opened this issue Jun 22, 2022 · 1 comment · Fixed by #286
Closed

ReferenceError: Cannot access 'c3x' before initialization #282

fstrube opened this issue Jun 22, 2022 · 1 comment · Fixed by #286

Comments

@fstrube
Copy link
Contributor

fstrube commented Jun 22, 2022

Version 1.9.0-2.0.2 introduced a regression in the parse() function. I'm getting the following error and stack trace with the attached OTF font. It works fine in 1.8.1.

/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:11520
                                    c3x = c2x + stack.shift();
                                        ^

ReferenceError: Cannot access 'c3x' before initialization
    at parse (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:11520:41)
    at $7ee0705195f3b047$export$2e2bcd8739ae039._getPath (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:11570:9)
    at $7ee0705195f3b047$export$2e2bcd8739ae039.get path (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:10750:21)
    at $7ee0705195f3b047$export$2e2bcd8739ae039.descriptor.get (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:92:29)
    at $7ee0705195f3b047$export$2e2bcd8739ae039._getCBox (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:10685:21)
    at $7ee0705195f3b047$export$2e2bcd8739ae039.get cbox (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:10735:21)
    at $7ee0705195f3b047$export$2e2bcd8739ae039.descriptor.get (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:92:29)
    at $7ee0705195f3b047$export$2e2bcd8739ae039._getMetrics (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:10706:72)
    at $7ee0705195f3b047$export$2e2bcd8739ae039.get advanceWidth (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:10764:21)
    at $7ee0705195f3b047$export$2e2bcd8739ae039.descriptor.get (/test-fontkit/2.0.2/node_modules/fontkit/dist/main.cjs:92:29)

KeplerStd-Bold.otf.zip

Use the following repo to reproduce: https://github.com/fstrube/fontkit-test

fstrube added a commit to fstrube/fontkit that referenced this issue Jul 7, 2022
fstrube added a commit to fstrube/fontkit that referenced this issue Jul 7, 2022
fstrube added a commit to fstrube/fontkit that referenced this issue Jul 7, 2022
@fstrube
Copy link
Contributor Author

fstrube commented Jul 8, 2022

@devongovett

After a bit of digging, the breaking change occurred in 1.9.0 because the build was switched from Babel to Parcel. The ReferenceError is due to a situation that arises when using let declarations inside a switch statement (see the MDN reference for let declarations).

In 1.8.1 and earlier, Babel transpiled let declarations to var declarations, so a ReferenceError was not thrown. But now, with Parcel building the code, the let declarations are left intact, thus the introduction of the ReferenceError.

I've submitted a fix in PR #286

fstrube added a commit to fstrube/fontkit that referenced this issue Jul 12, 2022
…ch, so as to mimic the old behavior when Babel would transpile `let` to `var`. See foliojs#282.
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 a pull request may close this issue.

1 participant