Sha256: e41b950dd9dc6f78e398ae4a1ba3ba5205b920493f299ecf97d88cebd33d0208

Contents?: true

Size: 1.41 KB

Versions: 26

Compression:

Stored size: 1.41 KB

Contents

function isReference(node, parent) {
    if (node.type === 'MemberExpression') {
        return !node.computed && isReference(node.object, node);
    }
    if (node.type === 'Identifier') {
        if (!parent)
            return true;
        switch (parent.type) {
            // disregard `bar` in `foo.bar`
            case 'MemberExpression': return parent.computed || node === parent.object;
            // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
            case 'MethodDefinition': return parent.computed;
            // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
            case 'FieldDefinition': return parent.computed || node === parent.value;
            // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
            case 'Property': return parent.computed || node === parent.value;
            // disregard the `bar` in `export { foo as bar }` or
            // the foo in `import { foo as bar }`
            case 'ExportSpecifier':
            case 'ImportSpecifier': return node === parent.local;
            // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
            case 'LabeledStatement':
            case 'BreakStatement':
            case 'ContinueStatement': return false;
            default: return true;
        }
    }
    return false;
}

export default isReference;

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/is-reference/dist/is-reference.es.js