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

Destructuring assignment syntax support #161

Open
hyllee opened this issue Dec 1, 2020 · 3 comments
Open

Destructuring assignment syntax support #161

hyllee opened this issue Dec 1, 2020 · 3 comments

Comments

@hyllee
Copy link

hyllee commented Dec 1, 2020

Unhandled exception from array destructuring assignment

Destructuring assignment syntax is not supported and results in an exception in version v0.2.6. This results in the instrumentor to crash and not produce any outputs.

let a;
let b;
let c = [1,2];

[a, b] = c;

Stack trace:

Failed to instrument let a;
let b;
let c = [1,2];

[a, b] = c;

/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/esnstrument.js:1952
                throw ex;
                ^

TypeError: Cannot read property 'name' of undefined
    at getPropertyAsAst (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/esnstrument.js:1103:76)
    at instrumentStore (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/esnstrument.js:1134:56)
    at Object.AssignmentExpression (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/esnstrument.js:1448:24)
    at transformAst (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/astUtil.js:152:36)
    at transformAst (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/astUtil.js:145:39)
    at transformAst (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/astUtil.js:145:39)
    at Object.transformAst (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/astUtil.js:145:39)
    at transformString (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/esnstrument.js:1871:30)
    at instrumentCode (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/instrument/esnstrument.js:1943:30)
    at instrumentFile (/home/hyllee/gelato/core/node_modules/jalangi2/src/js/commands/esnstrument_cli.js:191:31)

Invalid code generated from object destructuring assignment

Another issue with destructuring assignment where it does not throw an exception but outputs syntactically invalid code:

const f = ({ var: e }) => console.log(e);
f({ var: 5 });

which is transformed into something in the likes of the following:

            const f = J$.X1(57, J$.W(49, 'f', ({
                J$.R(9, 'var', var, 2): J$.R(17, 'e', e, 2)
            }) => J$.M(41, J$.R(25, 'console', console, 2), 'log', 0)(J$.R(33, 'e', e, 2)), f, 3));
            J$.X1(97, J$.F(89, J$.R(65, 'f', f, 1), 0)(J$.T(81, {
                var: J$.T(73, 5, 22, false)
            }, 11, false)));

This, when run, results in a syntax error at line 2: Uncaught SyntaxError: Unexpected token '.'

@msridhar
Copy link
Contributor

msridhar commented Dec 1, 2020

@hyllee most features introduced in ECMAScript 2015 and after are not support by Jalangi. Can you run your code through Babel first and then run the result through Jalangi?

@behnazh-w
Copy link

behnazh-w commented Dec 1, 2020

@msridhar thanks for the suggestion. Indeed we are also trying to use Babel for ECMAScript 2015 features. But given the complexity of our applications, that might not be the solution at the end. Apart from that, we didn't expect unhandled exceptions in Jalangi2 due to lack of support for a feature. We have noticed that the 0.2.5 release does not throw the exception. So it could possibly be due to a change in 0.2.6?

In general, I think it would make sense to make sure the unsupported features don't get instrumented and the code runs correctly.

@msridhar
Copy link
Contributor

msridhar commented Dec 1, 2020

In 0.2.6 I updated some dependencies (like the acorn parser) from extremely old versions. It's possible that's what caused the problem. I agree it would be great if Jalangi at least didn't break code with unsupported features. I would welcome a PR here to fix this issue. All the instrumentation code is in this file. It would take a bit of time to understand but shouldn't be too bad. I am happy to explain parts that are tricky.

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

3 participants