Closed fstrube closed 2 years ago
It might make sense to preallocate all the variables outside the switch, as that would have been the effective behaviour when babel transpiled to var
(due to hoisting) anyway.
@Pomax @blikblum I preallocated all the variables outside the switch as you suggested. The diff is much smaller, which is nice.
Any opportunity to move from scope-hoisting to block scoped vars is a good opportunity I'd say, but I'll let @devongovett decide whether that's something he would like to see in this PR.
Hi @devongovett, would you mind taking a look at this? It is causing most of our pdfkit projects that rely on OTF fonts to fail. I'm hoping we can get this merged in soon, then get https://github.com/foliojs/pdfkit/pull/1367 updated and merged as well.
It is possible to make a new release with this PR ? The latest version is 2.0.2, released on June 19 2022 before this PR, so the error
ReferenceError: Cannot access 'c3x' before initialization
still occurs (for example with the font PlayfairDisplay-Regular.otf
found in /test/data/PlayfairDisplay
).
Thanks in advance!
Fixes #282.
This branch fixes a ReferenceError that gets thrown when parsing certain fonts, including the Playfair Display font that is in the fontkit repository. The error started happening when version 1.9.0 of fontkit was released.
The fix involved refactoring the
parse()
function to use block-scoping inside the switch case statements in that function. See the MDN docs on redeclarations.