google / google/closure-templates
Cannot read property 'assertType' of undefined when using soyutils.js on soy generated by compileToJsSrc
- Dominant language
- Java
- Stars
- 700
- Forks
- 199
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 26
Description
Take the following template :
```javascript
/**
*
*/
{template .root}
{@param convention: string}
{/template}
```
This template produce this JavaScript file output :
```javascript
if (typeof eca == 'undefined') { var eca = {}; }
if (typeof eca.templates == 'undefined') { eca.templates = {}; }
if (typeof eca.templates.timepicker == 'undefined') { eca.templates.timepicker = {}; }
eca.templates.timepicker.root = function(opt_data, opt_ignored, opt_ijData) {
soy.asserts.assertType(goog.isString(opt_data.convention) || (opt_data.convention instanceof goog.soy.data.SanitizedContent), 'convention', opt_data.convention, 'string|goog.soy.data.SanitizedContent');
var convention = /** @type {string|goog.soy.data.SanitizedContent} */ (opt_data.convention);
return soydata.VERY_UNSAFE.ordainSanitizedHtml('
};
if (goog.DEBUG) {
eca.templates.timepicker.root.soyTemplateName = 'eca.templates.timepicker.root';
}
```
But I am getting this error : Cannot read property 'assertType' of undefined
I am using the soy-2016-08-25 Maven dependency and the latest version of closure-templates-for-javascript via :
> soyutils.js
In soyutils.js I cannot find this function :
`soy.asserts.assertType(...)`
Also I am using jQuery 1.7.2 and latest version of KnockoutJS.
Please could you help me with this ? What I am doing wrong ?
Remarks : I am trying to move from the first version of closure template '1.0' to the latest. I have no errors in my Java side.
On the Java side, here is my code to generate Js from Soy File :
```java
final SoyFileSet soyFileSet = SoyFileSet.builder().add(preparedContent, resource.getName()).add(commonPrepared, common.getName()).build();
if ("soy".equals(type)) {
tofus.put(tofuKey, new SoyTofuOrJavaScript(soyFileSet.compileToTofu()));
} else if ("js".equals(type)) {
final SoyJsSrcOptions jsOpt = new SoyJsSrcOptions();
tofus.put(tofuKey, new SoyTofuOrJavaScript(Joiner.on(';').join(soyFileSet.compileToJsSrc(jsOpt, null))));
}
```
And to render it :
```java
if (Arrays.asList(NEED_CONTENTKIND_JS).contains(templateName)) {
return renderer.setData(data).setContentKind(ContentKind.JS).render();
} else {
return renderer.setData(data).render();
}
```
Thank you very much.
Best regards.
Contributor guide
Assessment
This issue has not been assessed yet.