From 982661c083a1da8818a71560ac66f8391b874dce Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 25 Oct 2023 01:28:47 +0300 Subject: [PATCH] $mol_view_tree2_to_js prop name fixes, number fix --- list/demo/demo.view.tree | 2 +- list/demo/demo.view.ts | 2 +- view/tree2/prop/parts.test.ts | 44 +++++++++++++++ view/tree2/prop/parts.ts | 11 +++- view/tree2/prop/signature.ts | 2 +- view/tree2/to/dts/dts.ts | 14 +++-- view/tree2/to/js/js.ts | 15 +++--- .../simple_default_indexed_channel.view.tree | 3 +- view/tree2/to/js/test/ex/simple_nan.view.tree | 6 +++ view/tree2/to/js/test/js.simple.test.ts | 54 +++++++++++++------ view/tree2/to/locale/locale.ts | 4 +- 11 files changed, 118 insertions(+), 39 deletions(-) create mode 100644 view/tree2/prop/parts.test.ts create mode 100644 view/tree2/to/js/test/ex/simple_nan.view.tree diff --git a/list/demo/demo.view.tree b/list/demo/demo.view.tree index 6145772cae1..3c97354a386 100644 --- a/list/demo/demo.view.tree +++ b/list/demo/demo.view.tree @@ -4,7 +4,7 @@ $mol_list_demo $mol_example_small title \Items count content / <= Items_count $mol_number - value? <=> items_сount? 50 + value? <=> items_count? 50 value_min 0 value_max 100000 <= Items $mol_list diff --git a/list/demo/demo.view.ts b/list/demo/demo.view.ts index 0dd341b8d0b..3732435788a 100644 --- a/list/demo/demo.view.ts +++ b/list/demo/demo.view.ts @@ -9,7 +9,7 @@ namespace $.$$ { override list_items() { const rows = [] - for ( let key = 0 ; key < this.items_сount() ; key++ ) { + for ( let key = 0 ; key < this.items_count() ; key++ ) { rows.push( this.Item( key ) ) } diff --git a/view/tree2/prop/parts.test.ts b/view/tree2/prop/parts.test.ts new file mode 100644 index 00000000000..333034d43a7 --- /dev/null +++ b/view/tree2/prop/parts.test.ts @@ -0,0 +1,44 @@ +namespace $ { + + $mol_test({ + 'wrong order'($) { + $mol_assert_fail(() => { + $mol_view_tree2_prop_parts('some_bla?*') + }) + }, + + 'empty'($) { + $mol_assert_fail(() => { + $mol_view_tree2_prop_parts('') + }) + }, + + 'prop with index'($) { + const parts = $mol_view_tree2_prop_parts('some_bla*') + $mol_assert_equal(parts.name, 'some_bla') + $mol_assert_equal(parts.key, '*') + $mol_assert_equal(parts.next, '') + }, + + 'prop with index and value'($) { + const parts = $mol_view_tree2_prop_parts('some_bla*?') + $mol_assert_equal(parts.name, 'some_bla') + $mol_assert_equal(parts.key, '*') + $mol_assert_equal(parts.next, '?') + }, + + 'legacy indexed'($) { + const parts = $mol_view_tree2_prop_parts('Some*default') + $mol_assert_equal(parts.name, 'Some') + $mol_assert_equal(parts.key, '*') + $mol_assert_equal(parts.next, '') + }, + + 'legacy indexed value'($) { + const parts = $mol_view_tree2_prop_parts('Some*k?v') + $mol_assert_equal(parts.name, 'Some') + $mol_assert_equal(parts.key, '*') + $mol_assert_equal(parts.next, '?') + } + }) +} diff --git a/view/tree2/prop/parts.ts b/view/tree2/prop/parts.ts index 6f2e5969b0b..929418565ee 100644 --- a/view/tree2/prop/parts.ts +++ b/view/tree2/prop/parts.ts @@ -1,5 +1,12 @@ namespace $ { - export function $mol_view_tree2_prop_parts( prop: $mol_tree2 ) { - return [ ...prop.type.matchAll( $mol_view_tree2_prop_signature ) ][0].groups! + export function $mol_view_tree2_prop_parts( prop: string ) { + const groups = [ ...prop.matchAll( $mol_view_tree2_prop_signature ) ][0]?.groups + if (! groups) throw new Error(`${$mol_view_tree2_prop_signature} not matched: ${prop}`) + + return { + name: groups.name, + key: groups.key ? '*' : '', + next: groups.next ? '?' : '' + } } } diff --git a/view/tree2/prop/signature.ts b/view/tree2/prop/signature.ts index 750b524f0e0..e02bb1c2fab 100644 --- a/view/tree2/prop/signature.ts +++ b/view/tree2/prop/signature.ts @@ -1,6 +1,6 @@ namespace $ { - const { begin, end, latin_only: letter, optional, repeat_greedy } = $mol_regexp + const { begin, end, latin_only: letter, or, optional, repeat_greedy } = $mol_regexp export let $mol_view_tree2_prop_signature = $mol_regexp.from([ begin, diff --git a/view/tree2/to/dts/dts.ts b/view/tree2/to/dts/dts.ts index e3bdd2d2e0c..c3244d894d7 100644 --- a/view/tree2/to/dts/dts.ts +++ b/view/tree2/to/dts/dts.ts @@ -1,14 +1,12 @@ namespace $ { - const prop_parts = $mol_view_tree2_prop_parts - function name_of( prop: $mol_tree2 ) { - return prop_parts(prop).name + return $mol_view_tree2_prop_parts(prop.type).name } function params_of( prop: $mol_tree2, ... val: $mol_tree2[] ) { - const { key, next } = prop_parts(prop) + const { key, next } = $mol_view_tree2_prop_parts(prop.type) return prop.struct( 'line', [ prop.data('( '), @@ -119,11 +117,11 @@ namespace $ { input.type.trim().length > 1 ? input.data( input.type.slice(1) ) : input.data('any'), input.data('[]'), ] - - if( Number( input.type ).toString() === input.type.replace( /^\+/, '' ) ) return [ - input.data( 'number' ), + + if( input.type && (input.type.match(/[\+\-]*NaN/) || !Number.isNaN( Number( input.type ) ) ) ) return [ + input.data( 'number'), ] - + if( /^[$A-Z]/.test( input.type ) ) { const first = input.kids[0] diff --git a/view/tree2/to/js/js.ts b/view/tree2/to/js/js.ts index 1b6e7f06154..29c3ac5507c 100644 --- a/view/tree2/to/js/js.ts +++ b/view/tree2/to/js/js.ts @@ -1,15 +1,14 @@ namespace $ { const err = $mol_view_tree2_error_str - const prop_parts = $mol_view_tree2_prop_parts function name_of( prop: $mol_tree2 ) { - return prop_parts(prop).name + return $mol_view_tree2_prop_parts(prop.type).name } function params_of( prop: $mol_tree2, bidi = true ) { - const { key, next } = prop_parts(prop) + const { key, next } = $mol_view_tree2_prop_parts(prop.type) return prop.struct( '(,)', [ ... key ? [ prop.struct( 'id' ) ] : [], @@ -20,7 +19,7 @@ namespace $ { function args_of( prop: $mol_tree2, bidi = true ) { - const { key, next } = prop_parts(prop) + const { key, next } = $mol_view_tree2_prop_parts(prop.type) return prop.struct( '(,)', [ ... key ? [ prop.struct( key.length > 1 ? key.slice(1) : 'id' ) ] : [], @@ -51,7 +50,7 @@ namespace $ { prop: $mol_tree2 ) { const { klass, members, addons, methods } = acc - const { name, key, next } = prop_parts(prop) + const { name, key, next } = $mol_view_tree2_prop_parts(prop.type) if (methods.has(name)) return acc @@ -153,9 +152,11 @@ namespace $ { if( input.type[0] === '/' ) return [ input.struct( '[,]', input.hack( belt ) ), ] - + if( input.type && (input.type.match(/[\+\-]*NaN/) || !Number.isNaN( Number( input.type ) ) ) ) return [ + input + ] + if( /^[$A-Z]/.test( input.type ) ) { - const is_delegate = input.type === '<=' || input.type === '<=>' if( !next ) addons.push( decorate() ) const overrides = [] as $mol_tree2[] diff --git a/view/tree2/to/js/test/ex/simple_default_indexed_channel.view.tree b/view/tree2/to/js/test/ex/simple_default_indexed_channel.view.tree index 17f025a3c2b..ed20999fb44 100644 --- a/view/tree2/to/js/test/ex/simple_default_indexed_channel.view.tree +++ b/view/tree2/to/js/test/ex/simple_default_indexed_channel.view.tree @@ -1,2 +1,3 @@ $mol_view_tree2_to_js_test_ex_simple_default_indexed_channel_foo $mol_view - a*? null + a_b*? 0 + legacy*k?v 0 diff --git a/view/tree2/to/js/test/ex/simple_nan.view.tree b/view/tree2/to/js/test/ex/simple_nan.view.tree new file mode 100644 index 00000000000..a074af807ff --- /dev/null +++ b/view/tree2/to/js/test/ex/simple_nan.view.tree @@ -0,0 +1,6 @@ +$mol_view_tree2_to_js_test_ex_simple_nan_foo $mol_view + a NaN + b +NaN + c -NaN + d +Infinity + e -Infinity diff --git a/view/tree2/to/js/test/js.simple.test.ts b/view/tree2/to/js/test/js.simple.test.ts index 72b3e5d1963..8fabcd08135 100644 --- a/view/tree2/to/js/test/js.simple.test.ts +++ b/view/tree2/to/js/test/js.simple.test.ts @@ -5,8 +5,7 @@ namespace $ { 'simple empty class'( $ ) { const _foo = $mol_view_tree2_to_js_test_ex_simple_empty_class_foo - _foo.make({ $ }) - + $mol_assert_ok(_foo.make({ $ }) instanceof _foo) }, 'simple mutable and read only channels'( $ ) { @@ -14,7 +13,7 @@ namespace $ { const foo = _foo.make({ $ }) - $mol_assert_like( + $mol_assert_equal( foo.readonly(), // @ts-ignore foo.readonly( 1 ), @@ -22,12 +21,12 @@ namespace $ { null, ) - $mol_assert_like( + $mol_assert_equal( foo.mutable(), null, ) - $mol_assert_like( + $mol_assert_equal( foo.mutable(2), foo.mutable(), 2, @@ -38,12 +37,12 @@ namespace $ { 'simple string channel'( $ ) { const _foo = $mol_view_tree2_to_js_test_ex_simple_string_channel_foo - $mol_assert_like( + $mol_assert_equal( _foo.make({ $ }).hardcoded(), 'First\nSecond', ) - $mol_assert_like( + $mol_assert_equal( _foo.make({ $ }).localized(), `$mol_view_tree2_to_js_test_ex_simple_string_channel_foo_localized`, ) @@ -54,12 +53,17 @@ namespace $ { const foo = _foo.make({ $ }) - $mol_assert_like( - foo.a(0, 1), - foo.a(0), + $mol_assert_equal( + foo.a_b(0, 1), + foo.a_b(0), + 1 + ) + + $mol_assert_equal( + foo.legacy(0, 1), + foo.legacy(0), 1 ) - }, 'simple empty legacy indexed channel throws error'( $ ) { @@ -87,8 +91,8 @@ namespace $ { $mol_assert_ok(b instanceof _foo) $mol_assert_ok(b instanceof _bar) - $mol_assert_like( a.str(), 'some') - $mol_assert_like( b.str(), 'some2') + $mol_assert_equal( a.str(), 'some') + $mol_assert_equal( b.str(), 'some2') }, 'simple commented node'( $ ) { @@ -102,23 +106,41 @@ namespace $ { 'simple factory props'( $ ) { const _foo = $mol_view_tree2_to_js_test_ex_simple_factory_props_foo - const foo = _foo.make({ $ }) $mol_assert_ok(typeof foo.button().sub === 'function') $mol_assert_ok(typeof foo.button().some === 'function') - $mol_assert_like( + $mol_assert_equal( foo.button().loc(), `$mol_view_tree2_to_js_test_ex_simple_factory_props_foo_button_loc` ) - $mol_assert_like( + $mol_assert_equal( foo.button().sub()[0], 1 ) }, + + 'simple nan' ($) { + const _foo = $mol_view_tree2_to_js_test_ex_simple_nan_foo + const foo = _foo.make({ $ }) + type assert_a = $mol_type_assert, number> + type assert_d = $mol_type_assert, number> + $mol_assert_equal(foo.a(), foo.b(), foo.c(), NaN) + $mol_assert_equal(foo.d(), Infinity) + $mol_assert_equal(foo.e(), -Infinity) + }, + + 'extra char' ($) { + $mol_assert_fail(() => { + $mol_view_tree2_to_js_test_run(` + Foo $mol_view + item_чount 50 + `) + }) + }, }) } diff --git a/view/tree2/to/locale/locale.ts b/view/tree2/to/locale/locale.ts index e37163fabc9..e7e81c92535 100644 --- a/view/tree2/to/locale/locale.ts +++ b/view/tree2/to/locale/locale.ts @@ -10,7 +10,7 @@ namespace $ { const acc = { chain: [] as string[] } for (const prop of props) { - const { name } = $mol_view_tree2_prop_parts(prop) + const { name } = $mol_view_tree2_prop_parts(prop.type) prop.hack({ '': ( input, belt, context )=> { @@ -40,7 +40,7 @@ namespace $ { for( const over of input.kids ) { if( over.type === '/' ) continue - const oname = $mol_view_tree2_prop_parts( over ).name + const oname = $mol_view_tree2_prop_parts( over.type ).name const bind = over.kids[0] if( bind.type === '@' ) {