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

Substitutions not working #72

Open
zmorris opened this issue Apr 29, 2018 · 1 comment
Open

Substitutions not working #72

zmorris opened this issue Apr 29, 2018 · 1 comment

Comments

@zmorris
Copy link

zmorris commented Apr 29, 2018

I think there might be a problem with the current version of JSPath, or maybe I'm doing something wrong?

const JSPath = require('jspath');

console.log(JSPath.apply('.$name', {
            'x': 7
        }, {
            name: 'x'
        }));

console.log(JSPath.apply('.x', {
            'x': 7
        }, {
            name: 'x'
        }));

Output:

[]
[ 7 ]

Should be:

[ 7 ]
[ 7 ]

Live demo:

https://repl.it/@ZackMorris1/UnrealisticPrevailingWheel

@zmorris
Copy link
Author

zmorris commented Apr 30, 2018

Found part of the issue, the pattern parser is sensitive to whitespace around the == comparison:

const JSPath = require('jspath');

// works (spaces around ==)
console.log(JSPath.apply('.{.x == $name}', {
            'x': 7
        }, {
            name: 7
        }));

// fails (no spaces around ==)
console.log(JSPath.apply('.{.x==$name}', {
            'x': 7
        }, {
            name: 7
        }));

Output:

[ { x: 7 } ]
Error: Unexpected token "name"
    at throwError (/home/runner/node_modules/jspath/lib/jspath.js:671:21)
    at throwUnexpected (/home/runner/node_modules/jspath/lib/jspath.js:661:9)
    at parsePrimaryExpr (/home/runner/node_modules/jspath/lib/jspath.js:364:16)
    at parseUnaryExpr (/home/runner/node_modules/jspath/lib/jspath.js:342:16)
    at parseMultiplicativeExpr (/home/runner/node_modules/jspath/lib/jspath.js:288:20)
    at parseAdditiveExpr (/home/runner/node_modules/jspath/lib/jspath.js:274:20)
    at parseRelationalExpr (/home/runner/node_modules/jspath/lib/jspath.js:260:20)
    at parseEqualityExpr (/home/runner/node_modules/jspath/lib/jspath.js:241:20)
    at parseEqualityExpr (/home/runner/node_modules/jspath/lib/jspath.js:252:31)
    at parseLogicalANDExpr (/home/runner/node_modules/jspath/lib/jspath.js:223:20)

Live demo:

https://repl.it/@ZackMorris1/DarkorchidThoroughSquare

So I'm also not sure if substitutions can work for node names, which means that the second example JSPath.apply(".$name", { 'hello world': 7 }, {name: 'hello world'}); in #25 probably can't work either. It would be good to update that issue to mention that, since I kind of went on a wild goose chase to get to this issue.

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

1 participant