Upload folder using huggingface_hub (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/eslint-plugin-react-hooks/LICENSE +21 -0
- node_modules/eslint-plugin-react-hooks/README.md +109 -0
- node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.d.ts +91 -0
- node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js +0 -0
- node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js +0 -0
- node_modules/eslint-plugin-react-hooks/index.d.ts +1 -0
- node_modules/eslint-plugin-react-hooks/index.js +9 -0
- node_modules/eslint-plugin-react-hooks/package.json +58 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/resolver.js +613 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/resolver/symlinked/package/package.json +3 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/resolver/without_basedir/main.js +5 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/resolver_sync.js +727 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/shadowed_core.js +54 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/shadowed_core/node_modules/util/index.js +0 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/subdirs.js +13 -0
- node_modules/eslint-plugin-react/node_modules/resolve/test/symlinks.js +175 -0
- node_modules/eslint-plugin-react/node_modules/semver/LICENSE +15 -0
- node_modules/eslint-plugin-react/node_modules/semver/README.md +443 -0
- node_modules/eslint-plugin-react/node_modules/semver/bin/semver.js +174 -0
- node_modules/eslint-plugin-react/node_modules/semver/package.json +38 -0
- node_modules/eslint-plugin-react/node_modules/semver/range.bnf +16 -0
- node_modules/eslint-plugin-react/node_modules/semver/semver.js +1643 -0
- node_modules/eslint-plugin-react/package.json +125 -0
- node_modules/eslint-scope/LICENSE +22 -0
- node_modules/eslint-scope/README.md +198 -0
- node_modules/eslint-scope/dist/eslint-scope.cjs +2339 -0
- node_modules/eslint-scope/lib/assert.js +17 -0
- node_modules/eslint-scope/lib/definition.js +85 -0
- node_modules/eslint-scope/lib/index.js +170 -0
- node_modules/eslint-scope/lib/pattern-visitor.js +154 -0
- node_modules/eslint-scope/lib/reference.js +166 -0
- node_modules/eslint-scope/lib/referencer.js +708 -0
- node_modules/eslint-scope/lib/scope-manager.js +253 -0
- node_modules/eslint-scope/lib/scope.js +793 -0
- node_modules/eslint-scope/lib/variable.js +87 -0
- node_modules/eslint-scope/lib/version.js +3 -0
- node_modules/eslint-scope/package.json +64 -0
- node_modules/eslint-visitor-keys/LICENSE +201 -0
- node_modules/eslint-visitor-keys/README.md +121 -0
- node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs +396 -0
- node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.d.cts +28 -0
- node_modules/eslint-visitor-keys/dist/index.d.ts +16 -0
- node_modules/eslint-visitor-keys/dist/visitor-keys.d.ts +12 -0
- node_modules/eslint-visitor-keys/lib/index.js +67 -0
- node_modules/eslint-visitor-keys/lib/visitor-keys.js +327 -0
- node_modules/eslint-visitor-keys/package.json +70 -0
- node_modules/espree/LICENSE +25 -0
- node_modules/espree/README.md +262 -0
- node_modules/espree/dist/espree.cjs +940 -0
- node_modules/espree/espree.js +174 -0
node_modules/eslint-plugin-react-hooks/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
node_modules/eslint-plugin-react-hooks/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# `eslint-plugin-react-hooks`
|
| 2 |
+
|
| 3 |
+
This ESLint plugin enforces the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks).
|
| 4 |
+
|
| 5 |
+
It is a part of the [Hooks API](https://react.dev/reference/react/hooks) for React.
|
| 6 |
+
|
| 7 |
+
## Installation
|
| 8 |
+
|
| 9 |
+
**Note: If you're using Create React App, please use `react-scripts` >= 3 instead of adding it directly.**
|
| 10 |
+
|
| 11 |
+
Assuming you already have ESLint installed, run:
|
| 12 |
+
|
| 13 |
+
```sh
|
| 14 |
+
# npm
|
| 15 |
+
npm install eslint-plugin-react-hooks --save-dev
|
| 16 |
+
|
| 17 |
+
# yarn
|
| 18 |
+
yarn add eslint-plugin-react-hooks --dev
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
### Legacy Config (.eslintrc)
|
| 22 |
+
|
| 23 |
+
If you are still using ESLint below 9.0.0, please continue to use `recommended-legacy`. To avoid breaking changes, we still support `recommended` as well, but note that this will be changed to alias the flat recommended config in v6.
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
{
|
| 27 |
+
"extends": [
|
| 28 |
+
// ...
|
| 29 |
+
"plugin:react-hooks/recommended-legacy"
|
| 30 |
+
]
|
| 31 |
+
}
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
### Flat Config (eslint.config.js)
|
| 35 |
+
|
| 36 |
+
For [ESLint 9.0.0 and above](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/) users, add the `recommended-latest` config.
|
| 37 |
+
|
| 38 |
+
```js
|
| 39 |
+
import reactHooks from 'eslint-plugin-react-hooks';
|
| 40 |
+
|
| 41 |
+
export default [
|
| 42 |
+
// ...
|
| 43 |
+
reactHooks.configs['recommended-latest'],
|
| 44 |
+
];
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Custom Configuration
|
| 48 |
+
|
| 49 |
+
If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:
|
| 50 |
+
|
| 51 |
+
#### Legacy Config (.eslintrc)
|
| 52 |
+
|
| 53 |
+
```js
|
| 54 |
+
{
|
| 55 |
+
"plugins": [
|
| 56 |
+
// ...
|
| 57 |
+
"react-hooks"
|
| 58 |
+
],
|
| 59 |
+
"rules": {
|
| 60 |
+
// ...
|
| 61 |
+
"react-hooks/rules-of-hooks": "error",
|
| 62 |
+
"react-hooks/exhaustive-deps": "warn"
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
#### Flat Config (eslint.config.js)
|
| 68 |
+
|
| 69 |
+
```js
|
| 70 |
+
import reactHooks from 'eslint-plugin-react-hooks';
|
| 71 |
+
|
| 72 |
+
export default [
|
| 73 |
+
{
|
| 74 |
+
files: ['**/*.{js,jsx}'],
|
| 75 |
+
plugins: { 'react-hooks': reactHooks },
|
| 76 |
+
// ...
|
| 77 |
+
rules: {
|
| 78 |
+
'react-hooks/rules-of-hooks': 'error',
|
| 79 |
+
'react-hooks/exhaustive-deps': 'warn',
|
| 80 |
+
}
|
| 81 |
+
},
|
| 82 |
+
];
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
## Advanced Configuration
|
| 86 |
+
|
| 87 |
+
`exhaustive-deps` can be configured to validate dependencies of custom Hooks with the `additionalHooks` option.
|
| 88 |
+
This option accepts a regex to match the names of custom Hooks that have dependencies.
|
| 89 |
+
|
| 90 |
+
```js
|
| 91 |
+
{
|
| 92 |
+
"rules": {
|
| 93 |
+
// ...
|
| 94 |
+
"react-hooks/exhaustive-deps": ["warn", {
|
| 95 |
+
"additionalHooks": "(useMyCustomHook|useMyOtherCustomHook)"
|
| 96 |
+
}]
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case.
|
| 102 |
+
|
| 103 |
+
## Valid and Invalid Examples
|
| 104 |
+
|
| 105 |
+
Please refer to the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks) documentation to learn more about this rule.
|
| 106 |
+
|
| 107 |
+
## License
|
| 108 |
+
|
| 109 |
+
MIT
|
node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as estree from 'estree';
|
| 2 |
+
import { Rule, ESLint } from 'eslint';
|
| 3 |
+
|
| 4 |
+
declare const rules: {
|
| 5 |
+
'rules-of-hooks': {
|
| 6 |
+
meta: {
|
| 7 |
+
type: "problem";
|
| 8 |
+
docs: {
|
| 9 |
+
description: string;
|
| 10 |
+
recommended: true;
|
| 11 |
+
url: string;
|
| 12 |
+
};
|
| 13 |
+
};
|
| 14 |
+
create(context: Rule.RuleContext): {
|
| 15 |
+
onCodePathSegmentStart: (segment: Rule.CodePathSegment) => number;
|
| 16 |
+
onCodePathSegmentEnd: () => Rule.CodePathSegment | undefined;
|
| 17 |
+
onCodePathStart: () => number;
|
| 18 |
+
onCodePathEnd(codePath: Rule.CodePath, codePathNode: Rule.Node): void;
|
| 19 |
+
CallExpression(node: estree.CallExpression & Rule.NodeParentExtension): void;
|
| 20 |
+
Identifier(node: estree.Identifier & Rule.NodeParentExtension): void;
|
| 21 |
+
'CallExpression:exit'(node: estree.CallExpression & Rule.NodeParentExtension): void;
|
| 22 |
+
FunctionDeclaration(node: estree.FunctionDeclaration & Rule.NodeParentExtension): void;
|
| 23 |
+
ArrowFunctionExpression(node: estree.ArrowFunctionExpression & Rule.NodeParentExtension): void;
|
| 24 |
+
};
|
| 25 |
+
};
|
| 26 |
+
'exhaustive-deps': {
|
| 27 |
+
meta: {
|
| 28 |
+
type: "suggestion";
|
| 29 |
+
docs: {
|
| 30 |
+
description: string;
|
| 31 |
+
recommended: true;
|
| 32 |
+
url: string;
|
| 33 |
+
};
|
| 34 |
+
fixable: "code";
|
| 35 |
+
hasSuggestions: true;
|
| 36 |
+
schema: {
|
| 37 |
+
type: "object";
|
| 38 |
+
additionalProperties: false;
|
| 39 |
+
enableDangerousAutofixThisMayCauseInfiniteLoops: boolean;
|
| 40 |
+
properties: {
|
| 41 |
+
additionalHooks: {
|
| 42 |
+
type: "string";
|
| 43 |
+
};
|
| 44 |
+
enableDangerousAutofixThisMayCauseInfiniteLoops: {
|
| 45 |
+
type: "boolean";
|
| 46 |
+
};
|
| 47 |
+
};
|
| 48 |
+
}[];
|
| 49 |
+
};
|
| 50 |
+
create(context: Rule.RuleContext): {
|
| 51 |
+
CallExpression: (node: estree.CallExpression) => void;
|
| 52 |
+
};
|
| 53 |
+
};
|
| 54 |
+
};
|
| 55 |
+
declare const configs: {
|
| 56 |
+
/** Legacy recommended config, to be used with rc-based configurations */
|
| 57 |
+
'recommended-legacy': {
|
| 58 |
+
plugins: string[];
|
| 59 |
+
rules: {
|
| 60 |
+
'react-hooks/rules-of-hooks': "error";
|
| 61 |
+
'react-hooks/exhaustive-deps': "warn";
|
| 62 |
+
};
|
| 63 |
+
};
|
| 64 |
+
/**
|
| 65 |
+
* 'recommended' is currently aliased to the legacy / rc recommended config) to maintain backwards compatibility.
|
| 66 |
+
* This is deprecated and in v6, it will switch to alias the flat recommended config.
|
| 67 |
+
*/
|
| 68 |
+
recommended: {
|
| 69 |
+
plugins: string[];
|
| 70 |
+
rules: {
|
| 71 |
+
'react-hooks/rules-of-hooks': "error";
|
| 72 |
+
'react-hooks/exhaustive-deps': "warn";
|
| 73 |
+
};
|
| 74 |
+
};
|
| 75 |
+
/** Latest recommended config, to be used with flat configurations */
|
| 76 |
+
'recommended-latest': {
|
| 77 |
+
name: string;
|
| 78 |
+
plugins: {
|
| 79 |
+
readonly 'react-hooks': ESLint.Plugin;
|
| 80 |
+
};
|
| 81 |
+
rules: {
|
| 82 |
+
'react-hooks/rules-of-hooks': "error";
|
| 83 |
+
'react-hooks/exhaustive-deps': "warn";
|
| 84 |
+
};
|
| 85 |
+
};
|
| 86 |
+
};
|
| 87 |
+
declare const meta: {
|
| 88 |
+
name: string;
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
export { configs, meta, rules };
|
node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/eslint-plugin-react-hooks/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from './cjs/eslint-plugin-react-hooks';
|
node_modules/eslint-plugin-react-hooks/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
// TODO: this doesn't make sense for an ESLint rule.
|
| 4 |
+
// We need to fix our build process to not create bundles for "raw" packages like this.
|
| 5 |
+
if (process.env.NODE_ENV === 'production') {
|
| 6 |
+
module.exports = require('./cjs/eslint-plugin-react-hooks.production.js');
|
| 7 |
+
} else {
|
| 8 |
+
module.exports = require('./cjs/eslint-plugin-react-hooks.development.js');
|
| 9 |
+
}
|
node_modules/eslint-plugin-react-hooks/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-plugin-react-hooks",
|
| 3 |
+
"description": "ESLint rules for React Hooks",
|
| 4 |
+
"version": "5.2.0",
|
| 5 |
+
"repository": {
|
| 6 |
+
"type": "git",
|
| 7 |
+
"url": "https://github.com/facebook/react.git",
|
| 8 |
+
"directory": "packages/eslint-plugin-react-hooks"
|
| 9 |
+
},
|
| 10 |
+
"files": [
|
| 11 |
+
"LICENSE",
|
| 12 |
+
"README.md",
|
| 13 |
+
"cjs",
|
| 14 |
+
"index.js",
|
| 15 |
+
"index.d.ts"
|
| 16 |
+
],
|
| 17 |
+
"keywords": [
|
| 18 |
+
"eslint",
|
| 19 |
+
"eslint-plugin",
|
| 20 |
+
"eslintplugin",
|
| 21 |
+
"react"
|
| 22 |
+
],
|
| 23 |
+
"scripts": {
|
| 24 |
+
"test": "jest",
|
| 25 |
+
"typecheck": "tsc --noEmit"
|
| 26 |
+
},
|
| 27 |
+
"license": "MIT",
|
| 28 |
+
"bugs": {
|
| 29 |
+
"url": "https://github.com/facebook/react/issues"
|
| 30 |
+
},
|
| 31 |
+
"main": "./index.js",
|
| 32 |
+
"types": "./index.d.ts",
|
| 33 |
+
"engines": {
|
| 34 |
+
"node": ">=10"
|
| 35 |
+
},
|
| 36 |
+
"homepage": "https://react.dev/",
|
| 37 |
+
"peerDependencies": {
|
| 38 |
+
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0"
|
| 39 |
+
},
|
| 40 |
+
"devDependencies": {
|
| 41 |
+
"@babel/eslint-parser": "^7.11.4",
|
| 42 |
+
"@babel/preset-typescript": "^7.26.0",
|
| 43 |
+
"@tsconfig/strictest": "^2.0.5",
|
| 44 |
+
"@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
|
| 45 |
+
"@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
|
| 46 |
+
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0",
|
| 47 |
+
"@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.62.0",
|
| 48 |
+
"@types/eslint": "^8.56.12",
|
| 49 |
+
"@types/estree": "^1.0.6",
|
| 50 |
+
"@types/estree-jsx": "^1.0.5",
|
| 51 |
+
"@types/node": "^20.2.5",
|
| 52 |
+
"babel-eslint": "^10.0.3",
|
| 53 |
+
"eslint-v7": "npm:eslint@^7.7.0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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var path = require('path');
|
| 2 |
+
var fs = require('fs');
|
| 3 |
+
var test = require('tape');
|
| 4 |
+
var resolve = require('../');
|
| 5 |
+
var async = require('../async');
|
| 6 |
+
|
| 7 |
+
test('`./async` entry point', function (t) {
|
| 8 |
+
t.equal(resolve, async, '`./async` entry point is the same as `main`');
|
| 9 |
+
t.end();
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
test('async foo', function (t) {
|
| 13 |
+
t.plan(12);
|
| 14 |
+
var dir = path.join(__dirname, 'resolver');
|
| 15 |
+
|
| 16 |
+
resolve('./foo', { basedir: dir }, function (err, res, pkg) {
|
| 17 |
+
if (err) t.fail(err);
|
| 18 |
+
t.equal(res, path.join(dir, 'foo.js'));
|
| 19 |
+
t.equal(pkg && pkg.name, 'resolve');
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
resolve('./foo.js', { basedir: dir }, function (err, res, pkg) {
|
| 23 |
+
if (err) t.fail(err);
|
| 24 |
+
t.equal(res, path.join(dir, 'foo.js'));
|
| 25 |
+
t.equal(pkg && pkg.name, 'resolve');
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
resolve('./foo', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
|
| 29 |
+
if (err) t.fail(err);
|
| 30 |
+
t.equal(res, path.join(dir, 'foo.js'));
|
| 31 |
+
t.equal(pkg && pkg.main, 'resolver');
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
resolve('./foo.js', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
|
| 35 |
+
if (err) t.fail(err);
|
| 36 |
+
t.equal(res, path.join(dir, 'foo.js'));
|
| 37 |
+
t.equal(pkg.main, 'resolver');
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
resolve('./foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err, res) {
|
| 41 |
+
if (err) t.fail(err);
|
| 42 |
+
t.equal(res, path.join(dir, 'foo.js'));
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
resolve('foo', { basedir: dir }, function (err) {
|
| 46 |
+
t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");
|
| 47 |
+
t.equal(err.code, 'MODULE_NOT_FOUND');
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
// Test that filename is reported as the "from" value when passed.
|
| 51 |
+
resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) {
|
| 52 |
+
t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'");
|
| 53 |
+
});
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
test('bar', function (t) {
|
| 57 |
+
t.plan(6);
|
| 58 |
+
var dir = path.join(__dirname, 'resolver');
|
| 59 |
+
|
| 60 |
+
resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {
|
| 61 |
+
if (err) t.fail(err);
|
| 62 |
+
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
|
| 63 |
+
t.equal(pkg, undefined);
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {
|
| 67 |
+
if (err) t.fail(err);
|
| 68 |
+
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
|
| 69 |
+
t.equal(pkg, undefined);
|
| 70 |
+
});
|
| 71 |
+
|
| 72 |
+
resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) {
|
| 73 |
+
if (err) t.fail(err);
|
| 74 |
+
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
|
| 75 |
+
t.equal(pkg.main, 'bar');
|
| 76 |
+
});
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
test('baz', function (t) {
|
| 80 |
+
t.plan(4);
|
| 81 |
+
var dir = path.join(__dirname, 'resolver');
|
| 82 |
+
|
| 83 |
+
resolve('./baz', { basedir: dir }, function (err, res, pkg) {
|
| 84 |
+
if (err) t.fail(err);
|
| 85 |
+
t.equal(res, path.join(dir, 'baz/quux.js'));
|
| 86 |
+
t.equal(pkg.main, 'quux.js');
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
resolve('./baz', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
|
| 90 |
+
if (err) t.fail(err);
|
| 91 |
+
t.equal(res, path.join(dir, 'baz/quux.js'));
|
| 92 |
+
t.equal(pkg.main, 'quux.js');
|
| 93 |
+
});
|
| 94 |
+
});
|
| 95 |
+
|
| 96 |
+
test('biz', function (t) {
|
| 97 |
+
t.plan(24);
|
| 98 |
+
var dir = path.join(__dirname, 'resolver/biz/node_modules');
|
| 99 |
+
|
| 100 |
+
resolve('./grux', { basedir: dir }, function (err, res, pkg) {
|
| 101 |
+
if (err) t.fail(err);
|
| 102 |
+
t.equal(res, path.join(dir, 'grux/index.js'));
|
| 103 |
+
t.equal(pkg, undefined);
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {
|
| 107 |
+
if (err) t.fail(err);
|
| 108 |
+
t.equal(res, path.join(dir, 'grux/index.js'));
|
| 109 |
+
t.equal(pkg.main, 'biz');
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
resolve('./garply', { basedir: dir }, function (err, res, pkg) {
|
| 113 |
+
if (err) t.fail(err);
|
| 114 |
+
t.equal(res, path.join(dir, 'garply/lib/index.js'));
|
| 115 |
+
t.equal(pkg.main, './lib');
|
| 116 |
+
});
|
| 117 |
+
|
| 118 |
+
resolve('./garply', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {
|
| 119 |
+
if (err) t.fail(err);
|
| 120 |
+
t.equal(res, path.join(dir, 'garply/lib/index.js'));
|
| 121 |
+
t.equal(pkg.main, './lib');
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) {
|
| 125 |
+
if (err) t.fail(err);
|
| 126 |
+
t.equal(res, path.join(dir, 'tiv/index.js'));
|
| 127 |
+
t.equal(pkg, undefined);
|
| 128 |
+
});
|
| 129 |
+
|
| 130 |
+
resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) {
|
| 131 |
+
if (err) t.fail(err);
|
| 132 |
+
t.equal(res, path.join(dir, 'tiv/index.js'));
|
| 133 |
+
t.equal(pkg.main, 'grux');
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) {
|
| 137 |
+
if (err) t.fail(err);
|
| 138 |
+
t.equal(res, path.join(dir, 'tiv/index.js'));
|
| 139 |
+
t.equal(pkg, undefined);
|
| 140 |
+
});
|
| 141 |
+
|
| 142 |
+
resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) {
|
| 143 |
+
if (err) t.fail(err);
|
| 144 |
+
t.equal(res, path.join(dir, 'tiv/index.js'));
|
| 145 |
+
t.equal(pkg.main, './lib');
|
| 146 |
+
});
|
| 147 |
+
|
| 148 |
+
resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) {
|
| 149 |
+
if (err) t.fail(err);
|
| 150 |
+
t.equal(res, path.join(dir, 'grux/index.js'));
|
| 151 |
+
t.equal(pkg, undefined);
|
| 152 |
+
});
|
| 153 |
+
|
| 154 |
+
resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
|
| 155 |
+
if (err) t.fail(err);
|
| 156 |
+
t.equal(res, path.join(dir, 'grux/index.js'));
|
| 157 |
+
t.equal(pkg.main, 'tiv');
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) {
|
| 161 |
+
if (err) t.fail(err);
|
| 162 |
+
t.equal(res, path.join(dir, 'garply/lib/index.js'));
|
| 163 |
+
t.equal(pkg.main, './lib');
|
| 164 |
+
});
|
| 165 |
+
|
| 166 |
+
resolve('garply', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
|
| 167 |
+
if (err) t.fail(err);
|
| 168 |
+
t.equal(res, path.join(dir, 'garply/lib/index.js'));
|
| 169 |
+
t.equal(pkg.main, './lib');
|
| 170 |
+
});
|
| 171 |
+
});
|
| 172 |
+
|
| 173 |
+
test('quux', function (t) {
|
| 174 |
+
t.plan(2);
|
| 175 |
+
var dir = path.join(__dirname, 'resolver/quux');
|
| 176 |
+
|
| 177 |
+
resolve('./foo', { basedir: dir, 'package': { main: 'quux' } }, function (err, res, pkg) {
|
| 178 |
+
if (err) t.fail(err);
|
| 179 |
+
t.equal(res, path.join(dir, 'foo/index.js'));
|
| 180 |
+
t.equal(pkg.main, 'quux');
|
| 181 |
+
});
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
test('normalize', function (t) {
|
| 185 |
+
t.plan(2);
|
| 186 |
+
var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');
|
| 187 |
+
|
| 188 |
+
resolve('../grux', { basedir: dir }, function (err, res, pkg) {
|
| 189 |
+
if (err) t.fail(err);
|
| 190 |
+
t.equal(res, path.join(dir, 'index.js'));
|
| 191 |
+
t.equal(pkg, undefined);
|
| 192 |
+
});
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
test('cup', function (t) {
|
| 196 |
+
t.plan(5);
|
| 197 |
+
var dir = path.join(__dirname, 'resolver');
|
| 198 |
+
|
| 199 |
+
resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {
|
| 200 |
+
if (err) t.fail(err);
|
| 201 |
+
t.equal(res, path.join(dir, 'cup.coffee'));
|
| 202 |
+
});
|
| 203 |
+
|
| 204 |
+
resolve('./cup.coffee', { basedir: dir }, function (err, res) {
|
| 205 |
+
if (err) t.fail(err);
|
| 206 |
+
t.equal(res, path.join(dir, 'cup.coffee'));
|
| 207 |
+
});
|
| 208 |
+
|
| 209 |
+
resolve('./cup', { basedir: dir, extensions: ['.js'] }, function (err, res) {
|
| 210 |
+
t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");
|
| 211 |
+
t.equal(err.code, 'MODULE_NOT_FOUND');
|
| 212 |
+
});
|
| 213 |
+
|
| 214 |
+
// Test that filename is reported as the "from" value when passed.
|
| 215 |
+
resolve('./cup', { basedir: dir, extensions: ['.js'], filename: path.join(dir, 'cupboard.js') }, function (err, res) {
|
| 216 |
+
t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'");
|
| 217 |
+
});
|
| 218 |
+
});
|
| 219 |
+
|
| 220 |
+
test('mug', function (t) {
|
| 221 |
+
t.plan(3);
|
| 222 |
+
var dir = path.join(__dirname, 'resolver');
|
| 223 |
+
|
| 224 |
+
resolve('./mug', { basedir: dir }, function (err, res) {
|
| 225 |
+
if (err) t.fail(err);
|
| 226 |
+
t.equal(res, path.join(dir, 'mug.js'));
|
| 227 |
+
});
|
| 228 |
+
|
| 229 |
+
resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) {
|
| 230 |
+
if (err) t.fail(err);
|
| 231 |
+
t.equal(res, path.join(dir, '/mug.coffee'));
|
| 232 |
+
});
|
| 233 |
+
|
| 234 |
+
resolve('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {
|
| 235 |
+
t.equal(res, path.join(dir, '/mug.js'));
|
| 236 |
+
});
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
test('other path', function (t) {
|
| 240 |
+
t.plan(6);
|
| 241 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 242 |
+
var dir = path.join(resolverDir, 'bar');
|
| 243 |
+
var otherDir = path.join(resolverDir, 'other_path');
|
| 244 |
+
|
| 245 |
+
resolve('root', { basedir: dir, paths: [otherDir] }, function (err, res) {
|
| 246 |
+
if (err) t.fail(err);
|
| 247 |
+
t.equal(res, path.join(resolverDir, 'other_path/root.js'));
|
| 248 |
+
});
|
| 249 |
+
|
| 250 |
+
resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) {
|
| 251 |
+
if (err) t.fail(err);
|
| 252 |
+
t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js'));
|
| 253 |
+
});
|
| 254 |
+
|
| 255 |
+
resolve('root', { basedir: dir }, function (err, res) {
|
| 256 |
+
t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'");
|
| 257 |
+
t.equal(err.code, 'MODULE_NOT_FOUND');
|
| 258 |
+
});
|
| 259 |
+
|
| 260 |
+
resolve('zzz', { basedir: dir, paths: [otherDir] }, function (err, res) {
|
| 261 |
+
t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'");
|
| 262 |
+
t.equal(err.code, 'MODULE_NOT_FOUND');
|
| 263 |
+
});
|
| 264 |
+
});
|
| 265 |
+
|
| 266 |
+
test('path iterator', function (t) {
|
| 267 |
+
t.plan(2);
|
| 268 |
+
|
| 269 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 270 |
+
|
| 271 |
+
var exactIterator = function (x, start, getPackageCandidates, opts) {
|
| 272 |
+
return [path.join(resolverDir, x)];
|
| 273 |
+
};
|
| 274 |
+
|
| 275 |
+
resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) {
|
| 276 |
+
if (err) t.fail(err);
|
| 277 |
+
t.equal(res, path.join(resolverDir, 'baz/quux.js'));
|
| 278 |
+
t.equal(pkg && pkg.name, 'baz');
|
| 279 |
+
});
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
test('empty main', function (t) {
|
| 283 |
+
t.plan(1);
|
| 284 |
+
|
| 285 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 286 |
+
var dir = path.join(resolverDir, 'empty_main');
|
| 287 |
+
|
| 288 |
+
resolve('./empty_main', { basedir: resolverDir }, function (err, res, pkg) {
|
| 289 |
+
if (err) t.fail(err);
|
| 290 |
+
t.equal(res, path.join(dir, 'index.js'));
|
| 291 |
+
});
|
| 292 |
+
});
|
| 293 |
+
|
| 294 |
+
test('incorrect main', function (t) {
|
| 295 |
+
t.plan(1);
|
| 296 |
+
|
| 297 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 298 |
+
var dir = path.join(resolverDir, 'incorrect_main');
|
| 299 |
+
|
| 300 |
+
resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) {
|
| 301 |
+
if (err) t.fail(err);
|
| 302 |
+
t.equal(res, path.join(dir, 'index.js'));
|
| 303 |
+
});
|
| 304 |
+
});
|
| 305 |
+
|
| 306 |
+
test('missing index', function (t) {
|
| 307 |
+
t.plan(2);
|
| 308 |
+
|
| 309 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 310 |
+
resolve('./missing_index', { basedir: resolverDir }, function (err, res, pkg) {
|
| 311 |
+
t.ok(err instanceof Error);
|
| 312 |
+
t.equal(err && err.code, 'INCORRECT_PACKAGE_MAIN', 'error has correct error code');
|
| 313 |
+
});
|
| 314 |
+
});
|
| 315 |
+
|
| 316 |
+
test('missing main', function (t) {
|
| 317 |
+
t.plan(1);
|
| 318 |
+
|
| 319 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 320 |
+
var dir = path.join(resolverDir, 'missing_main');
|
| 321 |
+
|
| 322 |
+
resolve('./missing_main', { basedir: resolverDir }, function (err, res, pkg) {
|
| 323 |
+
if (err) t.fail(err);
|
| 324 |
+
t.equal(res, path.join(dir, 'index.js'));
|
| 325 |
+
});
|
| 326 |
+
});
|
| 327 |
+
|
| 328 |
+
test('null main', function (t) {
|
| 329 |
+
t.plan(1);
|
| 330 |
+
|
| 331 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 332 |
+
var dir = path.join(resolverDir, 'null_main');
|
| 333 |
+
|
| 334 |
+
resolve('./null_main', { basedir: resolverDir }, function (err, res, pkg) {
|
| 335 |
+
if (err) t.fail(err);
|
| 336 |
+
t.equal(res, path.join(dir, 'index.js'));
|
| 337 |
+
});
|
| 338 |
+
});
|
| 339 |
+
|
| 340 |
+
test('main: false', function (t) {
|
| 341 |
+
t.plan(2);
|
| 342 |
+
|
| 343 |
+
var basedir = path.join(__dirname, 'resolver');
|
| 344 |
+
var dir = path.join(basedir, 'false_main');
|
| 345 |
+
resolve('./false_main', { basedir: basedir }, function (err, res, pkg) {
|
| 346 |
+
if (err) t.fail(err);
|
| 347 |
+
t.equal(
|
| 348 |
+
res,
|
| 349 |
+
path.join(dir, 'index.js'),
|
| 350 |
+
'`"main": false`: resolves to `index.js`'
|
| 351 |
+
);
|
| 352 |
+
t.deepEqual(pkg, {
|
| 353 |
+
name: 'false_main',
|
| 354 |
+
main: false
|
| 355 |
+
});
|
| 356 |
+
});
|
| 357 |
+
});
|
| 358 |
+
|
| 359 |
+
test('without basedir', function (t) {
|
| 360 |
+
t.plan(1);
|
| 361 |
+
|
| 362 |
+
var dir = path.join(__dirname, 'resolver/without_basedir');
|
| 363 |
+
var tester = require(path.join(dir, 'main.js')); // eslint-disable-line global-require
|
| 364 |
+
|
| 365 |
+
tester(t, function (err, res, pkg) {
|
| 366 |
+
if (err) {
|
| 367 |
+
t.fail(err);
|
| 368 |
+
} else {
|
| 369 |
+
t.equal(res, path.join(dir, 'node_modules/mymodule.js'));
|
| 370 |
+
}
|
| 371 |
+
});
|
| 372 |
+
});
|
| 373 |
+
|
| 374 |
+
test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {
|
| 375 |
+
t.plan(2);
|
| 376 |
+
|
| 377 |
+
var dir = path.join(__dirname, 'resolver');
|
| 378 |
+
|
| 379 |
+
resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {
|
| 380 |
+
if (err) t.fail(err);
|
| 381 |
+
t.equal(res, path.join(dir, 'same_names/foo.js'));
|
| 382 |
+
});
|
| 383 |
+
|
| 384 |
+
resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {
|
| 385 |
+
if (err) t.fail(err);
|
| 386 |
+
t.equal(res, path.join(dir, 'same_names/foo/index.js'));
|
| 387 |
+
});
|
| 388 |
+
});
|
| 389 |
+
|
| 390 |
+
test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) {
|
| 391 |
+
t.plan(2);
|
| 392 |
+
|
| 393 |
+
var dir = path.join(__dirname, 'resolver');
|
| 394 |
+
|
| 395 |
+
resolve('./', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) {
|
| 396 |
+
if (err) t.fail(err);
|
| 397 |
+
t.equal(res, path.join(dir, 'same_names/foo/index.js'));
|
| 398 |
+
});
|
| 399 |
+
|
| 400 |
+
resolve('.', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) {
|
| 401 |
+
if (err) t.fail(err);
|
| 402 |
+
t.equal(res, path.join(dir, 'same_names/foo/index.js'));
|
| 403 |
+
});
|
| 404 |
+
});
|
| 405 |
+
|
| 406 |
+
test('async: #121 - treating an existing file as a dir when no basedir', function (t) {
|
| 407 |
+
var testFile = path.basename(__filename);
|
| 408 |
+
|
| 409 |
+
t.test('sanity check', function (st) {
|
| 410 |
+
st.plan(1);
|
| 411 |
+
resolve('./' + testFile, function (err, res, pkg) {
|
| 412 |
+
if (err) t.fail(err);
|
| 413 |
+
st.equal(res, __filename, 'sanity check');
|
| 414 |
+
});
|
| 415 |
+
});
|
| 416 |
+
|
| 417 |
+
t.test('with a fake directory', function (st) {
|
| 418 |
+
st.plan(4);
|
| 419 |
+
|
| 420 |
+
resolve('./' + testFile + '/blah', function (err, res, pkg) {
|
| 421 |
+
st.ok(err, 'there is an error');
|
| 422 |
+
st.notOk(res, 'no result');
|
| 423 |
+
|
| 424 |
+
st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
|
| 425 |
+
st.equal(
|
| 426 |
+
err && err.message,
|
| 427 |
+
'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',
|
| 428 |
+
'can not find nonexistent module'
|
| 429 |
+
);
|
| 430 |
+
st.end();
|
| 431 |
+
});
|
| 432 |
+
});
|
| 433 |
+
|
| 434 |
+
t.end();
|
| 435 |
+
});
|
| 436 |
+
|
| 437 |
+
test('async dot main', function (t) {
|
| 438 |
+
var start = new Date();
|
| 439 |
+
t.plan(3);
|
| 440 |
+
resolve('./resolver/dot_main', function (err, ret) {
|
| 441 |
+
t.notOk(err);
|
| 442 |
+
t.equal(ret, path.join(__dirname, 'resolver/dot_main/index.js'));
|
| 443 |
+
t.ok(new Date() - start < 50, 'resolve.sync timedout');
|
| 444 |
+
t.end();
|
| 445 |
+
});
|
| 446 |
+
});
|
| 447 |
+
|
| 448 |
+
test('async dot slash main', function (t) {
|
| 449 |
+
var start = new Date();
|
| 450 |
+
t.plan(3);
|
| 451 |
+
resolve('./resolver/dot_slash_main', function (err, ret) {
|
| 452 |
+
t.notOk(err);
|
| 453 |
+
t.equal(ret, path.join(__dirname, 'resolver/dot_slash_main/index.js'));
|
| 454 |
+
t.ok(new Date() - start < 50, 'resolve.sync timedout');
|
| 455 |
+
t.end();
|
| 456 |
+
});
|
| 457 |
+
});
|
| 458 |
+
|
| 459 |
+
test('not a directory', function (t) {
|
| 460 |
+
t.plan(6);
|
| 461 |
+
var path = './foo';
|
| 462 |
+
resolve(path, { basedir: __filename }, function (err, res, pkg) {
|
| 463 |
+
t.ok(err, 'a non-directory errors');
|
| 464 |
+
t.equal(arguments.length, 1);
|
| 465 |
+
t.equal(res, undefined);
|
| 466 |
+
t.equal(pkg, undefined);
|
| 467 |
+
|
| 468 |
+
t.equal(err && err.message, 'Provided basedir "' + __filename + '" is not a directory, or a symlink to a directory');
|
| 469 |
+
t.equal(err && err.code, 'INVALID_BASEDIR');
|
| 470 |
+
});
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
test('non-string "main" field in package.json', function (t) {
|
| 474 |
+
t.plan(5);
|
| 475 |
+
|
| 476 |
+
var dir = path.join(__dirname, 'resolver');
|
| 477 |
+
resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {
|
| 478 |
+
t.ok(err, 'errors on non-string main');
|
| 479 |
+
t.equal(err.message, 'package “invalid_main” `main` must be a string');
|
| 480 |
+
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
|
| 481 |
+
t.equal(res, undefined, 'res is undefined');
|
| 482 |
+
t.equal(pkg, undefined, 'pkg is undefined');
|
| 483 |
+
});
|
| 484 |
+
});
|
| 485 |
+
|
| 486 |
+
test('non-string "main" field in package.json', function (t) {
|
| 487 |
+
t.plan(5);
|
| 488 |
+
|
| 489 |
+
var dir = path.join(__dirname, 'resolver');
|
| 490 |
+
resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {
|
| 491 |
+
t.ok(err, 'errors on non-string main');
|
| 492 |
+
t.equal(err.message, 'package “invalid_main” `main` must be a string');
|
| 493 |
+
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
|
| 494 |
+
t.equal(res, undefined, 'res is undefined');
|
| 495 |
+
t.equal(pkg, undefined, 'pkg is undefined');
|
| 496 |
+
});
|
| 497 |
+
});
|
| 498 |
+
|
| 499 |
+
test('browser field in package.json', function (t) {
|
| 500 |
+
t.plan(3);
|
| 501 |
+
|
| 502 |
+
var dir = path.join(__dirname, 'resolver');
|
| 503 |
+
resolve(
|
| 504 |
+
'./browser_field',
|
| 505 |
+
{
|
| 506 |
+
basedir: dir,
|
| 507 |
+
packageFilter: function packageFilter(pkg) {
|
| 508 |
+
if (pkg.browser) {
|
| 509 |
+
pkg.main = pkg.browser; // eslint-disable-line no-param-reassign
|
| 510 |
+
delete pkg.browser; // eslint-disable-line no-param-reassign
|
| 511 |
+
}
|
| 512 |
+
return pkg;
|
| 513 |
+
}
|
| 514 |
+
},
|
| 515 |
+
function (err, res, pkg) {
|
| 516 |
+
if (err) t.fail(err);
|
| 517 |
+
t.equal(res, path.join(dir, 'browser_field', 'b.js'));
|
| 518 |
+
t.equal(pkg && pkg.main, 'b');
|
| 519 |
+
t.equal(pkg && pkg.browser, undefined);
|
| 520 |
+
}
|
| 521 |
+
);
|
| 522 |
+
});
|
| 523 |
+
|
| 524 |
+
test('absolute paths', function (t) {
|
| 525 |
+
t.plan(4);
|
| 526 |
+
|
| 527 |
+
var extensionless = __filename.slice(0, -path.extname(__filename).length);
|
| 528 |
+
|
| 529 |
+
resolve(__filename, function (err, res) {
|
| 530 |
+
t.equal(
|
| 531 |
+
res,
|
| 532 |
+
__filename,
|
| 533 |
+
'absolute path to this file resolves'
|
| 534 |
+
);
|
| 535 |
+
});
|
| 536 |
+
resolve(extensionless, function (err, res) {
|
| 537 |
+
t.equal(
|
| 538 |
+
res,
|
| 539 |
+
__filename,
|
| 540 |
+
'extensionless absolute path to this file resolves'
|
| 541 |
+
);
|
| 542 |
+
});
|
| 543 |
+
resolve(__filename, { basedir: process.cwd() }, function (err, res) {
|
| 544 |
+
t.equal(
|
| 545 |
+
res,
|
| 546 |
+
__filename,
|
| 547 |
+
'absolute path to this file with a basedir resolves'
|
| 548 |
+
);
|
| 549 |
+
});
|
| 550 |
+
resolve(extensionless, { basedir: process.cwd() }, function (err, res) {
|
| 551 |
+
t.equal(
|
| 552 |
+
res,
|
| 553 |
+
__filename,
|
| 554 |
+
'extensionless absolute path to this file with a basedir resolves'
|
| 555 |
+
);
|
| 556 |
+
});
|
| 557 |
+
});
|
| 558 |
+
|
| 559 |
+
var malformedDir = path.join(__dirname, 'resolver/malformed_package_json');
|
| 560 |
+
test('malformed package.json', { skip: !fs.existsSync(malformedDir) }, function (t) {
|
| 561 |
+
/* eslint operator-linebreak: ["error", "before"], function-paren-newline: "off" */
|
| 562 |
+
t.plan(
|
| 563 |
+
(3 * 3) // 3 sets of 3 assertions in the final callback
|
| 564 |
+
+ 2 // 1 readPackage call with malformed package.json
|
| 565 |
+
);
|
| 566 |
+
|
| 567 |
+
var basedir = malformedDir;
|
| 568 |
+
var expected = path.join(basedir, 'index.js');
|
| 569 |
+
|
| 570 |
+
resolve('./index.js', { basedir: basedir }, function (err, res, pkg) {
|
| 571 |
+
t.error(err, 'no error');
|
| 572 |
+
t.equal(res, expected, 'malformed package.json is silently ignored');
|
| 573 |
+
t.equal(pkg, undefined, 'malformed package.json gives an undefined `pkg` argument');
|
| 574 |
+
});
|
| 575 |
+
|
| 576 |
+
resolve(
|
| 577 |
+
'./index.js',
|
| 578 |
+
{
|
| 579 |
+
basedir: basedir,
|
| 580 |
+
packageFilter: function (pkg, pkgfile, dir) {
|
| 581 |
+
t.fail('should not reach here');
|
| 582 |
+
}
|
| 583 |
+
},
|
| 584 |
+
function (err, res, pkg) {
|
| 585 |
+
t.error(err, 'with packageFilter: no error');
|
| 586 |
+
t.equal(res, expected, 'with packageFilter: malformed package.json is silently ignored');
|
| 587 |
+
t.equal(pkg, undefined, 'with packageFilter: malformed package.json gives an undefined `pkg` argument');
|
| 588 |
+
}
|
| 589 |
+
);
|
| 590 |
+
|
| 591 |
+
resolve(
|
| 592 |
+
'./index.js',
|
| 593 |
+
{
|
| 594 |
+
basedir: basedir,
|
| 595 |
+
readPackage: function (readFile, pkgfile, cb) {
|
| 596 |
+
t.equal(pkgfile, path.join(basedir, 'package.json'), 'readPackageSync: `pkgfile` is package.json path');
|
| 597 |
+
readFile(pkgfile, function (err, result) {
|
| 598 |
+
try {
|
| 599 |
+
cb(null, JSON.parse(result));
|
| 600 |
+
} catch (e) {
|
| 601 |
+
t.ok(e instanceof SyntaxError, 'readPackage: malformed package.json parses as a syntax error');
|
| 602 |
+
cb(e);
|
| 603 |
+
}
|
| 604 |
+
});
|
| 605 |
+
}
|
| 606 |
+
},
|
| 607 |
+
function (err, res, pkg) {
|
| 608 |
+
t.error(err, 'with readPackage: no error');
|
| 609 |
+
t.equal(res, expected, 'with readPackage: malformed package.json is silently ignored');
|
| 610 |
+
t.equal(pkg, undefined, 'with readPackage: malformed package.json gives an undefined `pkg` argument');
|
| 611 |
+
}
|
| 612 |
+
);
|
| 613 |
+
});
|
node_modules/eslint-plugin-react/node_modules/resolve/test/resolver/symlinked/package/package.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"main": "bar.js"
|
| 3 |
+
}
|
node_modules/eslint-plugin-react/node_modules/resolve/test/resolver/without_basedir/main.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var resolve = require('../../../');
|
| 2 |
+
|
| 3 |
+
module.exports = function (t, cb) {
|
| 4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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var path = require('path');
|
| 2 |
+
var fs = require('fs');
|
| 3 |
+
var test = require('tape');
|
| 4 |
+
|
| 5 |
+
var resolve = require('../');
|
| 6 |
+
var sync = require('../sync');
|
| 7 |
+
|
| 8 |
+
var requireResolveSupportsPaths = require.resolve.length > 1
|
| 9 |
+
&& !(/^v12\.[012]\./).test(process.version); // broken in v12.0-12.2, see https://github.com/nodejs/node/issues/27794
|
| 10 |
+
|
| 11 |
+
var requireResolveDefaultPathsBroken = (/^v8\.9\.|^v9\.[01]\.0|^v9\.2\./).test(process.version);
|
| 12 |
+
// broken in node v8.9.x, v9.0, v9.1, v9.2.x. see https://github.com/nodejs/node/pull/17113
|
| 13 |
+
|
| 14 |
+
test('`./sync` entry point', function (t) {
|
| 15 |
+
t.equal(resolve.sync, sync, '`./sync` entry point is the same as `.sync` on `main`');
|
| 16 |
+
t.end();
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
test('foo', function (t) {
|
| 20 |
+
var dir = path.join(__dirname, 'resolver');
|
| 21 |
+
|
| 22 |
+
t.equal(
|
| 23 |
+
resolve.sync('./foo', { basedir: dir }),
|
| 24 |
+
path.join(dir, 'foo.js'),
|
| 25 |
+
'./foo'
|
| 26 |
+
);
|
| 27 |
+
if (requireResolveSupportsPaths) {
|
| 28 |
+
t.equal(
|
| 29 |
+
resolve.sync('./foo', { basedir: dir }),
|
| 30 |
+
require.resolve('./foo', { paths: [dir] }),
|
| 31 |
+
'./foo: resolve.sync === require.resolve'
|
| 32 |
+
);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
t.equal(
|
| 36 |
+
resolve.sync('./foo.js', { basedir: dir }),
|
| 37 |
+
path.join(dir, 'foo.js'),
|
| 38 |
+
'./foo.js'
|
| 39 |
+
);
|
| 40 |
+
if (requireResolveSupportsPaths) {
|
| 41 |
+
t.equal(
|
| 42 |
+
resolve.sync('./foo.js', { basedir: dir }),
|
| 43 |
+
require.resolve('./foo.js', { paths: [dir] }),
|
| 44 |
+
'./foo.js: resolve.sync === require.resolve'
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
t.equal(
|
| 49 |
+
resolve.sync('./foo.js', { basedir: dir, filename: path.join(dir, 'bar.js') }),
|
| 50 |
+
path.join(dir, 'foo.js')
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
t.throws(function () {
|
| 54 |
+
resolve.sync('foo', { basedir: dir });
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
// Test that filename is reported as the "from" value when passed.
|
| 58 |
+
t.throws(
|
| 59 |
+
function () {
|
| 60 |
+
resolve.sync('foo', { basedir: dir, filename: path.join(dir, 'bar.js') });
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
name: 'Error',
|
| 64 |
+
message: "Cannot find module 'foo' from '" + path.join(dir, 'bar.js') + "'"
|
| 65 |
+
}
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
t.end();
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
test('bar', function (t) {
|
| 72 |
+
var dir = path.join(__dirname, 'resolver');
|
| 73 |
+
|
| 74 |
+
var basedir = path.join(dir, 'bar');
|
| 75 |
+
|
| 76 |
+
t.equal(
|
| 77 |
+
resolve.sync('foo', { basedir: basedir }),
|
| 78 |
+
path.join(dir, 'bar/node_modules/foo/index.js'),
|
| 79 |
+
'foo in bar'
|
| 80 |
+
);
|
| 81 |
+
if (!requireResolveDefaultPathsBroken && requireResolveSupportsPaths) {
|
| 82 |
+
t.equal(
|
| 83 |
+
resolve.sync('foo', { basedir: basedir }),
|
| 84 |
+
require.resolve('foo', { paths: [basedir] }),
|
| 85 |
+
'foo in bar: resolve.sync === require.resolve'
|
| 86 |
+
);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
t.end();
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
test('baz', function (t) {
|
| 93 |
+
var dir = path.join(__dirname, 'resolver');
|
| 94 |
+
|
| 95 |
+
t.equal(
|
| 96 |
+
resolve.sync('./baz', { basedir: dir }),
|
| 97 |
+
path.join(dir, 'baz/quux.js'),
|
| 98 |
+
'./baz'
|
| 99 |
+
);
|
| 100 |
+
if (requireResolveSupportsPaths) {
|
| 101 |
+
t.equal(
|
| 102 |
+
resolve.sync('./baz', { basedir: dir }),
|
| 103 |
+
require.resolve('./baz', { paths: [dir] }),
|
| 104 |
+
'./baz: resolve.sync === require.resolve'
|
| 105 |
+
);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
t.end();
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
test('biz', function (t) {
|
| 112 |
+
var dir = path.join(__dirname, 'resolver/biz/node_modules');
|
| 113 |
+
|
| 114 |
+
t.equal(
|
| 115 |
+
resolve.sync('./grux', { basedir: dir }),
|
| 116 |
+
path.join(dir, 'grux/index.js')
|
| 117 |
+
);
|
| 118 |
+
if (requireResolveSupportsPaths) {
|
| 119 |
+
t.equal(
|
| 120 |
+
resolve.sync('./grux', { basedir: dir }),
|
| 121 |
+
require.resolve('./grux', { paths: [dir] }),
|
| 122 |
+
'./grux: resolve.sync === require.resolve'
|
| 123 |
+
);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
var tivDir = path.join(dir, 'grux');
|
| 127 |
+
t.equal(
|
| 128 |
+
resolve.sync('tiv', { basedir: tivDir }),
|
| 129 |
+
path.join(dir, 'tiv/index.js')
|
| 130 |
+
);
|
| 131 |
+
if (!requireResolveDefaultPathsBroken && requireResolveSupportsPaths) {
|
| 132 |
+
t.equal(
|
| 133 |
+
resolve.sync('tiv', { basedir: tivDir }),
|
| 134 |
+
require.resolve('tiv', { paths: [tivDir] }),
|
| 135 |
+
'tiv: resolve.sync === require.resolve'
|
| 136 |
+
);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
var gruxDir = path.join(dir, 'tiv');
|
| 140 |
+
t.equal(
|
| 141 |
+
resolve.sync('grux', { basedir: gruxDir }),
|
| 142 |
+
path.join(dir, 'grux/index.js')
|
| 143 |
+
);
|
| 144 |
+
if (!requireResolveDefaultPathsBroken && requireResolveSupportsPaths) {
|
| 145 |
+
t.equal(
|
| 146 |
+
resolve.sync('grux', { basedir: gruxDir }),
|
| 147 |
+
require.resolve('grux', { paths: [gruxDir] }),
|
| 148 |
+
'grux: resolve.sync === require.resolve'
|
| 149 |
+
);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
t.end();
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
test('normalize', function (t) {
|
| 156 |
+
var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');
|
| 157 |
+
|
| 158 |
+
t.equal(
|
| 159 |
+
resolve.sync('../grux', { basedir: dir }),
|
| 160 |
+
path.join(dir, 'index.js')
|
| 161 |
+
);
|
| 162 |
+
if (requireResolveSupportsPaths) {
|
| 163 |
+
t.equal(
|
| 164 |
+
resolve.sync('../grux', { basedir: dir }),
|
| 165 |
+
require.resolve('../grux', { paths: [dir] }),
|
| 166 |
+
'../grux: resolve.sync === require.resolve'
|
| 167 |
+
);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
t.end();
|
| 171 |
+
});
|
| 172 |
+
|
| 173 |
+
test('cup', function (t) {
|
| 174 |
+
var dir = path.join(__dirname, 'resolver');
|
| 175 |
+
|
| 176 |
+
t.equal(
|
| 177 |
+
resolve.sync('./cup', {
|
| 178 |
+
basedir: dir,
|
| 179 |
+
extensions: ['.js', '.coffee']
|
| 180 |
+
}),
|
| 181 |
+
path.join(dir, 'cup.coffee'),
|
| 182 |
+
'./cup -> ./cup.coffee'
|
| 183 |
+
);
|
| 184 |
+
|
| 185 |
+
t.equal(
|
| 186 |
+
resolve.sync('./cup.coffee', { basedir: dir }),
|
| 187 |
+
path.join(dir, 'cup.coffee'),
|
| 188 |
+
'./cup.coffee'
|
| 189 |
+
);
|
| 190 |
+
|
| 191 |
+
t.throws(function () {
|
| 192 |
+
resolve.sync('./cup', {
|
| 193 |
+
basedir: dir,
|
| 194 |
+
extensions: ['.js']
|
| 195 |
+
});
|
| 196 |
+
});
|
| 197 |
+
|
| 198 |
+
if (requireResolveSupportsPaths) {
|
| 199 |
+
t.equal(
|
| 200 |
+
resolve.sync('./cup.coffee', { basedir: dir, extensions: ['.js', '.coffee'] }),
|
| 201 |
+
require.resolve('./cup.coffee', { paths: [dir] }),
|
| 202 |
+
'./cup.coffee: resolve.sync === require.resolve'
|
| 203 |
+
);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
t.end();
|
| 207 |
+
});
|
| 208 |
+
|
| 209 |
+
test('mug', function (t) {
|
| 210 |
+
var dir = path.join(__dirname, 'resolver');
|
| 211 |
+
|
| 212 |
+
t.equal(
|
| 213 |
+
resolve.sync('./mug', { basedir: dir }),
|
| 214 |
+
path.join(dir, 'mug.js'),
|
| 215 |
+
'./mug -> ./mug.js'
|
| 216 |
+
);
|
| 217 |
+
if (requireResolveSupportsPaths) {
|
| 218 |
+
t.equal(
|
| 219 |
+
resolve.sync('./mug', { basedir: dir }),
|
| 220 |
+
require.resolve('./mug', { paths: [dir] }),
|
| 221 |
+
'./mug: resolve.sync === require.resolve'
|
| 222 |
+
);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
t.equal(
|
| 226 |
+
resolve.sync('./mug', {
|
| 227 |
+
basedir: dir,
|
| 228 |
+
extensions: ['.coffee', '.js']
|
| 229 |
+
}),
|
| 230 |
+
path.join(dir, 'mug.coffee'),
|
| 231 |
+
'./mug -> ./mug.coffee'
|
| 232 |
+
);
|
| 233 |
+
|
| 234 |
+
t.equal(
|
| 235 |
+
resolve.sync('./mug', {
|
| 236 |
+
basedir: dir,
|
| 237 |
+
extensions: ['.js', '.coffee']
|
| 238 |
+
}),
|
| 239 |
+
path.join(dir, 'mug.js'),
|
| 240 |
+
'./mug -> ./mug.js'
|
| 241 |
+
);
|
| 242 |
+
|
| 243 |
+
t.end();
|
| 244 |
+
});
|
| 245 |
+
|
| 246 |
+
test('other path', function (t) {
|
| 247 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 248 |
+
var dir = path.join(resolverDir, 'bar');
|
| 249 |
+
var otherDir = path.join(resolverDir, 'other_path');
|
| 250 |
+
|
| 251 |
+
t.equal(
|
| 252 |
+
resolve.sync('root', {
|
| 253 |
+
basedir: dir,
|
| 254 |
+
paths: [otherDir]
|
| 255 |
+
}),
|
| 256 |
+
path.join(resolverDir, 'other_path/root.js')
|
| 257 |
+
);
|
| 258 |
+
|
| 259 |
+
t.equal(
|
| 260 |
+
resolve.sync('lib/other-lib', {
|
| 261 |
+
basedir: dir,
|
| 262 |
+
paths: [otherDir]
|
| 263 |
+
}),
|
| 264 |
+
path.join(resolverDir, 'other_path/lib/other-lib.js')
|
| 265 |
+
);
|
| 266 |
+
|
| 267 |
+
t.throws(function () {
|
| 268 |
+
resolve.sync('root', { basedir: dir });
|
| 269 |
+
});
|
| 270 |
+
|
| 271 |
+
t.throws(function () {
|
| 272 |
+
resolve.sync('zzz', {
|
| 273 |
+
basedir: dir,
|
| 274 |
+
paths: [otherDir]
|
| 275 |
+
});
|
| 276 |
+
});
|
| 277 |
+
|
| 278 |
+
t.end();
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
test('path iterator', function (t) {
|
| 282 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 283 |
+
|
| 284 |
+
var exactIterator = function (x, start, getPackageCandidates, opts) {
|
| 285 |
+
return [path.join(resolverDir, x)];
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
t.equal(
|
| 289 |
+
resolve.sync('baz', { packageIterator: exactIterator }),
|
| 290 |
+
path.join(resolverDir, 'baz/quux.js')
|
| 291 |
+
);
|
| 292 |
+
|
| 293 |
+
t.end();
|
| 294 |
+
});
|
| 295 |
+
|
| 296 |
+
test('incorrect main', function (t) {
|
| 297 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 298 |
+
var dir = path.join(resolverDir, 'incorrect_main');
|
| 299 |
+
|
| 300 |
+
t.equal(
|
| 301 |
+
resolve.sync('./incorrect_main', { basedir: resolverDir }),
|
| 302 |
+
path.join(dir, 'index.js')
|
| 303 |
+
);
|
| 304 |
+
if (requireResolveSupportsPaths) {
|
| 305 |
+
t.equal(
|
| 306 |
+
resolve.sync('./incorrect_main', { basedir: resolverDir }),
|
| 307 |
+
require.resolve('./incorrect_main', { paths: [resolverDir] }),
|
| 308 |
+
'./incorrect_main: resolve.sync === require.resolve'
|
| 309 |
+
);
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
t.end();
|
| 313 |
+
});
|
| 314 |
+
|
| 315 |
+
test('missing index', function (t) {
|
| 316 |
+
t.plan(requireResolveSupportsPaths ? 2 : 1);
|
| 317 |
+
|
| 318 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 319 |
+
try {
|
| 320 |
+
resolve.sync('./missing_index', { basedir: resolverDir });
|
| 321 |
+
t.fail('did not fail');
|
| 322 |
+
} catch (err) {
|
| 323 |
+
t.equal(err && err.code, 'INCORRECT_PACKAGE_MAIN', 'error has correct error code');
|
| 324 |
+
}
|
| 325 |
+
if (requireResolveSupportsPaths) {
|
| 326 |
+
try {
|
| 327 |
+
require.resolve('./missing_index', { basedir: resolverDir });
|
| 328 |
+
t.fail('require.resolve did not fail');
|
| 329 |
+
} catch (err) {
|
| 330 |
+
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
|
| 331 |
+
}
|
| 332 |
+
}
|
| 333 |
+
});
|
| 334 |
+
|
| 335 |
+
test('missing main', function (t) {
|
| 336 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 337 |
+
var dir = path.join(resolverDir, 'missing_main');
|
| 338 |
+
|
| 339 |
+
t.equal(
|
| 340 |
+
resolve.sync('./missing_main', { basedir: resolverDir }),
|
| 341 |
+
path.join(dir, 'index.js')
|
| 342 |
+
);
|
| 343 |
+
if (requireResolveSupportsPaths) {
|
| 344 |
+
t.equal(
|
| 345 |
+
resolve.sync('./missing_main', { basedir: resolverDir }),
|
| 346 |
+
require.resolve('./missing_main', { paths: [resolverDir] }),
|
| 347 |
+
'"main" missing: resolve.sync === require.resolve'
|
| 348 |
+
);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
t.end();
|
| 352 |
+
});
|
| 353 |
+
|
| 354 |
+
test('null main', function (t) {
|
| 355 |
+
var resolverDir = path.join(__dirname, 'resolver');
|
| 356 |
+
var dir = path.join(resolverDir, 'null_main');
|
| 357 |
+
|
| 358 |
+
t.equal(
|
| 359 |
+
resolve.sync('./null_main', { basedir: resolverDir }),
|
| 360 |
+
path.join(dir, 'index.js')
|
| 361 |
+
);
|
| 362 |
+
if (requireResolveSupportsPaths) {
|
| 363 |
+
t.equal(
|
| 364 |
+
resolve.sync('./null_main', { basedir: resolverDir }),
|
| 365 |
+
require.resolve('./null_main', { paths: [resolverDir] }),
|
| 366 |
+
'`"main": null`: resolve.sync === require.resolve'
|
| 367 |
+
);
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
t.end();
|
| 371 |
+
});
|
| 372 |
+
|
| 373 |
+
test('main: false', function (t) {
|
| 374 |
+
var basedir = path.join(__dirname, 'resolver');
|
| 375 |
+
var dir = path.join(basedir, 'false_main');
|
| 376 |
+
t.equal(
|
| 377 |
+
resolve.sync('./false_main', { basedir: basedir }),
|
| 378 |
+
path.join(dir, 'index.js'),
|
| 379 |
+
'`"main": false`: resolves to `index.js`'
|
| 380 |
+
);
|
| 381 |
+
if (requireResolveSupportsPaths) {
|
| 382 |
+
t.equal(
|
| 383 |
+
resolve.sync('./false_main', { basedir: basedir }),
|
| 384 |
+
require.resolve('./false_main', { paths: [basedir] }),
|
| 385 |
+
'`"main": false`: resolve.sync === require.resolve'
|
| 386 |
+
);
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
t.end();
|
| 390 |
+
});
|
| 391 |
+
|
| 392 |
+
var stubStatSync = function stubStatSync(fn) {
|
| 393 |
+
var statSync = fs.statSync;
|
| 394 |
+
try {
|
| 395 |
+
fs.statSync = function () {
|
| 396 |
+
throw new EvalError('Unknown Error');
|
| 397 |
+
};
|
| 398 |
+
return fn();
|
| 399 |
+
} finally {
|
| 400 |
+
fs.statSync = statSync;
|
| 401 |
+
}
|
| 402 |
+
};
|
| 403 |
+
|
| 404 |
+
test('#79 - re-throw non ENOENT errors from stat', function (t) {
|
| 405 |
+
var dir = path.join(__dirname, 'resolver');
|
| 406 |
+
|
| 407 |
+
stubStatSync(function () {
|
| 408 |
+
t.throws(function () {
|
| 409 |
+
resolve.sync('foo', { basedir: dir });
|
| 410 |
+
}, /Unknown Error/);
|
| 411 |
+
});
|
| 412 |
+
|
| 413 |
+
t.end();
|
| 414 |
+
});
|
| 415 |
+
|
| 416 |
+
test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {
|
| 417 |
+
var dir = path.join(__dirname, 'resolver');
|
| 418 |
+
var basedir = path.join(dir, 'same_names');
|
| 419 |
+
|
| 420 |
+
t.equal(
|
| 421 |
+
resolve.sync('./foo', { basedir: basedir }),
|
| 422 |
+
path.join(dir, 'same_names/foo.js')
|
| 423 |
+
);
|
| 424 |
+
if (requireResolveSupportsPaths) {
|
| 425 |
+
t.equal(
|
| 426 |
+
resolve.sync('./foo', { basedir: basedir }),
|
| 427 |
+
require.resolve('./foo', { paths: [basedir] }),
|
| 428 |
+
'./foo: resolve.sync === require.resolve'
|
| 429 |
+
);
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
t.equal(
|
| 433 |
+
resolve.sync('./foo/', { basedir: basedir }),
|
| 434 |
+
path.join(dir, 'same_names/foo/index.js')
|
| 435 |
+
);
|
| 436 |
+
if (requireResolveSupportsPaths) {
|
| 437 |
+
t.equal(
|
| 438 |
+
resolve.sync('./foo/', { basedir: basedir }),
|
| 439 |
+
require.resolve('./foo/', { paths: [basedir] }),
|
| 440 |
+
'./foo/: resolve.sync === require.resolve'
|
| 441 |
+
);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
t.end();
|
| 445 |
+
});
|
| 446 |
+
|
| 447 |
+
test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) {
|
| 448 |
+
var dir = path.join(__dirname, 'resolver');
|
| 449 |
+
var basedir = path.join(dir, 'same_names/foo');
|
| 450 |
+
|
| 451 |
+
t.equal(
|
| 452 |
+
resolve.sync('./', { basedir: basedir }),
|
| 453 |
+
path.join(dir, 'same_names/foo/index.js'),
|
| 454 |
+
'./'
|
| 455 |
+
);
|
| 456 |
+
if (requireResolveSupportsPaths) {
|
| 457 |
+
t.equal(
|
| 458 |
+
resolve.sync('./', { basedir: basedir }),
|
| 459 |
+
require.resolve('./', { paths: [basedir] }),
|
| 460 |
+
'./: resolve.sync === require.resolve'
|
| 461 |
+
);
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
t.equal(
|
| 465 |
+
resolve.sync('.', { basedir: basedir }),
|
| 466 |
+
path.join(dir, 'same_names/foo/index.js'),
|
| 467 |
+
'.'
|
| 468 |
+
);
|
| 469 |
+
if (requireResolveSupportsPaths) {
|
| 470 |
+
t.equal(
|
| 471 |
+
resolve.sync('.', { basedir: basedir }),
|
| 472 |
+
require.resolve('.', { paths: [basedir] }),
|
| 473 |
+
'.: resolve.sync === require.resolve',
|
| 474 |
+
{ todo: true }
|
| 475 |
+
);
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
t.end();
|
| 479 |
+
});
|
| 480 |
+
|
| 481 |
+
test('sync: #121 - treating an existing file as a dir when no basedir', function (t) {
|
| 482 |
+
var testFile = path.basename(__filename);
|
| 483 |
+
|
| 484 |
+
t.test('sanity check', function (st) {
|
| 485 |
+
st.equal(
|
| 486 |
+
resolve.sync('./' + testFile),
|
| 487 |
+
__filename,
|
| 488 |
+
'sanity check'
|
| 489 |
+
);
|
| 490 |
+
st.equal(
|
| 491 |
+
resolve.sync('./' + testFile),
|
| 492 |
+
require.resolve('./' + testFile),
|
| 493 |
+
'sanity check: resolve.sync === require.resolve'
|
| 494 |
+
);
|
| 495 |
+
|
| 496 |
+
st.end();
|
| 497 |
+
});
|
| 498 |
+
|
| 499 |
+
t.test('with a fake directory', function (st) {
|
| 500 |
+
function run() { return resolve.sync('./' + testFile + '/blah'); }
|
| 501 |
+
|
| 502 |
+
st.throws(run, 'throws an error');
|
| 503 |
+
|
| 504 |
+
try {
|
| 505 |
+
run();
|
| 506 |
+
} catch (e) {
|
| 507 |
+
st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
|
| 508 |
+
st.equal(
|
| 509 |
+
e.message,
|
| 510 |
+
'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',
|
| 511 |
+
'can not find nonexistent module'
|
| 512 |
+
);
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
st.end();
|
| 516 |
+
});
|
| 517 |
+
|
| 518 |
+
t.end();
|
| 519 |
+
});
|
| 520 |
+
|
| 521 |
+
test('sync dot main', function (t) {
|
| 522 |
+
var start = new Date();
|
| 523 |
+
|
| 524 |
+
t.equal(
|
| 525 |
+
resolve.sync('./resolver/dot_main'),
|
| 526 |
+
path.join(__dirname, 'resolver/dot_main/index.js'),
|
| 527 |
+
'./resolver/dot_main'
|
| 528 |
+
);
|
| 529 |
+
t.equal(
|
| 530 |
+
resolve.sync('./resolver/dot_main'),
|
| 531 |
+
require.resolve('./resolver/dot_main'),
|
| 532 |
+
'./resolver/dot_main: resolve.sync === require.resolve'
|
| 533 |
+
);
|
| 534 |
+
|
| 535 |
+
t.ok(new Date() - start < 50, 'resolve.sync timedout');
|
| 536 |
+
|
| 537 |
+
t.end();
|
| 538 |
+
});
|
| 539 |
+
|
| 540 |
+
test('sync dot slash main', function (t) {
|
| 541 |
+
var start = new Date();
|
| 542 |
+
|
| 543 |
+
t.equal(
|
| 544 |
+
resolve.sync('./resolver/dot_slash_main'),
|
| 545 |
+
path.join(__dirname, 'resolver/dot_slash_main/index.js')
|
| 546 |
+
);
|
| 547 |
+
t.equal(
|
| 548 |
+
resolve.sync('./resolver/dot_slash_main'),
|
| 549 |
+
require.resolve('./resolver/dot_slash_main'),
|
| 550 |
+
'./resolver/dot_slash_main: resolve.sync === require.resolve'
|
| 551 |
+
);
|
| 552 |
+
|
| 553 |
+
t.ok(new Date() - start < 50, 'resolve.sync timedout');
|
| 554 |
+
|
| 555 |
+
t.end();
|
| 556 |
+
});
|
| 557 |
+
|
| 558 |
+
test('not a directory', function (t) {
|
| 559 |
+
var path = './foo';
|
| 560 |
+
try {
|
| 561 |
+
resolve.sync(path, { basedir: __filename });
|
| 562 |
+
t.fail();
|
| 563 |
+
} catch (err) {
|
| 564 |
+
t.ok(err, 'a non-directory errors');
|
| 565 |
+
t.equal(err && err.message, 'Provided basedir "' + __filename + '" is not a directory, or a symlink to a directory');
|
| 566 |
+
t.equal(err && err.code, 'INVALID_BASEDIR');
|
| 567 |
+
}
|
| 568 |
+
t.end();
|
| 569 |
+
});
|
| 570 |
+
|
| 571 |
+
test('non-string "main" field in package.json', function (t) {
|
| 572 |
+
var dir = path.join(__dirname, 'resolver');
|
| 573 |
+
try {
|
| 574 |
+
var result = resolve.sync('./invalid_main', { basedir: dir });
|
| 575 |
+
t.equal(result, undefined, 'result should not exist');
|
| 576 |
+
t.fail('should not get here');
|
| 577 |
+
} catch (err) {
|
| 578 |
+
t.ok(err, 'errors on non-string main');
|
| 579 |
+
t.equal(err.message, 'package “invalid_main” `main` must be a string');
|
| 580 |
+
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
|
| 581 |
+
}
|
| 582 |
+
t.end();
|
| 583 |
+
});
|
| 584 |
+
|
| 585 |
+
test('non-string "main" field in package.json', function (t) {
|
| 586 |
+
var dir = path.join(__dirname, 'resolver');
|
| 587 |
+
try {
|
| 588 |
+
var result = resolve.sync('./invalid_main', { basedir: dir });
|
| 589 |
+
t.equal(result, undefined, 'result should not exist');
|
| 590 |
+
t.fail('should not get here');
|
| 591 |
+
} catch (err) {
|
| 592 |
+
t.ok(err, 'errors on non-string main');
|
| 593 |
+
t.equal(err.message, 'package “invalid_main” `main` must be a string');
|
| 594 |
+
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
|
| 595 |
+
}
|
| 596 |
+
t.end();
|
| 597 |
+
});
|
| 598 |
+
|
| 599 |
+
test('browser field in package.json', function (t) {
|
| 600 |
+
var dir = path.join(__dirname, 'resolver');
|
| 601 |
+
var res = resolve.sync('./browser_field', {
|
| 602 |
+
basedir: dir,
|
| 603 |
+
packageFilter: function packageFilter(pkg) {
|
| 604 |
+
if (pkg.browser) {
|
| 605 |
+
pkg.main = pkg.browser; // eslint-disable-line no-param-reassign
|
| 606 |
+
delete pkg.browser; // eslint-disable-line no-param-reassign
|
| 607 |
+
}
|
| 608 |
+
return pkg;
|
| 609 |
+
}
|
| 610 |
+
});
|
| 611 |
+
t.equal(res, path.join(dir, 'browser_field', 'b.js'));
|
| 612 |
+
t.end();
|
| 613 |
+
});
|
| 614 |
+
|
| 615 |
+
test('absolute paths', function (t) {
|
| 616 |
+
var extensionless = __filename.slice(0, -path.extname(__filename).length);
|
| 617 |
+
|
| 618 |
+
t.equal(
|
| 619 |
+
resolve.sync(__filename),
|
| 620 |
+
__filename,
|
| 621 |
+
'absolute path to this file resolves'
|
| 622 |
+
);
|
| 623 |
+
t.equal(
|
| 624 |
+
resolve.sync(__filename),
|
| 625 |
+
require.resolve(__filename),
|
| 626 |
+
'absolute path to this file: resolve.sync === require.resolve'
|
| 627 |
+
);
|
| 628 |
+
|
| 629 |
+
t.equal(
|
| 630 |
+
resolve.sync(extensionless),
|
| 631 |
+
__filename,
|
| 632 |
+
'extensionless absolute path to this file resolves'
|
| 633 |
+
);
|
| 634 |
+
t.equal(
|
| 635 |
+
resolve.sync(__filename),
|
| 636 |
+
require.resolve(__filename),
|
| 637 |
+
'absolute path to this file: resolve.sync === require.resolve'
|
| 638 |
+
);
|
| 639 |
+
|
| 640 |
+
t.equal(
|
| 641 |
+
resolve.sync(__filename, { basedir: process.cwd() }),
|
| 642 |
+
__filename,
|
| 643 |
+
'absolute path to this file with a basedir resolves'
|
| 644 |
+
);
|
| 645 |
+
if (requireResolveSupportsPaths) {
|
| 646 |
+
t.equal(
|
| 647 |
+
resolve.sync(__filename, { basedir: process.cwd() }),
|
| 648 |
+
require.resolve(__filename, { paths: [process.cwd()] }),
|
| 649 |
+
'absolute path to this file + basedir: resolve.sync === require.resolve'
|
| 650 |
+
);
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
t.equal(
|
| 654 |
+
resolve.sync(extensionless, { basedir: process.cwd() }),
|
| 655 |
+
__filename,
|
| 656 |
+
'extensionless absolute path to this file with a basedir resolves'
|
| 657 |
+
);
|
| 658 |
+
if (requireResolveSupportsPaths) {
|
| 659 |
+
t.equal(
|
| 660 |
+
resolve.sync(extensionless, { basedir: process.cwd() }),
|
| 661 |
+
require.resolve(extensionless, { paths: [process.cwd()] }),
|
| 662 |
+
'extensionless absolute path to this file + basedir: resolve.sync === require.resolve'
|
| 663 |
+
);
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
t.end();
|
| 667 |
+
});
|
| 668 |
+
|
| 669 |
+
var malformedDir = path.join(__dirname, 'resolver/malformed_package_json');
|
| 670 |
+
test('malformed package.json', { skip: !fs.existsSync(malformedDir) }, function (t) {
|
| 671 |
+
t.plan(5 + (requireResolveSupportsPaths ? 1 : 0));
|
| 672 |
+
|
| 673 |
+
var basedir = malformedDir;
|
| 674 |
+
var expected = path.join(basedir, 'index.js');
|
| 675 |
+
|
| 676 |
+
t.equal(
|
| 677 |
+
resolve.sync('./index.js', { basedir: basedir }),
|
| 678 |
+
expected,
|
| 679 |
+
'malformed package.json is silently ignored'
|
| 680 |
+
);
|
| 681 |
+
if (requireResolveSupportsPaths) {
|
| 682 |
+
t.equal(
|
| 683 |
+
resolve.sync('./index.js', { basedir: basedir }),
|
| 684 |
+
require.resolve('./index.js', { paths: [basedir] }),
|
| 685 |
+
'malformed package.json: resolve.sync === require.resolve'
|
| 686 |
+
);
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
var res1 = resolve.sync(
|
| 690 |
+
'./index.js',
|
| 691 |
+
{
|
| 692 |
+
basedir: basedir,
|
| 693 |
+
packageFilter: function (pkg, pkgfile, dir) {
|
| 694 |
+
t.fail('should not reach here');
|
| 695 |
+
}
|
| 696 |
+
}
|
| 697 |
+
);
|
| 698 |
+
|
| 699 |
+
t.equal(
|
| 700 |
+
res1,
|
| 701 |
+
expected,
|
| 702 |
+
'with packageFilter: malformed package.json is silently ignored'
|
| 703 |
+
);
|
| 704 |
+
|
| 705 |
+
var res2 = resolve.sync(
|
| 706 |
+
'./index.js',
|
| 707 |
+
{
|
| 708 |
+
basedir: basedir,
|
| 709 |
+
readPackageSync: function (readFileSync, pkgfile) {
|
| 710 |
+
t.equal(pkgfile, path.join(basedir, 'package.json'), 'readPackageSync: `pkgfile` is package.json path');
|
| 711 |
+
var result = String(readFileSync(pkgfile));
|
| 712 |
+
try {
|
| 713 |
+
return JSON.parse(result);
|
| 714 |
+
} catch (e) {
|
| 715 |
+
t.ok(e instanceof SyntaxError, 'readPackageSync: malformed package.json parses as a syntax error');
|
| 716 |
+
throw e;
|
| 717 |
+
}
|
| 718 |
+
}
|
| 719 |
+
}
|
| 720 |
+
);
|
| 721 |
+
|
| 722 |
+
t.equal(
|
| 723 |
+
res2,
|
| 724 |
+
expected,
|
| 725 |
+
'with readPackageSync: malformed package.json is silently ignored'
|
| 726 |
+
);
|
| 727 |
+
});
|
node_modules/eslint-plugin-react/node_modules/resolve/test/shadowed_core.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var test = require('tape');
|
| 2 |
+
var resolve = require('../');
|
| 3 |
+
var path = require('path');
|
| 4 |
+
|
| 5 |
+
test('shadowed core modules still return core module', function (t) {
|
| 6 |
+
t.plan(2);
|
| 7 |
+
|
| 8 |
+
resolve('util', { basedir: path.join(__dirname, 'shadowed_core') }, function (err, res) {
|
| 9 |
+
t.ifError(err);
|
| 10 |
+
t.equal(res, 'util');
|
| 11 |
+
});
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
test('shadowed core modules still return core module [sync]', function (t) {
|
| 15 |
+
t.plan(1);
|
| 16 |
+
|
| 17 |
+
var res = resolve.sync('util', { basedir: path.join(__dirname, 'shadowed_core') });
|
| 18 |
+
|
| 19 |
+
t.equal(res, 'util');
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
test('shadowed core modules return shadow when appending `/`', function (t) {
|
| 23 |
+
t.plan(2);
|
| 24 |
+
|
| 25 |
+
resolve('util/', { basedir: path.join(__dirname, 'shadowed_core') }, function (err, res) {
|
| 26 |
+
t.ifError(err);
|
| 27 |
+
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
|
| 28 |
+
});
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
test('shadowed core modules return shadow when appending `/` [sync]', function (t) {
|
| 32 |
+
t.plan(1);
|
| 33 |
+
|
| 34 |
+
var res = resolve.sync('util/', { basedir: path.join(__dirname, 'shadowed_core') });
|
| 35 |
+
|
| 36 |
+
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
test('shadowed core modules return shadow with `includeCoreModules: false`', function (t) {
|
| 40 |
+
t.plan(2);
|
| 41 |
+
|
| 42 |
+
resolve('util', { basedir: path.join(__dirname, 'shadowed_core'), includeCoreModules: false }, function (err, res) {
|
| 43 |
+
t.ifError(err);
|
| 44 |
+
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
|
| 45 |
+
});
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
test('shadowed core modules return shadow with `includeCoreModules: false` [sync]', function (t) {
|
| 49 |
+
t.plan(1);
|
| 50 |
+
|
| 51 |
+
var res = resolve.sync('util', { basedir: path.join(__dirname, 'shadowed_core'), includeCoreModules: false });
|
| 52 |
+
|
| 53 |
+
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
|
| 54 |
+
});
|
node_modules/eslint-plugin-react/node_modules/resolve/test/shadowed_core/node_modules/util/index.js
ADDED
|
File without changes
|
node_modules/eslint-plugin-react/node_modules/resolve/test/subdirs.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var test = require('tape');
|
| 2 |
+
var resolve = require('../');
|
| 3 |
+
var path = require('path');
|
| 4 |
+
|
| 5 |
+
test('subdirs', function (t) {
|
| 6 |
+
t.plan(2);
|
| 7 |
+
|
| 8 |
+
var dir = path.join(__dirname, '/subdirs');
|
| 9 |
+
resolve('a/b/c/x.json', { basedir: dir }, function (err, res) {
|
| 10 |
+
t.ifError(err);
|
| 11 |
+
t.equal(res, path.join(dir, 'node_modules/a/b/c/x.json'));
|
| 12 |
+
});
|
| 13 |
+
});
|
node_modules/eslint-plugin-react/node_modules/resolve/test/symlinks.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var path = require('path');
|
| 2 |
+
var fs = require('fs');
|
| 3 |
+
var test = require('tape');
|
| 4 |
+
var map = require('array.prototype.map');
|
| 5 |
+
var resolve = require('../');
|
| 6 |
+
|
| 7 |
+
var symlinkDir = path.join(__dirname, 'resolver', 'symlinked', 'symlink');
|
| 8 |
+
var packageDir = path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'package');
|
| 9 |
+
var modADir = path.join(__dirname, 'symlinks', 'source', 'node_modules', 'mod-a');
|
| 10 |
+
var symlinkModADir = path.join(__dirname, 'symlinks', 'dest', 'node_modules', 'mod-a');
|
| 11 |
+
try {
|
| 12 |
+
fs.unlinkSync(symlinkDir);
|
| 13 |
+
} catch (err) {}
|
| 14 |
+
try {
|
| 15 |
+
fs.unlinkSync(packageDir);
|
| 16 |
+
} catch (err) {}
|
| 17 |
+
try {
|
| 18 |
+
fs.unlinkSync(modADir);
|
| 19 |
+
} catch (err) {}
|
| 20 |
+
try {
|
| 21 |
+
fs.unlinkSync(symlinkModADir);
|
| 22 |
+
} catch (err) {}
|
| 23 |
+
|
| 24 |
+
try {
|
| 25 |
+
fs.symlinkSync('./_/symlink_target', symlinkDir, 'dir');
|
| 26 |
+
} catch (err) {
|
| 27 |
+
if (err.code !== 'EEXIST') {
|
| 28 |
+
// if fails then it is probably on Windows and lets try to create a junction
|
| 29 |
+
fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction');
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
try {
|
| 33 |
+
fs.symlinkSync('../../package', packageDir, 'dir');
|
| 34 |
+
} catch (err) {
|
| 35 |
+
// if fails then it is probably on Windows and lets try to create a junction
|
| 36 |
+
fs.symlinkSync(path.join(__dirname, '..', '..', 'package') + '\\', packageDir, 'junction');
|
| 37 |
+
}
|
| 38 |
+
try {
|
| 39 |
+
fs.symlinkSync('../../source/node_modules/mod-a', symlinkModADir, 'dir');
|
| 40 |
+
} catch (err) {
|
| 41 |
+
// if fails then it is probably on Windows and lets try to create a junction
|
| 42 |
+
fs.symlinkSync(path.join(__dirname, '..', '..', 'source', 'node_modules', 'mod-a') + '\\', symlinkModADir, 'junction');
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
test('symlink', function (t) {
|
| 46 |
+
t.plan(2);
|
| 47 |
+
|
| 48 |
+
resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) {
|
| 49 |
+
t.error(err);
|
| 50 |
+
t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js'));
|
| 51 |
+
});
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
test('sync symlink when preserveSymlinks = true', function (t) {
|
| 55 |
+
t.plan(4);
|
| 56 |
+
|
| 57 |
+
resolve('foo', { basedir: symlinkDir, preserveSymlinks: true }, function (err, res, pkg) {
|
| 58 |
+
t.ok(err, 'there is an error');
|
| 59 |
+
t.notOk(res, 'no result');
|
| 60 |
+
|
| 61 |
+
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
|
| 62 |
+
t.equal(
|
| 63 |
+
err && err.message,
|
| 64 |
+
'Cannot find module \'foo\' from \'' + symlinkDir + '\'',
|
| 65 |
+
'can not find nonexistent module'
|
| 66 |
+
);
|
| 67 |
+
});
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
test('sync symlink', function (t) {
|
| 71 |
+
var start = new Date();
|
| 72 |
+
t.doesNotThrow(function () {
|
| 73 |
+
t.equal(
|
| 74 |
+
resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: false }),
|
| 75 |
+
path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')
|
| 76 |
+
);
|
| 77 |
+
});
|
| 78 |
+
t.ok(new Date() - start < 50, 'resolve.sync timedout');
|
| 79 |
+
t.end();
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
test('sync symlink when preserveSymlinks = true', function (t) {
|
| 83 |
+
t.throws(function () {
|
| 84 |
+
resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: true });
|
| 85 |
+
}, /Cannot find module 'foo'/);
|
| 86 |
+
t.end();
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
test('sync symlink from node_modules to other dir when preserveSymlinks = false', function (t) {
|
| 90 |
+
var basedir = path.join(__dirname, 'resolver', 'symlinked', '_');
|
| 91 |
+
var fn = resolve.sync('package', { basedir: basedir, preserveSymlinks: false });
|
| 92 |
+
|
| 93 |
+
t.equal(fn, path.resolve(__dirname, 'resolver/symlinked/package/bar.js'));
|
| 94 |
+
t.end();
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
test('async symlink from node_modules to other dir when preserveSymlinks = false', function (t) {
|
| 98 |
+
t.plan(2);
|
| 99 |
+
var basedir = path.join(__dirname, 'resolver', 'symlinked', '_');
|
| 100 |
+
resolve('package', { basedir: basedir, preserveSymlinks: false }, function (err, result) {
|
| 101 |
+
t.notOk(err, 'no error');
|
| 102 |
+
t.equal(result, path.resolve(__dirname, 'resolver/symlinked/package/bar.js'));
|
| 103 |
+
});
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
test('packageFilter', function (t) {
|
| 107 |
+
function relative(x) {
|
| 108 |
+
return path.relative(__dirname, x);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
function testPackageFilter(preserveSymlinks) {
|
| 112 |
+
return function (st) {
|
| 113 |
+
st.plan(5);
|
| 114 |
+
|
| 115 |
+
var destMain = 'symlinks/dest/node_modules/mod-a/index.js';
|
| 116 |
+
var destPkg = 'symlinks/dest/node_modules/mod-a/package.json';
|
| 117 |
+
var sourceMain = 'symlinks/source/node_modules/mod-a/index.js';
|
| 118 |
+
var sourcePkg = 'symlinks/source/node_modules/mod-a/package.json';
|
| 119 |
+
var destDir = path.join(__dirname, 'symlinks', 'dest');
|
| 120 |
+
|
| 121 |
+
var packageFilterPath = [];
|
| 122 |
+
var actualPath = resolve.sync('mod-a', {
|
| 123 |
+
basedir: destDir,
|
| 124 |
+
preserveSymlinks: preserveSymlinks,
|
| 125 |
+
packageFilter: function (pkg, pkgfile, dir) {
|
| 126 |
+
packageFilterPath.push(pkgfile);
|
| 127 |
+
}
|
| 128 |
+
});
|
| 129 |
+
st.equal(
|
| 130 |
+
relative(actualPath),
|
| 131 |
+
path.normalize(preserveSymlinks ? destMain : sourceMain),
|
| 132 |
+
'sync: actual path is correct'
|
| 133 |
+
);
|
| 134 |
+
st.deepEqual(
|
| 135 |
+
map(packageFilterPath, relative),
|
| 136 |
+
map(preserveSymlinks ? [destPkg, destPkg] : [sourcePkg, sourcePkg], path.normalize),
|
| 137 |
+
'sync: packageFilter pkgfile arg is correct'
|
| 138 |
+
);
|
| 139 |
+
|
| 140 |
+
var asyncPackageFilterPath = [];
|
| 141 |
+
resolve(
|
| 142 |
+
'mod-a',
|
| 143 |
+
{
|
| 144 |
+
basedir: destDir,
|
| 145 |
+
preserveSymlinks: preserveSymlinks,
|
| 146 |
+
packageFilter: function (pkg, pkgfile) {
|
| 147 |
+
asyncPackageFilterPath.push(pkgfile);
|
| 148 |
+
}
|
| 149 |
+
},
|
| 150 |
+
function (err, actualPath) {
|
| 151 |
+
st.error(err, 'no error');
|
| 152 |
+
st.equal(
|
| 153 |
+
relative(actualPath),
|
| 154 |
+
path.normalize(preserveSymlinks ? destMain : sourceMain),
|
| 155 |
+
'async: actual path is correct'
|
| 156 |
+
);
|
| 157 |
+
st.deepEqual(
|
| 158 |
+
map(asyncPackageFilterPath, relative),
|
| 159 |
+
map(
|
| 160 |
+
preserveSymlinks ? [destPkg, destPkg, destPkg] : [sourcePkg, sourcePkg, sourcePkg],
|
| 161 |
+
path.normalize
|
| 162 |
+
),
|
| 163 |
+
'async: packageFilter pkgfile arg is correct'
|
| 164 |
+
);
|
| 165 |
+
}
|
| 166 |
+
);
|
| 167 |
+
};
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
t.test('preserveSymlinks: false', testPackageFilter(false));
|
| 171 |
+
|
| 172 |
+
t.test('preserveSymlinks: true', testPackageFilter(true));
|
| 173 |
+
|
| 174 |
+
t.end();
|
| 175 |
+
});
|
node_modules/eslint-plugin-react/node_modules/semver/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 10 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 12 |
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
| 15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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
semver(1) -- The semantic versioner for npm
|
| 2 |
+
===========================================
|
| 3 |
+
|
| 4 |
+
## Install
|
| 5 |
+
|
| 6 |
+
```bash
|
| 7 |
+
npm install semver
|
| 8 |
+
````
|
| 9 |
+
|
| 10 |
+
## Usage
|
| 11 |
+
|
| 12 |
+
As a node module:
|
| 13 |
+
|
| 14 |
+
```js
|
| 15 |
+
const semver = require('semver')
|
| 16 |
+
|
| 17 |
+
semver.valid('1.2.3') // '1.2.3'
|
| 18 |
+
semver.valid('a.b.c') // null
|
| 19 |
+
semver.clean(' =v1.2.3 ') // '1.2.3'
|
| 20 |
+
semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
|
| 21 |
+
semver.gt('1.2.3', '9.8.7') // false
|
| 22 |
+
semver.lt('1.2.3', '9.8.7') // true
|
| 23 |
+
semver.minVersion('>=1.0.0') // '1.0.0'
|
| 24 |
+
semver.valid(semver.coerce('v2')) // '2.0.0'
|
| 25 |
+
semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
As a command-line utility:
|
| 29 |
+
|
| 30 |
+
```
|
| 31 |
+
$ semver -h
|
| 32 |
+
|
| 33 |
+
A JavaScript implementation of the https://semver.org/ specification
|
| 34 |
+
Copyright Isaac Z. Schlueter
|
| 35 |
+
|
| 36 |
+
Usage: semver [options] <version> [<version> [...]]
|
| 37 |
+
Prints valid versions sorted by SemVer precedence
|
| 38 |
+
|
| 39 |
+
Options:
|
| 40 |
+
-r --range <range>
|
| 41 |
+
Print versions that match the specified range.
|
| 42 |
+
|
| 43 |
+
-i --increment [<level>]
|
| 44 |
+
Increment a version by the specified level. Level can
|
| 45 |
+
be one of: major, minor, patch, premajor, preminor,
|
| 46 |
+
prepatch, or prerelease. Default level is 'patch'.
|
| 47 |
+
Only one version may be specified.
|
| 48 |
+
|
| 49 |
+
--preid <identifier>
|
| 50 |
+
Identifier to be used to prefix premajor, preminor,
|
| 51 |
+
prepatch or prerelease version increments.
|
| 52 |
+
|
| 53 |
+
-l --loose
|
| 54 |
+
Interpret versions and ranges loosely
|
| 55 |
+
|
| 56 |
+
-p --include-prerelease
|
| 57 |
+
Always include prerelease versions in range matching
|
| 58 |
+
|
| 59 |
+
-c --coerce
|
| 60 |
+
Coerce a string into SemVer if possible
|
| 61 |
+
(does not imply --loose)
|
| 62 |
+
|
| 63 |
+
--rtl
|
| 64 |
+
Coerce version strings right to left
|
| 65 |
+
|
| 66 |
+
--ltr
|
| 67 |
+
Coerce version strings left to right (default)
|
| 68 |
+
|
| 69 |
+
Program exits successfully if any valid version satisfies
|
| 70 |
+
all supplied ranges, and prints all satisfying versions.
|
| 71 |
+
|
| 72 |
+
If no satisfying versions are found, then exits failure.
|
| 73 |
+
|
| 74 |
+
Versions are printed in ascending order, so supplying
|
| 75 |
+
multiple versions to the utility will just sort them.
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Versions
|
| 79 |
+
|
| 80 |
+
A "version" is described by the `v2.0.0` specification found at
|
| 81 |
+
<https://semver.org/>.
|
| 82 |
+
|
| 83 |
+
A leading `"="` or `"v"` character is stripped off and ignored.
|
| 84 |
+
|
| 85 |
+
## Ranges
|
| 86 |
+
|
| 87 |
+
A `version range` is a set of `comparators` which specify versions
|
| 88 |
+
that satisfy the range.
|
| 89 |
+
|
| 90 |
+
A `comparator` is composed of an `operator` and a `version`. The set
|
| 91 |
+
of primitive `operators` is:
|
| 92 |
+
|
| 93 |
+
* `<` Less than
|
| 94 |
+
* `<=` Less than or equal to
|
| 95 |
+
* `>` Greater than
|
| 96 |
+
* `>=` Greater than or equal to
|
| 97 |
+
* `=` Equal. If no operator is specified, then equality is assumed,
|
| 98 |
+
so this operator is optional, but MAY be included.
|
| 99 |
+
|
| 100 |
+
For example, the comparator `>=1.2.7` would match the versions
|
| 101 |
+
`1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6`
|
| 102 |
+
or `1.1.0`.
|
| 103 |
+
|
| 104 |
+
Comparators can be joined by whitespace to form a `comparator set`,
|
| 105 |
+
which is satisfied by the **intersection** of all of the comparators
|
| 106 |
+
it includes.
|
| 107 |
+
|
| 108 |
+
A range is composed of one or more comparator sets, joined by `||`. A
|
| 109 |
+
version matches a range if and only if every comparator in at least
|
| 110 |
+
one of the `||`-separated comparator sets is satisfied by the version.
|
| 111 |
+
|
| 112 |
+
For example, the range `>=1.2.7 <1.3.0` would match the versions
|
| 113 |
+
`1.2.7`, `1.2.8`, and `1.2.99`, but not the versions `1.2.6`, `1.3.0`,
|
| 114 |
+
or `1.1.0`.
|
| 115 |
+
|
| 116 |
+
The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`,
|
| 117 |
+
`1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`.
|
| 118 |
+
|
| 119 |
+
### Prerelease Tags
|
| 120 |
+
|
| 121 |
+
If a version has a prerelease tag (for example, `1.2.3-alpha.3`) then
|
| 122 |
+
it will only be allowed to satisfy comparator sets if at least one
|
| 123 |
+
comparator with the same `[major, minor, patch]` tuple also has a
|
| 124 |
+
prerelease tag.
|
| 125 |
+
|
| 126 |
+
For example, the range `>1.2.3-alpha.3` would be allowed to match the
|
| 127 |
+
version `1.2.3-alpha.7`, but it would *not* be satisfied by
|
| 128 |
+
`3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater
|
| 129 |
+
than" `1.2.3-alpha.3` according to the SemVer sort rules. The version
|
| 130 |
+
range only accepts prerelease tags on the `1.2.3` version. The
|
| 131 |
+
version `3.4.5` *would* satisfy the range, because it does not have a
|
| 132 |
+
prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`.
|
| 133 |
+
|
| 134 |
+
The purpose for this behavior is twofold. First, prerelease versions
|
| 135 |
+
frequently are updated very quickly, and contain many breaking changes
|
| 136 |
+
that are (by the author's design) not yet fit for public consumption.
|
| 137 |
+
Therefore, by default, they are excluded from range matching
|
| 138 |
+
semantics.
|
| 139 |
+
|
| 140 |
+
Second, a user who has opted into using a prerelease version has
|
| 141 |
+
clearly indicated the intent to use *that specific* set of
|
| 142 |
+
alpha/beta/rc versions. By including a prerelease tag in the range,
|
| 143 |
+
the user is indicating that they are aware of the risk. However, it
|
| 144 |
+
is still not appropriate to assume that they have opted into taking a
|
| 145 |
+
similar risk on the *next* set of prerelease versions.
|
| 146 |
+
|
| 147 |
+
Note that this behavior can be suppressed (treating all prerelease
|
| 148 |
+
versions as if they were normal versions, for the purpose of range
|
| 149 |
+
matching) by setting the `includePrerelease` flag on the options
|
| 150 |
+
object to any
|
| 151 |
+
[functions](https://github.com/npm/node-semver#functions) that do
|
| 152 |
+
range matching.
|
| 153 |
+
|
| 154 |
+
#### Prerelease Identifiers
|
| 155 |
+
|
| 156 |
+
The method `.inc` takes an additional `identifier` string argument that
|
| 157 |
+
will append the value of the string as a prerelease identifier:
|
| 158 |
+
|
| 159 |
+
```javascript
|
| 160 |
+
semver.inc('1.2.3', 'prerelease', 'beta')
|
| 161 |
+
// '1.2.4-beta.0'
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
command-line example:
|
| 165 |
+
|
| 166 |
+
```bash
|
| 167 |
+
$ semver 1.2.3 -i prerelease --preid beta
|
| 168 |
+
1.2.4-beta.0
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
Which then can be used to increment further:
|
| 172 |
+
|
| 173 |
+
```bash
|
| 174 |
+
$ semver 1.2.4-beta.0 -i prerelease
|
| 175 |
+
1.2.4-beta.1
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
### Advanced Range Syntax
|
| 179 |
+
|
| 180 |
+
Advanced range syntax desugars to primitive comparators in
|
| 181 |
+
deterministic ways.
|
| 182 |
+
|
| 183 |
+
Advanced ranges may be combined in the same way as primitive
|
| 184 |
+
comparators using white space or `||`.
|
| 185 |
+
|
| 186 |
+
#### Hyphen Ranges `X.Y.Z - A.B.C`
|
| 187 |
+
|
| 188 |
+
Specifies an inclusive set.
|
| 189 |
+
|
| 190 |
+
* `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4`
|
| 191 |
+
|
| 192 |
+
If a partial version is provided as the first version in the inclusive
|
| 193 |
+
range, then the missing pieces are replaced with zeroes.
|
| 194 |
+
|
| 195 |
+
* `1.2 - 2.3.4` := `>=1.2.0 <=2.3.4`
|
| 196 |
+
|
| 197 |
+
If a partial version is provided as the second version in the
|
| 198 |
+
inclusive range, then all versions that start with the supplied parts
|
| 199 |
+
of the tuple are accepted, but nothing that would be greater than the
|
| 200 |
+
provided tuple parts.
|
| 201 |
+
|
| 202 |
+
* `1.2.3 - 2.3` := `>=1.2.3 <2.4.0`
|
| 203 |
+
* `1.2.3 - 2` := `>=1.2.3 <3.0.0`
|
| 204 |
+
|
| 205 |
+
#### X-Ranges `1.2.x` `1.X` `1.2.*` `*`
|
| 206 |
+
|
| 207 |
+
Any of `X`, `x`, or `*` may be used to "stand in" for one of the
|
| 208 |
+
numeric values in the `[major, minor, patch]` tuple.
|
| 209 |
+
|
| 210 |
+
* `*` := `>=0.0.0` (Any version satisfies)
|
| 211 |
+
* `1.x` := `>=1.0.0 <2.0.0` (Matching major version)
|
| 212 |
+
* `1.2.x` := `>=1.2.0 <1.3.0` (Matching major and minor versions)
|
| 213 |
+
|
| 214 |
+
A partial version range is treated as an X-Range, so the special
|
| 215 |
+
character is in fact optional.
|
| 216 |
+
|
| 217 |
+
* `""` (empty string) := `*` := `>=0.0.0`
|
| 218 |
+
* `1` := `1.x.x` := `>=1.0.0 <2.0.0`
|
| 219 |
+
* `1.2` := `1.2.x` := `>=1.2.0 <1.3.0`
|
| 220 |
+
|
| 221 |
+
#### Tilde Ranges `~1.2.3` `~1.2` `~1`
|
| 222 |
+
|
| 223 |
+
Allows patch-level changes if a minor version is specified on the
|
| 224 |
+
comparator. Allows minor-level changes if not.
|
| 225 |
+
|
| 226 |
+
* `~1.2.3` := `>=1.2.3 <1.(2+1).0` := `>=1.2.3 <1.3.0`
|
| 227 |
+
* `~1.2` := `>=1.2.0 <1.(2+1).0` := `>=1.2.0 <1.3.0` (Same as `1.2.x`)
|
| 228 |
+
* `~1` := `>=1.0.0 <(1+1).0.0` := `>=1.0.0 <2.0.0` (Same as `1.x`)
|
| 229 |
+
* `~0.2.3` := `>=0.2.3 <0.(2+1).0` := `>=0.2.3 <0.3.0`
|
| 230 |
+
* `~0.2` := `>=0.2.0 <0.(2+1).0` := `>=0.2.0 <0.3.0` (Same as `0.2.x`)
|
| 231 |
+
* `~0` := `>=0.0.0 <(0+1).0.0` := `>=0.0.0 <1.0.0` (Same as `0.x`)
|
| 232 |
+
* `~1.2.3-beta.2` := `>=1.2.3-beta.2 <1.3.0` Note that prereleases in
|
| 233 |
+
the `1.2.3` version will be allowed, if they are greater than or
|
| 234 |
+
equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
|
| 235 |
+
`1.2.4-beta.2` would not, because it is a prerelease of a
|
| 236 |
+
different `[major, minor, patch]` tuple.
|
| 237 |
+
|
| 238 |
+
#### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4`
|
| 239 |
+
|
| 240 |
+
Allows changes that do not modify the left-most non-zero element in the
|
| 241 |
+
`[major, minor, patch]` tuple. In other words, this allows patch and
|
| 242 |
+
minor updates for versions `1.0.0` and above, patch updates for
|
| 243 |
+
versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`.
|
| 244 |
+
|
| 245 |
+
Many authors treat a `0.x` version as if the `x` were the major
|
| 246 |
+
"breaking-change" indicator.
|
| 247 |
+
|
| 248 |
+
Caret ranges are ideal when an author may make breaking changes
|
| 249 |
+
between `0.2.4` and `0.3.0` releases, which is a common practice.
|
| 250 |
+
However, it presumes that there will *not* be breaking changes between
|
| 251 |
+
`0.2.4` and `0.2.5`. It allows for changes that are presumed to be
|
| 252 |
+
additive (but non-breaking), according to commonly observed practices.
|
| 253 |
+
|
| 254 |
+
* `^1.2.3` := `>=1.2.3 <2.0.0`
|
| 255 |
+
* `^0.2.3` := `>=0.2.3 <0.3.0`
|
| 256 |
+
* `^0.0.3` := `>=0.0.3 <0.0.4`
|
| 257 |
+
* `^1.2.3-beta.2` := `>=1.2.3-beta.2 <2.0.0` Note that prereleases in
|
| 258 |
+
the `1.2.3` version will be allowed, if they are greater than or
|
| 259 |
+
equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
|
| 260 |
+
`1.2.4-beta.2` would not, because it is a prerelease of a
|
| 261 |
+
different `[major, minor, patch]` tuple.
|
| 262 |
+
* `^0.0.3-beta` := `>=0.0.3-beta <0.0.4` Note that prereleases in the
|
| 263 |
+
`0.0.3` version *only* will be allowed, if they are greater than or
|
| 264 |
+
equal to `beta`. So, `0.0.3-pr.2` would be allowed.
|
| 265 |
+
|
| 266 |
+
When parsing caret ranges, a missing `patch` value desugars to the
|
| 267 |
+
number `0`, but will allow flexibility within that value, even if the
|
| 268 |
+
major and minor versions are both `0`.
|
| 269 |
+
|
| 270 |
+
* `^1.2.x` := `>=1.2.0 <2.0.0`
|
| 271 |
+
* `^0.0.x` := `>=0.0.0 <0.1.0`
|
| 272 |
+
* `^0.0` := `>=0.0.0 <0.1.0`
|
| 273 |
+
|
| 274 |
+
A missing `minor` and `patch` values will desugar to zero, but also
|
| 275 |
+
allow flexibility within those values, even if the major version is
|
| 276 |
+
zero.
|
| 277 |
+
|
| 278 |
+
* `^1.x` := `>=1.0.0 <2.0.0`
|
| 279 |
+
* `^0.x` := `>=0.0.0 <1.0.0`
|
| 280 |
+
|
| 281 |
+
### Range Grammar
|
| 282 |
+
|
| 283 |
+
Putting all this together, here is a Backus-Naur grammar for ranges,
|
| 284 |
+
for the benefit of parser authors:
|
| 285 |
+
|
| 286 |
+
```bnf
|
| 287 |
+
range-set ::= range ( logical-or range ) *
|
| 288 |
+
logical-or ::= ( ' ' ) * '||' ( ' ' ) *
|
| 289 |
+
range ::= hyphen | simple ( ' ' simple ) * | ''
|
| 290 |
+
hyphen ::= partial ' - ' partial
|
| 291 |
+
simple ::= primitive | partial | tilde | caret
|
| 292 |
+
primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
|
| 293 |
+
partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
|
| 294 |
+
xr ::= 'x' | 'X' | '*' | nr
|
| 295 |
+
nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
|
| 296 |
+
tilde ::= '~' partial
|
| 297 |
+
caret ::= '^' partial
|
| 298 |
+
qualifier ::= ( '-' pre )? ( '+' build )?
|
| 299 |
+
pre ::= parts
|
| 300 |
+
build ::= parts
|
| 301 |
+
parts ::= part ( '.' part ) *
|
| 302 |
+
part ::= nr | [-0-9A-Za-z]+
|
| 303 |
+
```
|
| 304 |
+
|
| 305 |
+
## Functions
|
| 306 |
+
|
| 307 |
+
All methods and classes take a final `options` object argument. All
|
| 308 |
+
options in this object are `false` by default. The options supported
|
| 309 |
+
are:
|
| 310 |
+
|
| 311 |
+
- `loose` Be more forgiving about not-quite-valid semver strings.
|
| 312 |
+
(Any resulting output will always be 100% strict compliant, of
|
| 313 |
+
course.) For backwards compatibility reasons, if the `options`
|
| 314 |
+
argument is a boolean value instead of an object, it is interpreted
|
| 315 |
+
to be the `loose` param.
|
| 316 |
+
- `includePrerelease` Set to suppress the [default
|
| 317 |
+
behavior](https://github.com/npm/node-semver#prerelease-tags) of
|
| 318 |
+
excluding prerelease tagged versions from ranges unless they are
|
| 319 |
+
explicitly opted into.
|
| 320 |
+
|
| 321 |
+
Strict-mode Comparators and Ranges will be strict about the SemVer
|
| 322 |
+
strings that they parse.
|
| 323 |
+
|
| 324 |
+
* `valid(v)`: Return the parsed version, or null if it's not valid.
|
| 325 |
+
* `inc(v, release)`: Return the version incremented by the release
|
| 326 |
+
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
|
| 327 |
+
`prepatch`, or `prerelease`), or null if it's not valid
|
| 328 |
+
* `premajor` in one call will bump the version up to the next major
|
| 329 |
+
version and down to a prerelease of that major version.
|
| 330 |
+
`preminor`, and `prepatch` work the same way.
|
| 331 |
+
* If called from a non-prerelease version, the `prerelease` will work the
|
| 332 |
+
same as `prepatch`. It increments the patch version, then makes a
|
| 333 |
+
prerelease. If the input version is already a prerelease it simply
|
| 334 |
+
increments it.
|
| 335 |
+
* `prerelease(v)`: Returns an array of prerelease components, or null
|
| 336 |
+
if none exist. Example: `prerelease('1.2.3-alpha.1') -> ['alpha', 1]`
|
| 337 |
+
* `major(v)`: Return the major version number.
|
| 338 |
+
* `minor(v)`: Return the minor version number.
|
| 339 |
+
* `patch(v)`: Return the patch version number.
|
| 340 |
+
* `intersects(r1, r2, loose)`: Return true if the two supplied ranges
|
| 341 |
+
or comparators intersect.
|
| 342 |
+
* `parse(v)`: Attempt to parse a string as a semantic version, returning either
|
| 343 |
+
a `SemVer` object or `null`.
|
| 344 |
+
|
| 345 |
+
### Comparison
|
| 346 |
+
|
| 347 |
+
* `gt(v1, v2)`: `v1 > v2`
|
| 348 |
+
* `gte(v1, v2)`: `v1 >= v2`
|
| 349 |
+
* `lt(v1, v2)`: `v1 < v2`
|
| 350 |
+
* `lte(v1, v2)`: `v1 <= v2`
|
| 351 |
+
* `eq(v1, v2)`: `v1 == v2` This is true if they're logically equivalent,
|
| 352 |
+
even if they're not the exact same string. You already know how to
|
| 353 |
+
compare strings.
|
| 354 |
+
* `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
|
| 355 |
+
* `cmp(v1, comparator, v2)`: Pass in a comparison string, and it'll call
|
| 356 |
+
the corresponding function above. `"==="` and `"!=="` do simple
|
| 357 |
+
string comparison, but are included for completeness. Throws if an
|
| 358 |
+
invalid comparison string is provided.
|
| 359 |
+
* `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if
|
| 360 |
+
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
| 361 |
+
* `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
|
| 362 |
+
in descending order when passed to `Array.sort()`.
|
| 363 |
+
* `compareBuild(v1, v2)`: The same as `compare` but considers `build` when two versions
|
| 364 |
+
are equal. Sorts in ascending order if passed to `Array.sort()`.
|
| 365 |
+
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
| 366 |
+
* `diff(v1, v2)`: Returns difference between two versions by the release type
|
| 367 |
+
(`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
|
| 368 |
+
or null if the versions are the same.
|
| 369 |
+
|
| 370 |
+
### Comparators
|
| 371 |
+
|
| 372 |
+
* `intersects(comparator)`: Return true if the comparators intersect
|
| 373 |
+
|
| 374 |
+
### Ranges
|
| 375 |
+
|
| 376 |
+
* `validRange(range)`: Return the valid range or null if it's not valid
|
| 377 |
+
* `satisfies(version, range)`: Return true if the version satisfies the
|
| 378 |
+
range.
|
| 379 |
+
* `maxSatisfying(versions, range)`: Return the highest version in the list
|
| 380 |
+
that satisfies the range, or `null` if none of them do.
|
| 381 |
+
* `minSatisfying(versions, range)`: Return the lowest version in the list
|
| 382 |
+
that satisfies the range, or `null` if none of them do.
|
| 383 |
+
* `minVersion(range)`: Return the lowest version that can possibly match
|
| 384 |
+
the given range.
|
| 385 |
+
* `gtr(version, range)`: Return `true` if version is greater than all the
|
| 386 |
+
versions possible in the range.
|
| 387 |
+
* `ltr(version, range)`: Return `true` if version is less than all the
|
| 388 |
+
versions possible in the range.
|
| 389 |
+
* `outside(version, range, hilo)`: Return true if the version is outside
|
| 390 |
+
the bounds of the range in either the high or low direction. The
|
| 391 |
+
`hilo` argument must be either the string `'>'` or `'<'`. (This is
|
| 392 |
+
the function called by `gtr` and `ltr`.)
|
| 393 |
+
* `intersects(range)`: Return true if any of the ranges comparators intersect
|
| 394 |
+
|
| 395 |
+
Note that, since ranges may be non-contiguous, a version might not be
|
| 396 |
+
greater than a range, less than a range, *or* satisfy a range! For
|
| 397 |
+
example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9`
|
| 398 |
+
until `2.0.0`, so the version `1.2.10` would not be greater than the
|
| 399 |
+
range (because `2.0.1` satisfies, which is higher), nor less than the
|
| 400 |
+
range (since `1.2.8` satisfies, which is lower), and it also does not
|
| 401 |
+
satisfy the range.
|
| 402 |
+
|
| 403 |
+
If you want to know if a version satisfies or does not satisfy a
|
| 404 |
+
range, use the `satisfies(version, range)` function.
|
| 405 |
+
|
| 406 |
+
### Coercion
|
| 407 |
+
|
| 408 |
+
* `coerce(version, options)`: Coerces a string to semver if possible
|
| 409 |
+
|
| 410 |
+
This aims to provide a very forgiving translation of a non-semver string to
|
| 411 |
+
semver. It looks for the first digit in a string, and consumes all
|
| 412 |
+
remaining characters which satisfy at least a partial semver (e.g., `1`,
|
| 413 |
+
`1.2`, `1.2.3`) up to the max permitted length (256 characters). Longer
|
| 414 |
+
versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`). All
|
| 415 |
+
surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes
|
| 416 |
+
`3.4.0`). Only text which lacks digits will fail coercion (`version one`
|
| 417 |
+
is not valid). The maximum length for any semver component considered for
|
| 418 |
+
coercion is 16 characters; longer components will be ignored
|
| 419 |
+
(`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any
|
| 420 |
+
semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
|
| 421 |
+
components are invalid (`9999999999999999.4.7.4` is likely invalid).
|
| 422 |
+
|
| 423 |
+
If the `options.rtl` flag is set, then `coerce` will return the right-most
|
| 424 |
+
coercible tuple that does not share an ending index with a longer coercible
|
| 425 |
+
tuple. For example, `1.2.3.4` will return `2.3.4` in rtl mode, not
|
| 426 |
+
`4.0.0`. `1.2.3/4` will return `4.0.0`, because the `4` is not a part of
|
| 427 |
+
any other overlapping SemVer tuple.
|
| 428 |
+
|
| 429 |
+
### Clean
|
| 430 |
+
|
| 431 |
+
* `clean(version)`: Clean a string to be a valid semver if possible
|
| 432 |
+
|
| 433 |
+
This will return a cleaned and trimmed semver version. If the provided version is not valid a null will be returned. This does not work for ranges.
|
| 434 |
+
|
| 435 |
+
ex.
|
| 436 |
+
* `s.clean(' = v 2.1.5foo')`: `null`
|
| 437 |
+
* `s.clean(' = v 2.1.5foo', { loose: true })`: `'2.1.5-foo'`
|
| 438 |
+
* `s.clean(' = v 2.1.5-foo')`: `null`
|
| 439 |
+
* `s.clean(' = v 2.1.5-foo', { loose: true })`: `'2.1.5-foo'`
|
| 440 |
+
* `s.clean('=v2.1.5')`: `'2.1.5'`
|
| 441 |
+
* `s.clean(' =v2.1.5')`: `2.1.5`
|
| 442 |
+
* `s.clean(' 2.1.5 ')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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
// Standalone semver comparison program.
|
| 3 |
+
// Exits successfully and prints matching version(s) if
|
| 4 |
+
// any supplied version is valid and passes all tests.
|
| 5 |
+
|
| 6 |
+
var argv = process.argv.slice(2)
|
| 7 |
+
|
| 8 |
+
var versions = []
|
| 9 |
+
|
| 10 |
+
var range = []
|
| 11 |
+
|
| 12 |
+
var inc = null
|
| 13 |
+
|
| 14 |
+
var version = require('../package.json').version
|
| 15 |
+
|
| 16 |
+
var loose = false
|
| 17 |
+
|
| 18 |
+
var includePrerelease = false
|
| 19 |
+
|
| 20 |
+
var coerce = false
|
| 21 |
+
|
| 22 |
+
var rtl = false
|
| 23 |
+
|
| 24 |
+
var identifier
|
| 25 |
+
|
| 26 |
+
var semver = require('../semver')
|
| 27 |
+
|
| 28 |
+
var reverse = false
|
| 29 |
+
|
| 30 |
+
var options = {}
|
| 31 |
+
|
| 32 |
+
main()
|
| 33 |
+
|
| 34 |
+
function main () {
|
| 35 |
+
if (!argv.length) return help()
|
| 36 |
+
while (argv.length) {
|
| 37 |
+
var a = argv.shift()
|
| 38 |
+
var indexOfEqualSign = a.indexOf('=')
|
| 39 |
+
if (indexOfEqualSign !== -1) {
|
| 40 |
+
a = a.slice(0, indexOfEqualSign)
|
| 41 |
+
argv.unshift(a.slice(indexOfEqualSign + 1))
|
| 42 |
+
}
|
| 43 |
+
switch (a) {
|
| 44 |
+
case '-rv': case '-rev': case '--rev': case '--reverse':
|
| 45 |
+
reverse = true
|
| 46 |
+
break
|
| 47 |
+
case '-l': case '--loose':
|
| 48 |
+
loose = true
|
| 49 |
+
break
|
| 50 |
+
case '-p': case '--include-prerelease':
|
| 51 |
+
includePrerelease = true
|
| 52 |
+
break
|
| 53 |
+
case '-v': case '--version':
|
| 54 |
+
versions.push(argv.shift())
|
| 55 |
+
break
|
| 56 |
+
case '-i': case '--inc': case '--increment':
|
| 57 |
+
switch (argv[0]) {
|
| 58 |
+
case 'major': case 'minor': case 'patch': case 'prerelease':
|
| 59 |
+
case 'premajor': case 'preminor': case 'prepatch':
|
| 60 |
+
inc = argv.shift()
|
| 61 |
+
break
|
| 62 |
+
default:
|
| 63 |
+
inc = 'patch'
|
| 64 |
+
break
|
| 65 |
+
}
|
| 66 |
+
break
|
| 67 |
+
case '--preid':
|
| 68 |
+
identifier = argv.shift()
|
| 69 |
+
break
|
| 70 |
+
case '-r': case '--range':
|
| 71 |
+
range.push(argv.shift())
|
| 72 |
+
break
|
| 73 |
+
case '-c': case '--coerce':
|
| 74 |
+
coerce = true
|
| 75 |
+
break
|
| 76 |
+
case '--rtl':
|
| 77 |
+
rtl = true
|
| 78 |
+
break
|
| 79 |
+
case '--ltr':
|
| 80 |
+
rtl = false
|
| 81 |
+
break
|
| 82 |
+
case '-h': case '--help': case '-?':
|
| 83 |
+
return help()
|
| 84 |
+
default:
|
| 85 |
+
versions.push(a)
|
| 86 |
+
break
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
var options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
|
| 91 |
+
|
| 92 |
+
versions = versions.map(function (v) {
|
| 93 |
+
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
|
| 94 |
+
}).filter(function (v) {
|
| 95 |
+
return semver.valid(v)
|
| 96 |
+
})
|
| 97 |
+
if (!versions.length) return fail()
|
| 98 |
+
if (inc && (versions.length !== 1 || range.length)) { return failInc() }
|
| 99 |
+
|
| 100 |
+
for (var i = 0, l = range.length; i < l; i++) {
|
| 101 |
+
versions = versions.filter(function (v) {
|
| 102 |
+
return semver.satisfies(v, range[i], options)
|
| 103 |
+
})
|
| 104 |
+
if (!versions.length) return fail()
|
| 105 |
+
}
|
| 106 |
+
return success(versions)
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
function failInc () {
|
| 110 |
+
console.error('--inc can only be used on a single version with no range')
|
| 111 |
+
fail()
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
function fail () { process.exit(1) }
|
| 115 |
+
|
| 116 |
+
function success () {
|
| 117 |
+
var compare = reverse ? 'rcompare' : 'compare'
|
| 118 |
+
versions.sort(function (a, b) {
|
| 119 |
+
return semver[compare](a, b, options)
|
| 120 |
+
}).map(function (v) {
|
| 121 |
+
return semver.clean(v, options)
|
| 122 |
+
}).map(function (v) {
|
| 123 |
+
return inc ? semver.inc(v, inc, options, identifier) : v
|
| 124 |
+
}).forEach(function (v, i, _) { console.log(v) })
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function help () {
|
| 128 |
+
console.log(['SemVer ' + version,
|
| 129 |
+
'',
|
| 130 |
+
'A JavaScript implementation of the https://semver.org/ specification',
|
| 131 |
+
'Copyright Isaac Z. Schlueter',
|
| 132 |
+
'',
|
| 133 |
+
'Usage: semver [options] <version> [<version> [...]]',
|
| 134 |
+
'Prints valid versions sorted by SemVer precedence',
|
| 135 |
+
'',
|
| 136 |
+
'Options:',
|
| 137 |
+
'-r --range <range>',
|
| 138 |
+
' Print versions that match the specified range.',
|
| 139 |
+
'',
|
| 140 |
+
'-i --increment [<level>]',
|
| 141 |
+
' Increment a version by the specified level. Level can',
|
| 142 |
+
' be one of: major, minor, patch, premajor, preminor,',
|
| 143 |
+
" prepatch, or prerelease. Default level is 'patch'.",
|
| 144 |
+
' Only one version may be specified.',
|
| 145 |
+
'',
|
| 146 |
+
'--preid <identifier>',
|
| 147 |
+
' Identifier to be used to prefix premajor, preminor,',
|
| 148 |
+
' prepatch or prerelease version increments.',
|
| 149 |
+
'',
|
| 150 |
+
'-l --loose',
|
| 151 |
+
' Interpret versions and ranges loosely',
|
| 152 |
+
'',
|
| 153 |
+
'-p --include-prerelease',
|
| 154 |
+
' Always include prerelease versions in range matching',
|
| 155 |
+
'',
|
| 156 |
+
'-c --coerce',
|
| 157 |
+
' Coerce a string into SemVer if possible',
|
| 158 |
+
' (does not imply --loose)',
|
| 159 |
+
'',
|
| 160 |
+
'--rtl',
|
| 161 |
+
' Coerce version strings right to left',
|
| 162 |
+
'',
|
| 163 |
+
'--ltr',
|
| 164 |
+
' Coerce version strings left to right (default)',
|
| 165 |
+
'',
|
| 166 |
+
'Program exits successfully if any valid version satisfies',
|
| 167 |
+
'all supplied ranges, and prints all satisfying versions.',
|
| 168 |
+
'',
|
| 169 |
+
'If no satisfying versions are found, then exits failure.',
|
| 170 |
+
'',
|
| 171 |
+
'Versions are printed in ascending order, so supplying',
|
| 172 |
+
'multiple versions to the utility will just sort them.'
|
| 173 |
+
].join('\n'))
|
| 174 |
+
}
|
node_modules/eslint-plugin-react/node_modules/semver/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "semver",
|
| 3 |
+
"version": "6.3.1",
|
| 4 |
+
"description": "The semantic version parser used by npm.",
|
| 5 |
+
"main": "semver.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"test": "tap test/ --100 --timeout=30",
|
| 8 |
+
"lint": "echo linting disabled",
|
| 9 |
+
"postlint": "template-oss-check",
|
| 10 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 11 |
+
"lintfix": "npm run lint -- --fix",
|
| 12 |
+
"snap": "tap test/ --100 --timeout=30",
|
| 13 |
+
"posttest": "npm run lint"
|
| 14 |
+
},
|
| 15 |
+
"devDependencies": {
|
| 16 |
+
"@npmcli/template-oss": "4.17.0",
|
| 17 |
+
"tap": "^12.7.0"
|
| 18 |
+
},
|
| 19 |
+
"license": "ISC",
|
| 20 |
+
"repository": {
|
| 21 |
+
"type": "git",
|
| 22 |
+
"url": "https://github.com/npm/node-semver.git"
|
| 23 |
+
},
|
| 24 |
+
"bin": {
|
| 25 |
+
"semver": "./bin/semver.js"
|
| 26 |
+
},
|
| 27 |
+
"files": [
|
| 28 |
+
"bin",
|
| 29 |
+
"range.bnf",
|
| 30 |
+
"semver.js"
|
| 31 |
+
],
|
| 32 |
+
"author": "GitHub Inc.",
|
| 33 |
+
"templateOSS": {
|
| 34 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 35 |
+
"content": "./scripts/template-oss",
|
| 36 |
+
"version": "4.17.0"
|
| 37 |
+
}
|
| 38 |
+
}
|
node_modules/eslint-plugin-react/node_modules/semver/range.bnf
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
range-set ::= range ( logical-or range ) *
|
| 2 |
+
logical-or ::= ( ' ' ) * '||' ( ' ' ) *
|
| 3 |
+
range ::= hyphen | simple ( ' ' simple ) * | ''
|
| 4 |
+
hyphen ::= partial ' - ' partial
|
| 5 |
+
simple ::= primitive | partial | tilde | caret
|
| 6 |
+
primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
|
| 7 |
+
partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
|
| 8 |
+
xr ::= 'x' | 'X' | '*' | nr
|
| 9 |
+
nr ::= '0' | [1-9] ( [0-9] ) *
|
| 10 |
+
tilde ::= '~' partial
|
| 11 |
+
caret ::= '^' partial
|
| 12 |
+
qualifier ::= ( '-' pre )? ( '+' build )?
|
| 13 |
+
pre ::= parts
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
exports = module.exports = SemVer
|
| 2 |
+
|
| 3 |
+
var debug
|
| 4 |
+
/* istanbul ignore next */
|
| 5 |
+
if (typeof process === 'object' &&
|
| 6 |
+
process.env &&
|
| 7 |
+
process.env.NODE_DEBUG &&
|
| 8 |
+
/\bsemver\b/i.test(process.env.NODE_DEBUG)) {
|
| 9 |
+
debug = function () {
|
| 10 |
+
var args = Array.prototype.slice.call(arguments, 0)
|
| 11 |
+
args.unshift('SEMVER')
|
| 12 |
+
console.log.apply(console, args)
|
| 13 |
+
}
|
| 14 |
+
} else {
|
| 15 |
+
debug = function () {}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
// Note: this is the semver.org version of the spec that it implements
|
| 19 |
+
// Not necessarily the package version of this code.
|
| 20 |
+
exports.SEMVER_SPEC_VERSION = '2.0.0'
|
| 21 |
+
|
| 22 |
+
var MAX_LENGTH = 256
|
| 23 |
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
|
| 24 |
+
/* istanbul ignore next */ 9007199254740991
|
| 25 |
+
|
| 26 |
+
// Max safe segment length for coercion.
|
| 27 |
+
var MAX_SAFE_COMPONENT_LENGTH = 16
|
| 28 |
+
|
| 29 |
+
var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6
|
| 30 |
+
|
| 31 |
+
// The actual regexps go on exports.re
|
| 32 |
+
var re = exports.re = []
|
| 33 |
+
var safeRe = exports.safeRe = []
|
| 34 |
+
var src = exports.src = []
|
| 35 |
+
var t = exports.tokens = {}
|
| 36 |
+
var R = 0
|
| 37 |
+
|
| 38 |
+
function tok (n) {
|
| 39 |
+
t[n] = R++
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
var LETTERDASHNUMBER = '[a-zA-Z0-9-]'
|
| 43 |
+
|
| 44 |
+
// Replace some greedy regex tokens to prevent regex dos issues. These regex are
|
| 45 |
+
// used internally via the safeRe object since all inputs in this library get
|
| 46 |
+
// normalized first to trim and collapse all extra whitespace. The original
|
| 47 |
+
// regexes are exported for userland consumption and lower level usage. A
|
| 48 |
+
// future breaking change could export the safer regex only with a note that
|
| 49 |
+
// all input should have extra whitespace removed.
|
| 50 |
+
var safeRegexReplacements = [
|
| 51 |
+
['\\s', 1],
|
| 52 |
+
['\\d', MAX_LENGTH],
|
| 53 |
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
function makeSafeRe (value) {
|
| 57 |
+
for (var i = 0; i < safeRegexReplacements.length; i++) {
|
| 58 |
+
var token = safeRegexReplacements[i][0]
|
| 59 |
+
var max = safeRegexReplacements[i][1]
|
| 60 |
+
value = value
|
| 61 |
+
.split(token + '*').join(token + '{0,' + max + '}')
|
| 62 |
+
.split(token + '+').join(token + '{1,' + max + '}')
|
| 63 |
+
}
|
| 64 |
+
return value
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// The following Regular Expressions can be used for tokenizing,
|
| 68 |
+
// validating, and parsing SemVer version strings.
|
| 69 |
+
|
| 70 |
+
// ## Numeric Identifier
|
| 71 |
+
// A single `0`, or a non-zero digit followed by zero or more digits.
|
| 72 |
+
|
| 73 |
+
tok('NUMERICIDENTIFIER')
|
| 74 |
+
src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*'
|
| 75 |
+
tok('NUMERICIDENTIFIERLOOSE')
|
| 76 |
+
src[t.NUMERICIDENTIFIERLOOSE] = '\\d+'
|
| 77 |
+
|
| 78 |
+
// ## Non-numeric Identifier
|
| 79 |
+
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
| 80 |
+
// more letters, digits, or hyphens.
|
| 81 |
+
|
| 82 |
+
tok('NONNUMERICIDENTIFIER')
|
| 83 |
+
src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-]' + LETTERDASHNUMBER + '*'
|
| 84 |
+
|
| 85 |
+
// ## Main Version
|
| 86 |
+
// Three dot-separated numeric identifiers.
|
| 87 |
+
|
| 88 |
+
tok('MAINVERSION')
|
| 89 |
+
src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
|
| 90 |
+
'(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
|
| 91 |
+
'(' + src[t.NUMERICIDENTIFIER] + ')'
|
| 92 |
+
|
| 93 |
+
tok('MAINVERSIONLOOSE')
|
| 94 |
+
src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
| 95 |
+
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
| 96 |
+
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'
|
| 97 |
+
|
| 98 |
+
// ## Pre-release Version Identifier
|
| 99 |
+
// A numeric identifier, or a non-numeric identifier.
|
| 100 |
+
|
| 101 |
+
tok('PRERELEASEIDENTIFIER')
|
| 102 |
+
src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] +
|
| 103 |
+
'|' + src[t.NONNUMERICIDENTIFIER] + ')'
|
| 104 |
+
|
| 105 |
+
tok('PRERELEASEIDENTIFIERLOOSE')
|
| 106 |
+
src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] +
|
| 107 |
+
'|' + src[t.NONNUMERICIDENTIFIER] + ')'
|
| 108 |
+
|
| 109 |
+
// ## Pre-release Version
|
| 110 |
+
// Hyphen, followed by one or more dot-separated pre-release version
|
| 111 |
+
// identifiers.
|
| 112 |
+
|
| 113 |
+
tok('PRERELEASE')
|
| 114 |
+
src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] +
|
| 115 |
+
'(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))'
|
| 116 |
+
|
| 117 |
+
tok('PRERELEASELOOSE')
|
| 118 |
+
src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] +
|
| 119 |
+
'(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'
|
| 120 |
+
|
| 121 |
+
// ## Build Metadata Identifier
|
| 122 |
+
// Any combination of digits, letters, or hyphens.
|
| 123 |
+
|
| 124 |
+
tok('BUILDIDENTIFIER')
|
| 125 |
+
src[t.BUILDIDENTIFIER] = LETTERDASHNUMBER + '+'
|
| 126 |
+
|
| 127 |
+
// ## Build Metadata
|
| 128 |
+
// Plus sign, followed by one or more period-separated build metadata
|
| 129 |
+
// identifiers.
|
| 130 |
+
|
| 131 |
+
tok('BUILD')
|
| 132 |
+
src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] +
|
| 133 |
+
'(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'
|
| 134 |
+
|
| 135 |
+
// ## Full Version String
|
| 136 |
+
// A main version, followed optionally by a pre-release version and
|
| 137 |
+
// build metadata.
|
| 138 |
+
|
| 139 |
+
// Note that the only major, minor, patch, and pre-release sections of
|
| 140 |
+
// the version string are capturing groups. The build metadata is not a
|
| 141 |
+
// capturing group, because it should not ever be used in version
|
| 142 |
+
// comparison.
|
| 143 |
+
|
| 144 |
+
tok('FULL')
|
| 145 |
+
tok('FULLPLAIN')
|
| 146 |
+
src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] +
|
| 147 |
+
src[t.PRERELEASE] + '?' +
|
| 148 |
+
src[t.BUILD] + '?'
|
| 149 |
+
|
| 150 |
+
src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'
|
| 151 |
+
|
| 152 |
+
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
| 153 |
+
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
| 154 |
+
// common in the npm registry.
|
| 155 |
+
tok('LOOSEPLAIN')
|
| 156 |
+
src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] +
|
| 157 |
+
src[t.PRERELEASELOOSE] + '?' +
|
| 158 |
+
src[t.BUILD] + '?'
|
| 159 |
+
|
| 160 |
+
tok('LOOSE')
|
| 161 |
+
src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$'
|
| 162 |
+
|
| 163 |
+
tok('GTLT')
|
| 164 |
+
src[t.GTLT] = '((?:<|>)?=?)'
|
| 165 |
+
|
| 166 |
+
// Something like "2.*" or "1.2.x".
|
| 167 |
+
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
| 168 |
+
// Only the first item is strictly required.
|
| 169 |
+
tok('XRANGEIDENTIFIERLOOSE')
|
| 170 |
+
src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
|
| 171 |
+
tok('XRANGEIDENTIFIER')
|
| 172 |
+
src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*'
|
| 173 |
+
|
| 174 |
+
tok('XRANGEPLAIN')
|
| 175 |
+
src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' +
|
| 176 |
+
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
|
| 177 |
+
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
|
| 178 |
+
'(?:' + src[t.PRERELEASE] + ')?' +
|
| 179 |
+
src[t.BUILD] + '?' +
|
| 180 |
+
')?)?'
|
| 181 |
+
|
| 182 |
+
tok('XRANGEPLAINLOOSE')
|
| 183 |
+
src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
| 184 |
+
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
| 185 |
+
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
| 186 |
+
'(?:' + src[t.PRERELEASELOOSE] + ')?' +
|
| 187 |
+
src[t.BUILD] + '?' +
|
| 188 |
+
')?)?'
|
| 189 |
+
|
| 190 |
+
tok('XRANGE')
|
| 191 |
+
src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$'
|
| 192 |
+
tok('XRANGELOOSE')
|
| 193 |
+
src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'
|
| 194 |
+
|
| 195 |
+
// Coercion.
|
| 196 |
+
// Extract anything that could conceivably be a part of a valid semver
|
| 197 |
+
tok('COERCE')
|
| 198 |
+
src[t.COERCE] = '(^|[^\\d])' +
|
| 199 |
+
'(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
|
| 200 |
+
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
| 201 |
+
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
| 202 |
+
'(?:$|[^\\d])'
|
| 203 |
+
tok('COERCERTL')
|
| 204 |
+
re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g')
|
| 205 |
+
safeRe[t.COERCERTL] = new RegExp(makeSafeRe(src[t.COERCE]), 'g')
|
| 206 |
+
|
| 207 |
+
// Tilde ranges.
|
| 208 |
+
// Meaning is "reasonably at or greater than"
|
| 209 |
+
tok('LONETILDE')
|
| 210 |
+
src[t.LONETILDE] = '(?:~>?)'
|
| 211 |
+
|
| 212 |
+
tok('TILDETRIM')
|
| 213 |
+
src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+'
|
| 214 |
+
re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g')
|
| 215 |
+
safeRe[t.TILDETRIM] = new RegExp(makeSafeRe(src[t.TILDETRIM]), 'g')
|
| 216 |
+
var tildeTrimReplace = '$1~'
|
| 217 |
+
|
| 218 |
+
tok('TILDE')
|
| 219 |
+
src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$'
|
| 220 |
+
tok('TILDELOOSE')
|
| 221 |
+
src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'
|
| 222 |
+
|
| 223 |
+
// Caret ranges.
|
| 224 |
+
// Meaning is "at least and backwards compatible with"
|
| 225 |
+
tok('LONECARET')
|
| 226 |
+
src[t.LONECARET] = '(?:\\^)'
|
| 227 |
+
|
| 228 |
+
tok('CARETTRIM')
|
| 229 |
+
src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+'
|
| 230 |
+
re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g')
|
| 231 |
+
safeRe[t.CARETTRIM] = new RegExp(makeSafeRe(src[t.CARETTRIM]), 'g')
|
| 232 |
+
var caretTrimReplace = '$1^'
|
| 233 |
+
|
| 234 |
+
tok('CARET')
|
| 235 |
+
src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$'
|
| 236 |
+
tok('CARETLOOSE')
|
| 237 |
+
src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'
|
| 238 |
+
|
| 239 |
+
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
| 240 |
+
tok('COMPARATORLOOSE')
|
| 241 |
+
src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$'
|
| 242 |
+
tok('COMPARATOR')
|
| 243 |
+
src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'
|
| 244 |
+
|
| 245 |
+
// An expression to strip any whitespace between the gtlt and the thing
|
| 246 |
+
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
| 247 |
+
tok('COMPARATORTRIM')
|
| 248 |
+
src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] +
|
| 249 |
+
'\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'
|
| 250 |
+
|
| 251 |
+
// this one has to use the /g flag
|
| 252 |
+
re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g')
|
| 253 |
+
safeRe[t.COMPARATORTRIM] = new RegExp(makeSafeRe(src[t.COMPARATORTRIM]), 'g')
|
| 254 |
+
var comparatorTrimReplace = '$1$2$3'
|
| 255 |
+
|
| 256 |
+
// Something like `1.2.3 - 1.2.4`
|
| 257 |
+
// Note that these all use the loose form, because they'll be
|
| 258 |
+
// checked against either the strict or loose comparator form
|
| 259 |
+
// later.
|
| 260 |
+
tok('HYPHENRANGE')
|
| 261 |
+
src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' +
|
| 262 |
+
'\\s+-\\s+' +
|
| 263 |
+
'(' + src[t.XRANGEPLAIN] + ')' +
|
| 264 |
+
'\\s*$'
|
| 265 |
+
|
| 266 |
+
tok('HYPHENRANGELOOSE')
|
| 267 |
+
src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' +
|
| 268 |
+
'\\s+-\\s+' +
|
| 269 |
+
'(' + src[t.XRANGEPLAINLOOSE] + ')' +
|
| 270 |
+
'\\s*$'
|
| 271 |
+
|
| 272 |
+
// Star ranges basically just allow anything at all.
|
| 273 |
+
tok('STAR')
|
| 274 |
+
src[t.STAR] = '(<|>)?=?\\s*\\*'
|
| 275 |
+
|
| 276 |
+
// Compile to actual regexp objects.
|
| 277 |
+
// All are flag-free, unless they were created above with a flag.
|
| 278 |
+
for (var i = 0; i < R; i++) {
|
| 279 |
+
debug(i, src[i])
|
| 280 |
+
if (!re[i]) {
|
| 281 |
+
re[i] = new RegExp(src[i])
|
| 282 |
+
|
| 283 |
+
// Replace all greedy whitespace to prevent regex dos issues. These regex are
|
| 284 |
+
// used internally via the safeRe object since all inputs in this library get
|
| 285 |
+
// normalized first to trim and collapse all extra whitespace. The original
|
| 286 |
+
// regexes are exported for userland consumption and lower level usage. A
|
| 287 |
+
// future breaking change could export the safer regex only with a note that
|
| 288 |
+
// all input should have extra whitespace removed.
|
| 289 |
+
safeRe[i] = new RegExp(makeSafeRe(src[i]))
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
exports.parse = parse
|
| 294 |
+
function parse (version, options) {
|
| 295 |
+
if (!options || typeof options !== 'object') {
|
| 296 |
+
options = {
|
| 297 |
+
loose: !!options,
|
| 298 |
+
includePrerelease: false
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
if (version instanceof SemVer) {
|
| 303 |
+
return version
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
if (typeof version !== 'string') {
|
| 307 |
+
return null
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
if (version.length > MAX_LENGTH) {
|
| 311 |
+
return null
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
var r = options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL]
|
| 315 |
+
if (!r.test(version)) {
|
| 316 |
+
return null
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
try {
|
| 320 |
+
return new SemVer(version, options)
|
| 321 |
+
} catch (er) {
|
| 322 |
+
return null
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
exports.valid = valid
|
| 327 |
+
function valid (version, options) {
|
| 328 |
+
var v = parse(version, options)
|
| 329 |
+
return v ? v.version : null
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
exports.clean = clean
|
| 333 |
+
function clean (version, options) {
|
| 334 |
+
var s = parse(version.trim().replace(/^[=v]+/, ''), options)
|
| 335 |
+
return s ? s.version : null
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
exports.SemVer = SemVer
|
| 339 |
+
|
| 340 |
+
function SemVer (version, options) {
|
| 341 |
+
if (!options || typeof options !== 'object') {
|
| 342 |
+
options = {
|
| 343 |
+
loose: !!options,
|
| 344 |
+
includePrerelease: false
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
if (version instanceof SemVer) {
|
| 348 |
+
if (version.loose === options.loose) {
|
| 349 |
+
return version
|
| 350 |
+
} else {
|
| 351 |
+
version = version.version
|
| 352 |
+
}
|
| 353 |
+
} else if (typeof version !== 'string') {
|
| 354 |
+
throw new TypeError('Invalid Version: ' + version)
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
if (version.length > MAX_LENGTH) {
|
| 358 |
+
throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
if (!(this instanceof SemVer)) {
|
| 362 |
+
return new SemVer(version, options)
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
debug('SemVer', version, options)
|
| 366 |
+
this.options = options
|
| 367 |
+
this.loose = !!options.loose
|
| 368 |
+
|
| 369 |
+
var m = version.trim().match(options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL])
|
| 370 |
+
|
| 371 |
+
if (!m) {
|
| 372 |
+
throw new TypeError('Invalid Version: ' + version)
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
this.raw = version
|
| 376 |
+
|
| 377 |
+
// these are actually numbers
|
| 378 |
+
this.major = +m[1]
|
| 379 |
+
this.minor = +m[2]
|
| 380 |
+
this.patch = +m[3]
|
| 381 |
+
|
| 382 |
+
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
| 383 |
+
throw new TypeError('Invalid major version')
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
| 387 |
+
throw new TypeError('Invalid minor version')
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
| 391 |
+
throw new TypeError('Invalid patch version')
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
// numberify any prerelease numeric ids
|
| 395 |
+
if (!m[4]) {
|
| 396 |
+
this.prerelease = []
|
| 397 |
+
} else {
|
| 398 |
+
this.prerelease = m[4].split('.').map(function (id) {
|
| 399 |
+
if (/^[0-9]+$/.test(id)) {
|
| 400 |
+
var num = +id
|
| 401 |
+
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
| 402 |
+
return num
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
return id
|
| 406 |
+
})
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
this.build = m[5] ? m[5].split('.') : []
|
| 410 |
+
this.format()
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
SemVer.prototype.format = function () {
|
| 414 |
+
this.version = this.major + '.' + this.minor + '.' + this.patch
|
| 415 |
+
if (this.prerelease.length) {
|
| 416 |
+
this.version += '-' + this.prerelease.join('.')
|
| 417 |
+
}
|
| 418 |
+
return this.version
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
SemVer.prototype.toString = function () {
|
| 422 |
+
return this.version
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
SemVer.prototype.compare = function (other) {
|
| 426 |
+
debug('SemVer.compare', this.version, this.options, other)
|
| 427 |
+
if (!(other instanceof SemVer)) {
|
| 428 |
+
other = new SemVer(other, this.options)
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
return this.compareMain(other) || this.comparePre(other)
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
SemVer.prototype.compareMain = function (other) {
|
| 435 |
+
if (!(other instanceof SemVer)) {
|
| 436 |
+
other = new SemVer(other, this.options)
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
return compareIdentifiers(this.major, other.major) ||
|
| 440 |
+
compareIdentifiers(this.minor, other.minor) ||
|
| 441 |
+
compareIdentifiers(this.patch, other.patch)
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
SemVer.prototype.comparePre = function (other) {
|
| 445 |
+
if (!(other instanceof SemVer)) {
|
| 446 |
+
other = new SemVer(other, this.options)
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
// NOT having a prerelease is > having one
|
| 450 |
+
if (this.prerelease.length && !other.prerelease.length) {
|
| 451 |
+
return -1
|
| 452 |
+
} else if (!this.prerelease.length && other.prerelease.length) {
|
| 453 |
+
return 1
|
| 454 |
+
} else if (!this.prerelease.length && !other.prerelease.length) {
|
| 455 |
+
return 0
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
var i = 0
|
| 459 |
+
do {
|
| 460 |
+
var a = this.prerelease[i]
|
| 461 |
+
var b = other.prerelease[i]
|
| 462 |
+
debug('prerelease compare', i, a, b)
|
| 463 |
+
if (a === undefined && b === undefined) {
|
| 464 |
+
return 0
|
| 465 |
+
} else if (b === undefined) {
|
| 466 |
+
return 1
|
| 467 |
+
} else if (a === undefined) {
|
| 468 |
+
return -1
|
| 469 |
+
} else if (a === b) {
|
| 470 |
+
continue
|
| 471 |
+
} else {
|
| 472 |
+
return compareIdentifiers(a, b)
|
| 473 |
+
}
|
| 474 |
+
} while (++i)
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
SemVer.prototype.compareBuild = function (other) {
|
| 478 |
+
if (!(other instanceof SemVer)) {
|
| 479 |
+
other = new SemVer(other, this.options)
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
var i = 0
|
| 483 |
+
do {
|
| 484 |
+
var a = this.build[i]
|
| 485 |
+
var b = other.build[i]
|
| 486 |
+
debug('prerelease compare', i, a, b)
|
| 487 |
+
if (a === undefined && b === undefined) {
|
| 488 |
+
return 0
|
| 489 |
+
} else if (b === undefined) {
|
| 490 |
+
return 1
|
| 491 |
+
} else if (a === undefined) {
|
| 492 |
+
return -1
|
| 493 |
+
} else if (a === b) {
|
| 494 |
+
continue
|
| 495 |
+
} else {
|
| 496 |
+
return compareIdentifiers(a, b)
|
| 497 |
+
}
|
| 498 |
+
} while (++i)
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
// preminor will bump the version up to the next minor release, and immediately
|
| 502 |
+
// down to pre-release. premajor and prepatch work the same way.
|
| 503 |
+
SemVer.prototype.inc = function (release, identifier) {
|
| 504 |
+
switch (release) {
|
| 505 |
+
case 'premajor':
|
| 506 |
+
this.prerelease.length = 0
|
| 507 |
+
this.patch = 0
|
| 508 |
+
this.minor = 0
|
| 509 |
+
this.major++
|
| 510 |
+
this.inc('pre', identifier)
|
| 511 |
+
break
|
| 512 |
+
case 'preminor':
|
| 513 |
+
this.prerelease.length = 0
|
| 514 |
+
this.patch = 0
|
| 515 |
+
this.minor++
|
| 516 |
+
this.inc('pre', identifier)
|
| 517 |
+
break
|
| 518 |
+
case 'prepatch':
|
| 519 |
+
// If this is already a prerelease, it will bump to the next version
|
| 520 |
+
// drop any prereleases that might already exist, since they are not
|
| 521 |
+
// relevant at this point.
|
| 522 |
+
this.prerelease.length = 0
|
| 523 |
+
this.inc('patch', identifier)
|
| 524 |
+
this.inc('pre', identifier)
|
| 525 |
+
break
|
| 526 |
+
// If the input is a non-prerelease version, this acts the same as
|
| 527 |
+
// prepatch.
|
| 528 |
+
case 'prerelease':
|
| 529 |
+
if (this.prerelease.length === 0) {
|
| 530 |
+
this.inc('patch', identifier)
|
| 531 |
+
}
|
| 532 |
+
this.inc('pre', identifier)
|
| 533 |
+
break
|
| 534 |
+
|
| 535 |
+
case 'major':
|
| 536 |
+
// If this is a pre-major version, bump up to the same major version.
|
| 537 |
+
// Otherwise increment major.
|
| 538 |
+
// 1.0.0-5 bumps to 1.0.0
|
| 539 |
+
// 1.1.0 bumps to 2.0.0
|
| 540 |
+
if (this.minor !== 0 ||
|
| 541 |
+
this.patch !== 0 ||
|
| 542 |
+
this.prerelease.length === 0) {
|
| 543 |
+
this.major++
|
| 544 |
+
}
|
| 545 |
+
this.minor = 0
|
| 546 |
+
this.patch = 0
|
| 547 |
+
this.prerelease = []
|
| 548 |
+
break
|
| 549 |
+
case 'minor':
|
| 550 |
+
// If this is a pre-minor version, bump up to the same minor version.
|
| 551 |
+
// Otherwise increment minor.
|
| 552 |
+
// 1.2.0-5 bumps to 1.2.0
|
| 553 |
+
// 1.2.1 bumps to 1.3.0
|
| 554 |
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
| 555 |
+
this.minor++
|
| 556 |
+
}
|
| 557 |
+
this.patch = 0
|
| 558 |
+
this.prerelease = []
|
| 559 |
+
break
|
| 560 |
+
case 'patch':
|
| 561 |
+
// If this is not a pre-release version, it will increment the patch.
|
| 562 |
+
// If it is a pre-release it will bump up to the same patch version.
|
| 563 |
+
// 1.2.0-5 patches to 1.2.0
|
| 564 |
+
// 1.2.0 patches to 1.2.1
|
| 565 |
+
if (this.prerelease.length === 0) {
|
| 566 |
+
this.patch++
|
| 567 |
+
}
|
| 568 |
+
this.prerelease = []
|
| 569 |
+
break
|
| 570 |
+
// This probably shouldn't be used publicly.
|
| 571 |
+
// 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
|
| 572 |
+
case 'pre':
|
| 573 |
+
if (this.prerelease.length === 0) {
|
| 574 |
+
this.prerelease = [0]
|
| 575 |
+
} else {
|
| 576 |
+
var i = this.prerelease.length
|
| 577 |
+
while (--i >= 0) {
|
| 578 |
+
if (typeof this.prerelease[i] === 'number') {
|
| 579 |
+
this.prerelease[i]++
|
| 580 |
+
i = -2
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
if (i === -1) {
|
| 584 |
+
// didn't increment anything
|
| 585 |
+
this.prerelease.push(0)
|
| 586 |
+
}
|
| 587 |
+
}
|
| 588 |
+
if (identifier) {
|
| 589 |
+
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
| 590 |
+
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
| 591 |
+
if (this.prerelease[0] === identifier) {
|
| 592 |
+
if (isNaN(this.prerelease[1])) {
|
| 593 |
+
this.prerelease = [identifier, 0]
|
| 594 |
+
}
|
| 595 |
+
} else {
|
| 596 |
+
this.prerelease = [identifier, 0]
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
break
|
| 600 |
+
|
| 601 |
+
default:
|
| 602 |
+
throw new Error('invalid increment argument: ' + release)
|
| 603 |
+
}
|
| 604 |
+
this.format()
|
| 605 |
+
this.raw = this.version
|
| 606 |
+
return this
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
exports.inc = inc
|
| 610 |
+
function inc (version, release, loose, identifier) {
|
| 611 |
+
if (typeof (loose) === 'string') {
|
| 612 |
+
identifier = loose
|
| 613 |
+
loose = undefined
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
try {
|
| 617 |
+
return new SemVer(version, loose).inc(release, identifier).version
|
| 618 |
+
} catch (er) {
|
| 619 |
+
return null
|
| 620 |
+
}
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
exports.diff = diff
|
| 624 |
+
function diff (version1, version2) {
|
| 625 |
+
if (eq(version1, version2)) {
|
| 626 |
+
return null
|
| 627 |
+
} else {
|
| 628 |
+
var v1 = parse(version1)
|
| 629 |
+
var v2 = parse(version2)
|
| 630 |
+
var prefix = ''
|
| 631 |
+
if (v1.prerelease.length || v2.prerelease.length) {
|
| 632 |
+
prefix = 'pre'
|
| 633 |
+
var defaultResult = 'prerelease'
|
| 634 |
+
}
|
| 635 |
+
for (var key in v1) {
|
| 636 |
+
if (key === 'major' || key === 'minor' || key === 'patch') {
|
| 637 |
+
if (v1[key] !== v2[key]) {
|
| 638 |
+
return prefix + key
|
| 639 |
+
}
|
| 640 |
+
}
|
| 641 |
+
}
|
| 642 |
+
return defaultResult // may be undefined
|
| 643 |
+
}
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
exports.compareIdentifiers = compareIdentifiers
|
| 647 |
+
|
| 648 |
+
var numeric = /^[0-9]+$/
|
| 649 |
+
function compareIdentifiers (a, b) {
|
| 650 |
+
var anum = numeric.test(a)
|
| 651 |
+
var bnum = numeric.test(b)
|
| 652 |
+
|
| 653 |
+
if (anum && bnum) {
|
| 654 |
+
a = +a
|
| 655 |
+
b = +b
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
return a === b ? 0
|
| 659 |
+
: (anum && !bnum) ? -1
|
| 660 |
+
: (bnum && !anum) ? 1
|
| 661 |
+
: a < b ? -1
|
| 662 |
+
: 1
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
exports.rcompareIdentifiers = rcompareIdentifiers
|
| 666 |
+
function rcompareIdentifiers (a, b) {
|
| 667 |
+
return compareIdentifiers(b, a)
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
exports.major = major
|
| 671 |
+
function major (a, loose) {
|
| 672 |
+
return new SemVer(a, loose).major
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
exports.minor = minor
|
| 676 |
+
function minor (a, loose) {
|
| 677 |
+
return new SemVer(a, loose).minor
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
exports.patch = patch
|
| 681 |
+
function patch (a, loose) {
|
| 682 |
+
return new SemVer(a, loose).patch
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
exports.compare = compare
|
| 686 |
+
function compare (a, b, loose) {
|
| 687 |
+
return new SemVer(a, loose).compare(new SemVer(b, loose))
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
exports.compareLoose = compareLoose
|
| 691 |
+
function compareLoose (a, b) {
|
| 692 |
+
return compare(a, b, true)
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
exports.compareBuild = compareBuild
|
| 696 |
+
function compareBuild (a, b, loose) {
|
| 697 |
+
var versionA = new SemVer(a, loose)
|
| 698 |
+
var versionB = new SemVer(b, loose)
|
| 699 |
+
return versionA.compare(versionB) || versionA.compareBuild(versionB)
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
exports.rcompare = rcompare
|
| 703 |
+
function rcompare (a, b, loose) {
|
| 704 |
+
return compare(b, a, loose)
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
exports.sort = sort
|
| 708 |
+
function sort (list, loose) {
|
| 709 |
+
return list.sort(function (a, b) {
|
| 710 |
+
return exports.compareBuild(a, b, loose)
|
| 711 |
+
})
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
exports.rsort = rsort
|
| 715 |
+
function rsort (list, loose) {
|
| 716 |
+
return list.sort(function (a, b) {
|
| 717 |
+
return exports.compareBuild(b, a, loose)
|
| 718 |
+
})
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
exports.gt = gt
|
| 722 |
+
function gt (a, b, loose) {
|
| 723 |
+
return compare(a, b, loose) > 0
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
exports.lt = lt
|
| 727 |
+
function lt (a, b, loose) {
|
| 728 |
+
return compare(a, b, loose) < 0
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
exports.eq = eq
|
| 732 |
+
function eq (a, b, loose) {
|
| 733 |
+
return compare(a, b, loose) === 0
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
exports.neq = neq
|
| 737 |
+
function neq (a, b, loose) {
|
| 738 |
+
return compare(a, b, loose) !== 0
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
exports.gte = gte
|
| 742 |
+
function gte (a, b, loose) {
|
| 743 |
+
return compare(a, b, loose) >= 0
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
exports.lte = lte
|
| 747 |
+
function lte (a, b, loose) {
|
| 748 |
+
return compare(a, b, loose) <= 0
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
exports.cmp = cmp
|
| 752 |
+
function cmp (a, op, b, loose) {
|
| 753 |
+
switch (op) {
|
| 754 |
+
case '===':
|
| 755 |
+
if (typeof a === 'object')
|
| 756 |
+
a = a.version
|
| 757 |
+
if (typeof b === 'object')
|
| 758 |
+
b = b.version
|
| 759 |
+
return a === b
|
| 760 |
+
|
| 761 |
+
case '!==':
|
| 762 |
+
if (typeof a === 'object')
|
| 763 |
+
a = a.version
|
| 764 |
+
if (typeof b === 'object')
|
| 765 |
+
b = b.version
|
| 766 |
+
return a !== b
|
| 767 |
+
|
| 768 |
+
case '':
|
| 769 |
+
case '=':
|
| 770 |
+
case '==':
|
| 771 |
+
return eq(a, b, loose)
|
| 772 |
+
|
| 773 |
+
case '!=':
|
| 774 |
+
return neq(a, b, loose)
|
| 775 |
+
|
| 776 |
+
case '>':
|
| 777 |
+
return gt(a, b, loose)
|
| 778 |
+
|
| 779 |
+
case '>=':
|
| 780 |
+
return gte(a, b, loose)
|
| 781 |
+
|
| 782 |
+
case '<':
|
| 783 |
+
return lt(a, b, loose)
|
| 784 |
+
|
| 785 |
+
case '<=':
|
| 786 |
+
return lte(a, b, loose)
|
| 787 |
+
|
| 788 |
+
default:
|
| 789 |
+
throw new TypeError('Invalid operator: ' + op)
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
exports.Comparator = Comparator
|
| 794 |
+
function Comparator (comp, options) {
|
| 795 |
+
if (!options || typeof options !== 'object') {
|
| 796 |
+
options = {
|
| 797 |
+
loose: !!options,
|
| 798 |
+
includePrerelease: false
|
| 799 |
+
}
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
if (comp instanceof Comparator) {
|
| 803 |
+
if (comp.loose === !!options.loose) {
|
| 804 |
+
return comp
|
| 805 |
+
} else {
|
| 806 |
+
comp = comp.value
|
| 807 |
+
}
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
if (!(this instanceof Comparator)) {
|
| 811 |
+
return new Comparator(comp, options)
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
comp = comp.trim().split(/\s+/).join(' ')
|
| 815 |
+
debug('comparator', comp, options)
|
| 816 |
+
this.options = options
|
| 817 |
+
this.loose = !!options.loose
|
| 818 |
+
this.parse(comp)
|
| 819 |
+
|
| 820 |
+
if (this.semver === ANY) {
|
| 821 |
+
this.value = ''
|
| 822 |
+
} else {
|
| 823 |
+
this.value = this.operator + this.semver.version
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
debug('comp', this)
|
| 827 |
+
}
|
| 828 |
+
|
| 829 |
+
var ANY = {}
|
| 830 |
+
Comparator.prototype.parse = function (comp) {
|
| 831 |
+
var r = this.options.loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR]
|
| 832 |
+
var m = comp.match(r)
|
| 833 |
+
|
| 834 |
+
if (!m) {
|
| 835 |
+
throw new TypeError('Invalid comparator: ' + comp)
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
this.operator = m[1] !== undefined ? m[1] : ''
|
| 839 |
+
if (this.operator === '=') {
|
| 840 |
+
this.operator = ''
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
// if it literally is just '>' or '' then allow anything.
|
| 844 |
+
if (!m[2]) {
|
| 845 |
+
this.semver = ANY
|
| 846 |
+
} else {
|
| 847 |
+
this.semver = new SemVer(m[2], this.options.loose)
|
| 848 |
+
}
|
| 849 |
+
}
|
| 850 |
+
|
| 851 |
+
Comparator.prototype.toString = function () {
|
| 852 |
+
return this.value
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
Comparator.prototype.test = function (version) {
|
| 856 |
+
debug('Comparator.test', version, this.options.loose)
|
| 857 |
+
|
| 858 |
+
if (this.semver === ANY || version === ANY) {
|
| 859 |
+
return true
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
if (typeof version === 'string') {
|
| 863 |
+
try {
|
| 864 |
+
version = new SemVer(version, this.options)
|
| 865 |
+
} catch (er) {
|
| 866 |
+
return false
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
return cmp(version, this.operator, this.semver, this.options)
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
Comparator.prototype.intersects = function (comp, options) {
|
| 874 |
+
if (!(comp instanceof Comparator)) {
|
| 875 |
+
throw new TypeError('a Comparator is required')
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
if (!options || typeof options !== 'object') {
|
| 879 |
+
options = {
|
| 880 |
+
loose: !!options,
|
| 881 |
+
includePrerelease: false
|
| 882 |
+
}
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
var rangeTmp
|
| 886 |
+
|
| 887 |
+
if (this.operator === '') {
|
| 888 |
+
if (this.value === '') {
|
| 889 |
+
return true
|
| 890 |
+
}
|
| 891 |
+
rangeTmp = new Range(comp.value, options)
|
| 892 |
+
return satisfies(this.value, rangeTmp, options)
|
| 893 |
+
} else if (comp.operator === '') {
|
| 894 |
+
if (comp.value === '') {
|
| 895 |
+
return true
|
| 896 |
+
}
|
| 897 |
+
rangeTmp = new Range(this.value, options)
|
| 898 |
+
return satisfies(comp.semver, rangeTmp, options)
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
var sameDirectionIncreasing =
|
| 902 |
+
(this.operator === '>=' || this.operator === '>') &&
|
| 903 |
+
(comp.operator === '>=' || comp.operator === '>')
|
| 904 |
+
var sameDirectionDecreasing =
|
| 905 |
+
(this.operator === '<=' || this.operator === '<') &&
|
| 906 |
+
(comp.operator === '<=' || comp.operator === '<')
|
| 907 |
+
var sameSemVer = this.semver.version === comp.semver.version
|
| 908 |
+
var differentDirectionsInclusive =
|
| 909 |
+
(this.operator === '>=' || this.operator === '<=') &&
|
| 910 |
+
(comp.operator === '>=' || comp.operator === '<=')
|
| 911 |
+
var oppositeDirectionsLessThan =
|
| 912 |
+
cmp(this.semver, '<', comp.semver, options) &&
|
| 913 |
+
((this.operator === '>=' || this.operator === '>') &&
|
| 914 |
+
(comp.operator === '<=' || comp.operator === '<'))
|
| 915 |
+
var oppositeDirectionsGreaterThan =
|
| 916 |
+
cmp(this.semver, '>', comp.semver, options) &&
|
| 917 |
+
((this.operator === '<=' || this.operator === '<') &&
|
| 918 |
+
(comp.operator === '>=' || comp.operator === '>'))
|
| 919 |
+
|
| 920 |
+
return sameDirectionIncreasing || sameDirectionDecreasing ||
|
| 921 |
+
(sameSemVer && differentDirectionsInclusive) ||
|
| 922 |
+
oppositeDirectionsLessThan || oppositeDirectionsGreaterThan
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
exports.Range = Range
|
| 926 |
+
function Range (range, options) {
|
| 927 |
+
if (!options || typeof options !== 'object') {
|
| 928 |
+
options = {
|
| 929 |
+
loose: !!options,
|
| 930 |
+
includePrerelease: false
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
if (range instanceof Range) {
|
| 935 |
+
if (range.loose === !!options.loose &&
|
| 936 |
+
range.includePrerelease === !!options.includePrerelease) {
|
| 937 |
+
return range
|
| 938 |
+
} else {
|
| 939 |
+
return new Range(range.raw, options)
|
| 940 |
+
}
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
if (range instanceof Comparator) {
|
| 944 |
+
return new Range(range.value, options)
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
if (!(this instanceof Range)) {
|
| 948 |
+
return new Range(range, options)
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
this.options = options
|
| 952 |
+
this.loose = !!options.loose
|
| 953 |
+
this.includePrerelease = !!options.includePrerelease
|
| 954 |
+
|
| 955 |
+
// First reduce all whitespace as much as possible so we do not have to rely
|
| 956 |
+
// on potentially slow regexes like \s*. This is then stored and used for
|
| 957 |
+
// future error messages as well.
|
| 958 |
+
this.raw = range
|
| 959 |
+
.trim()
|
| 960 |
+
.split(/\s+/)
|
| 961 |
+
.join(' ')
|
| 962 |
+
|
| 963 |
+
// First, split based on boolean or ||
|
| 964 |
+
this.set = this.raw.split('||').map(function (range) {
|
| 965 |
+
return this.parseRange(range.trim())
|
| 966 |
+
}, this).filter(function (c) {
|
| 967 |
+
// throw out any that are not relevant for whatever reason
|
| 968 |
+
return c.length
|
| 969 |
+
})
|
| 970 |
+
|
| 971 |
+
if (!this.set.length) {
|
| 972 |
+
throw new TypeError('Invalid SemVer Range: ' + this.raw)
|
| 973 |
+
}
|
| 974 |
+
|
| 975 |
+
this.format()
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
Range.prototype.format = function () {
|
| 979 |
+
this.range = this.set.map(function (comps) {
|
| 980 |
+
return comps.join(' ').trim()
|
| 981 |
+
}).join('||').trim()
|
| 982 |
+
return this.range
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
Range.prototype.toString = function () {
|
| 986 |
+
return this.range
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
Range.prototype.parseRange = function (range) {
|
| 990 |
+
var loose = this.options.loose
|
| 991 |
+
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
| 992 |
+
var hr = loose ? safeRe[t.HYPHENRANGELOOSE] : safeRe[t.HYPHENRANGE]
|
| 993 |
+
range = range.replace(hr, hyphenReplace)
|
| 994 |
+
debug('hyphen replace', range)
|
| 995 |
+
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
| 996 |
+
range = range.replace(safeRe[t.COMPARATORTRIM], comparatorTrimReplace)
|
| 997 |
+
debug('comparator trim', range, safeRe[t.COMPARATORTRIM])
|
| 998 |
+
|
| 999 |
+
// `~ 1.2.3` => `~1.2.3`
|
| 1000 |
+
range = range.replace(safeRe[t.TILDETRIM], tildeTrimReplace)
|
| 1001 |
+
|
| 1002 |
+
// `^ 1.2.3` => `^1.2.3`
|
| 1003 |
+
range = range.replace(safeRe[t.CARETTRIM], caretTrimReplace)
|
| 1004 |
+
|
| 1005 |
+
// normalize spaces
|
| 1006 |
+
range = range.split(/\s+/).join(' ')
|
| 1007 |
+
|
| 1008 |
+
// At this point, the range is completely trimmed and
|
| 1009 |
+
// ready to be split into comparators.
|
| 1010 |
+
|
| 1011 |
+
var compRe = loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR]
|
| 1012 |
+
var set = range.split(' ').map(function (comp) {
|
| 1013 |
+
return parseComparator(comp, this.options)
|
| 1014 |
+
}, this).join(' ').split(/\s+/)
|
| 1015 |
+
if (this.options.loose) {
|
| 1016 |
+
// in loose mode, throw out any that are not valid comparators
|
| 1017 |
+
set = set.filter(function (comp) {
|
| 1018 |
+
return !!comp.match(compRe)
|
| 1019 |
+
})
|
| 1020 |
+
}
|
| 1021 |
+
set = set.map(function (comp) {
|
| 1022 |
+
return new Comparator(comp, this.options)
|
| 1023 |
+
}, this)
|
| 1024 |
+
|
| 1025 |
+
return set
|
| 1026 |
+
}
|
| 1027 |
+
|
| 1028 |
+
Range.prototype.intersects = function (range, options) {
|
| 1029 |
+
if (!(range instanceof Range)) {
|
| 1030 |
+
throw new TypeError('a Range is required')
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
return this.set.some(function (thisComparators) {
|
| 1034 |
+
return (
|
| 1035 |
+
isSatisfiable(thisComparators, options) &&
|
| 1036 |
+
range.set.some(function (rangeComparators) {
|
| 1037 |
+
return (
|
| 1038 |
+
isSatisfiable(rangeComparators, options) &&
|
| 1039 |
+
thisComparators.every(function (thisComparator) {
|
| 1040 |
+
return rangeComparators.every(function (rangeComparator) {
|
| 1041 |
+
return thisComparator.intersects(rangeComparator, options)
|
| 1042 |
+
})
|
| 1043 |
+
})
|
| 1044 |
+
)
|
| 1045 |
+
})
|
| 1046 |
+
)
|
| 1047 |
+
})
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
// take a set of comparators and determine whether there
|
| 1051 |
+
// exists a version which can satisfy it
|
| 1052 |
+
function isSatisfiable (comparators, options) {
|
| 1053 |
+
var result = true
|
| 1054 |
+
var remainingComparators = comparators.slice()
|
| 1055 |
+
var testComparator = remainingComparators.pop()
|
| 1056 |
+
|
| 1057 |
+
while (result && remainingComparators.length) {
|
| 1058 |
+
result = remainingComparators.every(function (otherComparator) {
|
| 1059 |
+
return testComparator.intersects(otherComparator, options)
|
| 1060 |
+
})
|
| 1061 |
+
|
| 1062 |
+
testComparator = remainingComparators.pop()
|
| 1063 |
+
}
|
| 1064 |
+
|
| 1065 |
+
return result
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
// Mostly just for testing and legacy API reasons
|
| 1069 |
+
exports.toComparators = toComparators
|
| 1070 |
+
function toComparators (range, options) {
|
| 1071 |
+
return new Range(range, options).set.map(function (comp) {
|
| 1072 |
+
return comp.map(function (c) {
|
| 1073 |
+
return c.value
|
| 1074 |
+
}).join(' ').trim().split(' ')
|
| 1075 |
+
})
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
// comprised of xranges, tildes, stars, and gtlt's at this point.
|
| 1079 |
+
// already replaced the hyphen ranges
|
| 1080 |
+
// turn into a set of JUST comparators.
|
| 1081 |
+
function parseComparator (comp, options) {
|
| 1082 |
+
debug('comp', comp, options)
|
| 1083 |
+
comp = replaceCarets(comp, options)
|
| 1084 |
+
debug('caret', comp)
|
| 1085 |
+
comp = replaceTildes(comp, options)
|
| 1086 |
+
debug('tildes', comp)
|
| 1087 |
+
comp = replaceXRanges(comp, options)
|
| 1088 |
+
debug('xrange', comp)
|
| 1089 |
+
comp = replaceStars(comp, options)
|
| 1090 |
+
debug('stars', comp)
|
| 1091 |
+
return comp
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
function isX (id) {
|
| 1095 |
+
return !id || id.toLowerCase() === 'x' || id === '*'
|
| 1096 |
+
}
|
| 1097 |
+
|
| 1098 |
+
// ~, ~> --> * (any, kinda silly)
|
| 1099 |
+
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
|
| 1100 |
+
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
|
| 1101 |
+
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
|
| 1102 |
+
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
|
| 1103 |
+
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
|
| 1104 |
+
function replaceTildes (comp, options) {
|
| 1105 |
+
return comp.trim().split(/\s+/).map(function (comp) {
|
| 1106 |
+
return replaceTilde(comp, options)
|
| 1107 |
+
}).join(' ')
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
function replaceTilde (comp, options) {
|
| 1111 |
+
var r = options.loose ? safeRe[t.TILDELOOSE] : safeRe[t.TILDE]
|
| 1112 |
+
return comp.replace(r, function (_, M, m, p, pr) {
|
| 1113 |
+
debug('tilde', comp, _, M, m, p, pr)
|
| 1114 |
+
var ret
|
| 1115 |
+
|
| 1116 |
+
if (isX(M)) {
|
| 1117 |
+
ret = ''
|
| 1118 |
+
} else if (isX(m)) {
|
| 1119 |
+
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
|
| 1120 |
+
} else if (isX(p)) {
|
| 1121 |
+
// ~1.2 == >=1.2.0 <1.3.0
|
| 1122 |
+
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
|
| 1123 |
+
} else if (pr) {
|
| 1124 |
+
debug('replaceTilde pr', pr)
|
| 1125 |
+
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
|
| 1126 |
+
' <' + M + '.' + (+m + 1) + '.0'
|
| 1127 |
+
} else {
|
| 1128 |
+
// ~1.2.3 == >=1.2.3 <1.3.0
|
| 1129 |
+
ret = '>=' + M + '.' + m + '.' + p +
|
| 1130 |
+
' <' + M + '.' + (+m + 1) + '.0'
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
debug('tilde return', ret)
|
| 1134 |
+
return ret
|
| 1135 |
+
})
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
// ^ --> * (any, kinda silly)
|
| 1139 |
+
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
|
| 1140 |
+
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
|
| 1141 |
+
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
|
| 1142 |
+
// ^1.2.3 --> >=1.2.3 <2.0.0
|
| 1143 |
+
// ^1.2.0 --> >=1.2.0 <2.0.0
|
| 1144 |
+
function replaceCarets (comp, options) {
|
| 1145 |
+
return comp.trim().split(/\s+/).map(function (comp) {
|
| 1146 |
+
return replaceCaret(comp, options)
|
| 1147 |
+
}).join(' ')
|
| 1148 |
+
}
|
| 1149 |
+
|
| 1150 |
+
function replaceCaret (comp, options) {
|
| 1151 |
+
debug('caret', comp, options)
|
| 1152 |
+
var r = options.loose ? safeRe[t.CARETLOOSE] : safeRe[t.CARET]
|
| 1153 |
+
return comp.replace(r, function (_, M, m, p, pr) {
|
| 1154 |
+
debug('caret', comp, _, M, m, p, pr)
|
| 1155 |
+
var ret
|
| 1156 |
+
|
| 1157 |
+
if (isX(M)) {
|
| 1158 |
+
ret = ''
|
| 1159 |
+
} else if (isX(m)) {
|
| 1160 |
+
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
|
| 1161 |
+
} else if (isX(p)) {
|
| 1162 |
+
if (M === '0') {
|
| 1163 |
+
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
|
| 1164 |
+
} else {
|
| 1165 |
+
ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0'
|
| 1166 |
+
}
|
| 1167 |
+
} else if (pr) {
|
| 1168 |
+
debug('replaceCaret pr', pr)
|
| 1169 |
+
if (M === '0') {
|
| 1170 |
+
if (m === '0') {
|
| 1171 |
+
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
|
| 1172 |
+
' <' + M + '.' + m + '.' + (+p + 1)
|
| 1173 |
+
} else {
|
| 1174 |
+
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
|
| 1175 |
+
' <' + M + '.' + (+m + 1) + '.0'
|
| 1176 |
+
}
|
| 1177 |
+
} else {
|
| 1178 |
+
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
|
| 1179 |
+
' <' + (+M + 1) + '.0.0'
|
| 1180 |
+
}
|
| 1181 |
+
} else {
|
| 1182 |
+
debug('no pr')
|
| 1183 |
+
if (M === '0') {
|
| 1184 |
+
if (m === '0') {
|
| 1185 |
+
ret = '>=' + M + '.' + m + '.' + p +
|
| 1186 |
+
' <' + M + '.' + m + '.' + (+p + 1)
|
| 1187 |
+
} else {
|
| 1188 |
+
ret = '>=' + M + '.' + m + '.' + p +
|
| 1189 |
+
' <' + M + '.' + (+m + 1) + '.0'
|
| 1190 |
+
}
|
| 1191 |
+
} else {
|
| 1192 |
+
ret = '>=' + M + '.' + m + '.' + p +
|
| 1193 |
+
' <' + (+M + 1) + '.0.0'
|
| 1194 |
+
}
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
debug('caret return', ret)
|
| 1198 |
+
return ret
|
| 1199 |
+
})
|
| 1200 |
+
}
|
| 1201 |
+
|
| 1202 |
+
function replaceXRanges (comp, options) {
|
| 1203 |
+
debug('replaceXRanges', comp, options)
|
| 1204 |
+
return comp.split(/\s+/).map(function (comp) {
|
| 1205 |
+
return replaceXRange(comp, options)
|
| 1206 |
+
}).join(' ')
|
| 1207 |
+
}
|
| 1208 |
+
|
| 1209 |
+
function replaceXRange (comp, options) {
|
| 1210 |
+
comp = comp.trim()
|
| 1211 |
+
var r = options.loose ? safeRe[t.XRANGELOOSE] : safeRe[t.XRANGE]
|
| 1212 |
+
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
|
| 1213 |
+
debug('xRange', comp, ret, gtlt, M, m, p, pr)
|
| 1214 |
+
var xM = isX(M)
|
| 1215 |
+
var xm = xM || isX(m)
|
| 1216 |
+
var xp = xm || isX(p)
|
| 1217 |
+
var anyX = xp
|
| 1218 |
+
|
| 1219 |
+
if (gtlt === '=' && anyX) {
|
| 1220 |
+
gtlt = ''
|
| 1221 |
+
}
|
| 1222 |
+
|
| 1223 |
+
// if we're including prereleases in the match, then we need
|
| 1224 |
+
// to fix this to -0, the lowest possible prerelease value
|
| 1225 |
+
pr = options.includePrerelease ? '-0' : ''
|
| 1226 |
+
|
| 1227 |
+
if (xM) {
|
| 1228 |
+
if (gtlt === '>' || gtlt === '<') {
|
| 1229 |
+
// nothing is allowed
|
| 1230 |
+
ret = '<0.0.0-0'
|
| 1231 |
+
} else {
|
| 1232 |
+
// nothing is forbidden
|
| 1233 |
+
ret = '*'
|
| 1234 |
+
}
|
| 1235 |
+
} else if (gtlt && anyX) {
|
| 1236 |
+
// we know patch is an x, because we have any x at all.
|
| 1237 |
+
// replace X with 0
|
| 1238 |
+
if (xm) {
|
| 1239 |
+
m = 0
|
| 1240 |
+
}
|
| 1241 |
+
p = 0
|
| 1242 |
+
|
| 1243 |
+
if (gtlt === '>') {
|
| 1244 |
+
// >1 => >=2.0.0
|
| 1245 |
+
// >1.2 => >=1.3.0
|
| 1246 |
+
// >1.2.3 => >= 1.2.4
|
| 1247 |
+
gtlt = '>='
|
| 1248 |
+
if (xm) {
|
| 1249 |
+
M = +M + 1
|
| 1250 |
+
m = 0
|
| 1251 |
+
p = 0
|
| 1252 |
+
} else {
|
| 1253 |
+
m = +m + 1
|
| 1254 |
+
p = 0
|
| 1255 |
+
}
|
| 1256 |
+
} else if (gtlt === '<=') {
|
| 1257 |
+
// <=0.7.x is actually <0.8.0, since any 0.7.x should
|
| 1258 |
+
// pass. Similarly, <=7.x is actually <8.0.0, etc.
|
| 1259 |
+
gtlt = '<'
|
| 1260 |
+
if (xm) {
|
| 1261 |
+
M = +M + 1
|
| 1262 |
+
} else {
|
| 1263 |
+
m = +m + 1
|
| 1264 |
+
}
|
| 1265 |
+
}
|
| 1266 |
+
|
| 1267 |
+
ret = gtlt + M + '.' + m + '.' + p + pr
|
| 1268 |
+
} else if (xm) {
|
| 1269 |
+
ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr
|
| 1270 |
+
} else if (xp) {
|
| 1271 |
+
ret = '>=' + M + '.' + m + '.0' + pr +
|
| 1272 |
+
' <' + M + '.' + (+m + 1) + '.0' + pr
|
| 1273 |
+
}
|
| 1274 |
+
|
| 1275 |
+
debug('xRange return', ret)
|
| 1276 |
+
|
| 1277 |
+
return ret
|
| 1278 |
+
})
|
| 1279 |
+
}
|
| 1280 |
+
|
| 1281 |
+
// Because * is AND-ed with everything else in the comparator,
|
| 1282 |
+
// and '' means "any version", just remove the *s entirely.
|
| 1283 |
+
function replaceStars (comp, options) {
|
| 1284 |
+
debug('replaceStars', comp, options)
|
| 1285 |
+
// Looseness is ignored here. star is always as loose as it gets!
|
| 1286 |
+
return comp.trim().replace(safeRe[t.STAR], '')
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
| 1290 |
+
// M, m, patch, prerelease, build
|
| 1291 |
+
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
| 1292 |
+
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
| 1293 |
+
// 1.2 - 3.4 => >=1.2.0 <3.5.0
|
| 1294 |
+
function hyphenReplace ($0,
|
| 1295 |
+
from, fM, fm, fp, fpr, fb,
|
| 1296 |
+
to, tM, tm, tp, tpr, tb) {
|
| 1297 |
+
if (isX(fM)) {
|
| 1298 |
+
from = ''
|
| 1299 |
+
} else if (isX(fm)) {
|
| 1300 |
+
from = '>=' + fM + '.0.0'
|
| 1301 |
+
} else if (isX(fp)) {
|
| 1302 |
+
from = '>=' + fM + '.' + fm + '.0'
|
| 1303 |
+
} else {
|
| 1304 |
+
from = '>=' + from
|
| 1305 |
+
}
|
| 1306 |
+
|
| 1307 |
+
if (isX(tM)) {
|
| 1308 |
+
to = ''
|
| 1309 |
+
} else if (isX(tm)) {
|
| 1310 |
+
to = '<' + (+tM + 1) + '.0.0'
|
| 1311 |
+
} else if (isX(tp)) {
|
| 1312 |
+
to = '<' + tM + '.' + (+tm + 1) + '.0'
|
| 1313 |
+
} else if (tpr) {
|
| 1314 |
+
to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr
|
| 1315 |
+
} else {
|
| 1316 |
+
to = '<=' + to
|
| 1317 |
+
}
|
| 1318 |
+
|
| 1319 |
+
return (from + ' ' + to).trim()
|
| 1320 |
+
}
|
| 1321 |
+
|
| 1322 |
+
// if ANY of the sets match ALL of its comparators, then pass
|
| 1323 |
+
Range.prototype.test = function (version) {
|
| 1324 |
+
if (!version) {
|
| 1325 |
+
return false
|
| 1326 |
+
}
|
| 1327 |
+
|
| 1328 |
+
if (typeof version === 'string') {
|
| 1329 |
+
try {
|
| 1330 |
+
version = new SemVer(version, this.options)
|
| 1331 |
+
} catch (er) {
|
| 1332 |
+
return false
|
| 1333 |
+
}
|
| 1334 |
+
}
|
| 1335 |
+
|
| 1336 |
+
for (var i = 0; i < this.set.length; i++) {
|
| 1337 |
+
if (testSet(this.set[i], version, this.options)) {
|
| 1338 |
+
return true
|
| 1339 |
+
}
|
| 1340 |
+
}
|
| 1341 |
+
return false
|
| 1342 |
+
}
|
| 1343 |
+
|
| 1344 |
+
function testSet (set, version, options) {
|
| 1345 |
+
for (var i = 0; i < set.length; i++) {
|
| 1346 |
+
if (!set[i].test(version)) {
|
| 1347 |
+
return false
|
| 1348 |
+
}
|
| 1349 |
+
}
|
| 1350 |
+
|
| 1351 |
+
if (version.prerelease.length && !options.includePrerelease) {
|
| 1352 |
+
// Find the set of versions that are allowed to have prereleases
|
| 1353 |
+
// For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
|
| 1354 |
+
// That should allow `1.2.3-pr.2` to pass.
|
| 1355 |
+
// However, `1.2.4-alpha.notready` should NOT be allowed,
|
| 1356 |
+
// even though it's within the range set by the comparators.
|
| 1357 |
+
for (i = 0; i < set.length; i++) {
|
| 1358 |
+
debug(set[i].semver)
|
| 1359 |
+
if (set[i].semver === ANY) {
|
| 1360 |
+
continue
|
| 1361 |
+
}
|
| 1362 |
+
|
| 1363 |
+
if (set[i].semver.prerelease.length > 0) {
|
| 1364 |
+
var allowed = set[i].semver
|
| 1365 |
+
if (allowed.major === version.major &&
|
| 1366 |
+
allowed.minor === version.minor &&
|
| 1367 |
+
allowed.patch === version.patch) {
|
| 1368 |
+
return true
|
| 1369 |
+
}
|
| 1370 |
+
}
|
| 1371 |
+
}
|
| 1372 |
+
|
| 1373 |
+
// Version has a -pre, but it's not one of the ones we like.
|
| 1374 |
+
return false
|
| 1375 |
+
}
|
| 1376 |
+
|
| 1377 |
+
return true
|
| 1378 |
+
}
|
| 1379 |
+
|
| 1380 |
+
exports.satisfies = satisfies
|
| 1381 |
+
function satisfies (version, range, options) {
|
| 1382 |
+
try {
|
| 1383 |
+
range = new Range(range, options)
|
| 1384 |
+
} catch (er) {
|
| 1385 |
+
return false
|
| 1386 |
+
}
|
| 1387 |
+
return range.test(version)
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
exports.maxSatisfying = maxSatisfying
|
| 1391 |
+
function maxSatisfying (versions, range, options) {
|
| 1392 |
+
var max = null
|
| 1393 |
+
var maxSV = null
|
| 1394 |
+
try {
|
| 1395 |
+
var rangeObj = new Range(range, options)
|
| 1396 |
+
} catch (er) {
|
| 1397 |
+
return null
|
| 1398 |
+
}
|
| 1399 |
+
versions.forEach(function (v) {
|
| 1400 |
+
if (rangeObj.test(v)) {
|
| 1401 |
+
// satisfies(v, range, options)
|
| 1402 |
+
if (!max || maxSV.compare(v) === -1) {
|
| 1403 |
+
// compare(max, v, true)
|
| 1404 |
+
max = v
|
| 1405 |
+
maxSV = new SemVer(max, options)
|
| 1406 |
+
}
|
| 1407 |
+
}
|
| 1408 |
+
})
|
| 1409 |
+
return max
|
| 1410 |
+
}
|
| 1411 |
+
|
| 1412 |
+
exports.minSatisfying = minSatisfying
|
| 1413 |
+
function minSatisfying (versions, range, options) {
|
| 1414 |
+
var min = null
|
| 1415 |
+
var minSV = null
|
| 1416 |
+
try {
|
| 1417 |
+
var rangeObj = new Range(range, options)
|
| 1418 |
+
} catch (er) {
|
| 1419 |
+
return null
|
| 1420 |
+
}
|
| 1421 |
+
versions.forEach(function (v) {
|
| 1422 |
+
if (rangeObj.test(v)) {
|
| 1423 |
+
// satisfies(v, range, options)
|
| 1424 |
+
if (!min || minSV.compare(v) === 1) {
|
| 1425 |
+
// compare(min, v, true)
|
| 1426 |
+
min = v
|
| 1427 |
+
minSV = new SemVer(min, options)
|
| 1428 |
+
}
|
| 1429 |
+
}
|
| 1430 |
+
})
|
| 1431 |
+
return min
|
| 1432 |
+
}
|
| 1433 |
+
|
| 1434 |
+
exports.minVersion = minVersion
|
| 1435 |
+
function minVersion (range, loose) {
|
| 1436 |
+
range = new Range(range, loose)
|
| 1437 |
+
|
| 1438 |
+
var minver = new SemVer('0.0.0')
|
| 1439 |
+
if (range.test(minver)) {
|
| 1440 |
+
return minver
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
minver = new SemVer('0.0.0-0')
|
| 1444 |
+
if (range.test(minver)) {
|
| 1445 |
+
return minver
|
| 1446 |
+
}
|
| 1447 |
+
|
| 1448 |
+
minver = null
|
| 1449 |
+
for (var i = 0; i < range.set.length; ++i) {
|
| 1450 |
+
var comparators = range.set[i]
|
| 1451 |
+
|
| 1452 |
+
comparators.forEach(function (comparator) {
|
| 1453 |
+
// Clone to avoid manipulating the comparator's semver object.
|
| 1454 |
+
var compver = new SemVer(comparator.semver.version)
|
| 1455 |
+
switch (comparator.operator) {
|
| 1456 |
+
case '>':
|
| 1457 |
+
if (compver.prerelease.length === 0) {
|
| 1458 |
+
compver.patch++
|
| 1459 |
+
} else {
|
| 1460 |
+
compver.prerelease.push(0)
|
| 1461 |
+
}
|
| 1462 |
+
compver.raw = compver.format()
|
| 1463 |
+
/* fallthrough */
|
| 1464 |
+
case '':
|
| 1465 |
+
case '>=':
|
| 1466 |
+
if (!minver || gt(minver, compver)) {
|
| 1467 |
+
minver = compver
|
| 1468 |
+
}
|
| 1469 |
+
break
|
| 1470 |
+
case '<':
|
| 1471 |
+
case '<=':
|
| 1472 |
+
/* Ignore maximum versions */
|
| 1473 |
+
break
|
| 1474 |
+
/* istanbul ignore next */
|
| 1475 |
+
default:
|
| 1476 |
+
throw new Error('Unexpected operation: ' + comparator.operator)
|
| 1477 |
+
}
|
| 1478 |
+
})
|
| 1479 |
+
}
|
| 1480 |
+
|
| 1481 |
+
if (minver && range.test(minver)) {
|
| 1482 |
+
return minver
|
| 1483 |
+
}
|
| 1484 |
+
|
| 1485 |
+
return null
|
| 1486 |
+
}
|
| 1487 |
+
|
| 1488 |
+
exports.validRange = validRange
|
| 1489 |
+
function validRange (range, options) {
|
| 1490 |
+
try {
|
| 1491 |
+
// Return '*' instead of '' so that truthiness works.
|
| 1492 |
+
// This will throw if it's invalid anyway
|
| 1493 |
+
return new Range(range, options).range || '*'
|
| 1494 |
+
} catch (er) {
|
| 1495 |
+
return null
|
| 1496 |
+
}
|
| 1497 |
+
}
|
| 1498 |
+
|
| 1499 |
+
// Determine if version is less than all the versions possible in the range
|
| 1500 |
+
exports.ltr = ltr
|
| 1501 |
+
function ltr (version, range, options) {
|
| 1502 |
+
return outside(version, range, '<', options)
|
| 1503 |
+
}
|
| 1504 |
+
|
| 1505 |
+
// Determine if version is greater than all the versions possible in the range.
|
| 1506 |
+
exports.gtr = gtr
|
| 1507 |
+
function gtr (version, range, options) {
|
| 1508 |
+
return outside(version, range, '>', options)
|
| 1509 |
+
}
|
| 1510 |
+
|
| 1511 |
+
exports.outside = outside
|
| 1512 |
+
function outside (version, range, hilo, options) {
|
| 1513 |
+
version = new SemVer(version, options)
|
| 1514 |
+
range = new Range(range, options)
|
| 1515 |
+
|
| 1516 |
+
var gtfn, ltefn, ltfn, comp, ecomp
|
| 1517 |
+
switch (hilo) {
|
| 1518 |
+
case '>':
|
| 1519 |
+
gtfn = gt
|
| 1520 |
+
ltefn = lte
|
| 1521 |
+
ltfn = lt
|
| 1522 |
+
comp = '>'
|
| 1523 |
+
ecomp = '>='
|
| 1524 |
+
break
|
| 1525 |
+
case '<':
|
| 1526 |
+
gtfn = lt
|
| 1527 |
+
ltefn = gte
|
| 1528 |
+
ltfn = gt
|
| 1529 |
+
comp = '<'
|
| 1530 |
+
ecomp = '<='
|
| 1531 |
+
break
|
| 1532 |
+
default:
|
| 1533 |
+
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
| 1534 |
+
}
|
| 1535 |
+
|
| 1536 |
+
// If it satisifes the range it is not outside
|
| 1537 |
+
if (satisfies(version, range, options)) {
|
| 1538 |
+
return false
|
| 1539 |
+
}
|
| 1540 |
+
|
| 1541 |
+
// From now on, variable terms are as if we're in "gtr" mode.
|
| 1542 |
+
// but note that everything is flipped for the "ltr" function.
|
| 1543 |
+
|
| 1544 |
+
for (var i = 0; i < range.set.length; ++i) {
|
| 1545 |
+
var comparators = range.set[i]
|
| 1546 |
+
|
| 1547 |
+
var high = null
|
| 1548 |
+
var low = null
|
| 1549 |
+
|
| 1550 |
+
comparators.forEach(function (comparator) {
|
| 1551 |
+
if (comparator.semver === ANY) {
|
| 1552 |
+
comparator = new Comparator('>=0.0.0')
|
| 1553 |
+
}
|
| 1554 |
+
high = high || comparator
|
| 1555 |
+
low = low || comparator
|
| 1556 |
+
if (gtfn(comparator.semver, high.semver, options)) {
|
| 1557 |
+
high = comparator
|
| 1558 |
+
} else if (ltfn(comparator.semver, low.semver, options)) {
|
| 1559 |
+
low = comparator
|
| 1560 |
+
}
|
| 1561 |
+
})
|
| 1562 |
+
|
| 1563 |
+
// If the edge version comparator has a operator then our version
|
| 1564 |
+
// isn't outside it
|
| 1565 |
+
if (high.operator === comp || high.operator === ecomp) {
|
| 1566 |
+
return false
|
| 1567 |
+
}
|
| 1568 |
+
|
| 1569 |
+
// If the lowest version comparator has an operator and our version
|
| 1570 |
+
// is less than it then it isn't higher than the range
|
| 1571 |
+
if ((!low.operator || low.operator === comp) &&
|
| 1572 |
+
ltefn(version, low.semver)) {
|
| 1573 |
+
return false
|
| 1574 |
+
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
| 1575 |
+
return false
|
| 1576 |
+
}
|
| 1577 |
+
}
|
| 1578 |
+
return true
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
exports.prerelease = prerelease
|
| 1582 |
+
function prerelease (version, options) {
|
| 1583 |
+
var parsed = parse(version, options)
|
| 1584 |
+
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
|
| 1585 |
+
}
|
| 1586 |
+
|
| 1587 |
+
exports.intersects = intersects
|
| 1588 |
+
function intersects (r1, r2, options) {
|
| 1589 |
+
r1 = new Range(r1, options)
|
| 1590 |
+
r2 = new Range(r2, options)
|
| 1591 |
+
return r1.intersects(r2)
|
| 1592 |
+
}
|
| 1593 |
+
|
| 1594 |
+
exports.coerce = coerce
|
| 1595 |
+
function coerce (version, options) {
|
| 1596 |
+
if (version instanceof SemVer) {
|
| 1597 |
+
return version
|
| 1598 |
+
}
|
| 1599 |
+
|
| 1600 |
+
if (typeof version === 'number') {
|
| 1601 |
+
version = String(version)
|
| 1602 |
+
}
|
| 1603 |
+
|
| 1604 |
+
if (typeof version !== 'string') {
|
| 1605 |
+
return null
|
| 1606 |
+
}
|
| 1607 |
+
|
| 1608 |
+
options = options || {}
|
| 1609 |
+
|
| 1610 |
+
var match = null
|
| 1611 |
+
if (!options.rtl) {
|
| 1612 |
+
match = version.match(safeRe[t.COERCE])
|
| 1613 |
+
} else {
|
| 1614 |
+
// Find the right-most coercible string that does not share
|
| 1615 |
+
// a terminus with a more left-ward coercible string.
|
| 1616 |
+
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
| 1617 |
+
//
|
| 1618 |
+
// Walk through the string checking with a /g regexp
|
| 1619 |
+
// Manually set the index so as to pick up overlapping matches.
|
| 1620 |
+
// Stop when we get a match that ends at the string end, since no
|
| 1621 |
+
// coercible string can be more right-ward without the same terminus.
|
| 1622 |
+
var next
|
| 1623 |
+
while ((next = safeRe[t.COERCERTL].exec(version)) &&
|
| 1624 |
+
(!match || match.index + match[0].length !== version.length)
|
| 1625 |
+
) {
|
| 1626 |
+
if (!match ||
|
| 1627 |
+
next.index + next[0].length !== match.index + match[0].length) {
|
| 1628 |
+
match = next
|
| 1629 |
+
}
|
| 1630 |
+
safeRe[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
|
| 1631 |
+
}
|
| 1632 |
+
// leave it in a clean state
|
| 1633 |
+
safeRe[t.COERCERTL].lastIndex = -1
|
| 1634 |
+
}
|
| 1635 |
+
|
| 1636 |
+
if (match === null) {
|
| 1637 |
+
return null
|
| 1638 |
+
}
|
| 1639 |
+
|
| 1640 |
+
return parse(match[2] +
|
| 1641 |
+
'.' + (match[3] || '0') +
|
| 1642 |
+
'.' + (match[4] || '0'), options)
|
| 1643 |
+
}
|
node_modules/eslint-plugin-react/package.json
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-plugin-react",
|
| 3 |
+
"version": "7.37.5",
|
| 4 |
+
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>",
|
| 5 |
+
"description": "React specific linting rules for ESLint",
|
| 6 |
+
"main": "index.js",
|
| 7 |
+
"types": "index.d.ts",
|
| 8 |
+
"scripts": {
|
| 9 |
+
"clean-built-types": "rm -f $(find . -maxdepth 1 -type f -name '*.d.ts*') $(find lib -type f -name '*.d.ts*' ! -name 'types.d.ts')",
|
| 10 |
+
"prebuild-types": "npm run clean-built-types",
|
| 11 |
+
"build-types": "tsc -p build.tsconfig.json",
|
| 12 |
+
"prepack": "npm run build-types && npmignore --auto --commentLines=autogenerated",
|
| 13 |
+
"prelint": "npm run lint:docs",
|
| 14 |
+
"lint:docs": "markdownlint \"**/*.md\"",
|
| 15 |
+
"postlint:docs": "npm run update:eslint-docs -- --check",
|
| 16 |
+
"lint": "eslint .",
|
| 17 |
+
"postlint": "npm run type-check",
|
| 18 |
+
"pretest": "npm run lint",
|
| 19 |
+
"test": "npm run unit-test",
|
| 20 |
+
"posttest": "npx npm@'>= 10.2' audit --production",
|
| 21 |
+
"type-check": "tsc",
|
| 22 |
+
"unit-test": "istanbul cover node_modules/mocha/bin/_mocha tests/lib/**/*.js tests/util/**/*.js tests/index.js tests/flat-config.js",
|
| 23 |
+
"update:eslint-docs": "eslint-doc-generator"
|
| 24 |
+
},
|
| 25 |
+
"repository": {
|
| 26 |
+
"type": "git",
|
| 27 |
+
"url": "https://github.com/jsx-eslint/eslint-plugin-react"
|
| 28 |
+
},
|
| 29 |
+
"directories": {
|
| 30 |
+
"test": [
|
| 31 |
+
"test",
|
| 32 |
+
"tests",
|
| 33 |
+
"test-published-types"
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
"homepage": "https://github.com/jsx-eslint/eslint-plugin-react",
|
| 37 |
+
"bugs": "https://github.com/jsx-eslint/eslint-plugin-react/issues",
|
| 38 |
+
"dependencies": {
|
| 39 |
+
"array-includes": "^3.1.8",
|
| 40 |
+
"array.prototype.findlast": "^1.2.5",
|
| 41 |
+
"array.prototype.flatmap": "^1.3.3",
|
| 42 |
+
"array.prototype.tosorted": "^1.1.4",
|
| 43 |
+
"doctrine": "^2.1.0",
|
| 44 |
+
"es-iterator-helpers": "^1.2.1",
|
| 45 |
+
"estraverse": "^5.3.0",
|
| 46 |
+
"hasown": "^2.0.2",
|
| 47 |
+
"jsx-ast-utils": "^2.4.1 || ^3.0.0",
|
| 48 |
+
"minimatch": "^3.1.2",
|
| 49 |
+
"object.entries": "^1.1.9",
|
| 50 |
+
"object.fromentries": "^2.0.8",
|
| 51 |
+
"object.values": "^1.2.1",
|
| 52 |
+
"prop-types": "^15.8.1",
|
| 53 |
+
"resolve": "^2.0.0-next.5",
|
| 54 |
+
"semver": "^6.3.1",
|
| 55 |
+
"string.prototype.matchall": "^4.0.12",
|
| 56 |
+
"string.prototype.repeat": "^1.0.0"
|
| 57 |
+
},
|
| 58 |
+
"devDependencies": {
|
| 59 |
+
"@babel/core": "^7.26.10",
|
| 60 |
+
"@babel/eslint-parser": "^7.27.0",
|
| 61 |
+
"@babel/plugin-syntax-decorators": "^7.25.9",
|
| 62 |
+
"@babel/plugin-syntax-do-expressions": "^7.25.9",
|
| 63 |
+
"@babel/plugin-syntax-function-bind": "^7.25.9",
|
| 64 |
+
"@babel/preset-react": "^7.26.3",
|
| 65 |
+
"@types/eslint": "=7.2.10",
|
| 66 |
+
"@types/estree": "0.0.52",
|
| 67 |
+
"@types/node": "^4.9.5",
|
| 68 |
+
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4 || ^5 || ^6.20 || ^7.14.1 || 8.4 - 8.17",
|
| 69 |
+
"babel-eslint": "^8 || ^9 || ^10.1.0",
|
| 70 |
+
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7",
|
| 71 |
+
"eslint-config-airbnb-base": "^15.0.0",
|
| 72 |
+
"eslint-doc-generator": "^1.7.1",
|
| 73 |
+
"eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.0.5",
|
| 74 |
+
"eslint-plugin-import": "^2.31.0",
|
| 75 |
+
"eslint-remote-tester": "^3.0.1",
|
| 76 |
+
"eslint-remote-tester-repositories": "^1.0.1",
|
| 77 |
+
"eslint-scope": "^3.7.3",
|
| 78 |
+
"espree": "^3.5.4",
|
| 79 |
+
"gfm-footnotes": "^1.0.1",
|
| 80 |
+
"glob": "=10.3.7",
|
| 81 |
+
"istanbul": "^0.4.5",
|
| 82 |
+
"jackspeak": "=2.1.1",
|
| 83 |
+
"ls-engines": "^0.8.1",
|
| 84 |
+
"markdownlint-cli": "^0.8.0 || ^0.32.2",
|
| 85 |
+
"mocha": "^5.2.0",
|
| 86 |
+
"npmignore": "^0.3.1",
|
| 87 |
+
"sinon": "^7.5.0",
|
| 88 |
+
"typescript": "^3.9.9",
|
| 89 |
+
"typescript-eslint-parser": "^20.1.1"
|
| 90 |
+
},
|
| 91 |
+
"peerDependencies": {
|
| 92 |
+
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7"
|
| 93 |
+
},
|
| 94 |
+
"engines": {
|
| 95 |
+
"node": ">=4"
|
| 96 |
+
},
|
| 97 |
+
"keywords": [
|
| 98 |
+
"eslint",
|
| 99 |
+
"eslint-plugin",
|
| 100 |
+
"eslintplugin",
|
| 101 |
+
"react"
|
| 102 |
+
],
|
| 103 |
+
"license": "MIT",
|
| 104 |
+
"publishConfig": {
|
| 105 |
+
"ignore": [
|
| 106 |
+
".github/",
|
| 107 |
+
"!lib",
|
| 108 |
+
"docs/",
|
| 109 |
+
"test/",
|
| 110 |
+
"test-published-types/",
|
| 111 |
+
"tests/",
|
| 112 |
+
"*.md",
|
| 113 |
+
"*.config.js",
|
| 114 |
+
".eslint-doc-generatorrc.js",
|
| 115 |
+
".eslintrc",
|
| 116 |
+
".editorconfig",
|
| 117 |
+
"tsconfig.json",
|
| 118 |
+
"build.tsconfig.json",
|
| 119 |
+
".markdownlint*",
|
| 120 |
+
"types",
|
| 121 |
+
"!*.d.ts",
|
| 122 |
+
"!*.d.ts.map"
|
| 123 |
+
]
|
| 124 |
+
}
|
| 125 |
+
}
|
node_modules/eslint-scope/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright JS Foundation and other contributors, https://js.foundation
|
| 2 |
+
Copyright (C) 2012-2013 Yusuke Suzuki (twitter: @Constellation) and other contributors.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
node_modules/eslint-scope/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[](https://www.npmjs.com/package/eslint-scope)
|
| 2 |
+
[](https://www.npmjs.com/package/eslint-scope)
|
| 3 |
+
[](https://github.com/eslint/js/actions)
|
| 4 |
+
|
| 5 |
+
# ESLint Scope
|
| 6 |
+
|
| 7 |
+
ESLint Scope is the [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) scope analyzer used in ESLint. It is a fork of [escope](http://github.com/estools/escope).
|
| 8 |
+
|
| 9 |
+
## Install
|
| 10 |
+
|
| 11 |
+
```
|
| 12 |
+
npm i eslint-scope --save
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
## 📖 Usage
|
| 16 |
+
|
| 17 |
+
To use in an ESM file:
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
import * as eslintScope from 'eslint-scope';
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
To use in a CommonJS file:
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
const eslintScope = require('eslint-scope');
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
In order to analyze scope, you'll need to have an [ESTree](https://github.com/estree/estree) compliant AST structure to run it on. The primary method is `eslintScope.analyze()`, which takes two arguments:
|
| 30 |
+
|
| 31 |
+
1. `ast` - the ESTree-compliant AST structure to analyze.
|
| 32 |
+
2. `options` (optional) - Options to adjust how the scope is analyzed, including:
|
| 33 |
+
* `ignoreEval` (default: `false`) - Set to `true` to ignore all `eval()` calls (which would normally create scopes).
|
| 34 |
+
* `nodejsScope` (default: `false`) - Set to `true` to create a top-level function scope needed for CommonJS evaluation.
|
| 35 |
+
* `impliedStrict` (default: `false`) - Set to `true` to evaluate the code in strict mode even outside of modules and without `"use strict"`.
|
| 36 |
+
* `ecmaVersion` (default: `5`) - The version of ECMAScript to use to evaluate the code.
|
| 37 |
+
* `sourceType` (default: `"script"`) - The type of JavaScript file to evaluate. Change to `"module"` for ECMAScript module code.
|
| 38 |
+
* `childVisitorKeys` (default: `null`) - An object with visitor key information (like [`eslint-visitor-keys`](https://github.com/eslint/js/tree/main/packages/eslint-visitor-keys)). Without this, `eslint-scope` finds child nodes to visit algorithmically. Providing this option is a performance enhancement.
|
| 39 |
+
* `fallback` (default: `"iteration"`) - The strategy to use when `childVisitorKeys` is not specified. May be a function.
|
| 40 |
+
* `jsx` (default: `false`) - Enables the tracking of JSX components as variable references.
|
| 41 |
+
|
| 42 |
+
Example:
|
| 43 |
+
|
| 44 |
+
```js
|
| 45 |
+
import * as eslintScope from 'eslint-scope';
|
| 46 |
+
import * as espree from 'espree';
|
| 47 |
+
import estraverse from 'estraverse';
|
| 48 |
+
|
| 49 |
+
const options = {
|
| 50 |
+
ecmaVersion: 2022,
|
| 51 |
+
sourceType: "module"
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
const ast = espree.parse(code, { range: true, ...options });
|
| 55 |
+
const scopeManager = eslintScope.analyze(ast, options);
|
| 56 |
+
|
| 57 |
+
const currentScope = scopeManager.acquire(ast); // global scope
|
| 58 |
+
|
| 59 |
+
estraverse.traverse(ast, {
|
| 60 |
+
enter (node, parent) {
|
| 61 |
+
// do stuff
|
| 62 |
+
|
| 63 |
+
if (/Function/.test(node.type)) {
|
| 64 |
+
currentScope = scopeManager.acquire(node); // get current function scope
|
| 65 |
+
}
|
| 66 |
+
},
|
| 67 |
+
leave(node, parent) {
|
| 68 |
+
if (/Function/.test(node.type)) {
|
| 69 |
+
currentScope = currentScope.upper; // set to parent scope
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// do stuff
|
| 73 |
+
}
|
| 74 |
+
});
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## API
|
| 78 |
+
|
| 79 |
+
The following section describes the API for this package. You can also read [the docs](https://eslint.org/docs/latest/extend/scope-manager-interface).
|
| 80 |
+
|
| 81 |
+
### ScopeManager
|
| 82 |
+
|
| 83 |
+
The `ScopeManager` class is at the core of eslint-scope and is returned when you call `eslintScope.analyze()`. It manages all scopes in a given AST.
|
| 84 |
+
|
| 85 |
+
#### Properties
|
| 86 |
+
|
| 87 |
+
- `scopes` - An array of all scopes.
|
| 88 |
+
- `globalScope` - Reference to the global scope.
|
| 89 |
+
|
| 90 |
+
#### Methods
|
| 91 |
+
|
| 92 |
+
- **`acquire(node, inner)`**
|
| 93 |
+
Acquires the appropriate scope for a given node.
|
| 94 |
+
- `node` - The AST node to acquire the scope from.
|
| 95 |
+
- `inner` - Optional boolean. When `true`, returns the innermost scope, otherwise returns the outermost scope. Default is `false`.
|
| 96 |
+
- Returns: The acquired scope or `null` if no scope is found.
|
| 97 |
+
|
| 98 |
+
- **`acquireAll(node)`**
|
| 99 |
+
Acquires all scopes for a given node.
|
| 100 |
+
- `node` - The AST node to acquire scopes from.
|
| 101 |
+
- Returns: An array of scopes or `undefined` if none are found.
|
| 102 |
+
|
| 103 |
+
- **`release(node, inner)`**
|
| 104 |
+
Returns the upper scope for a given node.
|
| 105 |
+
- `node` - The AST node to release.
|
| 106 |
+
- `inner` - Optional boolean. When `true`, returns the innermost upper scope, otherwise returns the outermost upper scope. Default is `false`.
|
| 107 |
+
- Returns: The upper scope or `null` if no upper scope exists.
|
| 108 |
+
|
| 109 |
+
- **`getDeclaredVariables(node)`**
|
| 110 |
+
Get variables that are declared by the node.
|
| 111 |
+
- `node` - The AST node to get declarations from.
|
| 112 |
+
- Returns: An array of variable objects declared by the node. If the node doesn't declare any variables, it returns an empty array.
|
| 113 |
+
|
| 114 |
+
- **`isGlobalReturn()`**
|
| 115 |
+
Determines if the global return statement should be allowed.
|
| 116 |
+
- Returns: `true` if the global return is enabled.
|
| 117 |
+
|
| 118 |
+
- **`isModule()`**
|
| 119 |
+
Checks if the code should be handled as an ECMAScript module.
|
| 120 |
+
- Returns: `true` if the sourceType is "module".
|
| 121 |
+
|
| 122 |
+
- **`isImpliedStrict()`**
|
| 123 |
+
Checks if implied strict mode is enabled.
|
| 124 |
+
- Returns: `true` if implied strict mode is enabled.
|
| 125 |
+
|
| 126 |
+
- **`isStrictModeSupported()`**
|
| 127 |
+
Checks if strict mode is supported based on ECMAScript version.
|
| 128 |
+
- Returns: `true` if the ECMAScript version supports strict mode.
|
| 129 |
+
|
| 130 |
+
### Scope Objects
|
| 131 |
+
|
| 132 |
+
Scopes returned by the ScopeManager methods have the following properties:
|
| 133 |
+
|
| 134 |
+
- `type` - The type of scope (e.g., "function", "block", "global").
|
| 135 |
+
- `variables` - Array of variables declared in this scope.
|
| 136 |
+
- `set` - A Map of variable names to Variable objects for variables declared in this scope.
|
| 137 |
+
- `references` - Array of references in this scope.
|
| 138 |
+
- `through` - Array of references in this scope and its child scopes that aren't resolved in this scope or its child scopes.
|
| 139 |
+
- `variableScope` - Reference to the closest variable scope.
|
| 140 |
+
- `upper` - Reference to the parent scope.
|
| 141 |
+
- `childScopes` - Array of child scopes.
|
| 142 |
+
- `block` - The AST node that created this scope.
|
| 143 |
+
|
| 144 |
+
### GlobalScope
|
| 145 |
+
|
| 146 |
+
The `GlobalScope` class is a specialized scope representing the global execution context. It extends the base `Scope` class with additional functionality for handling implicitly defined global variables.
|
| 147 |
+
|
| 148 |
+
#### Properties
|
| 149 |
+
|
| 150 |
+
- **`implicit`** - Tracks implicitly defined global variables (those used without declaration).
|
| 151 |
+
- `set` - A Map of variable names to Variable objects for implicitly defined globals.
|
| 152 |
+
- `variables` - Array of implicit global Variable objects.
|
| 153 |
+
- `left` - Array of References that need to be linked to the variable they refer to.
|
| 154 |
+
|
| 155 |
+
### Variable Objects
|
| 156 |
+
|
| 157 |
+
Each variable object has the following properties:
|
| 158 |
+
|
| 159 |
+
- `name` - The variable name.
|
| 160 |
+
- `identifiers` - Array of identifier nodes declaring this variable.
|
| 161 |
+
- `references` - Array of references to this variable.
|
| 162 |
+
- `defs` - Array of definition objects for this variable.
|
| 163 |
+
- `scope` - The scope object where this variable is defined.
|
| 164 |
+
|
| 165 |
+
## Contributing
|
| 166 |
+
|
| 167 |
+
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/js/issues).
|
| 168 |
+
|
| 169 |
+
## Security Policy
|
| 170 |
+
|
| 171 |
+
We work hard to ensure that ESLint Scope is safe for everyone and that security issues are addressed quickly and responsibly. Read the full [security policy](https://github.com/eslint/.github/blob/master/SECURITY.md).
|
| 172 |
+
|
| 173 |
+
## Build Commands
|
| 174 |
+
|
| 175 |
+
* `npm test` - run all linting and tests
|
| 176 |
+
* `npm run lint` - run all linting
|
| 177 |
+
|
| 178 |
+
## License
|
| 179 |
+
|
| 180 |
+
ESLint Scope is licensed under a permissive BSD 2-clause license.
|
| 181 |
+
|
| 182 |
+
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
| 183 |
+
<!--sponsorsstart-->
|
| 184 |
+
## Sponsors
|
| 185 |
+
|
| 186 |
+
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
| 187 |
+
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
| 188 |
+
|
| 189 |
+
<h3>Diamond Sponsors</h3>
|
| 190 |
+
<p><a href="https://www.ag-grid.com/"><img src="https://images.opencollective.com/ag-grid/bec0580/logo.png" alt="AG Grid" height="128"></a></p><h3>Platinum Sponsors</h3>
|
| 191 |
+
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
|
| 192 |
+
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
|
| 193 |
+
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
| 194 |
+
<p><a href="https://sentry.io"><img src="https://github.com/getsentry.png" alt="Sentry" height="32"></a> <a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nolebase.ayaka.io"><img src="https://avatars.githubusercontent.com/u/11081491" alt="Neko" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="LambdaTest" height="32"></a></p>
|
| 195 |
+
<h3>Technology Sponsors</h3>
|
| 196 |
+
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
| 197 |
+
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
| 198 |
+
<!--sponsorsend-->
|
node_modules/eslint-scope/dist/eslint-scope.cjs
ADDED
|
@@ -0,0 +1,2339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 4 |
+
|
| 5 |
+
var estraverse = require('estraverse');
|
| 6 |
+
var esrecurse = require('esrecurse');
|
| 7 |
+
|
| 8 |
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
| 9 |
+
|
| 10 |
+
var estraverse__default = /*#__PURE__*/_interopDefaultLegacy(estraverse);
|
| 11 |
+
var esrecurse__default = /*#__PURE__*/_interopDefaultLegacy(esrecurse);
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @fileoverview Assertion utilities.
|
| 15 |
+
* @author Nicholas C. Zakas
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Throws an error if the given condition is not truthy.
|
| 20 |
+
* @param {boolean} condition The condition to check.
|
| 21 |
+
* @param {string} message The message to include with the error.
|
| 22 |
+
* @returns {void}
|
| 23 |
+
* @throws {Error} When the condition is not truthy.
|
| 24 |
+
*/
|
| 25 |
+
function assert(condition, message = "Assertion failed.") {
|
| 26 |
+
if (!condition) {
|
| 27 |
+
throw new Error(message);
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/*
|
| 32 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 33 |
+
|
| 34 |
+
Redistribution and use in source and binary forms, with or without
|
| 35 |
+
modification, are permitted provided that the following conditions are met:
|
| 36 |
+
|
| 37 |
+
* Redistributions of source code must retain the above copyright
|
| 38 |
+
notice, this list of conditions and the following disclaimer.
|
| 39 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 40 |
+
notice, this list of conditions and the following disclaimer in the
|
| 41 |
+
documentation and/or other materials provided with the distribution.
|
| 42 |
+
|
| 43 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 44 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 45 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 46 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 47 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 48 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 49 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 50 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 51 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 52 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
const READ = 0x1;
|
| 56 |
+
const WRITE = 0x2;
|
| 57 |
+
const RW = READ | WRITE;
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* A Reference represents a single occurrence of an identifier in code.
|
| 61 |
+
* @constructor Reference
|
| 62 |
+
*/
|
| 63 |
+
class Reference {
|
| 64 |
+
constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Identifier syntax node.
|
| 68 |
+
* @member {espreeIdentifier} Reference#identifier
|
| 69 |
+
*/
|
| 70 |
+
this.identifier = ident;
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Reference to the enclosing Scope.
|
| 74 |
+
* @member {Scope} Reference#from
|
| 75 |
+
*/
|
| 76 |
+
this.from = scope;
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Whether the reference comes from a dynamic scope (such as 'eval',
|
| 80 |
+
* 'with', etc.), and may be trapped by dynamic scopes.
|
| 81 |
+
* @member {boolean} Reference#tainted
|
| 82 |
+
*/
|
| 83 |
+
this.tainted = false;
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* The variable this reference is resolved with.
|
| 87 |
+
* @member {Variable} Reference#resolved
|
| 88 |
+
*/
|
| 89 |
+
this.resolved = null;
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* The read-write mode of the reference. (Value is one of {@link
|
| 93 |
+
* Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
|
| 94 |
+
* @member {number} Reference#flag
|
| 95 |
+
* @private
|
| 96 |
+
*/
|
| 97 |
+
this.flag = flag;
|
| 98 |
+
if (this.isWrite()) {
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* If reference is writeable, this is the tree being written to it.
|
| 102 |
+
* @member {espreeNode} Reference#writeExpr
|
| 103 |
+
*/
|
| 104 |
+
this.writeExpr = writeExpr;
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Whether the Reference might refer to a partial value of writeExpr.
|
| 108 |
+
* @member {boolean} Reference#partial
|
| 109 |
+
*/
|
| 110 |
+
this.partial = partial;
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* Whether the Reference is to write of initialization.
|
| 114 |
+
* @member {boolean} Reference#init
|
| 115 |
+
*/
|
| 116 |
+
this.init = init;
|
| 117 |
+
}
|
| 118 |
+
this.__maybeImplicitGlobal = maybeImplicitGlobal;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Whether the reference is static.
|
| 123 |
+
* @function Reference#isStatic
|
| 124 |
+
* @returns {boolean} static
|
| 125 |
+
*/
|
| 126 |
+
isStatic() {
|
| 127 |
+
return !this.tainted && this.resolved && this.resolved.scope.isStatic();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Whether the reference is writeable.
|
| 132 |
+
* @function Reference#isWrite
|
| 133 |
+
* @returns {boolean} write
|
| 134 |
+
*/
|
| 135 |
+
isWrite() {
|
| 136 |
+
return !!(this.flag & Reference.WRITE);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Whether the reference is readable.
|
| 141 |
+
* @function Reference#isRead
|
| 142 |
+
* @returns {boolean} read
|
| 143 |
+
*/
|
| 144 |
+
isRead() {
|
| 145 |
+
return !!(this.flag & Reference.READ);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Whether the reference is read-only.
|
| 150 |
+
* @function Reference#isReadOnly
|
| 151 |
+
* @returns {boolean} read only
|
| 152 |
+
*/
|
| 153 |
+
isReadOnly() {
|
| 154 |
+
return this.flag === Reference.READ;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Whether the reference is write-only.
|
| 159 |
+
* @function Reference#isWriteOnly
|
| 160 |
+
* @returns {boolean} write only
|
| 161 |
+
*/
|
| 162 |
+
isWriteOnly() {
|
| 163 |
+
return this.flag === Reference.WRITE;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* Whether the reference is read-write.
|
| 168 |
+
* @function Reference#isReadWrite
|
| 169 |
+
* @returns {boolean} read write
|
| 170 |
+
*/
|
| 171 |
+
isReadWrite() {
|
| 172 |
+
return this.flag === Reference.RW;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/**
|
| 177 |
+
* @constant Reference.READ
|
| 178 |
+
* @private
|
| 179 |
+
*/
|
| 180 |
+
Reference.READ = READ;
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* @constant Reference.WRITE
|
| 184 |
+
* @private
|
| 185 |
+
*/
|
| 186 |
+
Reference.WRITE = WRITE;
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* @constant Reference.RW
|
| 190 |
+
* @private
|
| 191 |
+
*/
|
| 192 |
+
Reference.RW = RW;
|
| 193 |
+
|
| 194 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 195 |
+
|
| 196 |
+
/*
|
| 197 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 198 |
+
|
| 199 |
+
Redistribution and use in source and binary forms, with or without
|
| 200 |
+
modification, are permitted provided that the following conditions are met:
|
| 201 |
+
|
| 202 |
+
* Redistributions of source code must retain the above copyright
|
| 203 |
+
notice, this list of conditions and the following disclaimer.
|
| 204 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 205 |
+
notice, this list of conditions and the following disclaimer in the
|
| 206 |
+
documentation and/or other materials provided with the distribution.
|
| 207 |
+
|
| 208 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 209 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 210 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 211 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 212 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 213 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 214 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 215 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 216 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 217 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 218 |
+
*/
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* A Variable represents a locally scoped identifier. These include arguments to
|
| 222 |
+
* functions.
|
| 223 |
+
* @constructor Variable
|
| 224 |
+
*/
|
| 225 |
+
class Variable {
|
| 226 |
+
constructor(name, scope) {
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* The variable name, as given in the source code.
|
| 230 |
+
* @member {string} Variable#name
|
| 231 |
+
*/
|
| 232 |
+
this.name = name;
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* List of defining occurrences of this variable (like in 'var ...'
|
| 236 |
+
* statements or as parameter), as AST nodes.
|
| 237 |
+
* @member {espree.Identifier[]} Variable#identifiers
|
| 238 |
+
*/
|
| 239 |
+
this.identifiers = [];
|
| 240 |
+
|
| 241 |
+
/**
|
| 242 |
+
* List of {@link Reference|references} of this variable (excluding parameter entries)
|
| 243 |
+
* in its defining scope and all nested scopes. For defining
|
| 244 |
+
* occurrences only see {@link Variable#defs}.
|
| 245 |
+
* @member {Reference[]} Variable#references
|
| 246 |
+
*/
|
| 247 |
+
this.references = [];
|
| 248 |
+
|
| 249 |
+
/**
|
| 250 |
+
* List of defining occurrences of this variable (like in 'var ...'
|
| 251 |
+
* statements or as parameter), as custom objects.
|
| 252 |
+
* @member {Definition[]} Variable#defs
|
| 253 |
+
*/
|
| 254 |
+
this.defs = [];
|
| 255 |
+
|
| 256 |
+
this.tainted = false;
|
| 257 |
+
|
| 258 |
+
/**
|
| 259 |
+
* Whether this is a stack variable.
|
| 260 |
+
* @member {boolean} Variable#stack
|
| 261 |
+
*/
|
| 262 |
+
this.stack = true;
|
| 263 |
+
|
| 264 |
+
/**
|
| 265 |
+
* Reference to the enclosing Scope.
|
| 266 |
+
* @member {Scope} Variable#scope
|
| 267 |
+
*/
|
| 268 |
+
this.scope = scope;
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
Variable.CatchClause = "CatchClause";
|
| 273 |
+
Variable.Parameter = "Parameter";
|
| 274 |
+
Variable.FunctionName = "FunctionName";
|
| 275 |
+
Variable.ClassName = "ClassName";
|
| 276 |
+
Variable.Variable = "Variable";
|
| 277 |
+
Variable.ImportBinding = "ImportBinding";
|
| 278 |
+
Variable.ImplicitGlobalVariable = "ImplicitGlobalVariable";
|
| 279 |
+
|
| 280 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 281 |
+
|
| 282 |
+
/*
|
| 283 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 284 |
+
|
| 285 |
+
Redistribution and use in source and binary forms, with or without
|
| 286 |
+
modification, are permitted provided that the following conditions are met:
|
| 287 |
+
|
| 288 |
+
* Redistributions of source code must retain the above copyright
|
| 289 |
+
notice, this list of conditions and the following disclaimer.
|
| 290 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 291 |
+
notice, this list of conditions and the following disclaimer in the
|
| 292 |
+
documentation and/or other materials provided with the distribution.
|
| 293 |
+
|
| 294 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 295 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 296 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 297 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 298 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 299 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 300 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 301 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 302 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 303 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 304 |
+
*/
|
| 305 |
+
|
| 306 |
+
/**
|
| 307 |
+
* @constructor Definition
|
| 308 |
+
*/
|
| 309 |
+
class Definition {
|
| 310 |
+
constructor(type, name, node, parent, index, kind) {
|
| 311 |
+
|
| 312 |
+
/**
|
| 313 |
+
* @member {string} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
|
| 314 |
+
*/
|
| 315 |
+
this.type = type;
|
| 316 |
+
|
| 317 |
+
/**
|
| 318 |
+
* @member {espree.Identifier} Definition#name - the identifier AST node of the occurrence.
|
| 319 |
+
*/
|
| 320 |
+
this.name = name;
|
| 321 |
+
|
| 322 |
+
/**
|
| 323 |
+
* @member {espree.Node} Definition#node - the enclosing node of the identifier.
|
| 324 |
+
*/
|
| 325 |
+
this.node = node;
|
| 326 |
+
|
| 327 |
+
/**
|
| 328 |
+
* @member {espree.Node?} Definition#parent - the enclosing statement node of the identifier.
|
| 329 |
+
*/
|
| 330 |
+
this.parent = parent;
|
| 331 |
+
|
| 332 |
+
/**
|
| 333 |
+
* @member {number?} Definition#index - the index in the declaration statement.
|
| 334 |
+
*/
|
| 335 |
+
this.index = index;
|
| 336 |
+
|
| 337 |
+
/**
|
| 338 |
+
* @member {string?} Definition#kind - the kind of the declaration statement.
|
| 339 |
+
*/
|
| 340 |
+
this.kind = kind;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
/**
|
| 345 |
+
* @constructor ParameterDefinition
|
| 346 |
+
*/
|
| 347 |
+
class ParameterDefinition extends Definition {
|
| 348 |
+
constructor(name, node, index, rest) {
|
| 349 |
+
super(Variable.Parameter, name, node, null, index, null);
|
| 350 |
+
|
| 351 |
+
/**
|
| 352 |
+
* Whether the parameter definition is a part of a rest parameter.
|
| 353 |
+
* @member {boolean} ParameterDefinition#rest
|
| 354 |
+
*/
|
| 355 |
+
this.rest = rest;
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 360 |
+
|
| 361 |
+
/*
|
| 362 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 363 |
+
|
| 364 |
+
Redistribution and use in source and binary forms, with or without
|
| 365 |
+
modification, are permitted provided that the following conditions are met:
|
| 366 |
+
|
| 367 |
+
* Redistributions of source code must retain the above copyright
|
| 368 |
+
notice, this list of conditions and the following disclaimer.
|
| 369 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 370 |
+
notice, this list of conditions and the following disclaimer in the
|
| 371 |
+
documentation and/or other materials provided with the distribution.
|
| 372 |
+
|
| 373 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 374 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 375 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 376 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 377 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 378 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 379 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 380 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 381 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 382 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 383 |
+
*/
|
| 384 |
+
|
| 385 |
+
const { Syntax: Syntax$2 } = estraverse__default["default"];
|
| 386 |
+
|
| 387 |
+
/**
|
| 388 |
+
* Test if scope is struct
|
| 389 |
+
* @param {Scope} scope scope
|
| 390 |
+
* @param {Block} block block
|
| 391 |
+
* @param {boolean} isMethodDefinition is method definition
|
| 392 |
+
* @returns {boolean} is strict scope
|
| 393 |
+
*/
|
| 394 |
+
function isStrictScope(scope, block, isMethodDefinition) {
|
| 395 |
+
let body;
|
| 396 |
+
|
| 397 |
+
// When upper scope is exists and strict, inner scope is also strict.
|
| 398 |
+
if (scope.upper && scope.upper.isStrict) {
|
| 399 |
+
return true;
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
if (isMethodDefinition) {
|
| 403 |
+
return true;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
if (scope.type === "class" || scope.type === "module") {
|
| 407 |
+
return true;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
if (scope.type === "block" || scope.type === "switch") {
|
| 411 |
+
return false;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
if (scope.type === "function") {
|
| 415 |
+
if (block.type === Syntax$2.ArrowFunctionExpression && block.body.type !== Syntax$2.BlockStatement) {
|
| 416 |
+
return false;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
if (block.type === Syntax$2.Program) {
|
| 420 |
+
body = block;
|
| 421 |
+
} else {
|
| 422 |
+
body = block.body;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
if (!body) {
|
| 426 |
+
return false;
|
| 427 |
+
}
|
| 428 |
+
} else if (scope.type === "global") {
|
| 429 |
+
body = block;
|
| 430 |
+
} else {
|
| 431 |
+
return false;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
// Search for a 'use strict' directive.
|
| 435 |
+
for (let i = 0, iz = body.body.length; i < iz; ++i) {
|
| 436 |
+
const stmt = body.body[i];
|
| 437 |
+
|
| 438 |
+
/*
|
| 439 |
+
* Check if the current statement is a directive.
|
| 440 |
+
* If it isn't, then we're past the directive prologue
|
| 441 |
+
* so stop the search because directives cannot
|
| 442 |
+
* appear after this point.
|
| 443 |
+
*
|
| 444 |
+
* Some parsers set `directive:null` on non-directive
|
| 445 |
+
* statements, so the `typeof` check is safer than
|
| 446 |
+
* checking for property existence.
|
| 447 |
+
*/
|
| 448 |
+
if (typeof stmt.directive !== "string") {
|
| 449 |
+
break;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
if (stmt.directive === "use strict") {
|
| 453 |
+
return true;
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
return false;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
/**
|
| 461 |
+
* Register scope
|
| 462 |
+
* @param {ScopeManager} scopeManager scope manager
|
| 463 |
+
* @param {Scope} scope scope
|
| 464 |
+
* @returns {void}
|
| 465 |
+
*/
|
| 466 |
+
function registerScope(scopeManager, scope) {
|
| 467 |
+
scopeManager.scopes.push(scope);
|
| 468 |
+
|
| 469 |
+
const scopes = scopeManager.__nodeToScope.get(scope.block);
|
| 470 |
+
|
| 471 |
+
if (scopes) {
|
| 472 |
+
scopes.push(scope);
|
| 473 |
+
} else {
|
| 474 |
+
scopeManager.__nodeToScope.set(scope.block, [scope]);
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
/**
|
| 479 |
+
* Should be statically
|
| 480 |
+
* @param {Object} def def
|
| 481 |
+
* @returns {boolean} should be statically
|
| 482 |
+
*/
|
| 483 |
+
function shouldBeStatically(def) {
|
| 484 |
+
return (
|
| 485 |
+
(def.type === Variable.ClassName) ||
|
| 486 |
+
(def.type === Variable.Variable && def.parent.kind !== "var")
|
| 487 |
+
);
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
/**
|
| 491 |
+
* @constructor Scope
|
| 492 |
+
*/
|
| 493 |
+
class Scope {
|
| 494 |
+
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {
|
| 495 |
+
|
| 496 |
+
/**
|
| 497 |
+
* One of "global", "module", "function", "function-expression-name", "block", "switch", "catch", "with", "for",
|
| 498 |
+
* "class", "class-field-initializer", "class-static-block".
|
| 499 |
+
* @member {string} Scope#type
|
| 500 |
+
*/
|
| 501 |
+
this.type = type;
|
| 502 |
+
|
| 503 |
+
/**
|
| 504 |
+
* The scoped {@link Variable}s of this scope, as <code>{ Variable.name
|
| 505 |
+
* : Variable }</code>.
|
| 506 |
+
* @member {Map} Scope#set
|
| 507 |
+
*/
|
| 508 |
+
this.set = new Map();
|
| 509 |
+
|
| 510 |
+
/**
|
| 511 |
+
* The tainted variables of this scope, as <code>{ Variable.name :
|
| 512 |
+
* boolean }</code>.
|
| 513 |
+
* @member {Map} Scope#taints
|
| 514 |
+
*/
|
| 515 |
+
this.taints = new Map();
|
| 516 |
+
|
| 517 |
+
/**
|
| 518 |
+
* Generally, through the lexical scoping of JS you can always know
|
| 519 |
+
* which variable an identifier in the source code refers to. There are
|
| 520 |
+
* a few exceptions to this rule. With 'global' and 'with' scopes you
|
| 521 |
+
* can only decide at runtime which variable a reference refers to.
|
| 522 |
+
* Moreover, if 'eval()' is used in a scope, it might introduce new
|
| 523 |
+
* bindings in this or its parent scopes.
|
| 524 |
+
* All those scopes are considered 'dynamic'.
|
| 525 |
+
* @member {boolean} Scope#dynamic
|
| 526 |
+
*/
|
| 527 |
+
this.dynamic = this.type === "global" || this.type === "with";
|
| 528 |
+
|
| 529 |
+
/**
|
| 530 |
+
* A reference to the scope-defining syntax node.
|
| 531 |
+
* @member {espree.Node} Scope#block
|
| 532 |
+
*/
|
| 533 |
+
this.block = block;
|
| 534 |
+
|
| 535 |
+
/**
|
| 536 |
+
* The {@link Reference|references} that are not resolved with this scope.
|
| 537 |
+
* @member {Reference[]} Scope#through
|
| 538 |
+
*/
|
| 539 |
+
this.through = [];
|
| 540 |
+
|
| 541 |
+
/**
|
| 542 |
+
* The scoped {@link Variable}s of this scope. In the case of a
|
| 543 |
+
* 'function' scope this includes the automatic argument <em>arguments</em> as
|
| 544 |
+
* its first element, as well as all further formal arguments.
|
| 545 |
+
* @member {Variable[]} Scope#variables
|
| 546 |
+
*/
|
| 547 |
+
this.variables = [];
|
| 548 |
+
|
| 549 |
+
/**
|
| 550 |
+
* Any variable {@link Reference|reference} found in this scope. This
|
| 551 |
+
* includes occurrences of local variables as well as variables from
|
| 552 |
+
* parent scopes (including the global scope). For local variables
|
| 553 |
+
* this also includes defining occurrences (like in a 'var' statement).
|
| 554 |
+
* In a 'function' scope this does not include the occurrences of the
|
| 555 |
+
* formal parameter in the parameter list.
|
| 556 |
+
* @member {Reference[]} Scope#references
|
| 557 |
+
*/
|
| 558 |
+
this.references = [];
|
| 559 |
+
|
| 560 |
+
/**
|
| 561 |
+
* For 'global' and 'function' scopes, this is a self-reference. For
|
| 562 |
+
* other scope types this is the <em>variableScope</em> value of the
|
| 563 |
+
* parent scope.
|
| 564 |
+
* @member {Scope} Scope#variableScope
|
| 565 |
+
*/
|
| 566 |
+
this.variableScope =
|
| 567 |
+
this.type === "global" ||
|
| 568 |
+
this.type === "module" ||
|
| 569 |
+
this.type === "function" ||
|
| 570 |
+
this.type === "class-field-initializer" ||
|
| 571 |
+
this.type === "class-static-block"
|
| 572 |
+
? this
|
| 573 |
+
: upperScope.variableScope;
|
| 574 |
+
|
| 575 |
+
/**
|
| 576 |
+
* Whether this scope is created by a FunctionExpression.
|
| 577 |
+
* @member {boolean} Scope#functionExpressionScope
|
| 578 |
+
*/
|
| 579 |
+
this.functionExpressionScope = false;
|
| 580 |
+
|
| 581 |
+
/**
|
| 582 |
+
* Whether this is a scope that contains an 'eval()' invocation.
|
| 583 |
+
* @member {boolean} Scope#directCallToEvalScope
|
| 584 |
+
*/
|
| 585 |
+
this.directCallToEvalScope = false;
|
| 586 |
+
|
| 587 |
+
/**
|
| 588 |
+
* @member {boolean} Scope#thisFound
|
| 589 |
+
*/
|
| 590 |
+
this.thisFound = false;
|
| 591 |
+
|
| 592 |
+
this.__left = [];
|
| 593 |
+
|
| 594 |
+
/**
|
| 595 |
+
* Reference to the parent {@link Scope|scope}.
|
| 596 |
+
* @member {Scope} Scope#upper
|
| 597 |
+
*/
|
| 598 |
+
this.upper = upperScope;
|
| 599 |
+
|
| 600 |
+
/**
|
| 601 |
+
* Whether 'use strict' is in effect in this scope.
|
| 602 |
+
* @member {boolean} Scope#isStrict
|
| 603 |
+
*/
|
| 604 |
+
this.isStrict = scopeManager.isStrictModeSupported()
|
| 605 |
+
? isStrictScope(this, block, isMethodDefinition)
|
| 606 |
+
: false;
|
| 607 |
+
|
| 608 |
+
/**
|
| 609 |
+
* List of nested {@link Scope}s.
|
| 610 |
+
* @member {Scope[]} Scope#childScopes
|
| 611 |
+
*/
|
| 612 |
+
this.childScopes = [];
|
| 613 |
+
if (this.upper) {
|
| 614 |
+
this.upper.childScopes.push(this);
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
this.__declaredVariables = scopeManager.__declaredVariables;
|
| 618 |
+
|
| 619 |
+
registerScope(scopeManager, this);
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
__shouldStaticallyClose(scopeManager) {
|
| 623 |
+
return (!this.dynamic || scopeManager.__isOptimistic());
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
__shouldStaticallyCloseForGlobal(ref) {
|
| 627 |
+
|
| 628 |
+
// On global scope, let/const/class declarations should be resolved statically.
|
| 629 |
+
const name = ref.identifier.name;
|
| 630 |
+
|
| 631 |
+
if (!this.set.has(name)) {
|
| 632 |
+
return false;
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
const variable = this.set.get(name);
|
| 636 |
+
const defs = variable.defs;
|
| 637 |
+
|
| 638 |
+
return defs.length > 0 && defs.every(shouldBeStatically);
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
__staticCloseRef(ref) {
|
| 642 |
+
if (!this.__resolve(ref)) {
|
| 643 |
+
this.__delegateToUpperScope(ref);
|
| 644 |
+
}
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
__dynamicCloseRef(ref) {
|
| 648 |
+
|
| 649 |
+
// notify all names are through to global
|
| 650 |
+
let current = this;
|
| 651 |
+
|
| 652 |
+
do {
|
| 653 |
+
current.through.push(ref);
|
| 654 |
+
current = current.upper;
|
| 655 |
+
} while (current);
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
__globalCloseRef(ref) {
|
| 659 |
+
|
| 660 |
+
// let/const/class declarations should be resolved statically.
|
| 661 |
+
// others should be resolved dynamically.
|
| 662 |
+
if (this.__shouldStaticallyCloseForGlobal(ref)) {
|
| 663 |
+
this.__staticCloseRef(ref);
|
| 664 |
+
} else {
|
| 665 |
+
this.__dynamicCloseRef(ref);
|
| 666 |
+
}
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
__close(scopeManager) {
|
| 670 |
+
let closeRef;
|
| 671 |
+
|
| 672 |
+
if (this.__shouldStaticallyClose(scopeManager)) {
|
| 673 |
+
closeRef = this.__staticCloseRef;
|
| 674 |
+
} else if (this.type !== "global") {
|
| 675 |
+
closeRef = this.__dynamicCloseRef;
|
| 676 |
+
} else {
|
| 677 |
+
closeRef = this.__globalCloseRef;
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
// Try Resolving all references in this scope.
|
| 681 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 682 |
+
const ref = this.__left[i];
|
| 683 |
+
|
| 684 |
+
closeRef.call(this, ref);
|
| 685 |
+
}
|
| 686 |
+
this.__left = null;
|
| 687 |
+
|
| 688 |
+
return this.upper;
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
// To override by function scopes.
|
| 692 |
+
// References in default parameters isn't resolved to variables which are in their function body.
|
| 693 |
+
__isValidResolution(ref, variable) { // eslint-disable-line class-methods-use-this, no-unused-vars -- Desired as instance method with signature
|
| 694 |
+
return true;
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
__resolve(ref) {
|
| 698 |
+
const name = ref.identifier.name;
|
| 699 |
+
|
| 700 |
+
if (!this.set.has(name)) {
|
| 701 |
+
return false;
|
| 702 |
+
}
|
| 703 |
+
const variable = this.set.get(name);
|
| 704 |
+
|
| 705 |
+
if (!this.__isValidResolution(ref, variable)) {
|
| 706 |
+
return false;
|
| 707 |
+
}
|
| 708 |
+
variable.references.push(ref);
|
| 709 |
+
variable.stack = variable.stack && ref.from.variableScope === this.variableScope;
|
| 710 |
+
if (ref.tainted) {
|
| 711 |
+
variable.tainted = true;
|
| 712 |
+
this.taints.set(variable.name, true);
|
| 713 |
+
}
|
| 714 |
+
ref.resolved = variable;
|
| 715 |
+
|
| 716 |
+
return true;
|
| 717 |
+
}
|
| 718 |
+
|
| 719 |
+
__delegateToUpperScope(ref) {
|
| 720 |
+
if (this.upper) {
|
| 721 |
+
this.upper.__left.push(ref);
|
| 722 |
+
}
|
| 723 |
+
this.through.push(ref);
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
__addDeclaredVariablesOfNode(variable, node) {
|
| 727 |
+
if (node === null || node === void 0) {
|
| 728 |
+
return;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
let variables = this.__declaredVariables.get(node);
|
| 732 |
+
|
| 733 |
+
if (variables === null || variables === void 0) {
|
| 734 |
+
variables = [];
|
| 735 |
+
this.__declaredVariables.set(node, variables);
|
| 736 |
+
}
|
| 737 |
+
if (!variables.includes(variable)) {
|
| 738 |
+
variables.push(variable);
|
| 739 |
+
}
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
__defineGeneric(name, set, variables, node, def) {
|
| 743 |
+
let variable;
|
| 744 |
+
|
| 745 |
+
variable = set.get(name);
|
| 746 |
+
if (!variable) {
|
| 747 |
+
variable = new Variable(name, this);
|
| 748 |
+
set.set(name, variable);
|
| 749 |
+
variables.push(variable);
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
if (def) {
|
| 753 |
+
variable.defs.push(def);
|
| 754 |
+
this.__addDeclaredVariablesOfNode(variable, def.node);
|
| 755 |
+
this.__addDeclaredVariablesOfNode(variable, def.parent);
|
| 756 |
+
}
|
| 757 |
+
if (node) {
|
| 758 |
+
variable.identifiers.push(node);
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
__define(node, def) {
|
| 763 |
+
if (node && node.type === Syntax$2.Identifier) {
|
| 764 |
+
this.__defineGeneric(
|
| 765 |
+
node.name,
|
| 766 |
+
this.set,
|
| 767 |
+
this.variables,
|
| 768 |
+
node,
|
| 769 |
+
def
|
| 770 |
+
);
|
| 771 |
+
}
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
__referencing(node, assign, writeExpr, maybeImplicitGlobal, partial, init) {
|
| 775 |
+
|
| 776 |
+
// because Array element may be null
|
| 777 |
+
if (!node || (node.type !== Syntax$2.Identifier && node.type !== "JSXIdentifier")) {
|
| 778 |
+
return;
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
// Specially handle like `this`.
|
| 782 |
+
if (node.name === "super") {
|
| 783 |
+
return;
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
const ref = new Reference(node, this, assign || Reference.READ, writeExpr, maybeImplicitGlobal, !!partial, !!init);
|
| 787 |
+
|
| 788 |
+
this.references.push(ref);
|
| 789 |
+
this.__left.push(ref);
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
__detectEval() {
|
| 793 |
+
let current = this;
|
| 794 |
+
|
| 795 |
+
this.directCallToEvalScope = true;
|
| 796 |
+
do {
|
| 797 |
+
current.dynamic = true;
|
| 798 |
+
current = current.upper;
|
| 799 |
+
} while (current);
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
__detectThis() {
|
| 803 |
+
this.thisFound = true;
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
__isClosed() {
|
| 807 |
+
return this.__left === null;
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
/**
|
| 811 |
+
* returns resolved {Reference}
|
| 812 |
+
* @function Scope#resolve
|
| 813 |
+
* @param {Espree.Identifier} ident identifier to be resolved.
|
| 814 |
+
* @returns {Reference} reference
|
| 815 |
+
*/
|
| 816 |
+
resolve(ident) {
|
| 817 |
+
let ref, i, iz;
|
| 818 |
+
|
| 819 |
+
assert(this.__isClosed(), "Scope should be closed.");
|
| 820 |
+
assert(ident.type === Syntax$2.Identifier, "Target should be identifier.");
|
| 821 |
+
for (i = 0, iz = this.references.length; i < iz; ++i) {
|
| 822 |
+
ref = this.references[i];
|
| 823 |
+
if (ref.identifier === ident) {
|
| 824 |
+
return ref;
|
| 825 |
+
}
|
| 826 |
+
}
|
| 827 |
+
return null;
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
/**
|
| 831 |
+
* returns this scope is static
|
| 832 |
+
* @function Scope#isStatic
|
| 833 |
+
* @returns {boolean} static
|
| 834 |
+
*/
|
| 835 |
+
isStatic() {
|
| 836 |
+
return !this.dynamic;
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
/**
|
| 840 |
+
* returns this scope has materialized arguments
|
| 841 |
+
* @function Scope#isArgumentsMaterialized
|
| 842 |
+
* @returns {boolean} arguemnts materialized
|
| 843 |
+
*/
|
| 844 |
+
isArgumentsMaterialized() { // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 845 |
+
return true;
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
/**
|
| 849 |
+
* returns this scope has materialized `this` reference
|
| 850 |
+
* @function Scope#isThisMaterialized
|
| 851 |
+
* @returns {boolean} this materialized
|
| 852 |
+
*/
|
| 853 |
+
isThisMaterialized() { // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 854 |
+
return true;
|
| 855 |
+
}
|
| 856 |
+
|
| 857 |
+
isUsedName(name) {
|
| 858 |
+
if (this.set.has(name)) {
|
| 859 |
+
return true;
|
| 860 |
+
}
|
| 861 |
+
for (let i = 0, iz = this.through.length; i < iz; ++i) {
|
| 862 |
+
if (this.through[i].identifier.name === name) {
|
| 863 |
+
return true;
|
| 864 |
+
}
|
| 865 |
+
}
|
| 866 |
+
return false;
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
/**
|
| 871 |
+
* Global scope.
|
| 872 |
+
*/
|
| 873 |
+
class GlobalScope extends Scope {
|
| 874 |
+
constructor(scopeManager, block) {
|
| 875 |
+
super(scopeManager, "global", null, block, false);
|
| 876 |
+
this.implicit = {
|
| 877 |
+
set: new Map(),
|
| 878 |
+
variables: [],
|
| 879 |
+
|
| 880 |
+
/**
|
| 881 |
+
* List of {@link Reference}s that are left to be resolved (i.e. which
|
| 882 |
+
* need to be linked to the variable they refer to).
|
| 883 |
+
* @member {Reference[]} Scope#implicit#left
|
| 884 |
+
*/
|
| 885 |
+
left: []
|
| 886 |
+
};
|
| 887 |
+
}
|
| 888 |
+
|
| 889 |
+
__close(scopeManager) {
|
| 890 |
+
const implicit = [];
|
| 891 |
+
|
| 892 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 893 |
+
const ref = this.__left[i];
|
| 894 |
+
|
| 895 |
+
if (ref.__maybeImplicitGlobal && !this.set.has(ref.identifier.name)) {
|
| 896 |
+
implicit.push(ref.__maybeImplicitGlobal);
|
| 897 |
+
}
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
// create an implicit global variable from assignment expression
|
| 901 |
+
for (let i = 0, iz = implicit.length; i < iz; ++i) {
|
| 902 |
+
const info = implicit[i];
|
| 903 |
+
|
| 904 |
+
this.__defineImplicit(info.pattern,
|
| 905 |
+
new Definition(
|
| 906 |
+
Variable.ImplicitGlobalVariable,
|
| 907 |
+
info.pattern,
|
| 908 |
+
info.node,
|
| 909 |
+
null,
|
| 910 |
+
null,
|
| 911 |
+
null
|
| 912 |
+
));
|
| 913 |
+
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
this.implicit.left = this.__left;
|
| 917 |
+
|
| 918 |
+
return super.__close(scopeManager);
|
| 919 |
+
}
|
| 920 |
+
|
| 921 |
+
__defineImplicit(node, def) {
|
| 922 |
+
if (node && node.type === Syntax$2.Identifier) {
|
| 923 |
+
this.__defineGeneric(
|
| 924 |
+
node.name,
|
| 925 |
+
this.implicit.set,
|
| 926 |
+
this.implicit.variables,
|
| 927 |
+
node,
|
| 928 |
+
def
|
| 929 |
+
);
|
| 930 |
+
}
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
/**
|
| 935 |
+
* Module scope.
|
| 936 |
+
*/
|
| 937 |
+
class ModuleScope extends Scope {
|
| 938 |
+
constructor(scopeManager, upperScope, block) {
|
| 939 |
+
super(scopeManager, "module", upperScope, block, false);
|
| 940 |
+
}
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
/**
|
| 944 |
+
* Function expression name scope.
|
| 945 |
+
*/
|
| 946 |
+
class FunctionExpressionNameScope extends Scope {
|
| 947 |
+
constructor(scopeManager, upperScope, block) {
|
| 948 |
+
super(scopeManager, "function-expression-name", upperScope, block, false);
|
| 949 |
+
this.__define(block.id,
|
| 950 |
+
new Definition(
|
| 951 |
+
Variable.FunctionName,
|
| 952 |
+
block.id,
|
| 953 |
+
block,
|
| 954 |
+
null,
|
| 955 |
+
null,
|
| 956 |
+
null
|
| 957 |
+
));
|
| 958 |
+
this.functionExpressionScope = true;
|
| 959 |
+
}
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
/**
|
| 963 |
+
* Catch scope.
|
| 964 |
+
*/
|
| 965 |
+
class CatchScope extends Scope {
|
| 966 |
+
constructor(scopeManager, upperScope, block) {
|
| 967 |
+
super(scopeManager, "catch", upperScope, block, false);
|
| 968 |
+
}
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
/**
|
| 972 |
+
* With statement scope.
|
| 973 |
+
*/
|
| 974 |
+
class WithScope extends Scope {
|
| 975 |
+
constructor(scopeManager, upperScope, block) {
|
| 976 |
+
super(scopeManager, "with", upperScope, block, false);
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
__close(scopeManager) {
|
| 980 |
+
if (this.__shouldStaticallyClose(scopeManager)) {
|
| 981 |
+
return super.__close(scopeManager);
|
| 982 |
+
}
|
| 983 |
+
|
| 984 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 985 |
+
const ref = this.__left[i];
|
| 986 |
+
|
| 987 |
+
ref.tainted = true;
|
| 988 |
+
this.__delegateToUpperScope(ref);
|
| 989 |
+
}
|
| 990 |
+
this.__left = null;
|
| 991 |
+
|
| 992 |
+
return this.upper;
|
| 993 |
+
}
|
| 994 |
+
}
|
| 995 |
+
|
| 996 |
+
/**
|
| 997 |
+
* Block scope.
|
| 998 |
+
*/
|
| 999 |
+
class BlockScope extends Scope {
|
| 1000 |
+
constructor(scopeManager, upperScope, block) {
|
| 1001 |
+
super(scopeManager, "block", upperScope, block, false);
|
| 1002 |
+
}
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
/**
|
| 1006 |
+
* Switch scope.
|
| 1007 |
+
*/
|
| 1008 |
+
class SwitchScope extends Scope {
|
| 1009 |
+
constructor(scopeManager, upperScope, block) {
|
| 1010 |
+
super(scopeManager, "switch", upperScope, block, false);
|
| 1011 |
+
}
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
/**
|
| 1015 |
+
* Function scope.
|
| 1016 |
+
*/
|
| 1017 |
+
class FunctionScope extends Scope {
|
| 1018 |
+
constructor(scopeManager, upperScope, block, isMethodDefinition) {
|
| 1019 |
+
super(scopeManager, "function", upperScope, block, isMethodDefinition);
|
| 1020 |
+
|
| 1021 |
+
// section 9.2.13, FunctionDeclarationInstantiation.
|
| 1022 |
+
// NOTE Arrow functions never have an arguments objects.
|
| 1023 |
+
if (this.block.type !== Syntax$2.ArrowFunctionExpression) {
|
| 1024 |
+
this.__defineArguments();
|
| 1025 |
+
}
|
| 1026 |
+
}
|
| 1027 |
+
|
| 1028 |
+
isArgumentsMaterialized() {
|
| 1029 |
+
|
| 1030 |
+
// TODO(Constellation)
|
| 1031 |
+
// We can more aggressive on this condition like this.
|
| 1032 |
+
//
|
| 1033 |
+
// function t() {
|
| 1034 |
+
// // arguments of t is always hidden.
|
| 1035 |
+
// function arguments() {
|
| 1036 |
+
// }
|
| 1037 |
+
// }
|
| 1038 |
+
if (this.block.type === Syntax$2.ArrowFunctionExpression) {
|
| 1039 |
+
return false;
|
| 1040 |
+
}
|
| 1041 |
+
|
| 1042 |
+
if (!this.isStatic()) {
|
| 1043 |
+
return true;
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
const variable = this.set.get("arguments");
|
| 1047 |
+
|
| 1048 |
+
assert(variable, "Always have arguments variable.");
|
| 1049 |
+
return variable.tainted || variable.references.length !== 0;
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
isThisMaterialized() {
|
| 1053 |
+
if (!this.isStatic()) {
|
| 1054 |
+
return true;
|
| 1055 |
+
}
|
| 1056 |
+
return this.thisFound;
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
__defineArguments() {
|
| 1060 |
+
this.__defineGeneric(
|
| 1061 |
+
"arguments",
|
| 1062 |
+
this.set,
|
| 1063 |
+
this.variables,
|
| 1064 |
+
null,
|
| 1065 |
+
null
|
| 1066 |
+
);
|
| 1067 |
+
this.taints.set("arguments", true);
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
// References in default parameters isn't resolved to variables which are in their function body.
|
| 1071 |
+
// const x = 1
|
| 1072 |
+
// function f(a = x) { // This `x` is resolved to the `x` in the outer scope.
|
| 1073 |
+
// const x = 2
|
| 1074 |
+
// console.log(a)
|
| 1075 |
+
// }
|
| 1076 |
+
__isValidResolution(ref, variable) {
|
| 1077 |
+
|
| 1078 |
+
// If `options.nodejsScope` is true, `this.block` becomes a Program node.
|
| 1079 |
+
if (this.block.type === "Program") {
|
| 1080 |
+
return true;
|
| 1081 |
+
}
|
| 1082 |
+
|
| 1083 |
+
const bodyStart = this.block.body.range[0];
|
| 1084 |
+
|
| 1085 |
+
// It's invalid resolution in the following case:
|
| 1086 |
+
return !(
|
| 1087 |
+
variable.scope === this &&
|
| 1088 |
+
ref.identifier.range[0] < bodyStart && // the reference is in the parameter part.
|
| 1089 |
+
variable.defs.every(d => d.name.range[0] >= bodyStart) // the variable is in the body.
|
| 1090 |
+
);
|
| 1091 |
+
}
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
/**
|
| 1095 |
+
* Scope of for, for-in, and for-of statements.
|
| 1096 |
+
*/
|
| 1097 |
+
class ForScope extends Scope {
|
| 1098 |
+
constructor(scopeManager, upperScope, block) {
|
| 1099 |
+
super(scopeManager, "for", upperScope, block, false);
|
| 1100 |
+
}
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
/**
|
| 1104 |
+
* Class scope.
|
| 1105 |
+
*/
|
| 1106 |
+
class ClassScope extends Scope {
|
| 1107 |
+
constructor(scopeManager, upperScope, block) {
|
| 1108 |
+
super(scopeManager, "class", upperScope, block, false);
|
| 1109 |
+
}
|
| 1110 |
+
}
|
| 1111 |
+
|
| 1112 |
+
/**
|
| 1113 |
+
* Class field initializer scope.
|
| 1114 |
+
*/
|
| 1115 |
+
class ClassFieldInitializerScope extends Scope {
|
| 1116 |
+
constructor(scopeManager, upperScope, block) {
|
| 1117 |
+
super(scopeManager, "class-field-initializer", upperScope, block, true);
|
| 1118 |
+
}
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
/**
|
| 1122 |
+
* Class static block scope.
|
| 1123 |
+
*/
|
| 1124 |
+
class ClassStaticBlockScope extends Scope {
|
| 1125 |
+
constructor(scopeManager, upperScope, block) {
|
| 1126 |
+
super(scopeManager, "class-static-block", upperScope, block, true);
|
| 1127 |
+
}
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 1131 |
+
|
| 1132 |
+
/*
|
| 1133 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 1134 |
+
|
| 1135 |
+
Redistribution and use in source and binary forms, with or without
|
| 1136 |
+
modification, are permitted provided that the following conditions are met:
|
| 1137 |
+
|
| 1138 |
+
* Redistributions of source code must retain the above copyright
|
| 1139 |
+
notice, this list of conditions and the following disclaimer.
|
| 1140 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 1141 |
+
notice, this list of conditions and the following disclaimer in the
|
| 1142 |
+
documentation and/or other materials provided with the distribution.
|
| 1143 |
+
|
| 1144 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 1145 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 1146 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 1147 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 1148 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 1149 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 1150 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 1151 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 1152 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 1153 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 1154 |
+
*/
|
| 1155 |
+
|
| 1156 |
+
/**
|
| 1157 |
+
* @constructor ScopeManager
|
| 1158 |
+
*/
|
| 1159 |
+
class ScopeManager {
|
| 1160 |
+
constructor(options) {
|
| 1161 |
+
this.scopes = [];
|
| 1162 |
+
this.globalScope = null;
|
| 1163 |
+
this.__nodeToScope = new WeakMap();
|
| 1164 |
+
this.__currentScope = null;
|
| 1165 |
+
this.__options = options;
|
| 1166 |
+
this.__declaredVariables = new WeakMap();
|
| 1167 |
+
}
|
| 1168 |
+
|
| 1169 |
+
__isOptimistic() {
|
| 1170 |
+
return this.__options.optimistic;
|
| 1171 |
+
}
|
| 1172 |
+
|
| 1173 |
+
__ignoreEval() {
|
| 1174 |
+
return this.__options.ignoreEval;
|
| 1175 |
+
}
|
| 1176 |
+
|
| 1177 |
+
__isJSXEnabled() {
|
| 1178 |
+
return this.__options.jsx === true;
|
| 1179 |
+
}
|
| 1180 |
+
|
| 1181 |
+
isGlobalReturn() {
|
| 1182 |
+
return this.__options.nodejsScope || this.__options.sourceType === "commonjs";
|
| 1183 |
+
}
|
| 1184 |
+
|
| 1185 |
+
isModule() {
|
| 1186 |
+
return this.__options.sourceType === "module";
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
isImpliedStrict() {
|
| 1190 |
+
return this.__options.impliedStrict;
|
| 1191 |
+
}
|
| 1192 |
+
|
| 1193 |
+
isStrictModeSupported() {
|
| 1194 |
+
return this.__options.ecmaVersion >= 5;
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
// Returns appropriate scope for this node.
|
| 1198 |
+
__get(node) {
|
| 1199 |
+
return this.__nodeToScope.get(node);
|
| 1200 |
+
}
|
| 1201 |
+
|
| 1202 |
+
/**
|
| 1203 |
+
* Get variables that are declared by the node.
|
| 1204 |
+
*
|
| 1205 |
+
* "are declared by the node" means the node is same as `Variable.defs[].node` or `Variable.defs[].parent`.
|
| 1206 |
+
* If the node declares nothing, this method returns an empty array.
|
| 1207 |
+
* CAUTION: This API is experimental. See https://github.com/estools/escope/pull/69 for more details.
|
| 1208 |
+
* @param {Espree.Node} node a node to get.
|
| 1209 |
+
* @returns {Variable[]} variables that declared by the node.
|
| 1210 |
+
*/
|
| 1211 |
+
getDeclaredVariables(node) {
|
| 1212 |
+
return this.__declaredVariables.get(node) || [];
|
| 1213 |
+
}
|
| 1214 |
+
|
| 1215 |
+
/**
|
| 1216 |
+
* acquire scope from node.
|
| 1217 |
+
* @function ScopeManager#acquire
|
| 1218 |
+
* @param {Espree.Node} node node for the acquired scope.
|
| 1219 |
+
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
|
| 1220 |
+
* @returns {Scope?} Scope from node
|
| 1221 |
+
*/
|
| 1222 |
+
acquire(node, inner) {
|
| 1223 |
+
|
| 1224 |
+
/**
|
| 1225 |
+
* predicate
|
| 1226 |
+
* @param {Scope} testScope scope to test
|
| 1227 |
+
* @returns {boolean} predicate
|
| 1228 |
+
*/
|
| 1229 |
+
function predicate(testScope) {
|
| 1230 |
+
if (testScope.type === "function" && testScope.functionExpressionScope) {
|
| 1231 |
+
return false;
|
| 1232 |
+
}
|
| 1233 |
+
return true;
|
| 1234 |
+
}
|
| 1235 |
+
|
| 1236 |
+
const scopes = this.__get(node);
|
| 1237 |
+
|
| 1238 |
+
if (!scopes || scopes.length === 0) {
|
| 1239 |
+
return null;
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
// Heuristic selection from all scopes.
|
| 1243 |
+
// If you would like to get all scopes, please use ScopeManager#acquireAll.
|
| 1244 |
+
if (scopes.length === 1) {
|
| 1245 |
+
return scopes[0];
|
| 1246 |
+
}
|
| 1247 |
+
|
| 1248 |
+
if (inner) {
|
| 1249 |
+
for (let i = scopes.length - 1; i >= 0; --i) {
|
| 1250 |
+
const scope = scopes[i];
|
| 1251 |
+
|
| 1252 |
+
if (predicate(scope)) {
|
| 1253 |
+
return scope;
|
| 1254 |
+
}
|
| 1255 |
+
}
|
| 1256 |
+
} else {
|
| 1257 |
+
for (let i = 0, iz = scopes.length; i < iz; ++i) {
|
| 1258 |
+
const scope = scopes[i];
|
| 1259 |
+
|
| 1260 |
+
if (predicate(scope)) {
|
| 1261 |
+
return scope;
|
| 1262 |
+
}
|
| 1263 |
+
}
|
| 1264 |
+
}
|
| 1265 |
+
|
| 1266 |
+
return null;
|
| 1267 |
+
}
|
| 1268 |
+
|
| 1269 |
+
/**
|
| 1270 |
+
* acquire all scopes from node.
|
| 1271 |
+
* @function ScopeManager#acquireAll
|
| 1272 |
+
* @param {Espree.Node} node node for the acquired scope.
|
| 1273 |
+
* @returns {Scopes?} Scope array
|
| 1274 |
+
*/
|
| 1275 |
+
acquireAll(node) {
|
| 1276 |
+
return this.__get(node);
|
| 1277 |
+
}
|
| 1278 |
+
|
| 1279 |
+
/**
|
| 1280 |
+
* release the node.
|
| 1281 |
+
* @function ScopeManager#release
|
| 1282 |
+
* @param {Espree.Node} node releasing node.
|
| 1283 |
+
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
|
| 1284 |
+
* @returns {Scope?} upper scope for the node.
|
| 1285 |
+
*/
|
| 1286 |
+
release(node, inner) {
|
| 1287 |
+
const scopes = this.__get(node);
|
| 1288 |
+
|
| 1289 |
+
if (scopes && scopes.length) {
|
| 1290 |
+
const scope = scopes[0].upper;
|
| 1291 |
+
|
| 1292 |
+
if (!scope) {
|
| 1293 |
+
return null;
|
| 1294 |
+
}
|
| 1295 |
+
return this.acquire(scope.block, inner);
|
| 1296 |
+
}
|
| 1297 |
+
return null;
|
| 1298 |
+
}
|
| 1299 |
+
|
| 1300 |
+
attach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 1301 |
+
|
| 1302 |
+
detach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 1303 |
+
|
| 1304 |
+
__nestScope(scope) {
|
| 1305 |
+
if (scope instanceof GlobalScope) {
|
| 1306 |
+
assert(this.__currentScope === null);
|
| 1307 |
+
this.globalScope = scope;
|
| 1308 |
+
}
|
| 1309 |
+
this.__currentScope = scope;
|
| 1310 |
+
return scope;
|
| 1311 |
+
}
|
| 1312 |
+
|
| 1313 |
+
__nestGlobalScope(node) {
|
| 1314 |
+
return this.__nestScope(new GlobalScope(this, node));
|
| 1315 |
+
}
|
| 1316 |
+
|
| 1317 |
+
__nestBlockScope(node) {
|
| 1318 |
+
return this.__nestScope(new BlockScope(this, this.__currentScope, node));
|
| 1319 |
+
}
|
| 1320 |
+
|
| 1321 |
+
__nestFunctionScope(node, isMethodDefinition) {
|
| 1322 |
+
return this.__nestScope(new FunctionScope(this, this.__currentScope, node, isMethodDefinition));
|
| 1323 |
+
}
|
| 1324 |
+
|
| 1325 |
+
__nestForScope(node) {
|
| 1326 |
+
return this.__nestScope(new ForScope(this, this.__currentScope, node));
|
| 1327 |
+
}
|
| 1328 |
+
|
| 1329 |
+
__nestCatchScope(node) {
|
| 1330 |
+
return this.__nestScope(new CatchScope(this, this.__currentScope, node));
|
| 1331 |
+
}
|
| 1332 |
+
|
| 1333 |
+
__nestWithScope(node) {
|
| 1334 |
+
return this.__nestScope(new WithScope(this, this.__currentScope, node));
|
| 1335 |
+
}
|
| 1336 |
+
|
| 1337 |
+
__nestClassScope(node) {
|
| 1338 |
+
return this.__nestScope(new ClassScope(this, this.__currentScope, node));
|
| 1339 |
+
}
|
| 1340 |
+
|
| 1341 |
+
__nestClassFieldInitializerScope(node) {
|
| 1342 |
+
return this.__nestScope(new ClassFieldInitializerScope(this, this.__currentScope, node));
|
| 1343 |
+
}
|
| 1344 |
+
|
| 1345 |
+
__nestClassStaticBlockScope(node) {
|
| 1346 |
+
return this.__nestScope(new ClassStaticBlockScope(this, this.__currentScope, node));
|
| 1347 |
+
}
|
| 1348 |
+
|
| 1349 |
+
__nestSwitchScope(node) {
|
| 1350 |
+
return this.__nestScope(new SwitchScope(this, this.__currentScope, node));
|
| 1351 |
+
}
|
| 1352 |
+
|
| 1353 |
+
__nestModuleScope(node) {
|
| 1354 |
+
return this.__nestScope(new ModuleScope(this, this.__currentScope, node));
|
| 1355 |
+
}
|
| 1356 |
+
|
| 1357 |
+
__nestFunctionExpressionNameScope(node) {
|
| 1358 |
+
return this.__nestScope(new FunctionExpressionNameScope(this, this.__currentScope, node));
|
| 1359 |
+
}
|
| 1360 |
+
|
| 1361 |
+
__isES6() {
|
| 1362 |
+
return this.__options.ecmaVersion >= 6;
|
| 1363 |
+
}
|
| 1364 |
+
}
|
| 1365 |
+
|
| 1366 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 1367 |
+
|
| 1368 |
+
/*
|
| 1369 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 1370 |
+
|
| 1371 |
+
Redistribution and use in source and binary forms, with or without
|
| 1372 |
+
modification, are permitted provided that the following conditions are met:
|
| 1373 |
+
|
| 1374 |
+
* Redistributions of source code must retain the above copyright
|
| 1375 |
+
notice, this list of conditions and the following disclaimer.
|
| 1376 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 1377 |
+
notice, this list of conditions and the following disclaimer in the
|
| 1378 |
+
documentation and/or other materials provided with the distribution.
|
| 1379 |
+
|
| 1380 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 1381 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 1382 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 1383 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 1384 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 1385 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 1386 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 1387 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 1388 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 1389 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 1390 |
+
*/
|
| 1391 |
+
|
| 1392 |
+
const { Syntax: Syntax$1 } = estraverse__default["default"];
|
| 1393 |
+
|
| 1394 |
+
/**
|
| 1395 |
+
* Get last array element
|
| 1396 |
+
* @param {Array} xs array
|
| 1397 |
+
* @returns {any} Last elment
|
| 1398 |
+
*/
|
| 1399 |
+
function getLast(xs) {
|
| 1400 |
+
return xs.at(-1) || null;
|
| 1401 |
+
}
|
| 1402 |
+
|
| 1403 |
+
/**
|
| 1404 |
+
* Visitor for destructuring patterns.
|
| 1405 |
+
*/
|
| 1406 |
+
class PatternVisitor extends esrecurse__default["default"].Visitor {
|
| 1407 |
+
static isPattern(node) {
|
| 1408 |
+
const nodeType = node.type;
|
| 1409 |
+
|
| 1410 |
+
return (
|
| 1411 |
+
nodeType === Syntax$1.Identifier ||
|
| 1412 |
+
nodeType === Syntax$1.ObjectPattern ||
|
| 1413 |
+
nodeType === Syntax$1.ArrayPattern ||
|
| 1414 |
+
nodeType === Syntax$1.SpreadElement ||
|
| 1415 |
+
nodeType === Syntax$1.RestElement ||
|
| 1416 |
+
nodeType === Syntax$1.AssignmentPattern
|
| 1417 |
+
);
|
| 1418 |
+
}
|
| 1419 |
+
|
| 1420 |
+
constructor(options, rootPattern, callback) {
|
| 1421 |
+
super(null, options);
|
| 1422 |
+
this.rootPattern = rootPattern;
|
| 1423 |
+
this.callback = callback;
|
| 1424 |
+
this.assignments = [];
|
| 1425 |
+
this.rightHandNodes = [];
|
| 1426 |
+
this.restElements = [];
|
| 1427 |
+
}
|
| 1428 |
+
|
| 1429 |
+
Identifier(pattern) {
|
| 1430 |
+
const lastRestElement = getLast(this.restElements);
|
| 1431 |
+
|
| 1432 |
+
this.callback(pattern, {
|
| 1433 |
+
topLevel: pattern === this.rootPattern,
|
| 1434 |
+
rest: lastRestElement !== null && lastRestElement !== void 0 && lastRestElement.argument === pattern,
|
| 1435 |
+
assignments: this.assignments
|
| 1436 |
+
});
|
| 1437 |
+
}
|
| 1438 |
+
|
| 1439 |
+
Property(property) {
|
| 1440 |
+
|
| 1441 |
+
// Computed property's key is a right hand node.
|
| 1442 |
+
if (property.computed) {
|
| 1443 |
+
this.rightHandNodes.push(property.key);
|
| 1444 |
+
}
|
| 1445 |
+
|
| 1446 |
+
// If it's shorthand, its key is same as its value.
|
| 1447 |
+
// If it's shorthand and has its default value, its key is same as its value.left (the value is AssignmentPattern).
|
| 1448 |
+
// If it's not shorthand, the name of new variable is its value's.
|
| 1449 |
+
this.visit(property.value);
|
| 1450 |
+
}
|
| 1451 |
+
|
| 1452 |
+
ArrayPattern(pattern) {
|
| 1453 |
+
for (let i = 0, iz = pattern.elements.length; i < iz; ++i) {
|
| 1454 |
+
const element = pattern.elements[i];
|
| 1455 |
+
|
| 1456 |
+
this.visit(element);
|
| 1457 |
+
}
|
| 1458 |
+
}
|
| 1459 |
+
|
| 1460 |
+
AssignmentPattern(pattern) {
|
| 1461 |
+
this.assignments.push(pattern);
|
| 1462 |
+
this.visit(pattern.left);
|
| 1463 |
+
this.rightHandNodes.push(pattern.right);
|
| 1464 |
+
this.assignments.pop();
|
| 1465 |
+
}
|
| 1466 |
+
|
| 1467 |
+
RestElement(pattern) {
|
| 1468 |
+
this.restElements.push(pattern);
|
| 1469 |
+
this.visit(pattern.argument);
|
| 1470 |
+
this.restElements.pop();
|
| 1471 |
+
}
|
| 1472 |
+
|
| 1473 |
+
MemberExpression(node) {
|
| 1474 |
+
|
| 1475 |
+
// Computed property's key is a right hand node.
|
| 1476 |
+
if (node.computed) {
|
| 1477 |
+
this.rightHandNodes.push(node.property);
|
| 1478 |
+
}
|
| 1479 |
+
|
| 1480 |
+
// the object is only read, write to its property.
|
| 1481 |
+
this.rightHandNodes.push(node.object);
|
| 1482 |
+
}
|
| 1483 |
+
|
| 1484 |
+
//
|
| 1485 |
+
// ForInStatement.left and AssignmentExpression.left are LeftHandSideExpression.
|
| 1486 |
+
// By spec, LeftHandSideExpression is Pattern or MemberExpression.
|
| 1487 |
+
// (see also: https://github.com/estree/estree/pull/20#issuecomment-74584758)
|
| 1488 |
+
// But espree 2.0 parses to ArrayExpression, ObjectExpression, etc...
|
| 1489 |
+
//
|
| 1490 |
+
|
| 1491 |
+
SpreadElement(node) {
|
| 1492 |
+
this.visit(node.argument);
|
| 1493 |
+
}
|
| 1494 |
+
|
| 1495 |
+
ArrayExpression(node) {
|
| 1496 |
+
node.elements.forEach(this.visit, this);
|
| 1497 |
+
}
|
| 1498 |
+
|
| 1499 |
+
AssignmentExpression(node) {
|
| 1500 |
+
this.assignments.push(node);
|
| 1501 |
+
this.visit(node.left);
|
| 1502 |
+
this.rightHandNodes.push(node.right);
|
| 1503 |
+
this.assignments.pop();
|
| 1504 |
+
}
|
| 1505 |
+
|
| 1506 |
+
CallExpression(node) {
|
| 1507 |
+
|
| 1508 |
+
// arguments are right hand nodes.
|
| 1509 |
+
node.arguments.forEach(a => {
|
| 1510 |
+
this.rightHandNodes.push(a);
|
| 1511 |
+
});
|
| 1512 |
+
this.visit(node.callee);
|
| 1513 |
+
}
|
| 1514 |
+
}
|
| 1515 |
+
|
| 1516 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 1517 |
+
|
| 1518 |
+
/*
|
| 1519 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 1520 |
+
|
| 1521 |
+
Redistribution and use in source and binary forms, with or without
|
| 1522 |
+
modification, are permitted provided that the following conditions are met:
|
| 1523 |
+
|
| 1524 |
+
* Redistributions of source code must retain the above copyright
|
| 1525 |
+
notice, this list of conditions and the following disclaimer.
|
| 1526 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 1527 |
+
notice, this list of conditions and the following disclaimer in the
|
| 1528 |
+
documentation and/or other materials provided with the distribution.
|
| 1529 |
+
|
| 1530 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 1531 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 1532 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 1533 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 1534 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 1535 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 1536 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 1537 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 1538 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 1539 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 1540 |
+
*/
|
| 1541 |
+
|
| 1542 |
+
const { Syntax } = estraverse__default["default"];
|
| 1543 |
+
|
| 1544 |
+
/**
|
| 1545 |
+
* Traverse identifier in pattern
|
| 1546 |
+
* @param {Object} options options
|
| 1547 |
+
* @param {pattern} rootPattern root pattern
|
| 1548 |
+
* @param {Refencer} referencer referencer
|
| 1549 |
+
* @param {callback} callback callback
|
| 1550 |
+
* @returns {void}
|
| 1551 |
+
*/
|
| 1552 |
+
function traverseIdentifierInPattern(options, rootPattern, referencer, callback) {
|
| 1553 |
+
|
| 1554 |
+
// Call the callback at left hand identifier nodes, and Collect right hand nodes.
|
| 1555 |
+
const visitor = new PatternVisitor(options, rootPattern, callback);
|
| 1556 |
+
|
| 1557 |
+
visitor.visit(rootPattern);
|
| 1558 |
+
|
| 1559 |
+
// Process the right hand nodes recursively.
|
| 1560 |
+
if (referencer !== null && referencer !== void 0) {
|
| 1561 |
+
visitor.rightHandNodes.forEach(referencer.visit, referencer);
|
| 1562 |
+
}
|
| 1563 |
+
}
|
| 1564 |
+
|
| 1565 |
+
// Importing ImportDeclaration.
|
| 1566 |
+
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
|
| 1567 |
+
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
|
| 1568 |
+
// FIXME: Now, we don't create module environment, because the context is
|
| 1569 |
+
// implementation dependent.
|
| 1570 |
+
|
| 1571 |
+
/**
|
| 1572 |
+
* Visitor for import specifiers.
|
| 1573 |
+
*/
|
| 1574 |
+
class Importer extends esrecurse__default["default"].Visitor {
|
| 1575 |
+
constructor(declaration, referencer) {
|
| 1576 |
+
super(null, referencer.options);
|
| 1577 |
+
this.declaration = declaration;
|
| 1578 |
+
this.referencer = referencer;
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
visitImport(id, specifier) {
|
| 1582 |
+
this.referencer.visitPattern(id, pattern => {
|
| 1583 |
+
this.referencer.currentScope().__define(pattern,
|
| 1584 |
+
new Definition(
|
| 1585 |
+
Variable.ImportBinding,
|
| 1586 |
+
pattern,
|
| 1587 |
+
specifier,
|
| 1588 |
+
this.declaration,
|
| 1589 |
+
null,
|
| 1590 |
+
null
|
| 1591 |
+
));
|
| 1592 |
+
});
|
| 1593 |
+
}
|
| 1594 |
+
|
| 1595 |
+
ImportNamespaceSpecifier(node) {
|
| 1596 |
+
const local = (node.local || node.id);
|
| 1597 |
+
|
| 1598 |
+
if (local) {
|
| 1599 |
+
this.visitImport(local, node);
|
| 1600 |
+
}
|
| 1601 |
+
}
|
| 1602 |
+
|
| 1603 |
+
ImportDefaultSpecifier(node) {
|
| 1604 |
+
const local = (node.local || node.id);
|
| 1605 |
+
|
| 1606 |
+
this.visitImport(local, node);
|
| 1607 |
+
}
|
| 1608 |
+
|
| 1609 |
+
ImportSpecifier(node) {
|
| 1610 |
+
const local = (node.local || node.id);
|
| 1611 |
+
|
| 1612 |
+
if (node.name) {
|
| 1613 |
+
this.visitImport(node.name, node);
|
| 1614 |
+
} else {
|
| 1615 |
+
this.visitImport(local, node);
|
| 1616 |
+
}
|
| 1617 |
+
}
|
| 1618 |
+
}
|
| 1619 |
+
|
| 1620 |
+
/**
|
| 1621 |
+
* Referencing variables and creating bindings.
|
| 1622 |
+
*/
|
| 1623 |
+
class Referencer extends esrecurse__default["default"].Visitor {
|
| 1624 |
+
constructor(options, scopeManager) {
|
| 1625 |
+
super(null, options);
|
| 1626 |
+
this.options = options;
|
| 1627 |
+
this.scopeManager = scopeManager;
|
| 1628 |
+
this.parent = null;
|
| 1629 |
+
this.isInnerMethodDefinition = false;
|
| 1630 |
+
}
|
| 1631 |
+
|
| 1632 |
+
currentScope() {
|
| 1633 |
+
return this.scopeManager.__currentScope;
|
| 1634 |
+
}
|
| 1635 |
+
|
| 1636 |
+
close(node) {
|
| 1637 |
+
while (this.currentScope() && node === this.currentScope().block) {
|
| 1638 |
+
this.scopeManager.__currentScope = this.currentScope().__close(this.scopeManager);
|
| 1639 |
+
}
|
| 1640 |
+
}
|
| 1641 |
+
|
| 1642 |
+
pushInnerMethodDefinition(isInnerMethodDefinition) {
|
| 1643 |
+
const previous = this.isInnerMethodDefinition;
|
| 1644 |
+
|
| 1645 |
+
this.isInnerMethodDefinition = isInnerMethodDefinition;
|
| 1646 |
+
return previous;
|
| 1647 |
+
}
|
| 1648 |
+
|
| 1649 |
+
popInnerMethodDefinition(isInnerMethodDefinition) {
|
| 1650 |
+
this.isInnerMethodDefinition = isInnerMethodDefinition;
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
+
referencingDefaultValue(pattern, assignments, maybeImplicitGlobal, init) {
|
| 1654 |
+
const scope = this.currentScope();
|
| 1655 |
+
|
| 1656 |
+
assignments.forEach(assignment => {
|
| 1657 |
+
scope.__referencing(
|
| 1658 |
+
pattern,
|
| 1659 |
+
Reference.WRITE,
|
| 1660 |
+
assignment.right,
|
| 1661 |
+
maybeImplicitGlobal,
|
| 1662 |
+
pattern !== assignment.left,
|
| 1663 |
+
init
|
| 1664 |
+
);
|
| 1665 |
+
});
|
| 1666 |
+
}
|
| 1667 |
+
|
| 1668 |
+
visitPattern(node, options, callback) {
|
| 1669 |
+
let visitPatternOptions = options;
|
| 1670 |
+
let visitPatternCallback = callback;
|
| 1671 |
+
|
| 1672 |
+
if (typeof options === "function") {
|
| 1673 |
+
visitPatternCallback = options;
|
| 1674 |
+
visitPatternOptions = { processRightHandNodes: false };
|
| 1675 |
+
}
|
| 1676 |
+
|
| 1677 |
+
traverseIdentifierInPattern(
|
| 1678 |
+
this.options,
|
| 1679 |
+
node,
|
| 1680 |
+
visitPatternOptions.processRightHandNodes ? this : null,
|
| 1681 |
+
visitPatternCallback
|
| 1682 |
+
);
|
| 1683 |
+
}
|
| 1684 |
+
|
| 1685 |
+
visitFunction(node) {
|
| 1686 |
+
let i, iz;
|
| 1687 |
+
|
| 1688 |
+
// FunctionDeclaration name is defined in upper scope
|
| 1689 |
+
// NOTE: Not referring variableScope. It is intended.
|
| 1690 |
+
// Since
|
| 1691 |
+
// in ES5, FunctionDeclaration should be in FunctionBody.
|
| 1692 |
+
// in ES6, FunctionDeclaration should be block scoped.
|
| 1693 |
+
|
| 1694 |
+
if (node.type === Syntax.FunctionDeclaration) {
|
| 1695 |
+
|
| 1696 |
+
// id is defined in upper scope
|
| 1697 |
+
this.currentScope().__define(node.id,
|
| 1698 |
+
new Definition(
|
| 1699 |
+
Variable.FunctionName,
|
| 1700 |
+
node.id,
|
| 1701 |
+
node,
|
| 1702 |
+
null,
|
| 1703 |
+
null,
|
| 1704 |
+
null
|
| 1705 |
+
));
|
| 1706 |
+
}
|
| 1707 |
+
|
| 1708 |
+
// FunctionExpression with name creates its special scope;
|
| 1709 |
+
// FunctionExpressionNameScope.
|
| 1710 |
+
if (node.type === Syntax.FunctionExpression && node.id) {
|
| 1711 |
+
this.scopeManager.__nestFunctionExpressionNameScope(node);
|
| 1712 |
+
}
|
| 1713 |
+
|
| 1714 |
+
// Consider this function is in the MethodDefinition.
|
| 1715 |
+
this.scopeManager.__nestFunctionScope(node, this.isInnerMethodDefinition);
|
| 1716 |
+
|
| 1717 |
+
const that = this;
|
| 1718 |
+
|
| 1719 |
+
/**
|
| 1720 |
+
* Visit pattern callback
|
| 1721 |
+
* @param {pattern} pattern pattern
|
| 1722 |
+
* @param {Object} info info
|
| 1723 |
+
* @returns {void}
|
| 1724 |
+
*/
|
| 1725 |
+
function visitPatternCallback(pattern, info) {
|
| 1726 |
+
that.currentScope().__define(pattern,
|
| 1727 |
+
new ParameterDefinition(
|
| 1728 |
+
pattern,
|
| 1729 |
+
node,
|
| 1730 |
+
i,
|
| 1731 |
+
info.rest
|
| 1732 |
+
));
|
| 1733 |
+
|
| 1734 |
+
that.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 1735 |
+
}
|
| 1736 |
+
|
| 1737 |
+
// Process parameter declarations.
|
| 1738 |
+
for (i = 0, iz = node.params.length; i < iz; ++i) {
|
| 1739 |
+
this.visitPattern(node.params[i], { processRightHandNodes: true }, visitPatternCallback);
|
| 1740 |
+
}
|
| 1741 |
+
|
| 1742 |
+
// if there's a rest argument, add that
|
| 1743 |
+
if (node.rest) {
|
| 1744 |
+
this.visitPattern({
|
| 1745 |
+
type: "RestElement",
|
| 1746 |
+
argument: node.rest
|
| 1747 |
+
}, pattern => {
|
| 1748 |
+
this.currentScope().__define(pattern,
|
| 1749 |
+
new ParameterDefinition(
|
| 1750 |
+
pattern,
|
| 1751 |
+
node,
|
| 1752 |
+
node.params.length,
|
| 1753 |
+
true
|
| 1754 |
+
));
|
| 1755 |
+
});
|
| 1756 |
+
}
|
| 1757 |
+
|
| 1758 |
+
// In TypeScript there are a number of function-like constructs which have no body,
|
| 1759 |
+
// so check it exists before traversing
|
| 1760 |
+
if (node.body) {
|
| 1761 |
+
|
| 1762 |
+
// Skip BlockStatement to prevent creating BlockStatement scope.
|
| 1763 |
+
if (node.body.type === Syntax.BlockStatement) {
|
| 1764 |
+
this.visitChildren(node.body);
|
| 1765 |
+
} else {
|
| 1766 |
+
this.visit(node.body);
|
| 1767 |
+
}
|
| 1768 |
+
}
|
| 1769 |
+
|
| 1770 |
+
this.close(node);
|
| 1771 |
+
}
|
| 1772 |
+
|
| 1773 |
+
visitClass(node) {
|
| 1774 |
+
if (node.type === Syntax.ClassDeclaration) {
|
| 1775 |
+
this.currentScope().__define(node.id,
|
| 1776 |
+
new Definition(
|
| 1777 |
+
Variable.ClassName,
|
| 1778 |
+
node.id,
|
| 1779 |
+
node,
|
| 1780 |
+
null,
|
| 1781 |
+
null,
|
| 1782 |
+
null
|
| 1783 |
+
));
|
| 1784 |
+
}
|
| 1785 |
+
|
| 1786 |
+
this.scopeManager.__nestClassScope(node);
|
| 1787 |
+
|
| 1788 |
+
if (node.id) {
|
| 1789 |
+
this.currentScope().__define(node.id,
|
| 1790 |
+
new Definition(
|
| 1791 |
+
Variable.ClassName,
|
| 1792 |
+
node.id,
|
| 1793 |
+
node
|
| 1794 |
+
));
|
| 1795 |
+
}
|
| 1796 |
+
|
| 1797 |
+
this.visit(node.superClass);
|
| 1798 |
+
this.visit(node.body);
|
| 1799 |
+
|
| 1800 |
+
this.close(node);
|
| 1801 |
+
}
|
| 1802 |
+
|
| 1803 |
+
visitProperty(node) {
|
| 1804 |
+
let previous;
|
| 1805 |
+
|
| 1806 |
+
if (node.computed) {
|
| 1807 |
+
this.visit(node.key);
|
| 1808 |
+
}
|
| 1809 |
+
|
| 1810 |
+
const isMethodDefinition = node.type === Syntax.MethodDefinition;
|
| 1811 |
+
|
| 1812 |
+
if (isMethodDefinition) {
|
| 1813 |
+
previous = this.pushInnerMethodDefinition(true);
|
| 1814 |
+
}
|
| 1815 |
+
this.visit(node.value);
|
| 1816 |
+
if (isMethodDefinition) {
|
| 1817 |
+
this.popInnerMethodDefinition(previous);
|
| 1818 |
+
}
|
| 1819 |
+
}
|
| 1820 |
+
|
| 1821 |
+
visitForIn(node) {
|
| 1822 |
+
if (node.left.type === Syntax.VariableDeclaration && node.left.kind !== "var") {
|
| 1823 |
+
this.scopeManager.__nestForScope(node);
|
| 1824 |
+
}
|
| 1825 |
+
|
| 1826 |
+
if (node.left.type === Syntax.VariableDeclaration) {
|
| 1827 |
+
this.visit(node.left);
|
| 1828 |
+
this.visitPattern(node.left.declarations[0].id, pattern => {
|
| 1829 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, null, true, true);
|
| 1830 |
+
});
|
| 1831 |
+
} else {
|
| 1832 |
+
this.visitPattern(node.left, { processRightHandNodes: true }, (pattern, info) => {
|
| 1833 |
+
let maybeImplicitGlobal = null;
|
| 1834 |
+
|
| 1835 |
+
if (!this.currentScope().isStrict) {
|
| 1836 |
+
maybeImplicitGlobal = {
|
| 1837 |
+
pattern,
|
| 1838 |
+
node
|
| 1839 |
+
};
|
| 1840 |
+
}
|
| 1841 |
+
this.referencingDefaultValue(pattern, info.assignments, maybeImplicitGlobal, false);
|
| 1842 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, maybeImplicitGlobal, true, false);
|
| 1843 |
+
});
|
| 1844 |
+
}
|
| 1845 |
+
this.visit(node.right);
|
| 1846 |
+
this.visit(node.body);
|
| 1847 |
+
|
| 1848 |
+
this.close(node);
|
| 1849 |
+
}
|
| 1850 |
+
|
| 1851 |
+
visitVariableDeclaration(variableTargetScope, type, node, index) {
|
| 1852 |
+
|
| 1853 |
+
const decl = node.declarations[index];
|
| 1854 |
+
const init = decl.init;
|
| 1855 |
+
|
| 1856 |
+
this.visitPattern(decl.id, { processRightHandNodes: true }, (pattern, info) => {
|
| 1857 |
+
variableTargetScope.__define(
|
| 1858 |
+
pattern,
|
| 1859 |
+
new Definition(
|
| 1860 |
+
type,
|
| 1861 |
+
pattern,
|
| 1862 |
+
decl,
|
| 1863 |
+
node,
|
| 1864 |
+
index,
|
| 1865 |
+
node.kind
|
| 1866 |
+
)
|
| 1867 |
+
);
|
| 1868 |
+
|
| 1869 |
+
this.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 1870 |
+
if (init) {
|
| 1871 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, init, null, !info.topLevel, true);
|
| 1872 |
+
}
|
| 1873 |
+
});
|
| 1874 |
+
}
|
| 1875 |
+
|
| 1876 |
+
AssignmentExpression(node) {
|
| 1877 |
+
if (PatternVisitor.isPattern(node.left)) {
|
| 1878 |
+
if (node.operator === "=") {
|
| 1879 |
+
this.visitPattern(node.left, { processRightHandNodes: true }, (pattern, info) => {
|
| 1880 |
+
let maybeImplicitGlobal = null;
|
| 1881 |
+
|
| 1882 |
+
if (!this.currentScope().isStrict) {
|
| 1883 |
+
maybeImplicitGlobal = {
|
| 1884 |
+
pattern,
|
| 1885 |
+
node
|
| 1886 |
+
};
|
| 1887 |
+
}
|
| 1888 |
+
this.referencingDefaultValue(pattern, info.assignments, maybeImplicitGlobal, false);
|
| 1889 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, maybeImplicitGlobal, !info.topLevel, false);
|
| 1890 |
+
});
|
| 1891 |
+
} else {
|
| 1892 |
+
this.currentScope().__referencing(node.left, Reference.RW, node.right);
|
| 1893 |
+
}
|
| 1894 |
+
} else {
|
| 1895 |
+
this.visit(node.left);
|
| 1896 |
+
}
|
| 1897 |
+
this.visit(node.right);
|
| 1898 |
+
}
|
| 1899 |
+
|
| 1900 |
+
CatchClause(node) {
|
| 1901 |
+
this.scopeManager.__nestCatchScope(node);
|
| 1902 |
+
|
| 1903 |
+
this.visitPattern(node.param, { processRightHandNodes: true }, (pattern, info) => {
|
| 1904 |
+
this.currentScope().__define(pattern,
|
| 1905 |
+
new Definition(
|
| 1906 |
+
Variable.CatchClause,
|
| 1907 |
+
pattern,
|
| 1908 |
+
node,
|
| 1909 |
+
null,
|
| 1910 |
+
null,
|
| 1911 |
+
null
|
| 1912 |
+
));
|
| 1913 |
+
this.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 1914 |
+
});
|
| 1915 |
+
this.visit(node.body);
|
| 1916 |
+
|
| 1917 |
+
this.close(node);
|
| 1918 |
+
}
|
| 1919 |
+
|
| 1920 |
+
Program(node) {
|
| 1921 |
+
this.scopeManager.__nestGlobalScope(node);
|
| 1922 |
+
|
| 1923 |
+
if (this.scopeManager.isGlobalReturn()) {
|
| 1924 |
+
|
| 1925 |
+
// Force strictness of GlobalScope to false when using node.js scope.
|
| 1926 |
+
this.currentScope().isStrict = false;
|
| 1927 |
+
this.scopeManager.__nestFunctionScope(node, false);
|
| 1928 |
+
}
|
| 1929 |
+
|
| 1930 |
+
if (this.scopeManager.__isES6() && this.scopeManager.isModule()) {
|
| 1931 |
+
this.scopeManager.__nestModuleScope(node);
|
| 1932 |
+
}
|
| 1933 |
+
|
| 1934 |
+
if (this.scopeManager.isStrictModeSupported() && this.scopeManager.isImpliedStrict()) {
|
| 1935 |
+
this.currentScope().isStrict = true;
|
| 1936 |
+
}
|
| 1937 |
+
|
| 1938 |
+
this.visitChildren(node);
|
| 1939 |
+
this.close(node);
|
| 1940 |
+
}
|
| 1941 |
+
|
| 1942 |
+
Identifier(node) {
|
| 1943 |
+
this.currentScope().__referencing(node);
|
| 1944 |
+
}
|
| 1945 |
+
|
| 1946 |
+
// eslint-disable-next-line class-methods-use-this -- Desired as instance method
|
| 1947 |
+
PrivateIdentifier() {
|
| 1948 |
+
|
| 1949 |
+
// Do nothing.
|
| 1950 |
+
}
|
| 1951 |
+
|
| 1952 |
+
UpdateExpression(node) {
|
| 1953 |
+
if (PatternVisitor.isPattern(node.argument)) {
|
| 1954 |
+
this.currentScope().__referencing(node.argument, Reference.RW, null);
|
| 1955 |
+
} else {
|
| 1956 |
+
this.visitChildren(node);
|
| 1957 |
+
}
|
| 1958 |
+
}
|
| 1959 |
+
|
| 1960 |
+
MemberExpression(node) {
|
| 1961 |
+
this.visit(node.object);
|
| 1962 |
+
if (node.computed) {
|
| 1963 |
+
this.visit(node.property);
|
| 1964 |
+
}
|
| 1965 |
+
}
|
| 1966 |
+
|
| 1967 |
+
Property(node) {
|
| 1968 |
+
this.visitProperty(node);
|
| 1969 |
+
}
|
| 1970 |
+
|
| 1971 |
+
PropertyDefinition(node) {
|
| 1972 |
+
const { computed, key, value } = node;
|
| 1973 |
+
|
| 1974 |
+
if (computed) {
|
| 1975 |
+
this.visit(key);
|
| 1976 |
+
}
|
| 1977 |
+
if (value) {
|
| 1978 |
+
this.scopeManager.__nestClassFieldInitializerScope(value);
|
| 1979 |
+
this.visit(value);
|
| 1980 |
+
this.close(value);
|
| 1981 |
+
}
|
| 1982 |
+
}
|
| 1983 |
+
|
| 1984 |
+
StaticBlock(node) {
|
| 1985 |
+
this.scopeManager.__nestClassStaticBlockScope(node);
|
| 1986 |
+
|
| 1987 |
+
this.visitChildren(node);
|
| 1988 |
+
|
| 1989 |
+
this.close(node);
|
| 1990 |
+
}
|
| 1991 |
+
|
| 1992 |
+
MethodDefinition(node) {
|
| 1993 |
+
this.visitProperty(node);
|
| 1994 |
+
}
|
| 1995 |
+
|
| 1996 |
+
BreakStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 1997 |
+
|
| 1998 |
+
ContinueStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 1999 |
+
|
| 2000 |
+
LabeledStatement(node) {
|
| 2001 |
+
this.visit(node.body);
|
| 2002 |
+
}
|
| 2003 |
+
|
| 2004 |
+
ForStatement(node) {
|
| 2005 |
+
|
| 2006 |
+
// Create ForStatement declaration.
|
| 2007 |
+
// NOTE: In ES6, ForStatement dynamically generates
|
| 2008 |
+
// per iteration environment. However, escope is
|
| 2009 |
+
// a static analyzer, we only generate one scope for ForStatement.
|
| 2010 |
+
if (node.init && node.init.type === Syntax.VariableDeclaration && node.init.kind !== "var") {
|
| 2011 |
+
this.scopeManager.__nestForScope(node);
|
| 2012 |
+
}
|
| 2013 |
+
|
| 2014 |
+
this.visitChildren(node);
|
| 2015 |
+
|
| 2016 |
+
this.close(node);
|
| 2017 |
+
}
|
| 2018 |
+
|
| 2019 |
+
ClassExpression(node) {
|
| 2020 |
+
this.visitClass(node);
|
| 2021 |
+
}
|
| 2022 |
+
|
| 2023 |
+
ClassDeclaration(node) {
|
| 2024 |
+
this.visitClass(node);
|
| 2025 |
+
}
|
| 2026 |
+
|
| 2027 |
+
CallExpression(node) {
|
| 2028 |
+
|
| 2029 |
+
// Check this is direct call to eval
|
| 2030 |
+
if (!this.scopeManager.__ignoreEval() && node.callee.type === Syntax.Identifier && node.callee.name === "eval") {
|
| 2031 |
+
|
| 2032 |
+
// NOTE: This should be `variableScope`. Since direct eval call always creates Lexical environment and
|
| 2033 |
+
// let / const should be enclosed into it. Only VariableDeclaration affects on the caller's environment.
|
| 2034 |
+
this.currentScope().variableScope.__detectEval();
|
| 2035 |
+
}
|
| 2036 |
+
this.visitChildren(node);
|
| 2037 |
+
}
|
| 2038 |
+
|
| 2039 |
+
BlockStatement(node) {
|
| 2040 |
+
if (this.scopeManager.__isES6()) {
|
| 2041 |
+
this.scopeManager.__nestBlockScope(node);
|
| 2042 |
+
}
|
| 2043 |
+
|
| 2044 |
+
this.visitChildren(node);
|
| 2045 |
+
|
| 2046 |
+
this.close(node);
|
| 2047 |
+
}
|
| 2048 |
+
|
| 2049 |
+
ThisExpression() {
|
| 2050 |
+
this.currentScope().variableScope.__detectThis();
|
| 2051 |
+
}
|
| 2052 |
+
|
| 2053 |
+
WithStatement(node) {
|
| 2054 |
+
this.visit(node.object);
|
| 2055 |
+
|
| 2056 |
+
// Then nest scope for WithStatement.
|
| 2057 |
+
this.scopeManager.__nestWithScope(node);
|
| 2058 |
+
|
| 2059 |
+
this.visit(node.body);
|
| 2060 |
+
|
| 2061 |
+
this.close(node);
|
| 2062 |
+
}
|
| 2063 |
+
|
| 2064 |
+
VariableDeclaration(node) {
|
| 2065 |
+
const variableTargetScope = (node.kind === "var") ? this.currentScope().variableScope : this.currentScope();
|
| 2066 |
+
|
| 2067 |
+
for (let i = 0, iz = node.declarations.length; i < iz; ++i) {
|
| 2068 |
+
const decl = node.declarations[i];
|
| 2069 |
+
|
| 2070 |
+
this.visitVariableDeclaration(variableTargetScope, Variable.Variable, node, i);
|
| 2071 |
+
if (decl.init) {
|
| 2072 |
+
this.visit(decl.init);
|
| 2073 |
+
}
|
| 2074 |
+
}
|
| 2075 |
+
}
|
| 2076 |
+
|
| 2077 |
+
// sec 13.11.8
|
| 2078 |
+
SwitchStatement(node) {
|
| 2079 |
+
this.visit(node.discriminant);
|
| 2080 |
+
|
| 2081 |
+
if (this.scopeManager.__isES6()) {
|
| 2082 |
+
this.scopeManager.__nestSwitchScope(node);
|
| 2083 |
+
}
|
| 2084 |
+
|
| 2085 |
+
for (let i = 0, iz = node.cases.length; i < iz; ++i) {
|
| 2086 |
+
this.visit(node.cases[i]);
|
| 2087 |
+
}
|
| 2088 |
+
|
| 2089 |
+
this.close(node);
|
| 2090 |
+
}
|
| 2091 |
+
|
| 2092 |
+
FunctionDeclaration(node) {
|
| 2093 |
+
this.visitFunction(node);
|
| 2094 |
+
}
|
| 2095 |
+
|
| 2096 |
+
FunctionExpression(node) {
|
| 2097 |
+
this.visitFunction(node);
|
| 2098 |
+
}
|
| 2099 |
+
|
| 2100 |
+
ForOfStatement(node) {
|
| 2101 |
+
this.visitForIn(node);
|
| 2102 |
+
}
|
| 2103 |
+
|
| 2104 |
+
ForInStatement(node) {
|
| 2105 |
+
this.visitForIn(node);
|
| 2106 |
+
}
|
| 2107 |
+
|
| 2108 |
+
ArrowFunctionExpression(node) {
|
| 2109 |
+
this.visitFunction(node);
|
| 2110 |
+
}
|
| 2111 |
+
|
| 2112 |
+
ImportDeclaration(node) {
|
| 2113 |
+
assert(this.scopeManager.__isES6() && this.scopeManager.isModule(), "ImportDeclaration should appear when the mode is ES6 and in the module context.");
|
| 2114 |
+
|
| 2115 |
+
const importer = new Importer(node, this);
|
| 2116 |
+
|
| 2117 |
+
importer.visit(node);
|
| 2118 |
+
}
|
| 2119 |
+
|
| 2120 |
+
visitExportDeclaration(node) {
|
| 2121 |
+
if (node.source) {
|
| 2122 |
+
return;
|
| 2123 |
+
}
|
| 2124 |
+
if (node.declaration) {
|
| 2125 |
+
this.visit(node.declaration);
|
| 2126 |
+
return;
|
| 2127 |
+
}
|
| 2128 |
+
|
| 2129 |
+
this.visitChildren(node);
|
| 2130 |
+
}
|
| 2131 |
+
|
| 2132 |
+
// TODO: ExportDeclaration doesn't exist. for bc?
|
| 2133 |
+
ExportDeclaration(node) {
|
| 2134 |
+
this.visitExportDeclaration(node);
|
| 2135 |
+
}
|
| 2136 |
+
|
| 2137 |
+
ExportAllDeclaration(node) {
|
| 2138 |
+
this.visitExportDeclaration(node);
|
| 2139 |
+
}
|
| 2140 |
+
|
| 2141 |
+
ExportDefaultDeclaration(node) {
|
| 2142 |
+
this.visitExportDeclaration(node);
|
| 2143 |
+
}
|
| 2144 |
+
|
| 2145 |
+
ExportNamedDeclaration(node) {
|
| 2146 |
+
this.visitExportDeclaration(node);
|
| 2147 |
+
}
|
| 2148 |
+
|
| 2149 |
+
ExportSpecifier(node) {
|
| 2150 |
+
|
| 2151 |
+
// TODO: `node.id` doesn't exist. for bc?
|
| 2152 |
+
const local = (node.id || node.local);
|
| 2153 |
+
|
| 2154 |
+
this.visit(local);
|
| 2155 |
+
}
|
| 2156 |
+
|
| 2157 |
+
MetaProperty() { // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 2158 |
+
|
| 2159 |
+
// do nothing.
|
| 2160 |
+
}
|
| 2161 |
+
|
| 2162 |
+
JSXIdentifier(node) {
|
| 2163 |
+
|
| 2164 |
+
// Special case: "this" should not count as a reference
|
| 2165 |
+
if (this.scopeManager.__isJSXEnabled() && node.name !== "this") {
|
| 2166 |
+
this.currentScope().__referencing(node);
|
| 2167 |
+
}
|
| 2168 |
+
}
|
| 2169 |
+
|
| 2170 |
+
JSXMemberExpression(node) {
|
| 2171 |
+
this.visit(node.object);
|
| 2172 |
+
}
|
| 2173 |
+
|
| 2174 |
+
JSXElement(node) {
|
| 2175 |
+
if (this.scopeManager.__isJSXEnabled()) {
|
| 2176 |
+
this.visit(node.openingElement);
|
| 2177 |
+
node.children.forEach(this.visit, this);
|
| 2178 |
+
} else {
|
| 2179 |
+
this.visitChildren(node);
|
| 2180 |
+
}
|
| 2181 |
+
}
|
| 2182 |
+
|
| 2183 |
+
JSXOpeningElement(node) {
|
| 2184 |
+
if (this.scopeManager.__isJSXEnabled()) {
|
| 2185 |
+
|
| 2186 |
+
const nameNode = node.name;
|
| 2187 |
+
const isComponentName = nameNode.type === "JSXIdentifier" && nameNode.name[0].toUpperCase() === nameNode.name[0];
|
| 2188 |
+
const isComponent = isComponentName || nameNode.type === "JSXMemberExpression";
|
| 2189 |
+
|
| 2190 |
+
// we only want to visit JSXIdentifier nodes if they are capitalized
|
| 2191 |
+
if (isComponent) {
|
| 2192 |
+
this.visit(nameNode);
|
| 2193 |
+
}
|
| 2194 |
+
}
|
| 2195 |
+
|
| 2196 |
+
node.attributes.forEach(this.visit, this);
|
| 2197 |
+
}
|
| 2198 |
+
|
| 2199 |
+
JSXAttribute(node) {
|
| 2200 |
+
if (node.value) {
|
| 2201 |
+
this.visit(node.value);
|
| 2202 |
+
}
|
| 2203 |
+
}
|
| 2204 |
+
|
| 2205 |
+
JSXExpressionContainer(node) {
|
| 2206 |
+
this.visit(node.expression);
|
| 2207 |
+
}
|
| 2208 |
+
|
| 2209 |
+
JSXNamespacedName(node) {
|
| 2210 |
+
this.visit(node.namespace);
|
| 2211 |
+
this.visit(node.name);
|
| 2212 |
+
}
|
| 2213 |
+
}
|
| 2214 |
+
|
| 2215 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 2216 |
+
|
| 2217 |
+
const version = "8.4.0";
|
| 2218 |
+
|
| 2219 |
+
/*
|
| 2220 |
+
Copyright (C) 2012-2014 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 2221 |
+
Copyright (C) 2013 Alex Seville <hi@alexanderseville.com>
|
| 2222 |
+
Copyright (C) 2014 Thiago de Arruda <tpadilha84@gmail.com>
|
| 2223 |
+
|
| 2224 |
+
Redistribution and use in source and binary forms, with or without
|
| 2225 |
+
modification, are permitted provided that the following conditions are met:
|
| 2226 |
+
|
| 2227 |
+
* Redistributions of source code must retain the above copyright
|
| 2228 |
+
notice, this list of conditions and the following disclaimer.
|
| 2229 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 2230 |
+
notice, this list of conditions and the following disclaimer in the
|
| 2231 |
+
documentation and/or other materials provided with the distribution.
|
| 2232 |
+
|
| 2233 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 2234 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 2235 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 2236 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 2237 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 2238 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 2239 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 2240 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 2241 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 2242 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 2243 |
+
*/
|
| 2244 |
+
|
| 2245 |
+
/**
|
| 2246 |
+
* Set the default options
|
| 2247 |
+
* @returns {Object} options
|
| 2248 |
+
*/
|
| 2249 |
+
function defaultOptions() {
|
| 2250 |
+
return {
|
| 2251 |
+
optimistic: false,
|
| 2252 |
+
nodejsScope: false,
|
| 2253 |
+
impliedStrict: false,
|
| 2254 |
+
sourceType: "script", // one of ['script', 'module', 'commonjs']
|
| 2255 |
+
ecmaVersion: 5,
|
| 2256 |
+
childVisitorKeys: null,
|
| 2257 |
+
fallback: "iteration"
|
| 2258 |
+
};
|
| 2259 |
+
}
|
| 2260 |
+
|
| 2261 |
+
/**
|
| 2262 |
+
* Preform deep update on option object
|
| 2263 |
+
* @param {Object} target Options
|
| 2264 |
+
* @param {Object} override Updates
|
| 2265 |
+
* @returns {Object} Updated options
|
| 2266 |
+
*/
|
| 2267 |
+
function updateDeeply(target, override) {
|
| 2268 |
+
|
| 2269 |
+
/**
|
| 2270 |
+
* Is hash object
|
| 2271 |
+
* @param {Object} value Test value
|
| 2272 |
+
* @returns {boolean} Result
|
| 2273 |
+
*/
|
| 2274 |
+
function isHashObject(value) {
|
| 2275 |
+
return typeof value === "object" && value instanceof Object && !(value instanceof Array) && !(value instanceof RegExp);
|
| 2276 |
+
}
|
| 2277 |
+
|
| 2278 |
+
for (const key in override) {
|
| 2279 |
+
if (Object.hasOwn(override, key)) {
|
| 2280 |
+
const val = override[key];
|
| 2281 |
+
|
| 2282 |
+
if (isHashObject(val)) {
|
| 2283 |
+
if (isHashObject(target[key])) {
|
| 2284 |
+
updateDeeply(target[key], val);
|
| 2285 |
+
} else {
|
| 2286 |
+
target[key] = updateDeeply({}, val);
|
| 2287 |
+
}
|
| 2288 |
+
} else {
|
| 2289 |
+
target[key] = val;
|
| 2290 |
+
}
|
| 2291 |
+
}
|
| 2292 |
+
}
|
| 2293 |
+
return target;
|
| 2294 |
+
}
|
| 2295 |
+
|
| 2296 |
+
/**
|
| 2297 |
+
* Main interface function. Takes an Espree syntax tree and returns the
|
| 2298 |
+
* analyzed scopes.
|
| 2299 |
+
* @function analyze
|
| 2300 |
+
* @param {espree.Tree} tree Abstract Syntax Tree
|
| 2301 |
+
* @param {Object} providedOptions Options that tailor the scope analysis
|
| 2302 |
+
* @param {boolean} [providedOptions.optimistic=false] the optimistic flag
|
| 2303 |
+
* @param {boolean} [providedOptions.ignoreEval=false] whether to check 'eval()' calls
|
| 2304 |
+
* @param {boolean} [providedOptions.nodejsScope=false] whether the whole
|
| 2305 |
+
* script is executed under node.js environment. When enabled, escope adds
|
| 2306 |
+
* a function scope immediately following the global scope.
|
| 2307 |
+
* @param {boolean} [providedOptions.impliedStrict=false] implied strict mode
|
| 2308 |
+
* (if ecmaVersion >= 5).
|
| 2309 |
+
* @param {string} [providedOptions.sourceType='script'] the source type of the script. one of 'script', 'module', and 'commonjs'
|
| 2310 |
+
* @param {number} [providedOptions.ecmaVersion=5] which ECMAScript version is considered
|
| 2311 |
+
* @param {boolean} [providedOptions.jsx=false] support JSX references
|
| 2312 |
+
* @param {Object} [providedOptions.childVisitorKeys=null] Additional known visitor keys. See [esrecurse](https://github.com/estools/esrecurse)'s the `childVisitorKeys` option.
|
| 2313 |
+
* @param {string} [providedOptions.fallback='iteration'] A kind of the fallback in order to encounter with unknown node. See [esrecurse](https://github.com/estools/esrecurse)'s the `fallback` option.
|
| 2314 |
+
* @returns {ScopeManager} ScopeManager
|
| 2315 |
+
*/
|
| 2316 |
+
function analyze(tree, providedOptions) {
|
| 2317 |
+
const options = updateDeeply(defaultOptions(), providedOptions);
|
| 2318 |
+
const scopeManager = new ScopeManager(options);
|
| 2319 |
+
const referencer = new Referencer(options, scopeManager);
|
| 2320 |
+
|
| 2321 |
+
referencer.visit(tree);
|
| 2322 |
+
|
| 2323 |
+
assert(scopeManager.__currentScope === null, "currentScope should be null.");
|
| 2324 |
+
|
| 2325 |
+
return scopeManager;
|
| 2326 |
+
}
|
| 2327 |
+
|
| 2328 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
| 2329 |
+
|
| 2330 |
+
exports.Definition = Definition;
|
| 2331 |
+
exports.PatternVisitor = PatternVisitor;
|
| 2332 |
+
exports.Reference = Reference;
|
| 2333 |
+
exports.Referencer = Referencer;
|
| 2334 |
+
exports.Scope = Scope;
|
| 2335 |
+
exports.ScopeManager = ScopeManager;
|
| 2336 |
+
exports.Variable = Variable;
|
| 2337 |
+
exports.analyze = analyze;
|
| 2338 |
+
exports.version = version;
|
| 2339 |
+
//# sourceMappingURL=eslint-scope.cjs.map
|
node_modules/eslint-scope/lib/assert.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Assertion utilities.
|
| 3 |
+
* @author Nicholas C. Zakas
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Throws an error if the given condition is not truthy.
|
| 8 |
+
* @param {boolean} condition The condition to check.
|
| 9 |
+
* @param {string} message The message to include with the error.
|
| 10 |
+
* @returns {void}
|
| 11 |
+
* @throws {Error} When the condition is not truthy.
|
| 12 |
+
*/
|
| 13 |
+
export function assert(condition, message = "Assertion failed.") {
|
| 14 |
+
if (!condition) {
|
| 15 |
+
throw new Error(message);
|
| 16 |
+
}
|
| 17 |
+
}
|
node_modules/eslint-scope/lib/definition.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import Variable from "./variable.js";
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @constructor Definition
|
| 29 |
+
*/
|
| 30 |
+
class Definition {
|
| 31 |
+
constructor(type, name, node, parent, index, kind) {
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* @member {string} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
|
| 35 |
+
*/
|
| 36 |
+
this.type = type;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* @member {espree.Identifier} Definition#name - the identifier AST node of the occurrence.
|
| 40 |
+
*/
|
| 41 |
+
this.name = name;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* @member {espree.Node} Definition#node - the enclosing node of the identifier.
|
| 45 |
+
*/
|
| 46 |
+
this.node = node;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* @member {espree.Node?} Definition#parent - the enclosing statement node of the identifier.
|
| 50 |
+
*/
|
| 51 |
+
this.parent = parent;
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* @member {number?} Definition#index - the index in the declaration statement.
|
| 55 |
+
*/
|
| 56 |
+
this.index = index;
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* @member {string?} Definition#kind - the kind of the declaration statement.
|
| 60 |
+
*/
|
| 61 |
+
this.kind = kind;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @constructor ParameterDefinition
|
| 67 |
+
*/
|
| 68 |
+
class ParameterDefinition extends Definition {
|
| 69 |
+
constructor(name, node, index, rest) {
|
| 70 |
+
super(Variable.Parameter, name, node, null, index, null);
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Whether the parameter definition is a part of a rest parameter.
|
| 74 |
+
* @member {boolean} ParameterDefinition#rest
|
| 75 |
+
*/
|
| 76 |
+
this.rest = rest;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
export {
|
| 81 |
+
ParameterDefinition,
|
| 82 |
+
Definition
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/index.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2012-2014 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
Copyright (C) 2013 Alex Seville <hi@alexanderseville.com>
|
| 4 |
+
Copyright (C) 2014 Thiago de Arruda <tpadilha84@gmail.com>
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer.
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
|
| 15 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 16 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 17 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 18 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 19 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 20 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 21 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 22 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 23 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 24 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Escope (<a href="http://github.com/estools/escope">escope</a>) is an <a
|
| 29 |
+
* href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript</a>
|
| 30 |
+
* scope analyzer extracted from the <a
|
| 31 |
+
* href="http://github.com/estools/esmangle">esmangle project</a/>.
|
| 32 |
+
* <p>
|
| 33 |
+
* <em>escope</em> finds lexical scopes in a source program, i.e. areas of that
|
| 34 |
+
* program where different occurrences of the same identifier refer to the same
|
| 35 |
+
* variable. With each scope the contained variables are collected, and each
|
| 36 |
+
* identifier reference in code is linked to its corresponding variable (if
|
| 37 |
+
* possible).
|
| 38 |
+
* <p>
|
| 39 |
+
* <em>escope</em> works on a syntax tree of the parsed source code which has
|
| 40 |
+
* to adhere to the <a
|
| 41 |
+
* href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API">
|
| 42 |
+
* Mozilla Parser API</a>. E.g. <a href="https://github.com/eslint/espree">espree</a> is a parser
|
| 43 |
+
* that produces such syntax trees.
|
| 44 |
+
* <p>
|
| 45 |
+
* The main interface is the {@link analyze} function.
|
| 46 |
+
* @module escope
|
| 47 |
+
*/
|
| 48 |
+
|
| 49 |
+
import { assert } from "./assert.js";
|
| 50 |
+
|
| 51 |
+
import ScopeManager from "./scope-manager.js";
|
| 52 |
+
import Referencer from "./referencer.js";
|
| 53 |
+
import Reference from "./reference.js";
|
| 54 |
+
import Variable from "./variable.js";
|
| 55 |
+
|
| 56 |
+
import eslintScopeVersion from "./version.js";
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Set the default options
|
| 60 |
+
* @returns {Object} options
|
| 61 |
+
*/
|
| 62 |
+
function defaultOptions() {
|
| 63 |
+
return {
|
| 64 |
+
optimistic: false,
|
| 65 |
+
nodejsScope: false,
|
| 66 |
+
impliedStrict: false,
|
| 67 |
+
sourceType: "script", // one of ['script', 'module', 'commonjs']
|
| 68 |
+
ecmaVersion: 5,
|
| 69 |
+
childVisitorKeys: null,
|
| 70 |
+
fallback: "iteration"
|
| 71 |
+
};
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Preform deep update on option object
|
| 76 |
+
* @param {Object} target Options
|
| 77 |
+
* @param {Object} override Updates
|
| 78 |
+
* @returns {Object} Updated options
|
| 79 |
+
*/
|
| 80 |
+
function updateDeeply(target, override) {
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Is hash object
|
| 84 |
+
* @param {Object} value Test value
|
| 85 |
+
* @returns {boolean} Result
|
| 86 |
+
*/
|
| 87 |
+
function isHashObject(value) {
|
| 88 |
+
return typeof value === "object" && value instanceof Object && !(value instanceof Array) && !(value instanceof RegExp);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
for (const key in override) {
|
| 92 |
+
if (Object.hasOwn(override, key)) {
|
| 93 |
+
const val = override[key];
|
| 94 |
+
|
| 95 |
+
if (isHashObject(val)) {
|
| 96 |
+
if (isHashObject(target[key])) {
|
| 97 |
+
updateDeeply(target[key], val);
|
| 98 |
+
} else {
|
| 99 |
+
target[key] = updateDeeply({}, val);
|
| 100 |
+
}
|
| 101 |
+
} else {
|
| 102 |
+
target[key] = val;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
return target;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Main interface function. Takes an Espree syntax tree and returns the
|
| 111 |
+
* analyzed scopes.
|
| 112 |
+
* @function analyze
|
| 113 |
+
* @param {espree.Tree} tree Abstract Syntax Tree
|
| 114 |
+
* @param {Object} providedOptions Options that tailor the scope analysis
|
| 115 |
+
* @param {boolean} [providedOptions.optimistic=false] the optimistic flag
|
| 116 |
+
* @param {boolean} [providedOptions.ignoreEval=false] whether to check 'eval()' calls
|
| 117 |
+
* @param {boolean} [providedOptions.nodejsScope=false] whether the whole
|
| 118 |
+
* script is executed under node.js environment. When enabled, escope adds
|
| 119 |
+
* a function scope immediately following the global scope.
|
| 120 |
+
* @param {boolean} [providedOptions.impliedStrict=false] implied strict mode
|
| 121 |
+
* (if ecmaVersion >= 5).
|
| 122 |
+
* @param {string} [providedOptions.sourceType='script'] the source type of the script. one of 'script', 'module', and 'commonjs'
|
| 123 |
+
* @param {number} [providedOptions.ecmaVersion=5] which ECMAScript version is considered
|
| 124 |
+
* @param {boolean} [providedOptions.jsx=false] support JSX references
|
| 125 |
+
* @param {Object} [providedOptions.childVisitorKeys=null] Additional known visitor keys. See [esrecurse](https://github.com/estools/esrecurse)'s the `childVisitorKeys` option.
|
| 126 |
+
* @param {string} [providedOptions.fallback='iteration'] A kind of the fallback in order to encounter with unknown node. See [esrecurse](https://github.com/estools/esrecurse)'s the `fallback` option.
|
| 127 |
+
* @returns {ScopeManager} ScopeManager
|
| 128 |
+
*/
|
| 129 |
+
function analyze(tree, providedOptions) {
|
| 130 |
+
const options = updateDeeply(defaultOptions(), providedOptions);
|
| 131 |
+
const scopeManager = new ScopeManager(options);
|
| 132 |
+
const referencer = new Referencer(options, scopeManager);
|
| 133 |
+
|
| 134 |
+
referencer.visit(tree);
|
| 135 |
+
|
| 136 |
+
assert(scopeManager.__currentScope === null, "currentScope should be null.");
|
| 137 |
+
|
| 138 |
+
return scopeManager;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
export {
|
| 142 |
+
|
| 143 |
+
/** @name module:escope.version */
|
| 144 |
+
eslintScopeVersion as version,
|
| 145 |
+
|
| 146 |
+
/** @name module:escope.Reference */
|
| 147 |
+
Reference,
|
| 148 |
+
|
| 149 |
+
/** @name module:escope.Variable */
|
| 150 |
+
Variable,
|
| 151 |
+
|
| 152 |
+
/** @name module:escope.ScopeManager */
|
| 153 |
+
ScopeManager,
|
| 154 |
+
|
| 155 |
+
/** @name module:escope.Referencer */
|
| 156 |
+
Referencer,
|
| 157 |
+
|
| 158 |
+
analyze
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
/** @name module:escope.Definition */
|
| 162 |
+
export { Definition } from "./definition.js";
|
| 163 |
+
|
| 164 |
+
/** @name module:escope.PatternVisitor */
|
| 165 |
+
export { default as PatternVisitor } from "./pattern-visitor.js";
|
| 166 |
+
|
| 167 |
+
/** @name module:escope.Scope */
|
| 168 |
+
export { Scope } from "./scope.js";
|
| 169 |
+
|
| 170 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/pattern-visitor.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import estraverse from "estraverse";
|
| 26 |
+
import esrecurse from "esrecurse";
|
| 27 |
+
|
| 28 |
+
const { Syntax } = estraverse;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Get last array element
|
| 32 |
+
* @param {Array} xs array
|
| 33 |
+
* @returns {any} Last elment
|
| 34 |
+
*/
|
| 35 |
+
function getLast(xs) {
|
| 36 |
+
return xs.at(-1) || null;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Visitor for destructuring patterns.
|
| 41 |
+
*/
|
| 42 |
+
class PatternVisitor extends esrecurse.Visitor {
|
| 43 |
+
static isPattern(node) {
|
| 44 |
+
const nodeType = node.type;
|
| 45 |
+
|
| 46 |
+
return (
|
| 47 |
+
nodeType === Syntax.Identifier ||
|
| 48 |
+
nodeType === Syntax.ObjectPattern ||
|
| 49 |
+
nodeType === Syntax.ArrayPattern ||
|
| 50 |
+
nodeType === Syntax.SpreadElement ||
|
| 51 |
+
nodeType === Syntax.RestElement ||
|
| 52 |
+
nodeType === Syntax.AssignmentPattern
|
| 53 |
+
);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
constructor(options, rootPattern, callback) {
|
| 57 |
+
super(null, options);
|
| 58 |
+
this.rootPattern = rootPattern;
|
| 59 |
+
this.callback = callback;
|
| 60 |
+
this.assignments = [];
|
| 61 |
+
this.rightHandNodes = [];
|
| 62 |
+
this.restElements = [];
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
Identifier(pattern) {
|
| 66 |
+
const lastRestElement = getLast(this.restElements);
|
| 67 |
+
|
| 68 |
+
this.callback(pattern, {
|
| 69 |
+
topLevel: pattern === this.rootPattern,
|
| 70 |
+
rest: lastRestElement !== null && lastRestElement !== void 0 && lastRestElement.argument === pattern,
|
| 71 |
+
assignments: this.assignments
|
| 72 |
+
});
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
Property(property) {
|
| 76 |
+
|
| 77 |
+
// Computed property's key is a right hand node.
|
| 78 |
+
if (property.computed) {
|
| 79 |
+
this.rightHandNodes.push(property.key);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// If it's shorthand, its key is same as its value.
|
| 83 |
+
// If it's shorthand and has its default value, its key is same as its value.left (the value is AssignmentPattern).
|
| 84 |
+
// If it's not shorthand, the name of new variable is its value's.
|
| 85 |
+
this.visit(property.value);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
ArrayPattern(pattern) {
|
| 89 |
+
for (let i = 0, iz = pattern.elements.length; i < iz; ++i) {
|
| 90 |
+
const element = pattern.elements[i];
|
| 91 |
+
|
| 92 |
+
this.visit(element);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
AssignmentPattern(pattern) {
|
| 97 |
+
this.assignments.push(pattern);
|
| 98 |
+
this.visit(pattern.left);
|
| 99 |
+
this.rightHandNodes.push(pattern.right);
|
| 100 |
+
this.assignments.pop();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
RestElement(pattern) {
|
| 104 |
+
this.restElements.push(pattern);
|
| 105 |
+
this.visit(pattern.argument);
|
| 106 |
+
this.restElements.pop();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
MemberExpression(node) {
|
| 110 |
+
|
| 111 |
+
// Computed property's key is a right hand node.
|
| 112 |
+
if (node.computed) {
|
| 113 |
+
this.rightHandNodes.push(node.property);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// the object is only read, write to its property.
|
| 117 |
+
this.rightHandNodes.push(node.object);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
//
|
| 121 |
+
// ForInStatement.left and AssignmentExpression.left are LeftHandSideExpression.
|
| 122 |
+
// By spec, LeftHandSideExpression is Pattern or MemberExpression.
|
| 123 |
+
// (see also: https://github.com/estree/estree/pull/20#issuecomment-74584758)
|
| 124 |
+
// But espree 2.0 parses to ArrayExpression, ObjectExpression, etc...
|
| 125 |
+
//
|
| 126 |
+
|
| 127 |
+
SpreadElement(node) {
|
| 128 |
+
this.visit(node.argument);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
ArrayExpression(node) {
|
| 132 |
+
node.elements.forEach(this.visit, this);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
AssignmentExpression(node) {
|
| 136 |
+
this.assignments.push(node);
|
| 137 |
+
this.visit(node.left);
|
| 138 |
+
this.rightHandNodes.push(node.right);
|
| 139 |
+
this.assignments.pop();
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
CallExpression(node) {
|
| 143 |
+
|
| 144 |
+
// arguments are right hand nodes.
|
| 145 |
+
node.arguments.forEach(a => {
|
| 146 |
+
this.rightHandNodes.push(a);
|
| 147 |
+
});
|
| 148 |
+
this.visit(node.callee);
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
export default PatternVisitor;
|
| 153 |
+
|
| 154 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/reference.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
const READ = 0x1;
|
| 26 |
+
const WRITE = 0x2;
|
| 27 |
+
const RW = READ | WRITE;
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* A Reference represents a single occurrence of an identifier in code.
|
| 31 |
+
* @constructor Reference
|
| 32 |
+
*/
|
| 33 |
+
class Reference {
|
| 34 |
+
constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Identifier syntax node.
|
| 38 |
+
* @member {espreeIdentifier} Reference#identifier
|
| 39 |
+
*/
|
| 40 |
+
this.identifier = ident;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Reference to the enclosing Scope.
|
| 44 |
+
* @member {Scope} Reference#from
|
| 45 |
+
*/
|
| 46 |
+
this.from = scope;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Whether the reference comes from a dynamic scope (such as 'eval',
|
| 50 |
+
* 'with', etc.), and may be trapped by dynamic scopes.
|
| 51 |
+
* @member {boolean} Reference#tainted
|
| 52 |
+
*/
|
| 53 |
+
this.tainted = false;
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* The variable this reference is resolved with.
|
| 57 |
+
* @member {Variable} Reference#resolved
|
| 58 |
+
*/
|
| 59 |
+
this.resolved = null;
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* The read-write mode of the reference. (Value is one of {@link
|
| 63 |
+
* Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
|
| 64 |
+
* @member {number} Reference#flag
|
| 65 |
+
* @private
|
| 66 |
+
*/
|
| 67 |
+
this.flag = flag;
|
| 68 |
+
if (this.isWrite()) {
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* If reference is writeable, this is the tree being written to it.
|
| 72 |
+
* @member {espreeNode} Reference#writeExpr
|
| 73 |
+
*/
|
| 74 |
+
this.writeExpr = writeExpr;
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Whether the Reference might refer to a partial value of writeExpr.
|
| 78 |
+
* @member {boolean} Reference#partial
|
| 79 |
+
*/
|
| 80 |
+
this.partial = partial;
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Whether the Reference is to write of initialization.
|
| 84 |
+
* @member {boolean} Reference#init
|
| 85 |
+
*/
|
| 86 |
+
this.init = init;
|
| 87 |
+
}
|
| 88 |
+
this.__maybeImplicitGlobal = maybeImplicitGlobal;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Whether the reference is static.
|
| 93 |
+
* @function Reference#isStatic
|
| 94 |
+
* @returns {boolean} static
|
| 95 |
+
*/
|
| 96 |
+
isStatic() {
|
| 97 |
+
return !this.tainted && this.resolved && this.resolved.scope.isStatic();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Whether the reference is writeable.
|
| 102 |
+
* @function Reference#isWrite
|
| 103 |
+
* @returns {boolean} write
|
| 104 |
+
*/
|
| 105 |
+
isWrite() {
|
| 106 |
+
return !!(this.flag & Reference.WRITE);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Whether the reference is readable.
|
| 111 |
+
* @function Reference#isRead
|
| 112 |
+
* @returns {boolean} read
|
| 113 |
+
*/
|
| 114 |
+
isRead() {
|
| 115 |
+
return !!(this.flag & Reference.READ);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/**
|
| 119 |
+
* Whether the reference is read-only.
|
| 120 |
+
* @function Reference#isReadOnly
|
| 121 |
+
* @returns {boolean} read only
|
| 122 |
+
*/
|
| 123 |
+
isReadOnly() {
|
| 124 |
+
return this.flag === Reference.READ;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Whether the reference is write-only.
|
| 129 |
+
* @function Reference#isWriteOnly
|
| 130 |
+
* @returns {boolean} write only
|
| 131 |
+
*/
|
| 132 |
+
isWriteOnly() {
|
| 133 |
+
return this.flag === Reference.WRITE;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Whether the reference is read-write.
|
| 138 |
+
* @function Reference#isReadWrite
|
| 139 |
+
* @returns {boolean} read write
|
| 140 |
+
*/
|
| 141 |
+
isReadWrite() {
|
| 142 |
+
return this.flag === Reference.RW;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* @constant Reference.READ
|
| 148 |
+
* @private
|
| 149 |
+
*/
|
| 150 |
+
Reference.READ = READ;
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* @constant Reference.WRITE
|
| 154 |
+
* @private
|
| 155 |
+
*/
|
| 156 |
+
Reference.WRITE = WRITE;
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* @constant Reference.RW
|
| 160 |
+
* @private
|
| 161 |
+
*/
|
| 162 |
+
Reference.RW = RW;
|
| 163 |
+
|
| 164 |
+
export default Reference;
|
| 165 |
+
|
| 166 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/referencer.js
ADDED
|
@@ -0,0 +1,708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import estraverse from "estraverse";
|
| 26 |
+
import esrecurse from "esrecurse";
|
| 27 |
+
import Reference from "./reference.js";
|
| 28 |
+
import Variable from "./variable.js";
|
| 29 |
+
import PatternVisitor from "./pattern-visitor.js";
|
| 30 |
+
import { Definition, ParameterDefinition } from "./definition.js";
|
| 31 |
+
import { assert } from "./assert.js";
|
| 32 |
+
|
| 33 |
+
const { Syntax } = estraverse;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Traverse identifier in pattern
|
| 37 |
+
* @param {Object} options options
|
| 38 |
+
* @param {pattern} rootPattern root pattern
|
| 39 |
+
* @param {Refencer} referencer referencer
|
| 40 |
+
* @param {callback} callback callback
|
| 41 |
+
* @returns {void}
|
| 42 |
+
*/
|
| 43 |
+
function traverseIdentifierInPattern(options, rootPattern, referencer, callback) {
|
| 44 |
+
|
| 45 |
+
// Call the callback at left hand identifier nodes, and Collect right hand nodes.
|
| 46 |
+
const visitor = new PatternVisitor(options, rootPattern, callback);
|
| 47 |
+
|
| 48 |
+
visitor.visit(rootPattern);
|
| 49 |
+
|
| 50 |
+
// Process the right hand nodes recursively.
|
| 51 |
+
if (referencer !== null && referencer !== void 0) {
|
| 52 |
+
visitor.rightHandNodes.forEach(referencer.visit, referencer);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// Importing ImportDeclaration.
|
| 57 |
+
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
|
| 58 |
+
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
|
| 59 |
+
// FIXME: Now, we don't create module environment, because the context is
|
| 60 |
+
// implementation dependent.
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Visitor for import specifiers.
|
| 64 |
+
*/
|
| 65 |
+
class Importer extends esrecurse.Visitor {
|
| 66 |
+
constructor(declaration, referencer) {
|
| 67 |
+
super(null, referencer.options);
|
| 68 |
+
this.declaration = declaration;
|
| 69 |
+
this.referencer = referencer;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
visitImport(id, specifier) {
|
| 73 |
+
this.referencer.visitPattern(id, pattern => {
|
| 74 |
+
this.referencer.currentScope().__define(pattern,
|
| 75 |
+
new Definition(
|
| 76 |
+
Variable.ImportBinding,
|
| 77 |
+
pattern,
|
| 78 |
+
specifier,
|
| 79 |
+
this.declaration,
|
| 80 |
+
null,
|
| 81 |
+
null
|
| 82 |
+
));
|
| 83 |
+
});
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
ImportNamespaceSpecifier(node) {
|
| 87 |
+
const local = (node.local || node.id);
|
| 88 |
+
|
| 89 |
+
if (local) {
|
| 90 |
+
this.visitImport(local, node);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
ImportDefaultSpecifier(node) {
|
| 95 |
+
const local = (node.local || node.id);
|
| 96 |
+
|
| 97 |
+
this.visitImport(local, node);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
ImportSpecifier(node) {
|
| 101 |
+
const local = (node.local || node.id);
|
| 102 |
+
|
| 103 |
+
if (node.name) {
|
| 104 |
+
this.visitImport(node.name, node);
|
| 105 |
+
} else {
|
| 106 |
+
this.visitImport(local, node);
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/**
|
| 112 |
+
* Referencing variables and creating bindings.
|
| 113 |
+
*/
|
| 114 |
+
class Referencer extends esrecurse.Visitor {
|
| 115 |
+
constructor(options, scopeManager) {
|
| 116 |
+
super(null, options);
|
| 117 |
+
this.options = options;
|
| 118 |
+
this.scopeManager = scopeManager;
|
| 119 |
+
this.parent = null;
|
| 120 |
+
this.isInnerMethodDefinition = false;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
currentScope() {
|
| 124 |
+
return this.scopeManager.__currentScope;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
close(node) {
|
| 128 |
+
while (this.currentScope() && node === this.currentScope().block) {
|
| 129 |
+
this.scopeManager.__currentScope = this.currentScope().__close(this.scopeManager);
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
pushInnerMethodDefinition(isInnerMethodDefinition) {
|
| 134 |
+
const previous = this.isInnerMethodDefinition;
|
| 135 |
+
|
| 136 |
+
this.isInnerMethodDefinition = isInnerMethodDefinition;
|
| 137 |
+
return previous;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
popInnerMethodDefinition(isInnerMethodDefinition) {
|
| 141 |
+
this.isInnerMethodDefinition = isInnerMethodDefinition;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
referencingDefaultValue(pattern, assignments, maybeImplicitGlobal, init) {
|
| 145 |
+
const scope = this.currentScope();
|
| 146 |
+
|
| 147 |
+
assignments.forEach(assignment => {
|
| 148 |
+
scope.__referencing(
|
| 149 |
+
pattern,
|
| 150 |
+
Reference.WRITE,
|
| 151 |
+
assignment.right,
|
| 152 |
+
maybeImplicitGlobal,
|
| 153 |
+
pattern !== assignment.left,
|
| 154 |
+
init
|
| 155 |
+
);
|
| 156 |
+
});
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
visitPattern(node, options, callback) {
|
| 160 |
+
let visitPatternOptions = options;
|
| 161 |
+
let visitPatternCallback = callback;
|
| 162 |
+
|
| 163 |
+
if (typeof options === "function") {
|
| 164 |
+
visitPatternCallback = options;
|
| 165 |
+
visitPatternOptions = { processRightHandNodes: false };
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
traverseIdentifierInPattern(
|
| 169 |
+
this.options,
|
| 170 |
+
node,
|
| 171 |
+
visitPatternOptions.processRightHandNodes ? this : null,
|
| 172 |
+
visitPatternCallback
|
| 173 |
+
);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
visitFunction(node) {
|
| 177 |
+
let i, iz;
|
| 178 |
+
|
| 179 |
+
// FunctionDeclaration name is defined in upper scope
|
| 180 |
+
// NOTE: Not referring variableScope. It is intended.
|
| 181 |
+
// Since
|
| 182 |
+
// in ES5, FunctionDeclaration should be in FunctionBody.
|
| 183 |
+
// in ES6, FunctionDeclaration should be block scoped.
|
| 184 |
+
|
| 185 |
+
if (node.type === Syntax.FunctionDeclaration) {
|
| 186 |
+
|
| 187 |
+
// id is defined in upper scope
|
| 188 |
+
this.currentScope().__define(node.id,
|
| 189 |
+
new Definition(
|
| 190 |
+
Variable.FunctionName,
|
| 191 |
+
node.id,
|
| 192 |
+
node,
|
| 193 |
+
null,
|
| 194 |
+
null,
|
| 195 |
+
null
|
| 196 |
+
));
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
// FunctionExpression with name creates its special scope;
|
| 200 |
+
// FunctionExpressionNameScope.
|
| 201 |
+
if (node.type === Syntax.FunctionExpression && node.id) {
|
| 202 |
+
this.scopeManager.__nestFunctionExpressionNameScope(node);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// Consider this function is in the MethodDefinition.
|
| 206 |
+
this.scopeManager.__nestFunctionScope(node, this.isInnerMethodDefinition);
|
| 207 |
+
|
| 208 |
+
const that = this;
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* Visit pattern callback
|
| 212 |
+
* @param {pattern} pattern pattern
|
| 213 |
+
* @param {Object} info info
|
| 214 |
+
* @returns {void}
|
| 215 |
+
*/
|
| 216 |
+
function visitPatternCallback(pattern, info) {
|
| 217 |
+
that.currentScope().__define(pattern,
|
| 218 |
+
new ParameterDefinition(
|
| 219 |
+
pattern,
|
| 220 |
+
node,
|
| 221 |
+
i,
|
| 222 |
+
info.rest
|
| 223 |
+
));
|
| 224 |
+
|
| 225 |
+
that.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// Process parameter declarations.
|
| 229 |
+
for (i = 0, iz = node.params.length; i < iz; ++i) {
|
| 230 |
+
this.visitPattern(node.params[i], { processRightHandNodes: true }, visitPatternCallback);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
// if there's a rest argument, add that
|
| 234 |
+
if (node.rest) {
|
| 235 |
+
this.visitPattern({
|
| 236 |
+
type: "RestElement",
|
| 237 |
+
argument: node.rest
|
| 238 |
+
}, pattern => {
|
| 239 |
+
this.currentScope().__define(pattern,
|
| 240 |
+
new ParameterDefinition(
|
| 241 |
+
pattern,
|
| 242 |
+
node,
|
| 243 |
+
node.params.length,
|
| 244 |
+
true
|
| 245 |
+
));
|
| 246 |
+
});
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// In TypeScript there are a number of function-like constructs which have no body,
|
| 250 |
+
// so check it exists before traversing
|
| 251 |
+
if (node.body) {
|
| 252 |
+
|
| 253 |
+
// Skip BlockStatement to prevent creating BlockStatement scope.
|
| 254 |
+
if (node.body.type === Syntax.BlockStatement) {
|
| 255 |
+
this.visitChildren(node.body);
|
| 256 |
+
} else {
|
| 257 |
+
this.visit(node.body);
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
this.close(node);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
visitClass(node) {
|
| 265 |
+
if (node.type === Syntax.ClassDeclaration) {
|
| 266 |
+
this.currentScope().__define(node.id,
|
| 267 |
+
new Definition(
|
| 268 |
+
Variable.ClassName,
|
| 269 |
+
node.id,
|
| 270 |
+
node,
|
| 271 |
+
null,
|
| 272 |
+
null,
|
| 273 |
+
null
|
| 274 |
+
));
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
this.scopeManager.__nestClassScope(node);
|
| 278 |
+
|
| 279 |
+
if (node.id) {
|
| 280 |
+
this.currentScope().__define(node.id,
|
| 281 |
+
new Definition(
|
| 282 |
+
Variable.ClassName,
|
| 283 |
+
node.id,
|
| 284 |
+
node
|
| 285 |
+
));
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
this.visit(node.superClass);
|
| 289 |
+
this.visit(node.body);
|
| 290 |
+
|
| 291 |
+
this.close(node);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
visitProperty(node) {
|
| 295 |
+
let previous;
|
| 296 |
+
|
| 297 |
+
if (node.computed) {
|
| 298 |
+
this.visit(node.key);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
const isMethodDefinition = node.type === Syntax.MethodDefinition;
|
| 302 |
+
|
| 303 |
+
if (isMethodDefinition) {
|
| 304 |
+
previous = this.pushInnerMethodDefinition(true);
|
| 305 |
+
}
|
| 306 |
+
this.visit(node.value);
|
| 307 |
+
if (isMethodDefinition) {
|
| 308 |
+
this.popInnerMethodDefinition(previous);
|
| 309 |
+
}
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
visitForIn(node) {
|
| 313 |
+
if (node.left.type === Syntax.VariableDeclaration && node.left.kind !== "var") {
|
| 314 |
+
this.scopeManager.__nestForScope(node);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
if (node.left.type === Syntax.VariableDeclaration) {
|
| 318 |
+
this.visit(node.left);
|
| 319 |
+
this.visitPattern(node.left.declarations[0].id, pattern => {
|
| 320 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, null, true, true);
|
| 321 |
+
});
|
| 322 |
+
} else {
|
| 323 |
+
this.visitPattern(node.left, { processRightHandNodes: true }, (pattern, info) => {
|
| 324 |
+
let maybeImplicitGlobal = null;
|
| 325 |
+
|
| 326 |
+
if (!this.currentScope().isStrict) {
|
| 327 |
+
maybeImplicitGlobal = {
|
| 328 |
+
pattern,
|
| 329 |
+
node
|
| 330 |
+
};
|
| 331 |
+
}
|
| 332 |
+
this.referencingDefaultValue(pattern, info.assignments, maybeImplicitGlobal, false);
|
| 333 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, maybeImplicitGlobal, true, false);
|
| 334 |
+
});
|
| 335 |
+
}
|
| 336 |
+
this.visit(node.right);
|
| 337 |
+
this.visit(node.body);
|
| 338 |
+
|
| 339 |
+
this.close(node);
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
visitVariableDeclaration(variableTargetScope, type, node, index) {
|
| 343 |
+
|
| 344 |
+
const decl = node.declarations[index];
|
| 345 |
+
const init = decl.init;
|
| 346 |
+
|
| 347 |
+
this.visitPattern(decl.id, { processRightHandNodes: true }, (pattern, info) => {
|
| 348 |
+
variableTargetScope.__define(
|
| 349 |
+
pattern,
|
| 350 |
+
new Definition(
|
| 351 |
+
type,
|
| 352 |
+
pattern,
|
| 353 |
+
decl,
|
| 354 |
+
node,
|
| 355 |
+
index,
|
| 356 |
+
node.kind
|
| 357 |
+
)
|
| 358 |
+
);
|
| 359 |
+
|
| 360 |
+
this.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 361 |
+
if (init) {
|
| 362 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, init, null, !info.topLevel, true);
|
| 363 |
+
}
|
| 364 |
+
});
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
AssignmentExpression(node) {
|
| 368 |
+
if (PatternVisitor.isPattern(node.left)) {
|
| 369 |
+
if (node.operator === "=") {
|
| 370 |
+
this.visitPattern(node.left, { processRightHandNodes: true }, (pattern, info) => {
|
| 371 |
+
let maybeImplicitGlobal = null;
|
| 372 |
+
|
| 373 |
+
if (!this.currentScope().isStrict) {
|
| 374 |
+
maybeImplicitGlobal = {
|
| 375 |
+
pattern,
|
| 376 |
+
node
|
| 377 |
+
};
|
| 378 |
+
}
|
| 379 |
+
this.referencingDefaultValue(pattern, info.assignments, maybeImplicitGlobal, false);
|
| 380 |
+
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, maybeImplicitGlobal, !info.topLevel, false);
|
| 381 |
+
});
|
| 382 |
+
} else {
|
| 383 |
+
this.currentScope().__referencing(node.left, Reference.RW, node.right);
|
| 384 |
+
}
|
| 385 |
+
} else {
|
| 386 |
+
this.visit(node.left);
|
| 387 |
+
}
|
| 388 |
+
this.visit(node.right);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
CatchClause(node) {
|
| 392 |
+
this.scopeManager.__nestCatchScope(node);
|
| 393 |
+
|
| 394 |
+
this.visitPattern(node.param, { processRightHandNodes: true }, (pattern, info) => {
|
| 395 |
+
this.currentScope().__define(pattern,
|
| 396 |
+
new Definition(
|
| 397 |
+
Variable.CatchClause,
|
| 398 |
+
pattern,
|
| 399 |
+
node,
|
| 400 |
+
null,
|
| 401 |
+
null,
|
| 402 |
+
null
|
| 403 |
+
));
|
| 404 |
+
this.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 405 |
+
});
|
| 406 |
+
this.visit(node.body);
|
| 407 |
+
|
| 408 |
+
this.close(node);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
Program(node) {
|
| 412 |
+
this.scopeManager.__nestGlobalScope(node);
|
| 413 |
+
|
| 414 |
+
if (this.scopeManager.isGlobalReturn()) {
|
| 415 |
+
|
| 416 |
+
// Force strictness of GlobalScope to false when using node.js scope.
|
| 417 |
+
this.currentScope().isStrict = false;
|
| 418 |
+
this.scopeManager.__nestFunctionScope(node, false);
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
if (this.scopeManager.__isES6() && this.scopeManager.isModule()) {
|
| 422 |
+
this.scopeManager.__nestModuleScope(node);
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
if (this.scopeManager.isStrictModeSupported() && this.scopeManager.isImpliedStrict()) {
|
| 426 |
+
this.currentScope().isStrict = true;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
this.visitChildren(node);
|
| 430 |
+
this.close(node);
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
Identifier(node) {
|
| 434 |
+
this.currentScope().__referencing(node);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
// eslint-disable-next-line class-methods-use-this -- Desired as instance method
|
| 438 |
+
PrivateIdentifier() {
|
| 439 |
+
|
| 440 |
+
// Do nothing.
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
UpdateExpression(node) {
|
| 444 |
+
if (PatternVisitor.isPattern(node.argument)) {
|
| 445 |
+
this.currentScope().__referencing(node.argument, Reference.RW, null);
|
| 446 |
+
} else {
|
| 447 |
+
this.visitChildren(node);
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
MemberExpression(node) {
|
| 452 |
+
this.visit(node.object);
|
| 453 |
+
if (node.computed) {
|
| 454 |
+
this.visit(node.property);
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
Property(node) {
|
| 459 |
+
this.visitProperty(node);
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
PropertyDefinition(node) {
|
| 463 |
+
const { computed, key, value } = node;
|
| 464 |
+
|
| 465 |
+
if (computed) {
|
| 466 |
+
this.visit(key);
|
| 467 |
+
}
|
| 468 |
+
if (value) {
|
| 469 |
+
this.scopeManager.__nestClassFieldInitializerScope(value);
|
| 470 |
+
this.visit(value);
|
| 471 |
+
this.close(value);
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
StaticBlock(node) {
|
| 476 |
+
this.scopeManager.__nestClassStaticBlockScope(node);
|
| 477 |
+
|
| 478 |
+
this.visitChildren(node);
|
| 479 |
+
|
| 480 |
+
this.close(node);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
MethodDefinition(node) {
|
| 484 |
+
this.visitProperty(node);
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
BreakStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 488 |
+
|
| 489 |
+
ContinueStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 490 |
+
|
| 491 |
+
LabeledStatement(node) {
|
| 492 |
+
this.visit(node.body);
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
ForStatement(node) {
|
| 496 |
+
|
| 497 |
+
// Create ForStatement declaration.
|
| 498 |
+
// NOTE: In ES6, ForStatement dynamically generates
|
| 499 |
+
// per iteration environment. However, escope is
|
| 500 |
+
// a static analyzer, we only generate one scope for ForStatement.
|
| 501 |
+
if (node.init && node.init.type === Syntax.VariableDeclaration && node.init.kind !== "var") {
|
| 502 |
+
this.scopeManager.__nestForScope(node);
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
this.visitChildren(node);
|
| 506 |
+
|
| 507 |
+
this.close(node);
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
ClassExpression(node) {
|
| 511 |
+
this.visitClass(node);
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
ClassDeclaration(node) {
|
| 515 |
+
this.visitClass(node);
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
CallExpression(node) {
|
| 519 |
+
|
| 520 |
+
// Check this is direct call to eval
|
| 521 |
+
if (!this.scopeManager.__ignoreEval() && node.callee.type === Syntax.Identifier && node.callee.name === "eval") {
|
| 522 |
+
|
| 523 |
+
// NOTE: This should be `variableScope`. Since direct eval call always creates Lexical environment and
|
| 524 |
+
// let / const should be enclosed into it. Only VariableDeclaration affects on the caller's environment.
|
| 525 |
+
this.currentScope().variableScope.__detectEval();
|
| 526 |
+
}
|
| 527 |
+
this.visitChildren(node);
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
BlockStatement(node) {
|
| 531 |
+
if (this.scopeManager.__isES6()) {
|
| 532 |
+
this.scopeManager.__nestBlockScope(node);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
this.visitChildren(node);
|
| 536 |
+
|
| 537 |
+
this.close(node);
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
ThisExpression() {
|
| 541 |
+
this.currentScope().variableScope.__detectThis();
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
WithStatement(node) {
|
| 545 |
+
this.visit(node.object);
|
| 546 |
+
|
| 547 |
+
// Then nest scope for WithStatement.
|
| 548 |
+
this.scopeManager.__nestWithScope(node);
|
| 549 |
+
|
| 550 |
+
this.visit(node.body);
|
| 551 |
+
|
| 552 |
+
this.close(node);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
VariableDeclaration(node) {
|
| 556 |
+
const variableTargetScope = (node.kind === "var") ? this.currentScope().variableScope : this.currentScope();
|
| 557 |
+
|
| 558 |
+
for (let i = 0, iz = node.declarations.length; i < iz; ++i) {
|
| 559 |
+
const decl = node.declarations[i];
|
| 560 |
+
|
| 561 |
+
this.visitVariableDeclaration(variableTargetScope, Variable.Variable, node, i);
|
| 562 |
+
if (decl.init) {
|
| 563 |
+
this.visit(decl.init);
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
// sec 13.11.8
|
| 569 |
+
SwitchStatement(node) {
|
| 570 |
+
this.visit(node.discriminant);
|
| 571 |
+
|
| 572 |
+
if (this.scopeManager.__isES6()) {
|
| 573 |
+
this.scopeManager.__nestSwitchScope(node);
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
for (let i = 0, iz = node.cases.length; i < iz; ++i) {
|
| 577 |
+
this.visit(node.cases[i]);
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
this.close(node);
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
FunctionDeclaration(node) {
|
| 584 |
+
this.visitFunction(node);
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
FunctionExpression(node) {
|
| 588 |
+
this.visitFunction(node);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
ForOfStatement(node) {
|
| 592 |
+
this.visitForIn(node);
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
ForInStatement(node) {
|
| 596 |
+
this.visitForIn(node);
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
ArrowFunctionExpression(node) {
|
| 600 |
+
this.visitFunction(node);
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
ImportDeclaration(node) {
|
| 604 |
+
assert(this.scopeManager.__isES6() && this.scopeManager.isModule(), "ImportDeclaration should appear when the mode is ES6 and in the module context.");
|
| 605 |
+
|
| 606 |
+
const importer = new Importer(node, this);
|
| 607 |
+
|
| 608 |
+
importer.visit(node);
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
visitExportDeclaration(node) {
|
| 612 |
+
if (node.source) {
|
| 613 |
+
return;
|
| 614 |
+
}
|
| 615 |
+
if (node.declaration) {
|
| 616 |
+
this.visit(node.declaration);
|
| 617 |
+
return;
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
this.visitChildren(node);
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
// TODO: ExportDeclaration doesn't exist. for bc?
|
| 624 |
+
ExportDeclaration(node) {
|
| 625 |
+
this.visitExportDeclaration(node);
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
ExportAllDeclaration(node) {
|
| 629 |
+
this.visitExportDeclaration(node);
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
ExportDefaultDeclaration(node) {
|
| 633 |
+
this.visitExportDeclaration(node);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
ExportNamedDeclaration(node) {
|
| 637 |
+
this.visitExportDeclaration(node);
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
ExportSpecifier(node) {
|
| 641 |
+
|
| 642 |
+
// TODO: `node.id` doesn't exist. for bc?
|
| 643 |
+
const local = (node.id || node.local);
|
| 644 |
+
|
| 645 |
+
this.visit(local);
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
MetaProperty() { // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 649 |
+
|
| 650 |
+
// do nothing.
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
JSXIdentifier(node) {
|
| 654 |
+
|
| 655 |
+
// Special case: "this" should not count as a reference
|
| 656 |
+
if (this.scopeManager.__isJSXEnabled() && node.name !== "this") {
|
| 657 |
+
this.currentScope().__referencing(node);
|
| 658 |
+
}
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
JSXMemberExpression(node) {
|
| 662 |
+
this.visit(node.object);
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
JSXElement(node) {
|
| 666 |
+
if (this.scopeManager.__isJSXEnabled()) {
|
| 667 |
+
this.visit(node.openingElement);
|
| 668 |
+
node.children.forEach(this.visit, this);
|
| 669 |
+
} else {
|
| 670 |
+
this.visitChildren(node);
|
| 671 |
+
}
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
JSXOpeningElement(node) {
|
| 675 |
+
if (this.scopeManager.__isJSXEnabled()) {
|
| 676 |
+
|
| 677 |
+
const nameNode = node.name;
|
| 678 |
+
const isComponentName = nameNode.type === "JSXIdentifier" && nameNode.name[0].toUpperCase() === nameNode.name[0];
|
| 679 |
+
const isComponent = isComponentName || nameNode.type === "JSXMemberExpression";
|
| 680 |
+
|
| 681 |
+
// we only want to visit JSXIdentifier nodes if they are capitalized
|
| 682 |
+
if (isComponent) {
|
| 683 |
+
this.visit(nameNode);
|
| 684 |
+
}
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
node.attributes.forEach(this.visit, this);
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
JSXAttribute(node) {
|
| 691 |
+
if (node.value) {
|
| 692 |
+
this.visit(node.value);
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
JSXExpressionContainer(node) {
|
| 697 |
+
this.visit(node.expression);
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
JSXNamespacedName(node) {
|
| 701 |
+
this.visit(node.namespace);
|
| 702 |
+
this.visit(node.name);
|
| 703 |
+
}
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
export default Referencer;
|
| 707 |
+
|
| 708 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/scope-manager.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import {
|
| 26 |
+
BlockScope,
|
| 27 |
+
CatchScope,
|
| 28 |
+
ClassFieldInitializerScope,
|
| 29 |
+
ClassStaticBlockScope,
|
| 30 |
+
ClassScope,
|
| 31 |
+
ForScope,
|
| 32 |
+
FunctionExpressionNameScope,
|
| 33 |
+
FunctionScope,
|
| 34 |
+
GlobalScope,
|
| 35 |
+
ModuleScope,
|
| 36 |
+
SwitchScope,
|
| 37 |
+
WithScope
|
| 38 |
+
} from "./scope.js";
|
| 39 |
+
import { assert } from "./assert.js";
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* @constructor ScopeManager
|
| 43 |
+
*/
|
| 44 |
+
class ScopeManager {
|
| 45 |
+
constructor(options) {
|
| 46 |
+
this.scopes = [];
|
| 47 |
+
this.globalScope = null;
|
| 48 |
+
this.__nodeToScope = new WeakMap();
|
| 49 |
+
this.__currentScope = null;
|
| 50 |
+
this.__options = options;
|
| 51 |
+
this.__declaredVariables = new WeakMap();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
__isOptimistic() {
|
| 55 |
+
return this.__options.optimistic;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
__ignoreEval() {
|
| 59 |
+
return this.__options.ignoreEval;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
__isJSXEnabled() {
|
| 63 |
+
return this.__options.jsx === true;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
isGlobalReturn() {
|
| 67 |
+
return this.__options.nodejsScope || this.__options.sourceType === "commonjs";
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
isModule() {
|
| 71 |
+
return this.__options.sourceType === "module";
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
isImpliedStrict() {
|
| 75 |
+
return this.__options.impliedStrict;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
isStrictModeSupported() {
|
| 79 |
+
return this.__options.ecmaVersion >= 5;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Returns appropriate scope for this node.
|
| 83 |
+
__get(node) {
|
| 84 |
+
return this.__nodeToScope.get(node);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Get variables that are declared by the node.
|
| 89 |
+
*
|
| 90 |
+
* "are declared by the node" means the node is same as `Variable.defs[].node` or `Variable.defs[].parent`.
|
| 91 |
+
* If the node declares nothing, this method returns an empty array.
|
| 92 |
+
* CAUTION: This API is experimental. See https://github.com/estools/escope/pull/69 for more details.
|
| 93 |
+
* @param {Espree.Node} node a node to get.
|
| 94 |
+
* @returns {Variable[]} variables that declared by the node.
|
| 95 |
+
*/
|
| 96 |
+
getDeclaredVariables(node) {
|
| 97 |
+
return this.__declaredVariables.get(node) || [];
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* acquire scope from node.
|
| 102 |
+
* @function ScopeManager#acquire
|
| 103 |
+
* @param {Espree.Node} node node for the acquired scope.
|
| 104 |
+
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
|
| 105 |
+
* @returns {Scope?} Scope from node
|
| 106 |
+
*/
|
| 107 |
+
acquire(node, inner) {
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* predicate
|
| 111 |
+
* @param {Scope} testScope scope to test
|
| 112 |
+
* @returns {boolean} predicate
|
| 113 |
+
*/
|
| 114 |
+
function predicate(testScope) {
|
| 115 |
+
if (testScope.type === "function" && testScope.functionExpressionScope) {
|
| 116 |
+
return false;
|
| 117 |
+
}
|
| 118 |
+
return true;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
const scopes = this.__get(node);
|
| 122 |
+
|
| 123 |
+
if (!scopes || scopes.length === 0) {
|
| 124 |
+
return null;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
// Heuristic selection from all scopes.
|
| 128 |
+
// If you would like to get all scopes, please use ScopeManager#acquireAll.
|
| 129 |
+
if (scopes.length === 1) {
|
| 130 |
+
return scopes[0];
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
if (inner) {
|
| 134 |
+
for (let i = scopes.length - 1; i >= 0; --i) {
|
| 135 |
+
const scope = scopes[i];
|
| 136 |
+
|
| 137 |
+
if (predicate(scope)) {
|
| 138 |
+
return scope;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
} else {
|
| 142 |
+
for (let i = 0, iz = scopes.length; i < iz; ++i) {
|
| 143 |
+
const scope = scopes[i];
|
| 144 |
+
|
| 145 |
+
if (predicate(scope)) {
|
| 146 |
+
return scope;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
return null;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/**
|
| 155 |
+
* acquire all scopes from node.
|
| 156 |
+
* @function ScopeManager#acquireAll
|
| 157 |
+
* @param {Espree.Node} node node for the acquired scope.
|
| 158 |
+
* @returns {Scopes?} Scope array
|
| 159 |
+
*/
|
| 160 |
+
acquireAll(node) {
|
| 161 |
+
return this.__get(node);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* release the node.
|
| 166 |
+
* @function ScopeManager#release
|
| 167 |
+
* @param {Espree.Node} node releasing node.
|
| 168 |
+
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
|
| 169 |
+
* @returns {Scope?} upper scope for the node.
|
| 170 |
+
*/
|
| 171 |
+
release(node, inner) {
|
| 172 |
+
const scopes = this.__get(node);
|
| 173 |
+
|
| 174 |
+
if (scopes && scopes.length) {
|
| 175 |
+
const scope = scopes[0].upper;
|
| 176 |
+
|
| 177 |
+
if (!scope) {
|
| 178 |
+
return null;
|
| 179 |
+
}
|
| 180 |
+
return this.acquire(scope.block, inner);
|
| 181 |
+
}
|
| 182 |
+
return null;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
attach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 186 |
+
|
| 187 |
+
detach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 188 |
+
|
| 189 |
+
__nestScope(scope) {
|
| 190 |
+
if (scope instanceof GlobalScope) {
|
| 191 |
+
assert(this.__currentScope === null);
|
| 192 |
+
this.globalScope = scope;
|
| 193 |
+
}
|
| 194 |
+
this.__currentScope = scope;
|
| 195 |
+
return scope;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
__nestGlobalScope(node) {
|
| 199 |
+
return this.__nestScope(new GlobalScope(this, node));
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
__nestBlockScope(node) {
|
| 203 |
+
return this.__nestScope(new BlockScope(this, this.__currentScope, node));
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
__nestFunctionScope(node, isMethodDefinition) {
|
| 207 |
+
return this.__nestScope(new FunctionScope(this, this.__currentScope, node, isMethodDefinition));
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
__nestForScope(node) {
|
| 211 |
+
return this.__nestScope(new ForScope(this, this.__currentScope, node));
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
__nestCatchScope(node) {
|
| 215 |
+
return this.__nestScope(new CatchScope(this, this.__currentScope, node));
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
__nestWithScope(node) {
|
| 219 |
+
return this.__nestScope(new WithScope(this, this.__currentScope, node));
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
__nestClassScope(node) {
|
| 223 |
+
return this.__nestScope(new ClassScope(this, this.__currentScope, node));
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
__nestClassFieldInitializerScope(node) {
|
| 227 |
+
return this.__nestScope(new ClassFieldInitializerScope(this, this.__currentScope, node));
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
__nestClassStaticBlockScope(node) {
|
| 231 |
+
return this.__nestScope(new ClassStaticBlockScope(this, this.__currentScope, node));
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
__nestSwitchScope(node) {
|
| 235 |
+
return this.__nestScope(new SwitchScope(this, this.__currentScope, node));
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
__nestModuleScope(node) {
|
| 239 |
+
return this.__nestScope(new ModuleScope(this, this.__currentScope, node));
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
__nestFunctionExpressionNameScope(node) {
|
| 243 |
+
return this.__nestScope(new FunctionExpressionNameScope(this, this.__currentScope, node));
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
__isES6() {
|
| 247 |
+
return this.__options.ecmaVersion >= 6;
|
| 248 |
+
}
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import estraverse from "estraverse";
|
| 26 |
+
|
| 27 |
+
import Reference from "./reference.js";
|
| 28 |
+
import Variable from "./variable.js";
|
| 29 |
+
import { Definition } from "./definition.js";
|
| 30 |
+
import { assert } from "./assert.js";
|
| 31 |
+
|
| 32 |
+
const { Syntax } = estraverse;
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Test if scope is struct
|
| 36 |
+
* @param {Scope} scope scope
|
| 37 |
+
* @param {Block} block block
|
| 38 |
+
* @param {boolean} isMethodDefinition is method definition
|
| 39 |
+
* @returns {boolean} is strict scope
|
| 40 |
+
*/
|
| 41 |
+
function isStrictScope(scope, block, isMethodDefinition) {
|
| 42 |
+
let body;
|
| 43 |
+
|
| 44 |
+
// When upper scope is exists and strict, inner scope is also strict.
|
| 45 |
+
if (scope.upper && scope.upper.isStrict) {
|
| 46 |
+
return true;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (isMethodDefinition) {
|
| 50 |
+
return true;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if (scope.type === "class" || scope.type === "module") {
|
| 54 |
+
return true;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (scope.type === "block" || scope.type === "switch") {
|
| 58 |
+
return false;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if (scope.type === "function") {
|
| 62 |
+
if (block.type === Syntax.ArrowFunctionExpression && block.body.type !== Syntax.BlockStatement) {
|
| 63 |
+
return false;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if (block.type === Syntax.Program) {
|
| 67 |
+
body = block;
|
| 68 |
+
} else {
|
| 69 |
+
body = block.body;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (!body) {
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
} else if (scope.type === "global") {
|
| 76 |
+
body = block;
|
| 77 |
+
} else {
|
| 78 |
+
return false;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Search for a 'use strict' directive.
|
| 82 |
+
for (let i = 0, iz = body.body.length; i < iz; ++i) {
|
| 83 |
+
const stmt = body.body[i];
|
| 84 |
+
|
| 85 |
+
/*
|
| 86 |
+
* Check if the current statement is a directive.
|
| 87 |
+
* If it isn't, then we're past the directive prologue
|
| 88 |
+
* so stop the search because directives cannot
|
| 89 |
+
* appear after this point.
|
| 90 |
+
*
|
| 91 |
+
* Some parsers set `directive:null` on non-directive
|
| 92 |
+
* statements, so the `typeof` check is safer than
|
| 93 |
+
* checking for property existence.
|
| 94 |
+
*/
|
| 95 |
+
if (typeof stmt.directive !== "string") {
|
| 96 |
+
break;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if (stmt.directive === "use strict") {
|
| 100 |
+
return true;
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
return false;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Register scope
|
| 109 |
+
* @param {ScopeManager} scopeManager scope manager
|
| 110 |
+
* @param {Scope} scope scope
|
| 111 |
+
* @returns {void}
|
| 112 |
+
*/
|
| 113 |
+
function registerScope(scopeManager, scope) {
|
| 114 |
+
scopeManager.scopes.push(scope);
|
| 115 |
+
|
| 116 |
+
const scopes = scopeManager.__nodeToScope.get(scope.block);
|
| 117 |
+
|
| 118 |
+
if (scopes) {
|
| 119 |
+
scopes.push(scope);
|
| 120 |
+
} else {
|
| 121 |
+
scopeManager.__nodeToScope.set(scope.block, [scope]);
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Should be statically
|
| 127 |
+
* @param {Object} def def
|
| 128 |
+
* @returns {boolean} should be statically
|
| 129 |
+
*/
|
| 130 |
+
function shouldBeStatically(def) {
|
| 131 |
+
return (
|
| 132 |
+
(def.type === Variable.ClassName) ||
|
| 133 |
+
(def.type === Variable.Variable && def.parent.kind !== "var")
|
| 134 |
+
);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* @constructor Scope
|
| 139 |
+
*/
|
| 140 |
+
class Scope {
|
| 141 |
+
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* One of "global", "module", "function", "function-expression-name", "block", "switch", "catch", "with", "for",
|
| 145 |
+
* "class", "class-field-initializer", "class-static-block".
|
| 146 |
+
* @member {string} Scope#type
|
| 147 |
+
*/
|
| 148 |
+
this.type = type;
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* The scoped {@link Variable}s of this scope, as <code>{ Variable.name
|
| 152 |
+
* : Variable }</code>.
|
| 153 |
+
* @member {Map} Scope#set
|
| 154 |
+
*/
|
| 155 |
+
this.set = new Map();
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* The tainted variables of this scope, as <code>{ Variable.name :
|
| 159 |
+
* boolean }</code>.
|
| 160 |
+
* @member {Map} Scope#taints
|
| 161 |
+
*/
|
| 162 |
+
this.taints = new Map();
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Generally, through the lexical scoping of JS you can always know
|
| 166 |
+
* which variable an identifier in the source code refers to. There are
|
| 167 |
+
* a few exceptions to this rule. With 'global' and 'with' scopes you
|
| 168 |
+
* can only decide at runtime which variable a reference refers to.
|
| 169 |
+
* Moreover, if 'eval()' is used in a scope, it might introduce new
|
| 170 |
+
* bindings in this or its parent scopes.
|
| 171 |
+
* All those scopes are considered 'dynamic'.
|
| 172 |
+
* @member {boolean} Scope#dynamic
|
| 173 |
+
*/
|
| 174 |
+
this.dynamic = this.type === "global" || this.type === "with";
|
| 175 |
+
|
| 176 |
+
/**
|
| 177 |
+
* A reference to the scope-defining syntax node.
|
| 178 |
+
* @member {espree.Node} Scope#block
|
| 179 |
+
*/
|
| 180 |
+
this.block = block;
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* The {@link Reference|references} that are not resolved with this scope.
|
| 184 |
+
* @member {Reference[]} Scope#through
|
| 185 |
+
*/
|
| 186 |
+
this.through = [];
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* The scoped {@link Variable}s of this scope. In the case of a
|
| 190 |
+
* 'function' scope this includes the automatic argument <em>arguments</em> as
|
| 191 |
+
* its first element, as well as all further formal arguments.
|
| 192 |
+
* @member {Variable[]} Scope#variables
|
| 193 |
+
*/
|
| 194 |
+
this.variables = [];
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* Any variable {@link Reference|reference} found in this scope. This
|
| 198 |
+
* includes occurrences of local variables as well as variables from
|
| 199 |
+
* parent scopes (including the global scope). For local variables
|
| 200 |
+
* this also includes defining occurrences (like in a 'var' statement).
|
| 201 |
+
* In a 'function' scope this does not include the occurrences of the
|
| 202 |
+
* formal parameter in the parameter list.
|
| 203 |
+
* @member {Reference[]} Scope#references
|
| 204 |
+
*/
|
| 205 |
+
this.references = [];
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* For 'global' and 'function' scopes, this is a self-reference. For
|
| 209 |
+
* other scope types this is the <em>variableScope</em> value of the
|
| 210 |
+
* parent scope.
|
| 211 |
+
* @member {Scope} Scope#variableScope
|
| 212 |
+
*/
|
| 213 |
+
this.variableScope =
|
| 214 |
+
this.type === "global" ||
|
| 215 |
+
this.type === "module" ||
|
| 216 |
+
this.type === "function" ||
|
| 217 |
+
this.type === "class-field-initializer" ||
|
| 218 |
+
this.type === "class-static-block"
|
| 219 |
+
? this
|
| 220 |
+
: upperScope.variableScope;
|
| 221 |
+
|
| 222 |
+
/**
|
| 223 |
+
* Whether this scope is created by a FunctionExpression.
|
| 224 |
+
* @member {boolean} Scope#functionExpressionScope
|
| 225 |
+
*/
|
| 226 |
+
this.functionExpressionScope = false;
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* Whether this is a scope that contains an 'eval()' invocation.
|
| 230 |
+
* @member {boolean} Scope#directCallToEvalScope
|
| 231 |
+
*/
|
| 232 |
+
this.directCallToEvalScope = false;
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* @member {boolean} Scope#thisFound
|
| 236 |
+
*/
|
| 237 |
+
this.thisFound = false;
|
| 238 |
+
|
| 239 |
+
this.__left = [];
|
| 240 |
+
|
| 241 |
+
/**
|
| 242 |
+
* Reference to the parent {@link Scope|scope}.
|
| 243 |
+
* @member {Scope} Scope#upper
|
| 244 |
+
*/
|
| 245 |
+
this.upper = upperScope;
|
| 246 |
+
|
| 247 |
+
/**
|
| 248 |
+
* Whether 'use strict' is in effect in this scope.
|
| 249 |
+
* @member {boolean} Scope#isStrict
|
| 250 |
+
*/
|
| 251 |
+
this.isStrict = scopeManager.isStrictModeSupported()
|
| 252 |
+
? isStrictScope(this, block, isMethodDefinition)
|
| 253 |
+
: false;
|
| 254 |
+
|
| 255 |
+
/**
|
| 256 |
+
* List of nested {@link Scope}s.
|
| 257 |
+
* @member {Scope[]} Scope#childScopes
|
| 258 |
+
*/
|
| 259 |
+
this.childScopes = [];
|
| 260 |
+
if (this.upper) {
|
| 261 |
+
this.upper.childScopes.push(this);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
this.__declaredVariables = scopeManager.__declaredVariables;
|
| 265 |
+
|
| 266 |
+
registerScope(scopeManager, this);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
__shouldStaticallyClose(scopeManager) {
|
| 270 |
+
return (!this.dynamic || scopeManager.__isOptimistic());
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
__shouldStaticallyCloseForGlobal(ref) {
|
| 274 |
+
|
| 275 |
+
// On global scope, let/const/class declarations should be resolved statically.
|
| 276 |
+
const name = ref.identifier.name;
|
| 277 |
+
|
| 278 |
+
if (!this.set.has(name)) {
|
| 279 |
+
return false;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
const variable = this.set.get(name);
|
| 283 |
+
const defs = variable.defs;
|
| 284 |
+
|
| 285 |
+
return defs.length > 0 && defs.every(shouldBeStatically);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
__staticCloseRef(ref) {
|
| 289 |
+
if (!this.__resolve(ref)) {
|
| 290 |
+
this.__delegateToUpperScope(ref);
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
__dynamicCloseRef(ref) {
|
| 295 |
+
|
| 296 |
+
// notify all names are through to global
|
| 297 |
+
let current = this;
|
| 298 |
+
|
| 299 |
+
do {
|
| 300 |
+
current.through.push(ref);
|
| 301 |
+
current = current.upper;
|
| 302 |
+
} while (current);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
__globalCloseRef(ref) {
|
| 306 |
+
|
| 307 |
+
// let/const/class declarations should be resolved statically.
|
| 308 |
+
// others should be resolved dynamically.
|
| 309 |
+
if (this.__shouldStaticallyCloseForGlobal(ref)) {
|
| 310 |
+
this.__staticCloseRef(ref);
|
| 311 |
+
} else {
|
| 312 |
+
this.__dynamicCloseRef(ref);
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
__close(scopeManager) {
|
| 317 |
+
let closeRef;
|
| 318 |
+
|
| 319 |
+
if (this.__shouldStaticallyClose(scopeManager)) {
|
| 320 |
+
closeRef = this.__staticCloseRef;
|
| 321 |
+
} else if (this.type !== "global") {
|
| 322 |
+
closeRef = this.__dynamicCloseRef;
|
| 323 |
+
} else {
|
| 324 |
+
closeRef = this.__globalCloseRef;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
// Try Resolving all references in this scope.
|
| 328 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 329 |
+
const ref = this.__left[i];
|
| 330 |
+
|
| 331 |
+
closeRef.call(this, ref);
|
| 332 |
+
}
|
| 333 |
+
this.__left = null;
|
| 334 |
+
|
| 335 |
+
return this.upper;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
// To override by function scopes.
|
| 339 |
+
// References in default parameters isn't resolved to variables which are in their function body.
|
| 340 |
+
__isValidResolution(ref, variable) { // eslint-disable-line class-methods-use-this, no-unused-vars -- Desired as instance method with signature
|
| 341 |
+
return true;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
__resolve(ref) {
|
| 345 |
+
const name = ref.identifier.name;
|
| 346 |
+
|
| 347 |
+
if (!this.set.has(name)) {
|
| 348 |
+
return false;
|
| 349 |
+
}
|
| 350 |
+
const variable = this.set.get(name);
|
| 351 |
+
|
| 352 |
+
if (!this.__isValidResolution(ref, variable)) {
|
| 353 |
+
return false;
|
| 354 |
+
}
|
| 355 |
+
variable.references.push(ref);
|
| 356 |
+
variable.stack = variable.stack && ref.from.variableScope === this.variableScope;
|
| 357 |
+
if (ref.tainted) {
|
| 358 |
+
variable.tainted = true;
|
| 359 |
+
this.taints.set(variable.name, true);
|
| 360 |
+
}
|
| 361 |
+
ref.resolved = variable;
|
| 362 |
+
|
| 363 |
+
return true;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
__delegateToUpperScope(ref) {
|
| 367 |
+
if (this.upper) {
|
| 368 |
+
this.upper.__left.push(ref);
|
| 369 |
+
}
|
| 370 |
+
this.through.push(ref);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
__addDeclaredVariablesOfNode(variable, node) {
|
| 374 |
+
if (node === null || node === void 0) {
|
| 375 |
+
return;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
let variables = this.__declaredVariables.get(node);
|
| 379 |
+
|
| 380 |
+
if (variables === null || variables === void 0) {
|
| 381 |
+
variables = [];
|
| 382 |
+
this.__declaredVariables.set(node, variables);
|
| 383 |
+
}
|
| 384 |
+
if (!variables.includes(variable)) {
|
| 385 |
+
variables.push(variable);
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
__defineGeneric(name, set, variables, node, def) {
|
| 390 |
+
let variable;
|
| 391 |
+
|
| 392 |
+
variable = set.get(name);
|
| 393 |
+
if (!variable) {
|
| 394 |
+
variable = new Variable(name, this);
|
| 395 |
+
set.set(name, variable);
|
| 396 |
+
variables.push(variable);
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
if (def) {
|
| 400 |
+
variable.defs.push(def);
|
| 401 |
+
this.__addDeclaredVariablesOfNode(variable, def.node);
|
| 402 |
+
this.__addDeclaredVariablesOfNode(variable, def.parent);
|
| 403 |
+
}
|
| 404 |
+
if (node) {
|
| 405 |
+
variable.identifiers.push(node);
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
__define(node, def) {
|
| 410 |
+
if (node && node.type === Syntax.Identifier) {
|
| 411 |
+
this.__defineGeneric(
|
| 412 |
+
node.name,
|
| 413 |
+
this.set,
|
| 414 |
+
this.variables,
|
| 415 |
+
node,
|
| 416 |
+
def
|
| 417 |
+
);
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
__referencing(node, assign, writeExpr, maybeImplicitGlobal, partial, init) {
|
| 422 |
+
|
| 423 |
+
// because Array element may be null
|
| 424 |
+
if (!node || (node.type !== Syntax.Identifier && node.type !== "JSXIdentifier")) {
|
| 425 |
+
return;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
// Specially handle like `this`.
|
| 429 |
+
if (node.name === "super") {
|
| 430 |
+
return;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
const ref = new Reference(node, this, assign || Reference.READ, writeExpr, maybeImplicitGlobal, !!partial, !!init);
|
| 434 |
+
|
| 435 |
+
this.references.push(ref);
|
| 436 |
+
this.__left.push(ref);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
__detectEval() {
|
| 440 |
+
let current = this;
|
| 441 |
+
|
| 442 |
+
this.directCallToEvalScope = true;
|
| 443 |
+
do {
|
| 444 |
+
current.dynamic = true;
|
| 445 |
+
current = current.upper;
|
| 446 |
+
} while (current);
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
__detectThis() {
|
| 450 |
+
this.thisFound = true;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
__isClosed() {
|
| 454 |
+
return this.__left === null;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
/**
|
| 458 |
+
* returns resolved {Reference}
|
| 459 |
+
* @function Scope#resolve
|
| 460 |
+
* @param {Espree.Identifier} ident identifier to be resolved.
|
| 461 |
+
* @returns {Reference} reference
|
| 462 |
+
*/
|
| 463 |
+
resolve(ident) {
|
| 464 |
+
let ref, i, iz;
|
| 465 |
+
|
| 466 |
+
assert(this.__isClosed(), "Scope should be closed.");
|
| 467 |
+
assert(ident.type === Syntax.Identifier, "Target should be identifier.");
|
| 468 |
+
for (i = 0, iz = this.references.length; i < iz; ++i) {
|
| 469 |
+
ref = this.references[i];
|
| 470 |
+
if (ref.identifier === ident) {
|
| 471 |
+
return ref;
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
return null;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
/**
|
| 478 |
+
* returns this scope is static
|
| 479 |
+
* @function Scope#isStatic
|
| 480 |
+
* @returns {boolean} static
|
| 481 |
+
*/
|
| 482 |
+
isStatic() {
|
| 483 |
+
return !this.dynamic;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
/**
|
| 487 |
+
* returns this scope has materialized arguments
|
| 488 |
+
* @function Scope#isArgumentsMaterialized
|
| 489 |
+
* @returns {boolean} arguemnts materialized
|
| 490 |
+
*/
|
| 491 |
+
isArgumentsMaterialized() { // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 492 |
+
return true;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
/**
|
| 496 |
+
* returns this scope has materialized `this` reference
|
| 497 |
+
* @function Scope#isThisMaterialized
|
| 498 |
+
* @returns {boolean} this materialized
|
| 499 |
+
*/
|
| 500 |
+
isThisMaterialized() { // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 501 |
+
return true;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
isUsedName(name) {
|
| 505 |
+
if (this.set.has(name)) {
|
| 506 |
+
return true;
|
| 507 |
+
}
|
| 508 |
+
for (let i = 0, iz = this.through.length; i < iz; ++i) {
|
| 509 |
+
if (this.through[i].identifier.name === name) {
|
| 510 |
+
return true;
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
return false;
|
| 514 |
+
}
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
/**
|
| 518 |
+
* Global scope.
|
| 519 |
+
*/
|
| 520 |
+
class GlobalScope extends Scope {
|
| 521 |
+
constructor(scopeManager, block) {
|
| 522 |
+
super(scopeManager, "global", null, block, false);
|
| 523 |
+
this.implicit = {
|
| 524 |
+
set: new Map(),
|
| 525 |
+
variables: [],
|
| 526 |
+
|
| 527 |
+
/**
|
| 528 |
+
* List of {@link Reference}s that are left to be resolved (i.e. which
|
| 529 |
+
* need to be linked to the variable they refer to).
|
| 530 |
+
* @member {Reference[]} Scope#implicit#left
|
| 531 |
+
*/
|
| 532 |
+
left: []
|
| 533 |
+
};
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
__close(scopeManager) {
|
| 537 |
+
const implicit = [];
|
| 538 |
+
|
| 539 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 540 |
+
const ref = this.__left[i];
|
| 541 |
+
|
| 542 |
+
if (ref.__maybeImplicitGlobal && !this.set.has(ref.identifier.name)) {
|
| 543 |
+
implicit.push(ref.__maybeImplicitGlobal);
|
| 544 |
+
}
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
// create an implicit global variable from assignment expression
|
| 548 |
+
for (let i = 0, iz = implicit.length; i < iz; ++i) {
|
| 549 |
+
const info = implicit[i];
|
| 550 |
+
|
| 551 |
+
this.__defineImplicit(info.pattern,
|
| 552 |
+
new Definition(
|
| 553 |
+
Variable.ImplicitGlobalVariable,
|
| 554 |
+
info.pattern,
|
| 555 |
+
info.node,
|
| 556 |
+
null,
|
| 557 |
+
null,
|
| 558 |
+
null
|
| 559 |
+
));
|
| 560 |
+
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
this.implicit.left = this.__left;
|
| 564 |
+
|
| 565 |
+
return super.__close(scopeManager);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
__defineImplicit(node, def) {
|
| 569 |
+
if (node && node.type === Syntax.Identifier) {
|
| 570 |
+
this.__defineGeneric(
|
| 571 |
+
node.name,
|
| 572 |
+
this.implicit.set,
|
| 573 |
+
this.implicit.variables,
|
| 574 |
+
node,
|
| 575 |
+
def
|
| 576 |
+
);
|
| 577 |
+
}
|
| 578 |
+
}
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
/**
|
| 582 |
+
* Module scope.
|
| 583 |
+
*/
|
| 584 |
+
class ModuleScope extends Scope {
|
| 585 |
+
constructor(scopeManager, upperScope, block) {
|
| 586 |
+
super(scopeManager, "module", upperScope, block, false);
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
/**
|
| 591 |
+
* Function expression name scope.
|
| 592 |
+
*/
|
| 593 |
+
class FunctionExpressionNameScope extends Scope {
|
| 594 |
+
constructor(scopeManager, upperScope, block) {
|
| 595 |
+
super(scopeManager, "function-expression-name", upperScope, block, false);
|
| 596 |
+
this.__define(block.id,
|
| 597 |
+
new Definition(
|
| 598 |
+
Variable.FunctionName,
|
| 599 |
+
block.id,
|
| 600 |
+
block,
|
| 601 |
+
null,
|
| 602 |
+
null,
|
| 603 |
+
null
|
| 604 |
+
));
|
| 605 |
+
this.functionExpressionScope = true;
|
| 606 |
+
}
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
/**
|
| 610 |
+
* Catch scope.
|
| 611 |
+
*/
|
| 612 |
+
class CatchScope extends Scope {
|
| 613 |
+
constructor(scopeManager, upperScope, block) {
|
| 614 |
+
super(scopeManager, "catch", upperScope, block, false);
|
| 615 |
+
}
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
/**
|
| 619 |
+
* With statement scope.
|
| 620 |
+
*/
|
| 621 |
+
class WithScope extends Scope {
|
| 622 |
+
constructor(scopeManager, upperScope, block) {
|
| 623 |
+
super(scopeManager, "with", upperScope, block, false);
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
__close(scopeManager) {
|
| 627 |
+
if (this.__shouldStaticallyClose(scopeManager)) {
|
| 628 |
+
return super.__close(scopeManager);
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 632 |
+
const ref = this.__left[i];
|
| 633 |
+
|
| 634 |
+
ref.tainted = true;
|
| 635 |
+
this.__delegateToUpperScope(ref);
|
| 636 |
+
}
|
| 637 |
+
this.__left = null;
|
| 638 |
+
|
| 639 |
+
return this.upper;
|
| 640 |
+
}
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
/**
|
| 644 |
+
* Block scope.
|
| 645 |
+
*/
|
| 646 |
+
class BlockScope extends Scope {
|
| 647 |
+
constructor(scopeManager, upperScope, block) {
|
| 648 |
+
super(scopeManager, "block", upperScope, block, false);
|
| 649 |
+
}
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
/**
|
| 653 |
+
* Switch scope.
|
| 654 |
+
*/
|
| 655 |
+
class SwitchScope extends Scope {
|
| 656 |
+
constructor(scopeManager, upperScope, block) {
|
| 657 |
+
super(scopeManager, "switch", upperScope, block, false);
|
| 658 |
+
}
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
/**
|
| 662 |
+
* Function scope.
|
| 663 |
+
*/
|
| 664 |
+
class FunctionScope extends Scope {
|
| 665 |
+
constructor(scopeManager, upperScope, block, isMethodDefinition) {
|
| 666 |
+
super(scopeManager, "function", upperScope, block, isMethodDefinition);
|
| 667 |
+
|
| 668 |
+
// section 9.2.13, FunctionDeclarationInstantiation.
|
| 669 |
+
// NOTE Arrow functions never have an arguments objects.
|
| 670 |
+
if (this.block.type !== Syntax.ArrowFunctionExpression) {
|
| 671 |
+
this.__defineArguments();
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
isArgumentsMaterialized() {
|
| 676 |
+
|
| 677 |
+
// TODO(Constellation)
|
| 678 |
+
// We can more aggressive on this condition like this.
|
| 679 |
+
//
|
| 680 |
+
// function t() {
|
| 681 |
+
// // arguments of t is always hidden.
|
| 682 |
+
// function arguments() {
|
| 683 |
+
// }
|
| 684 |
+
// }
|
| 685 |
+
if (this.block.type === Syntax.ArrowFunctionExpression) {
|
| 686 |
+
return false;
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
if (!this.isStatic()) {
|
| 690 |
+
return true;
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
const variable = this.set.get("arguments");
|
| 694 |
+
|
| 695 |
+
assert(variable, "Always have arguments variable.");
|
| 696 |
+
return variable.tainted || variable.references.length !== 0;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
isThisMaterialized() {
|
| 700 |
+
if (!this.isStatic()) {
|
| 701 |
+
return true;
|
| 702 |
+
}
|
| 703 |
+
return this.thisFound;
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
__defineArguments() {
|
| 707 |
+
this.__defineGeneric(
|
| 708 |
+
"arguments",
|
| 709 |
+
this.set,
|
| 710 |
+
this.variables,
|
| 711 |
+
null,
|
| 712 |
+
null
|
| 713 |
+
);
|
| 714 |
+
this.taints.set("arguments", true);
|
| 715 |
+
}
|
| 716 |
+
|
| 717 |
+
// References in default parameters isn't resolved to variables which are in their function body.
|
| 718 |
+
// const x = 1
|
| 719 |
+
// function f(a = x) { // This `x` is resolved to the `x` in the outer scope.
|
| 720 |
+
// const x = 2
|
| 721 |
+
// console.log(a)
|
| 722 |
+
// }
|
| 723 |
+
__isValidResolution(ref, variable) {
|
| 724 |
+
|
| 725 |
+
// If `options.nodejsScope` is true, `this.block` becomes a Program node.
|
| 726 |
+
if (this.block.type === "Program") {
|
| 727 |
+
return true;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
const bodyStart = this.block.body.range[0];
|
| 731 |
+
|
| 732 |
+
// It's invalid resolution in the following case:
|
| 733 |
+
return !(
|
| 734 |
+
variable.scope === this &&
|
| 735 |
+
ref.identifier.range[0] < bodyStart && // the reference is in the parameter part.
|
| 736 |
+
variable.defs.every(d => d.name.range[0] >= bodyStart) // the variable is in the body.
|
| 737 |
+
);
|
| 738 |
+
}
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
/**
|
| 742 |
+
* Scope of for, for-in, and for-of statements.
|
| 743 |
+
*/
|
| 744 |
+
class ForScope extends Scope {
|
| 745 |
+
constructor(scopeManager, upperScope, block) {
|
| 746 |
+
super(scopeManager, "for", upperScope, block, false);
|
| 747 |
+
}
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
/**
|
| 751 |
+
* Class scope.
|
| 752 |
+
*/
|
| 753 |
+
class ClassScope extends Scope {
|
| 754 |
+
constructor(scopeManager, upperScope, block) {
|
| 755 |
+
super(scopeManager, "class", upperScope, block, false);
|
| 756 |
+
}
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
/**
|
| 760 |
+
* Class field initializer scope.
|
| 761 |
+
*/
|
| 762 |
+
class ClassFieldInitializerScope extends Scope {
|
| 763 |
+
constructor(scopeManager, upperScope, block) {
|
| 764 |
+
super(scopeManager, "class-field-initializer", upperScope, block, true);
|
| 765 |
+
}
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
/**
|
| 769 |
+
* Class static block scope.
|
| 770 |
+
*/
|
| 771 |
+
class ClassStaticBlockScope extends Scope {
|
| 772 |
+
constructor(scopeManager, upperScope, block) {
|
| 773 |
+
super(scopeManager, "class-static-block", upperScope, block, true);
|
| 774 |
+
}
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
export {
|
| 778 |
+
Scope,
|
| 779 |
+
GlobalScope,
|
| 780 |
+
ModuleScope,
|
| 781 |
+
FunctionExpressionNameScope,
|
| 782 |
+
CatchScope,
|
| 783 |
+
WithScope,
|
| 784 |
+
BlockScope,
|
| 785 |
+
SwitchScope,
|
| 786 |
+
FunctionScope,
|
| 787 |
+
ForScope,
|
| 788 |
+
ClassScope,
|
| 789 |
+
ClassFieldInitializerScope,
|
| 790 |
+
ClassStaticBlockScope
|
| 791 |
+
};
|
| 792 |
+
|
| 793 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/variable.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* A Variable represents a locally scoped identifier. These include arguments to
|
| 27 |
+
* functions.
|
| 28 |
+
* @constructor Variable
|
| 29 |
+
*/
|
| 30 |
+
class Variable {
|
| 31 |
+
constructor(name, scope) {
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* The variable name, as given in the source code.
|
| 35 |
+
* @member {string} Variable#name
|
| 36 |
+
*/
|
| 37 |
+
this.name = name;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* List of defining occurrences of this variable (like in 'var ...'
|
| 41 |
+
* statements or as parameter), as AST nodes.
|
| 42 |
+
* @member {espree.Identifier[]} Variable#identifiers
|
| 43 |
+
*/
|
| 44 |
+
this.identifiers = [];
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* List of {@link Reference|references} of this variable (excluding parameter entries)
|
| 48 |
+
* in its defining scope and all nested scopes. For defining
|
| 49 |
+
* occurrences only see {@link Variable#defs}.
|
| 50 |
+
* @member {Reference[]} Variable#references
|
| 51 |
+
*/
|
| 52 |
+
this.references = [];
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* List of defining occurrences of this variable (like in 'var ...'
|
| 56 |
+
* statements or as parameter), as custom objects.
|
| 57 |
+
* @member {Definition[]} Variable#defs
|
| 58 |
+
*/
|
| 59 |
+
this.defs = [];
|
| 60 |
+
|
| 61 |
+
this.tainted = false;
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Whether this is a stack variable.
|
| 65 |
+
* @member {boolean} Variable#stack
|
| 66 |
+
*/
|
| 67 |
+
this.stack = true;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Reference to the enclosing Scope.
|
| 71 |
+
* @member {Scope} Variable#scope
|
| 72 |
+
*/
|
| 73 |
+
this.scope = scope;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
Variable.CatchClause = "CatchClause";
|
| 78 |
+
Variable.Parameter = "Parameter";
|
| 79 |
+
Variable.FunctionName = "FunctionName";
|
| 80 |
+
Variable.ClassName = "ClassName";
|
| 81 |
+
Variable.Variable = "Variable";
|
| 82 |
+
Variable.ImportBinding = "ImportBinding";
|
| 83 |
+
Variable.ImplicitGlobalVariable = "ImplicitGlobalVariable";
|
| 84 |
+
|
| 85 |
+
export default Variable;
|
| 86 |
+
|
| 87 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/version.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const version = "8.4.0";
|
| 2 |
+
|
| 3 |
+
export default version;
|
node_modules/eslint-scope/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-scope",
|
| 3 |
+
"description": "ECMAScript scope analyzer for ESLint",
|
| 4 |
+
"homepage": "https://github.com/eslint/js/blob/main/packages/eslint-scope/README.md",
|
| 5 |
+
"main": "./dist/eslint-scope.cjs",
|
| 6 |
+
"type": "module",
|
| 7 |
+
"exports": {
|
| 8 |
+
".": {
|
| 9 |
+
"import": "./lib/index.js",
|
| 10 |
+
"require": "./dist/eslint-scope.cjs"
|
| 11 |
+
},
|
| 12 |
+
"./package.json": "./package.json"
|
| 13 |
+
},
|
| 14 |
+
"version": "8.4.0",
|
| 15 |
+
"engines": {
|
| 16 |
+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
| 17 |
+
},
|
| 18 |
+
"repository": {
|
| 19 |
+
"type": "git",
|
| 20 |
+
"url": "https://github.com/eslint/js.git",
|
| 21 |
+
"directory": "packages/eslint-scope"
|
| 22 |
+
},
|
| 23 |
+
"funding": "https://opencollective.com/eslint",
|
| 24 |
+
"keywords": [
|
| 25 |
+
"eslint"
|
| 26 |
+
],
|
| 27 |
+
"bugs": {
|
| 28 |
+
"url": "https://github.com/eslint/js/issues"
|
| 29 |
+
},
|
| 30 |
+
"license": "BSD-2-Clause",
|
| 31 |
+
"scripts": {
|
| 32 |
+
"build": "rollup -c",
|
| 33 |
+
"build:update-version": "node tools/update-version.js",
|
| 34 |
+
"prepublishOnly": "npm run build:update-version && npm run build",
|
| 35 |
+
"pretest": "npm run build",
|
| 36 |
+
"release:generate:latest": "eslint-generate-release",
|
| 37 |
+
"release:generate:alpha": "eslint-generate-prerelease alpha",
|
| 38 |
+
"release:generate:beta": "eslint-generate-prerelease beta",
|
| 39 |
+
"release:generate:rc": "eslint-generate-prerelease rc",
|
| 40 |
+
"release:publish": "eslint-publish-release",
|
| 41 |
+
"test": "node Makefile.js test"
|
| 42 |
+
},
|
| 43 |
+
"files": [
|
| 44 |
+
"LICENSE",
|
| 45 |
+
"README.md",
|
| 46 |
+
"lib",
|
| 47 |
+
"dist/eslint-scope.cjs"
|
| 48 |
+
],
|
| 49 |
+
"dependencies": {
|
| 50 |
+
"esrecurse": "^4.3.0",
|
| 51 |
+
"estraverse": "^5.2.0"
|
| 52 |
+
},
|
| 53 |
+
"devDependencies": {
|
| 54 |
+
"@typescript-eslint/parser": "^8.7.0",
|
| 55 |
+
"chai": "^4.3.4",
|
| 56 |
+
"eslint-release": "^3.2.0",
|
| 57 |
+
"eslint-visitor-keys": "^4.2.1",
|
| 58 |
+
"espree": "^10.4.0",
|
| 59 |
+
"npm-license": "^0.3.3",
|
| 60 |
+
"rollup": "^2.52.7",
|
| 61 |
+
"shelljs": "^0.8.5",
|
| 62 |
+
"typescript": "^5.4.2"
|
| 63 |
+
}
|
| 64 |
+
}
|
node_modules/eslint-visitor-keys/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright contributors
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
node_modules/eslint-visitor-keys/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# eslint-visitor-keys
|
| 2 |
+
|
| 3 |
+
[](https://www.npmjs.com/package/eslint-visitor-keys)
|
| 4 |
+
[](http://www.npmtrends.com/eslint-visitor-keys)
|
| 5 |
+
[](https://github.com/eslint/js/actions)
|
| 6 |
+
|
| 7 |
+
Constants and utilities about visitor keys to traverse AST.
|
| 8 |
+
|
| 9 |
+
## 💿 Installation
|
| 10 |
+
|
| 11 |
+
Use [npm] to install.
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
$ npm install eslint-visitor-keys
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
### Requirements
|
| 18 |
+
|
| 19 |
+
- [Node.js] `^18.18.0`, `^20.9.0`, or `>=21.1.0`
|
| 20 |
+
|
| 21 |
+
## 📖 Usage
|
| 22 |
+
|
| 23 |
+
To use in an ESM file:
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
import * as evk from "eslint-visitor-keys"
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
To use in a CommonJS file:
|
| 30 |
+
|
| 31 |
+
```js
|
| 32 |
+
const evk = require("eslint-visitor-keys")
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### evk.KEYS
|
| 36 |
+
|
| 37 |
+
> type: `{ [type: string]: string[] | undefined }`
|
| 38 |
+
|
| 39 |
+
Visitor keys. This keys are frozen.
|
| 40 |
+
|
| 41 |
+
This is an object. Keys are the type of [ESTree] nodes. Their values are an array of property names which have child nodes.
|
| 42 |
+
|
| 43 |
+
For example:
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### evk.getKeys(node)
|
| 50 |
+
|
| 51 |
+
> type: `(node: object) => string[]`
|
| 52 |
+
|
| 53 |
+
Get the visitor keys of a given AST node.
|
| 54 |
+
|
| 55 |
+
This is similar to `Object.keys(node)` of ES Standard, but some keys are excluded: `parent`, `leadingComments`, `trailingComments`, and names which start with `_`.
|
| 56 |
+
|
| 57 |
+
This will be used to traverse unknown nodes.
|
| 58 |
+
|
| 59 |
+
For example:
|
| 60 |
+
|
| 61 |
+
```js
|
| 62 |
+
const node = {
|
| 63 |
+
type: "AssignmentExpression",
|
| 64 |
+
left: { type: "Identifier", name: "foo" },
|
| 65 |
+
right: { type: "Literal", value: 0 }
|
| 66 |
+
}
|
| 67 |
+
console.log(evk.getKeys(node)) // → ["type", "left", "right"]
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### evk.unionWith(additionalKeys)
|
| 71 |
+
|
| 72 |
+
> type: `(additionalKeys: object) => { [type: string]: string[] | undefined }`
|
| 73 |
+
|
| 74 |
+
Make the union set with `evk.KEYS` and the given keys.
|
| 75 |
+
|
| 76 |
+
- The order of keys is, `additionalKeys` is at first, then `evk.KEYS` is concatenated after that.
|
| 77 |
+
- It removes duplicated keys as keeping the first one.
|
| 78 |
+
|
| 79 |
+
For example:
|
| 80 |
+
|
| 81 |
+
```js
|
| 82 |
+
console.log(evk.unionWith({
|
| 83 |
+
MethodDefinition: ["decorators"]
|
| 84 |
+
})) // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## 📰 Change log
|
| 88 |
+
|
| 89 |
+
See [GitHub releases](https://github.com/eslint/js/releases).
|
| 90 |
+
|
| 91 |
+
## 🍻 Contributing
|
| 92 |
+
|
| 93 |
+
Welcome. See [ESLint contribution guidelines](https://eslint.org/docs/developer-guide/contributing/).
|
| 94 |
+
|
| 95 |
+
### Development commands
|
| 96 |
+
|
| 97 |
+
- `npm test` runs tests and measures code coverage.
|
| 98 |
+
- `npm run lint` checks source codes with ESLint.
|
| 99 |
+
- `npm run test:open-coverage` opens the code coverage report of the previous test with your default browser.
|
| 100 |
+
|
| 101 |
+
[npm]: https://www.npmjs.com/
|
| 102 |
+
[Node.js]: https://nodejs.org/
|
| 103 |
+
[ESTree]: https://github.com/estree/estree
|
| 104 |
+
|
| 105 |
+
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
| 106 |
+
<!--sponsorsstart-->
|
| 107 |
+
## Sponsors
|
| 108 |
+
|
| 109 |
+
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
| 110 |
+
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
| 111 |
+
|
| 112 |
+
<h3>Diamond Sponsors</h3>
|
| 113 |
+
<p><a href="https://www.ag-grid.com/"><img src="https://images.opencollective.com/ag-grid/bec0580/logo.png" alt="AG Grid" height="128"></a></p><h3>Platinum Sponsors</h3>
|
| 114 |
+
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
|
| 115 |
+
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
|
| 116 |
+
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
| 117 |
+
<p><a href="https://sentry.io"><img src="https://github.com/getsentry.png" alt="Sentry" height="32"></a> <a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nolebase.ayaka.io"><img src="https://avatars.githubusercontent.com/u/11081491" alt="Neko" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="LambdaTest" height="32"></a></p>
|
| 118 |
+
<h3>Technology Sponsors</h3>
|
| 119 |
+
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
| 120 |
+
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
| 121 |
+
<!--sponsorsend-->
|
node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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2 |
+
|
| 3 |
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
| 4 |
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
| 5 |
+
*/
|
| 6 |
+
/**
|
| 7 |
+
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
|
| 8 |
+
*/
|
| 9 |
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly string[]`. TODO: check why */
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* @type {VisitorKeys}
|
| 13 |
+
*/
|
| 14 |
+
const KEYS = {
|
| 15 |
+
ArrayExpression: [
|
| 16 |
+
"elements"
|
| 17 |
+
],
|
| 18 |
+
ArrayPattern: [
|
| 19 |
+
"elements"
|
| 20 |
+
],
|
| 21 |
+
ArrowFunctionExpression: [
|
| 22 |
+
"params",
|
| 23 |
+
"body"
|
| 24 |
+
],
|
| 25 |
+
AssignmentExpression: [
|
| 26 |
+
"left",
|
| 27 |
+
"right"
|
| 28 |
+
],
|
| 29 |
+
AssignmentPattern: [
|
| 30 |
+
"left",
|
| 31 |
+
"right"
|
| 32 |
+
],
|
| 33 |
+
AwaitExpression: [
|
| 34 |
+
"argument"
|
| 35 |
+
],
|
| 36 |
+
BinaryExpression: [
|
| 37 |
+
"left",
|
| 38 |
+
"right"
|
| 39 |
+
],
|
| 40 |
+
BlockStatement: [
|
| 41 |
+
"body"
|
| 42 |
+
],
|
| 43 |
+
BreakStatement: [
|
| 44 |
+
"label"
|
| 45 |
+
],
|
| 46 |
+
CallExpression: [
|
| 47 |
+
"callee",
|
| 48 |
+
"arguments"
|
| 49 |
+
],
|
| 50 |
+
CatchClause: [
|
| 51 |
+
"param",
|
| 52 |
+
"body"
|
| 53 |
+
],
|
| 54 |
+
ChainExpression: [
|
| 55 |
+
"expression"
|
| 56 |
+
],
|
| 57 |
+
ClassBody: [
|
| 58 |
+
"body"
|
| 59 |
+
],
|
| 60 |
+
ClassDeclaration: [
|
| 61 |
+
"id",
|
| 62 |
+
"superClass",
|
| 63 |
+
"body"
|
| 64 |
+
],
|
| 65 |
+
ClassExpression: [
|
| 66 |
+
"id",
|
| 67 |
+
"superClass",
|
| 68 |
+
"body"
|
| 69 |
+
],
|
| 70 |
+
ConditionalExpression: [
|
| 71 |
+
"test",
|
| 72 |
+
"consequent",
|
| 73 |
+
"alternate"
|
| 74 |
+
],
|
| 75 |
+
ContinueStatement: [
|
| 76 |
+
"label"
|
| 77 |
+
],
|
| 78 |
+
DebuggerStatement: [],
|
| 79 |
+
DoWhileStatement: [
|
| 80 |
+
"body",
|
| 81 |
+
"test"
|
| 82 |
+
],
|
| 83 |
+
EmptyStatement: [],
|
| 84 |
+
ExperimentalRestProperty: [
|
| 85 |
+
"argument"
|
| 86 |
+
],
|
| 87 |
+
ExperimentalSpreadProperty: [
|
| 88 |
+
"argument"
|
| 89 |
+
],
|
| 90 |
+
ExportAllDeclaration: [
|
| 91 |
+
"exported",
|
| 92 |
+
"source",
|
| 93 |
+
"attributes"
|
| 94 |
+
],
|
| 95 |
+
ExportDefaultDeclaration: [
|
| 96 |
+
"declaration"
|
| 97 |
+
],
|
| 98 |
+
ExportNamedDeclaration: [
|
| 99 |
+
"declaration",
|
| 100 |
+
"specifiers",
|
| 101 |
+
"source",
|
| 102 |
+
"attributes"
|
| 103 |
+
],
|
| 104 |
+
ExportSpecifier: [
|
| 105 |
+
"local",
|
| 106 |
+
"exported"
|
| 107 |
+
],
|
| 108 |
+
ExpressionStatement: [
|
| 109 |
+
"expression"
|
| 110 |
+
],
|
| 111 |
+
ForInStatement: [
|
| 112 |
+
"left",
|
| 113 |
+
"right",
|
| 114 |
+
"body"
|
| 115 |
+
],
|
| 116 |
+
ForOfStatement: [
|
| 117 |
+
"left",
|
| 118 |
+
"right",
|
| 119 |
+
"body"
|
| 120 |
+
],
|
| 121 |
+
ForStatement: [
|
| 122 |
+
"init",
|
| 123 |
+
"test",
|
| 124 |
+
"update",
|
| 125 |
+
"body"
|
| 126 |
+
],
|
| 127 |
+
FunctionDeclaration: [
|
| 128 |
+
"id",
|
| 129 |
+
"params",
|
| 130 |
+
"body"
|
| 131 |
+
],
|
| 132 |
+
FunctionExpression: [
|
| 133 |
+
"id",
|
| 134 |
+
"params",
|
| 135 |
+
"body"
|
| 136 |
+
],
|
| 137 |
+
Identifier: [],
|
| 138 |
+
IfStatement: [
|
| 139 |
+
"test",
|
| 140 |
+
"consequent",
|
| 141 |
+
"alternate"
|
| 142 |
+
],
|
| 143 |
+
ImportAttribute: [
|
| 144 |
+
"key",
|
| 145 |
+
"value"
|
| 146 |
+
],
|
| 147 |
+
ImportDeclaration: [
|
| 148 |
+
"specifiers",
|
| 149 |
+
"source",
|
| 150 |
+
"attributes"
|
| 151 |
+
],
|
| 152 |
+
ImportDefaultSpecifier: [
|
| 153 |
+
"local"
|
| 154 |
+
],
|
| 155 |
+
ImportExpression: [
|
| 156 |
+
"source",
|
| 157 |
+
"options"
|
| 158 |
+
],
|
| 159 |
+
ImportNamespaceSpecifier: [
|
| 160 |
+
"local"
|
| 161 |
+
],
|
| 162 |
+
ImportSpecifier: [
|
| 163 |
+
"imported",
|
| 164 |
+
"local"
|
| 165 |
+
],
|
| 166 |
+
JSXAttribute: [
|
| 167 |
+
"name",
|
| 168 |
+
"value"
|
| 169 |
+
],
|
| 170 |
+
JSXClosingElement: [
|
| 171 |
+
"name"
|
| 172 |
+
],
|
| 173 |
+
JSXClosingFragment: [],
|
| 174 |
+
JSXElement: [
|
| 175 |
+
"openingElement",
|
| 176 |
+
"children",
|
| 177 |
+
"closingElement"
|
| 178 |
+
],
|
| 179 |
+
JSXEmptyExpression: [],
|
| 180 |
+
JSXExpressionContainer: [
|
| 181 |
+
"expression"
|
| 182 |
+
],
|
| 183 |
+
JSXFragment: [
|
| 184 |
+
"openingFragment",
|
| 185 |
+
"children",
|
| 186 |
+
"closingFragment"
|
| 187 |
+
],
|
| 188 |
+
JSXIdentifier: [],
|
| 189 |
+
JSXMemberExpression: [
|
| 190 |
+
"object",
|
| 191 |
+
"property"
|
| 192 |
+
],
|
| 193 |
+
JSXNamespacedName: [
|
| 194 |
+
"namespace",
|
| 195 |
+
"name"
|
| 196 |
+
],
|
| 197 |
+
JSXOpeningElement: [
|
| 198 |
+
"name",
|
| 199 |
+
"attributes"
|
| 200 |
+
],
|
| 201 |
+
JSXOpeningFragment: [],
|
| 202 |
+
JSXSpreadAttribute: [
|
| 203 |
+
"argument"
|
| 204 |
+
],
|
| 205 |
+
JSXSpreadChild: [
|
| 206 |
+
"expression"
|
| 207 |
+
],
|
| 208 |
+
JSXText: [],
|
| 209 |
+
LabeledStatement: [
|
| 210 |
+
"label",
|
| 211 |
+
"body"
|
| 212 |
+
],
|
| 213 |
+
Literal: [],
|
| 214 |
+
LogicalExpression: [
|
| 215 |
+
"left",
|
| 216 |
+
"right"
|
| 217 |
+
],
|
| 218 |
+
MemberExpression: [
|
| 219 |
+
"object",
|
| 220 |
+
"property"
|
| 221 |
+
],
|
| 222 |
+
MetaProperty: [
|
| 223 |
+
"meta",
|
| 224 |
+
"property"
|
| 225 |
+
],
|
| 226 |
+
MethodDefinition: [
|
| 227 |
+
"key",
|
| 228 |
+
"value"
|
| 229 |
+
],
|
| 230 |
+
NewExpression: [
|
| 231 |
+
"callee",
|
| 232 |
+
"arguments"
|
| 233 |
+
],
|
| 234 |
+
ObjectExpression: [
|
| 235 |
+
"properties"
|
| 236 |
+
],
|
| 237 |
+
ObjectPattern: [
|
| 238 |
+
"properties"
|
| 239 |
+
],
|
| 240 |
+
PrivateIdentifier: [],
|
| 241 |
+
Program: [
|
| 242 |
+
"body"
|
| 243 |
+
],
|
| 244 |
+
Property: [
|
| 245 |
+
"key",
|
| 246 |
+
"value"
|
| 247 |
+
],
|
| 248 |
+
PropertyDefinition: [
|
| 249 |
+
"key",
|
| 250 |
+
"value"
|
| 251 |
+
],
|
| 252 |
+
RestElement: [
|
| 253 |
+
"argument"
|
| 254 |
+
],
|
| 255 |
+
ReturnStatement: [
|
| 256 |
+
"argument"
|
| 257 |
+
],
|
| 258 |
+
SequenceExpression: [
|
| 259 |
+
"expressions"
|
| 260 |
+
],
|
| 261 |
+
SpreadElement: [
|
| 262 |
+
"argument"
|
| 263 |
+
],
|
| 264 |
+
StaticBlock: [
|
| 265 |
+
"body"
|
| 266 |
+
],
|
| 267 |
+
Super: [],
|
| 268 |
+
SwitchCase: [
|
| 269 |
+
"test",
|
| 270 |
+
"consequent"
|
| 271 |
+
],
|
| 272 |
+
SwitchStatement: [
|
| 273 |
+
"discriminant",
|
| 274 |
+
"cases"
|
| 275 |
+
],
|
| 276 |
+
TaggedTemplateExpression: [
|
| 277 |
+
"tag",
|
| 278 |
+
"quasi"
|
| 279 |
+
],
|
| 280 |
+
TemplateElement: [],
|
| 281 |
+
TemplateLiteral: [
|
| 282 |
+
"quasis",
|
| 283 |
+
"expressions"
|
| 284 |
+
],
|
| 285 |
+
ThisExpression: [],
|
| 286 |
+
ThrowStatement: [
|
| 287 |
+
"argument"
|
| 288 |
+
],
|
| 289 |
+
TryStatement: [
|
| 290 |
+
"block",
|
| 291 |
+
"handler",
|
| 292 |
+
"finalizer"
|
| 293 |
+
],
|
| 294 |
+
UnaryExpression: [
|
| 295 |
+
"argument"
|
| 296 |
+
],
|
| 297 |
+
UpdateExpression: [
|
| 298 |
+
"argument"
|
| 299 |
+
],
|
| 300 |
+
VariableDeclaration: [
|
| 301 |
+
"declarations"
|
| 302 |
+
],
|
| 303 |
+
VariableDeclarator: [
|
| 304 |
+
"id",
|
| 305 |
+
"init"
|
| 306 |
+
],
|
| 307 |
+
WhileStatement: [
|
| 308 |
+
"test",
|
| 309 |
+
"body"
|
| 310 |
+
],
|
| 311 |
+
WithStatement: [
|
| 312 |
+
"object",
|
| 313 |
+
"body"
|
| 314 |
+
],
|
| 315 |
+
YieldExpression: [
|
| 316 |
+
"argument"
|
| 317 |
+
]
|
| 318 |
+
};
|
| 319 |
+
|
| 320 |
+
// Types.
|
| 321 |
+
const NODE_TYPES = Object.keys(KEYS);
|
| 322 |
+
|
| 323 |
+
// Freeze the keys.
|
| 324 |
+
for (const type of NODE_TYPES) {
|
| 325 |
+
Object.freeze(KEYS[type]);
|
| 326 |
+
}
|
| 327 |
+
Object.freeze(KEYS);
|
| 328 |
+
|
| 329 |
+
/**
|
| 330 |
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
| 331 |
+
* See LICENSE file in root directory for full license.
|
| 332 |
+
*/
|
| 333 |
+
|
| 334 |
+
/**
|
| 335 |
+
* @typedef {import('./visitor-keys.js').VisitorKeys} VisitorKeys
|
| 336 |
+
*/
|
| 337 |
+
|
| 338 |
+
// List to ignore keys.
|
| 339 |
+
const KEY_BLACKLIST = new Set([
|
| 340 |
+
"parent",
|
| 341 |
+
"leadingComments",
|
| 342 |
+
"trailingComments"
|
| 343 |
+
]);
|
| 344 |
+
|
| 345 |
+
/**
|
| 346 |
+
* Check whether a given key should be used or not.
|
| 347 |
+
* @param {string} key The key to check.
|
| 348 |
+
* @returns {boolean} `true` if the key should be used.
|
| 349 |
+
*/
|
| 350 |
+
function filterKey(key) {
|
| 351 |
+
return !KEY_BLACKLIST.has(key) && key[0] !== "_";
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
| 356 |
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
| 357 |
+
*/
|
| 358 |
+
/**
|
| 359 |
+
* Get visitor keys of a given node.
|
| 360 |
+
* @param {Object} node The AST node to get keys.
|
| 361 |
+
* @returns {readonly string[]} Visitor keys of the node.
|
| 362 |
+
*/
|
| 363 |
+
function getKeys(node) {
|
| 364 |
+
return Object.keys(node).filter(filterKey);
|
| 365 |
+
}
|
| 366 |
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly` */
|
| 367 |
+
|
| 368 |
+
/**
|
| 369 |
+
* Make the union set with `KEYS` and given keys.
|
| 370 |
+
* @param {VisitorKeys} additionalKeys The additional keys.
|
| 371 |
+
* @returns {VisitorKeys} The union set.
|
| 372 |
+
*/
|
| 373 |
+
function unionWith(additionalKeys) {
|
| 374 |
+
const retv = /** @type {{ [type: string]: ReadonlyArray<string> }} */
|
| 375 |
+
(Object.assign({}, KEYS));
|
| 376 |
+
|
| 377 |
+
for (const type of Object.keys(additionalKeys)) {
|
| 378 |
+
if (Object.hasOwn(retv, type)) {
|
| 379 |
+
const keys = new Set(additionalKeys[type]);
|
| 380 |
+
|
| 381 |
+
for (const key of retv[type]) {
|
| 382 |
+
keys.add(key);
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
retv[type] = Object.freeze(Array.from(keys));
|
| 386 |
+
} else {
|
| 387 |
+
retv[type] = Object.freeze(Array.from(additionalKeys[type]));
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
return Object.freeze(retv);
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
exports.KEYS = KEYS;
|
| 395 |
+
exports.getKeys = getKeys;
|
| 396 |
+
exports.unionWith = unionWith;
|
node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
type VisitorKeys$1 = {
|
| 2 |
+
readonly [type: string]: ReadonlyArray<string>;
|
| 3 |
+
};
|
| 4 |
+
/**
|
| 5 |
+
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
|
| 6 |
+
*/
|
| 7 |
+
/**
|
| 8 |
+
* @type {VisitorKeys}
|
| 9 |
+
*/
|
| 10 |
+
declare const KEYS: VisitorKeys$1;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Get visitor keys of a given node.
|
| 14 |
+
* @param {Object} node The AST node to get keys.
|
| 15 |
+
* @returns {readonly string[]} Visitor keys of the node.
|
| 16 |
+
*/
|
| 17 |
+
declare function getKeys(node: Object): readonly string[];
|
| 18 |
+
/**
|
| 19 |
+
* Make the union set with `KEYS` and given keys.
|
| 20 |
+
* @param {VisitorKeys} additionalKeys The additional keys.
|
| 21 |
+
* @returns {VisitorKeys} The union set.
|
| 22 |
+
*/
|
| 23 |
+
declare function unionWith(additionalKeys: VisitorKeys): VisitorKeys;
|
| 24 |
+
|
| 25 |
+
type VisitorKeys = VisitorKeys$1;
|
| 26 |
+
|
| 27 |
+
export { KEYS, getKeys, unionWith };
|
| 28 |
+
export type { VisitorKeys };
|
node_modules/eslint-visitor-keys/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Get visitor keys of a given node.
|
| 3 |
+
* @param {Object} node The AST node to get keys.
|
| 4 |
+
* @returns {readonly string[]} Visitor keys of the node.
|
| 5 |
+
*/
|
| 6 |
+
export function getKeys(node: Object): readonly string[];
|
| 7 |
+
/**
|
| 8 |
+
* Make the union set with `KEYS` and given keys.
|
| 9 |
+
* @param {VisitorKeys} additionalKeys The additional keys.
|
| 10 |
+
* @returns {VisitorKeys} The union set.
|
| 11 |
+
*/
|
| 12 |
+
export function unionWith(additionalKeys: VisitorKeys): VisitorKeys;
|
| 13 |
+
export { KEYS };
|
| 14 |
+
export type VisitorKeys = import("./visitor-keys.js").VisitorKeys;
|
| 15 |
+
import KEYS from "./visitor-keys.js";
|
| 16 |
+
//# sourceMappingURL=index.d.ts.map
|
node_modules/eslint-visitor-keys/dist/visitor-keys.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default KEYS;
|
| 2 |
+
export type VisitorKeys = {
|
| 3 |
+
readonly [type: string]: ReadonlyArray<string>;
|
| 4 |
+
};
|
| 5 |
+
/**
|
| 6 |
+
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
|
| 7 |
+
*/
|
| 8 |
+
/**
|
| 9 |
+
* @type {VisitorKeys}
|
| 10 |
+
*/
|
| 11 |
+
declare const KEYS: VisitorKeys;
|
| 12 |
+
//# sourceMappingURL=visitor-keys.d.ts.map
|
node_modules/eslint-visitor-keys/lib/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
| 3 |
+
* See LICENSE file in root directory for full license.
|
| 4 |
+
*/
|
| 5 |
+
import KEYS from "./visitor-keys.js";
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* @typedef {import('./visitor-keys.js').VisitorKeys} VisitorKeys
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
// List to ignore keys.
|
| 12 |
+
const KEY_BLACKLIST = new Set([
|
| 13 |
+
"parent",
|
| 14 |
+
"leadingComments",
|
| 15 |
+
"trailingComments"
|
| 16 |
+
]);
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Check whether a given key should be used or not.
|
| 20 |
+
* @param {string} key The key to check.
|
| 21 |
+
* @returns {boolean} `true` if the key should be used.
|
| 22 |
+
*/
|
| 23 |
+
function filterKey(key) {
|
| 24 |
+
return !KEY_BLACKLIST.has(key) && key[0] !== "_";
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
| 29 |
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
| 30 |
+
*/
|
| 31 |
+
/**
|
| 32 |
+
* Get visitor keys of a given node.
|
| 33 |
+
* @param {Object} node The AST node to get keys.
|
| 34 |
+
* @returns {readonly string[]} Visitor keys of the node.
|
| 35 |
+
*/
|
| 36 |
+
export function getKeys(node) {
|
| 37 |
+
return Object.keys(node).filter(filterKey);
|
| 38 |
+
}
|
| 39 |
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly` */
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Make the union set with `KEYS` and given keys.
|
| 43 |
+
* @param {VisitorKeys} additionalKeys The additional keys.
|
| 44 |
+
* @returns {VisitorKeys} The union set.
|
| 45 |
+
*/
|
| 46 |
+
export function unionWith(additionalKeys) {
|
| 47 |
+
const retv = /** @type {{ [type: string]: ReadonlyArray<string> }} */
|
| 48 |
+
(Object.assign({}, KEYS));
|
| 49 |
+
|
| 50 |
+
for (const type of Object.keys(additionalKeys)) {
|
| 51 |
+
if (Object.hasOwn(retv, type)) {
|
| 52 |
+
const keys = new Set(additionalKeys[type]);
|
| 53 |
+
|
| 54 |
+
for (const key of retv[type]) {
|
| 55 |
+
keys.add(key);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
retv[type] = Object.freeze(Array.from(keys));
|
| 59 |
+
} else {
|
| 60 |
+
retv[type] = Object.freeze(Array.from(additionalKeys[type]));
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return Object.freeze(retv);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
export { KEYS };
|
node_modules/eslint-visitor-keys/lib/visitor-keys.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
| 2 |
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
| 3 |
+
*/
|
| 4 |
+
/**
|
| 5 |
+
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
|
| 6 |
+
*/
|
| 7 |
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly string[]`. TODO: check why */
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @type {VisitorKeys}
|
| 11 |
+
*/
|
| 12 |
+
const KEYS = {
|
| 13 |
+
ArrayExpression: [
|
| 14 |
+
"elements"
|
| 15 |
+
],
|
| 16 |
+
ArrayPattern: [
|
| 17 |
+
"elements"
|
| 18 |
+
],
|
| 19 |
+
ArrowFunctionExpression: [
|
| 20 |
+
"params",
|
| 21 |
+
"body"
|
| 22 |
+
],
|
| 23 |
+
AssignmentExpression: [
|
| 24 |
+
"left",
|
| 25 |
+
"right"
|
| 26 |
+
],
|
| 27 |
+
AssignmentPattern: [
|
| 28 |
+
"left",
|
| 29 |
+
"right"
|
| 30 |
+
],
|
| 31 |
+
AwaitExpression: [
|
| 32 |
+
"argument"
|
| 33 |
+
],
|
| 34 |
+
BinaryExpression: [
|
| 35 |
+
"left",
|
| 36 |
+
"right"
|
| 37 |
+
],
|
| 38 |
+
BlockStatement: [
|
| 39 |
+
"body"
|
| 40 |
+
],
|
| 41 |
+
BreakStatement: [
|
| 42 |
+
"label"
|
| 43 |
+
],
|
| 44 |
+
CallExpression: [
|
| 45 |
+
"callee",
|
| 46 |
+
"arguments"
|
| 47 |
+
],
|
| 48 |
+
CatchClause: [
|
| 49 |
+
"param",
|
| 50 |
+
"body"
|
| 51 |
+
],
|
| 52 |
+
ChainExpression: [
|
| 53 |
+
"expression"
|
| 54 |
+
],
|
| 55 |
+
ClassBody: [
|
| 56 |
+
"body"
|
| 57 |
+
],
|
| 58 |
+
ClassDeclaration: [
|
| 59 |
+
"id",
|
| 60 |
+
"superClass",
|
| 61 |
+
"body"
|
| 62 |
+
],
|
| 63 |
+
ClassExpression: [
|
| 64 |
+
"id",
|
| 65 |
+
"superClass",
|
| 66 |
+
"body"
|
| 67 |
+
],
|
| 68 |
+
ConditionalExpression: [
|
| 69 |
+
"test",
|
| 70 |
+
"consequent",
|
| 71 |
+
"alternate"
|
| 72 |
+
],
|
| 73 |
+
ContinueStatement: [
|
| 74 |
+
"label"
|
| 75 |
+
],
|
| 76 |
+
DebuggerStatement: [],
|
| 77 |
+
DoWhileStatement: [
|
| 78 |
+
"body",
|
| 79 |
+
"test"
|
| 80 |
+
],
|
| 81 |
+
EmptyStatement: [],
|
| 82 |
+
ExperimentalRestProperty: [
|
| 83 |
+
"argument"
|
| 84 |
+
],
|
| 85 |
+
ExperimentalSpreadProperty: [
|
| 86 |
+
"argument"
|
| 87 |
+
],
|
| 88 |
+
ExportAllDeclaration: [
|
| 89 |
+
"exported",
|
| 90 |
+
"source",
|
| 91 |
+
"attributes"
|
| 92 |
+
],
|
| 93 |
+
ExportDefaultDeclaration: [
|
| 94 |
+
"declaration"
|
| 95 |
+
],
|
| 96 |
+
ExportNamedDeclaration: [
|
| 97 |
+
"declaration",
|
| 98 |
+
"specifiers",
|
| 99 |
+
"source",
|
| 100 |
+
"attributes"
|
| 101 |
+
],
|
| 102 |
+
ExportSpecifier: [
|
| 103 |
+
"local",
|
| 104 |
+
"exported"
|
| 105 |
+
],
|
| 106 |
+
ExpressionStatement: [
|
| 107 |
+
"expression"
|
| 108 |
+
],
|
| 109 |
+
ForInStatement: [
|
| 110 |
+
"left",
|
| 111 |
+
"right",
|
| 112 |
+
"body"
|
| 113 |
+
],
|
| 114 |
+
ForOfStatement: [
|
| 115 |
+
"left",
|
| 116 |
+
"right",
|
| 117 |
+
"body"
|
| 118 |
+
],
|
| 119 |
+
ForStatement: [
|
| 120 |
+
"init",
|
| 121 |
+
"test",
|
| 122 |
+
"update",
|
| 123 |
+
"body"
|
| 124 |
+
],
|
| 125 |
+
FunctionDeclaration: [
|
| 126 |
+
"id",
|
| 127 |
+
"params",
|
| 128 |
+
"body"
|
| 129 |
+
],
|
| 130 |
+
FunctionExpression: [
|
| 131 |
+
"id",
|
| 132 |
+
"params",
|
| 133 |
+
"body"
|
| 134 |
+
],
|
| 135 |
+
Identifier: [],
|
| 136 |
+
IfStatement: [
|
| 137 |
+
"test",
|
| 138 |
+
"consequent",
|
| 139 |
+
"alternate"
|
| 140 |
+
],
|
| 141 |
+
ImportAttribute: [
|
| 142 |
+
"key",
|
| 143 |
+
"value"
|
| 144 |
+
],
|
| 145 |
+
ImportDeclaration: [
|
| 146 |
+
"specifiers",
|
| 147 |
+
"source",
|
| 148 |
+
"attributes"
|
| 149 |
+
],
|
| 150 |
+
ImportDefaultSpecifier: [
|
| 151 |
+
"local"
|
| 152 |
+
],
|
| 153 |
+
ImportExpression: [
|
| 154 |
+
"source",
|
| 155 |
+
"options"
|
| 156 |
+
],
|
| 157 |
+
ImportNamespaceSpecifier: [
|
| 158 |
+
"local"
|
| 159 |
+
],
|
| 160 |
+
ImportSpecifier: [
|
| 161 |
+
"imported",
|
| 162 |
+
"local"
|
| 163 |
+
],
|
| 164 |
+
JSXAttribute: [
|
| 165 |
+
"name",
|
| 166 |
+
"value"
|
| 167 |
+
],
|
| 168 |
+
JSXClosingElement: [
|
| 169 |
+
"name"
|
| 170 |
+
],
|
| 171 |
+
JSXClosingFragment: [],
|
| 172 |
+
JSXElement: [
|
| 173 |
+
"openingElement",
|
| 174 |
+
"children",
|
| 175 |
+
"closingElement"
|
| 176 |
+
],
|
| 177 |
+
JSXEmptyExpression: [],
|
| 178 |
+
JSXExpressionContainer: [
|
| 179 |
+
"expression"
|
| 180 |
+
],
|
| 181 |
+
JSXFragment: [
|
| 182 |
+
"openingFragment",
|
| 183 |
+
"children",
|
| 184 |
+
"closingFragment"
|
| 185 |
+
],
|
| 186 |
+
JSXIdentifier: [],
|
| 187 |
+
JSXMemberExpression: [
|
| 188 |
+
"object",
|
| 189 |
+
"property"
|
| 190 |
+
],
|
| 191 |
+
JSXNamespacedName: [
|
| 192 |
+
"namespace",
|
| 193 |
+
"name"
|
| 194 |
+
],
|
| 195 |
+
JSXOpeningElement: [
|
| 196 |
+
"name",
|
| 197 |
+
"attributes"
|
| 198 |
+
],
|
| 199 |
+
JSXOpeningFragment: [],
|
| 200 |
+
JSXSpreadAttribute: [
|
| 201 |
+
"argument"
|
| 202 |
+
],
|
| 203 |
+
JSXSpreadChild: [
|
| 204 |
+
"expression"
|
| 205 |
+
],
|
| 206 |
+
JSXText: [],
|
| 207 |
+
LabeledStatement: [
|
| 208 |
+
"label",
|
| 209 |
+
"body"
|
| 210 |
+
],
|
| 211 |
+
Literal: [],
|
| 212 |
+
LogicalExpression: [
|
| 213 |
+
"left",
|
| 214 |
+
"right"
|
| 215 |
+
],
|
| 216 |
+
MemberExpression: [
|
| 217 |
+
"object",
|
| 218 |
+
"property"
|
| 219 |
+
],
|
| 220 |
+
MetaProperty: [
|
| 221 |
+
"meta",
|
| 222 |
+
"property"
|
| 223 |
+
],
|
| 224 |
+
MethodDefinition: [
|
| 225 |
+
"key",
|
| 226 |
+
"value"
|
| 227 |
+
],
|
| 228 |
+
NewExpression: [
|
| 229 |
+
"callee",
|
| 230 |
+
"arguments"
|
| 231 |
+
],
|
| 232 |
+
ObjectExpression: [
|
| 233 |
+
"properties"
|
| 234 |
+
],
|
| 235 |
+
ObjectPattern: [
|
| 236 |
+
"properties"
|
| 237 |
+
],
|
| 238 |
+
PrivateIdentifier: [],
|
| 239 |
+
Program: [
|
| 240 |
+
"body"
|
| 241 |
+
],
|
| 242 |
+
Property: [
|
| 243 |
+
"key",
|
| 244 |
+
"value"
|
| 245 |
+
],
|
| 246 |
+
PropertyDefinition: [
|
| 247 |
+
"key",
|
| 248 |
+
"value"
|
| 249 |
+
],
|
| 250 |
+
RestElement: [
|
| 251 |
+
"argument"
|
| 252 |
+
],
|
| 253 |
+
ReturnStatement: [
|
| 254 |
+
"argument"
|
| 255 |
+
],
|
| 256 |
+
SequenceExpression: [
|
| 257 |
+
"expressions"
|
| 258 |
+
],
|
| 259 |
+
SpreadElement: [
|
| 260 |
+
"argument"
|
| 261 |
+
],
|
| 262 |
+
StaticBlock: [
|
| 263 |
+
"body"
|
| 264 |
+
],
|
| 265 |
+
Super: [],
|
| 266 |
+
SwitchCase: [
|
| 267 |
+
"test",
|
| 268 |
+
"consequent"
|
| 269 |
+
],
|
| 270 |
+
SwitchStatement: [
|
| 271 |
+
"discriminant",
|
| 272 |
+
"cases"
|
| 273 |
+
],
|
| 274 |
+
TaggedTemplateExpression: [
|
| 275 |
+
"tag",
|
| 276 |
+
"quasi"
|
| 277 |
+
],
|
| 278 |
+
TemplateElement: [],
|
| 279 |
+
TemplateLiteral: [
|
| 280 |
+
"quasis",
|
| 281 |
+
"expressions"
|
| 282 |
+
],
|
| 283 |
+
ThisExpression: [],
|
| 284 |
+
ThrowStatement: [
|
| 285 |
+
"argument"
|
| 286 |
+
],
|
| 287 |
+
TryStatement: [
|
| 288 |
+
"block",
|
| 289 |
+
"handler",
|
| 290 |
+
"finalizer"
|
| 291 |
+
],
|
| 292 |
+
UnaryExpression: [
|
| 293 |
+
"argument"
|
| 294 |
+
],
|
| 295 |
+
UpdateExpression: [
|
| 296 |
+
"argument"
|
| 297 |
+
],
|
| 298 |
+
VariableDeclaration: [
|
| 299 |
+
"declarations"
|
| 300 |
+
],
|
| 301 |
+
VariableDeclarator: [
|
| 302 |
+
"id",
|
| 303 |
+
"init"
|
| 304 |
+
],
|
| 305 |
+
WhileStatement: [
|
| 306 |
+
"test",
|
| 307 |
+
"body"
|
| 308 |
+
],
|
| 309 |
+
WithStatement: [
|
| 310 |
+
"object",
|
| 311 |
+
"body"
|
| 312 |
+
],
|
| 313 |
+
YieldExpression: [
|
| 314 |
+
"argument"
|
| 315 |
+
]
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
// Types.
|
| 319 |
+
const NODE_TYPES = Object.keys(KEYS);
|
| 320 |
+
|
| 321 |
+
// Freeze the keys.
|
| 322 |
+
for (const type of NODE_TYPES) {
|
| 323 |
+
Object.freeze(KEYS[type]);
|
| 324 |
+
}
|
| 325 |
+
Object.freeze(KEYS);
|
| 326 |
+
|
| 327 |
+
export default KEYS;
|
node_modules/eslint-visitor-keys/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-visitor-keys",
|
| 3 |
+
"version": "4.2.1",
|
| 4 |
+
"description": "Constants and utilities about visitor keys to traverse AST.",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"main": "dist/eslint-visitor-keys.cjs",
|
| 7 |
+
"types": "./dist/index.d.ts",
|
| 8 |
+
"exports": {
|
| 9 |
+
".": [
|
| 10 |
+
{
|
| 11 |
+
"import": "./lib/index.js",
|
| 12 |
+
"require": "./dist/eslint-visitor-keys.cjs"
|
| 13 |
+
},
|
| 14 |
+
"./dist/eslint-visitor-keys.cjs"
|
| 15 |
+
],
|
| 16 |
+
"./package.json": "./package.json"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"dist/index.d.ts",
|
| 20 |
+
"dist/visitor-keys.d.ts",
|
| 21 |
+
"dist/eslint-visitor-keys.cjs",
|
| 22 |
+
"dist/eslint-visitor-keys.d.cts",
|
| 23 |
+
"lib"
|
| 24 |
+
],
|
| 25 |
+
"engines": {
|
| 26 |
+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
| 27 |
+
},
|
| 28 |
+
"devDependencies": {
|
| 29 |
+
"@types/estree": "^0.0.51",
|
| 30 |
+
"@types/estree-jsx": "^0.0.1",
|
| 31 |
+
"@typescript-eslint/parser": "^8.7.0",
|
| 32 |
+
"eslint-release": "^3.2.0",
|
| 33 |
+
"esquery": "^1.4.0",
|
| 34 |
+
"json-diff": "^0.7.3",
|
| 35 |
+
"opener": "^1.5.2",
|
| 36 |
+
"rollup": "^4.22.4",
|
| 37 |
+
"rollup-plugin-dts": "^6.1.1",
|
| 38 |
+
"tsd": "^0.31.2",
|
| 39 |
+
"typescript": "^5.6.2"
|
| 40 |
+
},
|
| 41 |
+
"scripts": {
|
| 42 |
+
"build": "npm run build:cjs && npm run build:types",
|
| 43 |
+
"build:cjs": "rollup -c",
|
| 44 |
+
"build:debug": "npm run build:cjs -- -m && npm run build:types",
|
| 45 |
+
"build:types": "tsc -v && tsc",
|
| 46 |
+
"release:generate:latest": "eslint-generate-release",
|
| 47 |
+
"release:generate:alpha": "eslint-generate-prerelease alpha",
|
| 48 |
+
"release:generate:beta": "eslint-generate-prerelease beta",
|
| 49 |
+
"release:generate:rc": "eslint-generate-prerelease rc",
|
| 50 |
+
"release:publish": "eslint-publish-release",
|
| 51 |
+
"test": "mocha tests/lib/**/*.cjs && c8 mocha tests/lib/**/*.js && npm run test:types",
|
| 52 |
+
"test:open-coverage": "c8 report --reporter lcov && opener coverage/lcov-report/index.html",
|
| 53 |
+
"test:types": "tsd"
|
| 54 |
+
},
|
| 55 |
+
"repository": {
|
| 56 |
+
"type": "git",
|
| 57 |
+
"url": "https://github.com/eslint/js.git",
|
| 58 |
+
"directory": "packages/eslint-visitor-keys"
|
| 59 |
+
},
|
| 60 |
+
"funding": "https://opencollective.com/eslint",
|
| 61 |
+
"keywords": [
|
| 62 |
+
"eslint"
|
| 63 |
+
],
|
| 64 |
+
"author": "Toru Nagashima (https://github.com/mysticatea)",
|
| 65 |
+
"license": "Apache-2.0",
|
| 66 |
+
"bugs": {
|
| 67 |
+
"url": "https://github.com/eslint/js/issues"
|
| 68 |
+
},
|
| 69 |
+
"homepage": "https://github.com/eslint/js/blob/main/packages/eslint-visitor-keys/README.md"
|
| 70 |
+
}
|
node_modules/espree/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 2-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Open JS Foundation
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
1. Redistributions of source code must retain the above copyright notice, this
|
| 10 |
+
list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
| 13 |
+
this list of conditions and the following disclaimer in the documentation
|
| 14 |
+
and/or other materials provided with the distribution.
|
| 15 |
+
|
| 16 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 17 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 18 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 19 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 20 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 21 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 22 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 23 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 24 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 25 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
node_modules/espree/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[](https://www.npmjs.com/package/espree)
|
| 2 |
+
[](https://www.npmjs.com/package/espree)
|
| 3 |
+
[](https://github.com/js/espree/actions)
|
| 4 |
+
[](https://www.bountysource.com/trackers/9348450-eslint?utm_source=9348450&utm_medium=shield&utm_campaign=TRACKER_BADGE)
|
| 5 |
+
|
| 6 |
+
# Espree
|
| 7 |
+
|
| 8 |
+
Espree started out as a fork of [Esprima](http://esprima.org) v1.2.2, the last stable published released of Esprima before work on ECMAScript 6 began. Espree is now built on top of [Acorn](https://github.com/ternjs/acorn), which has a modular architecture that allows extension of core functionality. The goal of Espree is to produce output that is similar to Esprima with a similar API so that it can be used in place of Esprima.
|
| 9 |
+
|
| 10 |
+
## Usage
|
| 11 |
+
|
| 12 |
+
Install:
|
| 13 |
+
|
| 14 |
+
```
|
| 15 |
+
npm i espree
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
To use in an ESM file:
|
| 19 |
+
|
| 20 |
+
```js
|
| 21 |
+
import * as espree from "espree";
|
| 22 |
+
|
| 23 |
+
const ast = espree.parse(code);
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
To use in a Common JS file:
|
| 27 |
+
|
| 28 |
+
```js
|
| 29 |
+
const espree = require("espree");
|
| 30 |
+
|
| 31 |
+
const ast = espree.parse(code);
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## API
|
| 35 |
+
|
| 36 |
+
### `parse()`
|
| 37 |
+
|
| 38 |
+
`parse` parses the given code and returns a abstract syntax tree (AST). It takes two parameters.
|
| 39 |
+
|
| 40 |
+
- `code` [string]() - the code which needs to be parsed.
|
| 41 |
+
- `options (Optional)` [Object]() - read more about this [here](#options).
|
| 42 |
+
|
| 43 |
+
```js
|
| 44 |
+
import * as espree from "espree";
|
| 45 |
+
|
| 46 |
+
const ast = espree.parse(code);
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
**Example :**
|
| 50 |
+
|
| 51 |
+
```js
|
| 52 |
+
const ast = espree.parse('let foo = "bar"', { ecmaVersion: 6 });
|
| 53 |
+
console.log(ast);
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
<details><summary>Output</summary>
|
| 57 |
+
<p>
|
| 58 |
+
|
| 59 |
+
```
|
| 60 |
+
Node {
|
| 61 |
+
type: 'Program',
|
| 62 |
+
start: 0,
|
| 63 |
+
end: 15,
|
| 64 |
+
body: [
|
| 65 |
+
Node {
|
| 66 |
+
type: 'VariableDeclaration',
|
| 67 |
+
start: 0,
|
| 68 |
+
end: 15,
|
| 69 |
+
declarations: [Array],
|
| 70 |
+
kind: 'let'
|
| 71 |
+
}
|
| 72 |
+
],
|
| 73 |
+
sourceType: 'script'
|
| 74 |
+
}
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
</p>
|
| 78 |
+
</details>
|
| 79 |
+
|
| 80 |
+
### `tokenize()`
|
| 81 |
+
|
| 82 |
+
`tokenize` returns the tokens of a given code. It takes two parameters.
|
| 83 |
+
|
| 84 |
+
- `code` [string]() - the code which needs to be parsed.
|
| 85 |
+
- `options (Optional)` [Object]() - read more about this [here](#options).
|
| 86 |
+
|
| 87 |
+
Even if `options` is empty or undefined or `options.tokens` is `false`, it assigns it to `true` in order to get the `tokens` array
|
| 88 |
+
|
| 89 |
+
**Example :**
|
| 90 |
+
|
| 91 |
+
```js
|
| 92 |
+
import * as espree from "espree";
|
| 93 |
+
|
| 94 |
+
const tokens = espree.tokenize('let foo = "bar"', { ecmaVersion: 6 });
|
| 95 |
+
console.log(tokens);
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
<details><summary>Output</summary>
|
| 99 |
+
<p>
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
Token { type: 'Keyword', value: 'let', start: 0, end: 3 },
|
| 103 |
+
Token { type: 'Identifier', value: 'foo', start: 4, end: 7 },
|
| 104 |
+
Token { type: 'Punctuator', value: '=', start: 8, end: 9 },
|
| 105 |
+
Token { type: 'String', value: '"bar"', start: 10, end: 15 }
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
</p>
|
| 109 |
+
</details>
|
| 110 |
+
|
| 111 |
+
### `version`
|
| 112 |
+
|
| 113 |
+
Returns the current `espree` version
|
| 114 |
+
|
| 115 |
+
### `VisitorKeys`
|
| 116 |
+
|
| 117 |
+
Returns all visitor keys for traversing the AST from [eslint-visitor-keys](https://github.com/eslint/js/tree/main/packages/eslint-visitor-keys)
|
| 118 |
+
|
| 119 |
+
### `latestEcmaVersion`
|
| 120 |
+
|
| 121 |
+
Returns the latest ECMAScript supported by `espree`
|
| 122 |
+
|
| 123 |
+
### `supportedEcmaVersions`
|
| 124 |
+
|
| 125 |
+
Returns an array of all supported ECMAScript versions
|
| 126 |
+
|
| 127 |
+
## Options
|
| 128 |
+
|
| 129 |
+
```js
|
| 130 |
+
const options = {
|
| 131 |
+
// attach range information to each node
|
| 132 |
+
range: false,
|
| 133 |
+
|
| 134 |
+
// attach line/column location information to each node
|
| 135 |
+
loc: false,
|
| 136 |
+
|
| 137 |
+
// create a top-level comments array containing all comments
|
| 138 |
+
comment: false,
|
| 139 |
+
|
| 140 |
+
// create a top-level tokens array containing all tokens
|
| 141 |
+
tokens: false,
|
| 142 |
+
|
| 143 |
+
// Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 or 17 to specify the version of ECMAScript syntax you want to use.
|
| 144 |
+
// You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), 2023 (same as 14), 2024 (same as 15), 2025 (same as 16) or 2026 (same as 17) to use the year-based naming.
|
| 145 |
+
// You can also set "latest" to use the most recently supported version.
|
| 146 |
+
ecmaVersion: 3,
|
| 147 |
+
|
| 148 |
+
allowReserved: true, // only allowed when ecmaVersion is 3
|
| 149 |
+
|
| 150 |
+
// specify which type of script you're parsing ("script", "module", or "commonjs")
|
| 151 |
+
sourceType: "script",
|
| 152 |
+
|
| 153 |
+
// specify additional language features
|
| 154 |
+
ecmaFeatures: {
|
| 155 |
+
|
| 156 |
+
// enable JSX parsing
|
| 157 |
+
jsx: false,
|
| 158 |
+
|
| 159 |
+
// enable return in global scope (set to true automatically when sourceType is "commonjs")
|
| 160 |
+
globalReturn: false,
|
| 161 |
+
|
| 162 |
+
// enable implied strict mode (if ecmaVersion >= 5)
|
| 163 |
+
impliedStrict: false
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
## Esprima Compatibility Going Forward
|
| 169 |
+
|
| 170 |
+
The primary goal is to produce the exact same AST structure and tokens as Esprima, and that takes precedence over anything else. (The AST structure being the [ESTree](https://github.com/estree/estree) API with JSX extensions.) Separate from that, Espree may deviate from what Esprima outputs in terms of where and how comments are attached, as well as what additional information is available on AST nodes. That is to say, Espree may add more things to the AST nodes than Esprima does but the overall AST structure produced will be the same.
|
| 171 |
+
|
| 172 |
+
Espree may also deviate from Esprima in the interface it exposes.
|
| 173 |
+
|
| 174 |
+
## Contributing
|
| 175 |
+
|
| 176 |
+
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/js/issues).
|
| 177 |
+
|
| 178 |
+
Espree is licensed under a permissive BSD 2-clause license.
|
| 179 |
+
|
| 180 |
+
## Security Policy
|
| 181 |
+
|
| 182 |
+
We work hard to ensure that Espree is safe for everyone and that security issues are addressed quickly and responsibly. Read the full [security policy](https://github.com/eslint/.github/blob/master/SECURITY.md).
|
| 183 |
+
|
| 184 |
+
## Build Commands
|
| 185 |
+
|
| 186 |
+
* `npm test` - run all tests
|
| 187 |
+
* `npm run lint` - run all linting
|
| 188 |
+
|
| 189 |
+
## Differences from Espree 2.x
|
| 190 |
+
|
| 191 |
+
* The `tokenize()` method does not use `ecmaFeatures`. Any string will be tokenized completely based on ECMAScript 6 semantics.
|
| 192 |
+
* Trailing whitespace no longer is counted as part of a node.
|
| 193 |
+
* `let` and `const` declarations are no longer parsed by default. You must opt-in by using an `ecmaVersion` newer than `5` or setting `sourceType` to `module`.
|
| 194 |
+
* The `esparse` and `esvalidate` binary scripts have been removed.
|
| 195 |
+
* There is no `tolerant` option. We will investigate adding this back in the future.
|
| 196 |
+
|
| 197 |
+
## Known Incompatibilities
|
| 198 |
+
|
| 199 |
+
In an effort to help those wanting to transition from other parsers to Espree, the following is a list of noteworthy incompatibilities with other parsers. These are known differences that we do not intend to change.
|
| 200 |
+
|
| 201 |
+
### Esprima 1.2.2
|
| 202 |
+
|
| 203 |
+
* Esprima counts trailing whitespace as part of each AST node while Espree does not. In Espree, the end of a node is where the last token occurs.
|
| 204 |
+
* Espree does not parse `let` and `const` declarations by default.
|
| 205 |
+
* Error messages returned for parsing errors are different.
|
| 206 |
+
* There are two addition properties on every node and token: `start` and `end`. These represent the same data as `range` and are used internally by Acorn.
|
| 207 |
+
|
| 208 |
+
### Esprima 2.x
|
| 209 |
+
|
| 210 |
+
* Esprima 2.x uses a different comment attachment algorithm that results in some comments being added in different places than Espree. The algorithm Espree uses is the same one used in Esprima 1.2.2.
|
| 211 |
+
|
| 212 |
+
## Frequently Asked Questions
|
| 213 |
+
|
| 214 |
+
### Why another parser
|
| 215 |
+
|
| 216 |
+
[ESLint](http://eslint.org) had been relying on Esprima as its parser from the beginning. While that was fine when the JavaScript language was evolving slowly, the pace of development increased dramatically and Esprima had fallen behind. ESLint, like many other tools reliant on Esprima, has been stuck in using new JavaScript language features until Esprima updates, and that caused our users frustration.
|
| 217 |
+
|
| 218 |
+
We decided the only way for us to move forward was to create our own parser, bringing us inline with JSHint and JSLint, and allowing us to keep implementing new features as we need them. We chose to fork Esprima instead of starting from scratch in order to move as quickly as possible with a compatible API.
|
| 219 |
+
|
| 220 |
+
With Espree 2.0.0, we are no longer a fork of Esprima but rather a translation layer between Acorn and Esprima syntax. This allows us to put work back into a community-supported parser (Acorn) that is continuing to grow and evolve while maintaining an Esprima-compatible parser for those utilities still built on Esprima.
|
| 221 |
+
|
| 222 |
+
### Have you tried working with Esprima?
|
| 223 |
+
|
| 224 |
+
Yes. Since the start of ESLint, we've regularly filed bugs and feature requests with Esprima and will continue to do so. However, there are some different philosophies around how the projects work that need to be worked through. The initial goal was to have Espree track Esprima and eventually merge the two back together, but we ultimately decided that building on top of Acorn was a better choice due to Acorn's plugin support.
|
| 225 |
+
|
| 226 |
+
### Why don't you just use Acorn?
|
| 227 |
+
|
| 228 |
+
Acorn is a great JavaScript parser that produces an AST that is compatible with Esprima. Unfortunately, ESLint relies on more than just the AST to do its job. It relies on Esprima's tokens and comment attachment features to get a complete picture of the source code. We investigated switching to Acorn, but the inconsistencies between Esprima and Acorn created too much work for a project like ESLint.
|
| 229 |
+
|
| 230 |
+
We are building on top of Acorn, however, so that we can contribute back and help make Acorn even better.
|
| 231 |
+
|
| 232 |
+
### What ECMAScript features do you support?
|
| 233 |
+
|
| 234 |
+
Espree supports all ECMAScript 2025 features and partially supports ECMAScript 2026 features.
|
| 235 |
+
|
| 236 |
+
Because ECMAScript 2026 is still under development, we are implementing features as they are finalized. Currently, Espree supports:
|
| 237 |
+
|
| 238 |
+
* [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)
|
| 239 |
+
|
| 240 |
+
See [finished-proposals.md](https://github.com/tc39/proposals/blob/master/finished-proposals.md) to know what features are finalized.
|
| 241 |
+
|
| 242 |
+
### How do you determine which experimental features to support?
|
| 243 |
+
|
| 244 |
+
In general, we do not support experimental JavaScript features. We may make exceptions from time to time depending on the maturity of the features.
|
| 245 |
+
|
| 246 |
+
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
| 247 |
+
<!--sponsorsstart-->
|
| 248 |
+
## Sponsors
|
| 249 |
+
|
| 250 |
+
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
| 251 |
+
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
| 252 |
+
|
| 253 |
+
<h3>Diamond Sponsors</h3>
|
| 254 |
+
<p><a href="https://www.ag-grid.com/"><img src="https://images.opencollective.com/ag-grid/bec0580/logo.png" alt="AG Grid" height="128"></a></p><h3>Platinum Sponsors</h3>
|
| 255 |
+
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
|
| 256 |
+
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
|
| 257 |
+
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
| 258 |
+
<p><a href="https://sentry.io"><img src="https://github.com/getsentry.png" alt="Sentry" height="32"></a> <a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nolebase.ayaka.io"><img src="https://avatars.githubusercontent.com/u/11081491" alt="Neko" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="LambdaTest" height="32"></a></p>
|
| 259 |
+
<h3>Technology Sponsors</h3>
|
| 260 |
+
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
| 261 |
+
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
| 262 |
+
<!--sponsorsend-->
|
node_modules/espree/dist/espree.cjs
ADDED
|
@@ -0,0 +1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 4 |
+
|
| 5 |
+
var acorn = require('acorn');
|
| 6 |
+
var jsx = require('acorn-jsx');
|
| 7 |
+
var visitorKeys = require('eslint-visitor-keys');
|
| 8 |
+
|
| 9 |
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
| 10 |
+
|
| 11 |
+
function _interopNamespace(e) {
|
| 12 |
+
if (e && e.__esModule) return e;
|
| 13 |
+
var n = Object.create(null);
|
| 14 |
+
if (e) {
|
| 15 |
+
Object.keys(e).forEach(function (k) {
|
| 16 |
+
if (k !== 'default') {
|
| 17 |
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
| 18 |
+
Object.defineProperty(n, k, d.get ? d : {
|
| 19 |
+
enumerable: true,
|
| 20 |
+
get: function () { return e[k]; }
|
| 21 |
+
});
|
| 22 |
+
}
|
| 23 |
+
});
|
| 24 |
+
}
|
| 25 |
+
n["default"] = e;
|
| 26 |
+
return Object.freeze(n);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);
|
| 30 |
+
var jsx__default = /*#__PURE__*/_interopDefaultLegacy(jsx);
|
| 31 |
+
var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* @fileoverview Translates tokens between Acorn format and Esprima format.
|
| 35 |
+
* @author Nicholas C. Zakas
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
//------------------------------------------------------------------------------
|
| 39 |
+
// Requirements
|
| 40 |
+
//------------------------------------------------------------------------------
|
| 41 |
+
|
| 42 |
+
// none!
|
| 43 |
+
|
| 44 |
+
//------------------------------------------------------------------------------
|
| 45 |
+
// Private
|
| 46 |
+
//------------------------------------------------------------------------------
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
// Esprima Token Types
|
| 50 |
+
const Token = {
|
| 51 |
+
Boolean: "Boolean",
|
| 52 |
+
EOF: "<end>",
|
| 53 |
+
Identifier: "Identifier",
|
| 54 |
+
PrivateIdentifier: "PrivateIdentifier",
|
| 55 |
+
Keyword: "Keyword",
|
| 56 |
+
Null: "Null",
|
| 57 |
+
Numeric: "Numeric",
|
| 58 |
+
Punctuator: "Punctuator",
|
| 59 |
+
String: "String",
|
| 60 |
+
RegularExpression: "RegularExpression",
|
| 61 |
+
Template: "Template",
|
| 62 |
+
JSXIdentifier: "JSXIdentifier",
|
| 63 |
+
JSXText: "JSXText"
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Converts part of a template into an Esprima token.
|
| 68 |
+
* @param {AcornToken[]} tokens The Acorn tokens representing the template.
|
| 69 |
+
* @param {string} code The source code.
|
| 70 |
+
* @returns {EsprimaToken} The Esprima equivalent of the template token.
|
| 71 |
+
* @private
|
| 72 |
+
*/
|
| 73 |
+
function convertTemplatePart(tokens, code) {
|
| 74 |
+
const firstToken = tokens[0],
|
| 75 |
+
lastTemplateToken = tokens.at(-1);
|
| 76 |
+
|
| 77 |
+
const token = {
|
| 78 |
+
type: Token.Template,
|
| 79 |
+
value: code.slice(firstToken.start, lastTemplateToken.end)
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
if (firstToken.loc) {
|
| 83 |
+
token.loc = {
|
| 84 |
+
start: firstToken.loc.start,
|
| 85 |
+
end: lastTemplateToken.loc.end
|
| 86 |
+
};
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
if (firstToken.range) {
|
| 90 |
+
token.start = firstToken.range[0];
|
| 91 |
+
token.end = lastTemplateToken.range[1];
|
| 92 |
+
token.range = [token.start, token.end];
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return token;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Contains logic to translate Acorn tokens into Esprima tokens.
|
| 100 |
+
* @param {Object} acornTokTypes The Acorn token types.
|
| 101 |
+
* @param {string} code The source code Acorn is parsing. This is necessary
|
| 102 |
+
* to correct the "value" property of some tokens.
|
| 103 |
+
* @constructor
|
| 104 |
+
*/
|
| 105 |
+
function TokenTranslator(acornTokTypes, code) {
|
| 106 |
+
|
| 107 |
+
// token types
|
| 108 |
+
this._acornTokTypes = acornTokTypes;
|
| 109 |
+
|
| 110 |
+
// token buffer for templates
|
| 111 |
+
this._tokens = [];
|
| 112 |
+
|
| 113 |
+
// track the last curly brace
|
| 114 |
+
this._curlyBrace = null;
|
| 115 |
+
|
| 116 |
+
// the source code
|
| 117 |
+
this._code = code;
|
| 118 |
+
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
TokenTranslator.prototype = {
|
| 122 |
+
constructor: TokenTranslator,
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Translates a single Esprima token to a single Acorn token. This may be
|
| 126 |
+
* inaccurate due to how templates are handled differently in Esprima and
|
| 127 |
+
* Acorn, but should be accurate for all other tokens.
|
| 128 |
+
* @param {AcornToken} token The Acorn token to translate.
|
| 129 |
+
* @param {Object} extra Espree extra object.
|
| 130 |
+
* @returns {EsprimaToken} The Esprima version of the token.
|
| 131 |
+
*/
|
| 132 |
+
translate(token, extra) {
|
| 133 |
+
|
| 134 |
+
const type = token.type,
|
| 135 |
+
tt = this._acornTokTypes;
|
| 136 |
+
|
| 137 |
+
if (type === tt.name) {
|
| 138 |
+
token.type = Token.Identifier;
|
| 139 |
+
|
| 140 |
+
// TODO: See if this is an Acorn bug
|
| 141 |
+
if (token.value === "static") {
|
| 142 |
+
token.type = Token.Keyword;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
if (extra.ecmaVersion > 5 && (token.value === "yield" || token.value === "let")) {
|
| 146 |
+
token.type = Token.Keyword;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
} else if (type === tt.privateId) {
|
| 150 |
+
token.type = Token.PrivateIdentifier;
|
| 151 |
+
|
| 152 |
+
} else if (type === tt.semi || type === tt.comma ||
|
| 153 |
+
type === tt.parenL || type === tt.parenR ||
|
| 154 |
+
type === tt.braceL || type === tt.braceR ||
|
| 155 |
+
type === tt.dot || type === tt.bracketL ||
|
| 156 |
+
type === tt.colon || type === tt.question ||
|
| 157 |
+
type === tt.bracketR || type === tt.ellipsis ||
|
| 158 |
+
type === tt.arrow || type === tt.jsxTagStart ||
|
| 159 |
+
type === tt.incDec || type === tt.starstar ||
|
| 160 |
+
type === tt.jsxTagEnd || type === tt.prefix ||
|
| 161 |
+
type === tt.questionDot ||
|
| 162 |
+
(type.binop && !type.keyword) ||
|
| 163 |
+
type.isAssign) {
|
| 164 |
+
|
| 165 |
+
token.type = Token.Punctuator;
|
| 166 |
+
token.value = this._code.slice(token.start, token.end);
|
| 167 |
+
} else if (type === tt.jsxName) {
|
| 168 |
+
token.type = Token.JSXIdentifier;
|
| 169 |
+
} else if (type.label === "jsxText" || type === tt.jsxAttrValueToken) {
|
| 170 |
+
token.type = Token.JSXText;
|
| 171 |
+
} else if (type.keyword) {
|
| 172 |
+
if (type.keyword === "true" || type.keyword === "false") {
|
| 173 |
+
token.type = Token.Boolean;
|
| 174 |
+
} else if (type.keyword === "null") {
|
| 175 |
+
token.type = Token.Null;
|
| 176 |
+
} else {
|
| 177 |
+
token.type = Token.Keyword;
|
| 178 |
+
}
|
| 179 |
+
} else if (type === tt.num) {
|
| 180 |
+
token.type = Token.Numeric;
|
| 181 |
+
token.value = this._code.slice(token.start, token.end);
|
| 182 |
+
} else if (type === tt.string) {
|
| 183 |
+
|
| 184 |
+
if (extra.jsxAttrValueToken) {
|
| 185 |
+
extra.jsxAttrValueToken = false;
|
| 186 |
+
token.type = Token.JSXText;
|
| 187 |
+
} else {
|
| 188 |
+
token.type = Token.String;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
token.value = this._code.slice(token.start, token.end);
|
| 192 |
+
} else if (type === tt.regexp) {
|
| 193 |
+
token.type = Token.RegularExpression;
|
| 194 |
+
const value = token.value;
|
| 195 |
+
|
| 196 |
+
token.regex = {
|
| 197 |
+
flags: value.flags,
|
| 198 |
+
pattern: value.pattern
|
| 199 |
+
};
|
| 200 |
+
token.value = `/${value.pattern}/${value.flags}`;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
return token;
|
| 204 |
+
},
|
| 205 |
+
|
| 206 |
+
/**
|
| 207 |
+
* Function to call during Acorn's onToken handler.
|
| 208 |
+
* @param {AcornToken} token The Acorn token.
|
| 209 |
+
* @param {Object} extra The Espree extra object.
|
| 210 |
+
* @returns {void}
|
| 211 |
+
*/
|
| 212 |
+
onToken(token, extra) {
|
| 213 |
+
|
| 214 |
+
const tt = this._acornTokTypes,
|
| 215 |
+
tokens = extra.tokens,
|
| 216 |
+
templateTokens = this._tokens;
|
| 217 |
+
|
| 218 |
+
/**
|
| 219 |
+
* Flushes the buffered template tokens and resets the template
|
| 220 |
+
* tracking.
|
| 221 |
+
* @returns {void}
|
| 222 |
+
* @private
|
| 223 |
+
*/
|
| 224 |
+
const translateTemplateTokens = () => {
|
| 225 |
+
tokens.push(convertTemplatePart(this._tokens, this._code));
|
| 226 |
+
this._tokens = [];
|
| 227 |
+
};
|
| 228 |
+
|
| 229 |
+
if (token.type === tt.eof) {
|
| 230 |
+
|
| 231 |
+
// might be one last curlyBrace
|
| 232 |
+
if (this._curlyBrace) {
|
| 233 |
+
tokens.push(this.translate(this._curlyBrace, extra));
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
return;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
if (token.type === tt.backQuote) {
|
| 240 |
+
|
| 241 |
+
// if there's already a curly, it's not part of the template
|
| 242 |
+
if (this._curlyBrace) {
|
| 243 |
+
tokens.push(this.translate(this._curlyBrace, extra));
|
| 244 |
+
this._curlyBrace = null;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
templateTokens.push(token);
|
| 248 |
+
|
| 249 |
+
// it's the end
|
| 250 |
+
if (templateTokens.length > 1) {
|
| 251 |
+
translateTemplateTokens();
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
return;
|
| 255 |
+
}
|
| 256 |
+
if (token.type === tt.dollarBraceL) {
|
| 257 |
+
templateTokens.push(token);
|
| 258 |
+
translateTemplateTokens();
|
| 259 |
+
return;
|
| 260 |
+
}
|
| 261 |
+
if (token.type === tt.braceR) {
|
| 262 |
+
|
| 263 |
+
// if there's already a curly, it's not part of the template
|
| 264 |
+
if (this._curlyBrace) {
|
| 265 |
+
tokens.push(this.translate(this._curlyBrace, extra));
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
// store new curly for later
|
| 269 |
+
this._curlyBrace = token;
|
| 270 |
+
return;
|
| 271 |
+
}
|
| 272 |
+
if (token.type === tt.template || token.type === tt.invalidTemplate) {
|
| 273 |
+
if (this._curlyBrace) {
|
| 274 |
+
templateTokens.push(this._curlyBrace);
|
| 275 |
+
this._curlyBrace = null;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
templateTokens.push(token);
|
| 279 |
+
return;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
if (this._curlyBrace) {
|
| 283 |
+
tokens.push(this.translate(this._curlyBrace, extra));
|
| 284 |
+
this._curlyBrace = null;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
tokens.push(this.translate(token, extra));
|
| 288 |
+
}
|
| 289 |
+
};
|
| 290 |
+
|
| 291 |
+
/**
|
| 292 |
+
* @fileoverview A collection of methods for processing Espree's options.
|
| 293 |
+
* @author Kai Cataldo
|
| 294 |
+
*/
|
| 295 |
+
|
| 296 |
+
//------------------------------------------------------------------------------
|
| 297 |
+
// Helpers
|
| 298 |
+
//------------------------------------------------------------------------------
|
| 299 |
+
|
| 300 |
+
const SUPPORTED_VERSIONS = [
|
| 301 |
+
3,
|
| 302 |
+
5,
|
| 303 |
+
6, // 2015
|
| 304 |
+
7, // 2016
|
| 305 |
+
8, // 2017
|
| 306 |
+
9, // 2018
|
| 307 |
+
10, // 2019
|
| 308 |
+
11, // 2020
|
| 309 |
+
12, // 2021
|
| 310 |
+
13, // 2022
|
| 311 |
+
14, // 2023
|
| 312 |
+
15, // 2024
|
| 313 |
+
16, // 2025
|
| 314 |
+
17 // 2026
|
| 315 |
+
];
|
| 316 |
+
|
| 317 |
+
/**
|
| 318 |
+
* Get the latest ECMAScript version supported by Espree.
|
| 319 |
+
* @returns {number} The latest ECMAScript version.
|
| 320 |
+
*/
|
| 321 |
+
function getLatestEcmaVersion() {
|
| 322 |
+
return SUPPORTED_VERSIONS.at(-1);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
/**
|
| 326 |
+
* Get the list of ECMAScript versions supported by Espree.
|
| 327 |
+
* @returns {number[]} An array containing the supported ECMAScript versions.
|
| 328 |
+
*/
|
| 329 |
+
function getSupportedEcmaVersions() {
|
| 330 |
+
return [...SUPPORTED_VERSIONS];
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
/**
|
| 334 |
+
* Normalize ECMAScript version from the initial config
|
| 335 |
+
* @param {(number|"latest")} ecmaVersion ECMAScript version from the initial config
|
| 336 |
+
* @throws {Error} throws an error if the ecmaVersion is invalid.
|
| 337 |
+
* @returns {number} normalized ECMAScript version
|
| 338 |
+
*/
|
| 339 |
+
function normalizeEcmaVersion(ecmaVersion = 5) {
|
| 340 |
+
|
| 341 |
+
let version = ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion;
|
| 342 |
+
|
| 343 |
+
if (typeof version !== "number") {
|
| 344 |
+
throw new Error(`ecmaVersion must be a number or "latest". Received value of type ${typeof ecmaVersion} instead.`);
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// Calculate ECMAScript edition number from official year version starting with
|
| 348 |
+
// ES2015, which corresponds with ES6 (or a difference of 2009).
|
| 349 |
+
if (version >= 2015) {
|
| 350 |
+
version -= 2009;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
| 354 |
+
throw new Error("Invalid ecmaVersion.");
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
return version;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
/**
|
| 361 |
+
* Normalize sourceType from the initial config
|
| 362 |
+
* @param {string} sourceType to normalize
|
| 363 |
+
* @throws {Error} throw an error if sourceType is invalid
|
| 364 |
+
* @returns {string} normalized sourceType
|
| 365 |
+
*/
|
| 366 |
+
function normalizeSourceType(sourceType = "script") {
|
| 367 |
+
if (sourceType === "script" || sourceType === "module") {
|
| 368 |
+
return sourceType;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
if (sourceType === "commonjs") {
|
| 372 |
+
return "script";
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
throw new Error("Invalid sourceType.");
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
/**
|
| 379 |
+
* Normalize parserOptions
|
| 380 |
+
* @param {Object} options the parser options to normalize
|
| 381 |
+
* @throws {Error} throw an error if found invalid option.
|
| 382 |
+
* @returns {Object} normalized options
|
| 383 |
+
*/
|
| 384 |
+
function normalizeOptions(options) {
|
| 385 |
+
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
|
| 386 |
+
const sourceType = normalizeSourceType(options.sourceType);
|
| 387 |
+
const ranges = options.range === true;
|
| 388 |
+
const locations = options.loc === true;
|
| 389 |
+
|
| 390 |
+
if (ecmaVersion !== 3 && options.allowReserved) {
|
| 391 |
+
|
| 392 |
+
// a value of `false` is intentionally allowed here, so a shared config can overwrite it when needed
|
| 393 |
+
throw new Error("`allowReserved` is only supported when ecmaVersion is 3");
|
| 394 |
+
}
|
| 395 |
+
if (typeof options.allowReserved !== "undefined" && typeof options.allowReserved !== "boolean") {
|
| 396 |
+
throw new Error("`allowReserved`, when present, must be `true` or `false`");
|
| 397 |
+
}
|
| 398 |
+
const allowReserved = ecmaVersion === 3 ? (options.allowReserved || "never") : false;
|
| 399 |
+
const ecmaFeatures = options.ecmaFeatures || {};
|
| 400 |
+
const allowReturnOutsideFunction = options.sourceType === "commonjs" ||
|
| 401 |
+
Boolean(ecmaFeatures.globalReturn);
|
| 402 |
+
|
| 403 |
+
if (sourceType === "module" && ecmaVersion < 6) {
|
| 404 |
+
throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
return Object.assign({}, options, {
|
| 408 |
+
ecmaVersion,
|
| 409 |
+
sourceType,
|
| 410 |
+
ranges,
|
| 411 |
+
locations,
|
| 412 |
+
allowReserved,
|
| 413 |
+
allowReturnOutsideFunction
|
| 414 |
+
});
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/* eslint no-param-reassign: 0 -- stylistic choice */
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
const STATE = Symbol("espree's internal state");
|
| 421 |
+
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
/**
|
| 425 |
+
* Converts an Acorn comment to a Esprima comment.
|
| 426 |
+
* @param {boolean} block True if it's a block comment, false if not.
|
| 427 |
+
* @param {string} text The text of the comment.
|
| 428 |
+
* @param {int} start The index at which the comment starts.
|
| 429 |
+
* @param {int} end The index at which the comment ends.
|
| 430 |
+
* @param {Location} startLoc The location at which the comment starts.
|
| 431 |
+
* @param {Location} endLoc The location at which the comment ends.
|
| 432 |
+
* @param {string} code The source code being parsed.
|
| 433 |
+
* @returns {Object} The comment object.
|
| 434 |
+
* @private
|
| 435 |
+
*/
|
| 436 |
+
function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code) {
|
| 437 |
+
let type;
|
| 438 |
+
|
| 439 |
+
if (block) {
|
| 440 |
+
type = "Block";
|
| 441 |
+
} else if (code.slice(start, start + 2) === "#!") {
|
| 442 |
+
type = "Hashbang";
|
| 443 |
+
} else {
|
| 444 |
+
type = "Line";
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
const comment = {
|
| 448 |
+
type,
|
| 449 |
+
value: text
|
| 450 |
+
};
|
| 451 |
+
|
| 452 |
+
if (typeof start === "number") {
|
| 453 |
+
comment.start = start;
|
| 454 |
+
comment.end = end;
|
| 455 |
+
comment.range = [start, end];
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
if (typeof startLoc === "object") {
|
| 459 |
+
comment.loc = {
|
| 460 |
+
start: startLoc,
|
| 461 |
+
end: endLoc
|
| 462 |
+
};
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
return comment;
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
var espree = () => Parser => {
|
| 469 |
+
const tokTypes = Object.assign({}, Parser.acorn.tokTypes);
|
| 470 |
+
|
| 471 |
+
if (Parser.acornJsx) {
|
| 472 |
+
Object.assign(tokTypes, Parser.acornJsx.tokTypes);
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
return class Espree extends Parser {
|
| 476 |
+
constructor(opts, code) {
|
| 477 |
+
if (typeof opts !== "object" || opts === null) {
|
| 478 |
+
opts = {};
|
| 479 |
+
}
|
| 480 |
+
if (typeof code !== "string" && !(code instanceof String)) {
|
| 481 |
+
code = String(code);
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
// save original source type in case of commonjs
|
| 485 |
+
const originalSourceType = opts.sourceType;
|
| 486 |
+
const options = normalizeOptions(opts);
|
| 487 |
+
const ecmaFeatures = options.ecmaFeatures || {};
|
| 488 |
+
const tokenTranslator =
|
| 489 |
+
options.tokens === true
|
| 490 |
+
? new TokenTranslator(tokTypes, code)
|
| 491 |
+
: null;
|
| 492 |
+
|
| 493 |
+
/*
|
| 494 |
+
* Data that is unique to Espree and is not represented internally
|
| 495 |
+
* in Acorn.
|
| 496 |
+
*
|
| 497 |
+
* For ES2023 hashbangs, Espree will call `onComment()` during the
|
| 498 |
+
* constructor, so we must define state before having access to
|
| 499 |
+
* `this`.
|
| 500 |
+
*/
|
| 501 |
+
const state = {
|
| 502 |
+
originalSourceType: originalSourceType || options.sourceType,
|
| 503 |
+
tokens: tokenTranslator ? [] : null,
|
| 504 |
+
comments: options.comment === true ? [] : null,
|
| 505 |
+
impliedStrict: ecmaFeatures.impliedStrict === true && options.ecmaVersion >= 5,
|
| 506 |
+
ecmaVersion: options.ecmaVersion,
|
| 507 |
+
jsxAttrValueToken: false,
|
| 508 |
+
lastToken: null,
|
| 509 |
+
templateElements: []
|
| 510 |
+
};
|
| 511 |
+
|
| 512 |
+
// Initialize acorn parser.
|
| 513 |
+
super({
|
| 514 |
+
|
| 515 |
+
// do not use spread, because we don't want to pass any unknown options to acorn
|
| 516 |
+
ecmaVersion: options.ecmaVersion,
|
| 517 |
+
sourceType: options.sourceType,
|
| 518 |
+
ranges: options.ranges,
|
| 519 |
+
locations: options.locations,
|
| 520 |
+
allowReserved: options.allowReserved,
|
| 521 |
+
|
| 522 |
+
// Truthy value is true for backward compatibility.
|
| 523 |
+
allowReturnOutsideFunction: options.allowReturnOutsideFunction,
|
| 524 |
+
|
| 525 |
+
// Collect tokens
|
| 526 |
+
onToken(token) {
|
| 527 |
+
if (tokenTranslator) {
|
| 528 |
+
|
| 529 |
+
// Use `tokens`, `ecmaVersion`, and `jsxAttrValueToken` in the state.
|
| 530 |
+
tokenTranslator.onToken(token, state);
|
| 531 |
+
}
|
| 532 |
+
if (token.type !== tokTypes.eof) {
|
| 533 |
+
state.lastToken = token;
|
| 534 |
+
}
|
| 535 |
+
},
|
| 536 |
+
|
| 537 |
+
// Collect comments
|
| 538 |
+
onComment(block, text, start, end, startLoc, endLoc) {
|
| 539 |
+
if (state.comments) {
|
| 540 |
+
const comment = convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code);
|
| 541 |
+
|
| 542 |
+
state.comments.push(comment);
|
| 543 |
+
}
|
| 544 |
+
}
|
| 545 |
+
}, code);
|
| 546 |
+
|
| 547 |
+
/*
|
| 548 |
+
* We put all of this data into a symbol property as a way to avoid
|
| 549 |
+
* potential naming conflicts with future versions of Acorn.
|
| 550 |
+
*/
|
| 551 |
+
this[STATE] = state;
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
tokenize() {
|
| 555 |
+
do {
|
| 556 |
+
this.next();
|
| 557 |
+
} while (this.type !== tokTypes.eof);
|
| 558 |
+
|
| 559 |
+
// Consume the final eof token
|
| 560 |
+
this.next();
|
| 561 |
+
|
| 562 |
+
const extra = this[STATE];
|
| 563 |
+
const tokens = extra.tokens;
|
| 564 |
+
|
| 565 |
+
if (extra.comments) {
|
| 566 |
+
tokens.comments = extra.comments;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
return tokens;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
finishNode(...args) {
|
| 573 |
+
const result = super.finishNode(...args);
|
| 574 |
+
|
| 575 |
+
return this[ESPRIMA_FINISH_NODE](result);
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
finishNodeAt(...args) {
|
| 579 |
+
const result = super.finishNodeAt(...args);
|
| 580 |
+
|
| 581 |
+
return this[ESPRIMA_FINISH_NODE](result);
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
parse() {
|
| 585 |
+
const extra = this[STATE];
|
| 586 |
+
const program = super.parse();
|
| 587 |
+
|
| 588 |
+
program.sourceType = extra.originalSourceType;
|
| 589 |
+
|
| 590 |
+
if (extra.comments) {
|
| 591 |
+
program.comments = extra.comments;
|
| 592 |
+
}
|
| 593 |
+
if (extra.tokens) {
|
| 594 |
+
program.tokens = extra.tokens;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
/*
|
| 598 |
+
* Adjust opening and closing position of program to match Esprima.
|
| 599 |
+
* Acorn always starts programs at range 0 whereas Esprima starts at the
|
| 600 |
+
* first AST node's start (the only real difference is when there's leading
|
| 601 |
+
* whitespace or leading comments). Acorn also counts trailing whitespace
|
| 602 |
+
* as part of the program whereas Esprima only counts up to the last token.
|
| 603 |
+
*/
|
| 604 |
+
if (program.body.length) {
|
| 605 |
+
const [firstNode] = program.body;
|
| 606 |
+
|
| 607 |
+
if (program.range) {
|
| 608 |
+
program.range[0] = firstNode.range[0];
|
| 609 |
+
}
|
| 610 |
+
if (program.loc) {
|
| 611 |
+
program.loc.start = firstNode.loc.start;
|
| 612 |
+
}
|
| 613 |
+
program.start = firstNode.start;
|
| 614 |
+
}
|
| 615 |
+
if (extra.lastToken) {
|
| 616 |
+
if (program.range) {
|
| 617 |
+
program.range[1] = extra.lastToken.range[1];
|
| 618 |
+
}
|
| 619 |
+
if (program.loc) {
|
| 620 |
+
program.loc.end = extra.lastToken.loc.end;
|
| 621 |
+
}
|
| 622 |
+
program.end = extra.lastToken.end;
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
|
| 626 |
+
/*
|
| 627 |
+
* https://github.com/eslint/espree/issues/349
|
| 628 |
+
* Ensure that template elements have correct range information.
|
| 629 |
+
* This is one location where Acorn produces a different value
|
| 630 |
+
* for its start and end properties vs. the values present in the
|
| 631 |
+
* range property. In order to avoid confusion, we set the start
|
| 632 |
+
* and end properties to the values that are present in range.
|
| 633 |
+
* This is done here, instead of in finishNode(), because Acorn
|
| 634 |
+
* uses the values of start and end internally while parsing, making
|
| 635 |
+
* it dangerous to change those values while parsing is ongoing.
|
| 636 |
+
* By waiting until the end of parsing, we can safely change these
|
| 637 |
+
* values without affect any other part of the process.
|
| 638 |
+
*/
|
| 639 |
+
this[STATE].templateElements.forEach(templateElement => {
|
| 640 |
+
const startOffset = -1;
|
| 641 |
+
const endOffset = templateElement.tail ? 1 : 2;
|
| 642 |
+
|
| 643 |
+
templateElement.start += startOffset;
|
| 644 |
+
templateElement.end += endOffset;
|
| 645 |
+
|
| 646 |
+
if (templateElement.range) {
|
| 647 |
+
templateElement.range[0] += startOffset;
|
| 648 |
+
templateElement.range[1] += endOffset;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
if (templateElement.loc) {
|
| 652 |
+
templateElement.loc.start.column += startOffset;
|
| 653 |
+
templateElement.loc.end.column += endOffset;
|
| 654 |
+
}
|
| 655 |
+
});
|
| 656 |
+
|
| 657 |
+
return program;
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
parseTopLevel(node) {
|
| 661 |
+
if (this[STATE].impliedStrict) {
|
| 662 |
+
this.strict = true;
|
| 663 |
+
}
|
| 664 |
+
return super.parseTopLevel(node);
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
/**
|
| 668 |
+
* Overwrites the default raise method to throw Esprima-style errors.
|
| 669 |
+
* @param {int} pos The position of the error.
|
| 670 |
+
* @param {string} message The error message.
|
| 671 |
+
* @throws {SyntaxError} A syntax error.
|
| 672 |
+
* @returns {void}
|
| 673 |
+
*/
|
| 674 |
+
raise(pos, message) {
|
| 675 |
+
const loc = Parser.acorn.getLineInfo(this.input, pos);
|
| 676 |
+
const err = new SyntaxError(message);
|
| 677 |
+
|
| 678 |
+
err.index = pos;
|
| 679 |
+
err.lineNumber = loc.line;
|
| 680 |
+
err.column = loc.column + 1; // acorn uses 0-based columns
|
| 681 |
+
throw err;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
/**
|
| 685 |
+
* Overwrites the default raise method to throw Esprima-style errors.
|
| 686 |
+
* @param {int} pos The position of the error.
|
| 687 |
+
* @param {string} message The error message.
|
| 688 |
+
* @throws {SyntaxError} A syntax error.
|
| 689 |
+
* @returns {void}
|
| 690 |
+
*/
|
| 691 |
+
raiseRecoverable(pos, message) {
|
| 692 |
+
this.raise(pos, message);
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
/**
|
| 696 |
+
* Overwrites the default unexpected method to throw Esprima-style errors.
|
| 697 |
+
* @param {int} pos The position of the error.
|
| 698 |
+
* @throws {SyntaxError} A syntax error.
|
| 699 |
+
* @returns {void}
|
| 700 |
+
*/
|
| 701 |
+
unexpected(pos) {
|
| 702 |
+
let message = "Unexpected token";
|
| 703 |
+
|
| 704 |
+
if (pos !== null && pos !== void 0) {
|
| 705 |
+
this.pos = pos;
|
| 706 |
+
|
| 707 |
+
if (this.options.locations) {
|
| 708 |
+
while (this.pos < this.lineStart) {
|
| 709 |
+
this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
|
| 710 |
+
--this.curLine;
|
| 711 |
+
}
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
this.nextToken();
|
| 715 |
+
}
|
| 716 |
+
|
| 717 |
+
if (this.end > this.start) {
|
| 718 |
+
message += ` ${this.input.slice(this.start, this.end)}`;
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
this.raise(this.start, message);
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
/*
|
| 725 |
+
* Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX
|
| 726 |
+
* uses regular tt.string without any distinction between this and regular JS
|
| 727 |
+
* strings. As such, we intercept an attempt to read a JSX string and set a flag
|
| 728 |
+
* on extra so that when tokens are converted, the next token will be switched
|
| 729 |
+
* to JSXText via onToken.
|
| 730 |
+
*/
|
| 731 |
+
jsx_readString(quote) { // eslint-disable-line camelcase -- required by API
|
| 732 |
+
const result = super.jsx_readString(quote);
|
| 733 |
+
|
| 734 |
+
if (this.type === tokTypes.string) {
|
| 735 |
+
this[STATE].jsxAttrValueToken = true;
|
| 736 |
+
}
|
| 737 |
+
return result;
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
/**
|
| 741 |
+
* Performs last-minute Esprima-specific compatibility checks and fixes.
|
| 742 |
+
* @param {ASTNode} result The node to check.
|
| 743 |
+
* @returns {ASTNode} The finished node.
|
| 744 |
+
*/
|
| 745 |
+
[ESPRIMA_FINISH_NODE](result) {
|
| 746 |
+
|
| 747 |
+
// Acorn doesn't count the opening and closing backticks as part of templates
|
| 748 |
+
// so we have to adjust ranges/locations appropriately.
|
| 749 |
+
if (result.type === "TemplateElement") {
|
| 750 |
+
|
| 751 |
+
// save template element references to fix start/end later
|
| 752 |
+
this[STATE].templateElements.push(result);
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
if (result.type.includes("Function") && !result.generator) {
|
| 756 |
+
result.generator = false;
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
return result;
|
| 760 |
+
}
|
| 761 |
+
};
|
| 762 |
+
};
|
| 763 |
+
|
| 764 |
+
const version$1 = "10.4.0";
|
| 765 |
+
|
| 766 |
+
/**
|
| 767 |
+
* @fileoverview Main Espree file that converts Acorn into Esprima output.
|
| 768 |
+
*
|
| 769 |
+
* This file contains code from the following MIT-licensed projects:
|
| 770 |
+
* 1. Acorn
|
| 771 |
+
* 2. Babylon
|
| 772 |
+
* 3. Babel-ESLint
|
| 773 |
+
*
|
| 774 |
+
* This file also contains code from Esprima, which is BSD licensed.
|
| 775 |
+
*
|
| 776 |
+
* Acorn is Copyright 2012-2015 Acorn Contributors (https://github.com/marijnh/acorn/blob/master/AUTHORS)
|
| 777 |
+
* Babylon is Copyright 2014-2015 various contributors (https://github.com/babel/babel/blob/master/packages/babylon/AUTHORS)
|
| 778 |
+
* Babel-ESLint is Copyright 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
|
| 779 |
+
*
|
| 780 |
+
* Redistribution and use in source and binary forms, with or without
|
| 781 |
+
* modification, are permitted provided that the following conditions are met:
|
| 782 |
+
*
|
| 783 |
+
* * Redistributions of source code must retain the above copyright
|
| 784 |
+
* notice, this list of conditions and the following disclaimer.
|
| 785 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 786 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 787 |
+
* documentation and/or other materials provided with the distribution.
|
| 788 |
+
*
|
| 789 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 790 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 791 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 792 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 793 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 794 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 795 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 796 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 797 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 798 |
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 799 |
+
*
|
| 800 |
+
* Esprima is Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
|
| 801 |
+
*
|
| 802 |
+
* Redistribution and use in source and binary forms, with or without
|
| 803 |
+
* modification, are permitted provided that the following conditions are met:
|
| 804 |
+
*
|
| 805 |
+
* * Redistributions of source code must retain the above copyright
|
| 806 |
+
* notice, this list of conditions and the following disclaimer.
|
| 807 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 808 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 809 |
+
* documentation and/or other materials provided with the distribution.
|
| 810 |
+
*
|
| 811 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 812 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 813 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 814 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 815 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 816 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 817 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 818 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 819 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 820 |
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 821 |
+
*/
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
// To initialize lazily.
|
| 825 |
+
const parsers = {
|
| 826 |
+
_regular: null,
|
| 827 |
+
_jsx: null,
|
| 828 |
+
|
| 829 |
+
get regular() {
|
| 830 |
+
if (this._regular === null) {
|
| 831 |
+
this._regular = acorn__namespace.Parser.extend(espree());
|
| 832 |
+
}
|
| 833 |
+
return this._regular;
|
| 834 |
+
},
|
| 835 |
+
|
| 836 |
+
get jsx() {
|
| 837 |
+
if (this._jsx === null) {
|
| 838 |
+
this._jsx = acorn__namespace.Parser.extend(jsx__default["default"](), espree());
|
| 839 |
+
}
|
| 840 |
+
return this._jsx;
|
| 841 |
+
},
|
| 842 |
+
|
| 843 |
+
get(options) {
|
| 844 |
+
const useJsx = Boolean(
|
| 845 |
+
options &&
|
| 846 |
+
options.ecmaFeatures &&
|
| 847 |
+
options.ecmaFeatures.jsx
|
| 848 |
+
);
|
| 849 |
+
|
| 850 |
+
return useJsx ? this.jsx : this.regular;
|
| 851 |
+
}
|
| 852 |
+
};
|
| 853 |
+
|
| 854 |
+
//------------------------------------------------------------------------------
|
| 855 |
+
// Tokenizer
|
| 856 |
+
//------------------------------------------------------------------------------
|
| 857 |
+
|
| 858 |
+
/**
|
| 859 |
+
* Tokenizes the given code.
|
| 860 |
+
* @param {string} code The code to tokenize.
|
| 861 |
+
* @param {Object} options Options defining how to tokenize.
|
| 862 |
+
* @returns {Token[]} An array of tokens.
|
| 863 |
+
* @throws {SyntaxError} If the input code is invalid.
|
| 864 |
+
* @private
|
| 865 |
+
*/
|
| 866 |
+
function tokenize(code, options) {
|
| 867 |
+
const Parser = parsers.get(options);
|
| 868 |
+
|
| 869 |
+
// Ensure to collect tokens.
|
| 870 |
+
if (!options || options.tokens !== true) {
|
| 871 |
+
options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
return new Parser(options, code).tokenize();
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
//------------------------------------------------------------------------------
|
| 878 |
+
// Parser
|
| 879 |
+
//------------------------------------------------------------------------------
|
| 880 |
+
|
| 881 |
+
/**
|
| 882 |
+
* Parses the given code.
|
| 883 |
+
* @param {string} code The code to tokenize.
|
| 884 |
+
* @param {Object} options Options defining how to tokenize.
|
| 885 |
+
* @returns {ASTNode} The "Program" AST node.
|
| 886 |
+
* @throws {SyntaxError} If the input code is invalid.
|
| 887 |
+
*/
|
| 888 |
+
function parse(code, options) {
|
| 889 |
+
const Parser = parsers.get(options);
|
| 890 |
+
|
| 891 |
+
return new Parser(options, code).parse();
|
| 892 |
+
}
|
| 893 |
+
|
| 894 |
+
//------------------------------------------------------------------------------
|
| 895 |
+
// Public
|
| 896 |
+
//------------------------------------------------------------------------------
|
| 897 |
+
|
| 898 |
+
const version = version$1;
|
| 899 |
+
const name = "espree";
|
| 900 |
+
|
| 901 |
+
/* istanbul ignore next */
|
| 902 |
+
const VisitorKeys = (function() {
|
| 903 |
+
return visitorKeys__namespace.KEYS;
|
| 904 |
+
}());
|
| 905 |
+
|
| 906 |
+
// Derive node types from VisitorKeys
|
| 907 |
+
/* istanbul ignore next */
|
| 908 |
+
const Syntax = (function() {
|
| 909 |
+
let key,
|
| 910 |
+
types = {};
|
| 911 |
+
|
| 912 |
+
if (typeof Object.create === "function") {
|
| 913 |
+
types = Object.create(null);
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
for (key in VisitorKeys) {
|
| 917 |
+
if (Object.hasOwn(VisitorKeys, key)) {
|
| 918 |
+
types[key] = key;
|
| 919 |
+
}
|
| 920 |
+
}
|
| 921 |
+
|
| 922 |
+
if (typeof Object.freeze === "function") {
|
| 923 |
+
Object.freeze(types);
|
| 924 |
+
}
|
| 925 |
+
|
| 926 |
+
return types;
|
| 927 |
+
}());
|
| 928 |
+
|
| 929 |
+
const latestEcmaVersion = getLatestEcmaVersion();
|
| 930 |
+
|
| 931 |
+
const supportedEcmaVersions = getSupportedEcmaVersions();
|
| 932 |
+
|
| 933 |
+
exports.Syntax = Syntax;
|
| 934 |
+
exports.VisitorKeys = VisitorKeys;
|
| 935 |
+
exports.latestEcmaVersion = latestEcmaVersion;
|
| 936 |
+
exports.name = name;
|
| 937 |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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Main Espree file that converts Acorn into Esprima output.
|
| 3 |
+
*
|
| 4 |
+
* This file contains code from the following MIT-licensed projects:
|
| 5 |
+
* 1. Acorn
|
| 6 |
+
* 2. Babylon
|
| 7 |
+
* 3. Babel-ESLint
|
| 8 |
+
*
|
| 9 |
+
* This file also contains code from Esprima, which is BSD licensed.
|
| 10 |
+
*
|
| 11 |
+
* Acorn is Copyright 2012-2015 Acorn Contributors (https://github.com/marijnh/acorn/blob/master/AUTHORS)
|
| 12 |
+
* Babylon is Copyright 2014-2015 various contributors (https://github.com/babel/babel/blob/master/packages/babylon/AUTHORS)
|
| 13 |
+
* Babel-ESLint is Copyright 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
|
| 14 |
+
*
|
| 15 |
+
* Redistribution and use in source and binary forms, with or without
|
| 16 |
+
* modification, are permitted provided that the following conditions are met:
|
| 17 |
+
*
|
| 18 |
+
* * Redistributions of source code must retain the above copyright
|
| 19 |
+
* notice, this list of conditions and the following disclaimer.
|
| 20 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 21 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 22 |
+
* documentation and/or other materials provided with the distribution.
|
| 23 |
+
*
|
| 24 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 25 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 26 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 27 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 28 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 29 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 30 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 31 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 32 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 33 |
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 34 |
+
*
|
| 35 |
+
* Esprima is Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
|
| 36 |
+
*
|
| 37 |
+
* Redistribution and use in source and binary forms, with or without
|
| 38 |
+
* modification, are permitted provided that the following conditions are met:
|
| 39 |
+
*
|
| 40 |
+
* * Redistributions of source code must retain the above copyright
|
| 41 |
+
* notice, this list of conditions and the following disclaimer.
|
| 42 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 43 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 44 |
+
* documentation and/or other materials provided with the distribution.
|
| 45 |
+
*
|
| 46 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 47 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 48 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 49 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 50 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 51 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 52 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 53 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 54 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 55 |
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 56 |
+
*/
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
import * as acorn from "acorn";
|
| 60 |
+
import jsx from "acorn-jsx";
|
| 61 |
+
import espree from "./lib/espree.js";
|
| 62 |
+
import espreeVersion from "./lib/version.js";
|
| 63 |
+
import * as visitorKeys from "eslint-visitor-keys";
|
| 64 |
+
import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js";
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
// To initialize lazily.
|
| 68 |
+
const parsers = {
|
| 69 |
+
_regular: null,
|
| 70 |
+
_jsx: null,
|
| 71 |
+
|
| 72 |
+
get regular() {
|
| 73 |
+
if (this._regular === null) {
|
| 74 |
+
this._regular = acorn.Parser.extend(espree());
|
| 75 |
+
}
|
| 76 |
+
return this._regular;
|
| 77 |
+
},
|
| 78 |
+
|
| 79 |
+
get jsx() {
|
| 80 |
+
if (this._jsx === null) {
|
| 81 |
+
this._jsx = acorn.Parser.extend(jsx(), espree());
|
| 82 |
+
}
|
| 83 |
+
return this._jsx;
|
| 84 |
+
},
|
| 85 |
+
|
| 86 |
+
get(options) {
|
| 87 |
+
const useJsx = Boolean(
|
| 88 |
+
options &&
|
| 89 |
+
options.ecmaFeatures &&
|
| 90 |
+
options.ecmaFeatures.jsx
|
| 91 |
+
);
|
| 92 |
+
|
| 93 |
+
return useJsx ? this.jsx : this.regular;
|
| 94 |
+
}
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
//------------------------------------------------------------------------------
|
| 98 |
+
// Tokenizer
|
| 99 |
+
//------------------------------------------------------------------------------
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* Tokenizes the given code.
|
| 103 |
+
* @param {string} code The code to tokenize.
|
| 104 |
+
* @param {Object} options Options defining how to tokenize.
|
| 105 |
+
* @returns {Token[]} An array of tokens.
|
| 106 |
+
* @throws {SyntaxError} If the input code is invalid.
|
| 107 |
+
* @private
|
| 108 |
+
*/
|
| 109 |
+
export function tokenize(code, options) {
|
| 110 |
+
const Parser = parsers.get(options);
|
| 111 |
+
|
| 112 |
+
// Ensure to collect tokens.
|
| 113 |
+
if (!options || options.tokens !== true) {
|
| 114 |
+
options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return new Parser(options, code).tokenize();
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
//------------------------------------------------------------------------------
|
| 121 |
+
// Parser
|
| 122 |
+
//------------------------------------------------------------------------------
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Parses the given code.
|
| 126 |
+
* @param {string} code The code to tokenize.
|
| 127 |
+
* @param {Object} options Options defining how to tokenize.
|
| 128 |
+
* @returns {ASTNode} The "Program" AST node.
|
| 129 |
+
* @throws {SyntaxError} If the input code is invalid.
|
| 130 |
+
*/
|
| 131 |
+
export function parse(code, options) {
|
| 132 |
+
const Parser = parsers.get(options);
|
| 133 |
+
|
| 134 |
+
return new Parser(options, code).parse();
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
//------------------------------------------------------------------------------
|
| 138 |
+
// Public
|
| 139 |
+
//------------------------------------------------------------------------------
|
| 140 |
+
|
| 141 |
+
export const version = espreeVersion;
|
| 142 |
+
export const name = "espree";
|
| 143 |
+
|
| 144 |
+
/* istanbul ignore next */
|
| 145 |
+
export const VisitorKeys = (function() {
|
| 146 |
+
return visitorKeys.KEYS;
|
| 147 |
+
}());
|
| 148 |
+
|
| 149 |
+
// Derive node types from VisitorKeys
|
| 150 |
+
/* istanbul ignore next */
|
| 151 |
+
export const Syntax = (function() {
|
| 152 |
+
let key,
|
| 153 |
+
types = {};
|
| 154 |
+
|
| 155 |
+
if (typeof Object.create === "function") {
|
| 156 |
+
types = Object.create(null);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
for (key in VisitorKeys) {
|
| 160 |
+
if (Object.hasOwn(VisitorKeys, key)) {
|
| 161 |
+
types[key] = key;
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
if (typeof Object.freeze === "function") {
|
| 166 |
+
Object.freeze(types);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
return types;
|
| 170 |
+
}());
|
| 171 |
+
|
| 172 |
+
export const latestEcmaVersion = getLatestEcmaVersion();
|
| 173 |
+
|
| 174 |
+
export const supportedEcmaVersions = getSupportedEcmaVersions();
|