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

Implement default parameters for NodeJS #9497

Closed
apastuhov opened this issue Jul 3, 2016 · 2 comments
Closed

Implement default parameters for NodeJS #9497

apastuhov opened this issue Jul 3, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@apastuhov
Copy link

TypeScript Version: 1.8.10
NodeJS LTS Version: 4.4.7

I have a project, which I write for NodeJS. I use async/await so there is need to set tartget: es6. But when I wrote function(or lamba) with default parameter value, compiler work well, but NodeJS gave me an error.

TSConfig

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs"
    }
}

Code

function foo(bar = 1) {
    console.log(bar);
}
foo();

Expected behavior:

Output JS:

function foo(bar) {
    if (bar === void 0) { bar = 1; }
    console.log(bar);
}
foo();

Display 1 as output.

Actual behavior:

Output JS:

function foo(bar = 1) {
    console.log(bar);
}
foo();

Run this code with NodeJS (v5.7.0) and get the error:

function foo(bar = 1) {
                          ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:141:18)
    at node.js:933:3

Assumption:

It would be great to set default parameters values via if for NodeJS, in case that problem occurs on NodeJS LTS.

@vladima
Copy link
Contributor

vladima commented Jul 3, 2016

Default parameters in node are available under a flag --harmony-default-parameters and eventually should be enabled by default.

@DanielRosenwasser
Copy link
Member

I'll point out that we have #4692 which covers granular targeting for certain feature sets, so I'm going to close in favor of that.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jul 3, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants