3.0.3 • Published 7 months ago

is-reference v3.0.3

Weekly downloads
1,099,641
License
MIT
Repository
github
Last release
7 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-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-test1webchestories-react-bdspemai-chatbotspemai-sdk-caitestapateste-teste-tcholasvavatarsveltesvelte-calculatorsvelte-crypt-textvs-tree-plus@donapot/mylibtest@dimcheify/dimui@cryptocode99/token-lists@cristianps1988/ds-template@cromwell/utils@csr632/rollup-plugin-commonjs@cute-apocalypse/react-tree@preconstruct/cli@percent/percent-api-hookscauseway-concrete-stylesip-designjson-categorizezitics-core-uiid-holiday-datepickerkjistik-component-librarysushi-sdk-ftm@purnasatria/directus-extension-document-interfacezzzxxxyyy321123string-ts-librarytehmusimhujantype-libarytsong-npool-cli-v2tldrawlignin@aristidenf/streak-counter@arkasuryawan/m2-interface@alexshmyrkov/react-ranger@alectalisman/preconstruct-cli@alta-ng-timeago/hiamtanh-alta@baolong281/gsplat@behzadebrhm/utils@bezael-challenge/innoit-date-format@bitovi/rollup-plugin-commonjs@bhzdbash/utils@buganto/client@adfinitas.fr/adfinitas-ui@aabelmann/ui-layer@bentley/monaco-editor@devorso/dcountdown@contagt/metismenuyyh-plugints-npool-clits-npm-publish-demozitics-core-ui-1zitics-core-ui-package@gratrockstar/native-dialog-component@hazyflame/vue-jitsi-meet@haysquare/svelte-multi-select@haysquare/svelte-multiselect@ibrahimcesar/middy-idempotent@hproinformatica/functions@hoang_ng/directus-extension-dependent-fields@humanity.cash/types@eki-group/svelvet@gem-mine/rollup-plugin-commonjs@eliteswap/token-lists@eusocial/formbuilder@graines-digitales/nice-handsome-button@krenaldi/learnstorybook-design-system-template@kickrtechnologies/authentication@luciadias/storybook-notimation@lordbeanbag/vite-plugin-svg-icons-monorepo@leiyulf/gantt-task-react
3.0.3

7 months ago

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

6 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