Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hyoo-ru/mam_mol into range3
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Sep 17, 2023
2 parents e555bc2 + b7509cf commit 99fce47
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 40 deletions.
2 changes: 1 addition & 1 deletion book2/book2.view.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
top: 1.5rem;
width: 1px;
height: 1rem;
background: var(--mol_theme_special);
background: var(--mol_theme_focus);
border-radius: var(--mol_gap_round);
opacity: .5;
}
Expand Down
10 changes: 5 additions & 5 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ namespace $ {
try {
this.modEnsure( dep.path() )
} catch( error: any ) {
error.message = `${ error.message }\nDependency "${ dep.relate( this.root() ) }" from "${ mod.relate( this.root() ) }" `
error.message = `${ error.message }\nDependency "${p}" -> "${ dep.relate( this.root() ) }" from "${ mod.relate( this.root() ) }" `
$mol_fail_hidden(error)
}

Expand Down Expand Up @@ -905,7 +905,7 @@ namespace $ {
var sources = this.sources_js( { path , exclude } )
if( sources.length === 0 ) return []

var concater = new $mol_sourcemap_builder( targetJS.parent().path(), ';')
var concater = new $mol_sourcemap_builder( this.root().relate( targetJS.parent() ), ';')
concater.add( '"use strict"' )

if( bundle === 'node' ) {
Expand All @@ -931,7 +931,7 @@ namespace $ {
concater.add( `\nvar $node = $node || {}\nvoid function( module ) { var exports = module.${''}exports = this; function require( id ) { return $node[ id.replace( /^.\\// , "` + src.parent().relate( this.root().resolve( 'node_modules' ) ) + `/" ) ] }; \n`, '-' )
}

concater.add( content.text , src.relate( targetJS.parent() ) , content.map )
concater.add( content.text , '' , content.map )

if( isCommonJs ) {
const idFull = src.relate( this.root().resolve( 'node_modules' ) )
Expand Down Expand Up @@ -1016,7 +1016,7 @@ namespace $ {
var target = pack.resolve( `-/${bundle}.test.js` )
var targetMap = pack.resolve( `-/${bundle}.test.js.map` )

var concater = new $mol_sourcemap_builder( target.parent().path(), ';')
var concater = new $mol_sourcemap_builder( this.root().relate( target.parent() ), ';')
concater.add( '"use strict"' )

var exclude_ext = exclude.filter( ex => ex !== 'test' && ex !== 'dev' )
Expand All @@ -1041,7 +1041,7 @@ namespace $ {
}
try {
const content = this.js_content( src.path() )
concater.add( content.text, src.relate( target.parent() ), content.map)
concater.add( content.text, '', content.map)
} catch( error: any ) {
errors.push( error )
}
Expand Down
8 changes: 4 additions & 4 deletions compare/deep/deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace $ {

if( left_proto !== right_proto ) return false

if( left instanceof Boolean ) return Object.is( left.valueOf(), right['valueOf']() )
if( left instanceof Number ) return Object.is( left.valueOf(), right['valueOf']() )
if( left instanceof String ) return Object.is( left.valueOf(), right['valueOf']() )
if( left instanceof Date ) return Object.is( left.valueOf(), right['valueOf']() )
if( left instanceof Boolean ) return Object.is( left.valueOf(), ( right as any )['valueOf']() )
if( left instanceof Number ) return Object.is( left.valueOf(), ( right as any )['valueOf']() )
if( left instanceof String ) return Object.is( left.valueOf(), ( right as any )['valueOf']() )
if( left instanceof Date ) return Object.is( left.valueOf(), ( right as any )['valueOf']() )
if( left instanceof RegExp ) return left.source === (right as any).source && left.flags === (right as any).flags
if( left instanceof Error ) return left.message === (right as any).message && left.stack === (right as any).stack

Expand Down
4 changes: 2 additions & 2 deletions object2/object2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace $ {

export class $mol_object2 {

static $ = $ as $
static $ = $ as any as $

[Symbol.toStringTag]!: string

Expand Down Expand Up @@ -31,7 +31,7 @@ namespace $ {
}

static toString() {
if( Symbol.toStringTag in this ) return this[ Symbol.toStringTag ] as string
if( Symbol.toStringTag in this ) return ( this as any )[ Symbol.toStringTag ] as string
return this.name
}

Expand Down
40 changes: 22 additions & 18 deletions range2/range2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace $ {
$mol_assert_ok( list instanceof Array )
$mol_assert_equal( list.length , 10 )

$mol_assert_equal( list[-1] , -1 )
$mol_assert_equal( list[-1] , undefined )
$mol_assert_equal( list[0] , 0 )
$mol_assert_equal( list[9] , 9 )
$mol_assert_equal( list[9.5] , undefined )
$mol_assert_equal( list[10] , 10 )
$mol_assert_equal( list[10] , undefined )

$mol_assert_equal( calls , 4 )
$mol_assert_equal( calls , 2 )

} ,

Expand All @@ -32,9 +32,9 @@ namespace $ {
$mol_assert_equal( list[0] , 0 )
$mol_assert_equal( list[4] , 4 )
$mol_assert_equal( list[Number.MAX_SAFE_INTEGER] , Number.MAX_SAFE_INTEGER )
$mol_assert_equal( list[Number.POSITIVE_INFINITY] , Number.POSITIVE_INFINITY )
$mol_assert_equal( list[Number.POSITIVE_INFINITY] , undefined )

$mol_assert_equal( calls , 4 )
$mol_assert_equal( calls , 3 )

} ,

Expand Down Expand Up @@ -100,10 +100,10 @@ namespace $ {
$mol_assert_equal( list[9] , 4 )
$mol_assert_equal( list[10] , 0 )
$mol_assert_equal( list[14] , 4 )
$mol_assert_equal( list[15] , 5 )
$mol_assert_equal( list[15] , undefined )

$mol_assert_equal( calls1 , 2 )
$mol_assert_equal( calls2 , 3 )
$mol_assert_equal( calls2 , 2 )

} ,

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

$mol_assert_equal( list[0] , 1 )
$mol_assert_equal( list[2] , 5 )
$mol_assert_equal( list[3] , 7 )
$mol_assert_equal( list[3] , undefined )

$mol_assert_equal( calls , 10 )
// $mol_assert_equal( calls , 6 ) // TODO: lazy filter
Expand All @@ -128,13 +128,14 @@ namespace $ {
'reverse'() {
let calls = 0

const list = $mol_range2( index => ( ++ calls , index ) , ()=> 10 ).reverse().slice(0, 3)
const list = $mol_range2( index => ( ++ calls , index ) , ()=> 10 ).toReversed().slice(0, 3)

$mol_assert_ok( list instanceof Array )
$mol_assert_equal( list.length , 3 )

$mol_assert_equal( list[0] , 9 )
$mol_assert_equal( list[3] , 6 )
$mol_assert_equal( list[2] , 7 )
$mol_assert_equal( list[3] , undefined )
$mol_assert_equal( calls , 2 )

} ,
Expand Down Expand Up @@ -170,10 +171,10 @@ namespace $ {

$mol_assert_equal( target[0] , 10 )
$mol_assert_equal( target[4] , 14 )
$mol_assert_equal( target[5] , 15 )
$mol_assert_equal( target[5] , undefined )

$mol_assert_equal( calls1 , 3 )
$mol_assert_equal( calls2 , 3 )
$mol_assert_equal( calls1 , 2 )
$mol_assert_equal( calls2 , 2 )

} ,

Expand All @@ -188,9 +189,9 @@ namespace $ {

$mol_assert_equal( list[0] , 3 )
$mol_assert_equal( list[3] , 6 )
$mol_assert_equal( list[4] , 7 )
$mol_assert_equal( list[4] , undefined )

$mol_assert_equal( calls , 3 )
$mol_assert_equal( calls , 2 )

} ,

Expand Down Expand Up @@ -231,9 +232,9 @@ namespace $ {

$mol_assert_equal( list[0] , 12 )
$mol_assert_equal( list[3] , 15 )
$mol_assert_equal( list[4] , Number.NaN )
$mol_assert_equal( list[4] , undefined )

$mol_assert_equal( calls , 3 )
$mol_assert_equal( calls , 2 )

} ,

Expand All @@ -246,9 +247,12 @@ namespace $ {

$mol_assert_fail( ()=> list.unshift( 4 ) , TypeError )
$mol_assert_fail( ()=> list.shift() , TypeError )

$mol_assert_fail( ()=> list.splice( 1 , 2 ) , TypeError )
$mol_assert_fail( ()=> list[ 1 ] = 2 , TypeError )

$mol_assert_fail( ()=> list.reverse() , TypeError )
$mol_assert_fail( ()=> list.sort() , TypeError )

$mol_assert_equal( list.toString() , '0,1,2,3,4' )

Expand Down
33 changes: 24 additions & 9 deletions range2/range2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ namespace $ {
if( field === 'length' ) return size()

const index = Number( field )
if( index < 0 ) return undefined
if( index >= size() ) return undefined
if( index === Math.trunc( index ) ) return item( index )
}

return target[ field as any ]
} ,

set( target , field ) {
return $mol_fail( new TypeError( `Lazy range is read only, ${String(field)}` ) )
return $mol_fail( new TypeError( `Lazy range is read only (trying to set field ${ JSON.stringify( field ) })` ) )
} ,

ownKeys( target ) {
Expand Down Expand Up @@ -53,8 +55,9 @@ namespace $ {
}

export class $mol_range2_array< Item > extends Array< Item > {

concat( ... tail : this[] ) : Item[] {

// Lazy
concat( ... tail : Item[][] ) : Item[] {
if( tail.length === 0 ) return this as any

if( tail.length > 1 ) {
Expand All @@ -69,6 +72,7 @@ namespace $ {
)
}

// Diligent
filter< Context > (
check : ( val : Item , index : number , list : Item[] )=> boolean ,
context? : Context ,
Expand All @@ -81,13 +85,15 @@ namespace $ {
return filtered
}

// Diligent
forEach< Context > (
proceed : ( this : Context , val : Item , index : number , list : Item[] )=> void ,
context? : Context,
) {
for( let [ key , value ] of this.entries() ) proceed.call( context as Context , value , key , this )
}

// Lazy
map< Item_out , Context > (
proceed : ( this : Context , val : Item , index : number , list : Item[] )=> Item_out ,
context? : Context ,
Expand All @@ -98,6 +104,7 @@ namespace $ {
)
}

// Diligent
reduce< Result > (
merge : ( result : Result , val : Item , index : number , list : Item[] )=> Result ,
result? : Result ,
Expand All @@ -115,24 +122,23 @@ namespace $ {
return result
}

reverse(): Item[] {
// Lazy
toReversed(): Item[] {
return $mol_range2(
index => this[ this.length - 1 - index ] ,
()=> this.length ,
)
}

slice( from = 0 , to = this.length ) : Item[] {
// Lazy
slice( from = 0 , to = this.length ) {
return $mol_range2(
index => this[ from + index ] ,
()=> Math.min( to , this.length ) - from ,
)
}

at(index: number): Item | undefined {
return this[index >= 0 ? index : this.length + index]
}

// Lazy
some< Context > (
check : ( this : Context , val : Item , index : number , list : Item[] )=> boolean ,
context? : Context ,
Expand All @@ -143,6 +149,7 @@ namespace $ {
return false
}

// Lazy
every< Context = null > (
check : ( this : Context , val : Item , index : number , list : Item[] )=> boolean ,
context? : Context ,
Expand All @@ -153,6 +160,14 @@ namespace $ {
return true
}

reverse() {
return $mol_fail( new TypeError( `Mutable reverse is forbidden. Use toReversed instead.` ) )
}

sort() {
return $mol_fail( new TypeError( `Mutable sort is forbidden. Use toSorted instead.` ) )
}

}

}
1 change: 1 addition & 0 deletions range2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const array = [ ... range ]
- concat
- map
- slice
- toReversed
- some
- every
- entries
Expand Down
3 changes: 3 additions & 0 deletions text/code/code.view.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace $.$$ {
$mol_style_define( $mol_text_code, {

whiteSpace: 'pre-wrap',
font: {
family: 'monospace',
},

Rows: {
padding: $mol_gap.text,
Expand Down
2 changes: 1 addition & 1 deletion wire/atom/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace $ {
const field = task.name + '()'
let dict = Object.getOwnPropertyDescriptor( host ?? task, field )?.value
const prefix = (host as any)?.[ Symbol.toStringTag ] ?? ( host instanceof Function ? $$.$mol_func_name( host ) : host )
const id = `${ prefix }.${ task.name }(${ $mol_key( key ) })`
const id = `${ prefix }.${ task.name }(${ $mol_key( key ).replace( /^"|"$/g, "'" ) })`

if( dict ) {
const existen = dict.get( id )
Expand Down

0 comments on commit 99fce47

Please sign in to comment.