chushihua
This commit is contained in:
+77
@@ -0,0 +1,77 @@
|
||||
# @babel/helper-module-imports
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install @babel/helper-module-imports --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### `import "source"`
|
||||
|
||||
```js
|
||||
import { addSideEffect } from "@babel/helper-module-imports";
|
||||
addSideEffect(path, 'source');
|
||||
```
|
||||
|
||||
### `import { named } from "source"`
|
||||
|
||||
```js
|
||||
import { addNamed } from "@babel/helper-module-imports";
|
||||
addNamed(path, 'named', 'source');
|
||||
```
|
||||
|
||||
### `import { named as _hintedName } from "source"`
|
||||
|
||||
```js
|
||||
import { addNamed } from "@babel/helper-module-imports";
|
||||
addNamed(path, 'named', 'source', { nameHint: "hintedName" });
|
||||
```
|
||||
|
||||
### `import _default from "source"`
|
||||
|
||||
```js
|
||||
import { addDefault } from "@babel/helper-module-imports";
|
||||
addDefault(path, 'source');
|
||||
```
|
||||
|
||||
### `import hintedName from "source"`
|
||||
|
||||
```js
|
||||
import { addDefault } from "@babel/helper-module-imports";
|
||||
addDefault(path, 'source', { nameHint: "hintedName" })
|
||||
```
|
||||
|
||||
### `import * as _namespace from "source"`
|
||||
|
||||
```js
|
||||
import { addNamespace } from "@babel/helper-module-imports";
|
||||
addNamespace(path, 'source');
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Adding a named import
|
||||
|
||||
```js
|
||||
import { addNamed } from "@babel/helper-module-imports";
|
||||
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ReferencedIdentifier(path) {
|
||||
let importName = this.importName;
|
||||
if (importName) {
|
||||
importName = t.cloneDeep(importName);
|
||||
} else {
|
||||
// require('bluebird').coroutine
|
||||
importName = this.importName = addNamed(path, 'coroutine', 'bluebird');
|
||||
}
|
||||
|
||||
path.replaceWith(importName);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = void 0;
|
||||
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var ImportBuilder = function () {
|
||||
function ImportBuilder(importedSource, scope, file) {
|
||||
this._statements = [];
|
||||
this._resultName = null;
|
||||
this._scope = null;
|
||||
this._file = null;
|
||||
this._scope = scope;
|
||||
this._file = file;
|
||||
this._importedSource = importedSource;
|
||||
}
|
||||
|
||||
var _proto = ImportBuilder.prototype;
|
||||
|
||||
_proto.done = function done() {
|
||||
return {
|
||||
statements: this._statements,
|
||||
resultName: this._resultName
|
||||
};
|
||||
};
|
||||
|
||||
_proto.import = function _import() {
|
||||
this._statements.push(t.importDeclaration([], t.stringLiteral(this._importedSource)));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.require = function require() {
|
||||
this._statements.push(t.expressionStatement(t.callExpression(t.identifier("require"), [t.stringLiteral(this._importedSource)])));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.namespace = function namespace(name) {
|
||||
if (name === void 0) {
|
||||
name = "namespace";
|
||||
}
|
||||
|
||||
name = this._scope.generateUidIdentifier(name);
|
||||
var statement = this._statements[this._statements.length - 1];
|
||||
(0, _assert.default)(statement.type === "ImportDeclaration");
|
||||
(0, _assert.default)(statement.specifiers.length === 0);
|
||||
statement.specifiers = [t.importNamespaceSpecifier(name)];
|
||||
this._resultName = t.clone(name);
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.default = function _default(name) {
|
||||
name = this._scope.generateUidIdentifier(name);
|
||||
var statement = this._statements[this._statements.length - 1];
|
||||
(0, _assert.default)(statement.type === "ImportDeclaration");
|
||||
(0, _assert.default)(statement.specifiers.length === 0);
|
||||
statement.specifiers = [t.importDefaultSpecifier(name)];
|
||||
this._resultName = t.clone(name);
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.named = function named(name, importName) {
|
||||
if (importName === "default") return this.default(name);
|
||||
name = this._scope.generateUidIdentifier(name);
|
||||
var statement = this._statements[this._statements.length - 1];
|
||||
(0, _assert.default)(statement.type === "ImportDeclaration");
|
||||
(0, _assert.default)(statement.specifiers.length === 0);
|
||||
statement.specifiers = [t.importSpecifier(name, t.identifier(importName))];
|
||||
this._resultName = t.clone(name);
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.var = function _var(name) {
|
||||
name = this._scope.generateUidIdentifier(name);
|
||||
var statement = this._statements[this._statements.length - 1];
|
||||
|
||||
if (statement.type !== "ExpressionStatement") {
|
||||
(0, _assert.default)(this._resultName);
|
||||
statement = t.expressionStatement(this._resultName);
|
||||
|
||||
this._statements.push(statement);
|
||||
}
|
||||
|
||||
this._statements[this._statements.length - 1] = t.variableDeclaration("var", [t.variableDeclarator(name, statement.expression)]);
|
||||
this._resultName = t.clone(name);
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.defaultInterop = function defaultInterop() {
|
||||
return this._interop(this._file.addHelper("interopRequireDefault"));
|
||||
};
|
||||
|
||||
_proto.wildcardInterop = function wildcardInterop() {
|
||||
return this._interop(this._file.addHelper("interopRequireWildcard"));
|
||||
};
|
||||
|
||||
_proto._interop = function _interop(callee) {
|
||||
var statement = this._statements[this._statements.length - 1];
|
||||
|
||||
if (statement.type === "ExpressionStatement") {
|
||||
statement.expression = t.callExpression(callee, [statement.expression]);
|
||||
} else if (statement.type === "VariableDeclaration") {
|
||||
(0, _assert.default)(statement.declarations.length === 1);
|
||||
statement.declarations[0].init = t.callExpression(callee, [statement.declarations[0].init]);
|
||||
} else {
|
||||
_assert.default.fail("Unexpected type.");
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.prop = function prop(name) {
|
||||
var statement = this._statements[this._statements.length - 1];
|
||||
|
||||
if (statement.type === "ExpressionStatement") {
|
||||
statement.expression = t.memberExpression(statement.expression, t.identifier(name));
|
||||
} else if (statement.type === "VariableDeclaration") {
|
||||
(0, _assert.default)(statement.declarations.length === 1);
|
||||
statement.declarations[0].init = t.memberExpression(statement.declarations[0].init, t.identifier(name));
|
||||
} else {
|
||||
_assert.default.fail("Unexpected type:" + statement.type);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.read = function read(name) {
|
||||
this._resultName = t.memberExpression(this._resultName, t.identifier(name));
|
||||
};
|
||||
|
||||
return ImportBuilder;
|
||||
}();
|
||||
|
||||
exports.default = ImportBuilder;
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = void 0;
|
||||
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
var _importBuilder = _interopRequireDefault(require("./import-builder"));
|
||||
|
||||
var _isModule = _interopRequireDefault(require("./is-module"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var ImportInjector = function () {
|
||||
function ImportInjector(path, importedSource, opts) {
|
||||
this._programPath = void 0;
|
||||
this._programScope = void 0;
|
||||
this._file = void 0;
|
||||
this._defaultOpts = {
|
||||
importedSource: null,
|
||||
importedType: "commonjs",
|
||||
importedInterop: "babel",
|
||||
importingInterop: "babel",
|
||||
ensureLiveReference: false,
|
||||
ensureNoContext: false
|
||||
};
|
||||
var programPath = path.find(function (p) {
|
||||
return p.isProgram();
|
||||
});
|
||||
this._programPath = programPath;
|
||||
this._programScope = programPath.scope;
|
||||
this._file = programPath.hub.file;
|
||||
this._defaultOpts = this._applyDefaults(importedSource, opts, true);
|
||||
}
|
||||
|
||||
var _proto = ImportInjector.prototype;
|
||||
|
||||
_proto.addDefault = function addDefault(importedSourceIn, opts) {
|
||||
return this.addNamed("default", importedSourceIn, opts);
|
||||
};
|
||||
|
||||
_proto.addNamed = function addNamed(importName, importedSourceIn, opts) {
|
||||
(0, _assert.default)(typeof importName === "string");
|
||||
return this._generateImport(this._applyDefaults(importedSourceIn, opts), importName);
|
||||
};
|
||||
|
||||
_proto.addNamespace = function addNamespace(importedSourceIn, opts) {
|
||||
return this._generateImport(this._applyDefaults(importedSourceIn, opts), null);
|
||||
};
|
||||
|
||||
_proto.addSideEffect = function addSideEffect(importedSourceIn, opts) {
|
||||
return this._generateImport(this._applyDefaults(importedSourceIn, opts), false);
|
||||
};
|
||||
|
||||
_proto._applyDefaults = function _applyDefaults(importedSource, opts, isInit) {
|
||||
if (isInit === void 0) {
|
||||
isInit = false;
|
||||
}
|
||||
|
||||
var optsList = [];
|
||||
|
||||
if (typeof importedSource === "string") {
|
||||
optsList.push({
|
||||
importedSource: importedSource
|
||||
});
|
||||
optsList.push(opts);
|
||||
} else {
|
||||
(0, _assert.default)(!opts, "Unexpected secondary arguments.");
|
||||
optsList.push(importedSource);
|
||||
}
|
||||
|
||||
var newOpts = Object.assign({}, this._defaultOpts);
|
||||
|
||||
var _loop = function _loop(_opts) {
|
||||
if (!_opts) return "continue";
|
||||
Object.keys(newOpts).forEach(function (key) {
|
||||
if (_opts[key] !== undefined) newOpts[key] = _opts[key];
|
||||
});
|
||||
|
||||
if (!isInit) {
|
||||
if (_opts.nameHint !== undefined) newOpts.nameHint = _opts.nameHint;
|
||||
if (_opts.blockHoist !== undefined) newOpts.blockHoist = _opts.blockHoist;
|
||||
}
|
||||
};
|
||||
|
||||
for (var _i = 0; _i < optsList.length; _i++) {
|
||||
var _opts = optsList[_i];
|
||||
|
||||
var _ret = _loop(_opts);
|
||||
|
||||
if (_ret === "continue") continue;
|
||||
}
|
||||
|
||||
return newOpts;
|
||||
};
|
||||
|
||||
_proto._generateImport = function _generateImport(opts, importName) {
|
||||
var isDefault = importName === "default";
|
||||
var isNamed = !!importName && !isDefault;
|
||||
var isNamespace = importName === null;
|
||||
var importedSource = opts.importedSource,
|
||||
importedType = opts.importedType,
|
||||
importedInterop = opts.importedInterop,
|
||||
importingInterop = opts.importingInterop,
|
||||
ensureLiveReference = opts.ensureLiveReference,
|
||||
ensureNoContext = opts.ensureNoContext,
|
||||
nameHint = opts.nameHint,
|
||||
blockHoist = opts.blockHoist;
|
||||
var name = nameHint || importName;
|
||||
var isMod = (0, _isModule.default)(this._programPath, true);
|
||||
var isModuleForNode = isMod && importingInterop === "node";
|
||||
var isModuleForBabel = isMod && importingInterop === "babel";
|
||||
var builder = new _importBuilder.default(importedSource, this._programScope, this._file);
|
||||
|
||||
if (importedType === "es6") {
|
||||
if (!isModuleForNode && !isModuleForBabel) {
|
||||
throw new Error("Cannot import an ES6 module from CommonJS");
|
||||
}
|
||||
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.namespace(nameHint || importedSource);
|
||||
} else if (isDefault || isNamed) {
|
||||
builder.named(name, importName);
|
||||
}
|
||||
} else if (importedType !== "commonjs") {
|
||||
throw new Error("Unexpected interopType \"" + importedType + "\"");
|
||||
} else if (importedInterop === "babel") {
|
||||
if (isModuleForNode) {
|
||||
name = name !== "default" ? name : importedSource;
|
||||
var es6Default = importedSource + "$es6Default";
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.default(es6Default).var(name || importedSource).wildcardInterop();
|
||||
} else if (isDefault) {
|
||||
if (ensureLiveReference) {
|
||||
builder.default(es6Default).var(name || importedSource).defaultInterop().read("default");
|
||||
} else {
|
||||
builder.default(es6Default).var(name).defaultInterop().prop(importName);
|
||||
}
|
||||
} else if (isNamed) {
|
||||
builder.default(es6Default).read(importName);
|
||||
}
|
||||
} else if (isModuleForBabel) {
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.namespace(name || importedSource);
|
||||
} else if (isDefault || isNamed) {
|
||||
builder.named(name, importName);
|
||||
}
|
||||
} else {
|
||||
builder.require();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.var(name || importedSource).wildcardInterop();
|
||||
} else if ((isDefault || isNamed) && ensureLiveReference) {
|
||||
if (isDefault) {
|
||||
name = name !== "default" ? name : importedSource;
|
||||
builder.var(name).read(importName);
|
||||
builder.defaultInterop();
|
||||
} else {
|
||||
builder.var(importedSource).read(importName);
|
||||
}
|
||||
} else if (isDefault) {
|
||||
builder.var(name).defaultInterop().prop(importName);
|
||||
} else if (isNamed) {
|
||||
builder.var(name).prop(importName);
|
||||
}
|
||||
}
|
||||
} else if (importedInterop === "compiled") {
|
||||
if (isModuleForNode) {
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.default(name || importedSource);
|
||||
} else if (isDefault || isNamed) {
|
||||
builder.default(importedSource).read(name);
|
||||
}
|
||||
} else if (isModuleForBabel) {
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.namespace(name || importedSource);
|
||||
} else if (isDefault || isNamed) {
|
||||
builder.named(name, importName);
|
||||
}
|
||||
} else {
|
||||
builder.require();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.var(name || importedSource);
|
||||
} else if (isDefault || isNamed) {
|
||||
if (ensureLiveReference) {
|
||||
builder.var(importedSource).read(name);
|
||||
} else {
|
||||
builder.prop(importName).var(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (importedInterop === "uncompiled") {
|
||||
if (isDefault && ensureLiveReference) {
|
||||
throw new Error("No live reference for commonjs default");
|
||||
}
|
||||
|
||||
if (isModuleForNode) {
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.default(name || importedSource);
|
||||
} else if (isDefault) {
|
||||
builder.default(name);
|
||||
} else if (isNamed) {
|
||||
builder.default(importedSource).read(name);
|
||||
}
|
||||
} else if (isModuleForBabel) {
|
||||
builder.import();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.default(name || importedSource);
|
||||
} else if (isDefault) {
|
||||
builder.default(name);
|
||||
} else if (isNamed) {
|
||||
builder.named(name, importName);
|
||||
}
|
||||
} else {
|
||||
builder.require();
|
||||
|
||||
if (isNamespace) {
|
||||
builder.var(name || importedSource);
|
||||
} else if (isDefault) {
|
||||
builder.var(name);
|
||||
} else if (isNamed) {
|
||||
if (ensureLiveReference) {
|
||||
builder.var(importedSource).read(name);
|
||||
} else {
|
||||
builder.var(name).prop(importName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error("Unknown importedInterop \"" + importedInterop + "\".");
|
||||
}
|
||||
|
||||
var _builder$done = builder.done(),
|
||||
statements = _builder$done.statements,
|
||||
resultName = _builder$done.resultName;
|
||||
|
||||
this._insertStatements(statements, blockHoist);
|
||||
|
||||
if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") {
|
||||
return t.sequenceExpression([t.numericLiteral(0), resultName]);
|
||||
}
|
||||
|
||||
return resultName;
|
||||
};
|
||||
|
||||
_proto._insertStatements = function _insertStatements(statements, blockHoist) {
|
||||
if (blockHoist === void 0) {
|
||||
blockHoist = 3;
|
||||
}
|
||||
|
||||
statements.forEach(function (node) {
|
||||
node._blockHoist = blockHoist;
|
||||
});
|
||||
|
||||
var targetPath = this._programPath.get("body").filter(function (p) {
|
||||
var val = p.node._blockHoist;
|
||||
return Number.isFinite(val) && val < 4;
|
||||
})[0];
|
||||
|
||||
if (targetPath) {
|
||||
targetPath.insertBefore(statements);
|
||||
} else {
|
||||
this._programPath.unshiftContainer("body", statements);
|
||||
}
|
||||
};
|
||||
|
||||
return ImportInjector;
|
||||
}();
|
||||
|
||||
exports.default = ImportInjector;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.addDefault = addDefault;
|
||||
exports.addNamed = addNamed;
|
||||
exports.addNamespace = addNamespace;
|
||||
exports.addSideEffect = addSideEffect;
|
||||
exports.isModule = void 0;
|
||||
|
||||
var _importInjector = _interopRequireDefault(require("./import-injector"));
|
||||
|
||||
exports.ImportInjector = _importInjector.default;
|
||||
|
||||
var _isModule = _interopRequireDefault(require("./is-module"));
|
||||
|
||||
exports.isModule = _isModule.default;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function addDefault(path, importedSource, opts) {
|
||||
return new _importInjector.default(path).addDefault(importedSource, opts);
|
||||
}
|
||||
|
||||
function addNamed(path, name, importedSource, opts) {
|
||||
return new _importInjector.default(path).addNamed(name, importedSource, opts);
|
||||
}
|
||||
|
||||
function addNamespace(path, importedSource, opts) {
|
||||
return new _importInjector.default(path).addNamespace(importedSource, opts);
|
||||
}
|
||||
|
||||
function addSideEffect(path, importedSource, opts) {
|
||||
return new _importInjector.default(path).addSideEffect(importedSource, opts);
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isModule;
|
||||
|
||||
function isModule(path, requireUnambiguous) {
|
||||
if (requireUnambiguous === void 0) {
|
||||
requireUnambiguous = false;
|
||||
}
|
||||
|
||||
var sourceType = path.node.sourceType;
|
||||
|
||||
if (sourceType !== "module" && sourceType !== "script") {
|
||||
throw path.buildCodeFrameError("Unknown sourceType \"" + sourceType + "\", cannot transform.");
|
||||
}
|
||||
|
||||
var filename = path.hub.file.opts.filename;
|
||||
|
||||
if (/\.mjs$/.test(filename)) {
|
||||
requireUnambiguous = false;
|
||||
}
|
||||
|
||||
return path.node.sourceType === "module" && (!requireUnambiguous || isUnambiguousModule(path));
|
||||
}
|
||||
|
||||
function isUnambiguousModule(path) {
|
||||
return path.get("body").some(function (p) {
|
||||
return p.isModuleDeclaration();
|
||||
});
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@babel/helper-module-imports",
|
||||
"version": "7.0.0-beta.35",
|
||||
"description": "Babel helper functions for inserting module loads",
|
||||
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-module-imports",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-beta.35",
|
||||
"lodash": "^4.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-beta.35"
|
||||
}
|
||||
}
|
||||
+1073
File diff suppressed because it is too large
Load Diff
+19
@@ -0,0 +1,19 @@
|
||||
Copyright (C) 2012-2014 by various contributors (see AUTHORS)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# @babel/parser
|
||||
|
||||
> A JavaScript parser
|
||||
|
||||
See our website [@babel/parser](https://babeljs.io/docs/en/babel-parser) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20parser%20(babylon)%22+is%3Aopen) associated with this package.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/parser
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/parser --dev
|
||||
```
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint no-var: 0 */
|
||||
|
||||
var parser = require("..");
|
||||
var fs = require("fs");
|
||||
|
||||
var filename = process.argv[2];
|
||||
if (!filename) {
|
||||
console.error("no filename specified");
|
||||
} else {
|
||||
var file = fs.readFileSync(filename, "utf8");
|
||||
var ast = parser.parse(file);
|
||||
|
||||
console.log(JSON.stringify(ast, null, " "));
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
module.exports = require("./lib/index.cjs");
|
||||
} catch {
|
||||
module.exports = require("./lib/index.js");
|
||||
}
|
||||
+14336
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@babel/parser",
|
||||
"version": "7.21.2",
|
||||
"description": "A JavaScript parser",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-parser",
|
||||
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A+parser+%28babylon%29%22+is%3Aopen",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"keywords": [
|
||||
"babel",
|
||||
"javascript",
|
||||
"parser",
|
||||
"tc39",
|
||||
"ecmascript",
|
||||
"@babel/parser"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-parser"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"types": "./typings/babel-parser.d.ts",
|
||||
"files": [
|
||||
"bin",
|
||||
"lib",
|
||||
"typings/babel-parser.d.ts",
|
||||
"index.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/helper-check-duplicate-nodes": "^7.18.6",
|
||||
"@babel/helper-fixtures": "^7.21.0",
|
||||
"@babel/helper-string-parser": "^7.19.4",
|
||||
"@babel/helper-validator-identifier": "^7.19.1",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"bin": "./bin/babel-parser.js",
|
||||
"type": "commonjs"
|
||||
}
|
||||
+239
@@ -0,0 +1,239 @@
|
||||
// This file is auto-generated! Do not modify it directly.
|
||||
/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */
|
||||
import * as _babel_types from '@babel/types';
|
||||
|
||||
type Plugin =
|
||||
| "asyncDoExpressions"
|
||||
| "asyncGenerators"
|
||||
| "bigInt"
|
||||
| "classPrivateMethods"
|
||||
| "classPrivateProperties"
|
||||
| "classProperties"
|
||||
| "classStaticBlock" // Enabled by default
|
||||
| "decimal"
|
||||
| "decorators-legacy"
|
||||
| "decoratorAutoAccessors"
|
||||
| "destructuringPrivate"
|
||||
| "doExpressions"
|
||||
| "dynamicImport"
|
||||
| "explicitResourceManagement"
|
||||
| "exportDefaultFrom"
|
||||
| "exportNamespaceFrom" // deprecated
|
||||
| "flow"
|
||||
| "flowComments"
|
||||
| "functionBind"
|
||||
| "functionSent"
|
||||
| "importMeta"
|
||||
| "jsx"
|
||||
| "logicalAssignment"
|
||||
| "importAssertions"
|
||||
| "importReflection"
|
||||
| "moduleBlocks"
|
||||
| "moduleStringNames"
|
||||
| "nullishCoalescingOperator"
|
||||
| "numericSeparator"
|
||||
| "objectRestSpread"
|
||||
| "optionalCatchBinding"
|
||||
| "optionalChaining"
|
||||
| "partialApplication"
|
||||
| "placeholders"
|
||||
| "privateIn" // Enabled by default
|
||||
| "regexpUnicodeSets"
|
||||
| "throwExpressions"
|
||||
| "topLevelAwait"
|
||||
| "v8intrinsic"
|
||||
| ParserPluginWithOptions[0];
|
||||
|
||||
type ParserPluginWithOptions =
|
||||
| ["decorators", DecoratorsPluginOptions]
|
||||
| ["estree", { classFeatures?: boolean }]
|
||||
// @deprecated
|
||||
| ["moduleAttributes", { version: "may-2020" }]
|
||||
| ["pipelineOperator", PipelineOperatorPluginOptions]
|
||||
| ["recordAndTuple", RecordAndTuplePluginOptions]
|
||||
| ["flow", FlowPluginOptions]
|
||||
| ["typescript", TypeScriptPluginOptions];
|
||||
|
||||
type PluginConfig = Plugin | ParserPluginWithOptions;
|
||||
|
||||
interface DecoratorsPluginOptions {
|
||||
decoratorsBeforeExport?: boolean;
|
||||
allowCallParenthesized?: boolean;
|
||||
}
|
||||
|
||||
interface PipelineOperatorPluginOptions {
|
||||
proposal: "minimal" | "fsharp" | "hack" | "smart";
|
||||
topicToken?: "%" | "#" | "@@" | "^^" | "^";
|
||||
}
|
||||
|
||||
interface RecordAndTuplePluginOptions {
|
||||
syntaxType: "bar" | "hash";
|
||||
}
|
||||
|
||||
interface FlowPluginOptions {
|
||||
all?: boolean;
|
||||
enums?: boolean;
|
||||
}
|
||||
|
||||
interface TypeScriptPluginOptions {
|
||||
dts?: boolean;
|
||||
disallowAmbiguousJSXLike?: boolean;
|
||||
}
|
||||
|
||||
// Type definitions for @babel/parser
|
||||
// Project: https://github.com/babel/babel/tree/main/packages/babel-parser
|
||||
// Definitions by: Troy Gerwien <https://github.com/yortus>
|
||||
// Marvin Hagemeister <https://github.com/marvinhagemeister>
|
||||
// Avi Vahl <https://github.com/AviVahl>
|
||||
// TypeScript Version: 2.9
|
||||
|
||||
/**
|
||||
* Parse the provided code as an entire ECMAScript program.
|
||||
*/
|
||||
declare function parse(
|
||||
input: string,
|
||||
options?: ParserOptions
|
||||
): ParseResult<_babel_types.File>;
|
||||
|
||||
/**
|
||||
* Parse the provided code as a single expression.
|
||||
*/
|
||||
declare function parseExpression(
|
||||
input: string,
|
||||
options?: ParserOptions
|
||||
): ParseResult<_babel_types.Expression>;
|
||||
|
||||
interface ParserOptions {
|
||||
/**
|
||||
* By default, import and export declarations can only appear at a program's top level.
|
||||
* Setting this option to true allows them anywhere where a statement is allowed.
|
||||
*/
|
||||
allowImportExportEverywhere?: boolean;
|
||||
|
||||
/**
|
||||
* By default, await use is not allowed outside of an async function.
|
||||
* Set this to true to accept such code.
|
||||
*/
|
||||
allowAwaitOutsideFunction?: boolean;
|
||||
|
||||
/**
|
||||
* By default, a return statement at the top level raises an error.
|
||||
* Set this to true to accept such code.
|
||||
*/
|
||||
allowReturnOutsideFunction?: boolean;
|
||||
|
||||
/**
|
||||
* By default, new.target use is not allowed outside of a function or class.
|
||||
* Set this to true to accept such code.
|
||||
*/
|
||||
allowNewTargetOutsideFunction?: boolean;
|
||||
|
||||
allowSuperOutsideMethod?: boolean;
|
||||
|
||||
/**
|
||||
* By default, exported identifiers must refer to a declared variable.
|
||||
* Set this to true to allow export statements to reference undeclared variables.
|
||||
*/
|
||||
allowUndeclaredExports?: boolean;
|
||||
|
||||
/**
|
||||
* By default, Babel parser JavaScript code according to Annex B syntax.
|
||||
* Set this to `false` to disable such behavior.
|
||||
*/
|
||||
annexB?: boolean;
|
||||
|
||||
/**
|
||||
* By default, Babel attaches comments to adjacent AST nodes.
|
||||
* When this option is set to false, comments are not attached.
|
||||
* It can provide up to 30% performance improvement when the input code has many comments.
|
||||
* @babel/eslint-parser will set it for you.
|
||||
* It is not recommended to use attachComment: false with Babel transform,
|
||||
* as doing so removes all the comments in output code, and renders annotations such as
|
||||
* /* istanbul ignore next *\/ nonfunctional.
|
||||
*/
|
||||
attachComment?: boolean;
|
||||
|
||||
/**
|
||||
* By default, Babel always throws an error when it finds some invalid code.
|
||||
* When this option is set to true, it will store the parsing error and
|
||||
* try to continue parsing the invalid input file.
|
||||
*/
|
||||
errorRecovery?: boolean;
|
||||
|
||||
/**
|
||||
* Indicate the mode the code should be parsed in.
|
||||
* Can be one of "script", "module", or "unambiguous". Defaults to "script".
|
||||
* "unambiguous" will make @babel/parser attempt to guess, based on the presence
|
||||
* of ES6 import or export statements.
|
||||
* Files with ES6 imports and exports are considered "module" and are otherwise "script".
|
||||
*/
|
||||
sourceType?: "script" | "module" | "unambiguous";
|
||||
|
||||
/**
|
||||
* Correlate output AST nodes with their source filename.
|
||||
* Useful when generating code and source maps from the ASTs of multiple input files.
|
||||
*/
|
||||
sourceFilename?: string;
|
||||
|
||||
/**
|
||||
* By default, the first line of code parsed is treated as line 1.
|
||||
* You can provide a line number to alternatively start with.
|
||||
* Useful for integration with other source tools.
|
||||
*/
|
||||
startLine?: number;
|
||||
|
||||
/**
|
||||
* By default, the parsed code is treated as if it starts from line 1, column 0.
|
||||
* You can provide a column number to alternatively start with.
|
||||
* Useful for integration with other source tools.
|
||||
*/
|
||||
startColumn?: number;
|
||||
|
||||
/**
|
||||
* Array containing the plugins that you want to enable.
|
||||
*/
|
||||
plugins?: ParserPlugin[];
|
||||
|
||||
/**
|
||||
* Should the parser work in strict mode.
|
||||
* Defaults to true if sourceType === 'module'. Otherwise, false.
|
||||
*/
|
||||
strictMode?: boolean;
|
||||
|
||||
/**
|
||||
* Adds a ranges property to each node: [node.start, node.end]
|
||||
*/
|
||||
ranges?: boolean;
|
||||
|
||||
/**
|
||||
* Adds all parsed tokens to a tokens property on the File node.
|
||||
*/
|
||||
tokens?: boolean;
|
||||
|
||||
/**
|
||||
* By default, the parser adds information about parentheses by setting
|
||||
* `extra.parenthesized` to `true` as needed.
|
||||
* When this option is `true` the parser creates `ParenthesizedExpression`
|
||||
* AST nodes instead of using the `extra` property.
|
||||
*/
|
||||
createParenthesizedExpressions?: boolean;
|
||||
}
|
||||
|
||||
type ParserPlugin = PluginConfig;
|
||||
|
||||
|
||||
declare const tokTypes: {
|
||||
// todo(flow->ts) real token type
|
||||
[name: string]: any;
|
||||
};
|
||||
|
||||
interface ParseError {
|
||||
code: string;
|
||||
reasonCode: string;
|
||||
}
|
||||
|
||||
type ParseResult<Result> = Result & {
|
||||
errors: ParseError[];
|
||||
};
|
||||
|
||||
export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };
|
||||
+2835
File diff suppressed because it is too large
Load Diff
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = assertNode;
|
||||
|
||||
var _isNode = _interopRequireDefault(require("../validators/isNode"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function assertNode(node) {
|
||||
if (!(0, _isNode.default)(node)) {
|
||||
var type = node && node.type || JSON.stringify(node);
|
||||
throw new TypeError("Not a valid node of type \"" + type + "\"");
|
||||
}
|
||||
}
|
||||
+2215
File diff suppressed because it is too large
Load Diff
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = builder;
|
||||
|
||||
var _clone = _interopRequireDefault(require("lodash/clone"));
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
var _validate = _interopRequireDefault(require("../validators/validate"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function builder(type) {
|
||||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
var keys = _definitions.BUILDER_KEYS[type];
|
||||
var countArgs = args.length;
|
||||
|
||||
if (countArgs > keys.length) {
|
||||
throw new Error(type + ": Too many arguments passed. Received " + countArgs + " but can receive no more than " + keys.length);
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: type
|
||||
};
|
||||
var i = 0;
|
||||
keys.forEach(function (key) {
|
||||
var field = _definitions.NODE_FIELDS[type][key];
|
||||
var arg;
|
||||
if (i < countArgs) arg = args[i];
|
||||
if (arg === undefined) arg = (0, _clone.default)(field.default);
|
||||
node[key] = arg;
|
||||
i++;
|
||||
});
|
||||
|
||||
for (var key in node) {
|
||||
(0, _validate.default)(node, key, node[key]);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = createTypeAnnotationBasedOnTypeof;
|
||||
|
||||
var _generated = require("../generated");
|
||||
|
||||
function createTypeAnnotationBasedOnTypeof(type) {
|
||||
if (type === "string") {
|
||||
return (0, _generated.stringTypeAnnotation)();
|
||||
} else if (type === "number") {
|
||||
return (0, _generated.numberTypeAnnotation)();
|
||||
} else if (type === "undefined") {
|
||||
return (0, _generated.voidTypeAnnotation)();
|
||||
} else if (type === "boolean") {
|
||||
return (0, _generated.booleanTypeAnnotation)();
|
||||
} else if (type === "function") {
|
||||
return (0, _generated.genericTypeAnnotation)((0, _generated.identifier)("Function"));
|
||||
} else if (type === "object") {
|
||||
return (0, _generated.genericTypeAnnotation)((0, _generated.identifier)("Object"));
|
||||
} else if (type === "symbol") {
|
||||
return (0, _generated.genericTypeAnnotation)((0, _generated.identifier)("Symbol"));
|
||||
} else {
|
||||
throw new Error("Invalid typeof value");
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = createUnionTypeAnnotation;
|
||||
|
||||
var _generated = require("../generated");
|
||||
|
||||
var _removeTypeDuplicates = _interopRequireDefault(require("../../modifications/flow/removeTypeDuplicates"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function createUnionTypeAnnotation(types) {
|
||||
var flattened = (0, _removeTypeDuplicates.default)(types);
|
||||
|
||||
if (flattened.length === 1) {
|
||||
return flattened[0];
|
||||
} else {
|
||||
return (0, _generated.unionTypeAnnotation)(flattened);
|
||||
}
|
||||
}
|
||||
+1869
File diff suppressed because it is too large
Load Diff
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = buildChildren;
|
||||
|
||||
var _generated = require("../../validators/generated");
|
||||
|
||||
var _cleanJSXElementLiteralChild = _interopRequireDefault(require("../../utils/react/cleanJSXElementLiteralChild"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function buildChildren(node) {
|
||||
var elements = [];
|
||||
|
||||
for (var i = 0; i < node.children.length; i++) {
|
||||
var child = node.children[i];
|
||||
|
||||
if ((0, _generated.isJSXText)(child)) {
|
||||
(0, _cleanJSXElementLiteralChild.default)(child, elements);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((0, _generated.isJSXExpressionContainer)(child)) child = child.expression;
|
||||
if ((0, _generated.isJSXEmptyExpression)(child)) continue;
|
||||
elements.push(child);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = clone;
|
||||
|
||||
function clone(node) {
|
||||
if (!node) return node;
|
||||
var newNode = {};
|
||||
Object.keys(node).forEach(function (key) {
|
||||
if (key[0] === "_") return;
|
||||
newNode[key] = node[key];
|
||||
});
|
||||
return newNode;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = cloneDeep;
|
||||
|
||||
function cloneDeep(node) {
|
||||
if (!node) return node;
|
||||
var newNode = {};
|
||||
Object.keys(node).forEach(function (key) {
|
||||
if (key[0] === "_") return;
|
||||
var val = node[key];
|
||||
|
||||
if (val) {
|
||||
if (val.type) {
|
||||
val = cloneDeep(val);
|
||||
} else if (Array.isArray(val)) {
|
||||
val = val.map(cloneDeep);
|
||||
}
|
||||
}
|
||||
|
||||
newNode[key] = val;
|
||||
});
|
||||
return newNode;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = cloneWithoutLoc;
|
||||
|
||||
var _clone = _interopRequireDefault(require("./clone"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function cloneWithoutLoc(node) {
|
||||
var newNode = (0, _clone.default)(node);
|
||||
newNode.loc = null;
|
||||
return newNode;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = addComment;
|
||||
|
||||
var _addComments = _interopRequireDefault(require("./addComments"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function addComment(node, type, content, line) {
|
||||
return (0, _addComments.default)(node, type, [{
|
||||
type: line ? "CommentLine" : "CommentBlock",
|
||||
value: content
|
||||
}]);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = addComments;
|
||||
|
||||
function addComments(node, type, comments) {
|
||||
if (!comments || !node) return node;
|
||||
var key = type + "Comments";
|
||||
|
||||
if (node[key]) {
|
||||
if (type === "leading") {
|
||||
node[key] = comments.concat(node[key]);
|
||||
} else {
|
||||
node[key] = node[key].concat(comments);
|
||||
}
|
||||
} else {
|
||||
node[key] = comments;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = inheritInnerComments;
|
||||
|
||||
var _inherit = _interopRequireDefault(require("../utils/inherit"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function inheritInnerComments(child, parent) {
|
||||
(0, _inherit.default)("innerComments", child, parent);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = inheritLeadingComments;
|
||||
|
||||
var _inherit = _interopRequireDefault(require("../utils/inherit"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function inheritLeadingComments(child, parent) {
|
||||
(0, _inherit.default)("leadingComments", child, parent);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = inheritTrailingComments;
|
||||
|
||||
var _inherit = _interopRequireDefault(require("../utils/inherit"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function inheritTrailingComments(child, parent) {
|
||||
(0, _inherit.default)("trailingComments", child, parent);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = inheritsComments;
|
||||
|
||||
var _inheritTrailingComments = _interopRequireDefault(require("./inheritTrailingComments"));
|
||||
|
||||
var _inheritLeadingComments = _interopRequireDefault(require("./inheritLeadingComments"));
|
||||
|
||||
var _inheritInnerComments = _interopRequireDefault(require("./inheritInnerComments"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function inheritsComments(child, parent) {
|
||||
(0, _inheritTrailingComments.default)(child, parent);
|
||||
(0, _inheritLeadingComments.default)(child, parent);
|
||||
(0, _inheritInnerComments.default)(child, parent);
|
||||
return child;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = removeComments;
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
function removeComments(node) {
|
||||
_constants.COMMENT_KEYS.forEach(function (key) {
|
||||
node[key] = null;
|
||||
});
|
||||
|
||||
return node;
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.TSTYPE_TYPES = exports.TSTYPEELEMENT_TYPES = exports.JSX_TYPES = exports.FLOWPREDICATE_TYPES = exports.FLOWDECLARATION_TYPES = exports.FLOWBASEANNOTATION_TYPES = exports.FLOW_TYPES = exports.MODULESPECIFIER_TYPES = exports.EXPORTDECLARATION_TYPES = exports.MODULEDECLARATION_TYPES = exports.CLASS_TYPES = exports.PATTERN_TYPES = exports.UNARYLIKE_TYPES = exports.PROPERTY_TYPES = exports.OBJECTMEMBER_TYPES = exports.METHOD_TYPES = exports.USERWHITESPACABLE_TYPES = exports.IMMUTABLE_TYPES = exports.LITERAL_TYPES = exports.TSENTITYNAME_TYPES = exports.LVAL_TYPES = exports.PATTERNLIKE_TYPES = exports.DECLARATION_TYPES = exports.PUREISH_TYPES = exports.FUNCTIONPARENT_TYPES = exports.FUNCTION_TYPES = exports.FORXSTATEMENT_TYPES = exports.FOR_TYPES = exports.EXPRESSIONWRAPPER_TYPES = exports.WHILE_TYPES = exports.LOOP_TYPES = exports.CONDITIONAL_TYPES = exports.COMPLETIONSTATEMENT_TYPES = exports.TERMINATORLESS_TYPES = exports.STATEMENT_TYPES = exports.BLOCK_TYPES = exports.BLOCKPARENT_TYPES = exports.SCOPABLE_TYPES = exports.BINARY_TYPES = exports.EXPRESSION_TYPES = void 0;
|
||||
|
||||
var _definitions = require("../../definitions");
|
||||
|
||||
var EXPRESSION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Expression"];
|
||||
exports.EXPRESSION_TYPES = EXPRESSION_TYPES;
|
||||
var BINARY_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Binary"];
|
||||
exports.BINARY_TYPES = BINARY_TYPES;
|
||||
var SCOPABLE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Scopable"];
|
||||
exports.SCOPABLE_TYPES = SCOPABLE_TYPES;
|
||||
var BLOCKPARENT_TYPES = _definitions.FLIPPED_ALIAS_KEYS["BlockParent"];
|
||||
exports.BLOCKPARENT_TYPES = BLOCKPARENT_TYPES;
|
||||
var BLOCK_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Block"];
|
||||
exports.BLOCK_TYPES = BLOCK_TYPES;
|
||||
var STATEMENT_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Statement"];
|
||||
exports.STATEMENT_TYPES = STATEMENT_TYPES;
|
||||
var TERMINATORLESS_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Terminatorless"];
|
||||
exports.TERMINATORLESS_TYPES = TERMINATORLESS_TYPES;
|
||||
var COMPLETIONSTATEMENT_TYPES = _definitions.FLIPPED_ALIAS_KEYS["CompletionStatement"];
|
||||
exports.COMPLETIONSTATEMENT_TYPES = COMPLETIONSTATEMENT_TYPES;
|
||||
var CONDITIONAL_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Conditional"];
|
||||
exports.CONDITIONAL_TYPES = CONDITIONAL_TYPES;
|
||||
var LOOP_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Loop"];
|
||||
exports.LOOP_TYPES = LOOP_TYPES;
|
||||
var WHILE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["While"];
|
||||
exports.WHILE_TYPES = WHILE_TYPES;
|
||||
var EXPRESSIONWRAPPER_TYPES = _definitions.FLIPPED_ALIAS_KEYS["ExpressionWrapper"];
|
||||
exports.EXPRESSIONWRAPPER_TYPES = EXPRESSIONWRAPPER_TYPES;
|
||||
var FOR_TYPES = _definitions.FLIPPED_ALIAS_KEYS["For"];
|
||||
exports.FOR_TYPES = FOR_TYPES;
|
||||
var FORXSTATEMENT_TYPES = _definitions.FLIPPED_ALIAS_KEYS["ForXStatement"];
|
||||
exports.FORXSTATEMENT_TYPES = FORXSTATEMENT_TYPES;
|
||||
var FUNCTION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Function"];
|
||||
exports.FUNCTION_TYPES = FUNCTION_TYPES;
|
||||
var FUNCTIONPARENT_TYPES = _definitions.FLIPPED_ALIAS_KEYS["FunctionParent"];
|
||||
exports.FUNCTIONPARENT_TYPES = FUNCTIONPARENT_TYPES;
|
||||
var PUREISH_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Pureish"];
|
||||
exports.PUREISH_TYPES = PUREISH_TYPES;
|
||||
var DECLARATION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Declaration"];
|
||||
exports.DECLARATION_TYPES = DECLARATION_TYPES;
|
||||
var PATTERNLIKE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["PatternLike"];
|
||||
exports.PATTERNLIKE_TYPES = PATTERNLIKE_TYPES;
|
||||
var LVAL_TYPES = _definitions.FLIPPED_ALIAS_KEYS["LVal"];
|
||||
exports.LVAL_TYPES = LVAL_TYPES;
|
||||
var TSENTITYNAME_TYPES = _definitions.FLIPPED_ALIAS_KEYS["TSEntityName"];
|
||||
exports.TSENTITYNAME_TYPES = TSENTITYNAME_TYPES;
|
||||
var LITERAL_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Literal"];
|
||||
exports.LITERAL_TYPES = LITERAL_TYPES;
|
||||
var IMMUTABLE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Immutable"];
|
||||
exports.IMMUTABLE_TYPES = IMMUTABLE_TYPES;
|
||||
var USERWHITESPACABLE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["UserWhitespacable"];
|
||||
exports.USERWHITESPACABLE_TYPES = USERWHITESPACABLE_TYPES;
|
||||
var METHOD_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Method"];
|
||||
exports.METHOD_TYPES = METHOD_TYPES;
|
||||
var OBJECTMEMBER_TYPES = _definitions.FLIPPED_ALIAS_KEYS["ObjectMember"];
|
||||
exports.OBJECTMEMBER_TYPES = OBJECTMEMBER_TYPES;
|
||||
var PROPERTY_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Property"];
|
||||
exports.PROPERTY_TYPES = PROPERTY_TYPES;
|
||||
var UNARYLIKE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["UnaryLike"];
|
||||
exports.UNARYLIKE_TYPES = UNARYLIKE_TYPES;
|
||||
var PATTERN_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Pattern"];
|
||||
exports.PATTERN_TYPES = PATTERN_TYPES;
|
||||
var CLASS_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Class"];
|
||||
exports.CLASS_TYPES = CLASS_TYPES;
|
||||
var MODULEDECLARATION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["ModuleDeclaration"];
|
||||
exports.MODULEDECLARATION_TYPES = MODULEDECLARATION_TYPES;
|
||||
var EXPORTDECLARATION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["ExportDeclaration"];
|
||||
exports.EXPORTDECLARATION_TYPES = EXPORTDECLARATION_TYPES;
|
||||
var MODULESPECIFIER_TYPES = _definitions.FLIPPED_ALIAS_KEYS["ModuleSpecifier"];
|
||||
exports.MODULESPECIFIER_TYPES = MODULESPECIFIER_TYPES;
|
||||
var FLOW_TYPES = _definitions.FLIPPED_ALIAS_KEYS["Flow"];
|
||||
exports.FLOW_TYPES = FLOW_TYPES;
|
||||
var FLOWBASEANNOTATION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["FlowBaseAnnotation"];
|
||||
exports.FLOWBASEANNOTATION_TYPES = FLOWBASEANNOTATION_TYPES;
|
||||
var FLOWDECLARATION_TYPES = _definitions.FLIPPED_ALIAS_KEYS["FlowDeclaration"];
|
||||
exports.FLOWDECLARATION_TYPES = FLOWDECLARATION_TYPES;
|
||||
var FLOWPREDICATE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["FlowPredicate"];
|
||||
exports.FLOWPREDICATE_TYPES = FLOWPREDICATE_TYPES;
|
||||
var JSX_TYPES = _definitions.FLIPPED_ALIAS_KEYS["JSX"];
|
||||
exports.JSX_TYPES = JSX_TYPES;
|
||||
var TSTYPEELEMENT_TYPES = _definitions.FLIPPED_ALIAS_KEYS["TSTypeElement"];
|
||||
exports.TSTYPEELEMENT_TYPES = TSTYPEELEMENT_TYPES;
|
||||
var TSTYPE_TYPES = _definitions.FLIPPED_ALIAS_KEYS["TSType"];
|
||||
exports.TSTYPE_TYPES = TSTYPE_TYPES;
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.NOT_LOCAL_BINDING = exports.BLOCK_SCOPED_SYMBOL = exports.INHERIT_KEYS = exports.UNARY_OPERATORS = exports.STRING_UNARY_OPERATORS = exports.NUMBER_UNARY_OPERATORS = exports.BOOLEAN_UNARY_OPERATORS = exports.BINARY_OPERATORS = exports.NUMBER_BINARY_OPERATORS = exports.BOOLEAN_BINARY_OPERATORS = exports.COMPARISON_BINARY_OPERATORS = exports.EQUALITY_BINARY_OPERATORS = exports.BOOLEAN_NUMBER_BINARY_OPERATORS = exports.UPDATE_OPERATORS = exports.LOGICAL_OPERATORS = exports.COMMENT_KEYS = exports.FOR_INIT_KEYS = exports.FLATTENABLE_KEYS = exports.STATEMENT_OR_BLOCK_KEYS = void 0;
|
||||
var STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
|
||||
exports.STATEMENT_OR_BLOCK_KEYS = STATEMENT_OR_BLOCK_KEYS;
|
||||
var FLATTENABLE_KEYS = ["body", "expressions"];
|
||||
exports.FLATTENABLE_KEYS = FLATTENABLE_KEYS;
|
||||
var FOR_INIT_KEYS = ["left", "init"];
|
||||
exports.FOR_INIT_KEYS = FOR_INIT_KEYS;
|
||||
var COMMENT_KEYS = ["leadingComments", "trailingComments", "innerComments"];
|
||||
exports.COMMENT_KEYS = COMMENT_KEYS;
|
||||
var LOGICAL_OPERATORS = ["||", "&&", "??"];
|
||||
exports.LOGICAL_OPERATORS = LOGICAL_OPERATORS;
|
||||
var UPDATE_OPERATORS = ["++", "--"];
|
||||
exports.UPDATE_OPERATORS = UPDATE_OPERATORS;
|
||||
var BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="];
|
||||
exports.BOOLEAN_NUMBER_BINARY_OPERATORS = BOOLEAN_NUMBER_BINARY_OPERATORS;
|
||||
var EQUALITY_BINARY_OPERATORS = ["==", "===", "!=", "!=="];
|
||||
exports.EQUALITY_BINARY_OPERATORS = EQUALITY_BINARY_OPERATORS;
|
||||
var COMPARISON_BINARY_OPERATORS = EQUALITY_BINARY_OPERATORS.concat(["in", "instanceof"]);
|
||||
exports.COMPARISON_BINARY_OPERATORS = COMPARISON_BINARY_OPERATORS;
|
||||
var BOOLEAN_BINARY_OPERATORS = COMPARISON_BINARY_OPERATORS.concat(BOOLEAN_NUMBER_BINARY_OPERATORS);
|
||||
exports.BOOLEAN_BINARY_OPERATORS = BOOLEAN_BINARY_OPERATORS;
|
||||
var NUMBER_BINARY_OPERATORS = ["-", "/", "%", "*", "**", "&", "|", ">>", ">>>", "<<", "^"];
|
||||
exports.NUMBER_BINARY_OPERATORS = NUMBER_BINARY_OPERATORS;
|
||||
var BINARY_OPERATORS = ["+"].concat(NUMBER_BINARY_OPERATORS, BOOLEAN_BINARY_OPERATORS);
|
||||
exports.BINARY_OPERATORS = BINARY_OPERATORS;
|
||||
var BOOLEAN_UNARY_OPERATORS = ["delete", "!"];
|
||||
exports.BOOLEAN_UNARY_OPERATORS = BOOLEAN_UNARY_OPERATORS;
|
||||
var NUMBER_UNARY_OPERATORS = ["+", "-", "~"];
|
||||
exports.NUMBER_UNARY_OPERATORS = NUMBER_UNARY_OPERATORS;
|
||||
var STRING_UNARY_OPERATORS = ["typeof"];
|
||||
exports.STRING_UNARY_OPERATORS = STRING_UNARY_OPERATORS;
|
||||
var UNARY_OPERATORS = ["void", "throw"].concat(BOOLEAN_UNARY_OPERATORS, NUMBER_UNARY_OPERATORS, STRING_UNARY_OPERATORS);
|
||||
exports.UNARY_OPERATORS = UNARY_OPERATORS;
|
||||
var INHERIT_KEYS = {
|
||||
optional: ["typeAnnotation", "typeParameters", "returnType"],
|
||||
force: ["start", "loc", "end"]
|
||||
};
|
||||
exports.INHERIT_KEYS = INHERIT_KEYS;
|
||||
var BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped");
|
||||
exports.BLOCK_SCOPED_SYMBOL = BLOCK_SCOPED_SYMBOL;
|
||||
var NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding");
|
||||
exports.NOT_LOCAL_BINDING = NOT_LOCAL_BINDING;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = ensureBlock;
|
||||
|
||||
var _toBlock = _interopRequireDefault(require("./toBlock"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function ensureBlock(node, key) {
|
||||
if (key === void 0) {
|
||||
key = "body";
|
||||
}
|
||||
|
||||
return node[key] = (0, _toBlock.default)(node[key], node);
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = gatherSequenceExpressions;
|
||||
|
||||
var _getBindingIdentifiers = _interopRequireDefault(require("../retrievers/getBindingIdentifiers"));
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
var _generated2 = require("../builders/generated");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function gatherSequenceExpressions(nodes, scope, declars) {
|
||||
var exprs = [];
|
||||
var ensureLastUndefined = true;
|
||||
|
||||
for (var _iterator = nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var _node = _ref;
|
||||
ensureLastUndefined = false;
|
||||
|
||||
if ((0, _generated.isExpression)(_node)) {
|
||||
exprs.push(_node);
|
||||
} else if ((0, _generated.isExpressionStatement)(_node)) {
|
||||
exprs.push(_node.expression);
|
||||
} else if ((0, _generated.isVariableDeclaration)(_node)) {
|
||||
if (_node.kind !== "var") return;
|
||||
var _arr = _node.declarations;
|
||||
|
||||
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
|
||||
var declar = _arr[_i2];
|
||||
var bindings = (0, _getBindingIdentifiers.default)(declar);
|
||||
|
||||
for (var key in bindings) {
|
||||
declars.push({
|
||||
kind: _node.kind,
|
||||
id: bindings[key]
|
||||
});
|
||||
}
|
||||
|
||||
if (declar.init) {
|
||||
exprs.push((0, _generated2.assignmentExpression)("=", declar.id, declar.init));
|
||||
}
|
||||
}
|
||||
|
||||
ensureLastUndefined = true;
|
||||
} else if ((0, _generated.isIfStatement)(_node)) {
|
||||
var consequent = _node.consequent ? gatherSequenceExpressions([_node.consequent], scope, declars) : scope.buildUndefinedNode();
|
||||
var alternate = _node.alternate ? gatherSequenceExpressions([_node.alternate], scope, declars) : scope.buildUndefinedNode();
|
||||
if (!consequent || !alternate) return;
|
||||
exprs.push((0, _generated2.conditionalExpression)(_node.test, consequent, alternate));
|
||||
} else if ((0, _generated.isBlockStatement)(_node)) {
|
||||
var body = gatherSequenceExpressions(_node.body, scope, declars);
|
||||
if (!body) return;
|
||||
exprs.push(body);
|
||||
} else if ((0, _generated.isEmptyStatement)(_node)) {
|
||||
ensureLastUndefined = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ensureLastUndefined) {
|
||||
exprs.push(scope.buildUndefinedNode());
|
||||
}
|
||||
|
||||
if (exprs.length === 1) {
|
||||
return exprs[0];
|
||||
} else {
|
||||
return (0, _generated2.sequenceExpression)(exprs);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toBindingIdentifierName;
|
||||
|
||||
var _toIdentifier = _interopRequireDefault(require("./toIdentifier"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function toBindingIdentifierName(name) {
|
||||
name = (0, _toIdentifier.default)(name);
|
||||
if (name === "eval" || name === "arguments") name = "_" + name;
|
||||
return name;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toBlock;
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
var _generated2 = require("../builders/generated");
|
||||
|
||||
function toBlock(node, parent) {
|
||||
if ((0, _generated.isBlockStatement)(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var blockNodes = [];
|
||||
|
||||
if ((0, _generated.isEmptyStatement)(node)) {
|
||||
blockNodes = [];
|
||||
} else {
|
||||
if (!(0, _generated.isStatement)(node)) {
|
||||
if ((0, _generated.isFunction)(parent)) {
|
||||
node = (0, _generated2.returnStatement)(node);
|
||||
} else {
|
||||
node = (0, _generated2.expressionStatement)(node);
|
||||
}
|
||||
}
|
||||
|
||||
blockNodes = [node];
|
||||
}
|
||||
|
||||
return (0, _generated2.blockStatement)(blockNodes);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toComputedKey;
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
var _generated2 = require("../builders/generated");
|
||||
|
||||
function toComputedKey(node, key) {
|
||||
if (key === void 0) {
|
||||
key = node.key || node.property;
|
||||
}
|
||||
|
||||
if (!node.computed && (0, _generated.isIdentifier)(key)) key = (0, _generated2.stringLiteral)(key.name);
|
||||
return key;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toExpression;
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
function toExpression(node) {
|
||||
if ((0, _generated.isExpressionStatement)(node)) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
if ((0, _generated.isExpression)(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
if ((0, _generated.isClass)(node)) {
|
||||
node.type = "ClassExpression";
|
||||
} else if ((0, _generated.isFunction)(node)) {
|
||||
node.type = "FunctionExpression";
|
||||
}
|
||||
|
||||
if (!(0, _generated.isExpression)(node)) {
|
||||
throw new Error("cannot turn " + node.type + " to an expression");
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toIdentifier;
|
||||
|
||||
var _isValidIdentifier = _interopRequireDefault(require("../validators/isValidIdentifier"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function toIdentifier(name) {
|
||||
name = name + "";
|
||||
name = name.replace(/[^a-zA-Z0-9$_]/g, "-");
|
||||
name = name.replace(/^[-0-9]+/, "");
|
||||
name = name.replace(/[-\s]+(.)?/g, function (match, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
});
|
||||
|
||||
if (!(0, _isValidIdentifier.default)(name)) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
return name || "_";
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toKeyAlias;
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
var _cloneDeep = _interopRequireDefault(require("../clone/cloneDeep"));
|
||||
|
||||
var _removePropertiesDeep = _interopRequireDefault(require("../modifications/removePropertiesDeep"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function toKeyAlias(node, key) {
|
||||
if (key === void 0) {
|
||||
key = node.key;
|
||||
}
|
||||
|
||||
var alias;
|
||||
|
||||
if (node.kind === "method") {
|
||||
return toKeyAlias.increment() + "";
|
||||
} else if ((0, _generated.isIdentifier)(key)) {
|
||||
alias = key.name;
|
||||
} else if ((0, _generated.isStringLiteral)(key)) {
|
||||
alias = JSON.stringify(key.value);
|
||||
} else {
|
||||
alias = JSON.stringify((0, _removePropertiesDeep.default)((0, _cloneDeep.default)(key)));
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
alias = "[" + alias + "]";
|
||||
}
|
||||
|
||||
if (node.static) {
|
||||
alias = "static:" + alias;
|
||||
}
|
||||
|
||||
return alias;
|
||||
}
|
||||
|
||||
toKeyAlias.uid = 0;
|
||||
|
||||
toKeyAlias.increment = function () {
|
||||
if (toKeyAlias.uid >= Number.MAX_SAFE_INTEGER) {
|
||||
return toKeyAlias.uid = 0;
|
||||
} else {
|
||||
return toKeyAlias.uid++;
|
||||
}
|
||||
};
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toSequenceExpression;
|
||||
|
||||
var _gatherSequenceExpressions = _interopRequireDefault(require("./gatherSequenceExpressions"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function toSequenceExpression(nodes, scope) {
|
||||
if (!nodes || !nodes.length) return;
|
||||
var declars = [];
|
||||
var result = (0, _gatherSequenceExpressions.default)(nodes, scope, declars);
|
||||
if (!result) return;
|
||||
|
||||
for (var _i = 0; _i < declars.length; _i++) {
|
||||
var declar = declars[_i];
|
||||
scope.push(declar);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = toStatement;
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
var _generated2 = require("../builders/generated");
|
||||
|
||||
function toStatement(node, ignore) {
|
||||
if ((0, _generated.isStatement)(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var mustHaveId = false;
|
||||
var newType;
|
||||
|
||||
if ((0, _generated.isClass)(node)) {
|
||||
mustHaveId = true;
|
||||
newType = "ClassDeclaration";
|
||||
} else if ((0, _generated.isFunction)(node)) {
|
||||
mustHaveId = true;
|
||||
newType = "FunctionDeclaration";
|
||||
} else if ((0, _generated.isAssignmentExpression)(node)) {
|
||||
return (0, _generated2.expressionStatement)(node);
|
||||
}
|
||||
|
||||
if (mustHaveId && !node.id) {
|
||||
newType = false;
|
||||
}
|
||||
|
||||
if (!newType) {
|
||||
if (ignore) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error("cannot turn " + node.type + " to a statement");
|
||||
}
|
||||
}
|
||||
|
||||
node.type = newType;
|
||||
return node;
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = valueToNode;
|
||||
|
||||
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
||||
|
||||
var _isRegExp = _interopRequireDefault(require("lodash/isRegExp"));
|
||||
|
||||
var _isValidIdentifier = _interopRequireDefault(require("../validators/isValidIdentifier"));
|
||||
|
||||
var _generated = require("../builders/generated");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function valueToNode(value) {
|
||||
if (value === undefined) {
|
||||
return (0, _generated.identifier)("undefined");
|
||||
}
|
||||
|
||||
if (value === true || value === false) {
|
||||
return (0, _generated.booleanLiteral)(value);
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return (0, _generated.nullLiteral)();
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
return (0, _generated.stringLiteral)(value);
|
||||
}
|
||||
|
||||
if (typeof value === "number") {
|
||||
return (0, _generated.numericLiteral)(value);
|
||||
}
|
||||
|
||||
if ((0, _isRegExp.default)(value)) {
|
||||
var pattern = value.source;
|
||||
var flags = value.toString().match(/\/([a-z]+|)$/)[1];
|
||||
return (0, _generated.regExpLiteral)(pattern, flags);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return (0, _generated.arrayExpression)(value.map(valueToNode));
|
||||
}
|
||||
|
||||
if ((0, _isPlainObject.default)(value)) {
|
||||
var props = [];
|
||||
|
||||
for (var key in value) {
|
||||
var nodeKey = void 0;
|
||||
|
||||
if ((0, _isValidIdentifier.default)(key)) {
|
||||
nodeKey = (0, _generated.identifier)(key);
|
||||
} else {
|
||||
nodeKey = (0, _generated.stringLiteral)(key);
|
||||
}
|
||||
|
||||
props.push((0, _generated.objectProperty)(nodeKey, valueToNode(value[key])));
|
||||
}
|
||||
|
||||
return (0, _generated.objectExpression)(props);
|
||||
}
|
||||
|
||||
throw new Error("don't know how to turn this value into a node");
|
||||
}
|
||||
+693
@@ -0,0 +1,693 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.patternLikeCommon = exports.functionDeclarationCommon = exports.functionTypeAnnotationCommon = exports.functionCommon = void 0;
|
||||
|
||||
var _isValidIdentifier = _interopRequireDefault(require("../validators/isValidIdentifier"));
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
(0, _utils.default)("ArrayExpression", {
|
||||
fields: {
|
||||
elements: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "Expression", "SpreadElement"))),
|
||||
default: []
|
||||
}
|
||||
},
|
||||
visitor: ["elements"],
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("AssignmentExpression", {
|
||||
fields: {
|
||||
operator: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
},
|
||||
left: {
|
||||
validate: (0, _utils.assertNodeType)("LVal")
|
||||
},
|
||||
right: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
},
|
||||
builder: ["operator", "left", "right"],
|
||||
visitor: ["left", "right"],
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("BinaryExpression", {
|
||||
builder: ["operator", "left", "right"],
|
||||
fields: {
|
||||
operator: {
|
||||
validate: _utils.assertOneOf.apply(void 0, _constants.BINARY_OPERATORS)
|
||||
},
|
||||
left: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
right: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
},
|
||||
visitor: ["left", "right"],
|
||||
aliases: ["Binary", "Expression"]
|
||||
});
|
||||
(0, _utils.default)("Directive", {
|
||||
visitor: ["value"],
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertNodeType)("DirectiveLiteral")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("DirectiveLiteral", {
|
||||
builder: ["value"],
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("BlockStatement", {
|
||||
builder: ["body", "directives"],
|
||||
visitor: ["directives", "body"],
|
||||
fields: {
|
||||
directives: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Directive"))),
|
||||
default: []
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Statement")))
|
||||
}
|
||||
},
|
||||
aliases: ["Scopable", "BlockParent", "Block", "Statement"]
|
||||
});
|
||||
(0, _utils.default)("BreakStatement", {
|
||||
visitor: ["label"],
|
||||
fields: {
|
||||
label: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier"),
|
||||
optional: true
|
||||
}
|
||||
},
|
||||
aliases: ["Statement", "Terminatorless", "CompletionStatement"]
|
||||
});
|
||||
(0, _utils.default)("CallExpression", {
|
||||
visitor: ["callee", "arguments", "typeParameters"],
|
||||
builder: ["callee", "arguments"],
|
||||
aliases: ["Expression"],
|
||||
fields: {
|
||||
callee: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
arguments: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName")))
|
||||
},
|
||||
optional: {
|
||||
validate: (0, _utils.assertOneOf)(true, false),
|
||||
optional: true
|
||||
},
|
||||
typeParameters: {
|
||||
validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"),
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("CatchClause", {
|
||||
visitor: ["param", "body"],
|
||||
fields: {
|
||||
param: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier"),
|
||||
optional: true
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
},
|
||||
aliases: ["Scopable", "BlockParent"]
|
||||
});
|
||||
(0, _utils.default)("ConditionalExpression", {
|
||||
visitor: ["test", "consequent", "alternate"],
|
||||
fields: {
|
||||
test: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
consequent: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
alternate: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
},
|
||||
aliases: ["Expression", "Conditional"]
|
||||
});
|
||||
(0, _utils.default)("ContinueStatement", {
|
||||
visitor: ["label"],
|
||||
fields: {
|
||||
label: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier"),
|
||||
optional: true
|
||||
}
|
||||
},
|
||||
aliases: ["Statement", "Terminatorless", "CompletionStatement"]
|
||||
});
|
||||
(0, _utils.default)("DebuggerStatement", {
|
||||
aliases: ["Statement"]
|
||||
});
|
||||
(0, _utils.default)("DoWhileStatement", {
|
||||
visitor: ["test", "body"],
|
||||
fields: {
|
||||
test: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
}
|
||||
},
|
||||
aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"]
|
||||
});
|
||||
(0, _utils.default)("EmptyStatement", {
|
||||
aliases: ["Statement"]
|
||||
});
|
||||
(0, _utils.default)("ExpressionStatement", {
|
||||
visitor: ["expression"],
|
||||
fields: {
|
||||
expression: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
},
|
||||
aliases: ["Statement", "ExpressionWrapper"]
|
||||
});
|
||||
(0, _utils.default)("File", {
|
||||
builder: ["program", "comments", "tokens"],
|
||||
visitor: ["program"],
|
||||
fields: {
|
||||
program: {
|
||||
validate: (0, _utils.assertNodeType)("Program")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ForInStatement", {
|
||||
visitor: ["left", "right", "body"],
|
||||
aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
|
||||
fields: {
|
||||
left: {
|
||||
validate: (0, _utils.assertNodeType)("VariableDeclaration", "LVal")
|
||||
},
|
||||
right: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ForStatement", {
|
||||
visitor: ["init", "test", "update", "body"],
|
||||
aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop"],
|
||||
fields: {
|
||||
init: {
|
||||
validate: (0, _utils.assertNodeType)("VariableDeclaration", "Expression"),
|
||||
optional: true
|
||||
},
|
||||
test: {
|
||||
validate: (0, _utils.assertNodeType)("Expression"),
|
||||
optional: true
|
||||
},
|
||||
update: {
|
||||
validate: (0, _utils.assertNodeType)("Expression"),
|
||||
optional: true
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
var functionCommon = {
|
||||
params: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("LVal")))
|
||||
},
|
||||
generator: {
|
||||
default: false,
|
||||
validate: (0, _utils.assertValueType)("boolean")
|
||||
},
|
||||
async: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
default: false
|
||||
}
|
||||
};
|
||||
exports.functionCommon = functionCommon;
|
||||
var functionTypeAnnotationCommon = {
|
||||
returnType: {
|
||||
validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||
optional: true
|
||||
},
|
||||
typeParameters: {
|
||||
validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"),
|
||||
optional: true
|
||||
}
|
||||
};
|
||||
exports.functionTypeAnnotationCommon = functionTypeAnnotationCommon;
|
||||
var functionDeclarationCommon = Object.assign({}, functionCommon, {
|
||||
declare: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
id: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier"),
|
||||
optional: true
|
||||
}
|
||||
});
|
||||
exports.functionDeclarationCommon = functionDeclarationCommon;
|
||||
(0, _utils.default)("FunctionDeclaration", {
|
||||
builder: ["id", "params", "body", "generator", "async"],
|
||||
visitor: ["id", "params", "body", "returnType", "typeParameters"],
|
||||
fields: Object.assign({}, functionDeclarationCommon, functionTypeAnnotationCommon, {
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
}),
|
||||
aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Statement", "Pureish", "Declaration"]
|
||||
});
|
||||
(0, _utils.default)("FunctionExpression", {
|
||||
inherits: "FunctionDeclaration",
|
||||
aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"],
|
||||
fields: Object.assign({}, functionCommon, functionTypeAnnotationCommon, {
|
||||
id: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier"),
|
||||
optional: true
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
})
|
||||
});
|
||||
var patternLikeCommon = {
|
||||
typeAnnotation: {
|
||||
validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||
optional: true
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator")))
|
||||
}
|
||||
};
|
||||
exports.patternLikeCommon = patternLikeCommon;
|
||||
(0, _utils.default)("Identifier", {
|
||||
builder: ["name"],
|
||||
visitor: ["typeAnnotation"],
|
||||
aliases: ["Expression", "PatternLike", "LVal", "TSEntityName"],
|
||||
fields: Object.assign({}, patternLikeCommon, {
|
||||
name: {
|
||||
validate: function validate(node, key, val) {
|
||||
if (!(0, _isValidIdentifier.default)(val)) {}
|
||||
}
|
||||
},
|
||||
optional: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("IfStatement", {
|
||||
visitor: ["test", "consequent", "alternate"],
|
||||
aliases: ["Statement", "Conditional"],
|
||||
fields: {
|
||||
test: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
consequent: {
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
},
|
||||
alternate: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("LabeledStatement", {
|
||||
visitor: ["label", "body"],
|
||||
aliases: ["Statement"],
|
||||
fields: {
|
||||
label: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("StringLiteral", {
|
||||
builder: ["value"],
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
}
|
||||
},
|
||||
aliases: ["Expression", "Pureish", "Literal", "Immutable"]
|
||||
});
|
||||
(0, _utils.default)("NumericLiteral", {
|
||||
builder: ["value"],
|
||||
deprecatedAlias: "NumberLiteral",
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertValueType)("number")
|
||||
}
|
||||
},
|
||||
aliases: ["Expression", "Pureish", "Literal", "Immutable"]
|
||||
});
|
||||
(0, _utils.default)("NullLiteral", {
|
||||
aliases: ["Expression", "Pureish", "Literal", "Immutable"]
|
||||
});
|
||||
(0, _utils.default)("BooleanLiteral", {
|
||||
builder: ["value"],
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertValueType)("boolean")
|
||||
}
|
||||
},
|
||||
aliases: ["Expression", "Pureish", "Literal", "Immutable"]
|
||||
});
|
||||
(0, _utils.default)("RegExpLiteral", {
|
||||
builder: ["pattern", "flags"],
|
||||
deprecatedAlias: "RegexLiteral",
|
||||
aliases: ["Expression", "Literal"],
|
||||
fields: {
|
||||
pattern: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
},
|
||||
flags: {
|
||||
validate: (0, _utils.assertValueType)("string"),
|
||||
default: ""
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("LogicalExpression", {
|
||||
builder: ["operator", "left", "right"],
|
||||
visitor: ["left", "right"],
|
||||
aliases: ["Binary", "Expression"],
|
||||
fields: {
|
||||
operator: {
|
||||
validate: _utils.assertOneOf.apply(void 0, _constants.LOGICAL_OPERATORS)
|
||||
},
|
||||
left: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
right: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("MemberExpression", {
|
||||
builder: ["object", "property", "computed", "optional"],
|
||||
visitor: ["object", "property"],
|
||||
aliases: ["Expression", "LVal"],
|
||||
fields: {
|
||||
object: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
property: {
|
||||
validate: function () {
|
||||
var normal = (0, _utils.assertNodeType)("Identifier");
|
||||
var computed = (0, _utils.assertNodeType)("Expression");
|
||||
return function (node, key, val) {
|
||||
var validator = node.computed ? computed : normal;
|
||||
validator(node, key, val);
|
||||
};
|
||||
}()
|
||||
},
|
||||
computed: {
|
||||
default: false
|
||||
},
|
||||
optional: {
|
||||
validate: (0, _utils.assertOneOf)(true, false),
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("NewExpression", {
|
||||
inherits: "CallExpression"
|
||||
});
|
||||
(0, _utils.default)("Program", {
|
||||
visitor: ["directives", "body"],
|
||||
builder: ["body", "directives", "sourceType"],
|
||||
fields: {
|
||||
sourceFile: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
},
|
||||
sourceType: {
|
||||
validate: (0, _utils.assertOneOf)("script", "module"),
|
||||
default: "script"
|
||||
},
|
||||
directives: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Directive"))),
|
||||
default: []
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Statement")))
|
||||
}
|
||||
},
|
||||
aliases: ["Scopable", "BlockParent", "Block"]
|
||||
});
|
||||
(0, _utils.default)("ObjectExpression", {
|
||||
visitor: ["properties"],
|
||||
aliases: ["Expression"],
|
||||
fields: {
|
||||
properties: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("ObjectMethod", "ObjectProperty", "SpreadElement")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ObjectMethod", {
|
||||
builder: ["kind", "key", "params", "body", "computed"],
|
||||
fields: Object.assign({}, functionCommon, functionTypeAnnotationCommon, {
|
||||
kind: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("method", "get", "set")),
|
||||
default: "method"
|
||||
},
|
||||
computed: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
default: false
|
||||
},
|
||||
key: {
|
||||
validate: function () {
|
||||
var normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral");
|
||||
var computed = (0, _utils.assertNodeType)("Expression");
|
||||
return function (node, key, val) {
|
||||
var validator = node.computed ? computed : normal;
|
||||
validator(node, key, val);
|
||||
};
|
||||
}()
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator")))
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
}),
|
||||
visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"],
|
||||
aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"]
|
||||
});
|
||||
(0, _utils.default)("ObjectProperty", {
|
||||
builder: ["key", "value", "computed", "shorthand", "decorators"],
|
||||
fields: {
|
||||
computed: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
default: false
|
||||
},
|
||||
key: {
|
||||
validate: function () {
|
||||
var normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral");
|
||||
var computed = (0, _utils.assertNodeType)("Expression");
|
||||
return function (node, key, val) {
|
||||
var validator = node.computed ? computed : normal;
|
||||
validator(node, key, val);
|
||||
};
|
||||
}()
|
||||
},
|
||||
value: {
|
||||
validate: (0, _utils.assertNodeType)("Expression", "PatternLike")
|
||||
},
|
||||
shorthand: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
default: false
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
|
||||
optional: true
|
||||
}
|
||||
},
|
||||
visitor: ["key", "value", "decorators"],
|
||||
aliases: ["UserWhitespacable", "Property", "ObjectMember"]
|
||||
});
|
||||
(0, _utils.default)("RestElement", {
|
||||
visitor: ["argument", "typeAnnotation"],
|
||||
builder: ["argument"],
|
||||
aliases: ["LVal", "PatternLike"],
|
||||
deprecatedAlias: "RestProperty",
|
||||
fields: Object.assign({}, patternLikeCommon, {
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("LVal")
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ReturnStatement", {
|
||||
visitor: ["argument"],
|
||||
aliases: ["Statement", "Terminatorless", "CompletionStatement"],
|
||||
fields: {
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression"),
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("SequenceExpression", {
|
||||
visitor: ["expressions"],
|
||||
fields: {
|
||||
expressions: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression")))
|
||||
}
|
||||
},
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("SwitchCase", {
|
||||
visitor: ["test", "consequent"],
|
||||
fields: {
|
||||
test: {
|
||||
validate: (0, _utils.assertNodeType)("Expression"),
|
||||
optional: true
|
||||
},
|
||||
consequent: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Statement")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("SwitchStatement", {
|
||||
visitor: ["discriminant", "cases"],
|
||||
aliases: ["Statement", "BlockParent", "Scopable"],
|
||||
fields: {
|
||||
discriminant: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
cases: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("SwitchCase")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ThisExpression", {
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("ThrowStatement", {
|
||||
visitor: ["argument"],
|
||||
aliases: ["Statement", "Terminatorless", "CompletionStatement"],
|
||||
fields: {
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TryStatement", {
|
||||
visitor: ["block", "handler", "finalizer"],
|
||||
aliases: ["Statement"],
|
||||
fields: {
|
||||
block: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
},
|
||||
handler: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("CatchClause")
|
||||
},
|
||||
finalizer: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("UnaryExpression", {
|
||||
builder: ["operator", "argument", "prefix"],
|
||||
fields: {
|
||||
prefix: {
|
||||
default: true
|
||||
},
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
operator: {
|
||||
validate: _utils.assertOneOf.apply(void 0, _constants.UNARY_OPERATORS)
|
||||
}
|
||||
},
|
||||
visitor: ["argument"],
|
||||
aliases: ["UnaryLike", "Expression"]
|
||||
});
|
||||
(0, _utils.default)("UpdateExpression", {
|
||||
builder: ["operator", "argument", "prefix"],
|
||||
fields: {
|
||||
prefix: {
|
||||
default: false
|
||||
},
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
operator: {
|
||||
validate: _utils.assertOneOf.apply(void 0, _constants.UPDATE_OPERATORS)
|
||||
}
|
||||
},
|
||||
visitor: ["argument"],
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("VariableDeclaration", {
|
||||
builder: ["kind", "declarations"],
|
||||
visitor: ["declarations"],
|
||||
aliases: ["Statement", "Declaration"],
|
||||
fields: {
|
||||
declare: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
kind: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("var", "let", "const"))
|
||||
},
|
||||
declarations: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("VariableDeclarator")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("VariableDeclarator", {
|
||||
visitor: ["id", "init"],
|
||||
fields: {
|
||||
id: {
|
||||
validate: (0, _utils.assertNodeType)("LVal")
|
||||
},
|
||||
init: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("WhileStatement", {
|
||||
visitor: ["test", "body"],
|
||||
aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"],
|
||||
fields: {
|
||||
test: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement", "Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("WithStatement", {
|
||||
visitor: ["object", "body"],
|
||||
aliases: ["Statement"],
|
||||
fields: {
|
||||
object: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement", "Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
+379
@@ -0,0 +1,379 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.classMethodOrDeclareMethodCommon = exports.classMethodOrPropertyCommon = void 0;
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
var _core = require("./core");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
(0, _utils.default)("AssignmentPattern", {
|
||||
visitor: ["left", "right"],
|
||||
builder: ["left", "right"],
|
||||
aliases: ["Pattern", "PatternLike", "LVal"],
|
||||
fields: Object.assign({}, _core.patternLikeCommon, {
|
||||
left: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier", "ObjectPattern", "ArrayPattern")
|
||||
},
|
||||
right: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator")))
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ArrayPattern", {
|
||||
visitor: ["elements", "typeAnnotation"],
|
||||
builder: ["elements"],
|
||||
aliases: ["Pattern", "PatternLike", "LVal"],
|
||||
fields: Object.assign({}, _core.patternLikeCommon, {
|
||||
elements: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("PatternLike")))
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator")))
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ArrowFunctionExpression", {
|
||||
builder: ["params", "body", "async"],
|
||||
visitor: ["params", "body", "returnType", "typeParameters"],
|
||||
aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"],
|
||||
fields: Object.assign({}, _core.functionCommon, _core.functionTypeAnnotationCommon, {
|
||||
expression: {
|
||||
validate: (0, _utils.assertValueType)("boolean")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement", "Expression")
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ClassBody", {
|
||||
visitor: ["body"],
|
||||
fields: {
|
||||
body: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("ClassMethod", "ClassProperty", "TSDeclareMethod", "TSIndexSignature")))
|
||||
}
|
||||
}
|
||||
});
|
||||
var classCommon = {
|
||||
typeParameters: {
|
||||
validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"),
|
||||
optional: true
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("ClassBody")
|
||||
},
|
||||
superClass: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
superTypeParameters: {
|
||||
validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"),
|
||||
optional: true
|
||||
},
|
||||
implements: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSExpressionWithTypeArguments", "FlowClassImplements"))),
|
||||
optional: true
|
||||
}
|
||||
};
|
||||
(0, _utils.default)("ClassDeclaration", {
|
||||
builder: ["id", "superClass", "body", "decorators"],
|
||||
visitor: ["id", "body", "superClass", "mixins", "typeParameters", "superTypeParameters", "implements", "decorators"],
|
||||
aliases: ["Scopable", "Class", "Statement", "Declaration", "Pureish"],
|
||||
fields: Object.assign({}, classCommon, {
|
||||
declare: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
abstract: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
id: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier"),
|
||||
optional: true
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
|
||||
optional: true
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ClassExpression", {
|
||||
inherits: "ClassDeclaration",
|
||||
aliases: ["Scopable", "Class", "Expression", "Pureish"],
|
||||
fields: Object.assign({}, classCommon, {
|
||||
id: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("ClassBody")
|
||||
},
|
||||
superClass: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
|
||||
optional: true
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ExportAllDeclaration", {
|
||||
visitor: ["source"],
|
||||
aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
fields: {
|
||||
source: {
|
||||
validate: (0, _utils.assertNodeType)("StringLiteral")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ExportDefaultDeclaration", {
|
||||
visitor: ["declaration"],
|
||||
aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
fields: {
|
||||
declaration: {
|
||||
validate: (0, _utils.assertNodeType)("FunctionDeclaration", "TSDeclareFunction", "ClassDeclaration", "Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ExportNamedDeclaration", {
|
||||
visitor: ["declaration", "specifiers", "source"],
|
||||
aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
fields: {
|
||||
declaration: {
|
||||
validate: (0, _utils.assertNodeType)("Declaration"),
|
||||
optional: true
|
||||
},
|
||||
specifiers: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier")))
|
||||
},
|
||||
source: {
|
||||
validate: (0, _utils.assertNodeType)("StringLiteral"),
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ExportSpecifier", {
|
||||
visitor: ["local", "exported"],
|
||||
aliases: ["ModuleSpecifier"],
|
||||
fields: {
|
||||
local: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
},
|
||||
exported: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ForOfStatement", {
|
||||
visitor: ["left", "right", "body"],
|
||||
aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
|
||||
fields: {
|
||||
left: {
|
||||
validate: (0, _utils.assertNodeType)("VariableDeclaration", "LVal")
|
||||
},
|
||||
right: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("Statement")
|
||||
},
|
||||
await: {
|
||||
default: false,
|
||||
validate: (0, _utils.assertValueType)("boolean")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ImportDeclaration", {
|
||||
visitor: ["specifiers", "source"],
|
||||
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
|
||||
fields: {
|
||||
specifiers: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier")))
|
||||
},
|
||||
source: {
|
||||
validate: (0, _utils.assertNodeType)("StringLiteral")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ImportDefaultSpecifier", {
|
||||
visitor: ["local"],
|
||||
aliases: ["ModuleSpecifier"],
|
||||
fields: {
|
||||
local: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ImportNamespaceSpecifier", {
|
||||
visitor: ["local"],
|
||||
aliases: ["ModuleSpecifier"],
|
||||
fields: {
|
||||
local: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ImportSpecifier", {
|
||||
visitor: ["local", "imported"],
|
||||
aliases: ["ModuleSpecifier"],
|
||||
fields: {
|
||||
local: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
},
|
||||
imported: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
},
|
||||
importKind: {
|
||||
validate: (0, _utils.assertOneOf)(null, "type", "typeof")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("MetaProperty", {
|
||||
visitor: ["meta", "property"],
|
||||
aliases: ["Expression"],
|
||||
fields: {
|
||||
meta: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
},
|
||||
property: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
var classMethodOrPropertyCommon = {
|
||||
abstract: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
accessibility: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("public", "private", "protected")),
|
||||
optional: true
|
||||
},
|
||||
static: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
computed: {
|
||||
default: false,
|
||||
validate: (0, _utils.assertValueType)("boolean")
|
||||
},
|
||||
optional: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
key: {
|
||||
validate: function () {
|
||||
var normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral");
|
||||
var computed = (0, _utils.assertNodeType)("Expression");
|
||||
return function (node, key, val) {
|
||||
var validator = node.computed ? computed : normal;
|
||||
validator(node, key, val);
|
||||
};
|
||||
}()
|
||||
}
|
||||
};
|
||||
exports.classMethodOrPropertyCommon = classMethodOrPropertyCommon;
|
||||
var classMethodOrDeclareMethodCommon = Object.assign({}, _core.functionCommon, classMethodOrPropertyCommon, {
|
||||
kind: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("get", "set", "method", "constructor")),
|
||||
default: "method"
|
||||
},
|
||||
access: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("public", "private", "protected")),
|
||||
optional: true
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
|
||||
optional: true
|
||||
}
|
||||
});
|
||||
exports.classMethodOrDeclareMethodCommon = classMethodOrDeclareMethodCommon;
|
||||
(0, _utils.default)("ClassMethod", {
|
||||
aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"],
|
||||
builder: ["kind", "key", "params", "body", "computed", "static"],
|
||||
visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"],
|
||||
fields: Object.assign({}, classMethodOrDeclareMethodCommon, _core.functionTypeAnnotationCommon, {
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("ObjectPattern", {
|
||||
visitor: ["properties", "typeAnnotation"],
|
||||
builder: ["properties"],
|
||||
aliases: ["Pattern", "PatternLike", "LVal"],
|
||||
fields: Object.assign({}, _core.patternLikeCommon, {
|
||||
properties: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("RestElement", "ObjectProperty")))
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("SpreadElement", {
|
||||
visitor: ["argument"],
|
||||
aliases: ["UnaryLike"],
|
||||
deprecatedAlias: "SpreadProperty",
|
||||
fields: {
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("Super", {
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("TaggedTemplateExpression", {
|
||||
visitor: ["tag", "quasi"],
|
||||
aliases: ["Expression"],
|
||||
fields: {
|
||||
tag: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
},
|
||||
quasi: {
|
||||
validate: (0, _utils.assertNodeType)("TemplateLiteral")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TemplateElement", {
|
||||
builder: ["value", "tail"],
|
||||
fields: {
|
||||
value: {},
|
||||
tail: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
default: false
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TemplateLiteral", {
|
||||
visitor: ["quasis", "expressions"],
|
||||
aliases: ["Expression", "Literal"],
|
||||
fields: {
|
||||
quasis: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TemplateElement")))
|
||||
},
|
||||
expressions: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("YieldExpression", {
|
||||
builder: ["argument", "delegate"],
|
||||
visitor: ["argument"],
|
||||
aliases: ["Expression", "Terminatorless"],
|
||||
fields: {
|
||||
delegate: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
default: false
|
||||
},
|
||||
argument: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
var _es = require("./es2015");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
(0, _utils.default)("AwaitExpression", {
|
||||
builder: ["argument"],
|
||||
visitor: ["argument"],
|
||||
aliases: ["Expression", "Terminatorless"],
|
||||
fields: {
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("BindExpression", {
|
||||
visitor: ["object", "callee"],
|
||||
aliases: ["Expression"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ClassProperty", {
|
||||
visitor: ["key", "value", "typeAnnotation", "decorators"],
|
||||
builder: ["key", "value", "typeAnnotation", "decorators", "computed"],
|
||||
aliases: ["Property"],
|
||||
fields: Object.assign({}, _es.classMethodOrPropertyCommon, {
|
||||
value: {
|
||||
validate: (0, _utils.assertNodeType)("Expression"),
|
||||
optional: true
|
||||
},
|
||||
typeAnnotation: {
|
||||
validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||
optional: true
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
|
||||
optional: true
|
||||
},
|
||||
readonly: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
}
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("Import", {
|
||||
aliases: ["Expression"]
|
||||
});
|
||||
(0, _utils.default)("Decorator", {
|
||||
visitor: ["expression"],
|
||||
fields: {
|
||||
expression: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("DoExpression", {
|
||||
visitor: ["body"],
|
||||
aliases: ["Expression"],
|
||||
fields: {
|
||||
body: {
|
||||
validate: (0, _utils.assertNodeType)("BlockStatement")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ExportDefaultSpecifier", {
|
||||
visitor: ["exported"],
|
||||
aliases: ["ModuleSpecifier"],
|
||||
fields: {
|
||||
exported: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("ExportNamespaceSpecifier", {
|
||||
visitor: ["exported"],
|
||||
aliases: ["ModuleSpecifier"],
|
||||
fields: {
|
||||
exported: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
"use strict";
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
(0, _utils.default)("AnyTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ArrayTypeAnnotation", {
|
||||
visitor: ["elementType"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("BooleanTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("BooleanLiteralTypeAnnotation", {
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("NullLiteralTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ClassImplements", {
|
||||
visitor: ["id", "typeParameters"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareClass", {
|
||||
visitor: ["id", "typeParameters", "extends", "body"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareFunction", {
|
||||
visitor: ["id"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareInterface", {
|
||||
visitor: ["id", "typeParameters", "extends", "body"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareModule", {
|
||||
visitor: ["id", "body"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareModuleExports", {
|
||||
visitor: ["typeAnnotation"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareTypeAlias", {
|
||||
visitor: ["id", "typeParameters", "right"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareOpaqueType", {
|
||||
visitor: ["id", "typeParameters", "supertype"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareVariable", {
|
||||
visitor: ["id"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareExportDeclaration", {
|
||||
visitor: ["declaration", "specifiers", "source"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclareExportAllDeclaration", {
|
||||
visitor: ["source"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("DeclaredPredicate", {
|
||||
visitor: ["value"],
|
||||
aliases: ["Flow", "FlowPredicate"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ExistsTypeAnnotation", {
|
||||
aliases: ["Flow"]
|
||||
});
|
||||
(0, _utils.default)("FunctionTypeAnnotation", {
|
||||
visitor: ["typeParameters", "params", "rest", "returnType"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("FunctionTypeParam", {
|
||||
visitor: ["name", "typeAnnotation"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("GenericTypeAnnotation", {
|
||||
visitor: ["id", "typeParameters"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("InferredPredicate", {
|
||||
aliases: ["Flow", "FlowPredicate"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("InterfaceExtends", {
|
||||
visitor: ["id", "typeParameters"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("InterfaceDeclaration", {
|
||||
visitor: ["id", "typeParameters", "extends", "body"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("IntersectionTypeAnnotation", {
|
||||
visitor: ["types"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("MixedTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"]
|
||||
});
|
||||
(0, _utils.default)("EmptyTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"]
|
||||
});
|
||||
(0, _utils.default)("NullableTypeAnnotation", {
|
||||
visitor: ["typeAnnotation"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("NumberLiteralTypeAnnotation", {
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("NumberTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ObjectTypeAnnotation", {
|
||||
visitor: ["properties", "indexers", "callProperties"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ObjectTypeCallProperty", {
|
||||
visitor: ["value"],
|
||||
aliases: ["Flow", "UserWhitespacable"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ObjectTypeIndexer", {
|
||||
visitor: ["id", "key", "value"],
|
||||
aliases: ["Flow", "UserWhitespacable"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ObjectTypeProperty", {
|
||||
visitor: ["key", "value"],
|
||||
aliases: ["Flow", "UserWhitespacable"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ObjectTypeSpreadProperty", {
|
||||
visitor: ["argument"],
|
||||
aliases: ["Flow", "UserWhitespacable"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("OpaqueType", {
|
||||
visitor: ["id", "typeParameters", "supertype", "impltype"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("QualifiedTypeIdentifier", {
|
||||
visitor: ["id", "qualification"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("StringLiteralTypeAnnotation", {
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("StringTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("ThisTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("TupleTypeAnnotation", {
|
||||
visitor: ["types"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("TypeofTypeAnnotation", {
|
||||
visitor: ["argument"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("TypeAlias", {
|
||||
visitor: ["id", "typeParameters", "right"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("TypeAnnotation", {
|
||||
aliases: ["Flow"],
|
||||
visitor: ["typeAnnotation"],
|
||||
fields: {
|
||||
typeAnnotation: {
|
||||
validate: (0, _utils.assertNodeType)("Flow")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TypeCastExpression", {
|
||||
visitor: ["expression", "typeAnnotation"],
|
||||
aliases: ["Flow", "ExpressionWrapper", "Expression"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("TypeParameter", {
|
||||
aliases: ["Flow"],
|
||||
visitor: ["bound", "default"],
|
||||
fields: {
|
||||
name: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
},
|
||||
bound: {
|
||||
validate: (0, _utils.assertNodeType)("TypeAnnotation"),
|
||||
optional: true
|
||||
},
|
||||
default: {
|
||||
validate: (0, _utils.assertNodeType)("Flow"),
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TypeParameterDeclaration", {
|
||||
aliases: ["Flow"],
|
||||
visitor: ["params"],
|
||||
fields: {
|
||||
params: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TypeParameter")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TypeParameterInstantiation", {
|
||||
aliases: ["Flow"],
|
||||
visitor: ["params"],
|
||||
fields: {
|
||||
params: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Flow")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("UnionTypeAnnotation", {
|
||||
visitor: ["types"],
|
||||
aliases: ["Flow"],
|
||||
fields: {}
|
||||
});
|
||||
(0, _utils.default)("VoidTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.TYPES = void 0;
|
||||
|
||||
var _toFastProperties = _interopRequireDefault(require("to-fast-properties"));
|
||||
|
||||
require("./core");
|
||||
|
||||
require("./es2015");
|
||||
|
||||
require("./flow");
|
||||
|
||||
require("./jsx");
|
||||
|
||||
require("./misc");
|
||||
|
||||
require("./experimental");
|
||||
|
||||
require("./typescript");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
exports.VISITOR_KEYS = _utils.VISITOR_KEYS;
|
||||
exports.ALIAS_KEYS = _utils.ALIAS_KEYS;
|
||||
exports.FLIPPED_ALIAS_KEYS = _utils.FLIPPED_ALIAS_KEYS;
|
||||
exports.NODE_FIELDS = _utils.NODE_FIELDS;
|
||||
exports.BUILDER_KEYS = _utils.BUILDER_KEYS;
|
||||
exports.DEPRECATED_KEYS = _utils.DEPRECATED_KEYS;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
(0, _toFastProperties.default)(_utils.VISITOR_KEYS);
|
||||
(0, _toFastProperties.default)(_utils.ALIAS_KEYS);
|
||||
(0, _toFastProperties.default)(_utils.FLIPPED_ALIAS_KEYS);
|
||||
(0, _toFastProperties.default)(_utils.NODE_FIELDS);
|
||||
(0, _toFastProperties.default)(_utils.BUILDER_KEYS);
|
||||
(0, _toFastProperties.default)(_utils.DEPRECATED_KEYS);
|
||||
var TYPES = Object.keys(_utils.VISITOR_KEYS).concat(Object.keys(_utils.FLIPPED_ALIAS_KEYS)).concat(Object.keys(_utils.DEPRECATED_KEYS));
|
||||
exports.TYPES = TYPES;
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
"use strict";
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
(0, _utils.default)("JSXAttribute", {
|
||||
visitor: ["name", "value"],
|
||||
aliases: ["JSX", "Immutable"],
|
||||
fields: {
|
||||
name: {
|
||||
validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXNamespacedName")
|
||||
},
|
||||
value: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("JSXElement", "JSXFragment", "StringLiteral", "JSXExpressionContainer")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXClosingElement", {
|
||||
visitor: ["name"],
|
||||
aliases: ["JSX", "Immutable"],
|
||||
fields: {
|
||||
name: {
|
||||
validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXMemberExpression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXElement", {
|
||||
builder: ["openingElement", "closingElement", "children", "selfClosing"],
|
||||
visitor: ["openingElement", "children", "closingElement"],
|
||||
aliases: ["JSX", "Immutable", "Expression"],
|
||||
fields: {
|
||||
openingElement: {
|
||||
validate: (0, _utils.assertNodeType)("JSXOpeningElement")
|
||||
},
|
||||
closingElement: {
|
||||
optional: true,
|
||||
validate: (0, _utils.assertNodeType)("JSXClosingElement")
|
||||
},
|
||||
children: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement", "JSXFragment")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXEmptyExpression", {
|
||||
aliases: ["JSX", "Expression"]
|
||||
});
|
||||
(0, _utils.default)("JSXExpressionContainer", {
|
||||
visitor: ["expression"],
|
||||
aliases: ["JSX", "Immutable"],
|
||||
fields: {
|
||||
expression: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXSpreadChild", {
|
||||
visitor: ["expression"],
|
||||
aliases: ["JSX", "Immutable"],
|
||||
fields: {
|
||||
expression: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXIdentifier", {
|
||||
builder: ["name"],
|
||||
aliases: ["JSX", "Expression"],
|
||||
fields: {
|
||||
name: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXMemberExpression", {
|
||||
visitor: ["object", "property"],
|
||||
aliases: ["JSX", "Expression"],
|
||||
fields: {
|
||||
object: {
|
||||
validate: (0, _utils.assertNodeType)("JSXMemberExpression", "JSXIdentifier")
|
||||
},
|
||||
property: {
|
||||
validate: (0, _utils.assertNodeType)("JSXIdentifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXNamespacedName", {
|
||||
visitor: ["namespace", "name"],
|
||||
aliases: ["JSX"],
|
||||
fields: {
|
||||
namespace: {
|
||||
validate: (0, _utils.assertNodeType)("JSXIdentifier")
|
||||
},
|
||||
name: {
|
||||
validate: (0, _utils.assertNodeType)("JSXIdentifier")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXOpeningElement", {
|
||||
builder: ["name", "attributes", "selfClosing"],
|
||||
visitor: ["name", "attributes"],
|
||||
aliases: ["JSX", "Immutable"],
|
||||
fields: {
|
||||
name: {
|
||||
validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXMemberExpression")
|
||||
},
|
||||
selfClosing: {
|
||||
default: false,
|
||||
validate: (0, _utils.assertValueType)("boolean")
|
||||
},
|
||||
attributes: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("JSXAttribute", "JSXSpreadAttribute")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXSpreadAttribute", {
|
||||
visitor: ["argument"],
|
||||
aliases: ["JSX"],
|
||||
fields: {
|
||||
argument: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXText", {
|
||||
aliases: ["JSX", "Immutable"],
|
||||
builder: ["value"],
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXFragment", {
|
||||
builder: ["openingFragment", "closingFragment", "children"],
|
||||
visitor: ["openingFragment", "children", "closingFragment"],
|
||||
aliases: ["JSX", "Immutable", "Expression"],
|
||||
fields: {
|
||||
openingFragment: {
|
||||
validate: (0, _utils.assertNodeType)("JSXOpeningFragment")
|
||||
},
|
||||
closingFragment: {
|
||||
validate: (0, _utils.assertNodeType)("JSXClosingFragment")
|
||||
},
|
||||
children: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement", "JSXFragment")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("JSXOpeningFragment", {
|
||||
aliases: ["JSX", "Immutable"]
|
||||
});
|
||||
(0, _utils.default)("JSXClosingFragment", {
|
||||
aliases: ["JSX", "Immutable"]
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
(0, _utils.default)("Noop", {
|
||||
visitor: []
|
||||
});
|
||||
(0, _utils.default)("ParenthesizedExpression", {
|
||||
visitor: ["expression"],
|
||||
aliases: ["Expression", "ExpressionWrapper"],
|
||||
fields: {
|
||||
expression: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
}
|
||||
}
|
||||
});
|
||||
+413
@@ -0,0 +1,413 @@
|
||||
"use strict";
|
||||
|
||||
var _utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
var _core = require("./core");
|
||||
|
||||
var _es = require("./es2015");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
var bool = (0, _utils.assertValueType)("boolean");
|
||||
|
||||
function validate(validate) {
|
||||
return {
|
||||
validate: validate
|
||||
};
|
||||
}
|
||||
|
||||
function typeIs(typeName) {
|
||||
return typeof typeName === "string" ? (0, _utils.assertNodeType)(typeName) : _utils.assertNodeType.apply(void 0, typeName);
|
||||
}
|
||||
|
||||
function validateType(name) {
|
||||
return validate(typeIs(name));
|
||||
}
|
||||
|
||||
function validateOptional(validate) {
|
||||
return {
|
||||
validate: validate,
|
||||
optional: true
|
||||
};
|
||||
}
|
||||
|
||||
function validateOptionalType(typeName) {
|
||||
return {
|
||||
validate: typeIs(typeName),
|
||||
optional: true
|
||||
};
|
||||
}
|
||||
|
||||
function arrayOf(elementType) {
|
||||
return (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)(elementType));
|
||||
}
|
||||
|
||||
function arrayOfType(nodeTypeName) {
|
||||
return arrayOf(typeIs(nodeTypeName));
|
||||
}
|
||||
|
||||
function validateArrayOfType(nodeTypeName) {
|
||||
return validate(arrayOfType(nodeTypeName));
|
||||
}
|
||||
|
||||
var tSFunctionTypeAnnotationCommon = {
|
||||
returnType: {
|
||||
validate: (0, _utils.assertNodeType)("TSTypeAnnotation", "Noop"),
|
||||
optional: true
|
||||
},
|
||||
typeParameters: {
|
||||
validate: (0, _utils.assertNodeType)("TSTypeParameterDeclaration", "Noop"),
|
||||
optional: true
|
||||
}
|
||||
};
|
||||
(0, _utils.default)("TSParameterProperty", {
|
||||
aliases: ["LVal"],
|
||||
visitor: ["parameter"],
|
||||
fields: {
|
||||
accessibility: {
|
||||
validate: (0, _utils.assertOneOf)("public", "private", "protected"),
|
||||
optional: true
|
||||
},
|
||||
readonly: {
|
||||
validate: (0, _utils.assertValueType)("boolean"),
|
||||
optional: true
|
||||
},
|
||||
parameter: {
|
||||
validate: (0, _utils.assertNodeType)("Identifier", "AssignmentPattern")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSDeclareFunction", {
|
||||
aliases: ["Statement", "Declaration"],
|
||||
visitor: ["id", "typeParameters", "params", "returnType"],
|
||||
fields: Object.assign({}, _core.functionDeclarationCommon, tSFunctionTypeAnnotationCommon)
|
||||
});
|
||||
(0, _utils.default)("TSDeclareMethod", {
|
||||
visitor: ["decorators", "key", "typeParameters", "params", "returnType"],
|
||||
fields: Object.assign({}, _es.classMethodOrDeclareMethodCommon, tSFunctionTypeAnnotationCommon)
|
||||
});
|
||||
(0, _utils.default)("TSQualifiedName", {
|
||||
aliases: ["TSEntityName"],
|
||||
visitor: ["left", "right"],
|
||||
fields: {
|
||||
left: validateType("TSEntityName"),
|
||||
right: validateType("Identifier")
|
||||
}
|
||||
});
|
||||
var signatureDeclarationCommon = {
|
||||
typeParameters: validateOptionalType("TSTypeParameterDeclaration"),
|
||||
parameters: validateArrayOfType(["Identifier", "RestElement"]),
|
||||
typeAnnotation: validateOptionalType("TSTypeAnnotation")
|
||||
};
|
||||
var callConstructSignatureDeclaration = {
|
||||
aliases: ["TSTypeElement"],
|
||||
visitor: ["typeParameters", "parameters", "typeAnnotation"],
|
||||
fields: signatureDeclarationCommon
|
||||
};
|
||||
(0, _utils.default)("TSCallSignatureDeclaration", callConstructSignatureDeclaration);
|
||||
(0, _utils.default)("TSConstructSignatureDeclaration", callConstructSignatureDeclaration);
|
||||
var namedTypeElementCommon = {
|
||||
key: validateType("Expression"),
|
||||
computed: validate(bool),
|
||||
optional: validateOptional(bool)
|
||||
};
|
||||
(0, _utils.default)("TSPropertySignature", {
|
||||
aliases: ["TSTypeElement"],
|
||||
visitor: ["key", "typeAnnotation", "initializer"],
|
||||
fields: Object.assign({}, namedTypeElementCommon, {
|
||||
readonly: validateOptional(bool),
|
||||
typeAnnotation: validateOptionalType("TSTypeAnnotation"),
|
||||
initializer: validateOptionalType("Expression")
|
||||
})
|
||||
});
|
||||
(0, _utils.default)("TSMethodSignature", {
|
||||
aliases: ["TSTypeElement"],
|
||||
visitor: ["key", "typeParameters", "parameters", "typeAnnotation"],
|
||||
fields: Object.assign({}, signatureDeclarationCommon, namedTypeElementCommon)
|
||||
});
|
||||
(0, _utils.default)("TSIndexSignature", {
|
||||
aliases: ["TSTypeElement"],
|
||||
visitor: ["parameters", "typeAnnotation"],
|
||||
fields: {
|
||||
readonly: validateOptional(bool),
|
||||
parameters: validateArrayOfType("Identifier"),
|
||||
typeAnnotation: validateOptionalType("TSTypeAnnotation")
|
||||
}
|
||||
});
|
||||
var tsKeywordTypes = ["TSAnyKeyword", "TSNumberKeyword", "TSObjectKeyword", "TSBooleanKeyword", "TSStringKeyword", "TSSymbolKeyword", "TSVoidKeyword", "TSUndefinedKeyword", "TSNullKeyword", "TSNeverKeyword"];
|
||||
|
||||
for (var _i = 0; _i < tsKeywordTypes.length; _i++) {
|
||||
var type = tsKeywordTypes[_i];
|
||||
(0, _utils.default)(type, {
|
||||
aliases: ["TSType"],
|
||||
visitor: [],
|
||||
fields: {}
|
||||
});
|
||||
}
|
||||
|
||||
(0, _utils.default)("TSThisType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: [],
|
||||
fields: {}
|
||||
});
|
||||
var fnOrCtr = {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["typeParameters", "typeAnnotation"],
|
||||
fields: signatureDeclarationCommon
|
||||
};
|
||||
(0, _utils.default)("TSFunctionType", fnOrCtr);
|
||||
(0, _utils.default)("TSConstructorType", fnOrCtr);
|
||||
(0, _utils.default)("TSTypeReference", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["typeName", "typeParameters"],
|
||||
fields: {
|
||||
typeName: validateType("TSEntityName"),
|
||||
typeParameters: validateOptionalType("TSTypeParameterInstantiation")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypePredicate", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["parameterName", "typeAnnotation"],
|
||||
fields: {
|
||||
parameterName: validateType(["Identifier", "TSThisType"]),
|
||||
typeAnnotation: validateType("TSTypeAnnotation")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeQuery", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["exprName"],
|
||||
fields: {
|
||||
exprName: validateType("TSEntityName")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeLiteral", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["members"],
|
||||
fields: {
|
||||
members: validateArrayOfType("TSTypeElement")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSArrayType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["elementType"],
|
||||
fields: {
|
||||
elementType: validateType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTupleType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["elementTypes"],
|
||||
fields: {
|
||||
elementTypes: validateArrayOfType("TSType")
|
||||
}
|
||||
});
|
||||
var unionOrIntersection = {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["types"],
|
||||
fields: {
|
||||
types: validateArrayOfType("TSType")
|
||||
}
|
||||
};
|
||||
(0, _utils.default)("TSUnionType", unionOrIntersection);
|
||||
(0, _utils.default)("TSIntersectionType", unionOrIntersection);
|
||||
(0, _utils.default)("TSParenthesizedType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["typeAnnotation"],
|
||||
fields: {
|
||||
typeAnnotation: validateType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeOperator", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["typeAnnotation"],
|
||||
fields: {
|
||||
operator: validate((0, _utils.assertValueType)("string")),
|
||||
typeAnnotation: validateType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSIndexedAccessType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["objectType", "indexType"],
|
||||
fields: {
|
||||
objectType: validateType("TSType"),
|
||||
indexType: validateType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSMappedType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["typeParameter", "typeAnnotation"],
|
||||
fields: {
|
||||
readonly: validateOptional(bool),
|
||||
typeParameter: validateType("TSTypeParameter"),
|
||||
optional: validateOptional(bool),
|
||||
typeAnnotation: validateOptionalType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSLiteralType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["literal"],
|
||||
fields: {
|
||||
literal: validateType(["NumericLiteral", "StringLiteral", "BooleanLiteral"])
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSExpressionWithTypeArguments", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["expression", "typeParameters"],
|
||||
fields: {
|
||||
expression: validateType("TSEntityName"),
|
||||
typeParameters: validateOptionalType("TSTypeParameterInstantiation")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSInterfaceDeclaration", {
|
||||
aliases: ["Statement", "Declaration"],
|
||||
visitor: ["id", "typeParameters", "extends", "body"],
|
||||
fields: {
|
||||
declare: validateOptional(bool),
|
||||
id: validateType("Identifier"),
|
||||
typeParameters: validateOptionalType("TSTypeParameterDeclaration"),
|
||||
extends: validateOptional(arrayOfType("TSExpressionWithTypeArguments")),
|
||||
body: validateType("TSInterfaceBody")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSInterfaceBody", {
|
||||
visitor: ["body"],
|
||||
fields: {
|
||||
body: validateArrayOfType("TSTypeElement")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeAliasDeclaration", {
|
||||
aliases: ["Statement", "Declaration"],
|
||||
visitor: ["id", "typeParameters", "typeAnnotation"],
|
||||
fields: {
|
||||
declare: validateOptional(bool),
|
||||
id: validateType("Identifier"),
|
||||
typeParameters: validateOptionalType("TSTypeParameterDeclaration"),
|
||||
typeAnnotation: validateType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSAsExpression", {
|
||||
aliases: ["Expression"],
|
||||
visitor: ["expression", "typeAnnotation"],
|
||||
fields: {
|
||||
expression: validateType("Expression"),
|
||||
typeAnnotation: validateType("TSType")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeAssertion", {
|
||||
aliases: ["Expression"],
|
||||
visitor: ["typeAnnotation", "expression"],
|
||||
fields: {
|
||||
typeAnnotation: validateType("TSType"),
|
||||
expression: validateType("Expression")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSEnumDeclaration", {
|
||||
aliases: ["Statement", "Declaration"],
|
||||
visitor: ["id", "members"],
|
||||
fields: {
|
||||
declare: validateOptional(bool),
|
||||
const: validateOptional(bool),
|
||||
id: validateType("Identifier"),
|
||||
members: validateArrayOfType("TSEnumMember"),
|
||||
initializer: validateOptionalType("Expression")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSEnumMember", {
|
||||
visitor: ["id", "initializer"],
|
||||
fields: {
|
||||
id: validateType(["Identifier", "StringLiteral"]),
|
||||
initializer: validateOptionalType("Expression")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSModuleDeclaration", {
|
||||
aliases: ["Statement", "Declaration"],
|
||||
visitor: ["id", "body"],
|
||||
fields: {
|
||||
declare: validateOptional(bool),
|
||||
global: validateOptional(bool),
|
||||
id: validateType(["Identifier", "StringLiteral"]),
|
||||
body: validateType(["TSModuleBlock", "TSModuleDeclaration"])
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSModuleBlock", {
|
||||
visitor: ["body"],
|
||||
fields: {
|
||||
body: validateArrayOfType("Statement")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSImportEqualsDeclaration", {
|
||||
aliases: ["Statement"],
|
||||
visitor: ["id", "moduleReference"],
|
||||
fields: {
|
||||
isExport: validate(bool),
|
||||
id: validateType("Identifier"),
|
||||
moduleReference: validateType(["TSEntityName", "TSExternalModuleReference"])
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSExternalModuleReference", {
|
||||
visitor: ["expression"],
|
||||
fields: {
|
||||
expression: validateType("StringLiteral")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSNonNullExpression", {
|
||||
aliases: ["Expression"],
|
||||
visitor: ["expression"],
|
||||
fields: {
|
||||
expression: validateType("Expression")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSExportAssignment", {
|
||||
aliases: ["Statement"],
|
||||
visitor: ["expression"],
|
||||
fields: {
|
||||
expression: validateType("Expression")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSNamespaceExportDeclaration", {
|
||||
aliases: ["Statement"],
|
||||
visitor: ["id"],
|
||||
fields: {
|
||||
id: validateType("Identifier")
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeAnnotation", {
|
||||
visitor: ["typeAnnotation"],
|
||||
fields: {
|
||||
typeAnnotation: {
|
||||
validate: (0, _utils.assertNodeType)("TSType")
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeParameterInstantiation", {
|
||||
visitor: ["params"],
|
||||
fields: {
|
||||
params: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSType")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeParameterDeclaration", {
|
||||
visitor: ["params"],
|
||||
fields: {
|
||||
params: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSTypeParameter")))
|
||||
}
|
||||
}
|
||||
});
|
||||
(0, _utils.default)("TSTypeParameter", {
|
||||
visitor: ["constraint", "default"],
|
||||
fields: {
|
||||
name: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
},
|
||||
constraint: {
|
||||
validate: (0, _utils.assertNodeType)("TSType"),
|
||||
optional: true
|
||||
},
|
||||
default: {
|
||||
validate: (0, _utils.assertNodeType)("TSType"),
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.assertEach = assertEach;
|
||||
exports.assertOneOf = assertOneOf;
|
||||
exports.assertNodeType = assertNodeType;
|
||||
exports.assertNodeOrValueType = assertNodeOrValueType;
|
||||
exports.assertValueType = assertValueType;
|
||||
exports.chain = chain;
|
||||
exports.default = defineType;
|
||||
exports.DEPRECATED_KEYS = exports.BUILDER_KEYS = exports.NODE_FIELDS = exports.FLIPPED_ALIAS_KEYS = exports.ALIAS_KEYS = exports.VISITOR_KEYS = void 0;
|
||||
|
||||
var _is = _interopRequireDefault(require("../validators/is"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var VISITOR_KEYS = {};
|
||||
exports.VISITOR_KEYS = VISITOR_KEYS;
|
||||
var ALIAS_KEYS = {};
|
||||
exports.ALIAS_KEYS = ALIAS_KEYS;
|
||||
var FLIPPED_ALIAS_KEYS = {};
|
||||
exports.FLIPPED_ALIAS_KEYS = FLIPPED_ALIAS_KEYS;
|
||||
var NODE_FIELDS = {};
|
||||
exports.NODE_FIELDS = NODE_FIELDS;
|
||||
var BUILDER_KEYS = {};
|
||||
exports.BUILDER_KEYS = BUILDER_KEYS;
|
||||
var DEPRECATED_KEYS = {};
|
||||
exports.DEPRECATED_KEYS = DEPRECATED_KEYS;
|
||||
|
||||
function getType(val) {
|
||||
if (Array.isArray(val)) {
|
||||
return "array";
|
||||
} else if (val === null) {
|
||||
return "null";
|
||||
} else if (val === undefined) {
|
||||
return "undefined";
|
||||
} else {
|
||||
return typeof val;
|
||||
}
|
||||
}
|
||||
|
||||
function assertEach(callback) {
|
||||
function validator(node, key, val) {
|
||||
if (!Array.isArray(val)) return;
|
||||
|
||||
for (var i = 0; i < val.length; i++) {
|
||||
callback(node, key + "[" + i + "]", val[i]);
|
||||
}
|
||||
}
|
||||
|
||||
validator.each = callback;
|
||||
return validator;
|
||||
}
|
||||
|
||||
function assertOneOf() {
|
||||
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
values[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
function validate(node, key, val) {
|
||||
if (values.indexOf(val) < 0) {
|
||||
throw new TypeError("Property " + key + " expected value to be one of " + JSON.stringify(values) + " but got " + JSON.stringify(val));
|
||||
}
|
||||
}
|
||||
|
||||
validate.oneOf = values;
|
||||
return validate;
|
||||
}
|
||||
|
||||
function assertNodeType() {
|
||||
for (var _len2 = arguments.length, types = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
||||
types[_key2] = arguments[_key2];
|
||||
}
|
||||
|
||||
function validate(node, key, val) {
|
||||
var valid = false;
|
||||
|
||||
for (var _i = 0; _i < types.length; _i++) {
|
||||
var type = types[_i];
|
||||
|
||||
if ((0, _is.default)(type, val)) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
throw new TypeError("Property " + key + " of " + node.type + " expected node to be of a type " + JSON.stringify(types) + " " + ("but instead got " + JSON.stringify(val && val.type)));
|
||||
}
|
||||
}
|
||||
|
||||
validate.oneOfNodeTypes = types;
|
||||
return validate;
|
||||
}
|
||||
|
||||
function assertNodeOrValueType() {
|
||||
for (var _len3 = arguments.length, types = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
||||
types[_key3] = arguments[_key3];
|
||||
}
|
||||
|
||||
function validate(node, key, val) {
|
||||
var valid = false;
|
||||
|
||||
for (var _i2 = 0; _i2 < types.length; _i2++) {
|
||||
var type = types[_i2];
|
||||
|
||||
if (getType(val) === type || (0, _is.default)(type, val)) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
throw new TypeError("Property " + key + " of " + node.type + " expected node to be of a type " + JSON.stringify(types) + " " + ("but instead got " + JSON.stringify(val && val.type)));
|
||||
}
|
||||
}
|
||||
|
||||
validate.oneOfNodeOrValueTypes = types;
|
||||
return validate;
|
||||
}
|
||||
|
||||
function assertValueType(type) {
|
||||
function validate(node, key, val) {
|
||||
var valid = getType(val) === type;
|
||||
|
||||
if (!valid) {
|
||||
throw new TypeError("Property " + key + " expected type of " + type + " but got " + getType(val));
|
||||
}
|
||||
}
|
||||
|
||||
validate.type = type;
|
||||
return validate;
|
||||
}
|
||||
|
||||
function chain() {
|
||||
for (var _len4 = arguments.length, fns = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
||||
fns[_key4] = arguments[_key4];
|
||||
}
|
||||
|
||||
function validate() {
|
||||
for (var _i3 = 0; _i3 < fns.length; _i3++) {
|
||||
var fn = fns[_i3];
|
||||
fn.apply(void 0, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
validate.chainOf = fns;
|
||||
return validate;
|
||||
}
|
||||
|
||||
function defineType(type, opts) {
|
||||
if (opts === void 0) {
|
||||
opts = {};
|
||||
}
|
||||
|
||||
var inherits = opts.inherits && store[opts.inherits] || {};
|
||||
var fields = opts.fields || inherits.fields || {};
|
||||
var visitor = opts.visitor || inherits.visitor || [];
|
||||
var aliases = opts.aliases || inherits.aliases || [];
|
||||
var builder = opts.builder || inherits.builder || opts.visitor || [];
|
||||
|
||||
if (opts.deprecatedAlias) {
|
||||
DEPRECATED_KEYS[opts.deprecatedAlias] = type;
|
||||
}
|
||||
|
||||
var _arr = visitor.concat(builder);
|
||||
|
||||
for (var _i4 = 0; _i4 < _arr.length; _i4++) {
|
||||
var key = _arr[_i4];
|
||||
fields[key] = fields[key] || {};
|
||||
}
|
||||
|
||||
for (var _key5 in fields) {
|
||||
var field = fields[_key5];
|
||||
|
||||
if (builder.indexOf(_key5) === -1) {
|
||||
field.optional = true;
|
||||
}
|
||||
|
||||
if (field.default === undefined) {
|
||||
field.default = null;
|
||||
} else if (!field.validate) {
|
||||
field.validate = assertValueType(getType(field.default));
|
||||
}
|
||||
}
|
||||
|
||||
VISITOR_KEYS[type] = opts.visitor = visitor;
|
||||
BUILDER_KEYS[type] = opts.builder = builder;
|
||||
NODE_FIELDS[type] = opts.fields = fields;
|
||||
ALIAS_KEYS[type] = opts.aliases = aliases;
|
||||
aliases.forEach(function (alias) {
|
||||
FLIPPED_ALIAS_KEYS[alias] = FLIPPED_ALIAS_KEYS[alias] || [];
|
||||
FLIPPED_ALIAS_KEYS[alias].push(type);
|
||||
});
|
||||
store[type] = opts;
|
||||
}
|
||||
|
||||
var store = {};
|
||||
+325
@@ -0,0 +1,325 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
var _exportNames = {
|
||||
assertNode: true,
|
||||
createTypeAnnotationBasedOnTypeof: true,
|
||||
createUnionTypeAnnotation: true,
|
||||
clone: true,
|
||||
cloneDeep: true,
|
||||
cloneWithoutLoc: true,
|
||||
addComment: true,
|
||||
addComments: true,
|
||||
inheritInnerComments: true,
|
||||
inheritLeadingComments: true,
|
||||
inheritsComments: true,
|
||||
inheritTrailingComments: true,
|
||||
removeComments: true,
|
||||
ensureBlock: true,
|
||||
toBindingIdentifierName: true,
|
||||
toBlock: true,
|
||||
toComputedKey: true,
|
||||
toExpression: true,
|
||||
toIdentifier: true,
|
||||
toKeyAlias: true,
|
||||
toSequenceExpression: true,
|
||||
toStatement: true,
|
||||
valueToNode: true,
|
||||
appendToMemberExpression: true,
|
||||
inherits: true,
|
||||
prependToMemberExpression: true,
|
||||
removeProperties: true,
|
||||
removePropertiesDeep: true,
|
||||
removeTypeDuplicates: true,
|
||||
getBindingIdentifiers: true,
|
||||
getOuterBindingIdentifiers: true,
|
||||
traverse: true,
|
||||
traverseFast: true,
|
||||
shallowEqual: true,
|
||||
is: true,
|
||||
isBinding: true,
|
||||
isBlockScoped: true,
|
||||
isImmutable: true,
|
||||
isLet: true,
|
||||
isNode: true,
|
||||
isNodesEquivalent: true,
|
||||
isReferenced: true,
|
||||
isScope: true,
|
||||
isSpecifierDefault: true,
|
||||
isType: true,
|
||||
isValidES3Identifier: true,
|
||||
isValidIdentifier: true,
|
||||
isVar: true,
|
||||
matchesPattern: true,
|
||||
validate: true,
|
||||
buildMatchMemberExpression: true,
|
||||
react: true
|
||||
};
|
||||
exports.react = exports.buildMatchMemberExpression = exports.validate = exports.matchesPattern = exports.isVar = exports.isValidIdentifier = exports.isValidES3Identifier = exports.isType = exports.isSpecifierDefault = exports.isScope = exports.isReferenced = exports.isNodesEquivalent = exports.isNode = exports.isLet = exports.isImmutable = exports.isBlockScoped = exports.isBinding = exports.is = exports.shallowEqual = exports.traverseFast = exports.traverse = exports.getOuterBindingIdentifiers = exports.getBindingIdentifiers = exports.removeTypeDuplicates = exports.removePropertiesDeep = exports.removeProperties = exports.prependToMemberExpression = exports.inherits = exports.appendToMemberExpression = exports.valueToNode = exports.toStatement = exports.toSequenceExpression = exports.toKeyAlias = exports.toIdentifier = exports.toExpression = exports.toComputedKey = exports.toBlock = exports.toBindingIdentifierName = exports.ensureBlock = exports.removeComments = exports.inheritTrailingComments = exports.inheritsComments = exports.inheritLeadingComments = exports.inheritInnerComments = exports.addComments = exports.addComment = exports.cloneWithoutLoc = exports.cloneDeep = exports.clone = exports.createUnionTypeAnnotation = exports.createTypeAnnotationBasedOnTypeof = exports.assertNode = void 0;
|
||||
|
||||
var _isReactComponent = _interopRequireDefault(require("./validators/react/isReactComponent"));
|
||||
|
||||
var _isCompatTag = _interopRequireDefault(require("./validators/react/isCompatTag"));
|
||||
|
||||
var _buildChildren = _interopRequireDefault(require("./builders/react/buildChildren"));
|
||||
|
||||
var _assertNode = _interopRequireDefault(require("./asserts/assertNode"));
|
||||
|
||||
exports.assertNode = _assertNode.default;
|
||||
|
||||
var _generated = require("./asserts/generated");
|
||||
|
||||
Object.keys(_generated).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
exports[key] = _generated[key];
|
||||
});
|
||||
|
||||
var _createTypeAnnotationBasedOnTypeof = _interopRequireDefault(require("./builders/flow/createTypeAnnotationBasedOnTypeof"));
|
||||
|
||||
exports.createTypeAnnotationBasedOnTypeof = _createTypeAnnotationBasedOnTypeof.default;
|
||||
|
||||
var _createUnionTypeAnnotation = _interopRequireDefault(require("./builders/flow/createUnionTypeAnnotation"));
|
||||
|
||||
exports.createUnionTypeAnnotation = _createUnionTypeAnnotation.default;
|
||||
|
||||
var _generated2 = require("./builders/generated");
|
||||
|
||||
Object.keys(_generated2).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
exports[key] = _generated2[key];
|
||||
});
|
||||
|
||||
var _clone = _interopRequireDefault(require("./clone/clone"));
|
||||
|
||||
exports.clone = _clone.default;
|
||||
|
||||
var _cloneDeep = _interopRequireDefault(require("./clone/cloneDeep"));
|
||||
|
||||
exports.cloneDeep = _cloneDeep.default;
|
||||
|
||||
var _cloneWithoutLoc = _interopRequireDefault(require("./clone/cloneWithoutLoc"));
|
||||
|
||||
exports.cloneWithoutLoc = _cloneWithoutLoc.default;
|
||||
|
||||
var _addComment = _interopRequireDefault(require("./comments/addComment"));
|
||||
|
||||
exports.addComment = _addComment.default;
|
||||
|
||||
var _addComments = _interopRequireDefault(require("./comments/addComments"));
|
||||
|
||||
exports.addComments = _addComments.default;
|
||||
|
||||
var _inheritInnerComments = _interopRequireDefault(require("./comments/inheritInnerComments"));
|
||||
|
||||
exports.inheritInnerComments = _inheritInnerComments.default;
|
||||
|
||||
var _inheritLeadingComments = _interopRequireDefault(require("./comments/inheritLeadingComments"));
|
||||
|
||||
exports.inheritLeadingComments = _inheritLeadingComments.default;
|
||||
|
||||
var _inheritsComments = _interopRequireDefault(require("./comments/inheritsComments"));
|
||||
|
||||
exports.inheritsComments = _inheritsComments.default;
|
||||
|
||||
var _inheritTrailingComments = _interopRequireDefault(require("./comments/inheritTrailingComments"));
|
||||
|
||||
exports.inheritTrailingComments = _inheritTrailingComments.default;
|
||||
|
||||
var _removeComments = _interopRequireDefault(require("./comments/removeComments"));
|
||||
|
||||
exports.removeComments = _removeComments.default;
|
||||
|
||||
var _generated3 = require("./constants/generated");
|
||||
|
||||
Object.keys(_generated3).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
exports[key] = _generated3[key];
|
||||
});
|
||||
|
||||
var _constants = require("./constants");
|
||||
|
||||
Object.keys(_constants).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
exports[key] = _constants[key];
|
||||
});
|
||||
|
||||
var _ensureBlock = _interopRequireDefault(require("./converters/ensureBlock"));
|
||||
|
||||
exports.ensureBlock = _ensureBlock.default;
|
||||
|
||||
var _toBindingIdentifierName = _interopRequireDefault(require("./converters/toBindingIdentifierName"));
|
||||
|
||||
exports.toBindingIdentifierName = _toBindingIdentifierName.default;
|
||||
|
||||
var _toBlock = _interopRequireDefault(require("./converters/toBlock"));
|
||||
|
||||
exports.toBlock = _toBlock.default;
|
||||
|
||||
var _toComputedKey = _interopRequireDefault(require("./converters/toComputedKey"));
|
||||
|
||||
exports.toComputedKey = _toComputedKey.default;
|
||||
|
||||
var _toExpression = _interopRequireDefault(require("./converters/toExpression"));
|
||||
|
||||
exports.toExpression = _toExpression.default;
|
||||
|
||||
var _toIdentifier = _interopRequireDefault(require("./converters/toIdentifier"));
|
||||
|
||||
exports.toIdentifier = _toIdentifier.default;
|
||||
|
||||
var _toKeyAlias = _interopRequireDefault(require("./converters/toKeyAlias"));
|
||||
|
||||
exports.toKeyAlias = _toKeyAlias.default;
|
||||
|
||||
var _toSequenceExpression = _interopRequireDefault(require("./converters/toSequenceExpression"));
|
||||
|
||||
exports.toSequenceExpression = _toSequenceExpression.default;
|
||||
|
||||
var _toStatement = _interopRequireDefault(require("./converters/toStatement"));
|
||||
|
||||
exports.toStatement = _toStatement.default;
|
||||
|
||||
var _valueToNode = _interopRequireDefault(require("./converters/valueToNode"));
|
||||
|
||||
exports.valueToNode = _valueToNode.default;
|
||||
|
||||
var _definitions = require("./definitions");
|
||||
|
||||
Object.keys(_definitions).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
exports[key] = _definitions[key];
|
||||
});
|
||||
|
||||
var _appendToMemberExpression = _interopRequireDefault(require("./modifications/appendToMemberExpression"));
|
||||
|
||||
exports.appendToMemberExpression = _appendToMemberExpression.default;
|
||||
|
||||
var _inherits = _interopRequireDefault(require("./modifications/inherits"));
|
||||
|
||||
exports.inherits = _inherits.default;
|
||||
|
||||
var _prependToMemberExpression = _interopRequireDefault(require("./modifications/prependToMemberExpression"));
|
||||
|
||||
exports.prependToMemberExpression = _prependToMemberExpression.default;
|
||||
|
||||
var _removeProperties = _interopRequireDefault(require("./modifications/removeProperties"));
|
||||
|
||||
exports.removeProperties = _removeProperties.default;
|
||||
|
||||
var _removePropertiesDeep = _interopRequireDefault(require("./modifications/removePropertiesDeep"));
|
||||
|
||||
exports.removePropertiesDeep = _removePropertiesDeep.default;
|
||||
|
||||
var _removeTypeDuplicates = _interopRequireDefault(require("./modifications/flow/removeTypeDuplicates"));
|
||||
|
||||
exports.removeTypeDuplicates = _removeTypeDuplicates.default;
|
||||
|
||||
var _getBindingIdentifiers = _interopRequireDefault(require("./retrievers/getBindingIdentifiers"));
|
||||
|
||||
exports.getBindingIdentifiers = _getBindingIdentifiers.default;
|
||||
|
||||
var _getOuterBindingIdentifiers = _interopRequireDefault(require("./retrievers/getOuterBindingIdentifiers"));
|
||||
|
||||
exports.getOuterBindingIdentifiers = _getOuterBindingIdentifiers.default;
|
||||
|
||||
var _traverse = _interopRequireDefault(require("./traverse/traverse"));
|
||||
|
||||
exports.traverse = _traverse.default;
|
||||
|
||||
var _traverseFast = _interopRequireDefault(require("./traverse/traverseFast"));
|
||||
|
||||
exports.traverseFast = _traverseFast.default;
|
||||
|
||||
var _shallowEqual = _interopRequireDefault(require("./utils/shallowEqual"));
|
||||
|
||||
exports.shallowEqual = _shallowEqual.default;
|
||||
|
||||
var _is = _interopRequireDefault(require("./validators/is"));
|
||||
|
||||
exports.is = _is.default;
|
||||
|
||||
var _isBinding = _interopRequireDefault(require("./validators/isBinding"));
|
||||
|
||||
exports.isBinding = _isBinding.default;
|
||||
|
||||
var _isBlockScoped = _interopRequireDefault(require("./validators/isBlockScoped"));
|
||||
|
||||
exports.isBlockScoped = _isBlockScoped.default;
|
||||
|
||||
var _isImmutable = _interopRequireDefault(require("./validators/isImmutable"));
|
||||
|
||||
exports.isImmutable = _isImmutable.default;
|
||||
|
||||
var _isLet = _interopRequireDefault(require("./validators/isLet"));
|
||||
|
||||
exports.isLet = _isLet.default;
|
||||
|
||||
var _isNode = _interopRequireDefault(require("./validators/isNode"));
|
||||
|
||||
exports.isNode = _isNode.default;
|
||||
|
||||
var _isNodesEquivalent = _interopRequireDefault(require("./validators/isNodesEquivalent"));
|
||||
|
||||
exports.isNodesEquivalent = _isNodesEquivalent.default;
|
||||
|
||||
var _isReferenced = _interopRequireDefault(require("./validators/isReferenced"));
|
||||
|
||||
exports.isReferenced = _isReferenced.default;
|
||||
|
||||
var _isScope = _interopRequireDefault(require("./validators/isScope"));
|
||||
|
||||
exports.isScope = _isScope.default;
|
||||
|
||||
var _isSpecifierDefault = _interopRequireDefault(require("./validators/isSpecifierDefault"));
|
||||
|
||||
exports.isSpecifierDefault = _isSpecifierDefault.default;
|
||||
|
||||
var _isType = _interopRequireDefault(require("./validators/isType"));
|
||||
|
||||
exports.isType = _isType.default;
|
||||
|
||||
var _isValidES3Identifier = _interopRequireDefault(require("./validators/isValidES3Identifier"));
|
||||
|
||||
exports.isValidES3Identifier = _isValidES3Identifier.default;
|
||||
|
||||
var _isValidIdentifier = _interopRequireDefault(require("./validators/isValidIdentifier"));
|
||||
|
||||
exports.isValidIdentifier = _isValidIdentifier.default;
|
||||
|
||||
var _isVar = _interopRequireDefault(require("./validators/isVar"));
|
||||
|
||||
exports.isVar = _isVar.default;
|
||||
|
||||
var _matchesPattern = _interopRequireDefault(require("./validators/matchesPattern"));
|
||||
|
||||
exports.matchesPattern = _matchesPattern.default;
|
||||
|
||||
var _validate = _interopRequireDefault(require("./validators/validate"));
|
||||
|
||||
exports.validate = _validate.default;
|
||||
|
||||
var _buildMatchMemberExpression = _interopRequireDefault(require("./validators/buildMatchMemberExpression"));
|
||||
|
||||
exports.buildMatchMemberExpression = _buildMatchMemberExpression.default;
|
||||
|
||||
var _generated4 = require("./validators/generated");
|
||||
|
||||
Object.keys(_generated4).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
exports[key] = _generated4[key];
|
||||
});
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var react = {
|
||||
isReactComponent: _isReactComponent.default,
|
||||
isCompatTag: _isCompatTag.default,
|
||||
buildChildren: _buildChildren.default
|
||||
};
|
||||
exports.react = react;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = appendToMemberExpression;
|
||||
|
||||
var _generated = require("../builders/generated");
|
||||
|
||||
function appendToMemberExpression(member, append, computed) {
|
||||
if (computed === void 0) {
|
||||
computed = false;
|
||||
}
|
||||
|
||||
member.object = (0, _generated.memberExpression)(member.object, member.property, member.computed);
|
||||
member.property = append;
|
||||
member.computed = !!computed;
|
||||
return member;
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = removeTypeDuplicates;
|
||||
|
||||
var _generated = require("../../validators/generated");
|
||||
|
||||
function removeTypeDuplicates(nodes) {
|
||||
var generics = {};
|
||||
var bases = {};
|
||||
var typeGroups = [];
|
||||
var types = [];
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
if (!node) continue;
|
||||
|
||||
if (types.indexOf(node) >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((0, _generated.isAnyTypeAnnotation)(node)) {
|
||||
return [node];
|
||||
}
|
||||
|
||||
if ((0, _generated.isFlowBaseAnnotation)(node)) {
|
||||
bases[node.type] = node;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((0, _generated.isUnionTypeAnnotation)(node)) {
|
||||
if (typeGroups.indexOf(node.types) < 0) {
|
||||
nodes = nodes.concat(node.types);
|
||||
typeGroups.push(node.types);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((0, _generated.isGenericTypeAnnotation)(node)) {
|
||||
var name = node.id.name;
|
||||
|
||||
if (generics[name]) {
|
||||
var existing = generics[name];
|
||||
|
||||
if (existing.typeParameters) {
|
||||
if (node.typeParameters) {
|
||||
existing.typeParameters.params = removeTypeDuplicates(existing.typeParameters.params.concat(node.typeParameters.params));
|
||||
}
|
||||
} else {
|
||||
existing = node.typeParameters;
|
||||
}
|
||||
} else {
|
||||
generics[name] = node;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
types.push(node);
|
||||
}
|
||||
|
||||
for (var type in bases) {
|
||||
types.push(bases[type]);
|
||||
}
|
||||
|
||||
for (var _name in generics) {
|
||||
types.push(generics[_name]);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = inherits;
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
var _inheritsComments = _interopRequireDefault(require("../comments/inheritsComments"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function inherits(child, parent) {
|
||||
if (!child || !parent) return child;
|
||||
var _arr = _constants.INHERIT_KEYS.optional;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var key = _arr[_i];
|
||||
|
||||
if (child[key] == null) {
|
||||
child[key] = parent[key];
|
||||
}
|
||||
}
|
||||
|
||||
for (var _key in parent) {
|
||||
if (_key[0] === "_" && _key !== "__clone") child[_key] = parent[_key];
|
||||
}
|
||||
|
||||
var _arr2 = _constants.INHERIT_KEYS.force;
|
||||
|
||||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
||||
var _key2 = _arr2[_i2];
|
||||
child[_key2] = parent[_key2];
|
||||
}
|
||||
|
||||
(0, _inheritsComments.default)(child, parent);
|
||||
return child;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = prependToMemberExpression;
|
||||
|
||||
var _generated = require("../builders/generated");
|
||||
|
||||
function prependToMemberExpression(member, prepend) {
|
||||
member.object = (0, _generated.memberExpression)(prepend, member.object);
|
||||
return member;
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = removeProperties;
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
var CLEAR_KEYS = ["tokens", "start", "end", "loc", "raw", "rawValue"];
|
||||
|
||||
var CLEAR_KEYS_PLUS_COMMENTS = _constants.COMMENT_KEYS.concat(["comments"]).concat(CLEAR_KEYS);
|
||||
|
||||
function removeProperties(node, opts) {
|
||||
if (opts === void 0) {
|
||||
opts = {};
|
||||
}
|
||||
|
||||
var map = opts.preserveComments ? CLEAR_KEYS : CLEAR_KEYS_PLUS_COMMENTS;
|
||||
|
||||
for (var _iterator = map, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var _key2 = _ref;
|
||||
if (node[_key2] != null) node[_key2] = undefined;
|
||||
}
|
||||
|
||||
for (var _key in node) {
|
||||
if (_key[0] === "_" && node[_key] != null) node[_key] = undefined;
|
||||
}
|
||||
|
||||
var symbols = Object.getOwnPropertySymbols(node);
|
||||
|
||||
for (var _iterator2 = symbols, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var _sym = _ref2;
|
||||
node[_sym] = null;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = removePropertiesDeep;
|
||||
|
||||
var _traverseFast = _interopRequireDefault(require("../traverse/traverseFast"));
|
||||
|
||||
var _removeProperties = _interopRequireDefault(require("./removeProperties"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function removePropertiesDeep(tree, opts) {
|
||||
(0, _traverseFast.default)(tree, _removeProperties.default, opts);
|
||||
return tree;
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = getBindingIdentifiers;
|
||||
|
||||
var _generated = require("../validators/generated");
|
||||
|
||||
function getBindingIdentifiers(node, duplicates, outerOnly) {
|
||||
var search = [].concat(node);
|
||||
var ids = Object.create(null);
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
var keys = getBindingIdentifiers.keys[id.type];
|
||||
|
||||
if ((0, _generated.isIdentifier)(id)) {
|
||||
if (duplicates) {
|
||||
var _ids = ids[id.name] = ids[id.name] || [];
|
||||
|
||||
_ids.push(id);
|
||||
} else {
|
||||
ids[id.name] = id;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((0, _generated.isExportDeclaration)(id)) {
|
||||
if ((0, _generated.isDeclaration)(id.declaration)) {
|
||||
search.push(id.declaration);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (outerOnly) {
|
||||
if ((0, _generated.isFunctionDeclaration)(id)) {
|
||||
search.push(id.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((0, _generated.isFunctionExpression)(id)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (keys) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
|
||||
if (id[key]) {
|
||||
search = search.concat(id[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
getBindingIdentifiers.keys = {
|
||||
DeclareClass: ["id"],
|
||||
DeclareFunction: ["id"],
|
||||
DeclareModule: ["id"],
|
||||
DeclareVariable: ["id"],
|
||||
InterfaceDeclaration: ["id"],
|
||||
TypeAlias: ["id"],
|
||||
OpaqueType: ["id"],
|
||||
CatchClause: ["param"],
|
||||
LabeledStatement: ["label"],
|
||||
UnaryExpression: ["argument"],
|
||||
AssignmentExpression: ["left"],
|
||||
ImportSpecifier: ["local"],
|
||||
ImportNamespaceSpecifier: ["local"],
|
||||
ImportDefaultSpecifier: ["local"],
|
||||
ImportDeclaration: ["specifiers"],
|
||||
ExportSpecifier: ["exported"],
|
||||
ExportNamespaceSpecifier: ["exported"],
|
||||
ExportDefaultSpecifier: ["exported"],
|
||||
FunctionDeclaration: ["id", "params"],
|
||||
FunctionExpression: ["id", "params"],
|
||||
ForInStatement: ["left"],
|
||||
ForOfStatement: ["left"],
|
||||
ClassDeclaration: ["id"],
|
||||
ClassExpression: ["id"],
|
||||
RestElement: ["argument"],
|
||||
UpdateExpression: ["argument"],
|
||||
ObjectProperty: ["value"],
|
||||
AssignmentPattern: ["left"],
|
||||
ArrayPattern: ["elements"],
|
||||
ObjectPattern: ["properties"],
|
||||
VariableDeclaration: ["declarations"],
|
||||
VariableDeclarator: ["id"]
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = getOuterBindingIdentifiers;
|
||||
|
||||
var _getBindingIdentifiers = _interopRequireDefault(require("./getBindingIdentifiers"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function getOuterBindingIdentifiers(node, duplicates) {
|
||||
return (0, _getBindingIdentifiers.default)(node, duplicates, true);
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = traverse;
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
function traverse(node, handlers, state) {
|
||||
if (typeof handlers === "function") {
|
||||
handlers = {
|
||||
enter: handlers
|
||||
};
|
||||
}
|
||||
|
||||
var _ref = handlers,
|
||||
enter = _ref.enter,
|
||||
exit = _ref.exit;
|
||||
traverseSimpleImpl(node, enter, exit, state, []);
|
||||
}
|
||||
|
||||
function traverseSimpleImpl(node, enter, exit, state, ancestors) {
|
||||
var keys = _definitions.VISITOR_KEYS[node.type];
|
||||
if (!keys) return;
|
||||
if (enter) enter(node, ancestors, state);
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref2 = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref2 = _i.value;
|
||||
}
|
||||
|
||||
var _key2 = _ref2;
|
||||
var subNode = node[_key2];
|
||||
|
||||
if (Array.isArray(subNode)) {
|
||||
for (var i = 0; i < subNode.length; i++) {
|
||||
var child = subNode[i];
|
||||
if (!child) continue;
|
||||
ancestors.push({
|
||||
node: node,
|
||||
key: _key2,
|
||||
index: i
|
||||
});
|
||||
traverseSimpleImpl(child, enter, exit, state, ancestors);
|
||||
ancestors.pop();
|
||||
}
|
||||
} else if (subNode) {
|
||||
ancestors.push({
|
||||
node: node,
|
||||
key: _key2
|
||||
});
|
||||
traverseSimpleImpl(subNode, enter, exit, state, ancestors);
|
||||
ancestors.pop();
|
||||
}
|
||||
}
|
||||
|
||||
if (exit) exit(node, ancestors, state);
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = traverseFast;
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
function traverseFast(node, enter, opts) {
|
||||
if (!node) return;
|
||||
var keys = _definitions.VISITOR_KEYS[node.type];
|
||||
if (!keys) return;
|
||||
opts = opts || {};
|
||||
enter(node, opts);
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var _key = _ref;
|
||||
var subNode = node[_key];
|
||||
|
||||
if (Array.isArray(subNode)) {
|
||||
for (var _iterator2 = subNode, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var _node2 = _ref2;
|
||||
traverseFast(_node2, enter, opts);
|
||||
}
|
||||
} else {
|
||||
traverseFast(subNode, enter, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = inherit;
|
||||
|
||||
var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function inherit(key, child, parent) {
|
||||
if (child && parent) {
|
||||
child[key] = (0, _uniq.default)([].concat(child[key], parent[key]).filter(Boolean));
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = cleanJSXElementLiteralChild;
|
||||
|
||||
var _generated = require("../../builders/generated");
|
||||
|
||||
function cleanJSXElementLiteralChild(child, args) {
|
||||
var lines = child.value.split(/\r\n|\n|\r/);
|
||||
var lastNonEmptyLine = 0;
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
if (lines[i].match(/[^ \t]/)) {
|
||||
lastNonEmptyLine = i;
|
||||
}
|
||||
}
|
||||
|
||||
var str = "";
|
||||
|
||||
for (var _i = 0; _i < lines.length; _i++) {
|
||||
var line = lines[_i];
|
||||
var isFirstLine = _i === 0;
|
||||
var isLastLine = _i === lines.length - 1;
|
||||
var isLastNonEmptyLine = _i === lastNonEmptyLine;
|
||||
var trimmedLine = line.replace(/\t/g, " ");
|
||||
|
||||
if (!isFirstLine) {
|
||||
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
|
||||
}
|
||||
|
||||
if (!isLastLine) {
|
||||
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
|
||||
}
|
||||
|
||||
if (trimmedLine) {
|
||||
if (!isLastNonEmptyLine) {
|
||||
trimmedLine += " ";
|
||||
}
|
||||
|
||||
str += trimmedLine;
|
||||
}
|
||||
}
|
||||
|
||||
if (str) args.push((0, _generated.stringLiteral)(str));
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = shallowEqual;
|
||||
|
||||
function shallowEqual(actual, expected) {
|
||||
var keys = Object.keys(expected);
|
||||
var _arr = keys;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var key = _arr[_i];
|
||||
|
||||
if (actual[key] !== expected[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = buildMatchMemberExpression;
|
||||
|
||||
var _matchesPattern = _interopRequireDefault(require("./matchesPattern"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function buildMatchMemberExpression(match, allowPartial) {
|
||||
var parts = match.split(".");
|
||||
return function (member) {
|
||||
return (0, _matchesPattern.default)(member, parts, allowPartial);
|
||||
};
|
||||
}
|
||||
+1241
File diff suppressed because it is too large
Load Diff
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = is;
|
||||
|
||||
var _shallowEqual = _interopRequireDefault(require("../utils/shallowEqual"));
|
||||
|
||||
var _isType = _interopRequireDefault(require("./isType"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function is(type, node, opts) {
|
||||
if (!node) return false;
|
||||
var matches = (0, _isType.default)(node.type, type);
|
||||
if (!matches) return false;
|
||||
|
||||
if (typeof opts === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return (0, _shallowEqual.default)(node, opts);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isBinding;
|
||||
|
||||
var _getBindingIdentifiers = _interopRequireDefault(require("../retrievers/getBindingIdentifiers"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function isBinding(node, parent) {
|
||||
var keys = _getBindingIdentifiers.default.keys[parent.type];
|
||||
|
||||
if (keys) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
var val = parent[key];
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
if (val.indexOf(node) >= 0) return true;
|
||||
} else {
|
||||
if (val === node) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isBlockScoped;
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
var _isLet = _interopRequireDefault(require("./isLet"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function isBlockScoped(node) {
|
||||
return (0, _generated.isFunctionDeclaration)(node) || (0, _generated.isClassDeclaration)(node) || (0, _isLet.default)(node);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isImmutable;
|
||||
|
||||
var _isType = _interopRequireDefault(require("./isType"));
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function isImmutable(node) {
|
||||
if ((0, _isType.default)(node.type, "Immutable")) return true;
|
||||
|
||||
if ((0, _generated.isIdentifier)(node)) {
|
||||
if (node.name === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isLet;
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
function isLet(node) {
|
||||
return (0, _generated.isVariableDeclaration)(node) && (node.kind !== "var" || node[_constants.BLOCK_SCOPED_SYMBOL]);
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isNode;
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
function isNode(node) {
|
||||
return !!(node && _definitions.VISITOR_KEYS[node.type]);
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isNodesEquivalent;
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
function isNodesEquivalent(a, b) {
|
||||
if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
|
||||
return a === b;
|
||||
}
|
||||
|
||||
if (a.type !== b.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var fields = Object.keys(_definitions.NODE_FIELDS[a.type] || a.type);
|
||||
|
||||
for (var _i = 0; _i < fields.length; _i++) {
|
||||
var field = fields[_i];
|
||||
|
||||
if (typeof a[field] !== typeof b[field]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(a[field])) {
|
||||
if (!Array.isArray(b[field])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a[field].length !== b[field].length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < a[field].length; i++) {
|
||||
if (!isNodesEquivalent(a[field][i], b[field][i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isNodesEquivalent(a[field], b[field])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isReferenced;
|
||||
|
||||
function isReferenced(node, parent) {
|
||||
switch (parent.type) {
|
||||
case "BindExpression":
|
||||
return parent.object === node || parent.callee === node;
|
||||
|
||||
case "MemberExpression":
|
||||
case "JSXMemberExpression":
|
||||
if (parent.property === node && parent.computed) {
|
||||
return true;
|
||||
} else if (parent.object === node) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
case "MetaProperty":
|
||||
return false;
|
||||
|
||||
case "ObjectProperty":
|
||||
if (parent.key === node) {
|
||||
return parent.computed;
|
||||
}
|
||||
|
||||
case "VariableDeclarator":
|
||||
return parent.id !== node;
|
||||
|
||||
case "ArrowFunctionExpression":
|
||||
case "FunctionDeclaration":
|
||||
case "FunctionExpression":
|
||||
var _arr = parent.params;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var param = _arr[_i];
|
||||
if (param === node) return false;
|
||||
}
|
||||
|
||||
return parent.id !== node;
|
||||
|
||||
case "ExportSpecifier":
|
||||
if (parent.source) {
|
||||
return false;
|
||||
} else {
|
||||
return parent.local === node;
|
||||
}
|
||||
|
||||
case "ExportNamespaceSpecifier":
|
||||
case "ExportDefaultSpecifier":
|
||||
return false;
|
||||
|
||||
case "JSXAttribute":
|
||||
return parent.name !== node;
|
||||
|
||||
case "ClassProperty":
|
||||
if (parent.key === node) {
|
||||
return parent.computed;
|
||||
} else {
|
||||
return parent.value === node;
|
||||
}
|
||||
|
||||
case "ImportDefaultSpecifier":
|
||||
case "ImportNamespaceSpecifier":
|
||||
case "ImportSpecifier":
|
||||
return false;
|
||||
|
||||
case "ClassDeclaration":
|
||||
case "ClassExpression":
|
||||
return parent.id !== node;
|
||||
|
||||
case "ClassMethod":
|
||||
case "ObjectMethod":
|
||||
return parent.key === node && parent.computed;
|
||||
|
||||
case "LabeledStatement":
|
||||
return false;
|
||||
|
||||
case "CatchClause":
|
||||
return parent.param !== node;
|
||||
|
||||
case "RestElement":
|
||||
return false;
|
||||
|
||||
case "AssignmentExpression":
|
||||
return parent.right === node;
|
||||
|
||||
case "AssignmentPattern":
|
||||
return parent.right === node;
|
||||
|
||||
case "ObjectPattern":
|
||||
case "ArrayPattern":
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isScope;
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
function isScope(node, parent) {
|
||||
if ((0, _generated.isBlockStatement)(node) && (0, _generated.isFunction)(parent, {
|
||||
body: node
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((0, _generated.isBlockStatement)(node) && (0, _generated.isCatchClause)(parent, {
|
||||
body: node
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (0, _generated.isScopable)(node);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isSpecifierDefault;
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
function isSpecifierDefault(specifier) {
|
||||
return (0, _generated.isImportDefaultSpecifier)(specifier) || (0, _generated.isIdentifier)(specifier.imported || specifier.exported, {
|
||||
name: "default"
|
||||
});
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isType;
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
function isType(nodeType, targetType) {
|
||||
if (nodeType === targetType) return true;
|
||||
if (_definitions.ALIAS_KEYS[targetType]) return false;
|
||||
var aliases = _definitions.FLIPPED_ALIAS_KEYS[targetType];
|
||||
|
||||
if (aliases) {
|
||||
if (aliases[0] === nodeType) return true;
|
||||
|
||||
for (var _iterator = aliases, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var _alias = _ref;
|
||||
if (nodeType === _alias) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isValidES3Identifier;
|
||||
|
||||
var _isValidIdentifier = _interopRequireDefault(require("./isValidIdentifier"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var RESERVED_WORDS_ES3_ONLY = new Set(["abstract", "boolean", "byte", "char", "double", "enum", "final", "float", "goto", "implements", "int", "interface", "long", "native", "package", "private", "protected", "public", "short", "static", "synchronized", "throws", "transient", "volatile"]);
|
||||
|
||||
function isValidES3Identifier(name) {
|
||||
return (0, _isValidIdentifier.default)(name) && !RESERVED_WORDS_ES3_ONLY.has(name);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isValidIdentifier;
|
||||
|
||||
var _esutils = _interopRequireDefault(require("esutils"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function isValidIdentifier(name) {
|
||||
if (typeof name !== "string" || _esutils.default.keyword.isReservedWordES6(name, true)) {
|
||||
return false;
|
||||
} else if (name === "await") {
|
||||
return false;
|
||||
} else {
|
||||
return _esutils.default.keyword.isIdentifierNameES6(name);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isVar;
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
function isVar(node) {
|
||||
return (0, _generated.isVariableDeclaration)(node, {
|
||||
kind: "var"
|
||||
}) && !node[_constants.BLOCK_SCOPED_SYMBOL];
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = matchesPattern;
|
||||
|
||||
var _generated = require("./generated");
|
||||
|
||||
function matchesPattern(member, match, allowPartial) {
|
||||
if (!(0, _generated.isMemberExpression)(member)) return false;
|
||||
var parts = Array.isArray(match) ? match : match.split(".");
|
||||
var nodes = [];
|
||||
var node;
|
||||
|
||||
for (node = member; (0, _generated.isMemberExpression)(node); node = node.object) {
|
||||
nodes.push(node.property);
|
||||
}
|
||||
|
||||
nodes.push(node);
|
||||
if (nodes.length < parts.length) return false;
|
||||
if (!allowPartial && nodes.length > parts.length) return false;
|
||||
|
||||
for (var i = 0, j = nodes.length - 1; i < parts.length; i++, j--) {
|
||||
var _node = nodes[j];
|
||||
var value = void 0;
|
||||
|
||||
if ((0, _generated.isIdentifier)(_node)) {
|
||||
value = _node.name;
|
||||
} else if ((0, _generated.isStringLiteral)(_node)) {
|
||||
value = _node.value;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parts[i] !== value) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = isCompatTag;
|
||||
|
||||
function isCompatTag(tagName) {
|
||||
return !!tagName && /^[a-z]|-/.test(tagName);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = void 0;
|
||||
|
||||
var _buildMatchMemberExpression = _interopRequireDefault(require("../buildMatchMemberExpression"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var isReactComponent = (0, _buildMatchMemberExpression.default)("React.Component");
|
||||
var _default = isReactComponent;
|
||||
exports.default = _default;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = validate;
|
||||
|
||||
var _definitions = require("../definitions");
|
||||
|
||||
function validate(node, key, val) {
|
||||
if (!node) return;
|
||||
var fields = _definitions.NODE_FIELDS[node.type];
|
||||
if (!fields) return;
|
||||
var field = fields[key];
|
||||
if (!field || !field.validate) return;
|
||||
if (field.optional && val == null) return;
|
||||
field.validate(node, key, val);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
let fastProto = null;
|
||||
|
||||
// Creates an object with permanently fast properties in V8. See Toon Verwaest's
|
||||
// post https://medium.com/@tverwaes/setting-up-prototypes-in-v8-ec9c9491dfe2#5f62
|
||||
// for more details. Use %HasFastProperties(object) and the Node.js flag
|
||||
// --allow-natives-syntax to check whether an object has fast properties.
|
||||
function FastObject(o) {
|
||||
// A prototype object will have "fast properties" enabled once it is checked
|
||||
// against the inline property cache of a function, e.g. fastProto.property:
|
||||
// https://github.com/v8/v8/blob/6.0.122/test/mjsunit/fast-prototype.js#L48-L63
|
||||
if (fastProto !== null && typeof fastProto.property) {
|
||||
const result = fastProto;
|
||||
fastProto = FastObject.prototype = null;
|
||||
return result;
|
||||
}
|
||||
fastProto = FastObject.prototype = o == null ? Object.create(null) : o;
|
||||
return new FastObject;
|
||||
}
|
||||
|
||||
// Initialize the inline property cache of FastObject
|
||||
FastObject();
|
||||
|
||||
module.exports = function toFastproperties(o) {
|
||||
return FastObject(o);
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014 Petka Antonov
|
||||
2015 Sindre Sorhus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "to-fast-properties",
|
||||
"version": "2.0.0",
|
||||
"description": "Force V8 to use fast properties for an object",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/to-fast-properties",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --allow-natives-syntax test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"object",
|
||||
"obj",
|
||||
"properties",
|
||||
"props",
|
||||
"v8",
|
||||
"optimize",
|
||||
"fast",
|
||||
"convert",
|
||||
"mode"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "0.0.4"
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
# to-fast-properties [](https://travis-ci.org/sindresorhus/to-fast-properties)
|
||||
|
||||
> Force V8 to use fast properties for an object
|
||||
|
||||
[Read more.](http://stackoverflow.com/questions/24987896/)
|
||||
|
||||
Use `%HasFastProperties(object)` and `--allow-natives-syntax` to check whether an object already has fast properties.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save to-fast-properties
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const toFastProperties = require('to-fast-properties');
|
||||
|
||||
const obj = {
|
||||
foo: true,
|
||||
bar: true
|
||||
};
|
||||
|
||||
delete obj.foo;
|
||||
// `obj` now has slow properties
|
||||
|
||||
toFastProperties(obj);
|
||||
// `obj` now has fast properties
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © Petka Antonov, John-David Dalton, Sindre Sorhus
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@babel/types",
|
||||
"version": "7.0.0-beta.35",
|
||||
"description": "Babel Types is a Lodash-esque utility library for AST nodes",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-types",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"esutils": "^2.0.2",
|
||||
"lodash": "^4.2.0",
|
||||
"to-fast-properties": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/generator": "7.0.0-beta.35",
|
||||
"babylon": "7.0.0-beta.35"
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const generateBuilders = require("./generators/generateBuilders");
|
||||
const generateValidators = require("./generators/generateValidators");
|
||||
const generateAsserts = require("./generators/generateAsserts");
|
||||
const generateConstants = require("./generators/generateConstants");
|
||||
const format = require("./utils/formatCode");
|
||||
|
||||
const baseDir = path.join(__dirname, "../src");
|
||||
|
||||
function writeFile(content, location) {
|
||||
const file = path.join(baseDir, location);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(file));
|
||||
} catch (error) {
|
||||
if (error.code !== "EEXIST") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(file, format(content, file));
|
||||
}
|
||||
|
||||
console.log("Generating @babel/types dynamic functions");
|
||||
|
||||
writeFile(generateBuilders(), "builders/generated/index.js");
|
||||
writeFile(generateValidators(), "validators/generated/index.js");
|
||||
writeFile(generateAsserts(), "asserts/generated/index.js");
|
||||
writeFile(generateConstants(), "constants/generated/index.js");
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
const definitions = require("../../lib/definitions");
|
||||
|
||||
function addAssertHelper(type) {
|
||||
return `export function assert${type}(node: Object, opts?: Object = {}): void {
|
||||
assert("${type}", node, opts) }
|
||||
`;
|
||||
}
|
||||
|
||||
module.exports = function generateAsserts() {
|
||||
let output = `// @flow
|
||||
/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'make build'
|
||||
*/
|
||||
import is from "../../validators/is";
|
||||
|
||||
function assert(type: string, node: Object, opts?: Object): void {
|
||||
if (!is(type, node, opts)) {
|
||||
throw new Error(
|
||||
\`Expected type "\${type}" with option \${JSON.stringify(opts)}, but instead got "\${node.type}".\`,
|
||||
);
|
||||
}
|
||||
}\n\n`;
|
||||
|
||||
Object.keys(definitions.VISITOR_KEYS).forEach(type => {
|
||||
output += addAssertHelper(type);
|
||||
});
|
||||
|
||||
Object.keys(definitions.FLIPPED_ALIAS_KEYS).forEach(type => {
|
||||
output += addAssertHelper(type);
|
||||
});
|
||||
|
||||
Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
|
||||
const newType = definitions.DEPRECATED_KEYS[type];
|
||||
output += `export function assert${type}(node: Object, opts: Object): void {
|
||||
console.trace("The node type ${type} has been renamed to ${newType}");
|
||||
assert("${type}", node, opts);
|
||||
}\n`;
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
const definitions = require("../../lib/definitions");
|
||||
const formatBuilderName = require("../utils/formatBuilderName");
|
||||
const lowerFirst = require("../utils/lowerFirst");
|
||||
|
||||
module.exports = function generateBuilders() {
|
||||
let output = `// @flow
|
||||
/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'make build'
|
||||
*/
|
||||
import builder from "../builder";\n\n`;
|
||||
|
||||
Object.keys(definitions.BUILDER_KEYS).forEach(type => {
|
||||
output += `export function ${type}(...args: Array<any>): Object { return builder("${type}", ...args); }
|
||||
export { ${type} as ${formatBuilderName(type)} };\n`;
|
||||
|
||||
// This is needed for backwards compatibility.
|
||||
// It should be removed in the next major version.
|
||||
// JSXIdentifier -> jSXIdentifier
|
||||
if (/^[A-Z]{2}/.test(type)) {
|
||||
output += `export { ${type} as ${lowerFirst(type)} }\n`;
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
|
||||
const newType = definitions.DEPRECATED_KEYS[type];
|
||||
output += `export function ${type}(...args: Array<any>): Object {
|
||||
console.trace("The node type ${type} has been renamed to ${newType}");
|
||||
return ${type}("${type}", ...args);
|
||||
}
|
||||
export { ${type} as ${formatBuilderName(type)} };\n`;
|
||||
|
||||
// This is needed for backwards compatibility.
|
||||
// It should be removed in the next major version.
|
||||
// JSXIdentifier -> jSXIdentifier
|
||||
if (/^[A-Z]{2}/.test(type)) {
|
||||
output += `export { ${type} as ${lowerFirst(type)} }\n`;
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
const definitions = require("../../lib/definitions");
|
||||
|
||||
module.exports = function generateConstants() {
|
||||
let output = `// @flow
|
||||
/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'make build'
|
||||
*/
|
||||
import { FLIPPED_ALIAS_KEYS } from "../../definitions";\n\n`;
|
||||
|
||||
Object.keys(definitions.FLIPPED_ALIAS_KEYS).forEach(type => {
|
||||
output += `export const ${type.toUpperCase()}_TYPES = FLIPPED_ALIAS_KEYS["${type}"];\n`;
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
const definitions = require("../../lib/definitions");
|
||||
|
||||
function addIsHelper(type) {
|
||||
return `export function is${type}(node: Object, opts?: Object): boolean {
|
||||
return is("${type}", node, opts) }
|
||||
`;
|
||||
}
|
||||
|
||||
module.exports = function generateValidators() {
|
||||
let output = `// @flow
|
||||
/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'make build'
|
||||
*/
|
||||
import is from "../is";\n\n`;
|
||||
|
||||
Object.keys(definitions.VISITOR_KEYS).forEach(type => {
|
||||
output += addIsHelper(type);
|
||||
});
|
||||
|
||||
Object.keys(definitions.FLIPPED_ALIAS_KEYS).forEach(type => {
|
||||
output += addIsHelper(type);
|
||||
});
|
||||
|
||||
Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
|
||||
const newType = definitions.DEPRECATED_KEYS[type];
|
||||
output += `export function is${type}(node: Object, opts: Object): boolean {
|
||||
console.trace("The node type ${type} has been renamed to ${newType}");
|
||||
return is("${type}", node, opts);
|
||||
}\n`;
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const toLowerCase = Function.call.bind("".toLowerCase);
|
||||
|
||||
module.exports = function formatBuilderName(type) {
|
||||
// FunctionExpression -> functionExpression
|
||||
// JSXIdentifier -> jsxIdentifier
|
||||
return type.replace(/^([A-Z](?=[a-z])|[A-Z]+(?=[A-Z]))/, toLowerCase);
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user