What about sweet.js renaming top level variables to Typescript output?

Typescript compiles

class ClassName { }

      

to

var ClassName = function () {
    function ClassName() {
    }
    return ClassName;
}();

      

I am running this JS code through sweet.js, which even without macros creates something like this:

var ClassName$659 = function () {
    function ClassName$663() {
    }
    return ClassName$663;
}();

      

I understand that sweet.js would not rename the first occurrence ClassName

if the top level was var

not used, or if a different name was used for the constructor function, but it's the Typescript compiler that does these things, not me.

Why is this a problem

  • I can't use ClassName

    in HTML files anymore . This is not something I want to do often, and of course I will always do without opportunity, but I still miss it.
  • The macros I want to use this far don't require any hygienic renaming. But now it seems to me that I will have to undo the rename with my own script. Source maps won't help easily as I already need a source map for the Typescript -> javascript conversion.

My question

Is there a way to disable hygienic renaming in sweet.js? Is there a better way to deal with this problem?

+3


source to share


2 answers


By using the -readable-names flag with sjs as @AnthonyCalandra suggested I solved my problem.



+2


source


Is there a way to disable hygienic renaming in sweet.js?

Not.

Is there a better way to deal with this problem?



Not sure. As a hack, you can send the file using a script that looks for ClassName $ xxx and then adds

var ClassName = ClassName$xxx;

      

+1


source







All Articles