Skip to content

Commit

Permalink
$mol_view_tree2_to_dts review fixes 2
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Dec 16, 2023
1 parent 2089bf9 commit fd7cfe7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
3 changes: 2 additions & 1 deletion build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ namespace $ {
if( mod !== this.root() ) this.modEnsure( parent.path() )

var mapping = mod === this.root()
? this.$.$mol_tree2_from_string( `pack ${ mod.name() } git \\https://github.com/hyoo-ru/mam.git\n` )
? this.$.$mol_tree2_from_string( `pack ${ mod.name() } git \\https://github.com/hyoo-ru/mam.git
` )
: this.modMeta( parent.path() )

if( mod.exists() ) {
Expand Down
2 changes: 1 addition & 1 deletion state/shared/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ namespace $ {
send( key: string, next?: readonly $hyoo_crowd_chunk[] ) {

const socket = this.socket()
$mol_wire_sync( this ).wait_connection()/* */
$mol_wire_sync( this ).wait_connection()

if( socket.readyState !== socket.OPEN ) return

Expand Down
2 changes: 1 addition & 1 deletion tree2/js/to/text/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace $ {
]

// number
if( input.type.match(/[+\-]?NaN/) || !Number.isNaN( Number( input.type ) ) ) return [
if( $mol_view_tree2_value_number(input.type) ) return [
input.data( input.type )
]

Expand Down
41 changes: 18 additions & 23 deletions view/tree2/to/dts/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace $ {
return prop.data(name)
}

function params_of( this: $, prop: $mol_tree2, ... val: $mol_tree2[] ) {
function channel_signature( this: $, prop: $mol_tree2, ... val: $mol_tree2[] ) {
const { name, key, next } = this.$mol_view_tree2_prop_parts(prop)

if (next && (! val.length || ! val[0].value) ) {
if (next && ! val[0]?.value ) {
this.$mol_fail(
err`Type empty for next value at ${prop.span}`
)
Expand All @@ -28,13 +28,16 @@ namespace $ {
prop.data(name),
prop.data('( '),
... key ? [
prop.data( 'id: any' + (next ? ', ' : '') ),
prop.data('id'),
prop.data( ': any' + ( next ? ', ' : '' ) ),
] : [],
... next ? [
prop.data( 'next?: ' ),
prop.data('next'),
prop.data( '?: ' ),
... val,
prop.data(' '),
] : [],
prop.data(' )'),
prop.data(')'),
] )

}
Expand All @@ -61,24 +64,17 @@ namespace $ {

function primitive_type(input: $mol_tree2) {
let type = 'string'
if (input.type && (
input.type.match(/[\+\-]*NaN/)
|| !Number.isNaN( Number( input.type ) )
)) type = 'number'
if (input.type && $mol_view_tree2_value_number(input.type)) type = 'number'

if (input.type === 'true' || input.type === 'false') type = 'boolean'

return input.data(type)
}

function readonly_arr(this: $, input: $mol_tree2, infered: readonly $mol_tree2[]) {
return infered.length === 1 ? [
input.data('readonly( '),
infered[0],
input.data(' )[]'),
] : [
function readonly_arr(input: $mol_tree2, infered: readonly $mol_tree2[]) {
return [
input.data('readonly('),
input.struct( 'indent', infered),
infered.length === 1 ? infered[0] : input.struct( 'indent', infered),
input.data(')[]'),
]
}
Expand Down Expand Up @@ -121,10 +117,9 @@ namespace $ {

'null': val => {
const kid = val.kids[0]
const kid_data = kid?.type ? kid.data(kid.type) : undefined

return kid_data
? [ kid_data, val.data( ' | null' ) ]
return kid?.type
? [ kid.data(kid.type), val.data( ' | null' ) ]
: [ val.data( 'any' ) ]
},

Expand Down Expand Up @@ -219,7 +214,7 @@ namespace $ {

return kid.struct( 'line', kid.type.match(/(?:\*|\?)/)
? [
params_of.call(this, kid, ...ret),
channel_signature.call(this, kid, ...ret),
kid.data(': '),
...ret,
kid.data( ',' ),
Expand Down Expand Up @@ -261,7 +256,7 @@ namespace $ {
]

if (array_type[0].value === 'any') {
return readonly_arr.call(this, input, array_type)
return readonly_arr(input, array_type)
}

for (const kid of input.kids) {
Expand All @@ -288,7 +283,7 @@ namespace $ {
)
}

return readonly_arr.call(this, input, array_type)
return readonly_arr(input, array_type)
}

if( $mol_view_tree2_class_match( input ) ) {
Expand Down Expand Up @@ -355,7 +350,7 @@ namespace $ {

return prop.struct( 'indent', [
prop.struct( 'line', [
params_of.call(this, prop, ... val ), // Parameter, not Return
channel_signature.call(this, prop, ... val ), // Parameter, not Return
prop.data(': '),
... val,
] )
Expand Down
4 changes: 2 additions & 2 deletions view/tree2/to/js/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace $ {
if( input.type[0] === '/' ) return [
input.struct( '[,]', input.hack( belt ) ),
]
if( input.type && (input.type.match(/[\+\-]*NaN/) || !Number.isNaN( Number( input.type ) ) ) ) return [
if( input.type && $mol_view_tree2_value_number(input.type) ) return [
input
]

Expand All @@ -154,7 +154,7 @@ namespace $ {

for( const over of input.kids ) {

if( over.type?.[0] === '/' ) continue
if( over.type[0] === '/' ) continue
const bind = over.kids[0]
if( bind.type === '=>' ) continue

Expand Down
5 changes: 5 additions & 0 deletions view/tree2/value/number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace $ {
export function $mol_view_tree2_value_number(type: string) {
return type.match(/[\+\-]*NaN/) || !Number.isNaN( Number( type ) )
}
}

0 comments on commit fd7cfe7

Please sign in to comment.