espurify icon indicating copy to clipboard operation
espurify copied to clipboard

Default parameters is missing

Open azu opened this issue 9 years ago • 1 comments

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;
 }
 */
  • https://tonicdev.com/578c3e2bccf2c41300e5e6a7/579ab778edc3e41200ab1e31

azu avatar Jul 29 '16 01:07 azu

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.

twada avatar Jul 29 '16 03:07 twada