Skip to content

Commit

Permalink
$mol_view_tree2_to_js prop name fixes, number fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Oct 24, 2023
1 parent b11f6f2 commit 982661c
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 39 deletions.
2 changes: 1 addition & 1 deletion list/demo/demo.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion list/demo/demo.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
}

Expand Down
44 changes: 44 additions & 0 deletions view/tree2/prop/parts.test.ts
Original file line number Diff line number Diff line change
@@ -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, '?')
}
})
}
11 changes: 9 additions & 2 deletions view/tree2/prop/parts.ts
Original file line number Diff line number Diff line change
@@ -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 ? '?' : ''
}
}
}
2 changes: 1 addition & 1 deletion view/tree2/prop/signature.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 6 additions & 8 deletions view/tree2/to/dts/dts.ts
Original file line number Diff line number Diff line change
@@ -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('( '),
Expand Down Expand Up @@ -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]
Expand Down
15 changes: 8 additions & 7 deletions view/tree2/to/js/js.ts
Original file line number Diff line number Diff line change
@@ -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' ) ] : [],
Expand All @@ -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' ) ] : [],
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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[]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions view/tree2/to/js/test/ex/simple_nan.view.tree
Original file line number Diff line number Diff line change
@@ -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
54 changes: 38 additions & 16 deletions view/tree2/to/js/test/js.simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ 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'( $ ) {
const _foo = $mol_view_tree2_to_js_test_ex_simple_mutable_and_read_only_channels_foo

const foo = _foo.make({ $ })

$mol_assert_like(
$mol_assert_equal(
foo.readonly(),
// @ts-ignore
foo.readonly( 1 ),
foo.readonly(),
null,
)

$mol_assert_like(
$mol_assert_equal(
foo.mutable(),
null,
)

$mol_assert_like(
$mol_assert_equal(
foo.mutable(2),
foo.mutable(),
2,
Expand All @@ -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`,
)
Expand All @@ -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'( $ ) {
Expand Down Expand Up @@ -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'( $ ) {
Expand All @@ -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<ReturnType<typeof foo['a']>, number>
type assert_d = $mol_type_assert<ReturnType<typeof foo['d']>, 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
`)
})
},
})

}
4 changes: 2 additions & 2 deletions view/tree2/to/locale/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof acc>({
'': ( input, belt, context )=> {
Expand Down Expand Up @@ -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 === '@' ) {
Expand Down

0 comments on commit 982661c

Please sign in to comment.