Skip to content

Error thrown on nth-child with ExperimentalSpreadSyntax #67

Description

@aduth

Minimal reproduceable example:

https://astexplorer.net/#/gist/e0fb7d08090a532c3cdce571593671b2/622c0d4fed220a6b8d6655f0f746916aeb8bfb60

The :nth-child selector throws an error if object spread syntax (type of ExperimentalSpreadSyntax) is encountered.

Stack trace:

> eslint .

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at nthChild (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/esquery/esquery.js:256:34)
    at matches (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/esquery/esquery.js:158:25)
    at Function.matches (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/esquery/esquery.js:103:25)
    at NodeEventGenerator.applySelector (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/util/node-event-generator.js:250:21)
    at NodeEventGenerator.applySelectors (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/util/node-event-generator.js:278:22)
    at NodeEventGenerator.enterNode (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at Traverser.enter [as _enter] (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/linter.js:1006:32)
    at Traverser._traverse (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/util/traverser.js:132:14)
    at Traverser._traverse (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/node_modules/eslint/lib/util/traverser.js:147:30)

Throwing line:

for (i = 0, l = keys.length; i < l; ++i) {

Real-world use-case:

I am trying to create a no-restricted-syntax ESLint rule for forbidding all but ArrayExpression as the second argument of Lodash methods which accept path argument:

CallExpression[callee.name=/^(invokeMap|get|has|hasIn|invoke|result|set|setWith|unset|update|updateWith)$/] > :not(ArrayExpression):nth-child(2)

This works in isolated usage:

https://astexplorer.net/#/gist/e0fb7d08090a532c3cdce571593671b2/b70d4572529d872e27f8c3df62c4ce0be43dba88

...but with above error, fails with the object spread syntax.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions