mathiasbynens / he

A robust HTML entity encoder/decoder written in JavaScript.
https://mths.be/he
MIT License
3.43k stars 255 forks source link

Chrome: Uncaught SyntaxError: Unexpected token '<' in he.js:32 #80

Closed adriespo closed 3 years ago

adriespo commented 3 years ago

Hi, I would like to use he.js in my site, but if I try to embed he.js as a client-side script as stated in the readme:

<script src="he.js"></script>

the Chrome console outputs this error

Chrome: Uncaught SyntaxError: Unexpected token '<' in he.js:32

and breaks, so the variable he is never declared and I can't use the library.

The parser breaks at this code, it's the operator <=%

var decodeMap = <%= decodeMap %>;
var decodeMapLegacy = <%= decodeMapLegacy %>;
var decodeMapNumeric = <%= decodeMapOverrides %>;
var invalidReferenceCodePoints = <%= invalidReferenceCodePoints %>;

Where am I wrong?

mathiasbynens commented 3 years ago

You're trying to use the src/ version. Use the built version at https://github.com/mathiasbynens/he/blob/master/he.js instead.

adriespo commented 3 years ago

Thank you very much! So that file contains some kind of JavaScript to compile! I'm sorry, I'm not familiar with that.

Now it's work perfectly and does what I was searching for. Thank you again.