3.0.2 • Published 2 years ago

is-reference v3.0.2

Weekly downloads
1,099,641
License
MIT
Repository
github
Last release
2 years ago

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

web-desktop-helper@dinert/utilsvuedragdropuploadimageskilli8n-react-native-fast-imagegql_din_mod@olivervorasai/sliderasterjscogoportutils@infinitebrahmanuniverse/nolb-is-r@saaspe/componentsoptimus-dcexpand-react-bridgeopea-bootstraap@everything-registry/sub-chunk-1934component-library-starter-packp149-tabletest-popups@mediakular/svelte-data-gridkjistik-fixed-component-library@saif29oct/react-tsc-uiphone-morkuptaleempresentationsvelte-outrosvelvet-customtest-demo-widgetwinx-form-winxvue-button-test1webcheresponsis-gantt-task-reactresponsive-react-approllup-plugin-commonjs3rollup-plugin-commonjsrollup-plugin-external-globalsrollup-plugin-external-globals-forkstories-react-bdspemai-chatbotspemai-sdk-cairenu-packsedanbosokrollup-plugin-userscripttestapateste-teste-tcholasvavatarsveltesvelte-calculatorsvelte-crypt-textvs-tree-pluszitics-core-uiid-holiday-datepickerkjistik-component-librarysushi-sdk-ftm@purnasatria/directus-extension-document-interfacezzzxxxyyy321123grids-over-polygonicons-vue-testip-designinputs-react-librarym2m-chartjs-plugin-crosshairlitepie-datepicker-gabelist-box-sveltempd-parser-1moonwalkerswap-default-token-listsktortestzsoltbkrown_login_libraryhexyun.helpersglobal_components_assignmentmangudinlagirajinmama-exportermavectrap147-tablep148-tableopea-bootstrappileuleuyanteanpool-cli-v2npool-cli-v3npool-cli-v4obsidian-utilitiesng-search-dropdownnka-gantt-task-reactperiscopicpetite-design2mypluginlolpatepangdeuireact-component-library-starter-packreact-dottiereact-flow-highly-customizable-edgesreact-form-component-libraryreact-credoreact-dynamic-input-formreact-lightbox-pack-18supportreact-router-v5-v6-bridged-featuresreact-plugin-package-corereact-solid-gradient-pickernumhandlernuxtpaginationsnot-svelte-kitpyreswap-sdkreact-button-packagereact-tailwindcss-datepicker-costume-2string-ts-library
3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.4

5 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago