Skip to content

Commit

Permalink
More ASI, object literal and call expression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rspivak committed May 7, 2011
1 parent 2fe52bc commit 3af5711
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/slimit/tests/test_ecmavisitor.py
Expand Up @@ -329,17 +329,20 @@ def setUp(self):
# test 36
'foo();',
'foo(x, 7);',
'foo()[10];',
# test 39
'foo().foo;',

################################
# misc
################################

# new
'var foo = new Foo();',
# test 39
# dot accessor
'var bar = new Foo.Bar();',

# test 42
# bracket accessor
'var bar = new Foo.Bar()[7];',

Expand All @@ -350,32 +353,36 @@ def setUp(self):
bar: 20
};
""",
# test 42
"""
var obj = {
1: 'a',
2: 'b'
};
""",
# test 45
"""
var obj = {
'a': 100,
'b': 200
};
""",
"""
var obj = {
};
""",

# array
"""
var a = [1,2,3,4,5];
var res = a[3];
""",
# test 45
# test 48
# elision
'var a = [,,,];',
'var a = [1,,,4];',
'var a = [1,,3,,5];',

# test 48
# test 51
"""
String.prototype.foo = function(data) {
var tmpl = this.toString();
Expand Down Expand Up @@ -445,6 +452,15 @@ class ASITestCase(unittest.TestCase):
return;
a;
"""),

# expression is not optional in throw statement
("""
throw
'exc';
""",
"""
'exc';
"""),
]

for index, (input, expected) in enumerate(ASITestCase.TEST_CASES):
Expand Down
4 changes: 3 additions & 1 deletion src/slimit/visitors/ecmavisitor.py
Expand Up @@ -309,7 +309,9 @@ def visit_Object(self, node):
s += ',\n'.join(self._make_indent() + self.visit(prop)
for prop in node.properties)
self.indent_level -= 2
s += '\n}'
if node.properties:
s += '\n'
s += self._make_indent() + '}'
return s

def visit_Array(self, node):
Expand Down

0 comments on commit 3af5711

Please sign in to comment.