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

Declare variables with let for module code, but var in the Node REPL #17

Open
benjamn opened this issue May 13, 2016 · 1 comment
Open
Assignees
Milestone

Comments

@benjamn
Copy link
Owner

benjamn commented May 13, 2016

Using let to declare imported variables in compiled code allows the variables to be scoped to the enclosing block, and enables warnings about redeclarations of identically-named variables:

if (process.env.NODE_ENV === "production") {
  import { S3 } from "aws-sdk";
  let s3 = new S3();
  s3.abortMultipartUpload(params, function (err, data) { ... });
}
// S3 and s3 should not be visible here!

Currently the import statement is compiled to

var S3;module.import("aws-sdk",{S3:function(v){S3=v}});

The use of var means the S3 variable will be visible anywhere in the enclosing function scope, which is dangerous if process.env.NODE_ENV !== "production".

Ideally (when possible) we would like to use let instead:

let S3;module.import("aws-sdk",{S3:function(v){S3=v}});

Note that const is not an option because imported symbols must be able to change their values whenever the source module gets around to exporting them.

However, using let in the Node REPL means you can't import the same symbol more than once, which can be really annoying. For that reason, when you require("reify/repl"), the compiler should generate var declarations instead (as it currently does).

@jdalton
Copy link
Contributor

jdalton commented May 16, 2017

This is configurable now.
Will this be resolved with the option.repl work or is it already resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants