Browse Source

correctly rename children of conditional expressions

rewrite
Rich-Harris 8 years ago
parent
commit
bd01c0acb4
  1. 2
      src/ast/nodes/ConditionalExpression.js
  2. 2
      src/ast/scopes/Scope.js
  3. 3
      test/function/rename-conditional-expression-children/_config.js
  4. 2
      test/function/rename-conditional-expression-children/foo.js
  5. 3
      test/function/rename-conditional-expression-children/main.js

2
src/ast/nodes/ConditionalExpression.js

@ -54,9 +54,11 @@ export default class ConditionalExpression extends Node {
else if ( this.testValue ) { else if ( this.testValue ) {
code.remove( this.start, this.consequent.start ); code.remove( this.start, this.consequent.start );
code.remove( this.consequent.end, this.end ); code.remove( this.consequent.end, this.end );
this.consequent.render( code, es );
} else { } else {
code.remove( this.start, this.alternate.start ); code.remove( this.start, this.alternate.start );
code.remove( this.alternate.end, this.end ); code.remove( this.alternate.end, this.end );
this.alternate.render( code, es );
} }
} }
} }

2
src/ast/scopes/Scope.js

@ -1,5 +1,3 @@
import getLocation from '../../utils/getLocation.js';
import error from '../../utils/error.js';
import { blank, keys } from '../../utils/object.js'; import { blank, keys } from '../../utils/object.js';
import { UNKNOWN } from '../values.js'; import { UNKNOWN } from '../values.js';

3
test/function/rename-conditional-expression-children/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'correctly renders children of ConditionalExpressions'
};

2
test/function/rename-conditional-expression-children/foo.js

@ -0,0 +1,2 @@
export const bar = 42;
export const baz = 43;

3
test/function/rename-conditional-expression-children/main.js

@ -0,0 +1,3 @@
import * as foo from './foo.js';
assert.equal( true ? foo.bar : foo.baz, 42 );
Loading…
Cancel
Save