Skip to content

Use optional chaining, where possible, in the web/-folder #12961

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

Merged
merged 2 commits into from
Feb 6, 2021

Conversation

Snuffleupagus
Copy link
Collaborator

  • Slightly re-factor how the BaseViewer/PDFThumbnailViewer handle page labels internally, to make the null default value clearer

    Currently it's not immediately clear from the code itself, unless you look at the definition of this._pageLabels, that the default value is null.[1]
    We can improve this, and also reduce the amount of code, by using modern ECMAScript features such as optional chaining and nullish coalescing.


    [1] Keep in mind that an empty string is actually a valid page label, according to the PDF specification.

  • Use optional chaining, where possible, in the web/-folder

    By using optional chaining, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining, it's possible to reduce unnecessary code-repetition in many cases.

…age labels internally, to make the `null` default value clearer

Currently it's not *immediately* clear from the code itself, unless you look at the definition of `this._pageLabels`, that the default value is `null`.[1]
We can improve this, and also reduce the amount of code, by using modern ECMAScript features such as optional chaining and nullish coalescing.

---
[1] Keep in mind that an *empty* string is actually a valid page label, according to the PDF specification.
By using optional chaining, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining, it's possible to reduce unnecessary code-repetition in many cases.
@Snuffleupagus Snuffleupagus changed the title Web optional chaining Use optional chaining, where possible, in the web/-folder Feb 5, 2021
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2021

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/ec1cbf2a7d622c5/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2021

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/ec1cbf2a7d622c5/output.txt

Total script time: 4.33 mins

Published

@timvandermeij timvandermeij merged commit 6263a21 into mozilla:master Feb 6, 2021
@timvandermeij
Copy link
Contributor

Looks good; thanks!

@Snuffleupagus Snuffleupagus deleted the web-optional-chaining branch February 6, 2021 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants