diff --git a/src/lang/arithmitic/index.fnk b/src/lang/arithmitic/index.fnk index efb0a59..0f5b8a1 100644 --- a/src/lang/arithmitic/index.fnk +++ b/src/lang/arithmitic/index.fnk @@ -6,6 +6,6 @@ add_arithmitic = fn ctx: pipe ctx: add:: 'arithm', any, transform_binary - add:: 'arithm_right', any, transform_binary - add:: 'arithm_prefix', any, transform_unary + add:: 'arithm:right', any, transform_binary + add:: 'arithm:prefix', any, transform_unary diff --git a/src/lang/conditionals/match.fnk b/src/lang/conditionals/match.fnk index 289a6d7..588e3b4 100644 --- a/src/lang/conditionals/match.fnk +++ b/src/lang/conditionals/match.fnk @@ -41,10 +41,10 @@ match_props = fn props, emit_result, ctx, cond: [{id, prop}, ...rest] = props value = match prop: - {key: {type: 'spread'}}: - prop.key + {left: {type: 'spread'}}: + prop.left else: - prop.value + prop.right emit = match props: {length: 1}: emit_result @@ -63,7 +63,7 @@ match_obj = fn value, obj, emit_result, ctx, cond: ... pipe id_props: map {id, prop}: match prop: - {key: {type: 'spread'}}: + {left: {type: 'spread'}}: restElement:: id else: [computed, key] = get_key:: prop, ctx @@ -184,7 +184,7 @@ match_all = fn value, matches, emit, ctx: [condition, result] = split_condition:: expr js_expr = match condition: - {value: 'else'}: + {type: 'literal', value: 'else'}: js_expr = emit:: result wrap_with_comment_loc:: js_expr, condition else: diff --git a/src/lang/generic/unary.fnk b/src/lang/generic/unary.fnk index e388989..c823fc8 100644 --- a/src/lang/generic/unary.fnk +++ b/src/lang/generic/unary.fnk @@ -1,6 +1,6 @@ {unaryExpression} = import '@babel/types' -transform_unary= fn node, {transform}: +transform_unary = fn node, {transform}: right = transform:: node.right unaryExpression:: node.op, right diff --git a/src/lang/literals/index.fnk b/src/lang/literals/index.fnk index b473470..1905f51 100644 --- a/src/lang/literals/index.fnk +++ b/src/lang/literals/index.fnk @@ -5,6 +5,8 @@ {transform_regex} = import './regex' {transform_array} = import './array' {transform_object, transform_prop} = import './object' +{transform_keyword} = import './keywords' + add_literals = fn ctx: @@ -14,4 +16,5 @@ add_literals = fn ctx: add:: 'regex', any, transform_regex add:: 'array', any, transform_array add:: 'object', any, transform_object - add:: 'prop', any, transform_prop + add:: 'object:prop', any, transform_prop + add:: 'literal', any, transform_keyword \ No newline at end of file diff --git a/src/lang/literals/object.fnk b/src/lang/literals/object.fnk index f5c9946..f3be3e9 100644 --- a/src/lang/literals/object.fnk +++ b/src/lang/literals/object.fnk @@ -13,7 +13,7 @@ str_key = fn {value, loc}: {...str, loc} -get_key = fn {key}, ctx: +get_key = fn {left: key}, ctx: match key: {type: 'group'}: [true, ctx.transform:: key] @@ -25,16 +25,16 @@ get_key = fn {key}, ctx: transform_prop = fn node, ctx: match node: - {key: {type: 'spread'}}: - ctx.transform:: node.key + {left: {type: 'spread'}}: + ctx.transform:: node.left else: [computed, key] = get_key:: node, ctx - value = ctx.transform:: node.value + value = ctx.transform:: node.right - shorthand = node.key == node.value + shorthand = node.left == node.right final_value = match node: - {value: {type: 'assign'}}: + {right: {type: 'assign'}}: assignmentPattern:: value.left, value.right else: value diff --git a/src/lang/literals/regex.fnk b/src/lang/literals/regex.fnk index b6582bf..c651297 100644 --- a/src/lang/literals/regex.fnk +++ b/src/lang/literals/regex.fnk @@ -2,6 +2,6 @@ transform_regex = fn node: - pattern = node.pattern.replace:: rx/(\#.*\n)|[\n\s]/gm, '' + pattern = node.value.replace:: rx/(\#.*\n)|[\n\s]/gm, '' regExpLiteral:: pattern, node.flags diff --git a/src/lang/literals/string.fnk b/src/lang/literals/string.fnk index e43850b..9a58313 100644 --- a/src/lang/literals/string.fnk +++ b/src/lang/literals/string.fnk @@ -2,16 +2,18 @@ transform_string = fn node, {transform}: - [...quasies] = pipe node.parts.filter:: fn part, idx: idx % 2 == 0: - map part: templateElement:: - {raw: part.value.replace(rx/\\([\s\S])|(`)/g, '\\$1$2')} + {exprs: parts, tag=null} = node + [...quasies] = pipe parts: + filter part: part.type == 'string:text' + map part: + templateElement:: {raw: part.value.replace(rx/\\([\s\S])|(`)/g, '\\$1$2')} - [...expressions] = pipe node.parts.filter:: fn part, idx: idx % 2 == 1: - map part:transform:: part + [...expressions] = pipe parts: + filter part: part.type != 'string:text' + map part: transform:: part templ_str = templateLiteral:: quasies, expressions - {tag=null} = node match tag: null: templ_str