diff --git a/tree2/js/to/text/text.ts b/tree2/js/to/text/text.ts index 5453d9f0ab3..f308674cad6 100644 --- a/tree2/js/to/text/text.ts +++ b/tree2/js/to/text/text.ts @@ -1,5 +1,10 @@ namespace $ { + function is_identifier( tree: $mol_tree2 ) { + if( tree.type ) return false + return /^[a-z_$][a-z_$0-9]*$/i.test( tree.text() ) + } + export function $mol_tree2_js_to_text( this: $, js: $mol_tree2 ) { function sequence( open?: string, separator?: string, close?: string ) { @@ -123,21 +128,19 @@ namespace $ { '[]': ( input, belt )=> { const first = input.kids[0] - if( first.type ) return sequence( '[', '', ']' )( input, belt ) + if( !is_identifier( first ) ) return sequence( '[', '', ']' )( input, belt ) else return [ input.data( '.' + first.text() ) ] }, '?.[]': ( input, belt )=> { const first = input.kids[0] - if( first.type ) return sequence( '?.[', '', ']' )( input, belt ) + if( !is_identifier( first ) ) return sequence( '?.[', '', ']' )( input, belt ) else return [ input.data( '?.' + first.text() ) ] }, - ':': ( input, belt )=> { - const first = input.kids[0] - if( first.type ) return duplet( '[', ']: ' )( input, belt ) - else return duplet( '', ': ' )( input, belt ) - }, + ':': ( input, belt )=> input.kids[0].type + ? duplet( '[', ']: ' )( input, belt ) + : duplet( '', ': ' )( input, belt ), 'let': duplet( 'let ', ' = ' ), 'const': duplet( 'const ', ' = ' ), @@ -174,7 +177,7 @@ namespace $ { '.': ( input, belt )=> { const first = input.kids[0] - if( first.type ) return triplet( '[', ']' )( input, belt ) + if( !is_identifier( first ) ) return triplet( '[', ']' )( input, belt ) else return [ input.data( first.text() ), ... input.list( input.kids.slice(1) ).hack( belt ), diff --git a/wasm/module/module.ts b/wasm/module/module.ts index 947d8eaeeb7..6cfa132883b 100644 --- a/wasm/module/module.ts +++ b/wasm/module/module.ts @@ -5,7 +5,7 @@ namespace $ { native : WebAssembly.Module constructor( - readonly buffer : ArrayBuffer + readonly buffer : Uint8Array ) { super() this.native = new WebAssembly.Module( buffer )