Skip to content

Commit

Permalink
Eliminate TildeCallExpression node type
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Sep 24, 2017
1 parent f2c3328 commit 2766ce4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
9 changes: 0 additions & 9 deletions src/index.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ Lightscript(babel) ->
else:
comprehension.transformPlainObjectComprehension(path)

TildeCallExpression: {
enter(path): void ->
{ node } = path
args = [ node.left, ...node.arguments ]
callExpr = t.callExpression(node.right, args)~atNode(node)
if node.optional: callExpr.optional = true
path.replaceWith(callExpr)
}

CallExpression: {
enter(path): void ->
maybeTransformSafe(path)
Expand Down
20 changes: 0 additions & 20 deletions src/lscNodeTypes.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,6 @@ export registerLightscriptNodeTypes(t): void ->
}
})

if not t.hasType("TildeCallExpression"):
definePluginType("TildeCallExpression", {
visitor: ["left", "right", "arguments"],
aliases: ["CallExpression", "Expression"],
fields: {
left: {
validate: assertNodeType("Expression"),
},
right: {
validate: assertOneOf("Identifier", "MemberExpression"),
},
arguments: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Expression", "SpreadElement"))
),
},
},
});

if not t.hasType("NamedArrowDeclaration"):
definePluginType("NamedArrowDeclaration", {
builder: ["id", "params", "body", "skinny", "async", "generator"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ comment 4
*/
'use @oigroup/lightscript with safeCall';

(typeof a === 'function' ? a() : void 0).b;
typeof a !== 'function' ? void 0 : a().b;
10 changes: 5 additions & 5 deletions test/fixtures/safe-member-expression/calls-after/expected.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var _ref, _ref2, _ref3;
var _a$b, _a$b$c, _c;

a == null ? void 0 : a.b();

(_ref = a == null ? void 0 : a.b()) == null ? void 0 : _ref.c().d.e();
a == null ? void 0 : (_a$b = a.b()) == null ? void 0 : _a$b.c().d.e();

(_ref2 = a == null ? void 0 : a.b().c) == null ? void 0 : _ref2.d().e.f();
a == null ? void 0 : (_a$b$c = a.b().c) == null ? void 0 : _a$b$c.d().e.f();

a == null ? void 0 : c(a.b);
c(a == null ? void 0 : a.b);

(_ref3 = a == null ? void 0 : c(a.b)) == null ? void 0 : e(_ref3.d);
e((_c = c(a == null ? void 0 : a.b)) == null ? void 0 : _c.d);

0 comments on commit 2766ce4

Please sign in to comment.