jleyba / js-dossier

A JavaScript documentation generation tool.
Apache License 2.0
149 stars 15 forks source link

error when a method name starts with "$" #99

Open myphysicslab opened 7 years ago

myphysicslab commented 7 years ago

An error occurs when navigating back to a page when the open card was for a method/function whose name starts with "$".

Here are steps to reproduce. I've done this on Mac OS X with Safari and Chrome.

  1. go to https://google.github.io/closure-library/api/goog.dom.DomHelper.html

  2. click one of the methods whose name start with "$" such as $dom. This opens the function "card".

  3. scroll down to getDocumentScroll(). (The $dom function should no longer be visible).

  4. click on goog.math.Coordinate to load that page.

  5. click the "back" browser button.

Result: you wind up back on the DomHelper page, but the $dom method is not open as it should be. In the Chrome browser console is this error message and stack:

dossier.js:36 Uncaught DOMException: Failed to execute 'querySelector' on 'Element': '#$dom'
is not a valid selector.
    at https://google.github.io/closure-library/api/dossier.js:214:161
    at Array.forEach (native)
    at lh (https://google.github.io/closure-library/api/dossier.js:214:134)
    at https://google.github.io/closure-library/api/dossier.js:214:390
    at e.c (https://google.github.io/closure-library/api/dossier.js:45:101)
    at nc (https://google.github.io/closure-library/api/dossier.js:48:195)
    at ic (https://google.github.io/closure-library/api/dossier.js:48:85)
    at C.l (https://google.github.io/closure-library/api/dossier.js:47:311)
    at Ob (https://google.github.io/closure-library/api/dossier.js:40:42)
    at <anonymous>

The error is occuring in the querySelector call in updatePageContent

  updatePageContent(data, snapshot, opt_path) {
    let newTitle = soy.renderAsFragment(pageTitle, {data});
    let newMain = soy.renderAsFragment(mainPageContent, {data});

    this.mainEl.innerHTML = '';
    this.mainEl.appendChild(newMain);
    document.title = newTitle.textContent;

    if (snapshot) {
      snapshot.getOpenCardList().forEach(id => {
        let card = this.mainEl.querySelector(`#${id.replace(/\./g, '\\.')}`);
        if (card) {
          card.classList.add('open');
        }
      });
      this.mainEl.parentElement.scrollTop = snapshot.getScroll();
    } else {
      this.mainEl.parentElement.scrollTop = 0;
    }

    if (opt_path) {
      this.historyService_.captureSnapshot(document.title, opt_path);
    }

    this.initProperties();
    this.updateSourceHighlight();
    this.navDrawer.updateCurrent();
  }