Coder Social home page Coder Social logo

Support Inline If about blanket HOT 10 CLOSED

alex-seville avatar alex-seville commented on June 30, 2024
Support Inline If

from blanket.

Comments (10)

alex-seville avatar alex-seville commented on June 30, 2024

I guess it depends how complex we do it. I think handling single line if's is the priority for now, and this could be an advanced thing later.

single line if:

if (blah)
   action;
 else
   otheraction;

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

Maybe we can somehow use the parser built into jshint, or copy the code:
https://github.com/jshint/jshint/tree/master/src/next

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

Or better yet, use the parsing of Uglify.js:
https://github.com/mishoo/UglifyJS

from blanket.

dervalp avatar dervalp commented on June 30, 2024

:) +1

On Tue, Oct 16, 2012 at 4:28 PM, Alex Seville [email protected]:

Or better yet, use the parsing of Uglify.js:
https://github.com/mishoo/UglifyJS


Reply to this email directly or view it on GitHubhttps://github.com/Migrii/blanket/issues/16#issuecomment-9491809.

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

These might be of some help:
https://github.com/mishoo/UglifyJS/blob/master/tmp/instrument.js
http://tobyho.com/2012/01/04/fun-with-asts-and-uglify/

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

Okay, I put some test cases into that instrument.js file and got the following results:

// EDGE CASE 1, no bracket for *FAILS* 
        for (var i = 0; i < 5; ++i)
                console.log("foo2");

        // EDGE case 2, no bracket if *FAILS*
        if (true)
            console.log("foo3")

        //EDGE case 3, mis matching the brackets *WORKS*
        if (false){
            console.log("dujh");
        }
        else
        {
            console.log("foo3");
        }

        //EDGE case 4, multi line logical statement *WORKS*
        var out = false ||
            true;
        console.log(out);

        //EDGE case 5, multi line arithmetic *WORKS*
        var lastcase = 12+
                        12+
                        6;
        console.log(lastcase);

So clearly this is a good tool to use. It will help with the parsing of js, except in a few cases. I'll work on getting the "no bracket if/for" issue working, and after that I'll integrate it into the lib/blanket.js file and write some tests.

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

Here are the results of above:

trace("for", 27, 8, 28, 35);
    //FAIL
    for (var i = 0; i < 5; ++i) trace("stat", 28, 16, 28, 35);
    console.log("foo2");
    //FAILEND

    trace("if", 31, 8, 32, 30);

    //FAIL
    if (true) trace("stat", 32, 12, 32, 30);
    console.log("foo3");
    //FAILEND

    trace("if", 35, 8, 41, 8);
    if (false) {
        trace("stat", 36, 12, 36, 31);
        console.log("dujh");
    } else {
        trace("stat", 40, 12, 40, 31);
        console.log("foo3");
    }
    trace("var", 44, 8, 45, 16);
    var out = false || true;
    trace("stat", 46, 8, 46, 24);
    console.log(out);
    trace("var", 49, 8, 51, 25);
    var lastcase = 12 + 12 + 6;
    trace("stat", 52, 8, 52, 29);
    console.log(lastcase);

I've added some extra spacing to clearly show the failing cases.

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

I figured out how to detect if it's an IF (or try, or while, etc...) without brackets, but I don't know how to update the parse tree.

Line 61: https://gist.github.com/3900493

is where this needs to be handled.

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

Nice, I think I got a parser working:
https://gist.github.com/3909508

I threw the ultimate one liner at it, and with a small modification it generates good instrumented code. Now I just need to integrate it into the solution and write tests.

from blanket.

alex-seville avatar alex-seville commented on June 30, 2024

I think I've resolved all these issues now.

from blanket.

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.