@@ -31,14 +31,22 @@ const PREAMBLE = `;{
31
31
const precompile = (r) => { r.exec('a'); r.exec('\\u1000'); };` ;
32
32
const POSTAMBLE = "}" ;
33
33
34
+ // TODO: This should also detect and update sourcemaps if they are present, otherwise the sourcemaps would be incorrect.
35
+ //
34
36
/// Emit a block of javascript that will pre-compile the regular expressions given. As spidermonkey
35
37
/// will intern regular expressions, duplicating them at the top level and testing them with both
36
38
/// an ascii and utf8 string should ensure that they won't be re-compiled when run in the fetch
37
39
/// handler.
38
- function precompile ( literals ) {
40
+ function precompile ( inputApplication ) {
41
+ let lits = findRegexLiterals ( inputApplication ) ;
42
+
43
+ if ( lits . length === 0 ) {
44
+ return inputApplication ;
45
+ }
46
+
39
47
return (
40
48
PREAMBLE +
41
- literals
49
+ lits
42
50
. map ( ( regex ) => {
43
51
return `precompile(/${ regex . pattern } /${ regex . flags } );` ;
44
52
} )
@@ -113,11 +121,7 @@ export async function compileApplicationToWasm(input, output, wasmEngine) {
113
121
process . exit ( 1 ) ;
114
122
}
115
123
116
- let lits = findRegexLiterals ( inputContents ) ;
117
-
118
- if ( lits . length != 0 ) {
119
- inputContents += precompile ( lits ) ;
120
- }
124
+ let application = precompile ( inputContents ) ;
121
125
122
126
try {
123
127
let wizerProcess = spawnSync (
@@ -131,7 +135,7 @@ export async function compileApplicationToWasm(input, output, wasmEngine) {
131
135
] ,
132
136
{
133
137
stdio : [ null , process . stdout , process . stderr ] ,
134
- input : inputContents ,
138
+ input : application ,
135
139
shell : true ,
136
140
encoding : "utf-8" ,
137
141
}
0 commit comments