@@ -21,8 +21,9 @@ const UNKNOWN = Symbol('unknown');
2121/** Includes `BigInt` */
2222export const NUMBER = Symbol ( 'number' ) ;
2323export const STRING = Symbol ( 'string' ) ;
24+ /** @typedef {NUMBER | STRING | UNKNOWN | undefined | boolean } TYPE */
2425
25- /** @type {Record<string, [type: NUMBER | STRING | UNKNOWN , fn?: Function]> } */
26+ /** @type {Record<string, [type: TYPE | TYPE[] , fn?: Function]> } */
2627const globals = {
2728 BigInt : [ NUMBER , BigInt ] ,
2829 'Date.now' : [ NUMBER ] ,
@@ -98,7 +99,7 @@ function call_bind(fn) {
9899const string_proto = String . prototype ;
99100const number_proto = Number . prototype ;
100101
101- /** @type {Record<string, Record<string, [type: NUMBER | STRING | UNKNOWN , fn?: Function]>> } */
102+ /** @type {Record<string, Record<string, [type: TYPE | TYPE[] , fn?: Function]>> } */
102103const prototype_methods = {
103104 string : {
104105 //@ts -ignore
@@ -109,14 +110,32 @@ const prototype_methods = {
109110 at : [ STRING , call_bind ( string_proto . at ) ] ,
110111 charAt : [ STRING , call_bind ( string_proto . charAt ) ] ,
111112 trim : [ STRING , call_bind ( string_proto . trim ) ] ,
112- indexOf : [ STRING , call_bind ( string_proto . indexOf ) ]
113+ indexOf : [ NUMBER , call_bind ( string_proto . indexOf ) ] ,
114+ charCodeAt : [ NUMBER , call_bind ( string_proto . charCodeAt ) ] ,
115+ codePointAt : [ [ NUMBER , undefined ] , call_bind ( string_proto . codePointAt ) ] ,
116+ startsWith : [ [ true , false ] , call_bind ( string_proto . startsWith ) ] ,
117+ endsWith : [ [ true , false ] , call_bind ( string_proto . endsWith ) ] ,
118+ isWellFormed : [ [ true , false ] , call_bind ( string_proto . isWellFormed ) ] ,
119+ lastIndexOf : [ NUMBER , call_bind ( string_proto . lastIndexOf ) ] ,
120+ normalize : [ STRING , call_bind ( string_proto . normalize ) ] ,
121+ padEnd : [ STRING , call_bind ( string_proto . padEnd ) ] ,
122+ padStart : [ STRING , call_bind ( string_proto . padStart ) ] ,
123+ repeat : [ STRING , call_bind ( string_proto . repeat ) ] ,
124+ substring : [ STRING , call_bind ( string_proto . substring ) ] ,
125+ trimEnd : [ STRING , call_bind ( string_proto . trimEnd ) ] ,
126+ trimStart : [ STRING , call_bind ( string_proto . trimStart ) ] ,
127+ toWellFormed : [ STRING , call_bind ( string_proto . toWellFormed ) ] ,
128+ //@ts -ignore
129+ valueOf : [ STRING , call_bind ( string_proto . valueOf ) ]
113130 } ,
114131 number : {
115132 //@ts -ignore
116133 toString : [ STRING , call_bind ( number_proto . toString ) ] ,
117134 toFixed : [ NUMBER , call_bind ( number_proto . toFixed ) ] ,
118135 toExponential : [ NUMBER , call_bind ( number_proto . toExponential ) ] ,
119- toPrecision : [ NUMBER , call_bind ( number_proto . toPrecision ) ]
136+ toPrecision : [ NUMBER , call_bind ( number_proto . toPrecision ) ] ,
137+ //@ts -ignore
138+ valueOf : [ NUMBER , call_bind ( number_proto . valueOf ) ]
120139 }
121140} ;
122141export class Binding {
@@ -494,7 +513,13 @@ class Evaluation {
494513 if ( fn && values . every ( ( e ) => e . is_known ) ) {
495514 this . values . add ( fn ( ...values . map ( ( e ) => e . value ) ) ) ;
496515 } else {
497- this . values . add ( type ) ;
516+ if ( Array . isArray ( type ) ) {
517+ for ( const t of type ) {
518+ this . values . add ( t ) ;
519+ }
520+ } else {
521+ this . values . add ( type ) ;
522+ }
498523 }
499524
500525 break ;
@@ -536,13 +561,18 @@ class Evaluation {
536561 prototype_methods [ /** @type {'string' | 'number' } */ ( typeof object . value ) ] ;
537562 if ( Object . hasOwn ( available_methods , property ) ) {
538563 const [ type , fn ] = available_methods [ property ] ;
539- console . log ( [ type , fn ] ) ;
540564 const values = expression . arguments . map ( ( arg ) => scope . evaluate ( arg ) ) ;
541565
542566 if ( fn && values . every ( ( e ) => e . is_known ) ) {
543567 this . values . add ( fn ( object . value , ...values . map ( ( e ) => e . value ) ) ) ;
544568 } else {
545- this . values . add ( type ) ;
569+ if ( Array . isArray ( type ) ) {
570+ for ( const t of type ) {
571+ this . values . add ( t ) ;
572+ }
573+ } else {
574+ this . values . add ( type ) ;
575+ }
546576 }
547577 break ;
548578 }
0 commit comments