Skip to content

Commit

Permalink
toBlockArrowFunctionExpression now preserves skinny arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 2, 2017
1 parent 8315dda commit e2f3e68
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/functions.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export replaceWithArrowFunction(path) ->
path.replaceWith(toArrowFunction(path.node))

export toBlockArrowFunctionExpression(node) ->
let { params, body, async } = node
let { params, body, async, skinny } = node
fn = t.arrowFunctionExpression(params, body~toBlockStatement(), async)~atNode(node)
if skinny: fn.skinny = true
if node.returnType: fn.returnType = node.returnType
if node.typeParameters: fn.typeParameters = node.typeParameters

Expand Down
2 changes: 0 additions & 2 deletions src/safe.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import atNode from 'ast-loc-utils/lib/placeAtNode'
import { hoistRef, isSimple } from './ref'
import { isa } from './is'

import { getLoc, placeTreeAtLocWhenUnplaced as allAtLoc } from 'ast-loc-utils'

// Optional-replacement algorithm based on babel-plugin-transform-optional-chaining
// See https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-optional-chaining/src/index.js

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/safe-member-expression/this/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-> this?.a
3 changes: 3 additions & 0 deletions test/fixtures/safe-member-expression/this/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function () {
return this == null ? void 0 : this.a;
});

0 comments on commit e2f3e68

Please sign in to comment.