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

Default parameters is missing #7

Open
azu opened this issue Jul 29, 2016 · 1 comment
Open

Default parameters is missing #7

azu opened this issue Jul 29, 2016 · 1 comment

Comments

@azu
Copy link
Member

azu commented Jul 29, 2016

espurify ignore .default property by default.
Is it expected bahavior?

"use strict";
const esprima = require("esprima");
const escodegen = require("escodegen");
const espurify = require('espurify');

var code = `function addPrefix(text, prefix = "Default:") {
                return prefix + text;
            }`;
const jsAst = esprima.parse(code);
const modifiedAst = espurify(jsAst);
console.log(escodegen.generate(modifiedAst));
/*
 function addPrefix(text, prefix) { // <= no default parameter
     return prefix + text;
 }
 */
@twada
Copy link
Member

twada commented Jul 29, 2016

espurify is intended to be compliant with The ESTree Spec.
defaults properly of Function(Declaration|Expression) is not in the spec, so it is discarded by default.

If you want to purify non-complient tree, please use espurify.cloneWithWhitelist function.

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

No branches or pull requests

2 participants