Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

TypeScript syntax incorrectly used in JavaScript file #3935

Closed
dancingfrog opened this issue Nov 9, 2021 · 4 comments
Closed

TypeScript syntax incorrectly used in JavaScript file #3935

dancingfrog opened this issue Nov 9, 2021 · 4 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@dancingfrog
Copy link

  • Version:
    0.11.1

  • Platform:
    Linux localhost.localdomain 5.8.15-301.fc33.x86_64 (Fedora 33)

  • Subsystem:

Severity:

Medium

Description:

Initially I read this as a typo on line 75 of packages/ipfs-http-gateway/src/index.js :

const gatewayAddrs = addresses?.Gateway || []

,.. and tried to correct this with pull request #3918
Through discussion on that request, it now appears that the author attempted to use valid TypeScript syntax within a JavaScript file. This is not valid JavaScript syntax and this code will throw an error in certain contexts.

Steps to reproduce the error:

The simplest way to reproduce this error is to install ipfs in a project using npm and then run:

$ node node_modules/.bin/jsipfs
(node:28639) ExperimentalWarning: The ESM module loader is experimental.
file:///home/revlin/Public/node_modules/ipfs-http-gateway/esm/src/index.js:44
    const gatewayAddrs = addresses?.Gateway || [];
                                   ^

SyntaxError: Unexpected token '.'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:117:18)
@dancingfrog dancingfrog added the need/triage Needs initial labeling and prioritization label Nov 9, 2021
@welcome
Copy link

welcome bot commented Nov 9, 2021

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@dancingfrog
Copy link
Author

dancingfrog commented Nov 9, 2021

The pull request reviewer also mentioned that this same TypeScript syntax is used in other JS files in this project. So, this pattern seems have become a convention within this project, but all of these files contain errors if directly evaluated as JavaScript, either via node or import into another JavaScript context.

#3918 (comment)

@achingbrain
Copy link
Member

achingbrain commented Nov 9, 2021

That operator is called the optional chaining operator. It's not TypeScript (see the MDN link), but is only supported by node 14+. Are you using an older version?

@dancingfrog
Copy link
Author

Thanks @achingbrain . As you can see in the reviewer's comment linked above, Optional Chaining was explained by way of a link to the TypeScript Language page, implying that the syntax of that file (and others) was intended to be TypeScript.

Yes, I'm using Node ~12 because that had the widest adoption on different cloud compute platforms up until recently (AWS Lambda did not adopt Node 14+ until this year).

I will consider upgrading in order to make use of js-ipfs without major revisions to the source. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

2 participants