Skip to content

Commit

Permalink
fix: remove eslint internal traverser (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and mysticatea committed Jun 24, 2019
1 parent c3111fe commit 9efcb6a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/rules/order-in-components.js
Expand Up @@ -5,7 +5,7 @@
'use strict'

const utils = require('../utils')
const Traverser = require('eslint/lib/util/traverser')
const traverseNodes = require('vue-eslint-parser').AST.traverseNodes

const defaultOrder = [
'el',
Expand Down Expand Up @@ -93,9 +93,14 @@ const LOGICAL_OPERATORS = ['&&', '||']
*/
function isNotSideEffectsNode (node, visitorKeys) {
let result = true
new Traverser().traverse(node, {
const noSideEffectsNodes = new Set()
traverseNodes(node, {
visitorKeys,
enter (node, parent) {
enterNode (node, parent) {
if (!result || noSideEffectsNodes.has(node)) {
return
}

if (
node.type === 'FunctionExpression' ||
node.type === 'Identifier' ||
Expand All @@ -105,7 +110,14 @@ function isNotSideEffectsNode (node, visitorKeys) {
node.type === 'TemplateElement'
) {
// no side effects node
this.skip()
noSideEffectsNodes.add(node)
traverseNodes(node, {
visitorKeys,
enterNode (node) {
noSideEffectsNodes.add(node)
},
leaveNode () {}
})
} else if (
node.type !== 'Property' &&
node.type !== 'ObjectExpression' &&
Expand All @@ -121,9 +133,9 @@ function isNotSideEffectsNode (node, visitorKeys) {
) {
// Can not be sure that a node has no side effects
result = false
this.break()
}
}
},
leaveNode () {}
})
return result
}
Expand Down

2 comments on commit 9efcb6a

@hiendv
Copy link

@hiendv hiendv commented on 9efcb6a Jun 24, 2019

Choose a reason for hiding this comment

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

Thank you. Could you please publish the new version now?

@mysticatea
Copy link
Member

Choose a reason for hiding this comment

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

Please sign in to comment.