diff options
author | Samuel Reed <samuel.trace.reed@gmail.com> | 2016-01-19 13:12:32 -0600 |
---|---|---|
committer | Samuel Reed <samuel.trace.reed@gmail.com> | 2016-01-19 13:23:02 -0600 |
commit | 8b71c6559b0e1773bb3455c68701ff512fc18277 (patch) | |
tree | a92525212a315a818ade6a763ec39148c5e09509 /lib | |
parent | 57e0fafd5c35552fb1ea63c829a7f6ea7000b6f8 (diff) | |
download | tracifyjs-8b71c6559b0e1773bb3455c68701ff512fc18277.tar.gz tracifyjs-8b71c6559b0e1773bb3455c68701ff512fc18277.zip |
Mark vars with /** @const */ pragma as consts so they can be eliminated.
Fixes older browser support for consts and allows more flexibility
in dead code removal.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/scope.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/scope.js b/lib/scope.js index 5e93020f..22fb150d 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -154,7 +154,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ else if (node instanceof AST_SymbolVar || node instanceof AST_SymbolConst) { var def = defun.def_variable(node); - def.constant = node instanceof AST_SymbolConst; + def.constant = node instanceof AST_SymbolConst || node.has_const_pragma(); def.init = tw.parent().value; } else if (node instanceof AST_SymbolCatch) { @@ -357,6 +357,16 @@ AST_Symbol.DEFMETHOD("global", function(){ return this.definition().global; }); +AST_Symbol.DEFMETHOD("has_const_pragma", function() { + var token = this.scope.body[0] && this.scope.body[0].start; + var comments = token && token.comments_before; + if (comments && comments.length > 0) { + var last = comments[comments.length - 1]; + return /@const/.test(last.value); + } + return false; +}) + AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){ return defaults(options, { except : [], |