Skip to content

Update deps and adds some useful API documentation - #49

Open
kristianmandrup wants to merge 7 commits into
estools:masterfrom
kristianmandrup:master
Open

Update deps and adds some useful API documentation#49
kristianmandrup wants to merge 7 commits into
estools:masterfrom
kristianmandrup:master

Conversation

@kristianmandrup

Copy link
Copy Markdown

Please review and merge ;)

@michaelficarramichaelficarra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're going to need more comprehensive tests for :has. I've left a bunch of comments and will do a follow-up review once they're addressed.

Comment threadAPI usage.md Outdated

*Install (via npm for Node.js)*

`npm i esquery --save`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I strongly prefer installation documentation to use npm install .... There's no reason to use shorthand in documentation.

Comment threadAPI usage.md Outdated
```js
const esquery = require('esquery');

const conditional = "if (x === 1) { foo(); } else { x = 2; }"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use single quotes or double quotes, but not both.

Comment threadAPI usage.md Outdated
`[name="x"]:function` - function named `x`
`[name="foo"]:declaration` - declaration named `foo`

## Complex

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Combinators

Comment threadAPI usage.md Outdated
- adjacent sibling selector (`+`)
- general sibling selector (`~`)

Please see [javascript: expressions-vs-statements](http://www.2ality.com/2012/09/expressions-vs-statements.html)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure how this is related. Instead, one should see the estree specification.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You might also want to point them to the CSS documentation because these combinators are both syntactically and semantically identical.

Comment threadAPI usage.md Outdated

Please see [javascript: expressions-vs-statements](http://www.2ality.com/2012/09/expressions-vs-statements.html)

`IfStatement > BinaryExpression` - `if` statement followed by a [binary expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators) fx `3+4` or `x*y`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, a BinaryExpression nested directly within an IfStatement.

Comment threadAPI usage.md Outdated

`VariableDeclaration ~ IfStatement`

`var` declaration with sibling `if` statement

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if statement with sibling var declaration. The if statement is the target.

Comment threadAPI usage.md Outdated

### Fields

You can also query on the [Mozilla Parser API](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API) fields directly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This link should be updated to estree.

Comment threadAPI usage.md Outdated

### Subject

`!IfStatement Identifier` - any not an If statement with an Identifier under, such as `const x = 3` but not `if (x == 2)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any not an If statement with an Identifier under

any if statement with one or more nested Identifier

Comment threadAPI usage.md Outdated

`!IfStatement Identifier` - any not an If statement with an Identifier under, such as `const x = 3` but not `if (x == 2)`

`!* > [name="foo"]` all nodes but those where the immediate child is a node namded `foo`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

namded -> named

Comment threadAPI usage.md Outdated
- `!:matches(*) > [name="foo"]`
- `!:not(BlockStatement) > [name="foo"]`
- `![left.name="x"][right.value=1]`
- `* !AssignmentExpression`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is a productive example. What is it trying to show off?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Please do whatever it takes to add sufficient docs for how to use the API. I tried my best using the tests cases for inspiration.

@QardQard mentioned this pull request Apr 11, 2017
@jkjustjoshing

Copy link
Copy Markdown

@kristianmandrup I hope you update the PR based on the feedback and help get this merged in - I found this document extremely helpful in understanding how to use esquery!

@kristianmandrup

Copy link
Copy Markdown
Author

Hey! I would be grateful if you would get it merged. Thanks!

@kristianmandrup

Copy link
Copy Markdown
Author

I made all the fixes as per your suggestions. Please review this PR again and let's make a good API documentation :)

@michaelficarra

Copy link
Copy Markdown
Member

@kristianmandrup It seems your branch has fallen behind. You should rebase on this repo's master branch. You can also use the GitHub web UI to resolve the conflicts with a commit.

Comment threadpackage.json
"name": "esquery",
"preferGlobal": false,
"version": "0.4.0",
"version": "0.4.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't bump the version. We'll bump it appropriately during a release.

Sign up for freeto 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.

5 participants

@kristianmandrup@jkjustjoshing@michaelficarra@GerHobbelt@nwronski