File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ function sum(a, b) {
44 return a + b ;
55}
66
7+ class ConstructorWithNamedParams {
8+ constructor ( a , { b= 1 , c= 2 } ) {
9+ this . sum = a + b + c ;
10+ }
11+ }
712
813export function main ( ) {
914 describe ( 'functions' , function ( ) {
@@ -35,6 +40,11 @@ export function main() {
3540 expect ( f ( { a : 10 } ) ) . toBe ( 12 ) ;
3641 expect ( f ( ) ) . toBe ( 3 ) ;
3742 } ) ;
43+
44+ it ( "should support new expressions" , function ( ) {
45+ var obj = new ConstructorWithNamedParams ( 100 , { b :10 } ) ;
46+ expect ( obj . sum ) . toEqual ( 112 ) ;
47+ } ) ;
3848 } ) ;
3949
4050 describe ( "optional params" , function ( ) {
Original file line number Diff line number Diff line change @@ -32,11 +32,27 @@ export class NamedParamsTransformer extends ParseTreeTransformer {
3232 */
3333 transformCallExpression ( tree ) {
3434 tree = super . transformCallExpression ( tree ) ;
35+ this . _handleNamedParams ( tree ) ;
36+ return tree ;
37+ }
38+
39+ /**
40+ * Transform new expressions.
41+ *
42+ * @param {NewExpression } tree
43+ * @return {ParseTree }
44+ */
45+ transformNewExpression ( tree ) {
46+ tree = super . transformNewExpression ( tree ) ;
47+ this . _handleNamedParams ( tree ) ;
48+ return tree ;
49+ }
50+
51+ _handleNamedParams ( tree ) {
3552 if ( this . _isLastArgAnNonEmptyObjectLiteral ( tree ) &&
3653 ! this . _isLastArgObjectLiteralWithQuotedKeys ( tree ) ) {
3754 this . _replaceLastArgWithNamedParams ( tree ) ;
3855 }
39- return tree ;
4056 }
4157
4258 _isLastArgAnNonEmptyObjectLiteral ( tree ) {
You can’t perform that action at this time.
0 commit comments