Skip to content

Commit

Permalink
Drop use of isVarWithRequireCalls from RequireDetector
Browse files Browse the repository at this point in the history
Just use simple node.type comparison and make the matchers for
the specific require-s more specific.

Refs #33
  • Loading branch information
nene committed Sep 18, 2016
1 parent 4e690d8 commit 4ddb447
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/transform/class/inheritance/RequireDetector.js
@@ -1,6 +1,5 @@
import _ from 'lodash';
import {isAstMatch, matchesLength} from '../../../utils/matchesAst';
import isVarWithRequireCalls from '../../../utils/isVarWithRequireCalls';

/**
* Detects variable name imported from require("util")
Expand All @@ -13,7 +12,7 @@ export default class RequireDetector {
* @return {Object} Identifier
*/
detectUtil(node) {
if (!isVarWithRequireCalls(node)) {
if (node.type !== 'VariableDeclaration') {
return undefined;
}

Expand All @@ -28,7 +27,7 @@ export default class RequireDetector {
* @return {Object} Identifier
*/
detectUtilInherits(node) {
if (!isVarWithRequireCalls(node)) {
if (node.type !== 'VariableDeclaration') {
return undefined;
}

Expand All @@ -39,11 +38,18 @@ export default class RequireDetector {
// Matches: <id> = require("util")
isRequireUtil(dec) {
return isAstMatch(dec, {
type: 'VariableDeclarator',
id: {
type: 'Identifier',
},
init: {
type: 'VariableDeclarator',
callee: {
type: 'Identifier',
name: 'require'
},
arguments: matchesLength([{
type: 'Literal',
value: 'util'
}])
}
Expand All @@ -53,16 +59,25 @@ export default class RequireDetector {
// Matches: <id> = require("util").inherits
isRequireUtilInherits(dec) {
return isAstMatch(dec, {
type: 'VariableDeclarator',
id: {
type: 'Identifier',
},
init: {
type: 'MemberExpression',
computed: false,
object: {
callee: {
type: 'Identifier',
name: 'require'
},
arguments: matchesLength([{
type: 'Literal',
value: 'util'
}])
},
property: {
type: 'Identifier',
name: 'inherits'
}
}
Expand Down

0 comments on commit 4ddb447

Please sign in to comment.