File size: 563 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * Injects a `{}*` CSS rule to force Svelte compiler to scope every elements.
 */
export const injectScopeEverythingCssRule = (parse, code) => {
  const { css } = parse(code)
  if (!css) return code
  const {
    content: { end },
  } = css
  return code.slice(0, end) + '*{}' + code.slice(end)
}

export const normalizeJsCode = code => {
  // Svelte now adds locations in dev mode, code locations can change when
  // CSS change, but we're unaffected (not real behaviour changes)
  code = code.replace(/\badd_location\s*\([^)]*\)\s*;?/g, '')
  return code
}