@@ -3,8 +3,10 @@ import { parse } from "acorn";
33import MagicString from "magic-string" ;
44import { simple as simpleWalk } from "acorn-walk" ;
55
6- const PREAMBLE = `;{ const precompileRegex = (r) => { r.exec('a'); r.exec('\\u1000'); }; ` ;
7- const POSTAMBLE = "; }; " ;
6+ const PREAMBLE = `;{
7+ // Precompiled regular expressions
8+ const precompile = (r) => { r.exec('a'); r.exec('\\u1000'); };` ;
9+ const POSTAMBLE = "}" ;
810
911/// Emit a block of javascript that will pre-compile the regular expressions given. As spidermonkey
1012/// will intern regular expressions, duplicating them at the top level and testing them with both
@@ -35,15 +37,14 @@ export function precompile(source, filename = "<input>") {
3537 transpiledPattern = pattern ;
3638 }
3739 const transpiledRegex = `/${ transpiledPattern } /${ node . regex . flags } ` ;
38- precompileCalls . push ( `precompileRegex (${ transpiledRegex } )` ) ;
40+ precompileCalls . push ( `precompile (${ transpiledRegex } ); ` ) ;
3941 magicString . overwrite ( node . start , node . end , transpiledRegex ) ;
4042 } ,
4143 } ) ;
4244
4345 if ( ! precompileCalls . length ) return source ;
4446
45- // by keeping this a one-liner, source maps will align since they use line offsets
46- magicString . prepend ( `${ PREAMBLE } ${ precompileCalls . join ( ";" ) } ${ POSTAMBLE } ` ) ;
47+ magicString . prepend ( `${ PREAMBLE } ${ precompileCalls . join ( "\n" ) } ${ POSTAMBLE } ` ) ;
4748
4849 // When we're ready to pipe in source maps:
4950 // const map = magicString.generateMap({
0 commit comments