Skip to content

Commit

Permalink
Merge pull request #79 from fink-lang/cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
kollhof authored Sep 27, 2020
2 parents 318d575 + 7d8a7f4 commit b1ca406
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 140 deletions.
96 changes: 48 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@
}
},
"devDependencies": {
"@fink/cli": "^6.2.0",
"@fink/jest": "^5.2.0",
"@fink/cli": "^6.2.1",
"@fink/jest": "^5.3.0",
"@fink/larix": "^12.2.1",
"@fink/loxia": "^12.2.0",
"@fink/loxia": "^12.2.1",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.1.0",
"jest-cli": "^26.1.0",
"npx-run": "^2.1.2",
"semantic-release": "^17.1.1"
"semantic-release": "^17.1.2"
},
"dependencies": {
"@babel/core": "^7.10.5",
"@babel/traverse": "^7.10.5",
"@babel/types": "^7.10.5",
"@fink/js-interop": "^1.1.0",
"@fink/std-lib": "^4.0.0"
"@fink/js-interop": "^1.1.1",
"@fink/std-lib": "^4.0.1"
}
}
4 changes: 2 additions & 2 deletions src/index.fnk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{default: traverse} = import '@babel/traverse'
{transformFromAstSync} = import '@babel/core'
{length} = import '@fink/std-lib/iter'
{is_empty} = import '@fink/std-lib/iter'

{transform_ast} = import './lang'

Expand All @@ -17,7 +17,7 @@ transform = fn node, code, filename, options:
else: {}

match ast:
{errors: 0 == length ?}:
{errors: is_empty ?}:
traverse ast, dict:
DoExpression: transform_do_expr
AwaitExpression: {enter: transform_async}
Expand Down
14 changes: 7 additions & 7 deletions src/js/do-expression.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
isReturnStatement, arrowFunctionExpression, callExpression
} = import '@babel/types'
{set_props} = import '@fink/js-interop/reflect'
{length} = import '@fink/std-lib/iter'
{is_empty} = import '@fink/std-lib/iter'
{wrap_with_comment_loc} = import '../lang/comments'


Expand All @@ -25,7 +25,7 @@ simple = fn body, sl=false:
[stmnt, ...rest] = get_body body

match rest:
0 == length ?:
is_empty ?:
# e.g. fn arg: match ...: ...
match {sl, stmnt}:
{sl: true, stmnt: isLabeledStatement ?}:
Expand Down Expand Up @@ -64,7 +64,7 @@ last_expressions = fn path:
body.traverse
dict:
LabeledStatement: fn nested_match:
nested_match.skip ()
nested_match.skip _

BreakStatement: fn brk:
last = brk.getSibling brk.key - 1
Expand All @@ -73,7 +73,7 @@ last_expressions = fn path:
{expression: {operator: 'throw'}}:
last.replaceWith
expressionStatement last.node.expression
brk.remove ()
brk.remove _
else:
# TODO: don't use mutation
items.push last
Expand All @@ -94,7 +94,7 @@ replace_with_return = fn path:
pipe last_expressions path:
map expr:
match expr:
{node: {expression: {operator:'throw'}}}:
{node: {expression: {operator: 'throw'}}}:
expr.replaceWith
wrap_with_comment_loc
expressionStatement expr.node.expression
Expand All @@ -110,7 +110,7 @@ replace_with_return = fn path:
match {sibl}:
# istanbul ignore else
{sibl: {}}:
sibl.remove ()
sibl.remove _

consume_all

Expand All @@ -123,7 +123,7 @@ replace_with_assign = fn target, path:
# TODO: needs loc
target.parentPath.insertBefore lets id
target.parentPath.insertBefore simple get_body path
target.parentPath.insertAfter assign id, undef ()
target.parentPath.insertAfter assign id, undef _

pipe last_expressions path:
map expr:
Expand Down
2 changes: 1 addition & 1 deletion src/js/identifier.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ str_36 = base_n ?, 36
replace_chars = fn name, idx=0:
prefixed_name = '${var_prefix}${name}'

match prefixed_name:
match prefixed_name:
matches ?, check_ident:
prefixed_name
else:
Expand Down
4 changes: 2 additions & 2 deletions src/js/module.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
identifier, assignmentExpression, expressionStatement,
identifier, assignmentExpression, expressionStatement
memberExpression, callExpression, objectProperty, objectPattern
variableDeclaration, variableDeclarator
isImportDefaultSpecifier, isImportSpecifier
Expand Down Expand Up @@ -56,7 +56,7 @@ module_transforms = dict:
id

path.insertAfter foo
path.remove ()
path.remove _
no_result

ExportNamedDeclaration: fn path:
Expand Down
18 changes: 9 additions & 9 deletions src/js/types.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logicalExpression, binaryExpression, unaryExpression
doExpression, assignmentExpression, isIdentifier
} = import'@babel/types'
{length} = import '@fink/std-lib/iter'
{is_empty} = import '@fink/std-lib/iter'


{escape_ident} = import'./identifier'
Expand Down Expand Up @@ -35,10 +35,10 @@ typof = fn value: unaryExpression 'typeof', value

and = fn left, ...rest:
match rest:
0 < length ?:
logicalExpression '&&', left, and ...rest
else:
is_empty ?:
left
else:
logicalExpression '&&', left, and ...rest


neq = fn left, right: binaryExpression '!==', left, right
Expand All @@ -53,8 +53,8 @@ false_ = fn: booleanLiteral false


not_nullish = fn value:
not_null = neq value, nullLiteral ()
not_undef = neq value, undef ()
not_null = neq value, nullLiteral _
not_undef = neq value, undef _
and not_undef, not_null


Expand All @@ -63,8 +63,8 @@ ident = fn name: identifier escape_ident name

raw_str = fn value:
dict:
type: 'StringLiteral',
value,
type: 'StringLiteral'
value
extra: dict:
raw: '"${value}"'
rawValue: value
Expand Down Expand Up @@ -101,7 +101,7 @@ func = fn args, ...expressions:
generator = fn name, args, ...statements:
func_name = ident name
body = blockStatement statements
functionExpression func_name, args, body, true
functionExpression func_name, args, body, true


for_of = fn [item, items], ...expressions:
Expand Down
Loading

0 comments on commit b1ca406

Please sign in to comment.