Code Monkey home page Code Monkey logo

Comments (8)

disnet avatar disnet commented on May 20, 2024

@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?

from sweet-core.

krisselden avatar krisselden commented on May 20, 2024

is there any more thought on this?

from sweet-core.

disnet avatar disnet commented on May 20, 2024

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

from sweet-core.

disnet avatar disnet commented on May 20, 2024

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

from sweet-core.

disnet avatar disnet commented on May 20, 2024

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.

from sweet-core.

disnet avatar disnet commented on May 20, 2024

Should be mostly working with 4f15b50.

from sweet-core.

Domiii avatar Domiii commented on May 20, 2024

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

from sweet-core.

disnet avatar disnet commented on May 20, 2024

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

from sweet-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.