aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-11-07 12:43:27 +0200
committerMihai Bazon <mihai@bazon.net>2012-11-07 12:43:27 +0200
commit5276a4a873d174ae594198045a15cb821cca29e7 (patch)
tree7938bf9d9ba815dd16b1f170858fa2be9a37f78c
parenta1ae0c8609ad5ab977dae8afcb96b04594a0cc9a (diff)
downloadtracifyjs-5276a4a873d174ae594198045a15cb821cca29e7.tar.gz
tracifyjs-5276a4a873d174ae594198045a15cb821cca29e7.zip
add AST_Accessor and AST_SymbolAccessor node types
AST_Accessor will represent the function for a setter or getter. Since they are not mangleable, and they should not introduce a name in scope, we have a new node for their name (AST_SymbolAccessor) which doesn't inherit from AST_SymbolDeclaration. fix #37
-rw-r--r--lib/ast.js8
-rw-r--r--lib/parse.js6
-rw-r--r--lib/scope.js12
3 files changed, 19 insertions, 7 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 32ec5380..d55ec223 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -345,6 +345,10 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
}
}, AST_Scope);
+var AST_Accessor = DEFNODE("Accessor", null, {
+ $documentation: "A setter/getter function"
+}, AST_Lambda);
+
var AST_Function = DEFNODE("Function", null, {
$documentation: "A function expression"
}, AST_Lambda);
@@ -758,6 +762,10 @@ var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
$documentation: "Base class for all symbols",
});
+var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
+ $documentation: "The name of a property accessor (setter/getter function)"
+}, AST_Symbol);
+
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
$propdoc: {
diff --git a/lib/parse.js b/lib/parse.js
index ea9eba50..ffdd7a53 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -883,6 +883,8 @@ function parse($TEXT, options) {
var function_ = function(in_statement, ctor) {
var name = is("name") ? as_symbol(in_statement
? AST_SymbolDefun
+ : ctor === AST_Accessor
+ ? AST_SymbolAccessor
: AST_SymbolLambda) : null;
if (in_statement && !name)
unexpected();
@@ -1158,7 +1160,7 @@ function parse($TEXT, options) {
a.push(new AST_ObjectGetter({
start : start,
key : name,
- value : function_(false, AST_Lambda),
+ value : function_(false, AST_Accessor),
end : prev()
}));
continue;
@@ -1167,7 +1169,7 @@ function parse($TEXT, options) {
a.push(new AST_ObjectSetter({
start : start,
key : name,
- value : function_(false, AST_Lambda),
+ value : function_(false, AST_Accessor),
end : prev()
}));
continue;
diff --git a/lib/scope.js b/lib/scope.js
index 27cd5259..f8a1cb8b 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -312,6 +312,11 @@ AST_Symbol.DEFMETHOD("unmangleable", function(options){
return this.definition().unmangleable(options);
});
+// property accessors are not mangleable
+AST_SymbolAccessor.DEFMETHOD("unmangleable", function(){
+ return true;
+});
+
// labels are always mangleable
AST_Label.DEFMETHOD("unmangleable", function(){
return false;
@@ -363,12 +368,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
}
if (node instanceof AST_Scope) {
var p = tw.parent();
- var is_setget = p instanceof AST_ObjectSetter || p instanceof AST_ObjectGetter;
node.variables.each(function(symbol){
- if (!(is_setget && symbol instanceof AST_SymbolLambda)) {
- if (options.except.indexOf(symbol.name) < 0) {
- to_mangle.push(symbol);
- }
+ if (options.except.indexOf(symbol.name) < 0) {
+ to_mangle.push(symbol);
}
});
return;