3.0.2 • Published 8 months ago

is-reference v3.0.2

Weekly downloads
1,099,641
License
MIT
Repository
github
Last release
8 months 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-1934@314oner_npm/universal-components-librarycomponent-library-starter-packp149-tabletest-popups@mediakular/svelte-data-griddirectus-extension-delete-users-with-filesdirectus-extension-filepreview-interface-sbndirectus-extension-layout-boilerplatedesign-system-trial-milyasbpa@cute-apocalypse/react-tree@devorso/dcountdown@dimcheify/dimuicotrader-dex-sdkdataormlitepie-datepicker-gabemangudinlagirajinm2m-chartjs-plugin-crosshairmama-exportersnowpack4snowpacksnow300spemai-chatbotspemai-sdk-cailist-box-sveltestories-react-bdktortestzsoltbsedanbosoksvelte-outrosvavatarsveltesvelte-calculatorsushi-sdk-ftmsvelvet-customeasier_datatabletype-libarytsong-npool-cli-v2test-demo-widgetng-search-dropdowndskcorenewobsidian-utilities@epigraph/epigraph-analyticsnka-gantt-task-reactnumhandlervue-button-test1nuxtpaginationstehmusimhujanmavectrateste-teste-tcholamoonwalkerswap-default-token-liststestapanot-svelte-kitzitics-core-uiid-holiday-datepickerap-vue-captchaaxonv2sdkavue-table-selector@bentley/monaco-editorblix_svelvet@bezael-challenge/innoit-date-format@bhzdbash/utilscandlelabssdkappxgenasync-busastra-ufo-sdkbackend-testing-corecliptool_hlbraid-extension-component-library@baolong281/gsplat@behzadebrhm/utilsappcharge-checkout-reactjs-sdkappcharge-checkoutant-design-draggable-modal-4ant-design-draggable-modal-fixant-design-draggable-modal-fix-2anakketigaanaklanangteaanakwadontea@contagt/metismenu@cromwell/utils@cryptocode99/token-lists@csr632/rollup-plugin-commonjs@arkasuryawan/m2-interface@aristidenf/streak-counter@bitovi/rollup-plugin-commonjs@buganto/clientcanvas-render--root
3.0.2

8 months ago

3.0.1

1 year ago

3.0.0

3 years ago

2.0.0

3 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago