initial commit
This commit is contained in:
37
node_modules/is-reference/CHANGELOG.md
generated
vendored
Normal file
37
node_modules/is-reference/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# is-reference changelog
|
||||
|
||||
## 1.2.1
|
||||
|
||||
* Relax version range for `@types/estree`
|
||||
|
||||
## 1.2.0
|
||||
|
||||
* Handle class fields ([#](https://github.com/Rich-Harris/is-reference/pull/8))
|
||||
|
||||
## 1.1.4
|
||||
|
||||
* Disregarded imported specifiers if they differ from local specifiers
|
||||
|
||||
## 1.1.3
|
||||
|
||||
* Handle expressions without a Program
|
||||
|
||||
## 1.1.2
|
||||
|
||||
* Ignore labels in break/continue statements ([#4](https://github.com/Rich-Harris/is-reference/pull/4))
|
||||
|
||||
## 1.1.1
|
||||
|
||||
* Prevent false positives with labeled statements
|
||||
|
||||
## 1.1.0
|
||||
|
||||
* Rewrite in TypeScript, add declarations
|
||||
|
||||
## 1.0.1
|
||||
|
||||
* Ensure `isReference` returns a boolean
|
||||
|
||||
## 1.0.0
|
||||
|
||||
* First release
|
||||
61
node_modules/is-reference/README.md
generated
vendored
Normal file
61
node_modules/is-reference/README.md
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# is-reference
|
||||
|
||||
Utility for determining whether an AST node is a reference.
|
||||
|
||||
`foo` is a reference in these cases:
|
||||
|
||||
```js
|
||||
console.log( foo );
|
||||
var foo;
|
||||
function foo () {}
|
||||
function bar ( foo ) {}
|
||||
export { foo as x };
|
||||
```
|
||||
|
||||
`foo` is *not* a reference in these cases:
|
||||
|
||||
```js
|
||||
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
|
||||
|
||||
```bash
|
||||
npm install is-reference
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Example using [Acorn](https://github.com/ternjs/acorn) and [estree-walker](https://github.com/Rich-Harris/estree-walker):
|
||||
|
||||
```js
|
||||
const { parse } = require( 'acorn' );
|
||||
const { walk } = require( 'estree-walker' );
|
||||
const isReference = require( '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 ( isReference( 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
|
||||
31
node_modules/is-reference/dist/is-reference.es.js
generated
vendored
Normal file
31
node_modules/is-reference/dist/is-reference.es.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
function isReference(node, parent) {
|
||||
if (node.type === 'MemberExpression') {
|
||||
return !node.computed && isReference(node.object, node);
|
||||
}
|
||||
if (node.type === 'Identifier') {
|
||||
if (!parent)
|
||||
return true;
|
||||
switch (parent.type) {
|
||||
// disregard `bar` in `foo.bar`
|
||||
case 'MemberExpression': return parent.computed || node === parent.object;
|
||||
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
||||
case 'MethodDefinition': return parent.computed;
|
||||
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
||||
case 'FieldDefinition': return parent.computed || node === parent.value;
|
||||
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
||||
case 'Property': return parent.computed || node === parent.value;
|
||||
// disregard the `bar` in `export { foo as bar }` or
|
||||
// the foo in `import { foo as bar }`
|
||||
case 'ExportSpecifier':
|
||||
case 'ImportSpecifier': return node === parent.local;
|
||||
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
||||
case 'LabeledStatement':
|
||||
case 'BreakStatement':
|
||||
case 'ContinueStatement': return false;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export default isReference;
|
||||
39
node_modules/is-reference/dist/is-reference.js
generated
vendored
Normal file
39
node_modules/is-reference/dist/is-reference.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.isReference = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function isReference(node, parent) {
|
||||
if (node.type === 'MemberExpression') {
|
||||
return !node.computed && isReference(node.object, node);
|
||||
}
|
||||
if (node.type === 'Identifier') {
|
||||
if (!parent)
|
||||
return true;
|
||||
switch (parent.type) {
|
||||
// disregard `bar` in `foo.bar`
|
||||
case 'MemberExpression': return parent.computed || node === parent.object;
|
||||
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
||||
case 'MethodDefinition': return parent.computed;
|
||||
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
||||
case 'FieldDefinition': return parent.computed || node === parent.value;
|
||||
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
||||
case 'Property': return parent.computed || node === parent.value;
|
||||
// disregard the `bar` in `export { foo as bar }` or
|
||||
// the foo in `import { foo as bar }`
|
||||
case 'ExportSpecifier':
|
||||
case 'ImportSpecifier': return node === parent.local;
|
||||
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
||||
case 'LabeledStatement':
|
||||
case 'BreakStatement':
|
||||
case 'ContinueStatement': return false;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return isReference;
|
||||
|
||||
})));
|
||||
2
node_modules/is-reference/dist/types/index.d.ts
generated
vendored
Normal file
2
node_modules/is-reference/dist/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Node } from 'estree';
|
||||
export default function isReference(node: Node, parent: Node): boolean;
|
||||
49
node_modules/is-reference/package.json
generated
vendored
Normal file
49
node_modules/is-reference/package.json
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "is-reference",
|
||||
"version": "1.2.1",
|
||||
"description": "Determine whether an AST node is a reference",
|
||||
"main": "dist/is-reference.js",
|
||||
"module": "dist/is-reference.es.js",
|
||||
"types": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
"dist/*.js",
|
||||
"dist/types/**/*.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"build": "rollup -c && tsc --emitDeclarationOnly",
|
||||
"pretest": "npm run build",
|
||||
"prepare": "npm run build",
|
||||
"prepublishOnly": "npm test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Rich-Harris/is-reference.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ast",
|
||||
"javascript",
|
||||
"estree",
|
||||
"acorn"
|
||||
],
|
||||
"author": "Rich Harris",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Rich-Harris/is-reference/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Rich-Harris/is-reference#readme",
|
||||
"dependencies": {
|
||||
"@types/estree": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "^7.2.0",
|
||||
"acorn-class-fields": "^0.3.2",
|
||||
"acorn-static-class-features": "^0.2.1",
|
||||
"estree-walker": "^2.0.1",
|
||||
"mocha": "^7.1.2",
|
||||
"rollup": "^2.10.3",
|
||||
"rollup-plugin-typescript": "^1.0.1",
|
||||
"tslib": "^2.0.0",
|
||||
"typescript": "^3.9.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user