File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ if (typeof add_css !== 'undefined' && !document.getElementById(${json(
109109}
110110`
111111
112+ // replace from last occurrence of the splitter
113+ const replaceLast = ( string , splitter , regex , replacer ) => {
114+ const lastIndex = string . lastIndexOf ( splitter )
115+ return (
116+ string . slice ( 0 , lastIndex ) +
117+ string . slice ( lastIndex ) . replace ( regex , replacer )
118+ )
119+ }
120+
112121// https://github.com/darkskyapp/string-hash/blob/master/index.js
113122// (via https://github.com/sveltejs/svelte/blob/91d758e35b2b2154512ddd11e6b6d9d65708a99e/src/compiler/compile/utils/hash.ts#L2)
114123const stringHashcode = str => {
@@ -447,11 +456,13 @@ const createMakeHot = ({ resolveAbsoluteImport, pkg = {} }) => ({
447456 emitCss,
448457 } )
449458
450- return compiledCode . replace (
459+ // NOTE export default can appear in strings in use code
460+ // see: https://github.com/rixo/svelte-hmr/issues/34
461+ return replaceLast (
462+ compiledCode ,
463+ 'export default' ,
451464 / ( \n ? e x p o r t d e f a u l t ( [ ^ ; ] * ) ; ) / ,
452- ( match , $1 , $2 ) => {
453- return replacement . replace ( / \$ 2 / g, ( ) => $2 )
454- }
465+ ( match , $1 , $2 ) => replacement . replace ( / \$ 2 / g, ( ) => $2 )
455466 )
456467 }
457468
You can’t perform that action at this time.
0 commit comments