From 441d9c8cc0795ef9f27648e54aa5f612599048af Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 25 Oct 2020 12:27:07 +0100 Subject: [PATCH] Change `src/core/{glyphlist, unicode}.js` to use standard `import`/`export` statements While the *built* `pdf.worker.js` file still works correctly with these changes, despite these two files being excluded by Babel[1], the development viewer does not because of issues with SystemJS[2] and/or its Babel-plugin (both of which are old). Furthermore, note also that excluding these two files from Babel-processing isn't *generally* necessary since e.g. the `gulp mozcentral` command works anyway. The explanation is rather that it's actually the source-map generation which fails for these huge sequences when building the `pdf.worker.js` file. However, not using standard `import`/`export` statements in all files means we also need to use SystemJS when e.e. running the unit-tests. This is very unfortunate, since SystemJS (or its old Babel-version) doesn't support modern ECMAScript features such as e.g. optional chaining and nullish coalescing. Unfortunately it also seems that https://bugzilla.mozilla.org/show_bug.cgi?id=1247687, which tracks the implementation of worker-modules in Firefox, has stalled since there hasn't been any updates for six months now. To hopefully address all of the above, this patch is the first in a series that attempts to further reduce our reliance on SystemJS. --- [1] The only difference being how the dependencies are handled, in the Webpack-bundled file. [2] Parsing takes way too long and consumes too much memory, thus rendering the development viewer essentially unusable. --- src/core/glyphlist.js | 5 ++--- src/core/unicode.js | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/glyphlist.js b/src/core/glyphlist.js index 2bf4423a8..071d3ee8d 100644 --- a/src/core/glyphlist.js +++ b/src/core/glyphlist.js @@ -15,7 +15,7 @@ /* no-babel-preset */ /* eslint-disable no-var */ -var getLookupTableFactory = require("./core_utils.js").getLookupTableFactory; +import { getLookupTableFactory } from "./core_utils.js"; var getGlyphsUnicode = getLookupTableFactory(function (t) { t.A = 0x0041; @@ -4550,5 +4550,4 @@ var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) { t[".notdef"] = 0x0000; }); -exports.getGlyphsUnicode = getGlyphsUnicode; -exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode; +export { getGlyphsUnicode, getDingbatsGlyphsUnicode }; diff --git a/src/core/unicode.js b/src/core/unicode.js index 118a713b1..043b8c097 100644 --- a/src/core/unicode.js +++ b/src/core/unicode.js @@ -15,7 +15,7 @@ /* no-babel-preset */ /* eslint-disable no-var */ -var getLookupTableFactory = require("./core_utils.js").getLookupTableFactory; +import { getLookupTableFactory } from "./core_utils.js"; // Some characters, e.g. copyrightserif, are mapped to the private use area // and might not be displayed using standard fonts. Mapping/hacking well-known @@ -1635,8 +1635,10 @@ function reverseIfRtl(chars) { return s; } -exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues; -exports.reverseIfRtl = reverseIfRtl; -exports.getUnicodeRangeFor = getUnicodeRangeFor; -exports.getNormalizedUnicodes = getNormalizedUnicodes; -exports.getUnicodeForGlyph = getUnicodeForGlyph; +export { + mapSpecialUnicodeValues, + reverseIfRtl, + getUnicodeRangeFor, + getNormalizedUnicodes, + getUnicodeForGlyph, +};