is-reference

WebJar for is-reference

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

is-reference
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

is-reference
WebJar for is-reference
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/Rich-Harris/is-reference

Download is-reference

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/is-reference/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>is-reference</artifactId>
    <version>1.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/is-reference/
implementation 'org.webjars.npm:is-reference:1.2.1'
// https://jarcasting.com/artifacts/org.webjars.npm/is-reference/
implementation ("org.webjars.npm:is-reference:1.2.1")
'org.webjars.npm:is-reference:jar:1.2.1'
<dependency org="org.webjars.npm" name="is-reference" rev="1.2.1">
  <artifact name="is-reference" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='is-reference', version='1.2.1')
)
libraryDependencies += "org.webjars.npm" % "is-reference" % "1.2.1"
[org.webjars.npm/is-reference "1.2.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : types__estree jar [0,)

Project Modules

There are no modules declared in this project.

is-reference

Utility for determining whether an AST node is a reference.

foo is a reference in these cases:

console.log(foo);
var foo;
function foo() {}
function bar(foo) {}
export { foo as x };

foo is not a reference in these cases:

var obj = { foo: 1 };
console.log(obj.foo);
export { x as foo };

In all cases, foo is an Identifier node, but the two kinds must be treated differently for the purposes of scope analysis etc. (The examples are non-exhaustive.)

Installation

npm install is-reference

Usage

Example using Acorn and estree-walker:

import { parse } from 'acorn';
import { walk } from 'estree-walker';
import is_reference from 'is-reference';

const identifiers = [];
const references = [];

const ast = parse(`var a = b.c;`);

walk(ast, {
	enter(node, parent) {
		if (node.type === 'Identifier') identifiers.push(node);
		if (is_reference(node, parent)) references.push(node);
	}
});

identifiers.forEach(node => console.log(node.name)); // a, b, c
references.forEach(node => console.log(node.name)); // a, b

License

MIT

Versions

Version
1.2.1
1.1.2
1.1.0