Skip to content

Commit

Permalink
Merge pull request #27 from fink-lang/fix-prop-access
Browse files Browse the repository at this point in the history
fix prop access
  • Loading branch information
kollhof authored Mar 31, 2020
2 parents 4877fd2 + 3d2bb80 commit ea55f2e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 29 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions src/js/do-expression.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ last_expressions = fn path:

path.isLabeledStatement():
body = path.get('body')
# console.log:: body.node

items = []
body.traverse(
Expand Down Expand Up @@ -57,7 +56,7 @@ consume_all = fold item, acc=null: null
replace_with_return = fn path:
pipe last_expressions(path):
map expr:
TODO = match true:
match true:
expr.node.expression.operator == 'throw':
# no return throw ...
expr.replaceWith(
Expand Down
23 changes: 11 additions & 12 deletions src/js/types.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ expr_block = fn ...exprs:
...pipe exprs:
map node:
match true:
(node.type.endsWith('Expression') || isIdentifier(node)):
expressionStatement(node)
else:
node
(node.type.endsWith('Expression') || isIdentifier(node)):
expressionStatement(node)
else:
node
])
)

Expand Down Expand Up @@ -75,9 +75,14 @@ not_nullish = fn value:

ident = fn name:
match name:
# TODO: typeof name == 'string': identifier(escape_ident(name))
# TODO: typeof name == 'string': identifier(escape_ident(name)) or
{constructor: String}: identifier(escape_ident(name))
else: name
else:
# {type: 'Identifier'}
# {type: 'ObjectPattern'}
# {type: 'ArrayPattern'}
# {type: 'AssignmentPattern'}
name


consts = fn id, init:
Expand Down Expand Up @@ -112,12 +117,6 @@ yield_or_stop = fn expr, unique_ident, delegate:

[
consts(result, expr),
# iff(eq(result, ident('stop')))(
# returns()
# ),
# iff(neq(result, ident('skip')))(
# yields(result, delegate)
# )
yields(result, delegate)
]

Expand Down
4 changes: 1 addition & 3 deletions src/lang/block/index.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ block_statement = fn {transform}: fn expr:
decl = variableDeclaration(
'const', [variableDeclarator(st.left, st.right)]
)
# TODO: do without assign
Object.assign(decl, {leadingComments: st.leadingComments})
decl
{...decl, leadingComments: st.leadingComments}
else:
# TODO: check if (isExpression(st)) ...
expressionStatement(st)
Expand Down
1 change: 1 addition & 0 deletions src/lang/conditionals/match.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe:: 'logical', fn:
123: spam
`) eq snapshot


it:: 'compiles nested match', fn:
fink2js(`
test = fn:
Expand Down
4 changes: 2 additions & 2 deletions src/lang/literals/object.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get_key = fn {key}, ctx:


transform_prop = fn node, ctx:
prop = match true:
match true:
node.key.type == 'spread':
ctx.transform(node.key)
else:
Expand All @@ -36,5 +36,5 @@ transform_prop = fn node, ctx:
value

objectProperty(key, final_value, computed, shorthand)
prop


7 changes: 4 additions & 3 deletions src/lang/prop-access/index.fnk
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{memberExpression} = import '@babel/types'
{memberExpression, identifier} = import '@babel/types'
{add, any} = import '../context'


transform_member = fn node, ctx:
left = ctx.transform(node.left)

# TODO: right hand side can be an identifier that should not be escaped
right = ctx.transform(node.right)
right = match node.right:
{type: 'ident'}: identifier(node.right.value)
else: ctx.transform(node.right)

computed = (
node.right.type == 'string'
Expand Down
1 change: 1 addition & 0 deletions src/lang/prop-access/index.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ describe:: 'member', fn:
foo = spam.shrub
computed_member = item.'bar spam'
computed_member2 = item.(Symbol.iterator)
reserved_prop = item.arguments
`) eq snapshot

4 changes: 3 additions & 1 deletion src/lang/prop-access/index.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ exports[`member compiles 1`] = `
"const foo = spam.shrub;
const computed_member = item[\`bar spam\`];
const computed_member2 = item[Symbol.iterator];
const reserved_prop = item.arguments;
Object.assign(module.exports, {
foo,
computed_member,
computed_member2
computed_member2,
reserved_prop
});"
`;

0 comments on commit ea55f2e

Please sign in to comment.