Skip to content

Commit 52cf2fb

Browse files
authored
Merge pull request #646 from hyoo-ru/tree2-dts-test
$mol_view_tree2_to_dts tests and fixes
2 parents 9315753 + 50cf8c2 commit 52cf2fb

File tree

160 files changed

+1973
-4553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+1973
-4553
lines changed

build/build.node.ts

+74-70
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ namespace $ {
5959
const file = $mol_file.absolute( path )
6060
const name = file.name()
6161

62-
const tree = $mol_tree.fromString( file.text() , file.path() )
62+
const tree = this.$.$mol_tree2_from_string( file.text() , file.path() )
6363

6464
let content = ''
65-
for( const step of tree.select( 'build' , '' ).sub ) {
65+
for( const step of tree.select( 'build' , '' ).kids ) {
6666

67-
const res = this.$.$mol_exec( file.parent().path() , step.value ).stdout.toString().trim()
67+
const res = this.$.$mol_exec( file.parent().path() , step.text() ).stdout.toString().trim()
6868
if( step.type ) content += `let ${ step.type } = ${ JSON.stringify( res ) }`
6969

7070
}
@@ -76,26 +76,37 @@ namespace $ {
7676
return [ script ]
7777

7878
}
79-
79+
8080
@ $mol_mem_key
8181
viewTreeTranspile( path : string ) {
8282

83-
const file = $mol_file.absolute( path )
84-
const name = file.name()
83+
const source = $mol_file.absolute( path )
84+
const target = source.parent().resolve( `-view.tree` )
85+
86+
const tree = this.$.$mol_tree2_from_string( source.text(), source.relate( this.root() ) )
87+
88+
const js = target.resolve( source.name() + '.js' )
89+
const js_map = target.resolve( js.name() + '.map' )
90+
const dts = target.resolve( source.name() + '.d.ts' )
91+
const dts_map = target.resolve( dts.name() + '.map' )
92+
93+
const js_text = this.$.$mol_tree2_js_to_text( this.$.$mol_view_tree2_to_js( tree ) )
94+
js.text( this.$.$mol_tree2_text_to_string( js_text ) + '\n//# sourceMappingURL=' + js_map.relate( target ) )
95+
js_map.text( JSON.stringify( this.$.$mol_tree2_text_to_sourcemap( js_text ), null, '\t' ) )
8596

86-
const script = file.parent().resolve( `-view.tree/${ name }.ts` )
87-
const sourceMap = file.parent().resolve( `-view.tree/${ name }.map` )
88-
const locale = file.parent().resolve( `-view.tree/${ name }.locale=en.json` )
97+
const dts_text = this.$.$mol_view_tree2_to_dts( tree )
98+
dts.text( this.$.$mol_tree2_text_to_string( dts_text ) + '\n//# sourceMappingURL=' + dts_map.relate( target ) )
8999

90-
const text = file.text()
91-
const tree = this.$.$mol_tree2_from_string( text , file.path() )
92-
const res = this.$.$mol_view_tree2_ts_compile( tree )
100+
const dts_map_raw = this.$.$mol_tree2_text_to_sourcemap( dts_text )
101+
delete dts_map_raw.sourcesContent
102+
dts_map_raw.file = dts.relate( target )
103+
dts_map_raw.sourceRoot = this.root().relate( target )
104+
dts_map.text( JSON.stringify( dts_map_raw, null, '\t' ) )
93105

94-
script.text( res.script )
95-
// sourceMap.text( res.map )
96-
locale.text( JSON.stringify( res.locales , null , '\t' ) )
97-
98-
return [ script , locale ]
106+
const locale_file = target.resolve( source.name() + `.locale=en.json` )
107+
locale_file.text( JSON.stringify( this.$.$mol_view_tree2_to_locale( tree ), null, '\t' ) )
108+
109+
return [ js, js_map, dts, dts_map, locale_file ]
99110
}
100111

101112
@ $mol_mem_key
@@ -292,8 +303,8 @@ namespace $ {
292303
if( sources.length && bundle === 'node' ) {
293304
const types = [] as string[]
294305

295-
for( let dep of this.nodeDeps({ path , exclude }) ) {
296-
types.push( '\t' + JSON.stringify( dep ) + ' : typeof import\( ' + JSON.stringify( dep ) + ' )' )
306+
for( let [ dep, src ] of this.nodeDeps({ path , exclude }) ) {
307+
types.push( '\t' + JSON.stringify( dep ) + ' : typeof import\( ' + JSON.stringify( dep ) + ' ) // ' + src )
297308
}
298309

299310
const node_types = $mol_file.absolute( path ).resolve( `-node/deps.d.ts` )
@@ -385,9 +396,10 @@ namespace $ {
385396
this.js_error( diagnostic.file.getSourceFile().fileName , error )
386397

387398
} else {
399+
const text = diagnostic.messageText
388400
this.$.$mol_log3_fail({
389401
place : `${this}.tsService()` ,
390-
message: String( diagnostic.messageText ) ,
402+
message: typeof text === 'string' ? text : text.messageText ,
391403
})
392404
}
393405

@@ -455,17 +467,16 @@ namespace $ {
455467
map.sources = [ src.relate() ]
456468

457469
return {
458-
text : res.outputText.replace( /^\/\/#\ssourceMappingURL=[^\n]*/mg , '//' + src.relate() )+'\n',
470+
text : this.$.$mol_sourcemap_strip(res.outputText),
471+
// .replace( /^\/\/#\ssourceMappingURL=[^\n]*/mg , '//' + src.relate() )+'\n',
459472
map : map,
460473
}
461474

462475
} else {
463476

464-
const srcMap = src.parent().resolve( src.name() + '.map' );
465-
466477
return {
467-
text : src.text().replace( /^\/\/#\ssourceMappingURL=/mg , '//' )+'\n',
468-
map : srcMap.exists() ? JSON.parse( srcMap.text() ) as $mol_sourcemap_raw : undefined
478+
text: this.$.$mol_sourcemap_strip(src.text()),
479+
map: this.$.$mol_sourcemap_from_file(src)
469480
}
470481

471482
}
@@ -590,7 +601,8 @@ namespace $ {
590601
if( mod !== this.root() ) this.modEnsure( parent.path() )
591602

592603
var mapping = mod === this.root()
593-
? $mol_tree.fromString( `pack ${ mod.name() } git \\https://github.com/hyoo-ru/mam.git\n` )
604+
? this.$.$mol_tree2_from_string( `pack ${ mod.name() } git \\https://github.com/hyoo-ru/mam.git
605+
` )
594606
: this.modMeta( parent.path() )
595607

596608
if( mod.exists() ) {
@@ -609,17 +621,17 @@ namespace $ {
609621
return false
610622
}
611623

612-
for( let repo of mapping.select( 'pack' , mod.name() , 'git' ).sub ) {
624+
for( let repo of mapping.select( 'pack' , mod.name() , 'git' ).kids ) {
613625

614626
this.$.$mol_exec( mod.path() , 'git' , 'init' )
615627

616-
const res = this.$.$mol_exec( mod.path() , 'git' , 'remote' , 'show' , repo.value )
628+
const res = this.$.$mol_exec( mod.path() , 'git' , 'remote' , 'show' , repo.text() )
617629
const matched = res.stdout.toString().match( /HEAD branch: (.*?)\n/ )
618630
const head_branch_name = res instanceof Error || matched === null || !matched[1]
619631
? 'master'
620632
: matched[1]
621633

622-
this.$.$mol_exec( mod.path() , 'git' , 'remote' , 'add' , '--track' , head_branch_name! , 'origin' , repo.value )
634+
this.$.$mol_exec( mod.path() , 'git' , 'remote' , 'add' , '--track' , head_branch_name! , 'origin' , repo.text() )
623635
this.$.$mol_exec( mod.path() , 'git' , 'pull', '--deepen=1' )
624636
mod.reset()
625637
for ( const sub of mod.sub() ) {
@@ -641,8 +653,8 @@ namespace $ {
641653
return false
642654
}
643655

644-
for( let repo of mapping.select( 'pack' , mod.name() , 'git' ).sub ) {
645-
this.$.$mol_exec( this.root().path() , 'git' , 'clone' , '--depth', '1', repo.value , mod.relate( this.root() ) )
656+
for( let repo of mapping.select( 'pack' , mod.name() , 'git' ).kids ) {
657+
this.$.$mol_exec( this.root().path() , 'git' , 'clone' , '--depth', '1' , repo.text() , mod.relate( this.root() ) )
646658
mod.reset()
647659
return true
648660
}
@@ -672,16 +684,14 @@ namespace $ {
672684
@ $mol_mem_key
673685
modMeta( path : string ) {
674686

675-
const decls = [] as $mol_tree[]
687+
const decls = [] as $mol_tree2[]
676688

677689
const pack = $mol_file.absolute( path )
678690
for( const file of pack.sub() ) {
679691
if( !/\.meta\.tree$/.test( file.name() ) ) continue
680-
decls.push( ... $mol_tree.fromString( file.text() , file.path() ).sub )
692+
decls.push( ... this.$.$mol_tree2_from_string( file.text() , file.path() ).kids )
681693
}
682-
683-
return new $mol_tree({ sub : decls })
684-
694+
return this.$.$mol_tree2.list(decls, decls[0]?.span)
685695
}
686696

687697
@ $mol_mem_key
@@ -698,7 +708,7 @@ namespace $ {
698708
const checkDep = ( p : string )=> {
699709

700710
const isFile = /\.\w+$/.test( p )
701-
711+
702712
var dep = ( p[ 0 ] === '/' )
703713
? this.root().resolve( p + ( isFile ? '' : '/' + p.replace( /.*\// , '' ) ) )
704714
: ( p[ 0 ] === '.' )
@@ -1117,6 +1127,7 @@ namespace $ {
11171127
var pack = $mol_file.absolute( path )
11181128

11191129
var target = pack.resolve( `-/${bundle}.d.ts` )
1130+
var targetMap = pack.resolve( `-/${bundle}.d.ts.map` )
11201131

11211132
var sources = this.sourcesDTS( { path , exclude } )
11221133
if( sources.length === 0 ) return []
@@ -1130,11 +1141,12 @@ namespace $ {
11301141
}
11311142
)
11321143

1133-
target.text( concater.content + '\nexport = $;' )
1144+
target.text( concater.content + '\nexport = $;\n//# sourceMappingURL=' + targetMap.relate( target.parent() ) + '\n' )
1145+
targetMap.text( concater.toString() )
11341146

11351147
this.logBundle( target , Date.now() - start )
11361148

1137-
return [ target ]
1149+
return [ target, targetMap ]
11381150
}
11391151

11401152
@ $mol_mem_key
@@ -1165,39 +1177,39 @@ namespace $ {
11651177

11661178
const sortedPaths = this.graph( { path , exclude } ).sorted
11671179

1168-
const namedMetas: $mol_tree[] = []
1180+
const namedMetas: $mol_tree2[] = []
11691181
sortedPaths.forEach( path => {
11701182
const meta = this.modMeta( this.root().resolve( path ).path() )
1171-
if( meta.sub.length > 0 ) {
1172-
namedMetas.push( meta.clone({ value: '/' + path }) )
1183+
if( meta.kids.length > 0 ) {
1184+
namedMetas.push( meta.data( '/' + path, meta.kids ) )
11731185
}
11741186
} )
1175-
1187+
11761188
if( namedMetas.length === 0 ) return []
11771189

1178-
target.text( new $mol_tree( { sub: namedMetas } ).toString() )
1190+
target.text( this.$.$mol_tree2.list(namedMetas, namedMetas[0]?.span).toString() )
11791191

11801192
this.logBundle( target , Date.now() - start )
11811193

11821194
return [ target ]
11831195
}
11841196

11851197
@ $mol_mem_key
1186-
nodeDeps( { path , exclude } : { path : string , exclude : string[] } ) : string[] {
1198+
nodeDeps( { path , exclude } : { path : string , exclude : string[] } ) {
11871199

1188-
var res = new Set<string>()
1200+
var res = new Map<string,string>()
11891201
var sources = this.sourcesAll( { path , exclude } )
11901202

11911203
for( let src of sources ) {
11921204
let deps = this.srcDeps( src.path() )
11931205
for( let dep in deps ) {
11941206
if( !/^\/node(?:_modules)?\//.test( dep ) ) continue
11951207
let mod = dep.replace( /^\/node(?:_modules)?\// , '' ).replace( /\/.*/g , '' )
1196-
res.add( mod )
1208+
res.set( mod, src.relate() )
11971209
}
11981210
}
11991211

1200-
return [ ... res ]
1212+
return res
12011213

12021214
}
12031215

@@ -1291,7 +1303,7 @@ namespace $ {
12911303

12921304
json.version = version.join( '.' )
12931305

1294-
for( let dep of this.nodeDeps({ path , exclude }) ) {
1306+
for( let dep of this.nodeDeps({ path , exclude }).keys() ) {
12951307
if( require('module').builtinModules.includes(dep) ) continue
12961308
json.dependencies[ dep ] = `*`
12971309
}
@@ -1346,9 +1358,8 @@ namespace $ {
13461358
.filter( src => /meta.tree$/.test( src.ext() ) )
13471359

13481360
const targets : $mol_file[] = []
1349-
13501361
sources.forEach( source => {
1351-
const tree = $mol_tree.fromString( source.text() , source.path() )
1362+
const tree = this.$.$mol_tree2_from_string( source.text() , source.path() )
13521363

13531364
const pushFile = (file:$mol_file) => {
13541365
const start = Date.now()
@@ -1371,9 +1382,8 @@ namespace $ {
13711382
}
13721383

13731384
}
1374-
1375-
tree.select( 'deploy' ).sub.forEach( deploy => {
1376-
addFilesRecursive(root.resolve(deploy.value.replace( /^\// , '' )))
1385+
tree.select( 'deploy' ).kids.forEach( deploy => {
1386+
addFilesRecursive(root.resolve(deploy.text().replace( /^\// , '' )))
13771387
} )
13781388

13791389
} )
@@ -1615,7 +1625,7 @@ namespace $ {
16151625
return depends
16161626
}
16171627

1618-
$mol_build.dependors[ 'ts' ] = $mol_build.dependors[ 'tsx' ] = $mol_build.dependors[ 'jam.js' ] = source => {
1628+
$mol_build.dependors[ 'ts' ] = $mol_build.dependors[ 'tsx' ] = $mol_build.dependors[ 'jam.js' ] = $mol_build.dependors[ 'tree.js' ] = source => {
16191629
var depends : { [ index : string ] : number } = {}
16201630

16211631
var lines = String( source.text() )
@@ -1652,20 +1662,13 @@ namespace $ {
16521662
return depends
16531663
}
16541664

1655-
// $mol_build.dependors[ 'test.ts' ] = source => {
1656-
// var ts = './' + source.name().replace( /\.test\./ , '.' )
1657-
// var depends : { [ index : string ] : number } = { [ ts ] : 0 }
1658-
// $mol_build_depsMerge( depends , $mol_build.dependors[ 'ts' ]!( source ) )
1659-
// return depends
1660-
// }
1661-
16621665
$mol_build.dependors[ 'view.ts' ] = source => {
16631666
var treeName = './' + source.name().replace( /ts$/ , 'tree' )
16641667
var depends : { [ index : string ] : number } = { [ treeName ] : 0 }
16651668
$mol_build_depsMerge( depends , $mol_build.dependors[ 'ts' ]!( source ) )
16661669
return depends
16671670
}
1668-
1671+
16691672
$mol_build.dependors[ 'node.ts' ] = $mol_build.dependors[ 'web.ts' ] = source => {
16701673
var common = './' + source.name().replace( /\.(node|web)\.ts$/ , '.ts' )
16711674
var depends : { [ index : string ] : number } = { [ common ] : 0 }
@@ -1746,22 +1749,23 @@ namespace $ {
17461749
$mol_build.dependors[ 'meta.tree' ] = source => {
17471750
const depends : { [ index : string ] : number } = {}
17481751

1749-
const tree = $mol_tree.fromString( source.text() , source.path() )
1750-
1751-
tree.select( 'require' ).sub.forEach( leaf => {
1752-
depends[ leaf.value ] = 0
1752+
const tree = $$.$mol_tree2_from_string( source.text() , source.path() )
1753+
1754+
tree.select( 'require' ).kids.forEach( leaf => {
1755+
depends[ leaf.text() ] = 0
17531756
} )
17541757

1755-
tree.select( 'include' ).sub.forEach( leaf => {
1756-
depends[ leaf.value ] = -9000
1758+
tree.select( 'include' ).kids.forEach( leaf => {
1759+
depends[ leaf.text() ] = -9000
17571760
} )
17581761

17591762
return depends
17601763
}
17611764

17621765
$mol_build.dependors[ 'view.tree' ] = source => {
17631766
return {
1764-
[`/${ source.parent().relate() }/-view.tree/${ source.name() }.ts`]: 0,
1767+
[`/${ source.parent().relate() }/-view.tree/${ source.name() }.js`]: 0,
1768+
[`/${ source.parent().relate() }/-view.tree/${ source.name() }.d.ts`]: 0,
17651769
}
17661770
}
17671771

build/server/server.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ namespace $ {
314314
command ,
315315
})
316316

317-
const server = $node.child_process.spawn(
317+
const server = $node['child_process'].spawn(
318318
'node',
319319
[ '--enable-source-maps', '--trace-uncaught', `./${path}/-/node.js`, ... args ],
320320
{

drag/drag.view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace $.$$ {
1414

1515
const transfer = this.transfer()
1616
for( let type in transfer ) {
17-
event.dataTransfer!.setData( type , transfer[ type ] )
17+
event.dataTransfer!.setData( type , transfer[ type as keyof typeof transfer] )
1818
}
1919

2020
event.dataTransfer!.setDragImage( this.image() , 0 , -32 )

form/draft/draft.view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace $.$$ {
5757
}
5858

5959
@ $mol_mem_key
60-
override value_number( field: string, next? : boolean | null ) {
60+
override value_number( field: string, next? : number | null ) {
6161
return norm_number( this.value( field, next ) )
6262
}
6363

http/http.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ namespace $ {
6161
}
6262

6363
@ $mol_mem
64-
json< Content >( next? : Content , force? : $mol_mem_force ) : Content {
64+
json< Content >( next? : Content , force? : $mol_mem_force ) {
6565
const next2 = next && JSON.stringify( next , null , '\t' )
66-
return this.response( next2 , force ).json()
66+
return this.response( next2 , force ).json() as Content
6767
}
6868

6969
}

0 commit comments

Comments
 (0)