@@ -24,21 +24,23 @@ function compile(script) {
24
24
script = script . replaceAll ( '+\n' , '+' )
25
25
script = script . replaceAll ( ' == ' , ' === ' )
26
26
script = script . replaceAll ( '.index(' , '.indexOf(' )
27
- script = script . replaceAll ( ' self.' , ' this.' )
28
- script = script . replaceAll ( '(self.' , '(this.' )
27
+ // script = script.replaceAll(' self.', ' this.')
28
+ // script = script.replaceAll('(self.', '(this.')
29
29
// script = script.replaceAll('(self.', '(this.')
30
30
31
- var all_lines = script . split ( '\n' ) ;
31
+ var all_lines = script . split ( '\n' )
32
32
var lines = [ ]
33
33
lines . push ( '\n' )
34
34
35
35
strings = [ ]
36
36
string_index = 0
37
- const regexp = '\'(.*?)\'' ;
38
- const regexp_backtick = '\`(.*?)\`' ;
37
+ const regexp = '\'(.*?)\''
38
+ const regexp_backtick = '\`(.*?)\`'
39
39
40
40
extra_replacements = [ ]
41
- is_in_multiline_string = false ;
41
+ is_in_multiline_string = false
42
+
43
+ prev_created_variable = null // for storing the recently defined variable starting with $, so it can be references with '_.'
42
44
43
45
for ( var i = 0 ; i < all_lines . length ; i ++ ) {
44
46
if ( ! all_lines [ i ] . trim ( ) ) {
@@ -266,7 +268,23 @@ function compile(script) {
266
268
lines [ i ] = lines [ i ] . replace ( '```' , '``)' )
267
269
}
268
270
271
+ if ( lines [ i ] . startsWith ( '$' ) ) {
272
+ prev_created_variable = lines [ i ] . substring ( 1 ) . split ( '=' ) [ 0 ] . trimEnd ( )
273
+ lines [ i ] = lines [ i ] . split ( '$' ) [ 1 ]
274
+ }
275
+ else if ( lines [ i ] . includes ( '_.' ) && prev_created_variable ) {
276
+ // indent = get_indent(lines[i])
277
+ // start = ' '.repeat(indent)
278
+ // end = lines[i].trimStart().substring(1)
279
+ // end = end.replaceAll('_.', prev_created_variable)
280
+ // print('---:', lines[i].trimStart().substring(1))
281
+
282
+ // lines[i] = start + prev_created_variable + end
283
+ lines [ i ] = lines [ i ] . replaceAll ( '_.' , prev_created_variable + '.' )
284
+ lines [ i ] = lines [ i ] . replaceAll ( '_,' , prev_created_variable + ',' )
285
+ }
269
286
287
+ // convert dict(...) to {...}
270
288
for ( var class_name of [ 'dict' , ] ) {
271
289
if ( lines [ i ] . includes ( `${ class_name } ({` ) ) {
272
290
continue
@@ -276,6 +294,7 @@ function compile(script) {
276
294
}
277
295
}
278
296
297
+ // add 'new' in front of class initializations
279
298
for ( var class_name of _class_names ) {
280
299
is_first_word = lines [ i ] . startsWith ( `${ class_name } (` ) ? '' : ' ' // don't add space if line starts with 'Entity(', do add otherwise, to ensure we match the whole name
281
300
if ( lines [ i ] . includes ( `${ is_first_word } ${ class_name } (` ) ) {
@@ -287,6 +306,8 @@ function compile(script) {
287
306
}
288
307
}
289
308
309
+
310
+ // units
290
311
for ( var n = 0 ; n < 10 ; n ++ ) {
291
312
lines [ i ] = lines [ i ] . replaceAll ( `${ n } ms` , `${ n } *.001` )
292
313
lines [ i ] = lines [ i ] . replaceAll ( `${ n } s` , `${ n } ` )
0 commit comments