Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Sep 24, 2017
1 parent cd7cdb0 commit 187231c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions src/index.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ensureConstructor, bindMethodsInConstructor, bindMethods } from "./clas
import * as matching from "./match";
import * as comprehension from "./comprehension";
import { transformExistentialExpression } from "./safe";
import { replaceWithInlinedOperator } from "./inlinedOperators";
import { maybeReplaceWithInlinedOperator } from "./inlinedOperators";
import { transformForInArrayStatement, transformForInObjectStatement, lintForInArrayStatement, lintForInObjectStatement } from "./for";
import { resetHelpers } from "./helpers";
import { markIdentifier } from "./stdlib";
Expand Down Expand Up @@ -91,11 +91,9 @@ Lightscript(babel) ->
else:
comprehension.transformPlainObjectComprehension(path)

CallExpression: {
exit(path): void ->
{ node } = path
if replaceWithInlinedOperator(path, node.callee, node.arguments): return
}
CallExpression(path): void ->
{ node } = path
maybeReplaceWithInlinedOperator(path, node.callee, node.arguments)

NamedArrowFunction(path): void ->
if (path.node.skinny):
Expand Down Expand Up @@ -174,10 +172,11 @@ Lightscript(babel) ->
exit(path): void ->
addImplicitReturns(path)

// As this is an exit visitor, other LSC transforms have reduced
// arrows to plain FunctionDeclarations by this point.
if path.node.type === "FunctionDeclaration":
// somehow this wasn't being done... may signal deeper issues...
// This is needed because named arrow declarations are new in
// Lightscript and therefore not acknowledged by Babel's default
// traversal algorithm for assessing declarations. We must
// register the declaration by hand here.
path.getFunctionParent().scope.registerDeclaration(path)
}

Expand Down
2 changes: 1 addition & 1 deletion src/inlinedOperators.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inlinedOperator = {
export getInlinedOperatorsEnabled(opts) ->
not ((opts.stdlib === false) or (typeof opts.stdlib === "object" && opts.stdlib.lightscript === false))

export replaceWithInlinedOperator(path, callee, args) ->
export maybeReplaceWithInlinedOperator(path, callee, args) ->
if(
!(getCompilerState().inlinedOperatorsEnabled) or
callee.type !== "Identifier"
Expand Down
4 changes: 2 additions & 2 deletions src/safe.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ findReplacementPath(path) ->
else: true
)

replaceOptionals(path, replacementPath, loose = true): void ->
replaceOptionals(path, replacementPath): void ->
{ scope } = path
optionals = []
nil = scope.buildUndefinedNode()
Expand Down Expand Up @@ -87,7 +87,7 @@ replaceOptionals(path, replacementPath, loose = true): void ->

export maybeTransformSafe(path): void ->
if path.node.optional:
replaceOptionals(path, path~findReplacementPath(), true)
replaceOptionals(path, path~findReplacementPath())

export transformExistentialExpression(path) ->
path.replaceWith(
Expand Down

0 comments on commit 187231c

Please sign in to comment.