diff --git a/src/ast_utils.js b/src/ast_utils.js index af1bad6..0588d9a 100644 --- a/src/ast_utils.js +++ b/src/ast_utils.js @@ -42,7 +42,7 @@ export const map_destructuring_identifiers = (node, mapper) => { export const collect_imports = module => { return uniq( - module.stmts + module.children .filter(n => n.type == 'import') .filter(n => !n.is_external) .map(n => n.full_import_path) diff --git a/src/cmd.js b/src/cmd.js index 91360e5..28ccde7 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -532,7 +532,7 @@ const goto_definition = (state, index) => { } else { let loc if(d.module != null) { - const exp = map_find(state.parse_result.modules[d.module].stmts, n => { + const exp = map_find(state.parse_result.modules[d.module].children, n => { if(n.type != 'export') { return null } diff --git a/src/eval.js b/src/eval.js index bd710b1..3be111c 100644 --- a/src/eval.js +++ b/src/eval.js @@ -157,8 +157,8 @@ const codegen = (node, node_cxt, parent) => { } else if(node.type == 'do'){ return [ // hoist function decls to the top - ...node.stmts.filter(s => s.type == 'function_decl'), - ...node.stmts.filter(s => s.type != 'function_decl'), + ...node.children.filter(s => s.type == 'function_decl'), + ...node.children.filter(s => s.type != 'function_decl'), ].reduce( (result, stmt) => result + (do_codegen(stmt)) + ';\n', '' @@ -850,7 +850,7 @@ const eval_statement = (s, scope, calls, context) => { if(s.type == 'do') { const node = s // hoist function decls to the top - const function_decls = node.stmts + const function_decls = node.children .filter(s => s.type == 'function_decl') .map(s => { const {ok, children, calls: next_calls} = eval_children(s, scope, calls, context) @@ -872,10 +872,10 @@ const eval_statement = (s, scope, calls, context) => { const initial_scope = {...scope, ...hoisted_functions_scope} - const {ok, assignments, returned, stmts, calls: next_calls} = node.stmts.reduce( - ({ok, returned, stmts, scope, calls, assignments}, s) => { + const {ok, assignments, returned, children, calls: next_calls} = node.children.reduce( + ({ok, returned, children, scope, calls, assignments}, s) => { if(returned || !ok) { - return {ok, returned, scope, calls, stmts: [...stmts, s], assignments} + return {ok, returned, scope, calls, children: [...children, s], assignments} } else if(s.type == 'function_decl') { const node = function_decls.find(decl => decl.index == s.index) return { @@ -885,7 +885,7 @@ const eval_statement = (s, scope, calls, context) => { assignments, scope, calls, - stmts: [...stmts, node], + children: [...children, node], } } else { const { @@ -902,14 +902,14 @@ const eval_statement = (s, scope, calls, context) => { assignments: {...assignments, ...next_assignments}, scope: nextscope, calls: next_calls, - stmts: [...stmts, node], + children: [...children, node], } } }, - {ok: true, returned: false, stmts: [], scope: initial_scope, calls, assignments: {}} + {ok: true, returned: false, children: [], scope: initial_scope, calls, assignments: {}} ) const {node: next_node, scope: next_scope} = - apply_assignments({...node, children: stmts, result: {ok}}, assignments) + apply_assignments({...node, children: children, result: {ok}}, assignments) return { ok, node: next_node, diff --git a/src/find_definitions.js b/src/find_definitions.js index 80db368..ed0ea12 100644 --- a/src/find_definitions.js +++ b/src/find_definitions.js @@ -228,7 +228,7 @@ const node_has_toplevel_await = node => { export const check_imports = modules => { // TODO allow circular imports return map_object(modules, (module, node) => { - const imports = node.stmts + const imports = node.children .filter(n => n.type == 'import') .reduce( (imports, n) => [ diff --git a/src/parse_js.js b/src/parse_js.js index 666a508..2ba5c22 100644 --- a/src/parse_js.js +++ b/src/parse_js.js @@ -1438,10 +1438,7 @@ const update_children_not_rec = (node, children = node.children) => { is_statement: true, } } else if(node.type == 'do'){ - return {...node, - stmts: children, - is_statement: true, - } + return {...node, is_statement: true} } else if(node.type == 'function_decl'){ return {...node, is_statement: true,