From 61705e4d22bb5c6ec0ee4a1057cef06ba8a59ae4 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 23 Dec 2010 12:57:27 -0800 Subject: [PATCH] Issue #964. Super should trigger an implicit call. --- lib/rewriter.js | 2 +- src/grammar.coffee | 6 ++---- src/rewriter.coffee | 2 +- test/test_classes.coffee | 6 ++++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/rewriter.js b/lib/rewriter.js index 8c496edc..01f52410 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -373,7 +373,7 @@ } EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END); IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS']; - IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', '@', '->', '=>', '[', '(', '{', '--', '++']; + IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++']; IMPLICIT_UNSPACED_CALL = ['+', '-']; IMPLICIT_BLOCK = ['->', '=>', '{', '[', ',']; IMPLICIT_END = ['POST_IF', 'FOR', 'WHILE', 'UNTIL', 'WHEN', 'BY', 'LOOP', 'TERMINATOR', 'INDENT']; diff --git a/src/grammar.coffee b/src/grammar.coffee index 4e783672..cb880188 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -290,10 +290,8 @@ grammar = Invocation: [ o 'Value OptFuncExist Arguments', -> new Call $1, $3, $2 o 'Invocation OptFuncExist Arguments', -> new Call $1, $3, $2 - o 'SUPER', -> - new Call 'super', [new Splat new Literal 'arguments'] - o 'SUPER Arguments', -> - new Call 'super', $2 + o 'SUPER', -> new Call 'super', [new Splat new Literal 'arguments'] + o 'SUPER Arguments', -> new Call 'super', $2 ] # An optional existence check on a function. diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 0a36e9f4..30a1542e 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -321,7 +321,7 @@ IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@ # If preceded by an `IMPLICIT_FUNC`, indicates a function invocation. IMPLICIT_CALL = [ 'IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS' - 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', + 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', 'SUPER' '@', '->', '=>', '[', '(', '{', '--', '++' ] diff --git a/test/test_classes.coffee b/test/test_classes.coffee index 0ca80708..80b73cc3 100644 --- a/test/test_classes.coffee +++ b/test/test_classes.coffee @@ -39,17 +39,19 @@ ok result is '9two/three/four' ok (new ThirdChild).array.join(' ') is '1 2 3' +identity = (f) -> f + class TopClass constructor: (arg) -> @prop = 'top-' + arg class SuperClass extends TopClass constructor: (arg) -> - super 'super-' + arg + identity super 'super-' + arg class SubClass extends SuperClass constructor: -> - super 'sub' + identity super 'sub' ok (new SubClass).prop is 'top-super-sub'