File tree Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -931,7 +931,7 @@ function compile(
931
931
isrc = reader ( imports [ i ] ) ;
932
932
}
933
933
targ =
934
- `/*___wenyan_import_ ${ imports [ i ] } _start___*/` +
934
+ `/*___wenyan_module_ ${ imports [ i ] } _start___*/` +
935
935
mwrapper (
936
936
imports [ i ] ,
937
937
compile ( lang , isrc , {
@@ -942,7 +942,7 @@ function compile(
942
942
lib
943
943
} )
944
944
) +
945
- `/*___wenyan_import_ ${ imports [ i ] } _end___*/` +
945
+ `/*___wenyan_module_ ${ imports [ i ] } _end___*/` +
946
946
targ ;
947
947
}
948
948
Original file line number Diff line number Diff line change @@ -18,6 +18,36 @@ for (var i = 0; i < files.length; i++) {
18
18
var lib = utils . loadlib ( ) ;
19
19
20
20
function main ( ) {
21
+ function hideImportedModules ( source ) {
22
+ const markerRegex = / \/ \* _ _ _ w e n y a n _ m o d u l e _ ( [ \s \S ] + ?) _ ( s t a r t | e n d ) _ _ _ \* \/ / g;
23
+ const matches = [ ] ;
24
+
25
+ var match ;
26
+ while ( ( match = markerRegex . exec ( source ) ) ) {
27
+ if ( ! match ) break ;
28
+
29
+ if ( matches . length ) {
30
+ const prev = matches [ matches . length - 1 ] ;
31
+ if ( prev [ 2 ] !== "end" && prev [ 1 ] !== match [ 1 ] ) continue ; // ignore nested imports
32
+ }
33
+
34
+ matches . push ( match ) ;
35
+ }
36
+
37
+ for ( const match of matches ) {
38
+ if ( match [ 2 ] === "start" ) continue ;
39
+
40
+ source = source . replace (
41
+ new RegExp (
42
+ `\\/\\*___wenyan_module_${ match [ 1 ] } _start___\\*\\/[\\s\\S]*\\/\\*___wenyan_module_${ match [ 1 ] } _end___\\*\\/`
43
+ ) ,
44
+ `/* module ${ match [ 1 ] } is hidden */\n`
45
+ ) ;
46
+ }
47
+
48
+ return source ;
49
+ }
50
+
21
51
var ed = newEditor ( prgms [ "mandelbrot" ] ) ;
22
52
// var ln = newLineNo(ed);
23
53
@@ -92,14 +122,7 @@ function main() {
92
122
reader : x => prgms [ x ]
93
123
} ) ;
94
124
95
- var showcode = code ;
96
-
97
- if ( hidestd . checked ) {
98
- showcode = showcode . replace (
99
- / \/ \* _ _ _ w e n y a n _ i m p o r t _ ( [ \s \S ] + ?) _ s t a r t _ _ _ \* \/ ( [ \s \S ] * ?) \/ \* _ _ _ w e n y a n _ i m p o r t _ ( [ \s \S ] + ?) _ e n d _ _ _ \* \/ / g,
100
- "/* module $1 is hidden */\n"
101
- ) ;
102
- }
125
+ var showcode = hidestd . checked ? hideImportedModules ( code ) : code ;
103
126
104
127
document . getElementById ( "js" ) . innerText = js_beautify ( showcode ) ;
105
128
hljs . highlightBlock ( document . getElementById ( "js" ) ) ;
You can’t perform that action at this time.
0 commit comments