     @styleElementsBySourcePath[sourcePath] ?= styleElement if sourcePath?
     @emitter.emit 'did-add-style-element', styleElement
 
-  removeStyleElement: (styleElement, params) ->
+  removeStyleElement: (styleElement) ->
     index = @styleElements.indexOf(styleElement)
     unless index is -1
       @styleElements.splice(index, 1)
-      if sourcePath = styleElement.getAttribute('source-path')
-        delete @styleElementsBySourcePath[sourcePath]
+      delete @styleElementsBySourcePath[styleElement.sourcePath] if styleElement.sourcePath?
       @emitter.emit 'did-remove-style-element', styleElement
 
   getSnapshot: ->


    existingStyleElements = @getStyleElements()
    for styleElement in styleElementsToRestore
      unless styleElement in existingStyleElements
        sourcePath = styleElement.getAttribute('source-path')
        group = styleElement.getAttribute('group')
        @addStyleElement(styleElement, {sourcePath, group})

      updated = true
    else
      styleElement = document.createElement('style')
      if sourcePath?
        styleElement.sourcePath = sourcePath
        styleElement.setAttribute('source-path', sourcePath)

      if context?
        styleElement.context = context
        styleElement.setAttribute('context', context)

      if group?
        styleElement.group = group
        styleElement.setAttribute('group', group)

    styleElement.textContent = source

    if updated
      @emitter.emit 'did-update-style-element', styleElement
    else
      @addStyleElement(styleElement)

    new Disposable => @removeStyleElement(styleElement)

  addStyleElement: (styleElement) ->
    {sourcePath, group} = styleElement

    if group?
      for existingElement, index in @styleElements
        if existingElement.group is group
          insertIndex = index + 1
        else
          break if insertIndex?
