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

integrate with source maps for good line numbers #13

Closed
disnet opened this issue Sep 16, 2012 · 8 comments
Closed

integrate with source maps for good line numbers #13

disnet opened this issue Sep 16, 2012 · 8 comments

Comments

@disnet
Copy link
Member

disnet commented Sep 16, 2012

It might "just work" with the latest version of escodegen but I have a feeling expansion introduced some problems.

@disnet
Copy link
Member Author

disnet commented Dec 31, 2012

@wycats brought up an interesting idea, to get better line numbers short of the complexity of sourcemaps you can just get smarter about inserting spaces and newlines. For example, a macro that emits a function with line breaks:

macro m {
    case => {
        function foo() {
            return x + 2;
        } 
    }
}
m

could be expanded to:

function foo() { return x + 2; }

This should be easy to do in the expander, just set the lineNumber on each token emitted by a macro expansion to the lineNumber of the invoking macro token (m above).

Going the other way (macro invocation is longer than emitted JS) should be pretty simple:

macro aLongMacroName {
    case => {42}
}
aLongMacroName + 24;

could use loc to expand to:

            42 + 24;

Unfortunately, ASI complicates the process a bit.

macro m {
    case => {
        return
        [1,2,3]
    }
}
m

If we naively expand this while collapsing lines:

return [1,2,3]

we get the wrong result. So the line collapsing needs to be grammar aware (I'm guessing minifiers do the same thing) and insert semicolons at the appropriate points:

return; [1,2,3]

But we still have a problem: return might be a macro. We can't make decisions about the grammar until after full expansion but by then we've lost too much information.

So maybe we can tag each token emitted from a macro with a "potential" collapse line number and do proper semicolon insertion after all macros have been expanded and we have the "real" grammar information?

@krisselden
Copy link

is there any more thought on this?

@disnet
Copy link
Member Author

disnet commented May 29, 2013

This is happening very soon. I'm expecting sourcemaps to land in the next few weeks.

@disnet
Copy link
Member Author

disnet commented Sep 12, 2013

Initial work checked in with 6c4c40c. Still rough atm but sjs -o outfile.js infile.sjs --sourcemap will create outfile.js.map.

disnet added a commit that referenced this issue Nov 20, 2013
mkSyntax no longer puts 0s for line information
if a context is not provided. Line info gets set
correctly after a macro expansion anyway.
@disnet
Copy link
Member Author

disnet commented Nov 21, 2013

Major fixes for this are in commit 3336448 and PR #127. Unless there are any bugs I don't know about sourcemaps should be usable now.

@disnet
Copy link
Member Author

disnet commented Dec 7, 2013

Should be mostly working with 4f15b50.

@disnet disnet closed this as completed Dec 7, 2013
@Domiii
Copy link

Domiii commented May 7, 2014

Any documentation on that? Sadly, the wiki entry is still red. :/

@disnet
Copy link
Member Author

disnet commented May 7, 2014

Use the --sourcemap flag on sjs. Thanks for pointing out the red wiki link, just made it blue :)

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

No branches or pull requests

3 participants