3.0.3 • Published 11 months ago

is-reference v3.0.3

Weekly downloads
1,099,641
License
MIT
Repository
github
Last release
11 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@preconstruct/cli@percent/percent-api-hookscauseway-concrete-stylesip-designjson-categorizeicons-vue-testhexyun.helpersgrids-over-polygoninputs-react-librarylitepie-datepicker-gabelist-box-sveltemama-exportermangudinlagirajinm2m-chartjs-plugin-crosshairktortestzsoltbkrown_login_librarymavectra@whitebird/kazam-transformer-vue@vue-helper/vue-keep-alive@wt-4/react-stateful-animations@thinkincoin-libs/token-lists@tibui/tibui@unified-api/svelte-directory@unicorncoder/design-system-alpha@torswap/tor-token-lists@tomw2w/my-nuxt-layer@traitsniper/web3-react-connector@traitsniper/web3-react-v6-connector@vigenere23/svelte-component@xswap/token-lists@ykominami/xcomp@yqrashawn/snowpack@zacharygriffee/rollup-plugin-external-globals@zh0st/evm-chainsanakketigaanaklanangteaanakwadonteaaxonv2sdkavue-table-selectorastra-ufo-sdkant-design-draggable-modal-4ant-design-draggable-modal-fixant-design-draggable-modal-fix-2ap-vue-captchaappxgenappcharge-checkoutasync-busbackend-testing-core@graines-digitales/nice-handsome-button@aabelmann/ui-layer@0xclearview/svelte-tiny-virtual-table@gratrockstar/native-dialog-component@contagt/metismenu@cristianps1988/ds-template@cromwell/utils@alta-ng-timeago/hiamtanh-alta@alectalisman/preconstruct-cli@alexshmyrkov/react-ranger@hazyflame/vue-jitsi-meet@haysquare/svelte-multi-select@haysquare/svelte-multiselectzitics-core-ui
3.0.3

11 months ago

3.0.2

2 years ago

3.0.1

3 years ago

3.0.0

4 years ago

2.0.0

5 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

7 years ago

1.1.1

7 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago