jleyba / js-dossier

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

errors when running simple-compiled #100

Open myphysicslab opened 7 years ago

myphysicslab commented 7 years ago

When Dossier is compiled using compilation_level = "SIMPLE" (instead of ADVANCED) in two places in src/js/BUILD, then this runtime error:

Exception with thrown value: TypeError: Right hand side of instanceof is not an object.

The problem occurs in code generated from this template in dossier.soy

/**
 * Renders a single row in an info table.
 */
{template .infoRow private="true"}
  {@param? title: html}
  {@param cell1: html}
  {@param? cell1Attributes: attributes}
  {@param? cell2: html}
  {@param? cell2Attributes: attributes}
  {@param? id: string}
  {@param? block: bool}

  <tr class="info-row{if $block} block{/if}" {if $id}id="{$id}"{/if}>
    {if $title}<th class="info-head">{$title}</th>{/if}
    <td class="info-cell" {if $cell1Attributes}{$cell1Attributes}{/if}>{$cell1}</td>
    {if $cell2}
      <td class="info-cell" {if $cell2Attributes}{$cell2Attributes}{/if}>{$cell2}</td>
    {/if}
  </tr>
{/template}

when simple-compiled, the above becomes (in part)

soydata.SanitizedHtmlAttribute || a.cell1Attributes instanceof soydata.UnsanitizedText || 
goog.isString(a.cell1Attributes), "cell1Attributes", a.cell1Attributes, "?
soydata.SanitizedHtmlAttribute|string|undefined");

The problem is there is no property soydata.UnsanitizedText. Similarly, there is also no property soydata.SanitizedHtmlAttribute which cause similar problems later on.

Workaround: Perform the following text replacements after compilation in the resulting output file dossier.js

using regular expressions:

find: soydata\.(UnsanitizedText|SanitizedHtmlAttribute)

replace: goog.soy.data.$1

jleyba commented 7 years ago

I cannot reproduce this at head:

$ bazel build //src/js:dossier_simple
INFO: Found 1 target...
Target //src/js:dossier_simple up-to-date:
  bazel-bin/src/js/dossier_simple.js
  bazel-bin/src/js/dossier_simple.js.map
INFO: Elapsed time: 0.158s, Critical Path: 0.00s