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

Add lexical validation for variable not present #5

Conversation

ShubhamUniyal
Copy link

No description provided.

test/syntax.js Outdated
expect(validateExp('y<!2', scope)).to.deep.equal(["y variable not present", "cannot eval '!2' as value"]);
})

it('should validate complex expression', function () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about checking that y is present and all..?

src/syntax.js Outdated
@@ -2,6 +2,8 @@ const operators = require('./operators.js')(isTruthy)
const lexical = require('./lexical.js')
const assert = require('../src/util/assert.js')

const listOfOperators= ["=","!", "<", ">", "contains", "and", "or" ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already defined as lexical.operators

also seems unused

for (var i = 0; i < operatorREs.length; i++) {
var operatorRE = operatorREs[i]
var expRE = new RegExp(`^(${lexical.quoteBalanced.source})(${operatorRE.source})(${lexical.quoteBalanced.source})$`)
if ((match = exp.match(expRE))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u autoformat this new code only?

like theres double (( here for no reason

var match;
for (var i = 0; i < operatorREs.length; i++) {
var operatorRE = operatorREs[i]
var expRE = new RegExp(`^(${lexical.quoteBalanced.source})(${operatorRE.source})(${lexical.quoteBalanced.source})$`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant use template strings - this does not go through a transpiler

if(scope.get(str) !== undefined && scope.get(str) !== null) {
return;
} else {
return `${str} variable not present`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use template strings?

i am not sure if they are safe. if we were using them before then you can keep them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we were using template strings in this module before.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK LGTM format if possible

@ankit886 ankit886 merged commit dc59ece into SpotDraft:master Jul 25, 2018
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

Successfully merging this pull request may close these issues.

3 participants