diff --git a/image/image.view.tree b/image/image.view.tree index cd0b4f39f7b..548f51e24d4 100644 --- a/image/image.view.tree +++ b/image/image.view.tree @@ -9,8 +9,8 @@ $mol_image $mol_view crossOrigin <= cors null attr *any ^ - width <= natural_width? 0 - height <= natural_height? 0 + width <= natural_width 0 + height <= natural_height 0 event *any load? <=> load? null minimal_width 16 diff --git a/image/image.view.ts b/image/image.view.ts index 53720f36bcb..c45da324ad0 100644 --- a/image/image.view.ts +++ b/image/image.view.ts @@ -2,24 +2,24 @@ namespace $.$$ { export class $mol_image extends $.$mol_image { @ $mol_mem - natural_width( next?: null | number ) { + natural_width( next?: null ) { const dom = this.dom_node() as HTMLImageElement if( dom.naturalWidth ) return dom.naturalWidth const found = this.uri().match( /\bwidth=(\d+)/ ) - return found ? Number( found[1] ) : null! + return found ? Number( found[1] ) : null! } @ $mol_mem - natural_height( next?: null | number ) { + natural_height( next?: null ) { const dom = this.dom_node() as HTMLImageElement if( dom.naturalHeight ) return dom.naturalHeight const found = this.uri().match( /\bheight=(\d+)/ ) - return found ? Number( found[1] ) : null! + return found ? Number( found[1] ) : null! } diff --git a/view/tree2/class/props.test.ts b/view/tree2/class/props.test.ts index c0c2198bc15..05da69ff9d5 100644 --- a/view/tree2/class/props.test.ts +++ b/view/tree2/class/props.test.ts @@ -10,16 +10,16 @@ namespace $.$$ { sub / <= title <= Close ${d}mol_button - title \close + title \\close click?event <=> close?event null - Some* ${d}mol_speech - Text => f - g => h + Dog ${d}mol_view_tree2_class_test_dog + Mouth => Dog_mouth + animation => dog_animation plugins / - <= Speech ${d}mol_speech - Text => a - b => c - d => e + <= Human* ${d}mol_view_tree2_class_test_human + Mouth => Human_mouth + animation => human_animation + text => human_text ` /* class A { @@ -38,35 +38,20 @@ namespace $.$$ { sub / <= Title <= Close - Some* ${d}mol_speech - Text => f - g => h - plugins / <= Speech + Dog $mol_view_tree2_class_test_dog Mouth => Dog_mouth animation => dog_animation + plugins / <= Human* Сlose_icon ${d}mol_icon_cross Title ${d}mol_view sub / <= title close?event null Close ${d}mol_button - title \close + title \\close click?event <=> close?event - f = - Some* ${d}mol_speech Text => f g => h - Text - h = - f - g - a = - Speech ${d}mol_speech Text => a b => c d => e - Text - c = - a - b - e = - c - d - Speech ${d}mol_speech - Text => a - b => c - d => e + Dog_mouth = Dog Mouth + dog_animation = Dog_mouth animation + Human_mouth = Human* Mouth + human_animation = Human_mouth animation + human_text = human_animation text + Human* $mol_view_tree2_class_test_human Mouth => Human_mouth animation => human_animation text => human_text `, 'reference') $mol_test({ diff --git a/view/tree2/class/props.ts b/view/tree2/class/props.ts index 47cef231bd6..b42fbad4fef 100644 --- a/view/tree2/class/props.ts +++ b/view/tree2/class/props.ts @@ -58,14 +58,15 @@ namespace $ { add_inner(right.clone([ right.struct('=', [ - context.factory, - left.clone([]) + context.factory.clone([ left.clone([]) ]), ]), ])) } if (right) context = { factory: right.clone([]) } - else if( operator && ! context.factory && $mol_view_tree2_class_match( operator ) ) context = { factory: left } + else if( operator && ! context.factory && $mol_view_tree2_class_match( operator ) ) { + context = { factory: left.clone([]) } + } return [ left.clone( left.hack( belt, context ) ) ] diff --git a/view/tree2/to/dts/dts.ts b/view/tree2/to/dts/dts.ts index 36ec4c49c49..b89da687115 100644 --- a/view/tree2/to/dts/dts.ts +++ b/view/tree2/to/dts/dts.ts @@ -52,14 +52,20 @@ namespace $ { ] } - function parameters(this: $, klass: $mol_tree2, input: $mol_tree2) { - return [ + function parameters(this: $, klass: $mol_tree2, input: $mol_tree2, pick_index?: number) { + const result = [ input.data( 'Parameters< ' ), klass, input.data( '[\'' ), name_of.call(this, input ), input.data( `'] >`), ] + + if (pick_index !== undefined) { + result.push(input.data(`[${pick_index}]`)) + } + + return result } function primitive_type(input: $mol_tree2) { @@ -131,6 +137,7 @@ namespace $ { '<=>': (input) => return_type.call(this, klass.data( klass.type ), this.$mol_view_tree2_child(input)), '<=': (input) => return_type.call(this, klass.data( klass.type ), this.$mol_view_tree2_child(input)), '=>': () => [], + '^': (input) => { const host = input.kids.length ? klass : parent return return_type.call( @@ -139,8 +146,11 @@ namespace $ { input.kids.length ? input.kids[0] : prop ) }, + '=': (input) => { - const [ left, right ] = input.kids + const left = input.kids[0] + const right = left.kids[0] + const left_parts = this.$mol_view_tree2_prop_parts(left) const right_parts = this.$mol_view_tree2_prop_parts(right) @@ -151,52 +161,45 @@ namespace $ { if (conflict) { this.$mol_fail(err`Only one "${conflict}" allowed: ${ - left_parts[conflict]} at ${left.span} or ${right_parts[conflict]} at ${right.span}`) + left_parts[conflict]} at ${left.span} or ${ + right_parts[conflict]} at ${right.span}`) } const main = klass.data(klass.type) const prop_parts = this.$mol_view_tree2_prop_parts(prop) const method = prop.data(`${ klass.type }_${prop_parts.name}`) + const second_main = left_parts.key || left_parts.next ? main : left.struct('line', + return_type.call(this, main, left) + ) + const second_key = left_parts.next || left_parts.key ? left : right + + if (prop_parts.key) { + types.push( type_enforce.call( + this, + method, + parameters.call(this, main, prop, 0), + parameters.call(this, second_main, second_key, 0), + ) ) + } - if (prop_parts.key || prop_parts.next) { - const prop_params = parameters.call(this, main, prop) - - const host = left.kids.length > 0 - ? left.kids[0].data(left.kids[0].type) - : undefined - - if (prop_parts.key) { - const second_key = left_parts.key ? left : right - types.push( type_enforce.call( - this, - method, - [ ...prop_params, prop.data('[0]') ], - [ ...parameters.call(this, right_parts.key && host ? host : main, second_key), second_key.data('[0]') ], - ) ) - } - - if (prop_parts.next) { - const second_next = left_parts.next ? left : right - const second_parts = left_parts.next ? left_parts : right_parts - - types.push( type_enforce.call( - this, - method, - [ ...prop_params, prop.data(`[${prop_parts.key ? '1' : '0'}]`) ], - [ ...parameters.call(this, right_parts.next && host ? host : main, second_next), - second_next.data(`[${second_parts.key ? '1' : '0'}]`) ], - ) ) - } + if (prop_parts.next) { + types.push( type_enforce.call( + this, + method, + parameters.call(this, main, prop, prop_parts.key ? 1 : 0), + parameters.call(this, second_main, second_key, (left_parts.next ? left_parts : right_parts).key ? 1 : 0), + ) ) } return return_type.call( this, left.struct('line', - return_type.call(this, main, name_of.call(this, left)) + return_type.call(this, main, left) ), name_of.call(this, right), ) }, + '': ( input, belt, context )=> { if (input.type[0] === '*') { diff --git a/view/tree2/to/js/js.ts b/view/tree2/to/js/js.ts index 354c7d36828..4d4102f2a9d 100644 --- a/view/tree2/to/js/js.ts +++ b/view/tree2/to/js/js.ts @@ -21,6 +21,12 @@ namespace $ { return params_of.call(this, prop, bidi) } + function call_method_name(this: $, child: $mol_tree2) { + return child.struct( '[]', [ + child.data( name_of.call( this, child ) ) + ] ) + } + function call_of(this: $, bind: $mol_tree2, bidi = true) { if( bind.kids.length === 0 ) { return this.$mol_fail( @@ -32,7 +38,7 @@ namespace $ { for (const child of bind.kids) { chain.push( - bind.struct( '[]', [ child.data( name_of.call( this, child ) ) ] ), + call_method_name.call(this, child), params_of.call(this, child, bidi), ) } @@ -113,8 +119,14 @@ namespace $ { ] ), ], - '=': bind => [ call_of.call(this, bind, true) ], - + '=': bind => [ bind.struct( '()', [ + bind.struct( 'this' ), + call_method_name.call(this, bind.kids[0]), + params_of.call(this, bind.kids[0]), + call_method_name.call(this, bind.kids[0].kids[0]), + params_of.call(this, bind.kids[0].kids[0]), + ] ) ], + '': ( input, belt, context )=> { if( input.type[0] === '*' ) {