Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

https://github.com/auth0/jwt-decode

This javascript code (simplified lib/index.js):

`
'use strict';
function InvalidTokenError(message) {}

InvalidTokenError.prototype = new Error();
InvalidTokenError.prototype.name = 'InvalidTokenError';

module.exports = function (token,options) {};

module.exports.InvalidTokenError = InvalidTokenError;
`

is compiled to:

var module$node_modules$jwt_decode$lib$index={}; module$node_modules$jwt_decode$lib$index["default"].InvalidTokenError=function(message){}; module$node_modules$jwt_decode$lib$index["default"].InvalidTokenError.prototype=new Error; module$node_modules$jwt_decode$lib$index["default"].InvalidTokenError.prototype.name="InvalidTokenError"; module$node_modules$jwt_decode$lib$index["default"]=function(token,options){}

It's failing with "Uncaught TypeError: Cannot set property 'InvalidTokenError' of undefined" - second line. In original code the function is exported first and then InvalidTokenError is assigned while in compiled code InvalidTokenError is assigned first to not yet ready "default" property.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2936 (reported by alex+import)
...