Skip to content

Commit

Permalink
Fix indentation for decorators. Move $B.make_args_parser_and_parse fr…
Browse files Browse the repository at this point in the history
…om ast_to_js.js to py_builtin_functions.js
  • Loading branch information
PierreQuentel committed Nov 19, 2024
1 parent 17630cb commit 055454f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
18 changes: 8 additions & 10 deletions www/src/ast_to_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,19 +1789,20 @@ $B.ast.ClassDef.prototype.to_js = function(scopes){

var class_ref = reference(scopes, enclosing_scope, this.name)

js += prefix
if(decorated){
class_ref = `decorated${make_id()}`
js += 'var '
}

js += prefix + `${class_ref} = `
js += `${class_ref} = `
if(has_type_params){
js += `TYPE_PARAMS_OF_${this.name}()\n`
}else{
js += `${ref}\n`
}
if(decorated){
js += reference(scopes, enclosing_scope, this.name) + ' = '
js += prefix + reference(scopes, enclosing_scope, this.name) + ' = '
var decorate = class_ref
for(let dec of decorators.reverse()){
decorate = `$B.$call(${dec})(${decorate})`
Expand Down Expand Up @@ -2274,6 +2275,7 @@ function generate_args0_str(hasPosOnly, posOnlyDefaults, hasPos, posDefaults, ha
}



// verify if it truly has no kw arguments.
if( ! hasPos && ! hasNamedOnly && ! hasKWargs ) {
fct += `
Expand Down Expand Up @@ -2636,10 +2638,6 @@ function type_param_in_def(tp, ref, scopes){
return js
}

$B.make_args_parser_and_parse = function make_args_parser_and_parse(fct, args) {
return $B.make_args_parser(fct)(fct, args);
}


$B.ast.FunctionDef.prototype.to_js = function(scopes){
compiler_check(this)
Expand All @@ -2661,15 +2659,15 @@ $B.ast.FunctionDef.prototype.to_js = function(scopes){
var decorators = [],
decorated = false,
decs_declare = this.decorator_list.length > 0 ?
'// declare decorators\n' : ''
prefix + '// declare decorators\n' : ''

// evaluate decorator in enclosing scope
for(let dec of this.decorator_list){
decorated = true
var dec_id = 'decorator' + make_id()
decorators.push(dec_id)
decs_declare += `$B.set_lineno(frame, ${dec.lineno})\n`
decs_declare += `var ${dec_id} = ${$B.js_from_ast(dec, scopes)}\n`
decs_declare += prefix + `$B.set_lineno(frame, ${dec.lineno})\n`
decs_declare += prefix + `var ${dec_id} = ${$B.js_from_ast(dec, scopes)}\n`
}

// Detect doc string
Expand Down Expand Up @@ -3006,7 +3004,7 @@ $B.ast.FunctionDef.prototype.to_js = function(scopes){
}

if(decorated && ! has_type_params){
js += `${make_scope_name(scopes, func_name_scope)}.${mangled} = `
js += prefix + `${make_scope_name(scopes, func_name_scope)}.${mangled} = `
let decorate = func_ref
for(let dec of decorators.reverse()){
decorate = `$B.$call(${dec})(${decorate})`
Expand Down
5 changes: 5 additions & 0 deletions www/src/py_builtin_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,11 @@ $B.make_function_infos = function(f, __module__, __defaults__,
co_positions: {}}
}


$B.make_args_parser_and_parse = function make_args_parser_and_parse(fct, args) {
return $B.make_args_parser(fct)(fct, args);
}

$B.make_args_parser = function(f){
if(f.$infos === undefined || f.$infos.__code__ === undefined){
throw _b_.AttributeError.$factory(`cannot set defauts to ${_b_.str.$factory(f)}`);
Expand Down
4 changes: 2 additions & 2 deletions www/src/version_info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__BRYTHON__.implementation = [3, 13, 1, 'dev', 0]
__BRYTHON__.version_info = [3, 13, 0, 'final', 0]
__BRYTHON__.compiled_date = "2024-11-13 10:50:08.615408"
__BRYTHON__.timestamp = 1731491408613
__BRYTHON__.compiled_date = "2024-11-19 08:01:01.767134"
__BRYTHON__.timestamp = 1731999661766
__BRYTHON__.builtin_module_names = ["_ajax",
"_ast",
"_base64",
Expand Down

0 comments on commit 055454f

Please sign in to comment.