Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps #11

Closed
mathiasbynens opened this issue Sep 6, 2012 · 13 comments
Closed

Source maps #11

mathiasbynens opened this issue Sep 6, 2012 · 13 comments

Comments

@mathiasbynens
Copy link
Contributor

Would be cool if Esmangle could generate Source Maps for minified files. More info here: http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

Is this something that could be considered?

/cc @paulirish

@michaelficarra
Copy link
Member

@mathiasbynens: where have you been? estools/escodegen#50

All that esmangle has to do is preserve the loc property through its transformations.

@paulirish
Copy link

Whoa, that's exciting. Nice work @michaelficarra

@mathiasbynens
Copy link
Contributor Author

@michaelficarra Nice!

@Constellation
Copy link
Member

/cc all

This is a good place to discuss about source-map generation, thanks @mathiasbynens.

Is this something that could be considered?

Yes. Thanks to @michaelficarra, now escodegen can generate source maps.
So in #9, we're considering attaching proper loc information to rewrited node. By this, we can provide mangled & compressed AST to developers. After that, we can get source-maps and code by passing AST to escodegen simply :)
my tweet

@Constellation
Copy link
Member

I've committed initial location copy code.

@michaelficarra
Copy link
Member

Full source map support: 97681bf

@Constellation
Copy link
Member

By passing original location information to generated node, we can get source-map from minified result to original script.

@paulirish
Copy link

@Constellation can you document this in the readme? Specifically the cmd line option?

@michaelficarra
Copy link
Member

@paulirish: What do you mean? Source information is now preserved (unconditionally) through transformations. The difference now is that, when you use escodegen to render the resulting AST as JS, the source information hasn't been lost. So it "just works" when you generate source maps through escodegen.

@paulirish
Copy link

I guess I don't understand the workflow. I'm thinking about using esmangle
as a minifier on javascript (perhaps some created by the redux compiler)

I'm looking at the source-map option:
https://github.com/Constellation/esmangle/blob/6faf12b5ee0da88682720b4f4e45d2a270f591b2/bin/esmangle.js#L43

How are you thinking about escodegen's role here?

On Tue, Nov 27, 2012 at 8:13 PM, Michael Ficarra
notifications@github.comwrote:

@paulirish https://github.com/paulirish: What do you mean? Source
information is now preserved (unconditionally) through transformations. The
difference now is that, when you use escodegen to render the resulting AST
as JS, the source information hasn't been lost. So it "just works" when you
generate source maps through escodegen.


Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-10789081.

@Constellation
Copy link
Member

@paulirish:

I describe design of tools, Esprima, Escodegen and Esmangle.
Those tools roles are simple,

Esprima: input JS code output AST
Escodegen: input AST output JS code
Esmangle: input AST output optimized AST

Escodegen's role is generating JavaScript code or SourceMap from AST.
We can attach location information to Mozilla AST, such as,

    loc: {
        start: { line: 1, column: 0 },
        end: { line: 1, column: 4 }
    }

When sourceMap option is specified to Escodegen, Escodegen generate SourceMap from above location information attached to AST.

And Esmangle preserves this location information through transformation. So if location information is attached to input AST, optimized AST generated by Esmangle also has location information to original source code.

bin/esmangle is JavaScript minifier command line tool consists of Esprima, Escodegen & Esmangle.

@tivac
Copy link

tivac commented Jul 1, 2013

@paulirish Just in case you were still wondering here's an example of how to generate sourcemaps from start to finish using esprima, esmangle, and escodegen. Only part not included is adding the //# line at the end of the compressed source.

http://jsbin.com/omakoh/3/edit

Note: The names array isn't currently populated by escodegen. I've got code for that in estools/escodegen#113

@paulirish
Copy link

Nice! thanks.

On Mon, Jul 1, 2013 at 3:15 PM, Pat Cavit notifications@github.com wrote:

@paulirish https://github.com/paulirish Just in case you were still
wondering here's an example of how to generate sourcemaps from start to
finish using esprima, esmangle, and escodegen. Only part not included is
adding the //# line at the end of the compressed source.

http://jsbin.com/omakoh/3/edit

Note: The names array isn't currently populated by escodegen. I've got
code for that in pull #113


Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-20314507
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants