From c6bba03f1da00fd4982ff3de38d59e90eb1ebb3b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 25 Feb 2018 10:48:06 -0500 Subject: [PATCH] use external is-reference library --- src/generators/Generator.ts | 2 +- src/generators/dom/index.ts | 2 +- src/utils/isReference.ts | 34 -------------------- src/validate/js/utils/usesThisOrArguments.ts | 2 +- 4 files changed, 3 insertions(+), 37 deletions(-) delete mode 100644 src/utils/isReference.ts diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 6aac05286d..294c7fd8fa 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -1,10 +1,10 @@ import MagicString, { Bundle } from 'magic-string'; +import isReference from 'is-reference'; import { walk, childKeys } from 'estree-walker'; import { getLocator } from 'locate-character'; import deindent from '../utils/deindent'; import CodeBuilder from '../utils/CodeBuilder'; import getCodeFrame from '../utils/getCodeFrame'; -import isReference from '../utils/isReference'; import flattenReference from '../utils/flattenReference'; import reservedNames from '../utils/reservedNames'; import namespaces from '../utils/namespaces'; diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 1d25c4bcfc..90d94ce384 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -1,7 +1,7 @@ import MagicString from 'magic-string'; +import isReference from 'is-reference'; import { parseExpressionAt } from 'acorn'; import annotateWithScopes from '../../utils/annotateWithScopes'; -import isReference from '../../utils/isReference'; import { walk } from 'estree-walker'; import deindent from '../../utils/deindent'; import { stringify, escape } from '../../utils/stringify'; diff --git a/src/utils/isReference.ts b/src/utils/isReference.ts deleted file mode 100644 index 9a5f3688fb..0000000000 --- a/src/utils/isReference.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Node } from '../interfaces'; - -export default function isReference(node: Node, parent: Node): boolean { - if (node.type === 'MemberExpression') { - return !node.computed && isReference(node.object, node); - } - - if (node.type === 'Identifier') { - // the only time we could have an identifier node without a parent is - // if it's the entire body of a function without a block statement – - // i.e. an arrow function expression like `a => a` - if (!parent) return true; - - // TODO is this right? - if ( - parent.type === 'MemberExpression' || - parent.type === 'MethodDefinition' - ) { - return parent.computed || node === parent.object; - } - - // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` - if (parent.type === 'Property') - return parent.computed || node === parent.value; - - // disregard the `bar` in `class Foo { bar () {...} }` - if (parent.type === 'MethodDefinition') return false; - - // disregard the `bar` in `export { foo as bar }` - if (parent.type === 'ExportSpecifier' && node !== parent.local) return; - - return true; - } -} diff --git a/src/validate/js/utils/usesThisOrArguments.ts b/src/validate/js/utils/usesThisOrArguments.ts index 958594a9eb..b727ed387b 100644 --- a/src/validate/js/utils/usesThisOrArguments.ts +++ b/src/validate/js/utils/usesThisOrArguments.ts @@ -1,5 +1,5 @@ import { walk } from 'estree-walker'; -import isReference from '../../../utils/isReference'; +import isReference from 'is-reference'; import { Node } from '../../../interfaces'; export default function usesThisOrArguments(node: Node) {