Removes node modules from version control
This commit is contained in:
parent
3cc5cee0b5
commit
c34ce4107e
|
@ -1,2 +1,3 @@
|
|||
build/*
|
||||
goldberry
|
||||
frontend/node_modules/**
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/code-frame
|
||||
|
||||
> Generate errors that contain a code frame that point to source locations.
|
||||
|
||||
See our website [@babel/code-frame](https://babeljs.io/docs/en/babel-code-frame) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/code-frame
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/code-frame --dev
|
||||
```
|
|
@ -1,167 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.codeFrameColumns = codeFrameColumns;
|
||||
exports.default = _default;
|
||||
|
||||
var _highlight = _interopRequireWildcard(require("@babel/highlight"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
let deprecationWarningShown = false;
|
||||
|
||||
function getDefs(chalk) {
|
||||
return {
|
||||
gutter: chalk.grey,
|
||||
marker: chalk.red.bold,
|
||||
message: chalk.red.bold
|
||||
};
|
||||
}
|
||||
|
||||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
||||
|
||||
function getMarkerLines(loc, source, opts) {
|
||||
const startLoc = Object.assign({
|
||||
column: 0,
|
||||
line: -1
|
||||
}, loc.start);
|
||||
const endLoc = Object.assign({}, startLoc, loc.end);
|
||||
const {
|
||||
linesAbove = 2,
|
||||
linesBelow = 3
|
||||
} = opts || {};
|
||||
const startLine = startLoc.line;
|
||||
const startColumn = startLoc.column;
|
||||
const endLine = endLoc.line;
|
||||
const endColumn = endLoc.column;
|
||||
let start = Math.max(startLine - (linesAbove + 1), 0);
|
||||
let end = Math.min(source.length, endLine + linesBelow);
|
||||
|
||||
if (startLine === -1) {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (endLine === -1) {
|
||||
end = source.length;
|
||||
}
|
||||
|
||||
const lineDiff = endLine - startLine;
|
||||
const markerLines = {};
|
||||
|
||||
if (lineDiff) {
|
||||
for (let i = 0; i <= lineDiff; i++) {
|
||||
const lineNumber = i + startLine;
|
||||
|
||||
if (!startColumn) {
|
||||
markerLines[lineNumber] = true;
|
||||
} else if (i === 0) {
|
||||
const sourceLength = source[lineNumber - 1].length;
|
||||
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
||||
} else if (i === lineDiff) {
|
||||
markerLines[lineNumber] = [0, endColumn];
|
||||
} else {
|
||||
const sourceLength = source[lineNumber - i].length;
|
||||
markerLines[lineNumber] = [0, sourceLength];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (startColumn === endColumn) {
|
||||
if (startColumn) {
|
||||
markerLines[startLine] = [startColumn, 0];
|
||||
} else {
|
||||
markerLines[startLine] = true;
|
||||
}
|
||||
} else {
|
||||
markerLines[startLine] = [startColumn, endColumn - startColumn];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
markerLines
|
||||
};
|
||||
}
|
||||
|
||||
function codeFrameColumns(rawLines, loc, opts = {}) {
|
||||
const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
|
||||
const chalk = (0, _highlight.getChalk)(opts);
|
||||
const defs = getDefs(chalk);
|
||||
|
||||
const maybeHighlight = (chalkFn, string) => {
|
||||
return highlighted ? chalkFn(string) : string;
|
||||
};
|
||||
|
||||
const lines = rawLines.split(NEWLINE);
|
||||
const {
|
||||
start,
|
||||
end,
|
||||
markerLines
|
||||
} = getMarkerLines(loc, lines, opts);
|
||||
const hasColumns = loc.start && typeof loc.start.column === "number";
|
||||
const numberMaxWidth = String(end).length;
|
||||
const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;
|
||||
let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
|
||||
const number = start + 1 + index;
|
||||
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
||||
const gutter = ` ${paddedNumber} |`;
|
||||
const hasMarker = markerLines[number];
|
||||
const lastMarkerLine = !markerLines[number + 1];
|
||||
|
||||
if (hasMarker) {
|
||||
let markerLine = "";
|
||||
|
||||
if (Array.isArray(hasMarker)) {
|
||||
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
||||
const numberOfMarkers = hasMarker[1] || 1;
|
||||
markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), " ", markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
|
||||
|
||||
if (lastMarkerLine && opts.message) {
|
||||
markerLine += " " + maybeHighlight(defs.message, opts.message);
|
||||
}
|
||||
}
|
||||
|
||||
return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
||||
} else {
|
||||
return ` ${maybeHighlight(defs.gutter, gutter)}${line.length > 0 ? ` ${line}` : ""}`;
|
||||
}
|
||||
}).join("\n");
|
||||
|
||||
if (opts.message && !hasColumns) {
|
||||
frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
|
||||
}
|
||||
|
||||
if (highlighted) {
|
||||
return chalk.reset(frame);
|
||||
} else {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
function _default(rawLines, lineNumber, colNumber, opts = {}) {
|
||||
if (!deprecationWarningShown) {
|
||||
deprecationWarningShown = true;
|
||||
const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
|
||||
|
||||
if (process.emitWarning) {
|
||||
process.emitWarning(message, "DeprecationWarning");
|
||||
} else {
|
||||
const deprecationError = new Error(message);
|
||||
deprecationError.name = "DeprecationWarning";
|
||||
console.warn(new Error(message));
|
||||
}
|
||||
}
|
||||
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
const location = {
|
||||
start: {
|
||||
column: colNumber,
|
||||
line: lineNumber
|
||||
}
|
||||
};
|
||||
return codeFrameColumns(rawLines, location, opts);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
{
|
||||
"name": "@babel/code-frame",
|
||||
"version": "7.12.13",
|
||||
"description": "Generate errors that contain a code frame that point to source locations.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-code-frame",
|
||||
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-code-frame"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/highlight": "^7.12.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^2.0.0",
|
||||
"chalk": "^2.0.0",
|
||||
"strip-ansi": "^4.0.0"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/generator
|
||||
|
||||
> Turns an AST into code.
|
||||
|
||||
See our website [@babel/generator](https://babeljs.io/docs/en/babel-generator) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20generator%22+is%3Aopen) associated with this package.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/generator
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/generator --dev
|
||||
```
|
|
@ -1,259 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
const SPACES_RE = /^[ \t]+$/;
|
||||
|
||||
class Buffer {
|
||||
constructor(map) {
|
||||
this._map = null;
|
||||
this._buf = [];
|
||||
this._last = "";
|
||||
this._queue = [];
|
||||
this._position = {
|
||||
line: 1,
|
||||
column: 0
|
||||
};
|
||||
this._sourcePosition = {
|
||||
identifierName: null,
|
||||
line: null,
|
||||
column: null,
|
||||
filename: null
|
||||
};
|
||||
this._disallowedPop = null;
|
||||
this._map = map;
|
||||
}
|
||||
|
||||
get() {
|
||||
this._flush();
|
||||
|
||||
const map = this._map;
|
||||
const result = {
|
||||
code: this._buf.join("").trimRight(),
|
||||
map: null,
|
||||
rawMappings: map == null ? void 0 : map.getRawMappings()
|
||||
};
|
||||
|
||||
if (map) {
|
||||
Object.defineProperty(result, "map", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
|
||||
get() {
|
||||
return this.map = map.get();
|
||||
},
|
||||
|
||||
set(value) {
|
||||
Object.defineProperty(this, "map", {
|
||||
value,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
append(str) {
|
||||
this._flush();
|
||||
|
||||
const {
|
||||
line,
|
||||
column,
|
||||
filename,
|
||||
identifierName,
|
||||
force
|
||||
} = this._sourcePosition;
|
||||
|
||||
this._append(str, line, column, identifierName, filename, force);
|
||||
}
|
||||
|
||||
queue(str) {
|
||||
if (str === "\n") {
|
||||
while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) {
|
||||
this._queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
line,
|
||||
column,
|
||||
filename,
|
||||
identifierName,
|
||||
force
|
||||
} = this._sourcePosition;
|
||||
|
||||
this._queue.unshift([str, line, column, identifierName, filename, force]);
|
||||
}
|
||||
|
||||
_flush() {
|
||||
let item;
|
||||
|
||||
while (item = this._queue.pop()) {
|
||||
this._append(...item);
|
||||
}
|
||||
}
|
||||
|
||||
_append(str, line, column, identifierName, filename, force) {
|
||||
this._buf.push(str);
|
||||
|
||||
this._last = str[str.length - 1];
|
||||
let i = str.indexOf("\n");
|
||||
let last = 0;
|
||||
|
||||
if (i !== 0) {
|
||||
this._mark(line, column, identifierName, filename, force);
|
||||
}
|
||||
|
||||
while (i !== -1) {
|
||||
this._position.line++;
|
||||
this._position.column = 0;
|
||||
last = i + 1;
|
||||
|
||||
if (last < str.length) {
|
||||
this._mark(++line, 0, identifierName, filename, force);
|
||||
}
|
||||
|
||||
i = str.indexOf("\n", last);
|
||||
}
|
||||
|
||||
this._position.column += str.length - last;
|
||||
}
|
||||
|
||||
_mark(line, column, identifierName, filename, force) {
|
||||
var _this$_map;
|
||||
|
||||
(_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force);
|
||||
}
|
||||
|
||||
removeTrailingNewline() {
|
||||
if (this._queue.length > 0 && this._queue[0][0] === "\n") {
|
||||
this._queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
removeLastSemicolon() {
|
||||
if (this._queue.length > 0 && this._queue[0][0] === ";") {
|
||||
this._queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
endsWith(suffix) {
|
||||
if (suffix.length === 1) {
|
||||
let last;
|
||||
|
||||
if (this._queue.length > 0) {
|
||||
const str = this._queue[0][0];
|
||||
last = str[str.length - 1];
|
||||
} else {
|
||||
last = this._last;
|
||||
}
|
||||
|
||||
return last === suffix;
|
||||
}
|
||||
|
||||
const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
|
||||
if (suffix.length <= end.length) {
|
||||
return end.slice(-suffix.length) === suffix;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hasContent() {
|
||||
return this._queue.length > 0 || !!this._last;
|
||||
}
|
||||
|
||||
exactSource(loc, cb) {
|
||||
this.source("start", loc, true);
|
||||
cb();
|
||||
this.source("end", loc);
|
||||
|
||||
this._disallowPop("start", loc);
|
||||
}
|
||||
|
||||
source(prop, loc, force) {
|
||||
if (prop && !loc) return;
|
||||
|
||||
this._normalizePosition(prop, loc, this._sourcePosition, force);
|
||||
}
|
||||
|
||||
withSource(prop, loc, cb) {
|
||||
if (!this._map) return cb();
|
||||
const originalLine = this._sourcePosition.line;
|
||||
const originalColumn = this._sourcePosition.column;
|
||||
const originalFilename = this._sourcePosition.filename;
|
||||
const originalIdentifierName = this._sourcePosition.identifierName;
|
||||
this.source(prop, loc);
|
||||
cb();
|
||||
|
||||
if ((!this._sourcePosition.force || this._sourcePosition.line !== originalLine || this._sourcePosition.column !== originalColumn || this._sourcePosition.filename !== originalFilename) && (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename)) {
|
||||
this._sourcePosition.line = originalLine;
|
||||
this._sourcePosition.column = originalColumn;
|
||||
this._sourcePosition.filename = originalFilename;
|
||||
this._sourcePosition.identifierName = originalIdentifierName;
|
||||
this._sourcePosition.force = false;
|
||||
this._disallowedPop = null;
|
||||
}
|
||||
}
|
||||
|
||||
_disallowPop(prop, loc) {
|
||||
if (prop && !loc) return;
|
||||
this._disallowedPop = this._normalizePosition(prop, loc);
|
||||
}
|
||||
|
||||
_normalizePosition(prop, loc, targetObj, force) {
|
||||
const pos = loc ? loc[prop] : null;
|
||||
|
||||
if (targetObj === undefined) {
|
||||
targetObj = {
|
||||
identifierName: null,
|
||||
line: null,
|
||||
column: null,
|
||||
filename: null,
|
||||
force: false
|
||||
};
|
||||
}
|
||||
|
||||
const origLine = targetObj.line;
|
||||
const origColumn = targetObj.column;
|
||||
const origFilename = targetObj.filename;
|
||||
targetObj.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || null;
|
||||
targetObj.line = pos == null ? void 0 : pos.line;
|
||||
targetObj.column = pos == null ? void 0 : pos.column;
|
||||
targetObj.filename = loc == null ? void 0 : loc.filename;
|
||||
|
||||
if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) {
|
||||
targetObj.force = force;
|
||||
}
|
||||
|
||||
return targetObj;
|
||||
}
|
||||
|
||||
getCurrentColumn() {
|
||||
const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
|
||||
const lastIndex = extra.lastIndexOf("\n");
|
||||
return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex;
|
||||
}
|
||||
|
||||
getCurrentLine() {
|
||||
const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
|
||||
let count = 0;
|
||||
|
||||
for (let i = 0; i < extra.length; i++) {
|
||||
if (extra[i] === "\n") count++;
|
||||
}
|
||||
|
||||
return this._position.line + count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Buffer;
|
|
@ -1,98 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.File = File;
|
||||
exports.Program = Program;
|
||||
exports.BlockStatement = BlockStatement;
|
||||
exports.Directive = Directive;
|
||||
exports.DirectiveLiteral = DirectiveLiteral;
|
||||
exports.InterpreterDirective = InterpreterDirective;
|
||||
exports.Placeholder = Placeholder;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function File(node) {
|
||||
if (node.program) {
|
||||
this.print(node.program.interpreter, node);
|
||||
}
|
||||
|
||||
this.print(node.program, node);
|
||||
}
|
||||
|
||||
function Program(node) {
|
||||
this.printInnerComments(node, false);
|
||||
this.printSequence(node.directives, node);
|
||||
if (node.directives && node.directives.length) this.newline();
|
||||
this.printSequence(node.body, node);
|
||||
}
|
||||
|
||||
function BlockStatement(node) {
|
||||
var _node$directives;
|
||||
|
||||
this.token("{");
|
||||
this.printInnerComments(node);
|
||||
const hasDirectives = (_node$directives = node.directives) == null ? void 0 : _node$directives.length;
|
||||
|
||||
if (node.body.length || hasDirectives) {
|
||||
this.newline();
|
||||
this.printSequence(node.directives, node, {
|
||||
indent: true
|
||||
});
|
||||
if (hasDirectives) this.newline();
|
||||
this.printSequence(node.body, node, {
|
||||
indent: true
|
||||
});
|
||||
this.removeTrailingNewline();
|
||||
this.source("end", node.loc);
|
||||
if (!this.endsWith("\n")) this.newline();
|
||||
this.rightBrace();
|
||||
} else {
|
||||
this.source("end", node.loc);
|
||||
this.token("}");
|
||||
}
|
||||
}
|
||||
|
||||
function Directive(node) {
|
||||
this.print(node.value, node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
const unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/;
|
||||
const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
|
||||
|
||||
function DirectiveLiteral(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
|
||||
if (raw != null) {
|
||||
this.token(raw);
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
value
|
||||
} = node;
|
||||
|
||||
if (!unescapedDoubleQuoteRE.test(value)) {
|
||||
this.token(`"${value}"`);
|
||||
} else if (!unescapedSingleQuoteRE.test(value)) {
|
||||
this.token(`'${value}'`);
|
||||
} else {
|
||||
throw new Error("Malformed AST: it is not possible to print a directive containing" + " both unescaped single and double quotes.");
|
||||
}
|
||||
}
|
||||
|
||||
function InterpreterDirective(node) {
|
||||
this.token(`#!${node.value}\n`);
|
||||
}
|
||||
|
||||
function Placeholder(node) {
|
||||
this.token("%%");
|
||||
this.print(node.name);
|
||||
this.token("%%");
|
||||
|
||||
if (node.expectedNode === "Statement") {
|
||||
this.semicolon();
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
|
||||
exports.ClassBody = ClassBody;
|
||||
exports.ClassProperty = ClassProperty;
|
||||
exports.ClassPrivateProperty = ClassPrivateProperty;
|
||||
exports.ClassMethod = ClassMethod;
|
||||
exports.ClassPrivateMethod = ClassPrivateMethod;
|
||||
exports._classMethodHead = _classMethodHead;
|
||||
exports.StaticBlock = StaticBlock;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function ClassDeclaration(node, parent) {
|
||||
if (!this.format.decoratorsBeforeExport || !t.isExportDefaultDeclaration(parent) && !t.isExportNamedDeclaration(parent)) {
|
||||
this.printJoin(node.decorators, node);
|
||||
}
|
||||
|
||||
if (node.declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.abstract) {
|
||||
this.word("abstract");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("class");
|
||||
|
||||
if (node.id) {
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.superClass) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.print(node.superClass, node);
|
||||
this.print(node.superTypeParameters, node);
|
||||
}
|
||||
|
||||
if (node.implements) {
|
||||
this.space();
|
||||
this.word("implements");
|
||||
this.space();
|
||||
this.printList(node.implements, node);
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function ClassBody(node) {
|
||||
this.token("{");
|
||||
this.printInnerComments(node);
|
||||
|
||||
if (node.body.length === 0) {
|
||||
this.token("}");
|
||||
} else {
|
||||
this.newline();
|
||||
this.indent();
|
||||
this.printSequence(node.body, node);
|
||||
this.dedent();
|
||||
if (!this.endsWith("\n")) this.newline();
|
||||
this.rightBrace();
|
||||
}
|
||||
}
|
||||
|
||||
function ClassProperty(node) {
|
||||
this.printJoin(node.decorators, node);
|
||||
this.source("end", node.key.loc);
|
||||
this.tsPrintClassMemberModifiers(node, true);
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
} else {
|
||||
this._variance(node);
|
||||
|
||||
this.print(node.key, node);
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
}
|
||||
|
||||
if (node.definite) {
|
||||
this.token("!");
|
||||
}
|
||||
|
||||
this.print(node.typeAnnotation, node);
|
||||
|
||||
if (node.value) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function ClassPrivateProperty(node) {
|
||||
this.printJoin(node.decorators, node);
|
||||
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
this.print(node.typeAnnotation, node);
|
||||
|
||||
if (node.value) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function ClassMethod(node) {
|
||||
this._classMethodHead(node);
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function ClassPrivateMethod(node) {
|
||||
this._classMethodHead(node);
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function _classMethodHead(node) {
|
||||
this.printJoin(node.decorators, node);
|
||||
this.source("end", node.key.loc);
|
||||
this.tsPrintClassMemberModifiers(node, false);
|
||||
|
||||
this._methodHead(node);
|
||||
}
|
||||
|
||||
function StaticBlock(node) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
this.token("{");
|
||||
|
||||
if (node.body.length === 0) {
|
||||
this.token("}");
|
||||
} else {
|
||||
this.newline();
|
||||
this.printSequence(node.body, node, {
|
||||
indent: true
|
||||
});
|
||||
this.rightBrace();
|
||||
}
|
||||
}
|
|
@ -1,310 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.UnaryExpression = UnaryExpression;
|
||||
exports.DoExpression = DoExpression;
|
||||
exports.ParenthesizedExpression = ParenthesizedExpression;
|
||||
exports.UpdateExpression = UpdateExpression;
|
||||
exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.NewExpression = NewExpression;
|
||||
exports.SequenceExpression = SequenceExpression;
|
||||
exports.ThisExpression = ThisExpression;
|
||||
exports.Super = Super;
|
||||
exports.Decorator = Decorator;
|
||||
exports.OptionalMemberExpression = OptionalMemberExpression;
|
||||
exports.OptionalCallExpression = OptionalCallExpression;
|
||||
exports.CallExpression = CallExpression;
|
||||
exports.Import = Import;
|
||||
exports.EmptyStatement = EmptyStatement;
|
||||
exports.ExpressionStatement = ExpressionStatement;
|
||||
exports.AssignmentPattern = AssignmentPattern;
|
||||
exports.LogicalExpression = exports.BinaryExpression = exports.AssignmentExpression = AssignmentExpression;
|
||||
exports.BindExpression = BindExpression;
|
||||
exports.MemberExpression = MemberExpression;
|
||||
exports.MetaProperty = MetaProperty;
|
||||
exports.PrivateName = PrivateName;
|
||||
exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier;
|
||||
exports.ModuleExpression = ModuleExpression;
|
||||
exports.AwaitExpression = exports.YieldExpression = void 0;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var n = require("../node");
|
||||
|
||||
function UnaryExpression(node) {
|
||||
if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof" || node.operator === "throw") {
|
||||
this.word(node.operator);
|
||||
this.space();
|
||||
} else {
|
||||
this.token(node.operator);
|
||||
}
|
||||
|
||||
this.print(node.argument, node);
|
||||
}
|
||||
|
||||
function DoExpression(node) {
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("do");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function ParenthesizedExpression(node) {
|
||||
this.token("(");
|
||||
this.print(node.expression, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function UpdateExpression(node) {
|
||||
if (node.prefix) {
|
||||
this.token(node.operator);
|
||||
this.print(node.argument, node);
|
||||
} else {
|
||||
this.startTerminatorless(true);
|
||||
this.print(node.argument, node);
|
||||
this.endTerminatorless();
|
||||
this.token(node.operator);
|
||||
}
|
||||
}
|
||||
|
||||
function ConditionalExpression(node) {
|
||||
this.print(node.test, node);
|
||||
this.space();
|
||||
this.token("?");
|
||||
this.space();
|
||||
this.print(node.consequent, node);
|
||||
this.space();
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.alternate, node);
|
||||
}
|
||||
|
||||
function NewExpression(node, parent) {
|
||||
this.word("new");
|
||||
this.space();
|
||||
this.print(node.callee, node);
|
||||
|
||||
if (this.format.minified && node.arguments.length === 0 && !node.optional && !t.isCallExpression(parent, {
|
||||
callee: node
|
||||
}) && !t.isMemberExpression(parent) && !t.isNewExpression(parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.print(node.typeArguments, node);
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function SequenceExpression(node) {
|
||||
this.printList(node.expressions, node);
|
||||
}
|
||||
|
||||
function ThisExpression() {
|
||||
this.word("this");
|
||||
}
|
||||
|
||||
function Super() {
|
||||
this.word("super");
|
||||
}
|
||||
|
||||
function Decorator(node) {
|
||||
this.token("@");
|
||||
this.print(node.expression, node);
|
||||
this.newline();
|
||||
}
|
||||
|
||||
function OptionalMemberExpression(node) {
|
||||
this.print(node.object, node);
|
||||
|
||||
if (!node.computed && t.isMemberExpression(node.property)) {
|
||||
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
||||
}
|
||||
|
||||
let computed = node.computed;
|
||||
|
||||
if (t.isLiteral(node.property) && typeof node.property.value === "number") {
|
||||
computed = true;
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
if (computed) {
|
||||
this.token("[");
|
||||
this.print(node.property, node);
|
||||
this.token("]");
|
||||
} else {
|
||||
if (!node.optional) {
|
||||
this.token(".");
|
||||
}
|
||||
|
||||
this.print(node.property, node);
|
||||
}
|
||||
}
|
||||
|
||||
function OptionalCallExpression(node) {
|
||||
this.print(node.callee, node);
|
||||
this.print(node.typeArguments, node);
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function CallExpression(node) {
|
||||
this.print(node.callee, node);
|
||||
this.print(node.typeArguments, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function Import() {
|
||||
this.word("import");
|
||||
}
|
||||
|
||||
function buildYieldAwait(keyword) {
|
||||
return function (node) {
|
||||
this.word(keyword);
|
||||
|
||||
if (node.delegate) {
|
||||
this.token("*");
|
||||
}
|
||||
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
const terminatorState = this.startTerminatorless();
|
||||
this.print(node.argument, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const YieldExpression = buildYieldAwait("yield");
|
||||
exports.YieldExpression = YieldExpression;
|
||||
const AwaitExpression = buildYieldAwait("await");
|
||||
exports.AwaitExpression = AwaitExpression;
|
||||
|
||||
function EmptyStatement() {
|
||||
this.semicolon(true);
|
||||
}
|
||||
|
||||
function ExpressionStatement(node) {
|
||||
this.print(node.expression, node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function AssignmentPattern(node) {
|
||||
this.print(node.left, node);
|
||||
if (node.left.optional) this.token("?");
|
||||
this.print(node.left.typeAnnotation, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
}
|
||||
|
||||
function AssignmentExpression(node, parent) {
|
||||
const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent);
|
||||
|
||||
if (parens) {
|
||||
this.token("(");
|
||||
}
|
||||
|
||||
this.print(node.left, node);
|
||||
this.space();
|
||||
|
||||
if (node.operator === "in" || node.operator === "instanceof") {
|
||||
this.word(node.operator);
|
||||
} else {
|
||||
this.token(node.operator);
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
|
||||
if (parens) {
|
||||
this.token(")");
|
||||
}
|
||||
}
|
||||
|
||||
function BindExpression(node) {
|
||||
this.print(node.object, node);
|
||||
this.token("::");
|
||||
this.print(node.callee, node);
|
||||
}
|
||||
|
||||
function MemberExpression(node) {
|
||||
this.print(node.object, node);
|
||||
|
||||
if (!node.computed && t.isMemberExpression(node.property)) {
|
||||
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
||||
}
|
||||
|
||||
let computed = node.computed;
|
||||
|
||||
if (t.isLiteral(node.property) && typeof node.property.value === "number") {
|
||||
computed = true;
|
||||
}
|
||||
|
||||
if (computed) {
|
||||
this.token("[");
|
||||
this.print(node.property, node);
|
||||
this.token("]");
|
||||
} else {
|
||||
this.token(".");
|
||||
this.print(node.property, node);
|
||||
}
|
||||
}
|
||||
|
||||
function MetaProperty(node) {
|
||||
this.print(node.meta, node);
|
||||
this.token(".");
|
||||
this.print(node.property, node);
|
||||
}
|
||||
|
||||
function PrivateName(node) {
|
||||
this.token("#");
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
function V8IntrinsicIdentifier(node) {
|
||||
this.token("%");
|
||||
this.word(node.name);
|
||||
}
|
||||
|
||||
function ModuleExpression(node) {
|
||||
this.word("module");
|
||||
this.space();
|
||||
this.token("{");
|
||||
|
||||
if (node.body.body.length === 0) {
|
||||
this.token("}");
|
||||
} else {
|
||||
this.newline();
|
||||
this.printSequence(node.body.body, node, {
|
||||
indent: true
|
||||
});
|
||||
this.rightBrace();
|
||||
}
|
||||
}
|
|
@ -1,790 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.AnyTypeAnnotation = AnyTypeAnnotation;
|
||||
exports.ArrayTypeAnnotation = ArrayTypeAnnotation;
|
||||
exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
|
||||
exports.BooleanLiteralTypeAnnotation = BooleanLiteralTypeAnnotation;
|
||||
exports.NullLiteralTypeAnnotation = NullLiteralTypeAnnotation;
|
||||
exports.DeclareClass = DeclareClass;
|
||||
exports.DeclareFunction = DeclareFunction;
|
||||
exports.InferredPredicate = InferredPredicate;
|
||||
exports.DeclaredPredicate = DeclaredPredicate;
|
||||
exports.DeclareInterface = DeclareInterface;
|
||||
exports.DeclareModule = DeclareModule;
|
||||
exports.DeclareModuleExports = DeclareModuleExports;
|
||||
exports.DeclareTypeAlias = DeclareTypeAlias;
|
||||
exports.DeclareOpaqueType = DeclareOpaqueType;
|
||||
exports.DeclareVariable = DeclareVariable;
|
||||
exports.DeclareExportDeclaration = DeclareExportDeclaration;
|
||||
exports.DeclareExportAllDeclaration = DeclareExportAllDeclaration;
|
||||
exports.EnumDeclaration = EnumDeclaration;
|
||||
exports.EnumBooleanBody = EnumBooleanBody;
|
||||
exports.EnumNumberBody = EnumNumberBody;
|
||||
exports.EnumStringBody = EnumStringBody;
|
||||
exports.EnumSymbolBody = EnumSymbolBody;
|
||||
exports.EnumDefaultedMember = EnumDefaultedMember;
|
||||
exports.EnumBooleanMember = EnumBooleanMember;
|
||||
exports.EnumNumberMember = EnumNumberMember;
|
||||
exports.EnumStringMember = EnumStringMember;
|
||||
exports.ExistsTypeAnnotation = ExistsTypeAnnotation;
|
||||
exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
||||
exports.FunctionTypeParam = FunctionTypeParam;
|
||||
exports.GenericTypeAnnotation = exports.ClassImplements = exports.InterfaceExtends = InterfaceExtends;
|
||||
exports._interfaceish = _interfaceish;
|
||||
exports._variance = _variance;
|
||||
exports.InterfaceDeclaration = InterfaceDeclaration;
|
||||
exports.InterfaceTypeAnnotation = InterfaceTypeAnnotation;
|
||||
exports.IntersectionTypeAnnotation = IntersectionTypeAnnotation;
|
||||
exports.MixedTypeAnnotation = MixedTypeAnnotation;
|
||||
exports.EmptyTypeAnnotation = EmptyTypeAnnotation;
|
||||
exports.NullableTypeAnnotation = NullableTypeAnnotation;
|
||||
exports.NumberTypeAnnotation = NumberTypeAnnotation;
|
||||
exports.StringTypeAnnotation = StringTypeAnnotation;
|
||||
exports.ThisTypeAnnotation = ThisTypeAnnotation;
|
||||
exports.TupleTypeAnnotation = TupleTypeAnnotation;
|
||||
exports.TypeofTypeAnnotation = TypeofTypeAnnotation;
|
||||
exports.TypeAlias = TypeAlias;
|
||||
exports.TypeAnnotation = TypeAnnotation;
|
||||
exports.TypeParameterDeclaration = exports.TypeParameterInstantiation = TypeParameterInstantiation;
|
||||
exports.TypeParameter = TypeParameter;
|
||||
exports.OpaqueType = OpaqueType;
|
||||
exports.ObjectTypeAnnotation = ObjectTypeAnnotation;
|
||||
exports.ObjectTypeInternalSlot = ObjectTypeInternalSlot;
|
||||
exports.ObjectTypeCallProperty = ObjectTypeCallProperty;
|
||||
exports.ObjectTypeIndexer = ObjectTypeIndexer;
|
||||
exports.ObjectTypeProperty = ObjectTypeProperty;
|
||||
exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
|
||||
exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
|
||||
exports.SymbolTypeAnnotation = SymbolTypeAnnotation;
|
||||
exports.UnionTypeAnnotation = UnionTypeAnnotation;
|
||||
exports.TypeCastExpression = TypeCastExpression;
|
||||
exports.Variance = Variance;
|
||||
exports.VoidTypeAnnotation = VoidTypeAnnotation;
|
||||
exports.IndexedAccessType = IndexedAccessType;
|
||||
exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
|
||||
Object.defineProperty(exports, "NumberLiteralTypeAnnotation", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _types2.NumericLiteral;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "StringLiteralTypeAnnotation", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _types2.StringLiteral;
|
||||
}
|
||||
});
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _modules = require("./modules");
|
||||
|
||||
var _types2 = require("./types");
|
||||
|
||||
function AnyTypeAnnotation() {
|
||||
this.word("any");
|
||||
}
|
||||
|
||||
function ArrayTypeAnnotation(node) {
|
||||
this.print(node.elementType, node);
|
||||
this.token("[");
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
function BooleanTypeAnnotation() {
|
||||
this.word("boolean");
|
||||
}
|
||||
|
||||
function BooleanLiteralTypeAnnotation(node) {
|
||||
this.word(node.value ? "true" : "false");
|
||||
}
|
||||
|
||||
function NullLiteralTypeAnnotation() {
|
||||
this.word("null");
|
||||
}
|
||||
|
||||
function DeclareClass(node, parent) {
|
||||
if (!t.isDeclareExportDeclaration(parent)) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("class");
|
||||
this.space();
|
||||
|
||||
this._interfaceish(node);
|
||||
}
|
||||
|
||||
function DeclareFunction(node, parent) {
|
||||
if (!t.isDeclareExportDeclaration(parent)) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("function");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.id.typeAnnotation.typeAnnotation, node);
|
||||
|
||||
if (node.predicate) {
|
||||
this.space();
|
||||
this.print(node.predicate, node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function InferredPredicate() {
|
||||
this.token("%");
|
||||
this.word("checks");
|
||||
}
|
||||
|
||||
function DeclaredPredicate(node) {
|
||||
this.token("%");
|
||||
this.word("checks");
|
||||
this.token("(");
|
||||
this.print(node.value, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function DeclareInterface(node) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.InterfaceDeclaration(node);
|
||||
}
|
||||
|
||||
function DeclareModule(node) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.word("module");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function DeclareModuleExports(node) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.word("module");
|
||||
this.token(".");
|
||||
this.word("exports");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function DeclareTypeAlias(node) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.TypeAlias(node);
|
||||
}
|
||||
|
||||
function DeclareOpaqueType(node, parent) {
|
||||
if (!t.isDeclareExportDeclaration(parent)) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.OpaqueType(node);
|
||||
}
|
||||
|
||||
function DeclareVariable(node, parent) {
|
||||
if (!t.isDeclareExportDeclaration(parent)) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("var");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.id.typeAnnotation, node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function DeclareExportDeclaration(node) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.word("export");
|
||||
this.space();
|
||||
|
||||
if (node.default) {
|
||||
this.word("default");
|
||||
this.space();
|
||||
}
|
||||
|
||||
FlowExportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
function DeclareExportAllDeclaration() {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
|
||||
_modules.ExportAllDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
function EnumDeclaration(node) {
|
||||
const {
|
||||
id,
|
||||
body
|
||||
} = node;
|
||||
this.word("enum");
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.print(body, node);
|
||||
}
|
||||
|
||||
function enumExplicitType(context, name, hasExplicitType) {
|
||||
if (hasExplicitType) {
|
||||
context.space();
|
||||
context.word("of");
|
||||
context.space();
|
||||
context.word(name);
|
||||
}
|
||||
|
||||
context.space();
|
||||
}
|
||||
|
||||
function enumBody(context, node) {
|
||||
const {
|
||||
members
|
||||
} = node;
|
||||
context.token("{");
|
||||
context.indent();
|
||||
context.newline();
|
||||
|
||||
for (const member of members) {
|
||||
context.print(member, node);
|
||||
context.newline();
|
||||
}
|
||||
|
||||
if (node.hasUnknownMembers) {
|
||||
context.token("...");
|
||||
context.newline();
|
||||
}
|
||||
|
||||
context.dedent();
|
||||
context.token("}");
|
||||
}
|
||||
|
||||
function EnumBooleanBody(node) {
|
||||
const {
|
||||
explicitType
|
||||
} = node;
|
||||
enumExplicitType(this, "boolean", explicitType);
|
||||
enumBody(this, node);
|
||||
}
|
||||
|
||||
function EnumNumberBody(node) {
|
||||
const {
|
||||
explicitType
|
||||
} = node;
|
||||
enumExplicitType(this, "number", explicitType);
|
||||
enumBody(this, node);
|
||||
}
|
||||
|
||||
function EnumStringBody(node) {
|
||||
const {
|
||||
explicitType
|
||||
} = node;
|
||||
enumExplicitType(this, "string", explicitType);
|
||||
enumBody(this, node);
|
||||
}
|
||||
|
||||
function EnumSymbolBody(node) {
|
||||
enumExplicitType(this, "symbol", true);
|
||||
enumBody(this, node);
|
||||
}
|
||||
|
||||
function EnumDefaultedMember(node) {
|
||||
const {
|
||||
id
|
||||
} = node;
|
||||
this.print(id, node);
|
||||
this.token(",");
|
||||
}
|
||||
|
||||
function enumInitializedMember(context, node) {
|
||||
const {
|
||||
id,
|
||||
init
|
||||
} = node;
|
||||
context.print(id, node);
|
||||
context.space();
|
||||
context.token("=");
|
||||
context.space();
|
||||
context.print(init, node);
|
||||
context.token(",");
|
||||
}
|
||||
|
||||
function EnumBooleanMember(node) {
|
||||
enumInitializedMember(this, node);
|
||||
}
|
||||
|
||||
function EnumNumberMember(node) {
|
||||
enumInitializedMember(this, node);
|
||||
}
|
||||
|
||||
function EnumStringMember(node) {
|
||||
enumInitializedMember(this, node);
|
||||
}
|
||||
|
||||
function FlowExportDeclaration(node) {
|
||||
if (node.declaration) {
|
||||
const declar = node.declaration;
|
||||
this.print(declar, node);
|
||||
if (!t.isStatement(declar)) this.semicolon();
|
||||
} else {
|
||||
this.token("{");
|
||||
|
||||
if (node.specifiers.length) {
|
||||
this.space();
|
||||
this.printList(node.specifiers, node);
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
|
||||
if (node.source) {
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.space();
|
||||
this.print(node.source, node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
}
|
||||
|
||||
function ExistsTypeAnnotation() {
|
||||
this.token("*");
|
||||
}
|
||||
|
||||
function FunctionTypeAnnotation(node, parent) {
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
|
||||
if (node.this) {
|
||||
this.word("this");
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.this.typeAnnotation, node);
|
||||
|
||||
if (node.params.length || node.rest) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
|
||||
this.printList(node.params, node);
|
||||
|
||||
if (node.rest) {
|
||||
if (node.params.length) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("...");
|
||||
this.print(node.rest, node);
|
||||
}
|
||||
|
||||
this.token(")");
|
||||
|
||||
if (parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction" || parent.type === "ObjectTypeProperty" && parent.method) {
|
||||
this.token(":");
|
||||
} else {
|
||||
this.space();
|
||||
this.token("=>");
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(node.returnType, node);
|
||||
}
|
||||
|
||||
function FunctionTypeParam(node) {
|
||||
this.print(node.name, node);
|
||||
if (node.optional) this.token("?");
|
||||
|
||||
if (node.name) {
|
||||
this.token(":");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function InterfaceExtends(node) {
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
}
|
||||
|
||||
function _interfaceish(node) {
|
||||
var _node$extends;
|
||||
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if ((_node$extends = node.extends) != null && _node$extends.length) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.printList(node.extends, node);
|
||||
}
|
||||
|
||||
if (node.mixins && node.mixins.length) {
|
||||
this.space();
|
||||
this.word("mixins");
|
||||
this.space();
|
||||
this.printList(node.mixins, node);
|
||||
}
|
||||
|
||||
if (node.implements && node.implements.length) {
|
||||
this.space();
|
||||
this.word("implements");
|
||||
this.space();
|
||||
this.printList(node.implements, node);
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function _variance(node) {
|
||||
if (node.variance) {
|
||||
if (node.variance.kind === "plus") {
|
||||
this.token("+");
|
||||
} else if (node.variance.kind === "minus") {
|
||||
this.token("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function InterfaceDeclaration(node) {
|
||||
this.word("interface");
|
||||
this.space();
|
||||
|
||||
this._interfaceish(node);
|
||||
}
|
||||
|
||||
function andSeparator() {
|
||||
this.space();
|
||||
this.token("&");
|
||||
this.space();
|
||||
}
|
||||
|
||||
function InterfaceTypeAnnotation(node) {
|
||||
this.word("interface");
|
||||
|
||||
if (node.extends && node.extends.length) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.printList(node.extends, node);
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function IntersectionTypeAnnotation(node) {
|
||||
this.printJoin(node.types, node, {
|
||||
separator: andSeparator
|
||||
});
|
||||
}
|
||||
|
||||
function MixedTypeAnnotation() {
|
||||
this.word("mixed");
|
||||
}
|
||||
|
||||
function EmptyTypeAnnotation() {
|
||||
this.word("empty");
|
||||
}
|
||||
|
||||
function NullableTypeAnnotation(node) {
|
||||
this.token("?");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function NumberTypeAnnotation() {
|
||||
this.word("number");
|
||||
}
|
||||
|
||||
function StringTypeAnnotation() {
|
||||
this.word("string");
|
||||
}
|
||||
|
||||
function ThisTypeAnnotation() {
|
||||
this.word("this");
|
||||
}
|
||||
|
||||
function TupleTypeAnnotation(node) {
|
||||
this.token("[");
|
||||
this.printList(node.types, node);
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
function TypeofTypeAnnotation(node) {
|
||||
this.word("typeof");
|
||||
this.space();
|
||||
this.print(node.argument, node);
|
||||
}
|
||||
|
||||
function TypeAlias(node) {
|
||||
this.word("type");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function TypeAnnotation(node) {
|
||||
this.token(":");
|
||||
this.space();
|
||||
if (node.optional) this.token("?");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TypeParameterInstantiation(node) {
|
||||
this.token("<");
|
||||
this.printList(node.params, node, {});
|
||||
this.token(">");
|
||||
}
|
||||
|
||||
function TypeParameter(node) {
|
||||
this._variance(node);
|
||||
|
||||
this.word(node.name);
|
||||
|
||||
if (node.bound) {
|
||||
this.print(node.bound, node);
|
||||
}
|
||||
|
||||
if (node.default) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.default, node);
|
||||
}
|
||||
}
|
||||
|
||||
function OpaqueType(node) {
|
||||
this.word("opaque");
|
||||
this.space();
|
||||
this.word("type");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.supertype) {
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.supertype, node);
|
||||
}
|
||||
|
||||
if (node.impltype) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.impltype, node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function ObjectTypeAnnotation(node) {
|
||||
if (node.exact) {
|
||||
this.token("{|");
|
||||
} else {
|
||||
this.token("{");
|
||||
}
|
||||
|
||||
const props = [...node.properties, ...(node.callProperties || []), ...(node.indexers || []), ...(node.internalSlots || [])];
|
||||
|
||||
if (props.length) {
|
||||
this.space();
|
||||
this.printJoin(props, node, {
|
||||
addNewlines(leading) {
|
||||
if (leading && !props[0]) return 1;
|
||||
},
|
||||
|
||||
indent: true,
|
||||
statement: true,
|
||||
iterator: () => {
|
||||
if (props.length !== 1 || node.inexact) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.inexact) {
|
||||
this.indent();
|
||||
this.token("...");
|
||||
|
||||
if (props.length) {
|
||||
this.newline();
|
||||
}
|
||||
|
||||
this.dedent();
|
||||
}
|
||||
|
||||
if (node.exact) {
|
||||
this.token("|}");
|
||||
} else {
|
||||
this.token("}");
|
||||
}
|
||||
}
|
||||
|
||||
function ObjectTypeInternalSlot(node) {
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.token("[");
|
||||
this.print(node.id, node);
|
||||
this.token("]");
|
||||
this.token("]");
|
||||
if (node.optional) this.token("?");
|
||||
|
||||
if (!node.method) {
|
||||
this.token(":");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
function ObjectTypeCallProperty(node) {
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
function ObjectTypeIndexer(node) {
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._variance(node);
|
||||
|
||||
this.token("[");
|
||||
|
||||
if (node.id) {
|
||||
this.print(node.id, node);
|
||||
this.token(":");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
function ObjectTypeProperty(node) {
|
||||
if (node.proto) {
|
||||
this.word("proto");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.kind === "get" || node.kind === "set") {
|
||||
this.word(node.kind);
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._variance(node);
|
||||
|
||||
this.print(node.key, node);
|
||||
if (node.optional) this.token("?");
|
||||
|
||||
if (!node.method) {
|
||||
this.token(":");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
function ObjectTypeSpreadProperty(node) {
|
||||
this.token("...");
|
||||
this.print(node.argument, node);
|
||||
}
|
||||
|
||||
function QualifiedTypeIdentifier(node) {
|
||||
this.print(node.qualification, node);
|
||||
this.token(".");
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
function SymbolTypeAnnotation() {
|
||||
this.word("symbol");
|
||||
}
|
||||
|
||||
function orSeparator() {
|
||||
this.space();
|
||||
this.token("|");
|
||||
this.space();
|
||||
}
|
||||
|
||||
function UnionTypeAnnotation(node) {
|
||||
this.printJoin(node.types, node, {
|
||||
separator: orSeparator
|
||||
});
|
||||
}
|
||||
|
||||
function TypeCastExpression(node) {
|
||||
this.token("(");
|
||||
this.print(node.expression, node);
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function Variance(node) {
|
||||
if (node.kind === "plus") {
|
||||
this.token("+");
|
||||
} else {
|
||||
this.token("-");
|
||||
}
|
||||
}
|
||||
|
||||
function VoidTypeAnnotation() {
|
||||
this.word("void");
|
||||
}
|
||||
|
||||
function IndexedAccessType(node) {
|
||||
this.print(node.objectType, node);
|
||||
this.token("[");
|
||||
this.print(node.indexType, node);
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
function OptionalIndexedAccessType(node) {
|
||||
this.print(node.objectType, node);
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.print(node.indexType, node);
|
||||
this.token("]");
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _templateLiterals = require("./template-literals");
|
||||
|
||||
Object.keys(_templateLiterals).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _templateLiterals[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _templateLiterals[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _expressions = require("./expressions");
|
||||
|
||||
Object.keys(_expressions).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _expressions[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _expressions[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _statements = require("./statements");
|
||||
|
||||
Object.keys(_statements).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _statements[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _statements[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _classes = require("./classes");
|
||||
|
||||
Object.keys(_classes).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _classes[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _classes[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _methods = require("./methods");
|
||||
|
||||
Object.keys(_methods).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _methods[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _methods[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _modules = require("./modules");
|
||||
|
||||
Object.keys(_modules).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _modules[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _modules[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _types = require("./types");
|
||||
|
||||
Object.keys(_types).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _types[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _types[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _flow = require("./flow");
|
||||
|
||||
Object.keys(_flow).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _flow[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _flow[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _base = require("./base");
|
||||
|
||||
Object.keys(_base).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _base[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _base[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _jsx = require("./jsx");
|
||||
|
||||
Object.keys(_jsx).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _jsx[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _jsx[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _typescript = require("./typescript");
|
||||
|
||||
Object.keys(_typescript).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (key in exports && exports[key] === _typescript[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _typescript[key];
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,147 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.JSXAttribute = JSXAttribute;
|
||||
exports.JSXIdentifier = JSXIdentifier;
|
||||
exports.JSXNamespacedName = JSXNamespacedName;
|
||||
exports.JSXMemberExpression = JSXMemberExpression;
|
||||
exports.JSXSpreadAttribute = JSXSpreadAttribute;
|
||||
exports.JSXExpressionContainer = JSXExpressionContainer;
|
||||
exports.JSXSpreadChild = JSXSpreadChild;
|
||||
exports.JSXText = JSXText;
|
||||
exports.JSXElement = JSXElement;
|
||||
exports.JSXOpeningElement = JSXOpeningElement;
|
||||
exports.JSXClosingElement = JSXClosingElement;
|
||||
exports.JSXEmptyExpression = JSXEmptyExpression;
|
||||
exports.JSXFragment = JSXFragment;
|
||||
exports.JSXOpeningFragment = JSXOpeningFragment;
|
||||
exports.JSXClosingFragment = JSXClosingFragment;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function JSXAttribute(node) {
|
||||
this.print(node.name, node);
|
||||
|
||||
if (node.value) {
|
||||
this.token("=");
|
||||
this.print(node.value, node);
|
||||
}
|
||||
}
|
||||
|
||||
function JSXIdentifier(node) {
|
||||
this.word(node.name);
|
||||
}
|
||||
|
||||
function JSXNamespacedName(node) {
|
||||
this.print(node.namespace, node);
|
||||
this.token(":");
|
||||
this.print(node.name, node);
|
||||
}
|
||||
|
||||
function JSXMemberExpression(node) {
|
||||
this.print(node.object, node);
|
||||
this.token(".");
|
||||
this.print(node.property, node);
|
||||
}
|
||||
|
||||
function JSXSpreadAttribute(node) {
|
||||
this.token("{");
|
||||
this.token("...");
|
||||
this.print(node.argument, node);
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
function JSXExpressionContainer(node) {
|
||||
this.token("{");
|
||||
this.print(node.expression, node);
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
function JSXSpreadChild(node) {
|
||||
this.token("{");
|
||||
this.token("...");
|
||||
this.print(node.expression, node);
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
function JSXText(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
|
||||
if (raw != null) {
|
||||
this.token(raw);
|
||||
} else {
|
||||
this.token(node.value);
|
||||
}
|
||||
}
|
||||
|
||||
function JSXElement(node) {
|
||||
const open = node.openingElement;
|
||||
this.print(open, node);
|
||||
if (open.selfClosing) return;
|
||||
this.indent();
|
||||
|
||||
for (const child of node.children) {
|
||||
this.print(child, node);
|
||||
}
|
||||
|
||||
this.dedent();
|
||||
this.print(node.closingElement, node);
|
||||
}
|
||||
|
||||
function spaceSeparator() {
|
||||
this.space();
|
||||
}
|
||||
|
||||
function JSXOpeningElement(node) {
|
||||
this.token("<");
|
||||
this.print(node.name, node);
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.attributes.length > 0) {
|
||||
this.space();
|
||||
this.printJoin(node.attributes, node, {
|
||||
separator: spaceSeparator
|
||||
});
|
||||
}
|
||||
|
||||
if (node.selfClosing) {
|
||||
this.space();
|
||||
this.token("/>");
|
||||
} else {
|
||||
this.token(">");
|
||||
}
|
||||
}
|
||||
|
||||
function JSXClosingElement(node) {
|
||||
this.token("</");
|
||||
this.print(node.name, node);
|
||||
this.token(">");
|
||||
}
|
||||
|
||||
function JSXEmptyExpression(node) {
|
||||
this.printInnerComments(node);
|
||||
}
|
||||
|
||||
function JSXFragment(node) {
|
||||
this.print(node.openingFragment, node);
|
||||
this.indent();
|
||||
|
||||
for (const child of node.children) {
|
||||
this.print(child, node);
|
||||
}
|
||||
|
||||
this.dedent();
|
||||
this.print(node.closingFragment, node);
|
||||
}
|
||||
|
||||
function JSXOpeningFragment() {
|
||||
this.token("<");
|
||||
this.token(">");
|
||||
}
|
||||
|
||||
function JSXClosingFragment() {
|
||||
this.token("</");
|
||||
this.token(">");
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports._params = _params;
|
||||
exports._parameters = _parameters;
|
||||
exports._param = _param;
|
||||
exports._methodHead = _methodHead;
|
||||
exports._predicate = _predicate;
|
||||
exports._functionHead = _functionHead;
|
||||
exports.FunctionDeclaration = exports.FunctionExpression = FunctionExpression;
|
||||
exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function _params(node) {
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
|
||||
this._parameters(node.params, node);
|
||||
|
||||
this.token(")");
|
||||
this.print(node.returnType, node);
|
||||
}
|
||||
|
||||
function _parameters(parameters, parent) {
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
this._param(parameters[i], parent);
|
||||
|
||||
if (i < parameters.length - 1) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _param(parameter, parent) {
|
||||
this.printJoin(parameter.decorators, parameter);
|
||||
this.print(parameter, parent);
|
||||
if (parameter.optional) this.token("?");
|
||||
this.print(parameter.typeAnnotation, parameter);
|
||||
}
|
||||
|
||||
function _methodHead(node) {
|
||||
const kind = node.kind;
|
||||
const key = node.key;
|
||||
|
||||
if (kind === "get" || kind === "set") {
|
||||
this.word(kind);
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.async) {
|
||||
this._catchUp("start", key.loc);
|
||||
|
||||
this.word("async");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (kind === "method" || kind === "init") {
|
||||
if (node.generator) {
|
||||
this.token("*");
|
||||
}
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.print(key, node);
|
||||
this.token("]");
|
||||
} else {
|
||||
this.print(key, node);
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
}
|
||||
|
||||
this._params(node);
|
||||
}
|
||||
|
||||
function _predicate(node) {
|
||||
if (node.predicate) {
|
||||
if (!node.returnType) {
|
||||
this.token(":");
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(node.predicate, node);
|
||||
}
|
||||
}
|
||||
|
||||
function _functionHead(node) {
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("function");
|
||||
if (node.generator) this.token("*");
|
||||
this.space();
|
||||
|
||||
if (node.id) {
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
this._params(node);
|
||||
|
||||
this._predicate(node);
|
||||
}
|
||||
|
||||
function FunctionExpression(node) {
|
||||
this._functionHead(node);
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function ArrowFunctionExpression(node) {
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
this.space();
|
||||
}
|
||||
|
||||
const firstParam = node.params[0];
|
||||
|
||||
if (!this.format.retainLines && !this.format.auxiliaryCommentBefore && !this.format.auxiliaryCommentAfter && node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypesOrComments(node, firstParam)) {
|
||||
this.print(firstParam, node);
|
||||
} else {
|
||||
this._params(node);
|
||||
}
|
||||
|
||||
this._predicate(node);
|
||||
|
||||
this.space();
|
||||
this.token("=>");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function hasTypesOrComments(node, param) {
|
||||
var _param$leadingComment, _param$trailingCommen;
|
||||
|
||||
return !!(node.typeParameters || node.returnType || node.predicate || param.typeAnnotation || param.optional || (_param$leadingComment = param.leadingComments) != null && _param$leadingComment.length || (_param$trailingCommen = param.trailingComments) != null && _param$trailingCommen.length);
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ImportSpecifier = ImportSpecifier;
|
||||
exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
|
||||
exports.ExportDefaultSpecifier = ExportDefaultSpecifier;
|
||||
exports.ExportSpecifier = ExportSpecifier;
|
||||
exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier;
|
||||
exports.ExportAllDeclaration = ExportAllDeclaration;
|
||||
exports.ExportNamedDeclaration = ExportNamedDeclaration;
|
||||
exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
|
||||
exports.ImportDeclaration = ImportDeclaration;
|
||||
exports.ImportAttribute = ImportAttribute;
|
||||
exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function ImportSpecifier(node) {
|
||||
if (node.importKind === "type" || node.importKind === "typeof") {
|
||||
this.word(node.importKind);
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.imported, node);
|
||||
|
||||
if (node.local && node.local.name !== node.imported.name) {
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.print(node.local, node);
|
||||
}
|
||||
}
|
||||
|
||||
function ImportDefaultSpecifier(node) {
|
||||
this.print(node.local, node);
|
||||
}
|
||||
|
||||
function ExportDefaultSpecifier(node) {
|
||||
this.print(node.exported, node);
|
||||
}
|
||||
|
||||
function ExportSpecifier(node) {
|
||||
this.print(node.local, node);
|
||||
|
||||
if (node.exported && node.local.name !== node.exported.name) {
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.print(node.exported, node);
|
||||
}
|
||||
}
|
||||
|
||||
function ExportNamespaceSpecifier(node) {
|
||||
this.token("*");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.print(node.exported, node);
|
||||
}
|
||||
|
||||
function ExportAllDeclaration(node) {
|
||||
this.word("export");
|
||||
this.space();
|
||||
|
||||
if (node.exportKind === "type") {
|
||||
this.word("type");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("*");
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.space();
|
||||
this.print(node.source, node);
|
||||
this.printAssertions(node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function ExportNamedDeclaration(node) {
|
||||
if (this.format.decoratorsBeforeExport && t.isClassDeclaration(node.declaration)) {
|
||||
this.printJoin(node.declaration.decorators, node);
|
||||
}
|
||||
|
||||
this.word("export");
|
||||
this.space();
|
||||
ExportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
function ExportDefaultDeclaration(node) {
|
||||
if (this.format.decoratorsBeforeExport && t.isClassDeclaration(node.declaration)) {
|
||||
this.printJoin(node.declaration.decorators, node);
|
||||
}
|
||||
|
||||
this.word("export");
|
||||
this.space();
|
||||
this.word("default");
|
||||
this.space();
|
||||
ExportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
function ExportDeclaration(node) {
|
||||
if (node.declaration) {
|
||||
const declar = node.declaration;
|
||||
this.print(declar, node);
|
||||
if (!t.isStatement(declar)) this.semicolon();
|
||||
} else {
|
||||
if (node.exportKind === "type") {
|
||||
this.word("type");
|
||||
this.space();
|
||||
}
|
||||
|
||||
const specifiers = node.specifiers.slice(0);
|
||||
let hasSpecial = false;
|
||||
|
||||
for (;;) {
|
||||
const first = specifiers[0];
|
||||
|
||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||
hasSpecial = true;
|
||||
this.print(specifiers.shift(), node);
|
||||
|
||||
if (specifiers.length) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (specifiers.length || !specifiers.length && !hasSpecial) {
|
||||
this.token("{");
|
||||
|
||||
if (specifiers.length) {
|
||||
this.space();
|
||||
this.printList(specifiers, node);
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.space();
|
||||
this.print(node.source, node);
|
||||
this.printAssertions(node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
}
|
||||
|
||||
function ImportDeclaration(node) {
|
||||
this.word("import");
|
||||
this.space();
|
||||
|
||||
if (node.importKind === "type" || node.importKind === "typeof") {
|
||||
this.word(node.importKind);
|
||||
this.space();
|
||||
}
|
||||
|
||||
const specifiers = node.specifiers.slice(0);
|
||||
|
||||
if (specifiers != null && specifiers.length) {
|
||||
for (;;) {
|
||||
const first = specifiers[0];
|
||||
|
||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||
this.print(specifiers.shift(), node);
|
||||
|
||||
if (specifiers.length) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (specifiers.length) {
|
||||
this.token("{");
|
||||
this.space();
|
||||
this.printList(specifiers, node);
|
||||
this.space();
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.source, node);
|
||||
this.printAssertions(node);
|
||||
{
|
||||
var _node$attributes;
|
||||
|
||||
if ((_node$attributes = node.attributes) != null && _node$attributes.length) {
|
||||
this.space();
|
||||
this.word("with");
|
||||
this.space();
|
||||
this.printList(node.attributes, node);
|
||||
}
|
||||
}
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function ImportAttribute(node) {
|
||||
this.print(node.key);
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.value);
|
||||
}
|
||||
|
||||
function ImportNamespaceSpecifier(node) {
|
||||
this.token("*");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.print(node.local, node);
|
||||
}
|
|
@ -1,314 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.WithStatement = WithStatement;
|
||||
exports.IfStatement = IfStatement;
|
||||
exports.ForStatement = ForStatement;
|
||||
exports.WhileStatement = WhileStatement;
|
||||
exports.DoWhileStatement = DoWhileStatement;
|
||||
exports.LabeledStatement = LabeledStatement;
|
||||
exports.TryStatement = TryStatement;
|
||||
exports.CatchClause = CatchClause;
|
||||
exports.SwitchStatement = SwitchStatement;
|
||||
exports.SwitchCase = SwitchCase;
|
||||
exports.DebuggerStatement = DebuggerStatement;
|
||||
exports.VariableDeclaration = VariableDeclaration;
|
||||
exports.VariableDeclarator = VariableDeclarator;
|
||||
exports.ThrowStatement = exports.BreakStatement = exports.ReturnStatement = exports.ContinueStatement = exports.ForOfStatement = exports.ForInStatement = void 0;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function WithStatement(node) {
|
||||
this.word("with");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.print(node.object, node);
|
||||
this.token(")");
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
function IfStatement(node) {
|
||||
this.word("if");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.print(node.test, node);
|
||||
this.token(")");
|
||||
this.space();
|
||||
const needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent));
|
||||
|
||||
if (needsBlock) {
|
||||
this.token("{");
|
||||
this.newline();
|
||||
this.indent();
|
||||
}
|
||||
|
||||
this.printAndIndentOnComments(node.consequent, node);
|
||||
|
||||
if (needsBlock) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
if (node.alternate) {
|
||||
if (this.endsWith("}")) this.space();
|
||||
this.word("else");
|
||||
this.space();
|
||||
this.printAndIndentOnComments(node.alternate, node);
|
||||
}
|
||||
}
|
||||
|
||||
function getLastStatement(statement) {
|
||||
if (!t.isStatement(statement.body)) return statement;
|
||||
return getLastStatement(statement.body);
|
||||
}
|
||||
|
||||
function ForStatement(node) {
|
||||
this.word("for");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.inForStatementInitCounter++;
|
||||
this.print(node.init, node);
|
||||
this.inForStatementInitCounter--;
|
||||
this.token(";");
|
||||
|
||||
if (node.test) {
|
||||
this.space();
|
||||
this.print(node.test, node);
|
||||
}
|
||||
|
||||
this.token(";");
|
||||
|
||||
if (node.update) {
|
||||
this.space();
|
||||
this.print(node.update, node);
|
||||
}
|
||||
|
||||
this.token(")");
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
function WhileStatement(node) {
|
||||
this.word("while");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.print(node.test, node);
|
||||
this.token(")");
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
const buildForXStatement = function (op) {
|
||||
return function (node) {
|
||||
this.word("for");
|
||||
this.space();
|
||||
|
||||
if (op === "of" && node.await) {
|
||||
this.word("await");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.print(node.left, node);
|
||||
this.space();
|
||||
this.word(op);
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
this.token(")");
|
||||
this.printBlock(node);
|
||||
};
|
||||
};
|
||||
|
||||
const ForInStatement = buildForXStatement("in");
|
||||
exports.ForInStatement = ForInStatement;
|
||||
const ForOfStatement = buildForXStatement("of");
|
||||
exports.ForOfStatement = ForOfStatement;
|
||||
|
||||
function DoWhileStatement(node) {
|
||||
this.word("do");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
this.space();
|
||||
this.word("while");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.print(node.test, node);
|
||||
this.token(")");
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function buildLabelStatement(prefix, key = "label") {
|
||||
return function (node) {
|
||||
this.word(prefix);
|
||||
const label = node[key];
|
||||
|
||||
if (label) {
|
||||
this.space();
|
||||
const isLabel = key == "label";
|
||||
const terminatorState = this.startTerminatorless(isLabel);
|
||||
this.print(label, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
};
|
||||
}
|
||||
|
||||
const ContinueStatement = buildLabelStatement("continue");
|
||||
exports.ContinueStatement = ContinueStatement;
|
||||
const ReturnStatement = buildLabelStatement("return", "argument");
|
||||
exports.ReturnStatement = ReturnStatement;
|
||||
const BreakStatement = buildLabelStatement("break");
|
||||
exports.BreakStatement = BreakStatement;
|
||||
const ThrowStatement = buildLabelStatement("throw", "argument");
|
||||
exports.ThrowStatement = ThrowStatement;
|
||||
|
||||
function LabeledStatement(node) {
|
||||
this.print(node.label, node);
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function TryStatement(node) {
|
||||
this.word("try");
|
||||
this.space();
|
||||
this.print(node.block, node);
|
||||
this.space();
|
||||
|
||||
if (node.handlers) {
|
||||
this.print(node.handlers[0], node);
|
||||
} else {
|
||||
this.print(node.handler, node);
|
||||
}
|
||||
|
||||
if (node.finalizer) {
|
||||
this.space();
|
||||
this.word("finally");
|
||||
this.space();
|
||||
this.print(node.finalizer, node);
|
||||
}
|
||||
}
|
||||
|
||||
function CatchClause(node) {
|
||||
this.word("catch");
|
||||
this.space();
|
||||
|
||||
if (node.param) {
|
||||
this.token("(");
|
||||
this.print(node.param, node);
|
||||
this.print(node.param.typeAnnotation, node);
|
||||
this.token(")");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function SwitchStatement(node) {
|
||||
this.word("switch");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.print(node.discriminant, node);
|
||||
this.token(")");
|
||||
this.space();
|
||||
this.token("{");
|
||||
this.printSequence(node.cases, node, {
|
||||
indent: true,
|
||||
|
||||
addNewlines(leading, cas) {
|
||||
if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
|
||||
}
|
||||
|
||||
});
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
function SwitchCase(node) {
|
||||
if (node.test) {
|
||||
this.word("case");
|
||||
this.space();
|
||||
this.print(node.test, node);
|
||||
this.token(":");
|
||||
} else {
|
||||
this.word("default");
|
||||
this.token(":");
|
||||
}
|
||||
|
||||
if (node.consequent.length) {
|
||||
this.newline();
|
||||
this.printSequence(node.consequent, node, {
|
||||
indent: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function DebuggerStatement() {
|
||||
this.word("debugger");
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function variableDeclarationIndent() {
|
||||
this.token(",");
|
||||
this.newline();
|
||||
if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true);
|
||||
}
|
||||
|
||||
function constDeclarationIndent() {
|
||||
this.token(",");
|
||||
this.newline();
|
||||
if (this.endsWith("\n")) for (let i = 0; i < 6; i++) this.space(true);
|
||||
}
|
||||
|
||||
function VariableDeclaration(node, parent) {
|
||||
if (node.declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word(node.kind);
|
||||
this.space();
|
||||
let hasInits = false;
|
||||
|
||||
if (!t.isFor(parent)) {
|
||||
for (const declar of node.declarations) {
|
||||
if (declar.init) {
|
||||
hasInits = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let separator;
|
||||
|
||||
if (hasInits) {
|
||||
separator = node.kind === "const" ? constDeclarationIndent : variableDeclarationIndent;
|
||||
}
|
||||
|
||||
this.printList(node.declarations, node, {
|
||||
separator
|
||||
});
|
||||
|
||||
if (t.isFor(parent)) {
|
||||
if (t.isForStatement(parent)) {
|
||||
if (parent.init === node) return;
|
||||
} else {
|
||||
if (parent.left === node) return;
|
||||
}
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function VariableDeclarator(node) {
|
||||
this.print(node.id, node);
|
||||
if (node.definite) this.token("!");
|
||||
this.print(node.id.typeAnnotation, node);
|
||||
|
||||
if (node.init) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.init, node);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
||||
exports.TemplateElement = TemplateElement;
|
||||
exports.TemplateLiteral = TemplateLiteral;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function TaggedTemplateExpression(node) {
|
||||
this.print(node.tag, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.print(node.quasi, node);
|
||||
}
|
||||
|
||||
function TemplateElement(node, parent) {
|
||||
const isFirst = parent.quasis[0] === node;
|
||||
const isLast = parent.quasis[parent.quasis.length - 1] === node;
|
||||
const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
|
||||
this.token(value);
|
||||
}
|
||||
|
||||
function TemplateLiteral(node) {
|
||||
const quasis = node.quasis;
|
||||
|
||||
for (let i = 0; i < quasis.length; i++) {
|
||||
this.print(quasis[i], node);
|
||||
|
||||
if (i + 1 < quasis.length) {
|
||||
this.print(node.expressions[i], node);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,254 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.Identifier = Identifier;
|
||||
exports.ArgumentPlaceholder = ArgumentPlaceholder;
|
||||
exports.SpreadElement = exports.RestElement = RestElement;
|
||||
exports.ObjectPattern = exports.ObjectExpression = ObjectExpression;
|
||||
exports.ObjectMethod = ObjectMethod;
|
||||
exports.ObjectProperty = ObjectProperty;
|
||||
exports.ArrayPattern = exports.ArrayExpression = ArrayExpression;
|
||||
exports.RecordExpression = RecordExpression;
|
||||
exports.TupleExpression = TupleExpression;
|
||||
exports.RegExpLiteral = RegExpLiteral;
|
||||
exports.BooleanLiteral = BooleanLiteral;
|
||||
exports.NullLiteral = NullLiteral;
|
||||
exports.NumericLiteral = NumericLiteral;
|
||||
exports.StringLiteral = StringLiteral;
|
||||
exports.BigIntLiteral = BigIntLiteral;
|
||||
exports.DecimalLiteral = DecimalLiteral;
|
||||
exports.PipelineTopicExpression = PipelineTopicExpression;
|
||||
exports.PipelineBareFunction = PipelineBareFunction;
|
||||
exports.PipelinePrimaryTopicReference = PipelinePrimaryTopicReference;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _jsesc = require("jsesc");
|
||||
|
||||
function Identifier(node) {
|
||||
this.exactSource(node.loc, () => {
|
||||
this.word(node.name);
|
||||
});
|
||||
}
|
||||
|
||||
function ArgumentPlaceholder() {
|
||||
this.token("?");
|
||||
}
|
||||
|
||||
function RestElement(node) {
|
||||
this.token("...");
|
||||
this.print(node.argument, node);
|
||||
}
|
||||
|
||||
function ObjectExpression(node) {
|
||||
const props = node.properties;
|
||||
this.token("{");
|
||||
this.printInnerComments(node);
|
||||
|
||||
if (props.length) {
|
||||
this.space();
|
||||
this.printList(props, node, {
|
||||
indent: true,
|
||||
statement: true
|
||||
});
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
function ObjectMethod(node) {
|
||||
this.printJoin(node.decorators, node);
|
||||
|
||||
this._methodHead(node);
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function ObjectProperty(node) {
|
||||
this.printJoin(node.decorators, node);
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
} else {
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
this.print(node.value, node);
|
||||
return;
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
|
||||
if (node.shorthand && t.isIdentifier(node.key) && t.isIdentifier(node.value) && node.key.name === node.value.name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
function ArrayExpression(node) {
|
||||
const elems = node.elements;
|
||||
const len = elems.length;
|
||||
this.token("[");
|
||||
this.printInnerComments(node);
|
||||
|
||||
for (let i = 0; i < elems.length; i++) {
|
||||
const elem = elems[i];
|
||||
|
||||
if (elem) {
|
||||
if (i > 0) this.space();
|
||||
this.print(elem, node);
|
||||
if (i < len - 1) this.token(",");
|
||||
} else {
|
||||
this.token(",");
|
||||
}
|
||||
}
|
||||
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
function RecordExpression(node) {
|
||||
const props = node.properties;
|
||||
let startToken;
|
||||
let endToken;
|
||||
|
||||
if (this.format.recordAndTupleSyntaxType === "bar") {
|
||||
startToken = "{|";
|
||||
endToken = "|}";
|
||||
} else if (this.format.recordAndTupleSyntaxType === "hash") {
|
||||
startToken = "#{";
|
||||
endToken = "}";
|
||||
} else {
|
||||
throw new Error(`The "recordAndTupleSyntaxType" generator option must be "bar" or "hash" (${JSON.stringify(this.format.recordAndTupleSyntaxType)} received).`);
|
||||
}
|
||||
|
||||
this.token(startToken);
|
||||
this.printInnerComments(node);
|
||||
|
||||
if (props.length) {
|
||||
this.space();
|
||||
this.printList(props, node, {
|
||||
indent: true,
|
||||
statement: true
|
||||
});
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token(endToken);
|
||||
}
|
||||
|
||||
function TupleExpression(node) {
|
||||
const elems = node.elements;
|
||||
const len = elems.length;
|
||||
let startToken;
|
||||
let endToken;
|
||||
|
||||
if (this.format.recordAndTupleSyntaxType === "bar") {
|
||||
startToken = "[|";
|
||||
endToken = "|]";
|
||||
} else if (this.format.recordAndTupleSyntaxType === "hash") {
|
||||
startToken = "#[";
|
||||
endToken = "]";
|
||||
} else {
|
||||
throw new Error(`${this.format.recordAndTupleSyntaxType} is not a valid recordAndTuple syntax type`);
|
||||
}
|
||||
|
||||
this.token(startToken);
|
||||
this.printInnerComments(node);
|
||||
|
||||
for (let i = 0; i < elems.length; i++) {
|
||||
const elem = elems[i];
|
||||
|
||||
if (elem) {
|
||||
if (i > 0) this.space();
|
||||
this.print(elem, node);
|
||||
if (i < len - 1) this.token(",");
|
||||
}
|
||||
}
|
||||
|
||||
this.token(endToken);
|
||||
}
|
||||
|
||||
function RegExpLiteral(node) {
|
||||
this.word(`/${node.pattern}/${node.flags}`);
|
||||
}
|
||||
|
||||
function BooleanLiteral(node) {
|
||||
this.word(node.value ? "true" : "false");
|
||||
}
|
||||
|
||||
function NullLiteral() {
|
||||
this.word("null");
|
||||
}
|
||||
|
||||
function NumericLiteral(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
const opts = this.format.jsescOption;
|
||||
const value = node.value + "";
|
||||
|
||||
if (opts.numbers) {
|
||||
this.number(_jsesc(node.value, opts));
|
||||
} else if (raw == null) {
|
||||
this.number(value);
|
||||
} else if (this.format.minified) {
|
||||
this.number(raw.length < value.length ? raw : value);
|
||||
} else {
|
||||
this.number(raw);
|
||||
}
|
||||
}
|
||||
|
||||
function StringLiteral(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
|
||||
if (!this.format.minified && raw != null) {
|
||||
this.token(raw);
|
||||
return;
|
||||
}
|
||||
|
||||
const val = _jsesc(node.value, Object.assign(this.format.jsescOption, this.format.jsonCompatibleStrings && {
|
||||
json: true
|
||||
}));
|
||||
|
||||
return this.token(val);
|
||||
}
|
||||
|
||||
function BigIntLiteral(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
|
||||
if (!this.format.minified && raw != null) {
|
||||
this.word(raw);
|
||||
return;
|
||||
}
|
||||
|
||||
this.word(node.value + "n");
|
||||
}
|
||||
|
||||
function DecimalLiteral(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
|
||||
if (!this.format.minified && raw != null) {
|
||||
this.word(raw);
|
||||
return;
|
||||
}
|
||||
|
||||
this.word(node.value + "m");
|
||||
}
|
||||
|
||||
function PipelineTopicExpression(node) {
|
||||
this.print(node.expression, node);
|
||||
}
|
||||
|
||||
function PipelineBareFunction(node) {
|
||||
this.print(node.callee, node);
|
||||
}
|
||||
|
||||
function PipelinePrimaryTopicReference() {
|
||||
this.token("#");
|
||||
}
|
|
@ -1,808 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.TSTypeAnnotation = TSTypeAnnotation;
|
||||
exports.TSTypeParameterDeclaration = exports.TSTypeParameterInstantiation = TSTypeParameterInstantiation;
|
||||
exports.TSTypeParameter = TSTypeParameter;
|
||||
exports.TSParameterProperty = TSParameterProperty;
|
||||
exports.TSDeclareFunction = TSDeclareFunction;
|
||||
exports.TSDeclareMethod = TSDeclareMethod;
|
||||
exports.TSQualifiedName = TSQualifiedName;
|
||||
exports.TSCallSignatureDeclaration = TSCallSignatureDeclaration;
|
||||
exports.TSConstructSignatureDeclaration = TSConstructSignatureDeclaration;
|
||||
exports.TSPropertySignature = TSPropertySignature;
|
||||
exports.tsPrintPropertyOrMethodName = tsPrintPropertyOrMethodName;
|
||||
exports.TSMethodSignature = TSMethodSignature;
|
||||
exports.TSIndexSignature = TSIndexSignature;
|
||||
exports.TSAnyKeyword = TSAnyKeyword;
|
||||
exports.TSBigIntKeyword = TSBigIntKeyword;
|
||||
exports.TSUnknownKeyword = TSUnknownKeyword;
|
||||
exports.TSNumberKeyword = TSNumberKeyword;
|
||||
exports.TSObjectKeyword = TSObjectKeyword;
|
||||
exports.TSBooleanKeyword = TSBooleanKeyword;
|
||||
exports.TSStringKeyword = TSStringKeyword;
|
||||
exports.TSSymbolKeyword = TSSymbolKeyword;
|
||||
exports.TSVoidKeyword = TSVoidKeyword;
|
||||
exports.TSUndefinedKeyword = TSUndefinedKeyword;
|
||||
exports.TSNullKeyword = TSNullKeyword;
|
||||
exports.TSNeverKeyword = TSNeverKeyword;
|
||||
exports.TSIntrinsicKeyword = TSIntrinsicKeyword;
|
||||
exports.TSThisType = TSThisType;
|
||||
exports.TSFunctionType = TSFunctionType;
|
||||
exports.TSConstructorType = TSConstructorType;
|
||||
exports.tsPrintFunctionOrConstructorType = tsPrintFunctionOrConstructorType;
|
||||
exports.TSTypeReference = TSTypeReference;
|
||||
exports.TSTypePredicate = TSTypePredicate;
|
||||
exports.TSTypeQuery = TSTypeQuery;
|
||||
exports.TSTypeLiteral = TSTypeLiteral;
|
||||
exports.tsPrintTypeLiteralOrInterfaceBody = tsPrintTypeLiteralOrInterfaceBody;
|
||||
exports.tsPrintBraced = tsPrintBraced;
|
||||
exports.TSArrayType = TSArrayType;
|
||||
exports.TSTupleType = TSTupleType;
|
||||
exports.TSOptionalType = TSOptionalType;
|
||||
exports.TSRestType = TSRestType;
|
||||
exports.TSNamedTupleMember = TSNamedTupleMember;
|
||||
exports.TSUnionType = TSUnionType;
|
||||
exports.TSIntersectionType = TSIntersectionType;
|
||||
exports.tsPrintUnionOrIntersectionType = tsPrintUnionOrIntersectionType;
|
||||
exports.TSConditionalType = TSConditionalType;
|
||||
exports.TSInferType = TSInferType;
|
||||
exports.TSParenthesizedType = TSParenthesizedType;
|
||||
exports.TSTypeOperator = TSTypeOperator;
|
||||
exports.TSIndexedAccessType = TSIndexedAccessType;
|
||||
exports.TSMappedType = TSMappedType;
|
||||
exports.TSLiteralType = TSLiteralType;
|
||||
exports.TSExpressionWithTypeArguments = TSExpressionWithTypeArguments;
|
||||
exports.TSInterfaceDeclaration = TSInterfaceDeclaration;
|
||||
exports.TSInterfaceBody = TSInterfaceBody;
|
||||
exports.TSTypeAliasDeclaration = TSTypeAliasDeclaration;
|
||||
exports.TSAsExpression = TSAsExpression;
|
||||
exports.TSTypeAssertion = TSTypeAssertion;
|
||||
exports.TSEnumDeclaration = TSEnumDeclaration;
|
||||
exports.TSEnumMember = TSEnumMember;
|
||||
exports.TSModuleDeclaration = TSModuleDeclaration;
|
||||
exports.TSModuleBlock = TSModuleBlock;
|
||||
exports.TSImportType = TSImportType;
|
||||
exports.TSImportEqualsDeclaration = TSImportEqualsDeclaration;
|
||||
exports.TSExternalModuleReference = TSExternalModuleReference;
|
||||
exports.TSNonNullExpression = TSNonNullExpression;
|
||||
exports.TSExportAssignment = TSExportAssignment;
|
||||
exports.TSNamespaceExportDeclaration = TSNamespaceExportDeclaration;
|
||||
exports.tsPrintSignatureDeclarationBase = tsPrintSignatureDeclarationBase;
|
||||
exports.tsPrintClassMemberModifiers = tsPrintClassMemberModifiers;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function TSTypeAnnotation(node) {
|
||||
this.token(":");
|
||||
this.space();
|
||||
if (node.optional) this.token("?");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TSTypeParameterInstantiation(node) {
|
||||
this.token("<");
|
||||
this.printList(node.params, node, {});
|
||||
this.token(">");
|
||||
}
|
||||
|
||||
function TSTypeParameter(node) {
|
||||
this.word(node.name);
|
||||
|
||||
if (node.constraint) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.print(node.constraint, node);
|
||||
}
|
||||
|
||||
if (node.default) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.default, node);
|
||||
}
|
||||
}
|
||||
|
||||
function TSParameterProperty(node) {
|
||||
if (node.accessibility) {
|
||||
this.word(node.accessibility);
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.readonly) {
|
||||
this.word("readonly");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._param(node.parameter);
|
||||
}
|
||||
|
||||
function TSDeclareFunction(node) {
|
||||
if (node.declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._functionHead(node);
|
||||
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSDeclareMethod(node) {
|
||||
this._classMethodHead(node);
|
||||
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSQualifiedName(node) {
|
||||
this.print(node.left, node);
|
||||
this.token(".");
|
||||
this.print(node.right, node);
|
||||
}
|
||||
|
||||
function TSCallSignatureDeclaration(node) {
|
||||
this.tsPrintSignatureDeclarationBase(node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSConstructSignatureDeclaration(node) {
|
||||
this.word("new");
|
||||
this.space();
|
||||
this.tsPrintSignatureDeclarationBase(node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSPropertySignature(node) {
|
||||
const {
|
||||
readonly,
|
||||
initializer
|
||||
} = node;
|
||||
|
||||
if (readonly) {
|
||||
this.word("readonly");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.tsPrintPropertyOrMethodName(node);
|
||||
this.print(node.typeAnnotation, node);
|
||||
|
||||
if (initializer) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(initializer, node);
|
||||
}
|
||||
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function tsPrintPropertyOrMethodName(node) {
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
|
||||
if (node.computed) {
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
}
|
||||
}
|
||||
|
||||
function TSMethodSignature(node) {
|
||||
const {
|
||||
kind
|
||||
} = node;
|
||||
|
||||
if (kind === "set" || kind === "get") {
|
||||
this.word(kind);
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.tsPrintPropertyOrMethodName(node);
|
||||
this.tsPrintSignatureDeclarationBase(node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSIndexSignature(node) {
|
||||
const {
|
||||
readonly,
|
||||
static: isStatic
|
||||
} = node;
|
||||
|
||||
if (isStatic) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (readonly) {
|
||||
this.word("readonly");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
|
||||
this._parameters(node.parameters, node);
|
||||
|
||||
this.token("]");
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSAnyKeyword() {
|
||||
this.word("any");
|
||||
}
|
||||
|
||||
function TSBigIntKeyword() {
|
||||
this.word("bigint");
|
||||
}
|
||||
|
||||
function TSUnknownKeyword() {
|
||||
this.word("unknown");
|
||||
}
|
||||
|
||||
function TSNumberKeyword() {
|
||||
this.word("number");
|
||||
}
|
||||
|
||||
function TSObjectKeyword() {
|
||||
this.word("object");
|
||||
}
|
||||
|
||||
function TSBooleanKeyword() {
|
||||
this.word("boolean");
|
||||
}
|
||||
|
||||
function TSStringKeyword() {
|
||||
this.word("string");
|
||||
}
|
||||
|
||||
function TSSymbolKeyword() {
|
||||
this.word("symbol");
|
||||
}
|
||||
|
||||
function TSVoidKeyword() {
|
||||
this.word("void");
|
||||
}
|
||||
|
||||
function TSUndefinedKeyword() {
|
||||
this.word("undefined");
|
||||
}
|
||||
|
||||
function TSNullKeyword() {
|
||||
this.word("null");
|
||||
}
|
||||
|
||||
function TSNeverKeyword() {
|
||||
this.word("never");
|
||||
}
|
||||
|
||||
function TSIntrinsicKeyword() {
|
||||
this.word("intrinsic");
|
||||
}
|
||||
|
||||
function TSThisType() {
|
||||
this.word("this");
|
||||
}
|
||||
|
||||
function TSFunctionType(node) {
|
||||
this.tsPrintFunctionOrConstructorType(node);
|
||||
}
|
||||
|
||||
function TSConstructorType(node) {
|
||||
if (node.abstract) {
|
||||
this.word("abstract");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("new");
|
||||
this.space();
|
||||
this.tsPrintFunctionOrConstructorType(node);
|
||||
}
|
||||
|
||||
function tsPrintFunctionOrConstructorType(node) {
|
||||
const {
|
||||
typeParameters,
|
||||
parameters
|
||||
} = node;
|
||||
this.print(typeParameters, node);
|
||||
this.token("(");
|
||||
|
||||
this._parameters(parameters, node);
|
||||
|
||||
this.token(")");
|
||||
this.space();
|
||||
this.token("=>");
|
||||
this.space();
|
||||
this.print(node.typeAnnotation.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TSTypeReference(node) {
|
||||
this.print(node.typeName, node);
|
||||
this.print(node.typeParameters, node);
|
||||
}
|
||||
|
||||
function TSTypePredicate(node) {
|
||||
if (node.asserts) {
|
||||
this.word("asserts");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.parameterName);
|
||||
|
||||
if (node.typeAnnotation) {
|
||||
this.space();
|
||||
this.word("is");
|
||||
this.space();
|
||||
this.print(node.typeAnnotation.typeAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
function TSTypeQuery(node) {
|
||||
this.word("typeof");
|
||||
this.space();
|
||||
this.print(node.exprName);
|
||||
}
|
||||
|
||||
function TSTypeLiteral(node) {
|
||||
this.tsPrintTypeLiteralOrInterfaceBody(node.members, node);
|
||||
}
|
||||
|
||||
function tsPrintTypeLiteralOrInterfaceBody(members, node) {
|
||||
this.tsPrintBraced(members, node);
|
||||
}
|
||||
|
||||
function tsPrintBraced(members, node) {
|
||||
this.token("{");
|
||||
|
||||
if (members.length) {
|
||||
this.indent();
|
||||
this.newline();
|
||||
|
||||
for (const member of members) {
|
||||
this.print(member, node);
|
||||
this.newline();
|
||||
}
|
||||
|
||||
this.dedent();
|
||||
this.rightBrace();
|
||||
} else {
|
||||
this.token("}");
|
||||
}
|
||||
}
|
||||
|
||||
function TSArrayType(node) {
|
||||
this.print(node.elementType, node);
|
||||
this.token("[]");
|
||||
}
|
||||
|
||||
function TSTupleType(node) {
|
||||
this.token("[");
|
||||
this.printList(node.elementTypes, node);
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
function TSOptionalType(node) {
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token("?");
|
||||
}
|
||||
|
||||
function TSRestType(node) {
|
||||
this.token("...");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TSNamedTupleMember(node) {
|
||||
this.print(node.label, node);
|
||||
if (node.optional) this.token("?");
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.elementType, node);
|
||||
}
|
||||
|
||||
function TSUnionType(node) {
|
||||
this.tsPrintUnionOrIntersectionType(node, "|");
|
||||
}
|
||||
|
||||
function TSIntersectionType(node) {
|
||||
this.tsPrintUnionOrIntersectionType(node, "&");
|
||||
}
|
||||
|
||||
function tsPrintUnionOrIntersectionType(node, sep) {
|
||||
this.printJoin(node.types, node, {
|
||||
separator() {
|
||||
this.space();
|
||||
this.token(sep);
|
||||
this.space();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function TSConditionalType(node) {
|
||||
this.print(node.checkType);
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.print(node.extendsType);
|
||||
this.space();
|
||||
this.token("?");
|
||||
this.space();
|
||||
this.print(node.trueType);
|
||||
this.space();
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.falseType);
|
||||
}
|
||||
|
||||
function TSInferType(node) {
|
||||
this.token("infer");
|
||||
this.space();
|
||||
this.print(node.typeParameter);
|
||||
}
|
||||
|
||||
function TSParenthesizedType(node) {
|
||||
this.token("(");
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function TSTypeOperator(node) {
|
||||
this.word(node.operator);
|
||||
this.space();
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TSIndexedAccessType(node) {
|
||||
this.print(node.objectType, node);
|
||||
this.token("[");
|
||||
this.print(node.indexType, node);
|
||||
this.token("]");
|
||||
}
|
||||
|
||||
function TSMappedType(node) {
|
||||
const {
|
||||
nameType,
|
||||
optional,
|
||||
readonly,
|
||||
typeParameter
|
||||
} = node;
|
||||
this.token("{");
|
||||
this.space();
|
||||
|
||||
if (readonly) {
|
||||
tokenIfPlusMinus(this, readonly);
|
||||
this.word("readonly");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.word(typeParameter.name);
|
||||
this.space();
|
||||
this.word("in");
|
||||
this.space();
|
||||
this.print(typeParameter.constraint, typeParameter);
|
||||
|
||||
if (nameType) {
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.print(nameType, node);
|
||||
}
|
||||
|
||||
this.token("]");
|
||||
|
||||
if (optional) {
|
||||
tokenIfPlusMinus(this, optional);
|
||||
this.token("?");
|
||||
}
|
||||
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.space();
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
function tokenIfPlusMinus(self, tok) {
|
||||
if (tok !== true) {
|
||||
self.token(tok);
|
||||
}
|
||||
}
|
||||
|
||||
function TSLiteralType(node) {
|
||||
this.print(node.literal, node);
|
||||
}
|
||||
|
||||
function TSExpressionWithTypeArguments(node) {
|
||||
this.print(node.expression, node);
|
||||
this.print(node.typeParameters, node);
|
||||
}
|
||||
|
||||
function TSInterfaceDeclaration(node) {
|
||||
const {
|
||||
declare,
|
||||
id,
|
||||
typeParameters,
|
||||
extends: extendz,
|
||||
body
|
||||
} = node;
|
||||
|
||||
if (declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("interface");
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.print(typeParameters, node);
|
||||
|
||||
if (extendz != null && extendz.length) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.printList(extendz, node);
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(body, node);
|
||||
}
|
||||
|
||||
function TSInterfaceBody(node) {
|
||||
this.tsPrintTypeLiteralOrInterfaceBody(node.body, node);
|
||||
}
|
||||
|
||||
function TSTypeAliasDeclaration(node) {
|
||||
const {
|
||||
declare,
|
||||
id,
|
||||
typeParameters,
|
||||
typeAnnotation
|
||||
} = node;
|
||||
|
||||
if (declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("type");
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.print(typeParameters, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(typeAnnotation, node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSAsExpression(node) {
|
||||
const {
|
||||
expression,
|
||||
typeAnnotation
|
||||
} = node;
|
||||
this.print(expression, node);
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.print(typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TSTypeAssertion(node) {
|
||||
const {
|
||||
typeAnnotation,
|
||||
expression
|
||||
} = node;
|
||||
this.token("<");
|
||||
this.print(typeAnnotation, node);
|
||||
this.token(">");
|
||||
this.space();
|
||||
this.print(expression, node);
|
||||
}
|
||||
|
||||
function TSEnumDeclaration(node) {
|
||||
const {
|
||||
declare,
|
||||
const: isConst,
|
||||
id,
|
||||
members
|
||||
} = node;
|
||||
|
||||
if (declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (isConst) {
|
||||
this.word("const");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("enum");
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.space();
|
||||
this.tsPrintBraced(members, node);
|
||||
}
|
||||
|
||||
function TSEnumMember(node) {
|
||||
const {
|
||||
id,
|
||||
initializer
|
||||
} = node;
|
||||
this.print(id, node);
|
||||
|
||||
if (initializer) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(initializer, node);
|
||||
}
|
||||
|
||||
this.token(",");
|
||||
}
|
||||
|
||||
function TSModuleDeclaration(node) {
|
||||
const {
|
||||
declare,
|
||||
id
|
||||
} = node;
|
||||
|
||||
if (declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (!node.global) {
|
||||
this.word(id.type === "Identifier" ? "namespace" : "module");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(id, node);
|
||||
|
||||
if (!node.body) {
|
||||
this.token(";");
|
||||
return;
|
||||
}
|
||||
|
||||
let body = node.body;
|
||||
|
||||
while (body.type === "TSModuleDeclaration") {
|
||||
this.token(".");
|
||||
this.print(body.id, body);
|
||||
body = body.body;
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.print(body, node);
|
||||
}
|
||||
|
||||
function TSModuleBlock(node) {
|
||||
this.tsPrintBraced(node.body, node);
|
||||
}
|
||||
|
||||
function TSImportType(node) {
|
||||
const {
|
||||
argument,
|
||||
qualifier,
|
||||
typeParameters
|
||||
} = node;
|
||||
this.word("import");
|
||||
this.token("(");
|
||||
this.print(argument, node);
|
||||
this.token(")");
|
||||
|
||||
if (qualifier) {
|
||||
this.token(".");
|
||||
this.print(qualifier, node);
|
||||
}
|
||||
|
||||
if (typeParameters) {
|
||||
this.print(typeParameters, node);
|
||||
}
|
||||
}
|
||||
|
||||
function TSImportEqualsDeclaration(node) {
|
||||
const {
|
||||
isExport,
|
||||
id,
|
||||
moduleReference
|
||||
} = node;
|
||||
|
||||
if (isExport) {
|
||||
this.word("export");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.word("import");
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(moduleReference, node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSExternalModuleReference(node) {
|
||||
this.token("require(");
|
||||
this.print(node.expression, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
function TSNonNullExpression(node) {
|
||||
this.print(node.expression, node);
|
||||
this.token("!");
|
||||
}
|
||||
|
||||
function TSExportAssignment(node) {
|
||||
this.word("export");
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.space();
|
||||
this.print(node.expression, node);
|
||||
this.token(";");
|
||||
}
|
||||
|
||||
function TSNamespaceExportDeclaration(node) {
|
||||
this.word("export");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
this.word("namespace");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
function tsPrintSignatureDeclarationBase(node) {
|
||||
const {
|
||||
typeParameters,
|
||||
parameters
|
||||
} = node;
|
||||
this.print(typeParameters, node);
|
||||
this.token("(");
|
||||
|
||||
this._parameters(parameters, node);
|
||||
|
||||
this.token(")");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function tsPrintClassMemberModifiers(node, isField) {
|
||||
if (isField && node.declare) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.accessibility) {
|
||||
this.word(node.accessibility);
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.override) {
|
||||
this.word("override");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.abstract) {
|
||||
this.word("abstract");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (isField && node.readonly) {
|
||||
this.word("readonly");
|
||||
this.space();
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = generate;
|
||||
exports.CodeGenerator = void 0;
|
||||
|
||||
var _sourceMap = require("./source-map");
|
||||
|
||||
var _printer = require("./printer");
|
||||
|
||||
class Generator extends _printer.default {
|
||||
constructor(ast, opts = {}, code) {
|
||||
const format = normalizeOptions(code, opts);
|
||||
const map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null;
|
||||
super(format, map);
|
||||
this.ast = void 0;
|
||||
this.ast = ast;
|
||||
}
|
||||
|
||||
generate() {
|
||||
return super.generate(this.ast);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function normalizeOptions(code, opts) {
|
||||
const format = {
|
||||
auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
|
||||
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
|
||||
shouldPrintComment: opts.shouldPrintComment,
|
||||
retainLines: opts.retainLines,
|
||||
retainFunctionParens: opts.retainFunctionParens,
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: opts.compact,
|
||||
minified: opts.minified,
|
||||
concise: opts.concise,
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: " ",
|
||||
base: 0
|
||||
},
|
||||
decoratorsBeforeExport: !!opts.decoratorsBeforeExport,
|
||||
jsescOption: Object.assign({
|
||||
quotes: "double",
|
||||
wrap: true,
|
||||
minimal: false
|
||||
}, opts.jsescOption),
|
||||
recordAndTupleSyntaxType: opts.recordAndTupleSyntaxType
|
||||
};
|
||||
{
|
||||
format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
|
||||
}
|
||||
|
||||
if (format.minified) {
|
||||
format.compact = true;
|
||||
|
||||
format.shouldPrintComment = format.shouldPrintComment || (() => format.comments);
|
||||
} else {
|
||||
format.shouldPrintComment = format.shouldPrintComment || (value => format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0);
|
||||
}
|
||||
|
||||
if (format.compact === "auto") {
|
||||
format.compact = code.length > 500000;
|
||||
|
||||
if (format.compact) {
|
||||
console.error("[BABEL] Note: The code generator has deoptimised the styling of " + `${opts.filename} as it exceeds the max of ${"500KB"}.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (format.compact) {
|
||||
format.indent.adjustMultilineComment = false;
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
class CodeGenerator {
|
||||
constructor(ast, opts, code) {
|
||||
this._generator = void 0;
|
||||
this._generator = new Generator(ast, opts, code);
|
||||
}
|
||||
|
||||
generate() {
|
||||
return this._generator.generate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.CodeGenerator = CodeGenerator;
|
||||
|
||||
function generate(ast, opts, code) {
|
||||
const gen = new Generator(ast, opts, code);
|
||||
return gen.generate();
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.needsWhitespace = needsWhitespace;
|
||||
exports.needsWhitespaceBefore = needsWhitespaceBefore;
|
||||
exports.needsWhitespaceAfter = needsWhitespaceAfter;
|
||||
exports.needsParens = needsParens;
|
||||
|
||||
var whitespace = require("./whitespace");
|
||||
|
||||
var parens = require("./parentheses");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function expandAliases(obj) {
|
||||
const newObj = {};
|
||||
|
||||
function add(type, func) {
|
||||
const fn = newObj[type];
|
||||
newObj[type] = fn ? function (node, parent, stack) {
|
||||
const result = fn(node, parent, stack);
|
||||
return result == null ? func(node, parent, stack) : result;
|
||||
} : func;
|
||||
}
|
||||
|
||||
for (const type of Object.keys(obj)) {
|
||||
const aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
|
||||
if (aliases) {
|
||||
for (const alias of aliases) {
|
||||
add(alias, obj[type]);
|
||||
}
|
||||
} else {
|
||||
add(type, obj[type]);
|
||||
}
|
||||
}
|
||||
|
||||
return newObj;
|
||||
}
|
||||
|
||||
const expandedParens = expandAliases(parens);
|
||||
const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
|
||||
const expandedWhitespaceList = expandAliases(whitespace.list);
|
||||
|
||||
function find(obj, node, parent, printStack) {
|
||||
const fn = obj[node.type];
|
||||
return fn ? fn(node, parent, printStack) : null;
|
||||
}
|
||||
|
||||
function isOrHasCallExpression(node) {
|
||||
if (t.isCallExpression(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return t.isMemberExpression(node) && isOrHasCallExpression(node.object);
|
||||
}
|
||||
|
||||
function needsWhitespace(node, parent, type) {
|
||||
if (!node) return 0;
|
||||
|
||||
if (t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
let linesInfo = find(expandedWhitespaceNodes, node, parent);
|
||||
|
||||
if (!linesInfo) {
|
||||
const items = find(expandedWhitespaceList, node, parent);
|
||||
|
||||
if (items) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
linesInfo = needsWhitespace(items[i], node, type);
|
||||
if (linesInfo) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof linesInfo === "object" && linesInfo !== null) {
|
||||
return linesInfo[type] || 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function needsWhitespaceBefore(node, parent) {
|
||||
return needsWhitespace(node, parent, "before");
|
||||
}
|
||||
|
||||
function needsWhitespaceAfter(node, parent) {
|
||||
return needsWhitespace(node, parent, "after");
|
||||
}
|
||||
|
||||
function needsParens(node, parent, printStack) {
|
||||
if (!parent) return false;
|
||||
|
||||
if (t.isNewExpression(parent) && parent.callee === node) {
|
||||
if (isOrHasCallExpression(node)) return true;
|
||||
}
|
||||
|
||||
return find(expandedParens, node, parent, printStack);
|
||||
}
|
|
@ -1,293 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.NullableTypeAnnotation = NullableTypeAnnotation;
|
||||
exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
||||
exports.UpdateExpression = UpdateExpression;
|
||||
exports.ObjectExpression = ObjectExpression;
|
||||
exports.DoExpression = DoExpression;
|
||||
exports.Binary = Binary;
|
||||
exports.IntersectionTypeAnnotation = exports.UnionTypeAnnotation = UnionTypeAnnotation;
|
||||
exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
|
||||
exports.TSAsExpression = TSAsExpression;
|
||||
exports.TSTypeAssertion = TSTypeAssertion;
|
||||
exports.TSIntersectionType = exports.TSUnionType = TSUnionType;
|
||||
exports.TSInferType = TSInferType;
|
||||
exports.BinaryExpression = BinaryExpression;
|
||||
exports.SequenceExpression = SequenceExpression;
|
||||
exports.AwaitExpression = exports.YieldExpression = YieldExpression;
|
||||
exports.ClassExpression = ClassExpression;
|
||||
exports.UnaryLike = UnaryLike;
|
||||
exports.FunctionExpression = FunctionExpression;
|
||||
exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
||||
exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.OptionalCallExpression = exports.OptionalMemberExpression = OptionalMemberExpression;
|
||||
exports.AssignmentExpression = AssignmentExpression;
|
||||
exports.LogicalExpression = LogicalExpression;
|
||||
exports.Identifier = Identifier;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const PRECEDENCE = {
|
||||
"||": 0,
|
||||
"??": 0,
|
||||
"&&": 1,
|
||||
"|": 2,
|
||||
"^": 3,
|
||||
"&": 4,
|
||||
"==": 5,
|
||||
"===": 5,
|
||||
"!=": 5,
|
||||
"!==": 5,
|
||||
"<": 6,
|
||||
">": 6,
|
||||
"<=": 6,
|
||||
">=": 6,
|
||||
in: 6,
|
||||
instanceof: 6,
|
||||
">>": 7,
|
||||
"<<": 7,
|
||||
">>>": 7,
|
||||
"+": 8,
|
||||
"-": 8,
|
||||
"*": 9,
|
||||
"/": 9,
|
||||
"%": 9,
|
||||
"**": 10
|
||||
};
|
||||
|
||||
const isClassExtendsClause = (node, parent) => (t.isClassDeclaration(parent) || t.isClassExpression(parent)) && parent.superClass === node;
|
||||
|
||||
const hasPostfixPart = (node, parent) => (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.object === node || (t.isCallExpression(parent) || t.isOptionalCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node || t.isTaggedTemplateExpression(parent) && parent.tag === node || t.isTSNonNullExpression(parent);
|
||||
|
||||
function NullableTypeAnnotation(node, parent) {
|
||||
return t.isArrayTypeAnnotation(parent);
|
||||
}
|
||||
|
||||
function FunctionTypeAnnotation(node, parent, printStack) {
|
||||
return t.isUnionTypeAnnotation(parent) || t.isIntersectionTypeAnnotation(parent) || t.isArrayTypeAnnotation(parent) || t.isTypeAnnotation(parent) && t.isArrowFunctionExpression(printStack[printStack.length - 3]);
|
||||
}
|
||||
|
||||
function UpdateExpression(node, parent) {
|
||||
return hasPostfixPart(node, parent) || isClassExtendsClause(node, parent);
|
||||
}
|
||||
|
||||
function ObjectExpression(node, parent, printStack) {
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: true,
|
||||
arrowBody: true
|
||||
});
|
||||
}
|
||||
|
||||
function DoExpression(node, parent, printStack) {
|
||||
return !node.async && isFirstInContext(printStack, {
|
||||
expressionStatement: true
|
||||
});
|
||||
}
|
||||
|
||||
function Binary(node, parent) {
|
||||
if (node.operator === "**" && t.isBinaryExpression(parent, {
|
||||
operator: "**"
|
||||
})) {
|
||||
return parent.left === node;
|
||||
}
|
||||
|
||||
if (isClassExtendsClause(node, parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasPostfixPart(node, parent) || t.isUnaryLike(parent) || t.isAwaitExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isBinary(parent)) {
|
||||
const parentOp = parent.operator;
|
||||
const parentPos = PRECEDENCE[parentOp];
|
||||
const nodeOp = node.operator;
|
||||
const nodePos = PRECEDENCE[nodeOp];
|
||||
|
||||
if (parentPos === nodePos && parent.right === node && !t.isLogicalExpression(parent) || parentPos > nodePos) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function UnionTypeAnnotation(node, parent) {
|
||||
return t.isArrayTypeAnnotation(parent) || t.isNullableTypeAnnotation(parent) || t.isIntersectionTypeAnnotation(parent) || t.isUnionTypeAnnotation(parent);
|
||||
}
|
||||
|
||||
function OptionalIndexedAccessType(node, parent) {
|
||||
return t.isIndexedAccessType(parent, {
|
||||
objectType: node
|
||||
});
|
||||
}
|
||||
|
||||
function TSAsExpression() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function TSTypeAssertion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function TSUnionType(node, parent) {
|
||||
return t.isTSArrayType(parent) || t.isTSOptionalType(parent) || t.isTSIntersectionType(parent) || t.isTSUnionType(parent) || t.isTSRestType(parent);
|
||||
}
|
||||
|
||||
function TSInferType(node, parent) {
|
||||
return t.isTSArrayType(parent) || t.isTSOptionalType(parent);
|
||||
}
|
||||
|
||||
function BinaryExpression(node, parent) {
|
||||
return node.operator === "in" && (t.isVariableDeclarator(parent) || t.isFor(parent));
|
||||
}
|
||||
|
||||
function SequenceExpression(node, parent) {
|
||||
if (t.isForStatement(parent) || t.isThrowStatement(parent) || t.isReturnStatement(parent) || t.isIfStatement(parent) && parent.test === node || t.isWhileStatement(parent) && parent.test === node || t.isForInStatement(parent) && parent.right === node || t.isSwitchStatement(parent) && parent.discriminant === node || t.isExpressionStatement(parent) && parent.expression === node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function YieldExpression(node, parent) {
|
||||
return t.isBinary(parent) || t.isUnaryLike(parent) || hasPostfixPart(node, parent) || t.isAwaitExpression(parent) && t.isYieldExpression(node) || t.isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent);
|
||||
}
|
||||
|
||||
function ClassExpression(node, parent, printStack) {
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: true,
|
||||
exportDefault: true
|
||||
});
|
||||
}
|
||||
|
||||
function UnaryLike(node, parent) {
|
||||
return hasPostfixPart(node, parent) || t.isBinaryExpression(parent, {
|
||||
operator: "**",
|
||||
left: node
|
||||
}) || isClassExtendsClause(node, parent);
|
||||
}
|
||||
|
||||
function FunctionExpression(node, parent, printStack) {
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: true,
|
||||
exportDefault: true
|
||||
});
|
||||
}
|
||||
|
||||
function ArrowFunctionExpression(node, parent) {
|
||||
return t.isExportDeclaration(parent) || ConditionalExpression(node, parent);
|
||||
}
|
||||
|
||||
function ConditionalExpression(node, parent) {
|
||||
if (t.isUnaryLike(parent) || t.isBinary(parent) || t.isConditionalExpression(parent, {
|
||||
test: node
|
||||
}) || t.isAwaitExpression(parent) || t.isTSTypeAssertion(parent) || t.isTSAsExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return UnaryLike(node, parent);
|
||||
}
|
||||
|
||||
function OptionalMemberExpression(node, parent) {
|
||||
return t.isCallExpression(parent, {
|
||||
callee: node
|
||||
}) || t.isMemberExpression(parent, {
|
||||
object: node
|
||||
});
|
||||
}
|
||||
|
||||
function AssignmentExpression(node, parent) {
|
||||
if (t.isObjectPattern(node.left)) {
|
||||
return true;
|
||||
} else {
|
||||
return ConditionalExpression(node, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function LogicalExpression(node, parent) {
|
||||
switch (node.operator) {
|
||||
case "||":
|
||||
if (!t.isLogicalExpression(parent)) return false;
|
||||
return parent.operator === "??" || parent.operator === "&&";
|
||||
|
||||
case "&&":
|
||||
return t.isLogicalExpression(parent, {
|
||||
operator: "??"
|
||||
});
|
||||
|
||||
case "??":
|
||||
return t.isLogicalExpression(parent) && parent.operator !== "??";
|
||||
}
|
||||
}
|
||||
|
||||
function Identifier(node, parent, printStack) {
|
||||
if (node.name === "let") {
|
||||
const isFollowedByBracket = t.isMemberExpression(parent, {
|
||||
object: node,
|
||||
computed: true
|
||||
}) || t.isOptionalMemberExpression(parent, {
|
||||
object: node,
|
||||
computed: true,
|
||||
optional: false
|
||||
});
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: isFollowedByBracket,
|
||||
forHead: isFollowedByBracket,
|
||||
forInHead: isFollowedByBracket,
|
||||
forOfHead: true
|
||||
});
|
||||
}
|
||||
|
||||
return node.name === "async" && t.isForOfStatement(parent) && node === parent.left;
|
||||
}
|
||||
|
||||
function isFirstInContext(printStack, {
|
||||
expressionStatement = false,
|
||||
arrowBody = false,
|
||||
exportDefault = false,
|
||||
forHead = false,
|
||||
forInHead = false,
|
||||
forOfHead = false
|
||||
}) {
|
||||
let i = printStack.length - 1;
|
||||
let node = printStack[i];
|
||||
i--;
|
||||
let parent = printStack[i];
|
||||
|
||||
while (i >= 0) {
|
||||
if (expressionStatement && t.isExpressionStatement(parent, {
|
||||
expression: node
|
||||
}) || exportDefault && t.isExportDefaultDeclaration(parent, {
|
||||
declaration: node
|
||||
}) || arrowBody && t.isArrowFunctionExpression(parent, {
|
||||
body: node
|
||||
}) || forHead && t.isForStatement(parent, {
|
||||
init: node
|
||||
}) || forInHead && t.isForInStatement(parent, {
|
||||
left: node
|
||||
}) || forOfHead && t.isForOfStatement(parent, {
|
||||
left: node
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasPostfixPart(node, parent) && !t.isNewExpression(parent) || t.isSequenceExpression(parent) && parent.expressions[0] === node || t.isConditional(parent, {
|
||||
test: node
|
||||
}) || t.isBinary(parent, {
|
||||
left: node
|
||||
}) || t.isAssignmentExpression(parent, {
|
||||
left: node
|
||||
})) {
|
||||
node = parent;
|
||||
i--;
|
||||
parent = printStack[i];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -1,197 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.list = exports.nodes = void 0;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function crawl(node, state = {}) {
|
||||
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
||||
crawl(node.object, state);
|
||||
if (node.computed) crawl(node.property, state);
|
||||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
|
||||
crawl(node.left, state);
|
||||
crawl(node.right, state);
|
||||
} else if (t.isCallExpression(node) || t.isOptionalCallExpression(node)) {
|
||||
state.hasCall = true;
|
||||
crawl(node.callee, state);
|
||||
} else if (t.isFunction(node)) {
|
||||
state.hasFunction = true;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
state.hasHelper = state.hasHelper || isHelper(node.callee);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
function isHelper(node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
return isHelper(node.object) || isHelper(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
return node.name === "require" || node.name[0] === "_";
|
||||
} else if (t.isCallExpression(node)) {
|
||||
return isHelper(node.callee);
|
||||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
|
||||
return t.isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isType(node) {
|
||||
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) || t.isIdentifier(node) || t.isMemberExpression(node);
|
||||
}
|
||||
|
||||
const nodes = {
|
||||
AssignmentExpression(node) {
|
||||
const state = crawl(node.right);
|
||||
|
||||
if (state.hasCall && state.hasHelper || state.hasFunction) {
|
||||
return {
|
||||
before: state.hasFunction,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
SwitchCase(node, parent) {
|
||||
return {
|
||||
before: !!node.consequent.length || parent.cases[0] === node,
|
||||
after: !node.consequent.length && parent.cases[parent.cases.length - 1] === node
|
||||
};
|
||||
},
|
||||
|
||||
LogicalExpression(node) {
|
||||
if (t.isFunction(node.left) || t.isFunction(node.right)) {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
Literal(node) {
|
||||
if (t.isStringLiteral(node) && node.value === "use strict") {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if (t.isFunction(node.callee) || isHelper(node)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
OptionalCallExpression(node) {
|
||||
if (t.isFunction(node.callee)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
VariableDeclaration(node) {
|
||||
for (let i = 0; i < node.declarations.length; i++) {
|
||||
const declar = node.declarations[i];
|
||||
let enabled = isHelper(declar.id) && !isType(declar.init);
|
||||
|
||||
if (!enabled) {
|
||||
const state = crawl(declar.init);
|
||||
enabled = isHelper(declar.init) && state.hasCall || state.hasFunction;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
IfStatement(node) {
|
||||
if (t.isBlockStatement(node.consequent)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
exports.nodes = nodes;
|
||||
|
||||
nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
nodes.ObjectTypeCallProperty = function (node, parent) {
|
||||
var _parent$properties;
|
||||
|
||||
if (parent.callProperties[0] === node && !((_parent$properties = parent.properties) != null && _parent$properties.length)) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
nodes.ObjectTypeIndexer = function (node, parent) {
|
||||
var _parent$properties2, _parent$callPropertie;
|
||||
|
||||
if (parent.indexers[0] === node && !((_parent$properties2 = parent.properties) != null && _parent$properties2.length) && !((_parent$callPropertie = parent.callProperties) != null && _parent$callPropertie.length)) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
nodes.ObjectTypeInternalSlot = function (node, parent) {
|
||||
var _parent$properties3, _parent$callPropertie2, _parent$indexers;
|
||||
|
||||
if (parent.internalSlots[0] === node && !((_parent$properties3 = parent.properties) != null && _parent$properties3.length) && !((_parent$callPropertie2 = parent.callProperties) != null && _parent$callPropertie2.length) && !((_parent$indexers = parent.indexers) != null && _parent$indexers.length)) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const list = {
|
||||
VariableDeclaration(node) {
|
||||
return node.declarations.map(decl => decl.init);
|
||||
},
|
||||
|
||||
ArrayExpression(node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression(node) {
|
||||
return node.properties;
|
||||
}
|
||||
|
||||
};
|
||||
exports.list = list;
|
||||
[["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) {
|
||||
if (typeof amounts === "boolean") {
|
||||
amounts = {
|
||||
after: amounts,
|
||||
before: amounts
|
||||
};
|
||||
}
|
||||
|
||||
[type].concat(t.FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) {
|
||||
nodes[type] = function () {
|
||||
return amounts;
|
||||
};
|
||||
});
|
||||
});
|
|
@ -1,505 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _buffer = require("./buffer");
|
||||
|
||||
var n = require("./node");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var generatorFunctions = require("./generators");
|
||||
|
||||
const SCIENTIFIC_NOTATION = /e/i;
|
||||
const ZERO_DECIMAL_INTEGER = /\.0+$/;
|
||||
const NON_DECIMAL_LITERAL = /^0[box]/;
|
||||
const PURE_ANNOTATION_RE = /^\s*[@#]__PURE__\s*$/;
|
||||
|
||||
class Printer {
|
||||
constructor(format, map) {
|
||||
this.inForStatementInitCounter = 0;
|
||||
this._printStack = [];
|
||||
this._indent = 0;
|
||||
this._insideAux = false;
|
||||
this._parenPushNewlineState = null;
|
||||
this._noLineTerminator = false;
|
||||
this._printAuxAfterOnNextUserNode = false;
|
||||
this._printedComments = new WeakSet();
|
||||
this._endsWithInteger = false;
|
||||
this._endsWithWord = false;
|
||||
this.format = format;
|
||||
this._buf = new _buffer.default(map);
|
||||
}
|
||||
|
||||
generate(ast) {
|
||||
this.print(ast);
|
||||
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
return this._buf.get();
|
||||
}
|
||||
|
||||
indent() {
|
||||
if (this.format.compact || this.format.concise) return;
|
||||
this._indent++;
|
||||
}
|
||||
|
||||
dedent() {
|
||||
if (this.format.compact || this.format.concise) return;
|
||||
this._indent--;
|
||||
}
|
||||
|
||||
semicolon(force = false) {
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._append(";", !force);
|
||||
}
|
||||
|
||||
rightBrace() {
|
||||
if (this.format.minified) {
|
||||
this._buf.removeLastSemicolon();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
space(force = false) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (this._buf.hasContent() && !this.endsWith(" ") && !this.endsWith("\n") || force) {
|
||||
this._space();
|
||||
}
|
||||
}
|
||||
|
||||
word(str) {
|
||||
if (this._endsWithWord || this.endsWith("/") && str.indexOf("/") === 0) {
|
||||
this._space();
|
||||
}
|
||||
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._append(str);
|
||||
|
||||
this._endsWithWord = true;
|
||||
}
|
||||
|
||||
number(str) {
|
||||
this.word(str);
|
||||
this._endsWithInteger = Number.isInteger(+str) && !NON_DECIMAL_LITERAL.test(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str[str.length - 1] !== ".";
|
||||
}
|
||||
|
||||
token(str) {
|
||||
if (str === "--" && this.endsWith("!") || str[0] === "+" && this.endsWith("+") || str[0] === "-" && this.endsWith("-") || str[0] === "." && this._endsWithInteger) {
|
||||
this._space();
|
||||
}
|
||||
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._append(str);
|
||||
}
|
||||
|
||||
newline(i) {
|
||||
if (this.format.retainLines || this.format.compact) return;
|
||||
|
||||
if (this.format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.endsWith("\n\n")) return;
|
||||
if (typeof i !== "number") i = 1;
|
||||
i = Math.min(2, i);
|
||||
if (this.endsWith("{\n") || this.endsWith(":\n")) i--;
|
||||
if (i <= 0) return;
|
||||
|
||||
for (let j = 0; j < i; j++) {
|
||||
this._newline();
|
||||
}
|
||||
}
|
||||
|
||||
endsWith(str) {
|
||||
return this._buf.endsWith(str);
|
||||
}
|
||||
|
||||
removeTrailingNewline() {
|
||||
this._buf.removeTrailingNewline();
|
||||
}
|
||||
|
||||
exactSource(loc, cb) {
|
||||
this._catchUp("start", loc);
|
||||
|
||||
this._buf.exactSource(loc, cb);
|
||||
}
|
||||
|
||||
source(prop, loc) {
|
||||
this._catchUp(prop, loc);
|
||||
|
||||
this._buf.source(prop, loc);
|
||||
}
|
||||
|
||||
withSource(prop, loc, cb) {
|
||||
this._catchUp(prop, loc);
|
||||
|
||||
this._buf.withSource(prop, loc, cb);
|
||||
}
|
||||
|
||||
_space() {
|
||||
this._append(" ", true);
|
||||
}
|
||||
|
||||
_newline() {
|
||||
this._append("\n", true);
|
||||
}
|
||||
|
||||
_append(str, queue = false) {
|
||||
this._maybeAddParen(str);
|
||||
|
||||
this._maybeIndent(str);
|
||||
|
||||
if (queue) this._buf.queue(str);else this._buf.append(str);
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
}
|
||||
|
||||
_maybeIndent(str) {
|
||||
if (this._indent && this.endsWith("\n") && str[0] !== "\n") {
|
||||
this._buf.queue(this._getIndent());
|
||||
}
|
||||
}
|
||||
|
||||
_maybeAddParen(str) {
|
||||
const parenPushNewlineState = this._parenPushNewlineState;
|
||||
if (!parenPushNewlineState) return;
|
||||
let i;
|
||||
|
||||
for (i = 0; i < str.length && str[i] === " "; i++) continue;
|
||||
|
||||
if (i === str.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cha = str[i];
|
||||
|
||||
if (cha !== "\n") {
|
||||
if (cha !== "/" || i + 1 === str.length) {
|
||||
this._parenPushNewlineState = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const chaPost = str[i + 1];
|
||||
|
||||
if (chaPost === "*") {
|
||||
if (PURE_ANNOTATION_RE.test(str.slice(i + 2, str.length - 2))) {
|
||||
return;
|
||||
}
|
||||
} else if (chaPost !== "/") {
|
||||
this._parenPushNewlineState = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.indent();
|
||||
parenPushNewlineState.printed = true;
|
||||
}
|
||||
|
||||
_catchUp(prop, loc) {
|
||||
if (!this.format.retainLines) return;
|
||||
const pos = loc ? loc[prop] : null;
|
||||
|
||||
if ((pos == null ? void 0 : pos.line) != null) {
|
||||
const count = pos.line - this._buf.getCurrentLine();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
this._newline();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_getIndent() {
|
||||
return this.format.indent.style.repeat(this._indent);
|
||||
}
|
||||
|
||||
startTerminatorless(isLabel = false) {
|
||||
if (isLabel) {
|
||||
this._noLineTerminator = true;
|
||||
return null;
|
||||
} else {
|
||||
return this._parenPushNewlineState = {
|
||||
printed: false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
endTerminatorless(state) {
|
||||
this._noLineTerminator = false;
|
||||
|
||||
if (state != null && state.printed) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.token(")");
|
||||
}
|
||||
}
|
||||
|
||||
print(node, parent) {
|
||||
if (!node) return;
|
||||
const oldConcise = this.format.concise;
|
||||
|
||||
if (node._compact) {
|
||||
this.format.concise = true;
|
||||
}
|
||||
|
||||
const printMethod = this[node.type];
|
||||
|
||||
if (!printMethod) {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node == null ? void 0 : node.constructor.name)}`);
|
||||
}
|
||||
|
||||
this._printStack.push(node);
|
||||
|
||||
const oldInAux = this._insideAux;
|
||||
this._insideAux = !node.loc;
|
||||
|
||||
this._maybeAddAuxComment(this._insideAux && !oldInAux);
|
||||
|
||||
let needsParens = n.needsParens(node, parent, this._printStack);
|
||||
|
||||
if (this.format.retainFunctionParens && node.type === "FunctionExpression" && node.extra && node.extra.parenthesized) {
|
||||
needsParens = true;
|
||||
}
|
||||
|
||||
if (needsParens) this.token("(");
|
||||
|
||||
this._printLeadingComments(node);
|
||||
|
||||
const loc = t.isProgram(node) || t.isFile(node) ? null : node.loc;
|
||||
this.withSource("start", loc, () => {
|
||||
printMethod.call(this, node, parent);
|
||||
});
|
||||
|
||||
this._printTrailingComments(node);
|
||||
|
||||
if (needsParens) this.token(")");
|
||||
|
||||
this._printStack.pop();
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
this._insideAux = oldInAux;
|
||||
}
|
||||
|
||||
_maybeAddAuxComment(enteredPositionlessNode) {
|
||||
if (enteredPositionlessNode) this._printAuxBeforeComment();
|
||||
if (!this._insideAux) this._printAuxAfterComment();
|
||||
}
|
||||
|
||||
_printAuxBeforeComment() {
|
||||
if (this._printAuxAfterOnNextUserNode) return;
|
||||
this._printAuxAfterOnNextUserNode = true;
|
||||
const comment = this.format.auxiliaryCommentBefore;
|
||||
|
||||
if (comment) {
|
||||
this._printComment({
|
||||
type: "CommentBlock",
|
||||
value: comment
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_printAuxAfterComment() {
|
||||
if (!this._printAuxAfterOnNextUserNode) return;
|
||||
this._printAuxAfterOnNextUserNode = false;
|
||||
const comment = this.format.auxiliaryCommentAfter;
|
||||
|
||||
if (comment) {
|
||||
this._printComment({
|
||||
type: "CommentBlock",
|
||||
value: comment
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getPossibleRaw(node) {
|
||||
const extra = node.extra;
|
||||
|
||||
if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) {
|
||||
return extra.raw;
|
||||
}
|
||||
}
|
||||
|
||||
printJoin(nodes, parent, opts = {}) {
|
||||
if (!(nodes != null && nodes.length)) return;
|
||||
if (opts.indent) this.indent();
|
||||
const newlineOpts = {
|
||||
addNewlines: opts.addNewlines
|
||||
};
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const node = nodes[i];
|
||||
if (!node) continue;
|
||||
if (opts.statement) this._printNewline(true, node, parent, newlineOpts);
|
||||
this.print(node, parent);
|
||||
|
||||
if (opts.iterator) {
|
||||
opts.iterator(node, i);
|
||||
}
|
||||
|
||||
if (opts.separator && i < nodes.length - 1) {
|
||||
opts.separator.call(this);
|
||||
}
|
||||
|
||||
if (opts.statement) this._printNewline(false, node, parent, newlineOpts);
|
||||
}
|
||||
|
||||
if (opts.indent) this.dedent();
|
||||
}
|
||||
|
||||
printAndIndentOnComments(node, parent) {
|
||||
const indent = node.leadingComments && node.leadingComments.length > 0;
|
||||
if (indent) this.indent();
|
||||
this.print(node, parent);
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
|
||||
printBlock(parent) {
|
||||
const node = parent.body;
|
||||
|
||||
if (!t.isEmptyStatement(node)) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node, parent);
|
||||
}
|
||||
|
||||
_printTrailingComments(node) {
|
||||
this._printComments(this._getComments(false, node));
|
||||
}
|
||||
|
||||
_printLeadingComments(node) {
|
||||
this._printComments(this._getComments(true, node), true);
|
||||
}
|
||||
|
||||
printInnerComments(node, indent = true) {
|
||||
var _node$innerComments;
|
||||
|
||||
if (!((_node$innerComments = node.innerComments) != null && _node$innerComments.length)) return;
|
||||
if (indent) this.indent();
|
||||
|
||||
this._printComments(node.innerComments);
|
||||
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
|
||||
printSequence(nodes, parent, opts = {}) {
|
||||
opts.statement = true;
|
||||
return this.printJoin(nodes, parent, opts);
|
||||
}
|
||||
|
||||
printList(items, parent, opts = {}) {
|
||||
if (opts.separator == null) {
|
||||
opts.separator = commaSeparator;
|
||||
}
|
||||
|
||||
return this.printJoin(items, parent, opts);
|
||||
}
|
||||
|
||||
_printNewline(leading, node, parent, opts) {
|
||||
if (this.format.retainLines || this.format.compact) return;
|
||||
|
||||
if (this.format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
|
||||
let lines = 0;
|
||||
|
||||
if (this._buf.hasContent()) {
|
||||
if (!leading) lines++;
|
||||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0;
|
||||
const needs = leading ? n.needsWhitespaceBefore : n.needsWhitespaceAfter;
|
||||
if (needs(node, parent)) lines++;
|
||||
}
|
||||
|
||||
this.newline(lines);
|
||||
}
|
||||
|
||||
_getComments(leading, node) {
|
||||
return node && (leading ? node.leadingComments : node.trailingComments) || [];
|
||||
}
|
||||
|
||||
_printComment(comment, skipNewLines) {
|
||||
if (!this.format.shouldPrintComment(comment.value)) return;
|
||||
if (comment.ignore) return;
|
||||
if (this._printedComments.has(comment)) return;
|
||||
|
||||
this._printedComments.add(comment);
|
||||
|
||||
const isBlockComment = comment.type === "CommentBlock";
|
||||
const printNewLines = isBlockComment && !skipNewLines && !this._noLineTerminator;
|
||||
if (printNewLines && this._buf.hasContent()) this.newline(1);
|
||||
if (!this.endsWith("[") && !this.endsWith("{")) this.space();
|
||||
let val = !isBlockComment && !this._noLineTerminator ? `//${comment.value}\n` : `/*${comment.value}*/`;
|
||||
|
||||
if (isBlockComment && this.format.indent.adjustMultilineComment) {
|
||||
var _comment$loc;
|
||||
|
||||
const offset = (_comment$loc = comment.loc) == null ? void 0 : _comment$loc.start.column;
|
||||
|
||||
if (offset) {
|
||||
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
}
|
||||
|
||||
const indentSize = Math.max(this._getIndent().length, this.format.retainLines ? 0 : this._buf.getCurrentColumn());
|
||||
val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
|
||||
}
|
||||
|
||||
if (this.endsWith("/")) this._space();
|
||||
this.withSource("start", comment.loc, () => {
|
||||
this._append(val);
|
||||
});
|
||||
if (printNewLines) this.newline(1);
|
||||
}
|
||||
|
||||
_printComments(comments, inlinePureAnnotation) {
|
||||
if (!(comments != null && comments.length)) return;
|
||||
|
||||
if (inlinePureAnnotation && comments.length === 1 && PURE_ANNOTATION_RE.test(comments[0].value)) {
|
||||
this._printComment(comments[0], this._buf.hasContent() && !this.endsWith("\n"));
|
||||
} else {
|
||||
for (const comment of comments) {
|
||||
this._printComment(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printAssertions(node) {
|
||||
var _node$assertions;
|
||||
|
||||
if ((_node$assertions = node.assertions) != null && _node$assertions.length) {
|
||||
this.space();
|
||||
this.word("assert");
|
||||
this.space();
|
||||
this.token("{");
|
||||
this.space();
|
||||
this.printList(node.assertions, node);
|
||||
this.space();
|
||||
this.token("}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.assign(Printer.prototype, generatorFunctions);
|
||||
{
|
||||
Printer.prototype.Noop = function Noop() {};
|
||||
}
|
||||
var _default = Printer;
|
||||
exports.default = _default;
|
||||
|
||||
function commaSeparator() {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _sourceMap = require("source-map");
|
||||
|
||||
class SourceMap {
|
||||
constructor(opts, code) {
|
||||
this._cachedMap = void 0;
|
||||
this._code = void 0;
|
||||
this._opts = void 0;
|
||||
this._rawMappings = void 0;
|
||||
this._lastGenLine = void 0;
|
||||
this._lastSourceLine = void 0;
|
||||
this._lastSourceColumn = void 0;
|
||||
this._cachedMap = null;
|
||||
this._code = code;
|
||||
this._opts = opts;
|
||||
this._rawMappings = [];
|
||||
}
|
||||
|
||||
get() {
|
||||
if (!this._cachedMap) {
|
||||
const map = this._cachedMap = new _sourceMap.SourceMapGenerator({
|
||||
sourceRoot: this._opts.sourceRoot
|
||||
});
|
||||
const code = this._code;
|
||||
|
||||
if (typeof code === "string") {
|
||||
map.setSourceContent(this._opts.sourceFileName.replace(/\\/g, "/"), code);
|
||||
} else if (typeof code === "object") {
|
||||
Object.keys(code).forEach(sourceFileName => {
|
||||
map.setSourceContent(sourceFileName.replace(/\\/g, "/"), code[sourceFileName]);
|
||||
});
|
||||
}
|
||||
|
||||
this._rawMappings.forEach(mapping => map.addMapping(mapping), map);
|
||||
}
|
||||
|
||||
return this._cachedMap.toJSON();
|
||||
}
|
||||
|
||||
getRawMappings() {
|
||||
return this._rawMappings.slice();
|
||||
}
|
||||
|
||||
mark(generatedLine, generatedColumn, line, column, identifierName, filename, force) {
|
||||
if (this._lastGenLine !== generatedLine && line === null) return;
|
||||
|
||||
if (!force && this._lastGenLine === generatedLine && this._lastSourceLine === line && this._lastSourceColumn === column) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._cachedMap = null;
|
||||
this._lastGenLine = generatedLine;
|
||||
this._lastSourceLine = line;
|
||||
this._lastSourceColumn = column;
|
||||
|
||||
this._rawMappings.push({
|
||||
name: identifierName || undefined,
|
||||
generated: {
|
||||
line: generatedLine,
|
||||
column: generatedColumn
|
||||
},
|
||||
source: line == null ? undefined : (filename || this._opts.sourceFileName).replace(/\\/g, "/"),
|
||||
original: line == null ? undefined : {
|
||||
line: line,
|
||||
column: column
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = SourceMap;
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
"name": "@babel/generator",
|
||||
"version": "7.14.3",
|
||||
"description": "Turns an AST into code.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-generator"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-generator",
|
||||
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20generator%22+is%3Aopen",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.14.2",
|
||||
"jsesc": "^2.5.1",
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-fixtures": "7.13.13",
|
||||
"@babel/parser": "7.14.3",
|
||||
"@types/jsesc": "^2.5.0",
|
||||
"@types/source-map": "^0.5.0"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/helper-function-name
|
||||
|
||||
> Helper function to change the property 'name' of every function
|
||||
|
||||
See our website [@babel/helper-function-name](https://babeljs.io/docs/en/babel-helper-function-name) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-function-name
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-function-name --dev
|
||||
```
|
|
@ -1,172 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
var _helperGetFunctionArity = require("@babel/helper-get-function-arity");
|
||||
|
||||
var _template = require("@babel/template");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const buildPropertyMethodAssignmentWrapper = (0, _template.default)(`
|
||||
(function (FUNCTION_KEY) {
|
||||
function FUNCTION_ID() {
|
||||
return FUNCTION_KEY.apply(this, arguments);
|
||||
}
|
||||
|
||||
FUNCTION_ID.toString = function () {
|
||||
return FUNCTION_KEY.toString();
|
||||
}
|
||||
|
||||
return FUNCTION_ID;
|
||||
})(FUNCTION)
|
||||
`);
|
||||
const buildGeneratorPropertyMethodAssignmentWrapper = (0, _template.default)(`
|
||||
(function (FUNCTION_KEY) {
|
||||
function* FUNCTION_ID() {
|
||||
return yield* FUNCTION_KEY.apply(this, arguments);
|
||||
}
|
||||
|
||||
FUNCTION_ID.toString = function () {
|
||||
return FUNCTION_KEY.toString();
|
||||
};
|
||||
|
||||
return FUNCTION_ID;
|
||||
})(FUNCTION)
|
||||
`);
|
||||
const visitor = {
|
||||
"ReferencedIdentifier|BindingIdentifier"(path, state) {
|
||||
if (path.node.name !== state.name) return;
|
||||
const localDeclar = path.scope.getBindingIdentifier(state.name);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
state.selfReference = true;
|
||||
path.stop();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function getNameFromLiteralId(id) {
|
||||
if (t.isNullLiteral(id)) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (t.isRegExpLiteral(id)) {
|
||||
return `_${id.pattern}_${id.flags}`;
|
||||
}
|
||||
|
||||
if (t.isTemplateLiteral(id)) {
|
||||
return id.quasis.map(quasi => quasi.value.raw).join("");
|
||||
}
|
||||
|
||||
if (id.value !== undefined) {
|
||||
return id.value + "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
function wrap(state, method, id, scope) {
|
||||
if (state.selfReference) {
|
||||
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
|
||||
scope.rename(id.name);
|
||||
} else {
|
||||
if (!t.isFunction(method)) return;
|
||||
let build = buildPropertyMethodAssignmentWrapper;
|
||||
|
||||
if (method.generator) {
|
||||
build = buildGeneratorPropertyMethodAssignmentWrapper;
|
||||
}
|
||||
|
||||
const template = build({
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||
}).expression;
|
||||
const params = template.callee.body.body[0].params;
|
||||
|
||||
for (let i = 0, len = (0, _helperGetFunctionArity.default)(method); i < len; i++) {
|
||||
params.push(scope.generateUidIdentifier("x"));
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
method.id = id;
|
||||
scope.getProgramParent().references[id.name] = true;
|
||||
}
|
||||
|
||||
function visit(node, name, scope) {
|
||||
const state = {
|
||||
selfAssignment: false,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(name),
|
||||
references: [],
|
||||
name: name
|
||||
};
|
||||
const binding = scope.getOwnBinding(name);
|
||||
|
||||
if (binding) {
|
||||
if (binding.kind === "param") {
|
||||
state.selfReference = true;
|
||||
} else {}
|
||||
} else if (state.outerDeclar || scope.hasGlobal(name)) {
|
||||
scope.traverse(node, visitor, state);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
function _default({
|
||||
node,
|
||||
parent,
|
||||
scope,
|
||||
id
|
||||
}, localBinding = false) {
|
||||
if (node.id) return;
|
||||
|
||||
if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, {
|
||||
kind: "method"
|
||||
})) && (!parent.computed || t.isLiteral(parent.key))) {
|
||||
id = parent.key;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
id = parent.id;
|
||||
|
||||
if (t.isIdentifier(id) && !localBinding) {
|
||||
const binding = scope.parent.getBinding(id.name);
|
||||
|
||||
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
|
||||
node.id = t.cloneNode(id);
|
||||
node.id[t.NOT_LOCAL_BINDING] = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (t.isAssignmentExpression(parent, {
|
||||
operator: "="
|
||||
})) {
|
||||
id = parent.left;
|
||||
} else if (!id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let name;
|
||||
|
||||
if (id && t.isLiteral(id)) {
|
||||
name = getNameFromLiteralId(id);
|
||||
} else if (id && t.isIdentifier(id)) {
|
||||
name = id.name;
|
||||
}
|
||||
|
||||
if (name === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
name = t.toBindingIdentifierName(name);
|
||||
id = t.identifier(name);
|
||||
id[t.NOT_LOCAL_BINDING] = true;
|
||||
const state = visit(node, name, scope);
|
||||
return wrap(state, node, id, scope) || node;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"name": "@babel/helper-function-name",
|
||||
"version": "7.14.2",
|
||||
"description": "Helper function to change the property 'name' of every function",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-function-name"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-function-name",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-get-function-arity": "^7.12.13",
|
||||
"@babel/template": "^7.12.13",
|
||||
"@babel/types": "^7.14.2"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/helper-get-function-arity
|
||||
|
||||
> Helper function to get function arity
|
||||
|
||||
See our website [@babel/helper-get-function-arity](https://babeljs.io/docs/en/babel-helper-get-function-arity) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-get-function-arity
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-get-function-arity --dev
|
||||
```
|
|
@ -1,26 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _default(node) {
|
||||
const params = node.params;
|
||||
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
const param = params[i];
|
||||
|
||||
if (t.isAssignmentPattern(param) || t.isRestElement(param)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return params.length;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "@babel/helper-get-function-arity",
|
||||
"version": "7.12.13",
|
||||
"description": "Helper function to get function arity",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-get-function-arity"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-get-function-arity",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.12.13"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/helper-split-export-declaration
|
||||
|
||||
>
|
||||
|
||||
See our website [@babel/helper-split-export-declaration](https://babeljs.io/docs/en/babel-helper-split-export-declaration) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-split-export-declaration
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-split-export-declaration --dev
|
||||
```
|
|
@ -1,62 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = splitExportDeclaration;
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function splitExportDeclaration(exportDeclaration) {
|
||||
if (!exportDeclaration.isExportDeclaration()) {
|
||||
throw new Error("Only export declarations can be split.");
|
||||
}
|
||||
|
||||
const isDefault = exportDeclaration.isExportDefaultDeclaration();
|
||||
const declaration = exportDeclaration.get("declaration");
|
||||
const isClassDeclaration = declaration.isClassDeclaration();
|
||||
|
||||
if (isDefault) {
|
||||
const standaloneDeclaration = declaration.isFunctionDeclaration() || isClassDeclaration;
|
||||
const scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
|
||||
let id = declaration.node.id;
|
||||
let needBindingRegistration = false;
|
||||
|
||||
if (!id) {
|
||||
needBindingRegistration = true;
|
||||
id = scope.generateUidIdentifier("default");
|
||||
|
||||
if (standaloneDeclaration || declaration.isFunctionExpression() || declaration.isClassExpression()) {
|
||||
declaration.node.id = t.cloneNode(id);
|
||||
}
|
||||
}
|
||||
|
||||
const updatedDeclaration = standaloneDeclaration ? declaration : t.variableDeclaration("var", [t.variableDeclarator(t.cloneNode(id), declaration.node)]);
|
||||
const updatedExportDeclaration = t.exportNamedDeclaration(null, [t.exportSpecifier(t.cloneNode(id), t.identifier("default"))]);
|
||||
exportDeclaration.insertAfter(updatedExportDeclaration);
|
||||
exportDeclaration.replaceWith(updatedDeclaration);
|
||||
|
||||
if (needBindingRegistration) {
|
||||
scope.registerDeclaration(exportDeclaration);
|
||||
}
|
||||
|
||||
return exportDeclaration;
|
||||
}
|
||||
|
||||
if (exportDeclaration.get("specifiers").length > 0) {
|
||||
throw new Error("It doesn't make sense to split exported specifiers.");
|
||||
}
|
||||
|
||||
const bindingIdentifiers = declaration.getOuterBindingIdentifiers();
|
||||
const specifiers = Object.keys(bindingIdentifiers).map(name => {
|
||||
return t.exportSpecifier(t.identifier(name), t.identifier(name));
|
||||
});
|
||||
const aliasDeclar = t.exportNamedDeclaration(null, specifiers);
|
||||
exportDeclaration.insertAfter(aliasDeclar);
|
||||
exportDeclaration.replaceWith(declaration.node);
|
||||
return exportDeclaration;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "@babel/helper-split-export-declaration",
|
||||
"version": "7.12.13",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-split-export-declaration"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-split-export-declaration",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.12.13"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/helper-validator-identifier
|
||||
|
||||
> Validate identifier/keywords name
|
||||
|
||||
See our website [@babel/helper-validator-identifier](https://babeljs.io/docs/en/babel-helper-validator-identifier) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-validator-identifier
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-validator-identifier --dev
|
||||
```
|
|
@ -1,84 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isIdentifierStart = isIdentifierStart;
|
||||
exports.isIdentifierChar = isIdentifierChar;
|
||||
exports.isIdentifierName = isIdentifierName;
|
||||
let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
|
||||
let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
|
||||
const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
||||
const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
||||
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
|
||||
const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 107, 20, 28, 22, 13, 52, 76, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 230, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 190, 0, 80, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8952, 286, 50, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 2357, 44, 11, 6, 17, 0, 370, 43, 1301, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42717, 35, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938];
|
||||
const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 419, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
||||
|
||||
function isInAstralSet(code, set) {
|
||||
let pos = 0x10000;
|
||||
|
||||
for (let i = 0, length = set.length; i < length; i += 2) {
|
||||
pos += set[i];
|
||||
if (pos > code) return false;
|
||||
pos += set[i + 1];
|
||||
if (pos >= code) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isIdentifierStart(code) {
|
||||
if (code < 65) return code === 36;
|
||||
if (code <= 90) return true;
|
||||
if (code < 97) return code === 95;
|
||||
if (code <= 122) return true;
|
||||
|
||||
if (code <= 0xffff) {
|
||||
return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
|
||||
}
|
||||
|
||||
return isInAstralSet(code, astralIdentifierStartCodes);
|
||||
}
|
||||
|
||||
function isIdentifierChar(code) {
|
||||
if (code < 48) return code === 36;
|
||||
if (code < 58) return true;
|
||||
if (code < 65) return false;
|
||||
if (code <= 90) return true;
|
||||
if (code < 97) return code === 95;
|
||||
if (code <= 122) return true;
|
||||
|
||||
if (code <= 0xffff) {
|
||||
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
|
||||
}
|
||||
|
||||
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
|
||||
}
|
||||
|
||||
function isIdentifierName(name) {
|
||||
let isFirst = true;
|
||||
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
let cp = name.charCodeAt(i);
|
||||
|
||||
if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) {
|
||||
const trail = name.charCodeAt(++i);
|
||||
|
||||
if ((trail & 0xfc00) === 0xdc00) {
|
||||
cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
|
||||
if (!isIdentifierStart(cp)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!isIdentifierChar(cp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !isFirst;
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "isIdentifierName", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _identifier.isIdentifierName;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isIdentifierChar", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _identifier.isIdentifierChar;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isIdentifierStart", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _identifier.isIdentifierStart;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isStrictBindOnlyReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isStrictBindReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isStrictBindReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isStrictReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isStrictReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isKeyword", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isKeyword;
|
||||
}
|
||||
});
|
||||
|
||||
var _identifier = require("./identifier");
|
||||
|
||||
var _keyword = require("./keyword");
|
|
@ -1,38 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isReservedWord = isReservedWord;
|
||||
exports.isStrictReservedWord = isStrictReservedWord;
|
||||
exports.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
|
||||
exports.isStrictBindReservedWord = isStrictBindReservedWord;
|
||||
exports.isKeyword = isKeyword;
|
||||
const reservedWords = {
|
||||
keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
|
||||
strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
|
||||
strictBind: ["eval", "arguments"]
|
||||
};
|
||||
const keywords = new Set(reservedWords.keyword);
|
||||
const reservedWordsStrictSet = new Set(reservedWords.strict);
|
||||
const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
|
||||
|
||||
function isReservedWord(word, inModule) {
|
||||
return inModule && word === "await" || word === "enum";
|
||||
}
|
||||
|
||||
function isStrictReservedWord(word, inModule) {
|
||||
return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
|
||||
}
|
||||
|
||||
function isStrictBindOnlyReservedWord(word) {
|
||||
return reservedWordsStrictBindSet.has(word);
|
||||
}
|
||||
|
||||
function isStrictBindReservedWord(word, inModule) {
|
||||
return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
|
||||
}
|
||||
|
||||
function isKeyword(word) {
|
||||
return keywords.has(word);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "@babel/helper-validator-identifier",
|
||||
"version": "7.14.0",
|
||||
"description": "Validate identifier/keywords name",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-validator-identifier"
|
||||
},
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"exports": "./lib/index.js",
|
||||
"devDependencies": {
|
||||
"@babel/helper-validator-identifier-baseline": "npm:@babel/helper-validator-identifier@7.10.4",
|
||||
"@unicode/unicode-13.0.0": "^1.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"charcodes": "^0.2.0"
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
// Always use the latest available version of Unicode!
|
||||
// https://tc39.github.io/ecma262/#sec-conformance
|
||||
const version = "13.0.0";
|
||||
|
||||
const start = require("@unicode/unicode-" +
|
||||
version +
|
||||
"/Binary_Property/ID_Start/code-points.js").filter(function (ch) {
|
||||
return ch > 0x7f;
|
||||
});
|
||||
let last = -1;
|
||||
const cont = [0x200c, 0x200d].concat(
|
||||
require("@unicode/unicode-" +
|
||||
version +
|
||||
"/Binary_Property/ID_Continue/code-points.js").filter(function (ch) {
|
||||
return ch > 0x7f && search(start, ch, last + 1) == -1;
|
||||
})
|
||||
);
|
||||
|
||||
function search(arr, ch, starting) {
|
||||
for (let i = starting; arr[i] <= ch && i < arr.length; last = i++) {
|
||||
if (arr[i] === ch) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function pad(str, width) {
|
||||
while (str.length < width) str = "0" + str;
|
||||
return str;
|
||||
}
|
||||
|
||||
function esc(code) {
|
||||
const hex = code.toString(16);
|
||||
if (hex.length <= 2) return "\\x" + pad(hex, 2);
|
||||
else return "\\u" + pad(hex, 4);
|
||||
}
|
||||
|
||||
function generate(chars) {
|
||||
const astral = [];
|
||||
let re = "";
|
||||
for (let i = 0, at = 0x10000; i < chars.length; i++) {
|
||||
const from = chars[i];
|
||||
let to = from;
|
||||
while (i < chars.length - 1 && chars[i + 1] == to + 1) {
|
||||
i++;
|
||||
to++;
|
||||
}
|
||||
if (to <= 0xffff) {
|
||||
if (from == to) re += esc(from);
|
||||
else if (from + 1 == to) re += esc(from) + esc(to);
|
||||
else re += esc(from) + "-" + esc(to);
|
||||
} else {
|
||||
astral.push(from - at, to - from);
|
||||
at = to;
|
||||
}
|
||||
}
|
||||
return { nonASCII: re, astral: astral };
|
||||
}
|
||||
|
||||
const startData = generate(start);
|
||||
const contData = generate(cont);
|
||||
|
||||
console.log("/* prettier-ignore */");
|
||||
console.log('let nonASCIIidentifierStartChars = "' + startData.nonASCII + '";');
|
||||
console.log("/* prettier-ignore */");
|
||||
console.log('let nonASCIIidentifierChars = "' + contData.nonASCII + '";');
|
||||
console.log("/* prettier-ignore */");
|
||||
console.log(
|
||||
"const astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";"
|
||||
);
|
||||
console.log("/* prettier-ignore */");
|
||||
console.log(
|
||||
"const astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";"
|
||||
);
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/highlight
|
||||
|
||||
> Syntax highlight JavaScript strings for output in terminals.
|
||||
|
||||
See our website [@babel/highlight](https://babeljs.io/docs/en/babel-highlight) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/highlight
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/highlight --dev
|
||||
```
|
|
@ -1,115 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.shouldHighlight = shouldHighlight;
|
||||
exports.getChalk = getChalk;
|
||||
exports.default = highlight;
|
||||
|
||||
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
|
||||
|
||||
const jsTokens = require("js-tokens");
|
||||
|
||||
const Chalk = require("chalk");
|
||||
|
||||
const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]);
|
||||
|
||||
function getDefs(chalk) {
|
||||
return {
|
||||
keyword: chalk.cyan,
|
||||
capitalized: chalk.yellow,
|
||||
jsxIdentifier: chalk.yellow,
|
||||
punctuator: chalk.yellow,
|
||||
number: chalk.magenta,
|
||||
string: chalk.green,
|
||||
regex: chalk.magenta,
|
||||
comment: chalk.grey,
|
||||
invalid: chalk.white.bgRed.bold
|
||||
};
|
||||
}
|
||||
|
||||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
||||
const BRACKET = /^[()[\]{}]$/;
|
||||
let tokenize;
|
||||
{
|
||||
const JSX_TAG = /^[a-z][\w-]*$/i;
|
||||
|
||||
const getTokenType = function (token, offset, text) {
|
||||
if (token.type === "name") {
|
||||
if ((0, _helperValidatorIdentifier.isKeyword)(token.value) || (0, _helperValidatorIdentifier.isStrictReservedWord)(token.value, true) || sometimesKeywords.has(token.value)) {
|
||||
return "keyword";
|
||||
}
|
||||
|
||||
if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
|
||||
return "jsxIdentifier";
|
||||
}
|
||||
|
||||
if (token.value[0] !== token.value[0].toLowerCase()) {
|
||||
return "capitalized";
|
||||
}
|
||||
}
|
||||
|
||||
if (token.type === "punctuator" && BRACKET.test(token.value)) {
|
||||
return "bracket";
|
||||
}
|
||||
|
||||
if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
|
||||
return "punctuator";
|
||||
}
|
||||
|
||||
return token.type;
|
||||
};
|
||||
|
||||
tokenize = function* (text) {
|
||||
let match;
|
||||
|
||||
while (match = jsTokens.default.exec(text)) {
|
||||
const token = jsTokens.matchToToken(match);
|
||||
yield {
|
||||
type: getTokenType(token, match.index, text),
|
||||
value: token.value
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function highlightTokens(defs, text) {
|
||||
let highlighted = "";
|
||||
|
||||
for (const {
|
||||
type,
|
||||
value
|
||||
} of tokenize(text)) {
|
||||
const colorize = defs[type];
|
||||
|
||||
if (colorize) {
|
||||
highlighted += value.split(NEWLINE).map(str => colorize(str)).join("\n");
|
||||
} else {
|
||||
highlighted += value;
|
||||
}
|
||||
}
|
||||
|
||||
return highlighted;
|
||||
}
|
||||
|
||||
function shouldHighlight(options) {
|
||||
return !!Chalk.supportsColor || options.forceColor;
|
||||
}
|
||||
|
||||
function getChalk(options) {
|
||||
return options.forceColor ? new Chalk.constructor({
|
||||
enabled: true,
|
||||
level: 1
|
||||
}) : Chalk;
|
||||
}
|
||||
|
||||
function highlight(code, options = {}) {
|
||||
if (shouldHighlight(options)) {
|
||||
const chalk = getChalk(options);
|
||||
const defs = getDefs(chalk);
|
||||
return highlightTokens(defs, code);
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
{
|
||||
"name": "@babel/highlight",
|
||||
"version": "7.14.0",
|
||||
"description": "Syntax highlight JavaScript strings for output in terminals.",
|
||||
"author": "suchipi <me@suchipi.com>",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-highlight",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-highlight"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-validator-identifier": "^7.14.0",
|
||||
"chalk": "^2.0.0",
|
||||
"js-tokens": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^2.0.0",
|
||||
"strip-ansi": "^4.0.0"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,19 +0,0 @@
|
|||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @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
|
||||
```
|
|
@ -1,15 +0,0 @@
|
|||
#!/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, " "));
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"name": "@babel/parser",
|
||||
"version": "7.14.3",
|
||||
"description": "A JavaScript parser",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"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"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel-baseline/parser": "npm:@babel/parser@^7.14.0",
|
||||
"@babel/code-frame": "7.12.13",
|
||||
"@babel/helper-fixtures": "7.13.13",
|
||||
"@babel/helper-validator-identifier": "7.14.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"bin": "./bin/babel-parser.js"
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
// 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.
|
||||
*/
|
||||
export function parse(
|
||||
input: string,
|
||||
options?: ParserOptions
|
||||
): import("@babel/types").File;
|
||||
|
||||
/**
|
||||
* Parse the provided code as a single expression.
|
||||
*/
|
||||
export function parseExpression(
|
||||
input: string,
|
||||
options?: ParserOptions
|
||||
): import("@babel/types").Expression;
|
||||
|
||||
export 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;
|
||||
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export type ParserPlugin =
|
||||
| "asyncDoExpressions"
|
||||
| "asyncGenerators"
|
||||
| "bigInt"
|
||||
| "classPrivateMethods"
|
||||
| "classPrivateProperties"
|
||||
| "classProperties"
|
||||
| "classStaticBlock"
|
||||
| "decimal"
|
||||
| "decorators"
|
||||
| "decorators-legacy"
|
||||
| "doExpressions"
|
||||
| "dynamicImport"
|
||||
| "estree"
|
||||
| "exportDefaultFrom"
|
||||
| "exportNamespaceFrom" // deprecated
|
||||
| "flow"
|
||||
| "flowComments"
|
||||
| "functionBind"
|
||||
| "functionSent"
|
||||
| "importMeta"
|
||||
| "jsx"
|
||||
| "logicalAssignment"
|
||||
| "importAssertions"
|
||||
| "moduleStringNames"
|
||||
| "nullishCoalescingOperator"
|
||||
| "numericSeparator"
|
||||
| "objectRestSpread"
|
||||
| "optionalCatchBinding"
|
||||
| "optionalChaining"
|
||||
| "partialApplication"
|
||||
| "pipelineOperator"
|
||||
| "placeholders"
|
||||
| "privateIn"
|
||||
| "throwExpressions"
|
||||
| "topLevelAwait"
|
||||
| "typescript"
|
||||
| "v8intrinsic"
|
||||
| ParserPluginWithOptions;
|
||||
|
||||
export type ParserPluginWithOptions =
|
||||
| ["decorators", DecoratorsPluginOptions]
|
||||
| ["pipelineOperator", PipelineOperatorPluginOptions]
|
||||
| ["recordAndTuple", RecordAndTuplePluginOptions]
|
||||
| ["flow", FlowPluginOptions];
|
||||
|
||||
export interface DecoratorsPluginOptions {
|
||||
decoratorsBeforeExport?: boolean;
|
||||
}
|
||||
|
||||
export interface PipelineOperatorPluginOptions {
|
||||
proposal: "fsharp" | "minimal" | "smart";
|
||||
}
|
||||
|
||||
export interface RecordAndTuplePluginOptions {
|
||||
syntaxType: "bar" | "hash";
|
||||
}
|
||||
|
||||
export interface FlowPluginOptions {
|
||||
all?: boolean;
|
||||
}
|
||||
|
||||
export const tokTypes: {
|
||||
// todo(flow->ts) real token type
|
||||
[name: string]: any;
|
||||
};
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/template
|
||||
|
||||
> Generate an AST from a string template.
|
||||
|
||||
See our website [@babel/template](https://babeljs.io/docs/en/babel-template) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20template%22+is%3Aopen) associated with this package.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/template
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/template --dev
|
||||
```
|
|
@ -1,83 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = createTemplateBuilder;
|
||||
|
||||
var _options = require("./options");
|
||||
|
||||
var _string = _interopRequireDefault(require("./string"));
|
||||
|
||||
var _literal = _interopRequireDefault(require("./literal"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const NO_PLACEHOLDER = (0, _options.validate)({
|
||||
placeholderPattern: false
|
||||
});
|
||||
|
||||
function createTemplateBuilder(formatter, defaultOpts) {
|
||||
const templateFnCache = new WeakMap();
|
||||
const templateAstCache = new WeakMap();
|
||||
const cachedOpts = defaultOpts || (0, _options.validate)(null);
|
||||
return Object.assign((tpl, ...args) => {
|
||||
if (typeof tpl === "string") {
|
||||
if (args.length > 1) throw new Error("Unexpected extra params.");
|
||||
return extendedTrace((0, _string.default)(formatter, tpl, (0, _options.merge)(cachedOpts, (0, _options.validate)(args[0]))));
|
||||
} else if (Array.isArray(tpl)) {
|
||||
let builder = templateFnCache.get(tpl);
|
||||
|
||||
if (!builder) {
|
||||
builder = (0, _literal.default)(formatter, tpl, cachedOpts);
|
||||
templateFnCache.set(tpl, builder);
|
||||
}
|
||||
|
||||
return extendedTrace(builder(args));
|
||||
} else if (typeof tpl === "object" && tpl) {
|
||||
if (args.length > 0) throw new Error("Unexpected extra params.");
|
||||
return createTemplateBuilder(formatter, (0, _options.merge)(cachedOpts, (0, _options.validate)(tpl)));
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected template param ${typeof tpl}`);
|
||||
}, {
|
||||
ast: (tpl, ...args) => {
|
||||
if (typeof tpl === "string") {
|
||||
if (args.length > 1) throw new Error("Unexpected extra params.");
|
||||
return (0, _string.default)(formatter, tpl, (0, _options.merge)((0, _options.merge)(cachedOpts, (0, _options.validate)(args[0])), NO_PLACEHOLDER))();
|
||||
} else if (Array.isArray(tpl)) {
|
||||
let builder = templateAstCache.get(tpl);
|
||||
|
||||
if (!builder) {
|
||||
builder = (0, _literal.default)(formatter, tpl, (0, _options.merge)(cachedOpts, NO_PLACEHOLDER));
|
||||
templateAstCache.set(tpl, builder);
|
||||
}
|
||||
|
||||
return builder(args)();
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected template param ${typeof tpl}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function extendedTrace(fn) {
|
||||
let rootStack = "";
|
||||
|
||||
try {
|
||||
throw new Error();
|
||||
} catch (error) {
|
||||
if (error.stack) {
|
||||
rootStack = error.stack.split("\n").slice(3).join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return arg => {
|
||||
try {
|
||||
return fn(arg);
|
||||
} catch (err) {
|
||||
err.stack += `\n =============\n${rootStack}`;
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.program = exports.expression = exports.statement = exports.statements = exports.smart = void 0;
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function makeStatementFormatter(fn) {
|
||||
return {
|
||||
code: str => `/* @babel/template */;\n${str}`,
|
||||
validate: () => {},
|
||||
unwrap: ast => {
|
||||
return fn(ast.program.body.slice(1));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const smart = makeStatementFormatter(body => {
|
||||
if (body.length > 1) {
|
||||
return body;
|
||||
} else {
|
||||
return body[0];
|
||||
}
|
||||
});
|
||||
exports.smart = smart;
|
||||
const statements = makeStatementFormatter(body => body);
|
||||
exports.statements = statements;
|
||||
const statement = makeStatementFormatter(body => {
|
||||
if (body.length === 0) {
|
||||
throw new Error("Found nothing to return.");
|
||||
}
|
||||
|
||||
if (body.length > 1) {
|
||||
throw new Error("Found multiple statements but wanted one");
|
||||
}
|
||||
|
||||
return body[0];
|
||||
});
|
||||
exports.statement = statement;
|
||||
const expression = {
|
||||
code: str => `(\n${str}\n)`,
|
||||
validate: ast => {
|
||||
if (ast.program.body.length > 1) {
|
||||
throw new Error("Found multiple statements but wanted one");
|
||||
}
|
||||
|
||||
if (expression.unwrap(ast).start === 0) {
|
||||
throw new Error("Parse result included parens.");
|
||||
}
|
||||
},
|
||||
unwrap: ({
|
||||
program
|
||||
}) => {
|
||||
const [stmt] = program.body;
|
||||
t.assertExpressionStatement(stmt);
|
||||
return stmt.expression;
|
||||
}
|
||||
};
|
||||
exports.expression = expression;
|
||||
const program = {
|
||||
code: str => str,
|
||||
validate: () => {},
|
||||
unwrap: ast => ast.program
|
||||
};
|
||||
exports.program = program;
|
|
@ -1,38 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = exports.program = exports.expression = exports.statements = exports.statement = exports.smart = void 0;
|
||||
|
||||
var formatters = _interopRequireWildcard(require("./formatters"));
|
||||
|
||||
var _builder = _interopRequireDefault(require("./builder"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
const smart = (0, _builder.default)(formatters.smart);
|
||||
exports.smart = smart;
|
||||
const statement = (0, _builder.default)(formatters.statement);
|
||||
exports.statement = statement;
|
||||
const statements = (0, _builder.default)(formatters.statements);
|
||||
exports.statements = statements;
|
||||
const expression = (0, _builder.default)(formatters.expression);
|
||||
exports.expression = expression;
|
||||
const program = (0, _builder.default)(formatters.program);
|
||||
exports.program = program;
|
||||
|
||||
var _default = Object.assign(smart.bind(undefined), {
|
||||
smart,
|
||||
statement,
|
||||
statements,
|
||||
expression,
|
||||
program,
|
||||
ast: smart.ast
|
||||
});
|
||||
|
||||
exports.default = _default;
|
|
@ -1,82 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = literalTemplate;
|
||||
|
||||
var _options = require("./options");
|
||||
|
||||
var _parse = _interopRequireDefault(require("./parse"));
|
||||
|
||||
var _populate = _interopRequireDefault(require("./populate"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function literalTemplate(formatter, tpl, opts) {
|
||||
const {
|
||||
metadata,
|
||||
names
|
||||
} = buildLiteralData(formatter, tpl, opts);
|
||||
return arg => {
|
||||
const defaultReplacements = {};
|
||||
arg.forEach((replacement, i) => {
|
||||
defaultReplacements[names[i]] = replacement;
|
||||
});
|
||||
return arg => {
|
||||
const replacements = (0, _options.normalizeReplacements)(arg);
|
||||
|
||||
if (replacements) {
|
||||
Object.keys(replacements).forEach(key => {
|
||||
if (Object.prototype.hasOwnProperty.call(defaultReplacements, key)) {
|
||||
throw new Error("Unexpected replacement overlap.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return formatter.unwrap((0, _populate.default)(metadata, replacements ? Object.assign(replacements, defaultReplacements) : defaultReplacements));
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function buildLiteralData(formatter, tpl, opts) {
|
||||
let names;
|
||||
let nameSet;
|
||||
let metadata;
|
||||
let prefix = "";
|
||||
|
||||
do {
|
||||
prefix += "$";
|
||||
const result = buildTemplateCode(tpl, prefix);
|
||||
names = result.names;
|
||||
nameSet = new Set(names);
|
||||
metadata = (0, _parse.default)(formatter, formatter.code(result.code), {
|
||||
parser: opts.parser,
|
||||
placeholderWhitelist: new Set(result.names.concat(opts.placeholderWhitelist ? Array.from(opts.placeholderWhitelist) : [])),
|
||||
placeholderPattern: opts.placeholderPattern,
|
||||
preserveComments: opts.preserveComments,
|
||||
syntacticPlaceholders: opts.syntacticPlaceholders
|
||||
});
|
||||
} while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name)));
|
||||
|
||||
return {
|
||||
metadata,
|
||||
names
|
||||
};
|
||||
}
|
||||
|
||||
function buildTemplateCode(tpl, prefix) {
|
||||
const names = [];
|
||||
let code = tpl[0];
|
||||
|
||||
for (let i = 1; i < tpl.length; i++) {
|
||||
const value = `${prefix}${i - 1}`;
|
||||
names.push(value);
|
||||
code += value + tpl[i];
|
||||
}
|
||||
|
||||
return {
|
||||
names,
|
||||
code
|
||||
};
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.merge = merge;
|
||||
exports.validate = validate;
|
||||
exports.normalizeReplacements = normalizeReplacements;
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function merge(a, b) {
|
||||
const {
|
||||
placeholderWhitelist = a.placeholderWhitelist,
|
||||
placeholderPattern = a.placeholderPattern,
|
||||
preserveComments = a.preserveComments,
|
||||
syntacticPlaceholders = a.syntacticPlaceholders
|
||||
} = b;
|
||||
return {
|
||||
parser: Object.assign({}, a.parser, b.parser),
|
||||
placeholderWhitelist,
|
||||
placeholderPattern,
|
||||
preserveComments,
|
||||
syntacticPlaceholders
|
||||
};
|
||||
}
|
||||
|
||||
function validate(opts) {
|
||||
if (opts != null && typeof opts !== "object") {
|
||||
throw new Error("Unknown template options.");
|
||||
}
|
||||
|
||||
const _ref = opts || {},
|
||||
{
|
||||
placeholderWhitelist,
|
||||
placeholderPattern,
|
||||
preserveComments,
|
||||
syntacticPlaceholders
|
||||
} = _ref,
|
||||
parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"]);
|
||||
|
||||
if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {
|
||||
throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined");
|
||||
}
|
||||
|
||||
if (placeholderPattern != null && !(placeholderPattern instanceof RegExp) && placeholderPattern !== false) {
|
||||
throw new Error("'.placeholderPattern' must be a RegExp, false, null, or undefined");
|
||||
}
|
||||
|
||||
if (preserveComments != null && typeof preserveComments !== "boolean") {
|
||||
throw new Error("'.preserveComments' must be a boolean, null, or undefined");
|
||||
}
|
||||
|
||||
if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") {
|
||||
throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined");
|
||||
}
|
||||
|
||||
if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) {
|
||||
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
|
||||
}
|
||||
|
||||
return {
|
||||
parser,
|
||||
placeholderWhitelist: placeholderWhitelist || undefined,
|
||||
placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern,
|
||||
preserveComments: preserveComments == null ? undefined : preserveComments,
|
||||
syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeReplacements(replacements) {
|
||||
if (Array.isArray(replacements)) {
|
||||
return replacements.reduce((acc, replacement, i) => {
|
||||
acc["$" + i] = replacement;
|
||||
return acc;
|
||||
}, {});
|
||||
} else if (typeof replacements === "object" || replacements == null) {
|
||||
return replacements || undefined;
|
||||
}
|
||||
|
||||
throw new Error("Template replacements must be an array, object, null, or undefined");
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = parseAndBuildMetadata;
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
var _parser = require("@babel/parser");
|
||||
|
||||
var _codeFrame = require("@babel/code-frame");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
const PATTERN = /^[_$A-Z0-9]+$/;
|
||||
|
||||
function parseAndBuildMetadata(formatter, code, opts) {
|
||||
const {
|
||||
placeholderWhitelist,
|
||||
placeholderPattern,
|
||||
preserveComments,
|
||||
syntacticPlaceholders
|
||||
} = opts;
|
||||
const ast = parseWithCodeFrame(code, opts.parser, syntacticPlaceholders);
|
||||
t.removePropertiesDeep(ast, {
|
||||
preserveComments
|
||||
});
|
||||
formatter.validate(ast);
|
||||
const syntactic = {
|
||||
placeholders: [],
|
||||
placeholderNames: new Set()
|
||||
};
|
||||
const legacy = {
|
||||
placeholders: [],
|
||||
placeholderNames: new Set()
|
||||
};
|
||||
const isLegacyRef = {
|
||||
value: undefined
|
||||
};
|
||||
t.traverse(ast, placeholderVisitorHandler, {
|
||||
syntactic,
|
||||
legacy,
|
||||
isLegacyRef,
|
||||
placeholderWhitelist,
|
||||
placeholderPattern,
|
||||
syntacticPlaceholders
|
||||
});
|
||||
return Object.assign({
|
||||
ast
|
||||
}, isLegacyRef.value ? legacy : syntactic);
|
||||
}
|
||||
|
||||
function placeholderVisitorHandler(node, ancestors, state) {
|
||||
var _state$placeholderWhi;
|
||||
|
||||
let name;
|
||||
|
||||
if (t.isPlaceholder(node)) {
|
||||
if (state.syntacticPlaceholders === false) {
|
||||
throw new Error("%%foo%%-style placeholders can't be used when " + "'.syntacticPlaceholders' is false.");
|
||||
} else {
|
||||
name = node.name.name;
|
||||
state.isLegacyRef.value = false;
|
||||
}
|
||||
} else if (state.isLegacyRef.value === false || state.syntacticPlaceholders) {
|
||||
return;
|
||||
} else if (t.isIdentifier(node) || t.isJSXIdentifier(node)) {
|
||||
name = node.name;
|
||||
state.isLegacyRef.value = true;
|
||||
} else if (t.isStringLiteral(node)) {
|
||||
name = node.value;
|
||||
state.isLegacyRef.value = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!state.isLegacyRef.value && (state.placeholderPattern != null || state.placeholderWhitelist != null)) {
|
||||
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
|
||||
}
|
||||
|
||||
if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && !((_state$placeholderWhi = state.placeholderWhitelist) == null ? void 0 : _state$placeholderWhi.has(name))) {
|
||||
return;
|
||||
}
|
||||
|
||||
ancestors = ancestors.slice();
|
||||
const {
|
||||
node: parent,
|
||||
key
|
||||
} = ancestors[ancestors.length - 1];
|
||||
let type;
|
||||
|
||||
if (t.isStringLiteral(node) || t.isPlaceholder(node, {
|
||||
expectedNode: "StringLiteral"
|
||||
})) {
|
||||
type = "string";
|
||||
} else if (t.isNewExpression(parent) && key === "arguments" || t.isCallExpression(parent) && key === "arguments" || t.isFunction(parent) && key === "params") {
|
||||
type = "param";
|
||||
} else if (t.isExpressionStatement(parent) && !t.isPlaceholder(node)) {
|
||||
type = "statement";
|
||||
ancestors = ancestors.slice(0, -1);
|
||||
} else if (t.isStatement(node) && t.isPlaceholder(node)) {
|
||||
type = "statement";
|
||||
} else {
|
||||
type = "other";
|
||||
}
|
||||
|
||||
const {
|
||||
placeholders,
|
||||
placeholderNames
|
||||
} = state.isLegacyRef.value ? state.legacy : state.syntactic;
|
||||
placeholders.push({
|
||||
name,
|
||||
type,
|
||||
resolve: ast => resolveAncestors(ast, ancestors),
|
||||
isDuplicate: placeholderNames.has(name)
|
||||
});
|
||||
placeholderNames.add(name);
|
||||
}
|
||||
|
||||
function resolveAncestors(ast, ancestors) {
|
||||
let parent = ast;
|
||||
|
||||
for (let i = 0; i < ancestors.length - 1; i++) {
|
||||
const {
|
||||
key,
|
||||
index
|
||||
} = ancestors[i];
|
||||
|
||||
if (index === undefined) {
|
||||
parent = parent[key];
|
||||
} else {
|
||||
parent = parent[key][index];
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
key,
|
||||
index
|
||||
} = ancestors[ancestors.length - 1];
|
||||
return {
|
||||
parent,
|
||||
key,
|
||||
index
|
||||
};
|
||||
}
|
||||
|
||||
function parseWithCodeFrame(code, parserOpts, syntacticPlaceholders) {
|
||||
const plugins = (parserOpts.plugins || []).slice();
|
||||
|
||||
if (syntacticPlaceholders !== false) {
|
||||
plugins.push("placeholders");
|
||||
}
|
||||
|
||||
parserOpts = Object.assign({
|
||||
allowReturnOutsideFunction: true,
|
||||
allowSuperOutsideMethod: true,
|
||||
sourceType: "module"
|
||||
}, parserOpts, {
|
||||
plugins
|
||||
});
|
||||
|
||||
try {
|
||||
return (0, _parser.parse)(code, parserOpts);
|
||||
} catch (err) {
|
||||
const loc = err.loc;
|
||||
|
||||
if (loc) {
|
||||
err.message += "\n" + (0, _codeFrame.codeFrameColumns)(code, {
|
||||
start: loc
|
||||
});
|
||||
err.code = "BABEL_TEMPLATE_PARSE_ERROR";
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = populatePlaceholders;
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function populatePlaceholders(metadata, replacements) {
|
||||
const ast = t.cloneNode(metadata.ast);
|
||||
|
||||
if (replacements) {
|
||||
metadata.placeholders.forEach(placeholder => {
|
||||
if (!Object.prototype.hasOwnProperty.call(replacements, placeholder.name)) {
|
||||
const placeholderName = placeholder.name;
|
||||
throw new Error(`Error: No substitution given for "${placeholderName}". If this is not meant to be a
|
||||
placeholder you may want to consider passing one of the following options to @babel/template:
|
||||
- { placeholderPattern: false, placeholderWhitelist: new Set(['${placeholderName}'])}
|
||||
- { placeholderPattern: /^${placeholderName}$/ }`);
|
||||
}
|
||||
});
|
||||
Object.keys(replacements).forEach(key => {
|
||||
if (!metadata.placeholderNames.has(key)) {
|
||||
throw new Error(`Unknown substitution "${key}" given`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
metadata.placeholders.slice().reverse().forEach(placeholder => {
|
||||
try {
|
||||
applyReplacement(placeholder, ast, replacements && replacements[placeholder.name] || null);
|
||||
} catch (e) {
|
||||
e.message = `@babel/template placeholder "${placeholder.name}": ${e.message}`;
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
return ast;
|
||||
}
|
||||
|
||||
function applyReplacement(placeholder, ast, replacement) {
|
||||
if (placeholder.isDuplicate) {
|
||||
if (Array.isArray(replacement)) {
|
||||
replacement = replacement.map(node => t.cloneNode(node));
|
||||
} else if (typeof replacement === "object") {
|
||||
replacement = t.cloneNode(replacement);
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
parent,
|
||||
key,
|
||||
index
|
||||
} = placeholder.resolve(ast);
|
||||
|
||||
if (placeholder.type === "string") {
|
||||
if (typeof replacement === "string") {
|
||||
replacement = t.stringLiteral(replacement);
|
||||
}
|
||||
|
||||
if (!replacement || !t.isStringLiteral(replacement)) {
|
||||
throw new Error("Expected string substitution");
|
||||
}
|
||||
} else if (placeholder.type === "statement") {
|
||||
if (index === undefined) {
|
||||
if (!replacement) {
|
||||
replacement = t.emptyStatement();
|
||||
} else if (Array.isArray(replacement)) {
|
||||
replacement = t.blockStatement(replacement);
|
||||
} else if (typeof replacement === "string") {
|
||||
replacement = t.expressionStatement(t.identifier(replacement));
|
||||
} else if (!t.isStatement(replacement)) {
|
||||
replacement = t.expressionStatement(replacement);
|
||||
}
|
||||
} else {
|
||||
if (replacement && !Array.isArray(replacement)) {
|
||||
if (typeof replacement === "string") {
|
||||
replacement = t.identifier(replacement);
|
||||
}
|
||||
|
||||
if (!t.isStatement(replacement)) {
|
||||
replacement = t.expressionStatement(replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (placeholder.type === "param") {
|
||||
if (typeof replacement === "string") {
|
||||
replacement = t.identifier(replacement);
|
||||
}
|
||||
|
||||
if (index === undefined) throw new Error("Assertion failure.");
|
||||
} else {
|
||||
if (typeof replacement === "string") {
|
||||
replacement = t.identifier(replacement);
|
||||
}
|
||||
|
||||
if (Array.isArray(replacement)) {
|
||||
throw new Error("Cannot replace single expression with an array.");
|
||||
}
|
||||
}
|
||||
|
||||
if (index === undefined) {
|
||||
t.validate(parent, key, replacement);
|
||||
parent[key] = replacement;
|
||||
} else {
|
||||
const items = parent[key].slice();
|
||||
|
||||
if (placeholder.type === "statement" || placeholder.type === "param") {
|
||||
if (replacement == null) {
|
||||
items.splice(index, 1);
|
||||
} else if (Array.isArray(replacement)) {
|
||||
items.splice(index, 1, ...replacement);
|
||||
} else {
|
||||
items[index] = replacement;
|
||||
}
|
||||
} else {
|
||||
items[index] = replacement;
|
||||
}
|
||||
|
||||
t.validate(parent, key, items);
|
||||
parent[key] = items;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = stringTemplate;
|
||||
|
||||
var _options = require("./options");
|
||||
|
||||
var _parse = _interopRequireDefault(require("./parse"));
|
||||
|
||||
var _populate = _interopRequireDefault(require("./populate"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function stringTemplate(formatter, code, opts) {
|
||||
code = formatter.code(code);
|
||||
let metadata;
|
||||
return arg => {
|
||||
const replacements = (0, _options.normalizeReplacements)(arg);
|
||||
if (!metadata) metadata = (0, _parse.default)(formatter, code, opts);
|
||||
return formatter.unwrap((0, _populate.default)(metadata, replacements));
|
||||
};
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"name": "@babel/template",
|
||||
"version": "7.12.13",
|
||||
"description": "Generate an AST from a string template.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-template",
|
||||
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20template%22+is%3Aopen",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-template"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.12.13",
|
||||
"@babel/parser": "^7.12.13",
|
||||
"@babel/types": "^7.12.13"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
|
@ -1,19 +0,0 @@
|
|||
# @babel/traverse
|
||||
|
||||
> The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes
|
||||
|
||||
See our website [@babel/traverse](https://babeljs.io/docs/en/babel-traverse) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/traverse
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/traverse --dev
|
||||
```
|
|
@ -1,26 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.clear = clear;
|
||||
exports.clearPath = clearPath;
|
||||
exports.clearScope = clearScope;
|
||||
exports.scope = exports.path = void 0;
|
||||
let path = new WeakMap();
|
||||
exports.path = path;
|
||||
let scope = new WeakMap();
|
||||
exports.scope = scope;
|
||||
|
||||
function clear() {
|
||||
clearPath();
|
||||
clearScope();
|
||||
}
|
||||
|
||||
function clearPath() {
|
||||
exports.path = path = new WeakMap();
|
||||
}
|
||||
|
||||
function clearScope() {
|
||||
exports.scope = scope = new WeakMap();
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _path = require("./path");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const testing = process.env.NODE_ENV === "test";
|
||||
|
||||
class TraversalContext {
|
||||
constructor(scope, opts, state, parentPath) {
|
||||
this.queue = null;
|
||||
this.priorityQueue = null;
|
||||
this.parentPath = parentPath;
|
||||
this.scope = scope;
|
||||
this.state = state;
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
shouldVisit(node) {
|
||||
const opts = this.opts;
|
||||
if (opts.enter || opts.exit) return true;
|
||||
if (opts[node.type]) return true;
|
||||
const keys = t.VISITOR_KEYS[node.type];
|
||||
if (!(keys != null && keys.length)) return false;
|
||||
|
||||
for (const key of keys) {
|
||||
if (node[key]) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
create(node, obj, key, listKey) {
|
||||
return _path.default.get({
|
||||
parentPath: this.parentPath,
|
||||
parent: node,
|
||||
container: obj,
|
||||
key: key,
|
||||
listKey
|
||||
});
|
||||
}
|
||||
|
||||
maybeQueue(path, notPriority) {
|
||||
if (this.trap) {
|
||||
throw new Error("Infinite cycle detected");
|
||||
}
|
||||
|
||||
if (this.queue) {
|
||||
if (notPriority) {
|
||||
this.queue.push(path);
|
||||
} else {
|
||||
this.priorityQueue.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitMultiple(container, parent, listKey) {
|
||||
if (container.length === 0) return false;
|
||||
const queue = [];
|
||||
|
||||
for (let key = 0; key < container.length; key++) {
|
||||
const node = container[key];
|
||||
|
||||
if (node && this.shouldVisit(node)) {
|
||||
queue.push(this.create(parent, container, key, listKey));
|
||||
}
|
||||
}
|
||||
|
||||
return this.visitQueue(queue);
|
||||
}
|
||||
|
||||
visitSingle(node, key) {
|
||||
if (this.shouldVisit(node[key])) {
|
||||
return this.visitQueue([this.create(node, node, key)]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
visitQueue(queue) {
|
||||
this.queue = queue;
|
||||
this.priorityQueue = [];
|
||||
const visited = new WeakSet();
|
||||
let stop = false;
|
||||
|
||||
for (const path of queue) {
|
||||
path.resync();
|
||||
|
||||
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
||||
path.pushContext(this);
|
||||
}
|
||||
|
||||
if (path.key === null) continue;
|
||||
|
||||
if (testing && queue.length >= 10000) {
|
||||
this.trap = true;
|
||||
}
|
||||
|
||||
const {
|
||||
node
|
||||
} = path;
|
||||
if (visited.has(node)) continue;
|
||||
if (node) visited.add(node);
|
||||
|
||||
if (path.visit()) {
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.priorityQueue.length) {
|
||||
stop = this.visitQueue(this.priorityQueue);
|
||||
this.priorityQueue = [];
|
||||
this.queue = queue;
|
||||
if (stop) break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const path of queue) {
|
||||
path.popContext();
|
||||
}
|
||||
|
||||
this.queue = null;
|
||||
return stop;
|
||||
}
|
||||
|
||||
visit(node, key) {
|
||||
const nodes = node[key];
|
||||
if (!nodes) return false;
|
||||
|
||||
if (Array.isArray(nodes)) {
|
||||
return this.visitMultiple(nodes, node, key);
|
||||
} else {
|
||||
return this.visitSingle(node, key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = TraversalContext;
|
|
@ -1,23 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
class Hub {
|
||||
getCode() {}
|
||||
|
||||
getScope() {}
|
||||
|
||||
addHelper() {
|
||||
throw new Error("Helpers are not supported by the default hub.");
|
||||
}
|
||||
|
||||
buildError(node, msg, Error = TypeError) {
|
||||
return new Error(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Hub;
|
|
@ -1,112 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "NodePath", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _path.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Scope", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _scope.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Hub", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _hub.default;
|
||||
}
|
||||
});
|
||||
exports.visitors = exports.default = void 0;
|
||||
|
||||
var _context = require("./context");
|
||||
|
||||
var visitors = require("./visitors");
|
||||
|
||||
exports.visitors = visitors;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var cache = require("./cache");
|
||||
|
||||
var _path = require("./path");
|
||||
|
||||
var _scope = require("./scope");
|
||||
|
||||
var _hub = require("./hub");
|
||||
|
||||
function traverse(parent, opts = {}, scope, state, parentPath) {
|
||||
if (!parent) return;
|
||||
|
||||
if (!opts.noScope && !scope) {
|
||||
if (parent.type !== "Program" && parent.type !== "File") {
|
||||
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!t.VISITOR_KEYS[parent.type]) {
|
||||
return;
|
||||
}
|
||||
|
||||
visitors.explode(opts);
|
||||
traverse.node(parent, opts, scope, state, parentPath);
|
||||
}
|
||||
|
||||
var _default = traverse;
|
||||
exports.default = _default;
|
||||
traverse.visitors = visitors;
|
||||
traverse.verify = visitors.verify;
|
||||
traverse.explode = visitors.explode;
|
||||
|
||||
traverse.cheap = function (node, enter) {
|
||||
return t.traverseFast(node, enter);
|
||||
};
|
||||
|
||||
traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
|
||||
const keys = t.VISITOR_KEYS[node.type];
|
||||
if (!keys) return;
|
||||
const context = new _context.default(scope, opts, state, parentPath);
|
||||
|
||||
for (const key of keys) {
|
||||
if (skipKeys && skipKeys[key]) continue;
|
||||
if (context.visit(node, key)) return;
|
||||
}
|
||||
};
|
||||
|
||||
traverse.clearNode = function (node, opts) {
|
||||
t.removeProperties(node, opts);
|
||||
cache.path.delete(node);
|
||||
};
|
||||
|
||||
traverse.removeProperties = function (tree, opts) {
|
||||
t.traverseFast(tree, traverse.clearNode, opts);
|
||||
return tree;
|
||||
};
|
||||
|
||||
function hasDenylistedType(path, state) {
|
||||
if (path.node.type === state.type) {
|
||||
state.has = true;
|
||||
path.stop();
|
||||
}
|
||||
}
|
||||
|
||||
traverse.hasType = function (tree, type, denylistTypes) {
|
||||
if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
|
||||
if (tree.type === type) return true;
|
||||
const state = {
|
||||
has: false,
|
||||
type: type
|
||||
};
|
||||
traverse(tree, {
|
||||
noScope: true,
|
||||
denylist: denylistTypes,
|
||||
enter: hasDenylistedType
|
||||
}, null, state);
|
||||
return state.has;
|
||||
};
|
||||
|
||||
traverse.cache = cache;
|
|
@ -1,176 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.findParent = findParent;
|
||||
exports.find = find;
|
||||
exports.getFunctionParent = getFunctionParent;
|
||||
exports.getStatementParent = getStatementParent;
|
||||
exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
|
||||
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
|
||||
exports.getAncestry = getAncestry;
|
||||
exports.isAncestor = isAncestor;
|
||||
exports.isDescendant = isDescendant;
|
||||
exports.inType = inType;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
function findParent(callback) {
|
||||
let path = this;
|
||||
|
||||
while (path = path.parentPath) {
|
||||
if (callback(path)) return path;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function find(callback) {
|
||||
let path = this;
|
||||
|
||||
do {
|
||||
if (callback(path)) return path;
|
||||
} while (path = path.parentPath);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getFunctionParent() {
|
||||
return this.findParent(p => p.isFunction());
|
||||
}
|
||||
|
||||
function getStatementParent() {
|
||||
let path = this;
|
||||
|
||||
do {
|
||||
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
||||
break;
|
||||
} else {
|
||||
path = path.parentPath;
|
||||
}
|
||||
} while (path);
|
||||
|
||||
if (path && (path.isProgram() || path.isFile())) {
|
||||
throw new Error("File/Program node, we can't possibly find a statement parent to this");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
function getEarliestCommonAncestorFrom(paths) {
|
||||
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
||||
let earliest;
|
||||
const keys = t.VISITOR_KEYS[deepest.type];
|
||||
|
||||
for (const ancestry of ancestries) {
|
||||
const path = ancestry[i + 1];
|
||||
|
||||
if (!earliest) {
|
||||
earliest = path;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (path.listKey && earliest.listKey === path.listKey) {
|
||||
if (path.key < earliest.key) {
|
||||
earliest = path;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const earliestKeyIndex = keys.indexOf(earliest.parentKey);
|
||||
const currentKeyIndex = keys.indexOf(path.parentKey);
|
||||
|
||||
if (earliestKeyIndex > currentKeyIndex) {
|
||||
earliest = path;
|
||||
}
|
||||
}
|
||||
|
||||
return earliest;
|
||||
});
|
||||
}
|
||||
|
||||
function getDeepestCommonAncestorFrom(paths, filter) {
|
||||
if (!paths.length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (paths.length === 1) {
|
||||
return paths[0];
|
||||
}
|
||||
|
||||
let minDepth = Infinity;
|
||||
let lastCommonIndex, lastCommon;
|
||||
const ancestries = paths.map(path => {
|
||||
const ancestry = [];
|
||||
|
||||
do {
|
||||
ancestry.unshift(path);
|
||||
} while ((path = path.parentPath) && path !== this);
|
||||
|
||||
if (ancestry.length < minDepth) {
|
||||
minDepth = ancestry.length;
|
||||
}
|
||||
|
||||
return ancestry;
|
||||
});
|
||||
const first = ancestries[0];
|
||||
|
||||
depthLoop: for (let i = 0; i < minDepth; i++) {
|
||||
const shouldMatch = first[i];
|
||||
|
||||
for (const ancestry of ancestries) {
|
||||
if (ancestry[i] !== shouldMatch) {
|
||||
break depthLoop;
|
||||
}
|
||||
}
|
||||
|
||||
lastCommonIndex = i;
|
||||
lastCommon = shouldMatch;
|
||||
}
|
||||
|
||||
if (lastCommon) {
|
||||
if (filter) {
|
||||
return filter(lastCommon, lastCommonIndex, ancestries);
|
||||
} else {
|
||||
return lastCommon;
|
||||
}
|
||||
} else {
|
||||
throw new Error("Couldn't find intersection");
|
||||
}
|
||||
}
|
||||
|
||||
function getAncestry() {
|
||||
let path = this;
|
||||
const paths = [];
|
||||
|
||||
do {
|
||||
paths.push(path);
|
||||
} while (path = path.parentPath);
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function isAncestor(maybeDescendant) {
|
||||
return maybeDescendant.isDescendant(this);
|
||||
}
|
||||
|
||||
function isDescendant(maybeAncestor) {
|
||||
return !!this.findParent(parent => parent === maybeAncestor);
|
||||
}
|
||||
|
||||
function inType(...candidateTypes) {
|
||||
let path = this;
|
||||
|
||||
while (path) {
|
||||
for (const type of candidateTypes) {
|
||||
if (path.node.type === type) return true;
|
||||
}
|
||||
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
||||
exports.addComment = addComment;
|
||||
exports.addComments = addComments;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function shareCommentsWithSiblings() {
|
||||
if (typeof this.key === "string") return;
|
||||
const node = this.node;
|
||||
if (!node) return;
|
||||
const trailing = node.trailingComments;
|
||||
const leading = node.leadingComments;
|
||||
if (!trailing && !leading) return;
|
||||
const prev = this.getSibling(this.key - 1);
|
||||
const next = this.getSibling(this.key + 1);
|
||||
const hasPrev = Boolean(prev.node);
|
||||
const hasNext = Boolean(next.node);
|
||||
|
||||
if (hasPrev && !hasNext) {
|
||||
prev.addComments("trailing", trailing);
|
||||
} else if (hasNext && !hasPrev) {
|
||||
next.addComments("leading", leading);
|
||||
}
|
||||
}
|
||||
|
||||
function addComment(type, content, line) {
|
||||
t.addComment(this.node, type, content, line);
|
||||
}
|
||||
|
||||
function addComments(type, comments) {
|
||||
t.addComments(this.node, type, comments);
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.call = call;
|
||||
exports._call = _call;
|
||||
exports.isBlacklisted = exports.isDenylisted = isDenylisted;
|
||||
exports.visit = visit;
|
||||
exports.skip = skip;
|
||||
exports.skipKey = skipKey;
|
||||
exports.stop = stop;
|
||||
exports.setScope = setScope;
|
||||
exports.setContext = setContext;
|
||||
exports.resync = resync;
|
||||
exports._resyncParent = _resyncParent;
|
||||
exports._resyncKey = _resyncKey;
|
||||
exports._resyncList = _resyncList;
|
||||
exports._resyncRemoved = _resyncRemoved;
|
||||
exports.popContext = popContext;
|
||||
exports.pushContext = pushContext;
|
||||
exports.setup = setup;
|
||||
exports.setKey = setKey;
|
||||
exports.requeue = requeue;
|
||||
exports._getQueueContexts = _getQueueContexts;
|
||||
|
||||
var _index = require("../index");
|
||||
|
||||
var _index2 = require("./index");
|
||||
|
||||
function call(key) {
|
||||
const opts = this.opts;
|
||||
this.debug(key);
|
||||
|
||||
if (this.node) {
|
||||
if (this._call(opts[key])) return true;
|
||||
}
|
||||
|
||||
if (this.node) {
|
||||
return this._call(opts[this.node.type] && opts[this.node.type][key]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _call(fns) {
|
||||
if (!fns) return false;
|
||||
|
||||
for (const fn of fns) {
|
||||
if (!fn) continue;
|
||||
const node = this.node;
|
||||
if (!node) return true;
|
||||
const ret = fn.call(this.state, this, this.state);
|
||||
|
||||
if (ret && typeof ret === "object" && typeof ret.then === "function") {
|
||||
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
throw new Error(`Unexpected return value from visitor method ${fn}`);
|
||||
}
|
||||
|
||||
if (this.node !== node) return true;
|
||||
if (this._traverseFlags > 0) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isDenylisted() {
|
||||
var _this$opts$denylist;
|
||||
|
||||
const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
|
||||
return denylist && denylist.indexOf(this.node.type) > -1;
|
||||
}
|
||||
|
||||
function visit() {
|
||||
if (!this.node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isDenylisted()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.shouldSkip || this.call("enter") || this.shouldSkip) {
|
||||
this.debug("Skip...");
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
this.debug("Recursing into...");
|
||||
|
||||
_index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
||||
|
||||
this.call("exit");
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
function skip() {
|
||||
this.shouldSkip = true;
|
||||
}
|
||||
|
||||
function skipKey(key) {
|
||||
if (this.skipKeys == null) {
|
||||
this.skipKeys = {};
|
||||
}
|
||||
|
||||
this.skipKeys[key] = true;
|
||||
}
|
||||
|
||||
function stop() {
|
||||
this._traverseFlags |= _index2.SHOULD_SKIP | _index2.SHOULD_STOP;
|
||||
}
|
||||
|
||||
function setScope() {
|
||||
if (this.opts && this.opts.noScope) return;
|
||||
let path = this.parentPath;
|
||||
if (this.key === "key" && path.isMethod()) path = path.parentPath;
|
||||
let target;
|
||||
|
||||
while (path && !target) {
|
||||
if (path.opts && path.opts.noScope) return;
|
||||
target = path.scope;
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
this.scope = this.getScope(target);
|
||||
if (this.scope) this.scope.init();
|
||||
}
|
||||
|
||||
function setContext(context) {
|
||||
if (this.skipKeys != null) {
|
||||
this.skipKeys = {};
|
||||
}
|
||||
|
||||
this._traverseFlags = 0;
|
||||
|
||||
if (context) {
|
||||
this.context = context;
|
||||
this.state = context.state;
|
||||
this.opts = context.opts;
|
||||
}
|
||||
|
||||
this.setScope();
|
||||
return this;
|
||||
}
|
||||
|
||||
function resync() {
|
||||
if (this.removed) return;
|
||||
|
||||
this._resyncParent();
|
||||
|
||||
this._resyncList();
|
||||
|
||||
this._resyncKey();
|
||||
}
|
||||
|
||||
function _resyncParent() {
|
||||
if (this.parentPath) {
|
||||
this.parent = this.parentPath.node;
|
||||
}
|
||||
}
|
||||
|
||||
function _resyncKey() {
|
||||
if (!this.container) return;
|
||||
if (this.node === this.container[this.key]) return;
|
||||
|
||||
if (Array.isArray(this.container)) {
|
||||
for (let i = 0; i < this.container.length; i++) {
|
||||
if (this.container[i] === this.node) {
|
||||
return this.setKey(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const key of Object.keys(this.container)) {
|
||||
if (this.container[key] === this.node) {
|
||||
return this.setKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.key = null;
|
||||
}
|
||||
|
||||
function _resyncList() {
|
||||
if (!this.parent || !this.inList) return;
|
||||
const newContainer = this.parent[this.listKey];
|
||||
if (this.container === newContainer) return;
|
||||
this.container = newContainer || null;
|
||||
}
|
||||
|
||||
function _resyncRemoved() {
|
||||
if (this.key == null || !this.container || this.container[this.key] !== this.node) {
|
||||
this._markRemoved();
|
||||
}
|
||||
}
|
||||
|
||||
function popContext() {
|
||||
this.contexts.pop();
|
||||
|
||||
if (this.contexts.length > 0) {
|
||||
this.setContext(this.contexts[this.contexts.length - 1]);
|
||||
} else {
|
||||
this.setContext(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
function pushContext(context) {
|
||||
this.contexts.push(context);
|
||||
this.setContext(context);
|
||||
}
|
||||
|
||||
function setup(parentPath, container, listKey, key) {
|
||||
this.listKey = listKey;
|
||||
this.container = container;
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.setKey(key);
|
||||
}
|
||||
|
||||
function setKey(key) {
|
||||
var _this$node;
|
||||
|
||||
this.key = key;
|
||||
this.node = this.container[this.key];
|
||||
this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
|
||||
}
|
||||
|
||||
function requeue(pathToQueue = this) {
|
||||
if (pathToQueue.removed) return;
|
||||
;
|
||||
const contexts = this.contexts;
|
||||
|
||||
for (const context of contexts) {
|
||||
context.maybeQueue(pathToQueue);
|
||||
}
|
||||
}
|
||||
|
||||
function _getQueueContexts() {
|
||||
let path = this;
|
||||
let contexts = this.contexts;
|
||||
|
||||
while (!contexts.length) {
|
||||
path = path.parentPath;
|
||||
if (!path) break;
|
||||
contexts = path.contexts;
|
||||
}
|
||||
|
||||
return contexts;
|
||||
}
|
|
@ -1,422 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.toComputedKey = toComputedKey;
|
||||
exports.ensureBlock = ensureBlock;
|
||||
exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
|
||||
exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
|
||||
exports.arrowFunctionToExpression = arrowFunctionToExpression;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _helperFunctionName = require("@babel/helper-function-name");
|
||||
|
||||
function toComputedKey() {
|
||||
let key;
|
||||
|
||||
if (this.isMemberExpression()) {
|
||||
key = this.node.property;
|
||||
} else if (this.isProperty() || this.isMethod()) {
|
||||
key = this.node.key;
|
||||
} else {
|
||||
throw new ReferenceError("todo");
|
||||
}
|
||||
|
||||
if (!this.node.computed) {
|
||||
if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
function ensureBlock() {
|
||||
const body = this.get("body");
|
||||
const bodyNode = body.node;
|
||||
|
||||
if (Array.isArray(body)) {
|
||||
throw new Error("Can't convert array path to a block statement");
|
||||
}
|
||||
|
||||
if (!bodyNode) {
|
||||
throw new Error("Can't convert node without a body");
|
||||
}
|
||||
|
||||
if (body.isBlockStatement()) {
|
||||
return bodyNode;
|
||||
}
|
||||
|
||||
const statements = [];
|
||||
let stringPath = "body";
|
||||
let key;
|
||||
let listKey;
|
||||
|
||||
if (body.isStatement()) {
|
||||
listKey = "body";
|
||||
key = 0;
|
||||
statements.push(body.node);
|
||||
} else {
|
||||
stringPath += ".body.0";
|
||||
|
||||
if (this.isFunction()) {
|
||||
key = "argument";
|
||||
statements.push(t.returnStatement(body.node));
|
||||
} else {
|
||||
key = "expression";
|
||||
statements.push(t.expressionStatement(body.node));
|
||||
}
|
||||
}
|
||||
|
||||
this.node.body = t.blockStatement(statements);
|
||||
const parentPath = this.get(stringPath);
|
||||
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
|
||||
return this.node;
|
||||
}
|
||||
|
||||
function arrowFunctionToShadowed() {
|
||||
if (!this.isArrowFunctionExpression()) return;
|
||||
this.arrowFunctionToExpression();
|
||||
}
|
||||
|
||||
function unwrapFunctionEnvironment() {
|
||||
if (!this.isArrowFunctionExpression() && !this.isFunctionExpression() && !this.isFunctionDeclaration()) {
|
||||
throw this.buildCodeFrameError("Can only unwrap the environment of a function.");
|
||||
}
|
||||
|
||||
hoistFunctionEnvironment(this);
|
||||
}
|
||||
|
||||
function arrowFunctionToExpression({
|
||||
allowInsertArrow = true,
|
||||
specCompliant = false,
|
||||
noNewArrows = !specCompliant
|
||||
} = {}) {
|
||||
if (!this.isArrowFunctionExpression()) {
|
||||
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
|
||||
}
|
||||
|
||||
const thisBinding = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
|
||||
this.ensureBlock();
|
||||
this.node.type = "FunctionExpression";
|
||||
|
||||
if (!noNewArrows) {
|
||||
const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
|
||||
|
||||
if (checkBinding) {
|
||||
this.parentPath.scope.push({
|
||||
id: checkBinding,
|
||||
init: t.objectExpression([])
|
||||
});
|
||||
}
|
||||
|
||||
this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(this.hub.addHelper("newArrowCheck"), [t.thisExpression(), checkBinding ? t.identifier(checkBinding.name) : t.identifier(thisBinding)])));
|
||||
this.replaceWith(t.callExpression(t.memberExpression((0, _helperFunctionName.default)(this, true) || this.node, t.identifier("bind")), [checkBinding ? t.identifier(checkBinding.name) : t.thisExpression()]));
|
||||
}
|
||||
}
|
||||
|
||||
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) {
|
||||
const thisEnvFn = fnPath.findParent(p => {
|
||||
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
|
||||
static: false
|
||||
});
|
||||
});
|
||||
const inConstructor = (thisEnvFn == null ? void 0 : thisEnvFn.node.kind) === "constructor";
|
||||
|
||||
if (thisEnvFn.isClassProperty()) {
|
||||
throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
|
||||
}
|
||||
|
||||
const {
|
||||
thisPaths,
|
||||
argumentsPaths,
|
||||
newTargetPaths,
|
||||
superProps,
|
||||
superCalls
|
||||
} = getScopeInformation(fnPath);
|
||||
|
||||
if (inConstructor && superCalls.length > 0) {
|
||||
if (!allowInsertArrow) {
|
||||
throw superCalls[0].buildCodeFrameError("Unable to handle nested super() usage in arrow");
|
||||
}
|
||||
|
||||
const allSuperCalls = [];
|
||||
thisEnvFn.traverse({
|
||||
Function(child) {
|
||||
if (child.isArrowFunctionExpression()) return;
|
||||
child.skip();
|
||||
},
|
||||
|
||||
ClassProperty(child) {
|
||||
child.skip();
|
||||
},
|
||||
|
||||
CallExpression(child) {
|
||||
if (!child.get("callee").isSuper()) return;
|
||||
allSuperCalls.push(child);
|
||||
}
|
||||
|
||||
});
|
||||
const superBinding = getSuperBinding(thisEnvFn);
|
||||
allSuperCalls.forEach(superCall => {
|
||||
const callee = t.identifier(superBinding);
|
||||
callee.loc = superCall.node.callee.loc;
|
||||
superCall.get("callee").replaceWith(callee);
|
||||
});
|
||||
}
|
||||
|
||||
if (argumentsPaths.length > 0) {
|
||||
const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t.identifier("arguments"));
|
||||
argumentsPaths.forEach(argumentsChild => {
|
||||
const argsRef = t.identifier(argumentsBinding);
|
||||
argsRef.loc = argumentsChild.node.loc;
|
||||
argumentsChild.replaceWith(argsRef);
|
||||
});
|
||||
}
|
||||
|
||||
if (newTargetPaths.length > 0) {
|
||||
const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t.metaProperty(t.identifier("new"), t.identifier("target")));
|
||||
newTargetPaths.forEach(targetChild => {
|
||||
const targetRef = t.identifier(newTargetBinding);
|
||||
targetRef.loc = targetChild.node.loc;
|
||||
targetChild.replaceWith(targetRef);
|
||||
});
|
||||
}
|
||||
|
||||
if (superProps.length > 0) {
|
||||
if (!allowInsertArrow) {
|
||||
throw superProps[0].buildCodeFrameError("Unable to handle nested super.prop usage");
|
||||
}
|
||||
|
||||
const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
|
||||
flatSuperProps.forEach(superProp => {
|
||||
const key = superProp.node.computed ? "" : superProp.get("property").node.name;
|
||||
const isAssignment = superProp.parentPath.isAssignmentExpression({
|
||||
left: superProp.node
|
||||
});
|
||||
const isCall = superProp.parentPath.isCallExpression({
|
||||
callee: superProp.node
|
||||
});
|
||||
const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
|
||||
const args = [];
|
||||
|
||||
if (superProp.node.computed) {
|
||||
args.push(superProp.get("property").node);
|
||||
}
|
||||
|
||||
if (isAssignment) {
|
||||
const value = superProp.parentPath.node.right;
|
||||
args.push(value);
|
||||
}
|
||||
|
||||
const call = t.callExpression(t.identifier(superBinding), args);
|
||||
|
||||
if (isCall) {
|
||||
superProp.parentPath.unshiftContainer("arguments", t.thisExpression());
|
||||
superProp.replaceWith(t.memberExpression(call, t.identifier("call")));
|
||||
thisPaths.push(superProp.parentPath.get("arguments.0"));
|
||||
} else if (isAssignment) {
|
||||
superProp.parentPath.replaceWith(call);
|
||||
} else {
|
||||
superProp.replaceWith(call);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let thisBinding;
|
||||
|
||||
if (thisPaths.length > 0 || !noNewArrows) {
|
||||
thisBinding = getThisBinding(thisEnvFn, inConstructor);
|
||||
|
||||
if (noNewArrows || inConstructor && hasSuperClass(thisEnvFn)) {
|
||||
thisPaths.forEach(thisChild => {
|
||||
const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding);
|
||||
thisRef.loc = thisChild.node.loc;
|
||||
thisChild.replaceWith(thisRef);
|
||||
});
|
||||
if (!noNewArrows) thisBinding = null;
|
||||
}
|
||||
}
|
||||
|
||||
return thisBinding;
|
||||
}
|
||||
|
||||
function standardizeSuperProperty(superProp) {
|
||||
if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") {
|
||||
const assignmentPath = superProp.parentPath;
|
||||
const op = assignmentPath.node.operator.slice(0, -1);
|
||||
const value = assignmentPath.node.right;
|
||||
assignmentPath.node.operator = "=";
|
||||
|
||||
if (superProp.node.computed) {
|
||||
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
||||
assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, t.assignmentExpression("=", tmp, superProp.node.property), true));
|
||||
assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(tmp.name), true), value));
|
||||
} else {
|
||||
assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, superProp.node.property));
|
||||
assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(superProp.node.property.name)), value));
|
||||
}
|
||||
|
||||
return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
|
||||
} else if (superProp.parentPath.isUpdateExpression()) {
|
||||
const updateExpr = superProp.parentPath;
|
||||
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
||||
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
|
||||
const parts = [t.assignmentExpression("=", tmp, t.memberExpression(superProp.node.object, computedKey ? t.assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t.assignmentExpression("=", t.memberExpression(superProp.node.object, computedKey ? t.identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t.binaryExpression("+", t.identifier(tmp.name), t.numericLiteral(1)))];
|
||||
|
||||
if (!superProp.parentPath.node.prefix) {
|
||||
parts.push(t.identifier(tmp.name));
|
||||
}
|
||||
|
||||
updateExpr.replaceWith(t.sequenceExpression(parts));
|
||||
const left = updateExpr.get("expressions.0.right");
|
||||
const right = updateExpr.get("expressions.1.left");
|
||||
return [left, right];
|
||||
}
|
||||
|
||||
return [superProp];
|
||||
}
|
||||
|
||||
function hasSuperClass(thisEnvFn) {
|
||||
return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
|
||||
}
|
||||
|
||||
function getThisBinding(thisEnvFn, inConstructor) {
|
||||
return getBinding(thisEnvFn, "this", thisBinding => {
|
||||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();
|
||||
const supers = new WeakSet();
|
||||
thisEnvFn.traverse({
|
||||
Function(child) {
|
||||
if (child.isArrowFunctionExpression()) return;
|
||||
child.skip();
|
||||
},
|
||||
|
||||
ClassProperty(child) {
|
||||
child.skip();
|
||||
},
|
||||
|
||||
CallExpression(child) {
|
||||
if (!child.get("callee").isSuper()) return;
|
||||
if (supers.has(child.node)) return;
|
||||
supers.add(child.node);
|
||||
child.replaceWithMultiple([child.node, t.assignmentExpression("=", t.identifier(thisBinding), t.identifier("this"))]);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSuperBinding(thisEnvFn) {
|
||||
return getBinding(thisEnvFn, "supercall", () => {
|
||||
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
||||
return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))]));
|
||||
});
|
||||
}
|
||||
|
||||
function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
|
||||
const op = isAssignment ? "set" : "get";
|
||||
return getBinding(thisEnvFn, `superprop_${op}:${propName || ""}`, () => {
|
||||
const argsList = [];
|
||||
let fnBody;
|
||||
|
||||
if (propName) {
|
||||
fnBody = t.memberExpression(t.super(), t.identifier(propName));
|
||||
} else {
|
||||
const method = thisEnvFn.scope.generateUidIdentifier("prop");
|
||||
argsList.unshift(method);
|
||||
fnBody = t.memberExpression(t.super(), t.identifier(method.name), true);
|
||||
}
|
||||
|
||||
if (isAssignment) {
|
||||
const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
|
||||
argsList.push(valueIdent);
|
||||
fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
|
||||
}
|
||||
|
||||
return t.arrowFunctionExpression(argsList, fnBody);
|
||||
});
|
||||
}
|
||||
|
||||
function getBinding(thisEnvFn, key, init) {
|
||||
const cacheKey = "binding:" + key;
|
||||
let data = thisEnvFn.getData(cacheKey);
|
||||
|
||||
if (!data) {
|
||||
const id = thisEnvFn.scope.generateUidIdentifier(key);
|
||||
data = id.name;
|
||||
thisEnvFn.setData(cacheKey, data);
|
||||
thisEnvFn.scope.push({
|
||||
id: id,
|
||||
init: init(data)
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function getScopeInformation(fnPath) {
|
||||
const thisPaths = [];
|
||||
const argumentsPaths = [];
|
||||
const newTargetPaths = [];
|
||||
const superProps = [];
|
||||
const superCalls = [];
|
||||
fnPath.traverse({
|
||||
ClassProperty(child) {
|
||||
child.skip();
|
||||
},
|
||||
|
||||
Function(child) {
|
||||
if (child.isArrowFunctionExpression()) return;
|
||||
child.skip();
|
||||
},
|
||||
|
||||
ThisExpression(child) {
|
||||
thisPaths.push(child);
|
||||
},
|
||||
|
||||
JSXIdentifier(child) {
|
||||
if (child.node.name !== "this") return;
|
||||
|
||||
if (!child.parentPath.isJSXMemberExpression({
|
||||
object: child.node
|
||||
}) && !child.parentPath.isJSXOpeningElement({
|
||||
name: child.node
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
|
||||
thisPaths.push(child);
|
||||
},
|
||||
|
||||
CallExpression(child) {
|
||||
if (child.get("callee").isSuper()) superCalls.push(child);
|
||||
},
|
||||
|
||||
MemberExpression(child) {
|
||||
if (child.get("object").isSuper()) superProps.push(child);
|
||||
},
|
||||
|
||||
ReferencedIdentifier(child) {
|
||||
if (child.node.name !== "arguments") return;
|
||||
argumentsPaths.push(child);
|
||||
},
|
||||
|
||||
MetaProperty(child) {
|
||||
if (!child.get("meta").isIdentifier({
|
||||
name: "new"
|
||||
})) return;
|
||||
if (!child.get("property").isIdentifier({
|
||||
name: "target"
|
||||
})) return;
|
||||
newTargetPaths.push(child);
|
||||
}
|
||||
|
||||
});
|
||||
return {
|
||||
thisPaths,
|
||||
argumentsPaths,
|
||||
newTargetPaths,
|
||||
superProps,
|
||||
superCalls
|
||||
};
|
||||
}
|
|
@ -1,401 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.evaluateTruthy = evaluateTruthy;
|
||||
exports.evaluate = evaluate;
|
||||
const VALID_CALLEES = ["String", "Number", "Math"];
|
||||
const INVALID_METHODS = ["random"];
|
||||
|
||||
function evaluateTruthy() {
|
||||
const res = this.evaluate();
|
||||
if (res.confident) return !!res.value;
|
||||
}
|
||||
|
||||
function deopt(path, state) {
|
||||
if (!state.confident) return;
|
||||
state.deoptPath = path;
|
||||
state.confident = false;
|
||||
}
|
||||
|
||||
function evaluateCached(path, state) {
|
||||
const {
|
||||
node
|
||||
} = path;
|
||||
const {
|
||||
seen
|
||||
} = state;
|
||||
|
||||
if (seen.has(node)) {
|
||||
const existing = seen.get(node);
|
||||
|
||||
if (existing.resolved) {
|
||||
return existing.value;
|
||||
} else {
|
||||
deopt(path, state);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
const item = {
|
||||
resolved: false
|
||||
};
|
||||
seen.set(node, item);
|
||||
|
||||
const val = _evaluate(path, state);
|
||||
|
||||
if (state.confident) {
|
||||
item.resolved = true;
|
||||
item.value = val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
function _evaluate(path, state) {
|
||||
if (!state.confident) return;
|
||||
|
||||
if (path.isSequenceExpression()) {
|
||||
const exprs = path.get("expressions");
|
||||
return evaluateCached(exprs[exprs.length - 1], state);
|
||||
}
|
||||
|
||||
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
|
||||
return path.node.value;
|
||||
}
|
||||
|
||||
if (path.isNullLiteral()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (path.isTemplateLiteral()) {
|
||||
return evaluateQuasis(path, path.node.quasis, state);
|
||||
}
|
||||
|
||||
if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) {
|
||||
const object = path.get("tag.object");
|
||||
const {
|
||||
node: {
|
||||
name
|
||||
}
|
||||
} = object;
|
||||
const property = path.get("tag.property");
|
||||
|
||||
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") {
|
||||
return evaluateQuasis(path, path.node.quasi.quasis, state, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isConditionalExpression()) {
|
||||
const testResult = evaluateCached(path.get("test"), state);
|
||||
if (!state.confident) return;
|
||||
|
||||
if (testResult) {
|
||||
return evaluateCached(path.get("consequent"), state);
|
||||
} else {
|
||||
return evaluateCached(path.get("alternate"), state);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isExpressionWrapper()) {
|
||||
return evaluateCached(path.get("expression"), state);
|
||||
}
|
||||
|
||||
if (path.isMemberExpression() && !path.parentPath.isCallExpression({
|
||||
callee: path.node
|
||||
})) {
|
||||
const property = path.get("property");
|
||||
const object = path.get("object");
|
||||
|
||||
if (object.isLiteral() && property.isIdentifier()) {
|
||||
const value = object.node.value;
|
||||
const type = typeof value;
|
||||
|
||||
if (type === "number" || type === "string") {
|
||||
return value[property.node.name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isReferencedIdentifier()) {
|
||||
const binding = path.scope.getBinding(path.node.name);
|
||||
|
||||
if (binding && binding.constantViolations.length > 0) {
|
||||
return deopt(binding.path, state);
|
||||
}
|
||||
|
||||
if (binding && path.node.start < binding.path.node.end) {
|
||||
return deopt(binding.path, state);
|
||||
}
|
||||
|
||||
if (binding != null && binding.hasValue) {
|
||||
return binding.value;
|
||||
} else {
|
||||
if (path.node.name === "undefined") {
|
||||
return binding ? deopt(binding.path, state) : undefined;
|
||||
} else if (path.node.name === "Infinity") {
|
||||
return binding ? deopt(binding.path, state) : Infinity;
|
||||
} else if (path.node.name === "NaN") {
|
||||
return binding ? deopt(binding.path, state) : NaN;
|
||||
}
|
||||
|
||||
const resolved = path.resolve();
|
||||
|
||||
if (resolved === path) {
|
||||
return deopt(path, state);
|
||||
} else {
|
||||
return evaluateCached(resolved, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isUnaryExpression({
|
||||
prefix: true
|
||||
})) {
|
||||
if (path.node.operator === "void") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const argument = path.get("argument");
|
||||
|
||||
if (path.node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
|
||||
return "function";
|
||||
}
|
||||
|
||||
const arg = evaluateCached(argument, state);
|
||||
if (!state.confident) return;
|
||||
|
||||
switch (path.node.operator) {
|
||||
case "!":
|
||||
return !arg;
|
||||
|
||||
case "+":
|
||||
return +arg;
|
||||
|
||||
case "-":
|
||||
return -arg;
|
||||
|
||||
case "~":
|
||||
return ~arg;
|
||||
|
||||
case "typeof":
|
||||
return typeof arg;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isArrayExpression()) {
|
||||
const arr = [];
|
||||
const elems = path.get("elements");
|
||||
|
||||
for (const elem of elems) {
|
||||
const elemValue = elem.evaluate();
|
||||
|
||||
if (elemValue.confident) {
|
||||
arr.push(elemValue.value);
|
||||
} else {
|
||||
return deopt(elemValue.deopt, state);
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
if (path.isObjectExpression()) {
|
||||
const obj = {};
|
||||
const props = path.get("properties");
|
||||
|
||||
for (const prop of props) {
|
||||
if (prop.isObjectMethod() || prop.isSpreadElement()) {
|
||||
return deopt(prop, state);
|
||||
}
|
||||
|
||||
const keyPath = prop.get("key");
|
||||
let key = keyPath;
|
||||
|
||||
if (prop.node.computed) {
|
||||
key = key.evaluate();
|
||||
|
||||
if (!key.confident) {
|
||||
return deopt(key.deopt, state);
|
||||
}
|
||||
|
||||
key = key.value;
|
||||
} else if (key.isIdentifier()) {
|
||||
key = key.node.name;
|
||||
} else {
|
||||
key = key.node.value;
|
||||
}
|
||||
|
||||
const valuePath = prop.get("value");
|
||||
let value = valuePath.evaluate();
|
||||
|
||||
if (!value.confident) {
|
||||
return deopt(value.deopt, state);
|
||||
}
|
||||
|
||||
value = value.value;
|
||||
obj[key] = value;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (path.isLogicalExpression()) {
|
||||
const wasConfident = state.confident;
|
||||
const left = evaluateCached(path.get("left"), state);
|
||||
const leftConfident = state.confident;
|
||||
state.confident = wasConfident;
|
||||
const right = evaluateCached(path.get("right"), state);
|
||||
const rightConfident = state.confident;
|
||||
|
||||
switch (path.node.operator) {
|
||||
case "||":
|
||||
state.confident = leftConfident && (!!left || rightConfident);
|
||||
if (!state.confident) return;
|
||||
return left || right;
|
||||
|
||||
case "&&":
|
||||
state.confident = leftConfident && (!left || rightConfident);
|
||||
if (!state.confident) return;
|
||||
return left && right;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isBinaryExpression()) {
|
||||
const left = evaluateCached(path.get("left"), state);
|
||||
if (!state.confident) return;
|
||||
const right = evaluateCached(path.get("right"), state);
|
||||
if (!state.confident) return;
|
||||
|
||||
switch (path.node.operator) {
|
||||
case "-":
|
||||
return left - right;
|
||||
|
||||
case "+":
|
||||
return left + right;
|
||||
|
||||
case "/":
|
||||
return left / right;
|
||||
|
||||
case "*":
|
||||
return left * right;
|
||||
|
||||
case "%":
|
||||
return left % right;
|
||||
|
||||
case "**":
|
||||
return Math.pow(left, right);
|
||||
|
||||
case "<":
|
||||
return left < right;
|
||||
|
||||
case ">":
|
||||
return left > right;
|
||||
|
||||
case "<=":
|
||||
return left <= right;
|
||||
|
||||
case ">=":
|
||||
return left >= right;
|
||||
|
||||
case "==":
|
||||
return left == right;
|
||||
|
||||
case "!=":
|
||||
return left != right;
|
||||
|
||||
case "===":
|
||||
return left === right;
|
||||
|
||||
case "!==":
|
||||
return left !== right;
|
||||
|
||||
case "|":
|
||||
return left | right;
|
||||
|
||||
case "&":
|
||||
return left & right;
|
||||
|
||||
case "^":
|
||||
return left ^ right;
|
||||
|
||||
case "<<":
|
||||
return left << right;
|
||||
|
||||
case ">>":
|
||||
return left >> right;
|
||||
|
||||
case ">>>":
|
||||
return left >>> right;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isCallExpression()) {
|
||||
const callee = path.get("callee");
|
||||
let context;
|
||||
let func;
|
||||
|
||||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
|
||||
func = global[callee.node.name];
|
||||
}
|
||||
|
||||
if (callee.isMemberExpression()) {
|
||||
const object = callee.get("object");
|
||||
const property = callee.get("property");
|
||||
|
||||
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
|
||||
context = global[object.node.name];
|
||||
func = context[property.node.name];
|
||||
}
|
||||
|
||||
if (object.isLiteral() && property.isIdentifier()) {
|
||||
const type = typeof object.node.value;
|
||||
|
||||
if (type === "string" || type === "number") {
|
||||
context = object.node.value;
|
||||
func = context[property.node.name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (func) {
|
||||
const args = path.get("arguments").map(arg => evaluateCached(arg, state));
|
||||
if (!state.confident) return;
|
||||
return func.apply(context, args);
|
||||
}
|
||||
}
|
||||
|
||||
deopt(path, state);
|
||||
}
|
||||
|
||||
function evaluateQuasis(path, quasis, state, raw = false) {
|
||||
let str = "";
|
||||
let i = 0;
|
||||
const exprs = path.get("expressions");
|
||||
|
||||
for (const elem of quasis) {
|
||||
if (!state.confident) break;
|
||||
str += raw ? elem.value.raw : elem.value.cooked;
|
||||
const expr = exprs[i++];
|
||||
if (expr) str += String(evaluateCached(expr, state));
|
||||
}
|
||||
|
||||
if (!state.confident) return;
|
||||
return str;
|
||||
}
|
||||
|
||||
function evaluate() {
|
||||
const state = {
|
||||
confident: true,
|
||||
deoptPath: null,
|
||||
seen: new Map()
|
||||
};
|
||||
let value = evaluateCached(this, state);
|
||||
if (!state.confident) value = undefined;
|
||||
return {
|
||||
confident: state.confident,
|
||||
deopt: state.deoptPath,
|
||||
value: value
|
||||
};
|
||||
}
|
|
@ -1,377 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getOpposite = getOpposite;
|
||||
exports.getCompletionRecords = getCompletionRecords;
|
||||
exports.getSibling = getSibling;
|
||||
exports.getPrevSibling = getPrevSibling;
|
||||
exports.getNextSibling = getNextSibling;
|
||||
exports.getAllNextSiblings = getAllNextSiblings;
|
||||
exports.getAllPrevSiblings = getAllPrevSiblings;
|
||||
exports.get = get;
|
||||
exports._getKey = _getKey;
|
||||
exports._getPattern = _getPattern;
|
||||
exports.getBindingIdentifiers = getBindingIdentifiers;
|
||||
exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
|
||||
exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
|
||||
exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const NORMAL_COMPLETION = 0;
|
||||
const BREAK_COMPLETION = 1;
|
||||
|
||||
function NormalCompletion(path) {
|
||||
return {
|
||||
type: NORMAL_COMPLETION,
|
||||
path
|
||||
};
|
||||
}
|
||||
|
||||
function BreakCompletion(path) {
|
||||
return {
|
||||
type: BREAK_COMPLETION,
|
||||
path
|
||||
};
|
||||
}
|
||||
|
||||
function getOpposite() {
|
||||
if (this.key === "left") {
|
||||
return this.getSibling("right");
|
||||
} else if (this.key === "right") {
|
||||
return this.getSibling("left");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function addCompletionRecords(path, records, context) {
|
||||
if (path) return records.concat(_getCompletionRecords(path, context));
|
||||
return records;
|
||||
}
|
||||
|
||||
function completionRecordForSwitch(cases, records, context) {
|
||||
let lastNormalCompletions = [];
|
||||
|
||||
for (let i = 0; i < cases.length; i++) {
|
||||
const casePath = cases[i];
|
||||
|
||||
const caseCompletions = _getCompletionRecords(casePath, context);
|
||||
|
||||
const normalCompletions = [];
|
||||
const breakCompletions = [];
|
||||
|
||||
for (const c of caseCompletions) {
|
||||
if (c.type === NORMAL_COMPLETION) {
|
||||
normalCompletions.push(c);
|
||||
}
|
||||
|
||||
if (c.type === BREAK_COMPLETION) {
|
||||
breakCompletions.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (normalCompletions.length) {
|
||||
lastNormalCompletions = normalCompletions;
|
||||
}
|
||||
|
||||
records = records.concat(breakCompletions);
|
||||
}
|
||||
|
||||
records = records.concat(lastNormalCompletions);
|
||||
return records;
|
||||
}
|
||||
|
||||
function normalCompletionToBreak(completions) {
|
||||
completions.forEach(c => {
|
||||
c.type = BREAK_COMPLETION;
|
||||
});
|
||||
}
|
||||
|
||||
function replaceBreakStatementInBreakCompletion(completions, reachable) {
|
||||
completions.forEach(c => {
|
||||
if (c.path.isBreakStatement({
|
||||
label: null
|
||||
})) {
|
||||
if (reachable) {
|
||||
c.path.replaceWith(t.unaryExpression("void", t.numericLiteral(0)));
|
||||
} else {
|
||||
c.path.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getStatementListCompletion(paths, context) {
|
||||
let completions = [];
|
||||
|
||||
if (context.canHaveBreak) {
|
||||
let lastNormalCompletions = [];
|
||||
|
||||
for (let i = 0; i < paths.length; i++) {
|
||||
const path = paths[i];
|
||||
const newContext = Object.assign({}, context, {
|
||||
inCaseClause: false
|
||||
});
|
||||
|
||||
if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) {
|
||||
newContext.shouldPopulateBreak = true;
|
||||
} else {
|
||||
newContext.shouldPopulateBreak = false;
|
||||
}
|
||||
|
||||
const statementCompletions = _getCompletionRecords(path, newContext);
|
||||
|
||||
if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
|
||||
if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({
|
||||
label: null
|
||||
}))) {
|
||||
normalCompletionToBreak(lastNormalCompletions);
|
||||
completions = completions.concat(lastNormalCompletions);
|
||||
|
||||
if (lastNormalCompletions.some(c => c.path.isDeclaration())) {
|
||||
completions = completions.concat(statementCompletions);
|
||||
replaceBreakStatementInBreakCompletion(statementCompletions, true);
|
||||
}
|
||||
|
||||
replaceBreakStatementInBreakCompletion(statementCompletions, false);
|
||||
} else {
|
||||
completions = completions.concat(statementCompletions);
|
||||
|
||||
if (!context.shouldPopulateBreak) {
|
||||
replaceBreakStatementInBreakCompletion(statementCompletions, true);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (i === paths.length - 1) {
|
||||
completions = completions.concat(statementCompletions);
|
||||
} else {
|
||||
completions = completions.concat(statementCompletions.filter(c => c.type === BREAK_COMPLETION));
|
||||
lastNormalCompletions = statementCompletions.filter(c => c.type === NORMAL_COMPLETION);
|
||||
}
|
||||
}
|
||||
} else if (paths.length) {
|
||||
completions = completions.concat(_getCompletionRecords(paths[paths.length - 1], context));
|
||||
}
|
||||
|
||||
return completions;
|
||||
}
|
||||
|
||||
function _getCompletionRecords(path, context) {
|
||||
let records = [];
|
||||
|
||||
if (path.isIfStatement()) {
|
||||
records = addCompletionRecords(path.get("consequent"), records, context);
|
||||
records = addCompletionRecords(path.get("alternate"), records, context);
|
||||
} else if (path.isDoExpression() || path.isFor() || path.isWhile() || path.isLabeledStatement()) {
|
||||
records = addCompletionRecords(path.get("body"), records, context);
|
||||
} else if (path.isProgram() || path.isBlockStatement()) {
|
||||
records = records.concat(getStatementListCompletion(path.get("body"), context));
|
||||
} else if (path.isFunction()) {
|
||||
return _getCompletionRecords(path.get("body"), context);
|
||||
} else if (path.isTryStatement()) {
|
||||
records = addCompletionRecords(path.get("block"), records, context);
|
||||
records = addCompletionRecords(path.get("handler"), records, context);
|
||||
} else if (path.isCatchClause()) {
|
||||
records = addCompletionRecords(path.get("body"), records, context);
|
||||
} else if (path.isSwitchStatement()) {
|
||||
records = completionRecordForSwitch(path.get("cases"), records, context);
|
||||
} else if (path.isSwitchCase()) {
|
||||
records = records.concat(getStatementListCompletion(path.get("consequent"), {
|
||||
canHaveBreak: true,
|
||||
shouldPopulateBreak: false,
|
||||
inCaseClause: true
|
||||
}));
|
||||
} else if (path.isBreakStatement()) {
|
||||
records.push(BreakCompletion(path));
|
||||
} else {
|
||||
records.push(NormalCompletion(path));
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
function getCompletionRecords() {
|
||||
const records = _getCompletionRecords(this, {
|
||||
canHaveBreak: false,
|
||||
shouldPopulateBreak: false,
|
||||
inCaseClause: false
|
||||
});
|
||||
|
||||
return records.map(r => r.path);
|
||||
}
|
||||
|
||||
function getSibling(key) {
|
||||
return _index.default.get({
|
||||
parentPath: this.parentPath,
|
||||
parent: this.parent,
|
||||
container: this.container,
|
||||
listKey: this.listKey,
|
||||
key: key
|
||||
}).setContext(this.context);
|
||||
}
|
||||
|
||||
function getPrevSibling() {
|
||||
return this.getSibling(this.key - 1);
|
||||
}
|
||||
|
||||
function getNextSibling() {
|
||||
return this.getSibling(this.key + 1);
|
||||
}
|
||||
|
||||
function getAllNextSiblings() {
|
||||
let _key = this.key;
|
||||
let sibling = this.getSibling(++_key);
|
||||
const siblings = [];
|
||||
|
||||
while (sibling.node) {
|
||||
siblings.push(sibling);
|
||||
sibling = this.getSibling(++_key);
|
||||
}
|
||||
|
||||
return siblings;
|
||||
}
|
||||
|
||||
function getAllPrevSiblings() {
|
||||
let _key = this.key;
|
||||
let sibling = this.getSibling(--_key);
|
||||
const siblings = [];
|
||||
|
||||
while (sibling.node) {
|
||||
siblings.push(sibling);
|
||||
sibling = this.getSibling(--_key);
|
||||
}
|
||||
|
||||
return siblings;
|
||||
}
|
||||
|
||||
function get(key, context = true) {
|
||||
if (context === true) context = this.context;
|
||||
const parts = key.split(".");
|
||||
|
||||
if (parts.length === 1) {
|
||||
return this._getKey(key, context);
|
||||
} else {
|
||||
return this._getPattern(parts, context);
|
||||
}
|
||||
}
|
||||
|
||||
function _getKey(key, context) {
|
||||
const node = this.node;
|
||||
const container = node[key];
|
||||
|
||||
if (Array.isArray(container)) {
|
||||
return container.map((_, i) => {
|
||||
return _index.default.get({
|
||||
listKey: key,
|
||||
parentPath: this,
|
||||
parent: node,
|
||||
container: container,
|
||||
key: i
|
||||
}).setContext(context);
|
||||
});
|
||||
} else {
|
||||
return _index.default.get({
|
||||
parentPath: this,
|
||||
parent: node,
|
||||
container: node,
|
||||
key: key
|
||||
}).setContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
function _getPattern(parts, context) {
|
||||
let path = this;
|
||||
|
||||
for (const part of parts) {
|
||||
if (part === ".") {
|
||||
path = path.parentPath;
|
||||
} else {
|
||||
if (Array.isArray(path)) {
|
||||
path = path[part];
|
||||
} else {
|
||||
path = path.get(part, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
function getBindingIdentifiers(duplicates) {
|
||||
return t.getBindingIdentifiers(this.node, duplicates);
|
||||
}
|
||||
|
||||
function getOuterBindingIdentifiers(duplicates) {
|
||||
return t.getOuterBindingIdentifiers(this.node, duplicates);
|
||||
}
|
||||
|
||||
function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
||||
const path = this;
|
||||
let search = [].concat(path);
|
||||
const ids = Object.create(null);
|
||||
|
||||
while (search.length) {
|
||||
const id = search.shift();
|
||||
if (!id) continue;
|
||||
if (!id.node) continue;
|
||||
const keys = t.getBindingIdentifiers.keys[id.node.type];
|
||||
|
||||
if (id.isIdentifier()) {
|
||||
if (duplicates) {
|
||||
const _ids = ids[id.node.name] = ids[id.node.name] || [];
|
||||
|
||||
_ids.push(id);
|
||||
} else {
|
||||
ids[id.node.name] = id;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id.isExportDeclaration()) {
|
||||
const declaration = id.get("declaration");
|
||||
|
||||
if (declaration.isDeclaration()) {
|
||||
search.push(declaration);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (outerOnly) {
|
||||
if (id.isFunctionDeclaration()) {
|
||||
search.push(id.get("id"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id.isFunctionExpression()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
const child = id.get(key);
|
||||
|
||||
if (Array.isArray(child) || child.node) {
|
||||
search = search.concat(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
function getOuterBindingIdentifierPaths(duplicates) {
|
||||
return this.getBindingIdentifierPaths(duplicates, true);
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _index = require("../index");
|
|
@ -1,5 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _index = require("../index");
|
|
@ -1,3 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
|
@ -1,247 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = exports.SHOULD_SKIP = exports.SHOULD_STOP = exports.REMOVED = void 0;
|
||||
|
||||
var virtualTypes = require("./lib/virtual-types");
|
||||
|
||||
var _debug = require("debug");
|
||||
|
||||
var _index = require("../index");
|
||||
|
||||
var _scope = require("../scope");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
var _generator = require("@babel/generator");
|
||||
|
||||
var NodePath_ancestry = require("./ancestry");
|
||||
|
||||
var NodePath_inference = require("./inference");
|
||||
|
||||
var NodePath_replacement = require("./replacement");
|
||||
|
||||
var NodePath_evaluation = require("./evaluation");
|
||||
|
||||
var NodePath_conversion = require("./conversion");
|
||||
|
||||
var NodePath_introspection = require("./introspection");
|
||||
|
||||
var NodePath_context = require("./context");
|
||||
|
||||
var NodePath_removal = require("./removal");
|
||||
|
||||
var NodePath_modification = require("./modification");
|
||||
|
||||
var NodePath_family = require("./family");
|
||||
|
||||
var NodePath_comments = require("./comments");
|
||||
|
||||
const debug = _debug("babel");
|
||||
|
||||
const REMOVED = 1 << 0;
|
||||
exports.REMOVED = REMOVED;
|
||||
const SHOULD_STOP = 1 << 1;
|
||||
exports.SHOULD_STOP = SHOULD_STOP;
|
||||
const SHOULD_SKIP = 1 << 2;
|
||||
exports.SHOULD_SKIP = SHOULD_SKIP;
|
||||
|
||||
class NodePath {
|
||||
constructor(hub, parent) {
|
||||
this.contexts = [];
|
||||
this.state = null;
|
||||
this.opts = null;
|
||||
this._traverseFlags = 0;
|
||||
this.skipKeys = null;
|
||||
this.parentPath = null;
|
||||
this.container = null;
|
||||
this.listKey = null;
|
||||
this.key = null;
|
||||
this.node = null;
|
||||
this.type = null;
|
||||
this.parent = parent;
|
||||
this.hub = hub;
|
||||
this.data = null;
|
||||
this.context = null;
|
||||
this.scope = null;
|
||||
}
|
||||
|
||||
static get({
|
||||
hub,
|
||||
parentPath,
|
||||
parent,
|
||||
container,
|
||||
listKey,
|
||||
key
|
||||
}) {
|
||||
if (!hub && parentPath) {
|
||||
hub = parentPath.hub;
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
throw new Error("To get a node path the parent needs to exist");
|
||||
}
|
||||
|
||||
const targetNode = container[key];
|
||||
|
||||
let paths = _cache.path.get(parent);
|
||||
|
||||
if (!paths) {
|
||||
paths = new Map();
|
||||
|
||||
_cache.path.set(parent, paths);
|
||||
}
|
||||
|
||||
let path = paths.get(targetNode);
|
||||
|
||||
if (!path) {
|
||||
path = new NodePath(hub, parent);
|
||||
if (targetNode) paths.set(targetNode, path);
|
||||
}
|
||||
|
||||
path.setup(parentPath, container, listKey, key);
|
||||
return path;
|
||||
}
|
||||
|
||||
getScope(scope) {
|
||||
return this.isScope() ? new _scope.default(this) : scope;
|
||||
}
|
||||
|
||||
setData(key, val) {
|
||||
if (this.data == null) {
|
||||
this.data = Object.create(null);
|
||||
}
|
||||
|
||||
return this.data[key] = val;
|
||||
}
|
||||
|
||||
getData(key, def) {
|
||||
if (this.data == null) {
|
||||
this.data = Object.create(null);
|
||||
}
|
||||
|
||||
let val = this.data[key];
|
||||
if (val === undefined && def !== undefined) val = this.data[key] = def;
|
||||
return val;
|
||||
}
|
||||
|
||||
buildCodeFrameError(msg, Error = SyntaxError) {
|
||||
return this.hub.buildError(this.node, msg, Error);
|
||||
}
|
||||
|
||||
traverse(visitor, state) {
|
||||
(0, _index.default)(this.node, visitor, this.scope, state, this);
|
||||
}
|
||||
|
||||
set(key, node) {
|
||||
t.validate(this.node, key, node);
|
||||
this.node[key] = node;
|
||||
}
|
||||
|
||||
getPathLocation() {
|
||||
const parts = [];
|
||||
let path = this;
|
||||
|
||||
do {
|
||||
let key = path.key;
|
||||
if (path.inList) key = `${path.listKey}[${key}]`;
|
||||
parts.unshift(key);
|
||||
} while (path = path.parentPath);
|
||||
|
||||
return parts.join(".");
|
||||
}
|
||||
|
||||
debug(message) {
|
||||
if (!debug.enabled) return;
|
||||
debug(`${this.getPathLocation()} ${this.type}: ${message}`);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (0, _generator.default)(this.node).code;
|
||||
}
|
||||
|
||||
get inList() {
|
||||
return !!this.listKey;
|
||||
}
|
||||
|
||||
set inList(inList) {
|
||||
if (!inList) {
|
||||
this.listKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
get parentKey() {
|
||||
return this.listKey || this.key;
|
||||
}
|
||||
|
||||
get shouldSkip() {
|
||||
return !!(this._traverseFlags & SHOULD_SKIP);
|
||||
}
|
||||
|
||||
set shouldSkip(v) {
|
||||
if (v) {
|
||||
this._traverseFlags |= SHOULD_SKIP;
|
||||
} else {
|
||||
this._traverseFlags &= ~SHOULD_SKIP;
|
||||
}
|
||||
}
|
||||
|
||||
get shouldStop() {
|
||||
return !!(this._traverseFlags & SHOULD_STOP);
|
||||
}
|
||||
|
||||
set shouldStop(v) {
|
||||
if (v) {
|
||||
this._traverseFlags |= SHOULD_STOP;
|
||||
} else {
|
||||
this._traverseFlags &= ~SHOULD_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
get removed() {
|
||||
return !!(this._traverseFlags & REMOVED);
|
||||
}
|
||||
|
||||
set removed(v) {
|
||||
if (v) {
|
||||
this._traverseFlags |= REMOVED;
|
||||
} else {
|
||||
this._traverseFlags &= ~REMOVED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
|
||||
|
||||
for (const type of t.TYPES) {
|
||||
const typeKey = `is${type}`;
|
||||
const fn = t[typeKey];
|
||||
|
||||
NodePath.prototype[typeKey] = function (opts) {
|
||||
return fn(this.node, opts);
|
||||
};
|
||||
|
||||
NodePath.prototype[`assert${type}`] = function (opts) {
|
||||
if (!fn(this.node, opts)) {
|
||||
throw new TypeError(`Expected node path of type ${type}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
for (const type of Object.keys(virtualTypes)) {
|
||||
if (type[0] === "_") continue;
|
||||
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type);
|
||||
const virtualType = virtualTypes[type];
|
||||
|
||||
NodePath.prototype[`is${type}`] = function (opts) {
|
||||
return virtualType.checkPath(this, opts);
|
||||
};
|
||||
}
|
||||
|
||||
var _default = NodePath;
|
||||
exports.default = _default;
|
|
@ -1,138 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getTypeAnnotation = getTypeAnnotation;
|
||||
exports._getTypeAnnotation = _getTypeAnnotation;
|
||||
exports.isBaseType = isBaseType;
|
||||
exports.couldBeBaseType = couldBeBaseType;
|
||||
exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
|
||||
exports.isGenericType = isGenericType;
|
||||
|
||||
var inferers = require("./inferers");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function getTypeAnnotation() {
|
||||
if (this.typeAnnotation) return this.typeAnnotation;
|
||||
let type = this._getTypeAnnotation() || t.anyTypeAnnotation();
|
||||
if (t.isTypeAnnotation(type)) type = type.typeAnnotation;
|
||||
return this.typeAnnotation = type;
|
||||
}
|
||||
|
||||
const typeAnnotationInferringNodes = new WeakSet();
|
||||
|
||||
function _getTypeAnnotation() {
|
||||
const node = this.node;
|
||||
|
||||
if (!node) {
|
||||
if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
|
||||
const declar = this.parentPath.parentPath;
|
||||
const declarParent = declar.parentPath;
|
||||
|
||||
if (declar.key === "left" && declarParent.isForInStatement()) {
|
||||
return t.stringTypeAnnotation();
|
||||
}
|
||||
|
||||
if (declar.key === "left" && declarParent.isForOfStatement()) {
|
||||
return t.anyTypeAnnotation();
|
||||
}
|
||||
|
||||
return t.voidTypeAnnotation();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.typeAnnotation) {
|
||||
return node.typeAnnotation;
|
||||
}
|
||||
|
||||
if (typeAnnotationInferringNodes.has(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
typeAnnotationInferringNodes.add(node);
|
||||
|
||||
try {
|
||||
var _inferer;
|
||||
|
||||
let inferer = inferers[node.type];
|
||||
|
||||
if (inferer) {
|
||||
return inferer.call(this, node);
|
||||
}
|
||||
|
||||
inferer = inferers[this.parentPath.type];
|
||||
|
||||
if ((_inferer = inferer) != null && _inferer.validParent) {
|
||||
return this.parentPath.getTypeAnnotation();
|
||||
}
|
||||
} finally {
|
||||
typeAnnotationInferringNodes.delete(node);
|
||||
}
|
||||
}
|
||||
|
||||
function isBaseType(baseName, soft) {
|
||||
return _isBaseType(baseName, this.getTypeAnnotation(), soft);
|
||||
}
|
||||
|
||||
function _isBaseType(baseName, type, soft) {
|
||||
if (baseName === "string") {
|
||||
return t.isStringTypeAnnotation(type);
|
||||
} else if (baseName === "number") {
|
||||
return t.isNumberTypeAnnotation(type);
|
||||
} else if (baseName === "boolean") {
|
||||
return t.isBooleanTypeAnnotation(type);
|
||||
} else if (baseName === "any") {
|
||||
return t.isAnyTypeAnnotation(type);
|
||||
} else if (baseName === "mixed") {
|
||||
return t.isMixedTypeAnnotation(type);
|
||||
} else if (baseName === "empty") {
|
||||
return t.isEmptyTypeAnnotation(type);
|
||||
} else if (baseName === "void") {
|
||||
return t.isVoidTypeAnnotation(type);
|
||||
} else {
|
||||
if (soft) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error(`Unknown base type ${baseName}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function couldBeBaseType(name) {
|
||||
const type = this.getTypeAnnotation();
|
||||
if (t.isAnyTypeAnnotation(type)) return true;
|
||||
|
||||
if (t.isUnionTypeAnnotation(type)) {
|
||||
for (const type2 of type.types) {
|
||||
if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return _isBaseType(name, type, true);
|
||||
}
|
||||
}
|
||||
|
||||
function baseTypeStrictlyMatches(rightArg) {
|
||||
const left = this.getTypeAnnotation();
|
||||
const right = rightArg.getTypeAnnotation();
|
||||
|
||||
if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) {
|
||||
return right.type === left.type;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isGenericType(genericName) {
|
||||
const type = this.getTypeAnnotation();
|
||||
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, {
|
||||
name: genericName
|
||||
});
|
||||
}
|
195
frontend/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
195
frontend/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
|
@ -1,195 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function _default(node) {
|
||||
if (!this.isReferenced()) return;
|
||||
const binding = this.scope.getBinding(node.name);
|
||||
|
||||
if (binding) {
|
||||
if (binding.identifier.typeAnnotation) {
|
||||
return binding.identifier.typeAnnotation;
|
||||
} else {
|
||||
return getTypeAnnotationBindingConstantViolations(binding, this, node.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.name === "undefined") {
|
||||
return t.voidTypeAnnotation();
|
||||
} else if (node.name === "NaN" || node.name === "Infinity") {
|
||||
return t.numberTypeAnnotation();
|
||||
} else if (node.name === "arguments") {}
|
||||
}
|
||||
|
||||
function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
||||
const types = [];
|
||||
const functionConstantViolations = [];
|
||||
let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
|
||||
const testType = getConditionalAnnotation(binding, path, name);
|
||||
|
||||
if (testType) {
|
||||
const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
|
||||
constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
|
||||
types.push(testType.typeAnnotation);
|
||||
}
|
||||
|
||||
if (constantViolations.length) {
|
||||
constantViolations = constantViolations.concat(functionConstantViolations);
|
||||
|
||||
for (const violation of constantViolations) {
|
||||
types.push(violation.getTypeAnnotation());
|
||||
}
|
||||
}
|
||||
|
||||
if (!types.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
|
||||
return t.createTSUnionType(types);
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return t.createFlowUnionType(types);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(types);
|
||||
}
|
||||
|
||||
function getConstantViolationsBefore(binding, path, functions) {
|
||||
const violations = binding.constantViolations.slice();
|
||||
violations.unshift(binding.path);
|
||||
return violations.filter(violation => {
|
||||
violation = violation.resolve();
|
||||
|
||||
const status = violation._guessExecutionStatusRelativeTo(path);
|
||||
|
||||
if (functions && status === "unknown") functions.push(violation);
|
||||
return status === "before";
|
||||
});
|
||||
}
|
||||
|
||||
function inferAnnotationFromBinaryExpression(name, path) {
|
||||
const operator = path.node.operator;
|
||||
const right = path.get("right").resolve();
|
||||
const left = path.get("left").resolve();
|
||||
let target;
|
||||
|
||||
if (left.isIdentifier({
|
||||
name
|
||||
})) {
|
||||
target = right;
|
||||
} else if (right.isIdentifier({
|
||||
name
|
||||
})) {
|
||||
target = left;
|
||||
}
|
||||
|
||||
if (target) {
|
||||
if (operator === "===") {
|
||||
return target.getTypeAnnotation();
|
||||
}
|
||||
|
||||
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t.numberTypeAnnotation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (operator !== "===" && operator !== "==") return;
|
||||
let typeofPath;
|
||||
let typePath;
|
||||
|
||||
if (left.isUnaryExpression({
|
||||
operator: "typeof"
|
||||
})) {
|
||||
typeofPath = left;
|
||||
typePath = right;
|
||||
} else if (right.isUnaryExpression({
|
||||
operator: "typeof"
|
||||
})) {
|
||||
typeofPath = right;
|
||||
typePath = left;
|
||||
}
|
||||
|
||||
if (!typeofPath) return;
|
||||
if (!typeofPath.get("argument").isIdentifier({
|
||||
name
|
||||
})) return;
|
||||
typePath = typePath.resolve();
|
||||
if (!typePath.isLiteral()) return;
|
||||
const typeValue = typePath.node.value;
|
||||
if (typeof typeValue !== "string") return;
|
||||
return t.createTypeAnnotationBasedOnTypeof(typeValue);
|
||||
}
|
||||
|
||||
function getParentConditionalPath(binding, path, name) {
|
||||
let parentPath;
|
||||
|
||||
while (parentPath = path.parentPath) {
|
||||
if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
|
||||
if (path.key === "test") {
|
||||
return;
|
||||
}
|
||||
|
||||
return parentPath;
|
||||
}
|
||||
|
||||
if (parentPath.isFunction()) {
|
||||
if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
|
||||
}
|
||||
|
||||
path = parentPath;
|
||||
}
|
||||
}
|
||||
|
||||
function getConditionalAnnotation(binding, path, name) {
|
||||
const ifStatement = getParentConditionalPath(binding, path, name);
|
||||
if (!ifStatement) return;
|
||||
const test = ifStatement.get("test");
|
||||
const paths = [test];
|
||||
const types = [];
|
||||
|
||||
for (let i = 0; i < paths.length; i++) {
|
||||
const path = paths[i];
|
||||
|
||||
if (path.isLogicalExpression()) {
|
||||
if (path.node.operator === "&&") {
|
||||
paths.push(path.get("left"));
|
||||
paths.push(path.get("right"));
|
||||
}
|
||||
} else if (path.isBinaryExpression()) {
|
||||
const type = inferAnnotationFromBinaryExpression(name, path);
|
||||
if (type) types.push(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
|
||||
return {
|
||||
typeAnnotation: t.createTSUnionType(types),
|
||||
ifStatement
|
||||
};
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return {
|
||||
typeAnnotation: t.createFlowUnionType(types),
|
||||
ifStatement
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
typeAnnotation: t.createUnionTypeAnnotation(types),
|
||||
ifStatement
|
||||
};
|
||||
}
|
||||
|
||||
return getConditionalAnnotation(ifStatement, name);
|
||||
}
|
|
@ -1,237 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.VariableDeclarator = VariableDeclarator;
|
||||
exports.TypeCastExpression = TypeCastExpression;
|
||||
exports.NewExpression = NewExpression;
|
||||
exports.TemplateLiteral = TemplateLiteral;
|
||||
exports.UnaryExpression = UnaryExpression;
|
||||
exports.BinaryExpression = BinaryExpression;
|
||||
exports.LogicalExpression = LogicalExpression;
|
||||
exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.SequenceExpression = SequenceExpression;
|
||||
exports.ParenthesizedExpression = ParenthesizedExpression;
|
||||
exports.AssignmentExpression = AssignmentExpression;
|
||||
exports.UpdateExpression = UpdateExpression;
|
||||
exports.StringLiteral = StringLiteral;
|
||||
exports.NumericLiteral = NumericLiteral;
|
||||
exports.BooleanLiteral = BooleanLiteral;
|
||||
exports.NullLiteral = NullLiteral;
|
||||
exports.RegExpLiteral = RegExpLiteral;
|
||||
exports.ObjectExpression = ObjectExpression;
|
||||
exports.ArrayExpression = ArrayExpression;
|
||||
exports.RestElement = RestElement;
|
||||
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
|
||||
exports.CallExpression = CallExpression;
|
||||
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
||||
Object.defineProperty(exports, "Identifier", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _infererReference.default;
|
||||
}
|
||||
});
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _infererReference = require("./inferer-reference");
|
||||
|
||||
function VariableDeclarator() {
|
||||
var _type;
|
||||
|
||||
const id = this.get("id");
|
||||
if (!id.isIdentifier()) return;
|
||||
const init = this.get("init");
|
||||
let type = init.getTypeAnnotation();
|
||||
|
||||
if (((_type = type) == null ? void 0 : _type.type) === "AnyTypeAnnotation") {
|
||||
if (init.isCallExpression() && init.get("callee").isIdentifier({
|
||||
name: "Array"
|
||||
}) && !init.scope.hasBinding("Array", true)) {
|
||||
type = ArrayExpression();
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function TypeCastExpression(node) {
|
||||
return node.typeAnnotation;
|
||||
}
|
||||
|
||||
TypeCastExpression.validParent = true;
|
||||
|
||||
function NewExpression(node) {
|
||||
if (this.get("callee").isIdentifier()) {
|
||||
return t.genericTypeAnnotation(node.callee);
|
||||
}
|
||||
}
|
||||
|
||||
function TemplateLiteral() {
|
||||
return t.stringTypeAnnotation();
|
||||
}
|
||||
|
||||
function UnaryExpression(node) {
|
||||
const operator = node.operator;
|
||||
|
||||
if (operator === "void") {
|
||||
return t.voidTypeAnnotation();
|
||||
} else if (t.NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t.numberTypeAnnotation();
|
||||
} else if (t.STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t.stringTypeAnnotation();
|
||||
} else if (t.BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t.booleanTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function BinaryExpression(node) {
|
||||
const operator = node.operator;
|
||||
|
||||
if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t.numberTypeAnnotation();
|
||||
} else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t.booleanTypeAnnotation();
|
||||
} else if (operator === "+") {
|
||||
const right = this.get("right");
|
||||
const left = this.get("left");
|
||||
|
||||
if (left.isBaseType("number") && right.isBaseType("number")) {
|
||||
return t.numberTypeAnnotation();
|
||||
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
||||
return t.stringTypeAnnotation();
|
||||
}
|
||||
|
||||
return t.unionTypeAnnotation([t.stringTypeAnnotation(), t.numberTypeAnnotation()]);
|
||||
}
|
||||
}
|
||||
|
||||
function LogicalExpression() {
|
||||
const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
|
||||
|
||||
if (t.isTSTypeAnnotation(argumentTypes[0]) && t.createTSUnionType) {
|
||||
return t.createTSUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return t.createFlowUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(argumentTypes);
|
||||
}
|
||||
|
||||
function ConditionalExpression() {
|
||||
const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
|
||||
|
||||
if (t.isTSTypeAnnotation(argumentTypes[0]) && t.createTSUnionType) {
|
||||
return t.createTSUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return t.createFlowUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(argumentTypes);
|
||||
}
|
||||
|
||||
function SequenceExpression() {
|
||||
return this.get("expressions").pop().getTypeAnnotation();
|
||||
}
|
||||
|
||||
function ParenthesizedExpression() {
|
||||
return this.get("expression").getTypeAnnotation();
|
||||
}
|
||||
|
||||
function AssignmentExpression() {
|
||||
return this.get("right").getTypeAnnotation();
|
||||
}
|
||||
|
||||
function UpdateExpression(node) {
|
||||
const operator = node.operator;
|
||||
|
||||
if (operator === "++" || operator === "--") {
|
||||
return t.numberTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function StringLiteral() {
|
||||
return t.stringTypeAnnotation();
|
||||
}
|
||||
|
||||
function NumericLiteral() {
|
||||
return t.numberTypeAnnotation();
|
||||
}
|
||||
|
||||
function BooleanLiteral() {
|
||||
return t.booleanTypeAnnotation();
|
||||
}
|
||||
|
||||
function NullLiteral() {
|
||||
return t.nullLiteralTypeAnnotation();
|
||||
}
|
||||
|
||||
function RegExpLiteral() {
|
||||
return t.genericTypeAnnotation(t.identifier("RegExp"));
|
||||
}
|
||||
|
||||
function ObjectExpression() {
|
||||
return t.genericTypeAnnotation(t.identifier("Object"));
|
||||
}
|
||||
|
||||
function ArrayExpression() {
|
||||
return t.genericTypeAnnotation(t.identifier("Array"));
|
||||
}
|
||||
|
||||
function RestElement() {
|
||||
return ArrayExpression();
|
||||
}
|
||||
|
||||
RestElement.validParent = true;
|
||||
|
||||
function Func() {
|
||||
return t.genericTypeAnnotation(t.identifier("Function"));
|
||||
}
|
||||
|
||||
const isArrayFrom = t.buildMatchMemberExpression("Array.from");
|
||||
const isObjectKeys = t.buildMatchMemberExpression("Object.keys");
|
||||
const isObjectValues = t.buildMatchMemberExpression("Object.values");
|
||||
const isObjectEntries = t.buildMatchMemberExpression("Object.entries");
|
||||
|
||||
function CallExpression() {
|
||||
const {
|
||||
callee
|
||||
} = this.node;
|
||||
|
||||
if (isObjectKeys(callee)) {
|
||||
return t.arrayTypeAnnotation(t.stringTypeAnnotation());
|
||||
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
||||
return t.arrayTypeAnnotation(t.anyTypeAnnotation());
|
||||
} else if (isObjectEntries(callee)) {
|
||||
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()]));
|
||||
}
|
||||
|
||||
return resolveCall(this.get("callee"));
|
||||
}
|
||||
|
||||
function TaggedTemplateExpression() {
|
||||
return resolveCall(this.get("tag"));
|
||||
}
|
||||
|
||||
function resolveCall(callee) {
|
||||
callee = callee.resolve();
|
||||
|
||||
if (callee.isFunction()) {
|
||||
if (callee.is("async")) {
|
||||
if (callee.is("generator")) {
|
||||
return t.genericTypeAnnotation(t.identifier("AsyncIterator"));
|
||||
} else {
|
||||
return t.genericTypeAnnotation(t.identifier("Promise"));
|
||||
}
|
||||
} else {
|
||||
if (callee.node.returnType) {
|
||||
return callee.node.returnType;
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,424 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.matchesPattern = matchesPattern;
|
||||
exports.has = has;
|
||||
exports.isStatic = isStatic;
|
||||
exports.isnt = isnt;
|
||||
exports.equals = equals;
|
||||
exports.isNodeType = isNodeType;
|
||||
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
|
||||
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
|
||||
exports.isCompletionRecord = isCompletionRecord;
|
||||
exports.isStatementOrBlock = isStatementOrBlock;
|
||||
exports.referencesImport = referencesImport;
|
||||
exports.getSource = getSource;
|
||||
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
|
||||
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
|
||||
exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
|
||||
exports.resolve = resolve;
|
||||
exports._resolve = _resolve;
|
||||
exports.isConstantExpression = isConstantExpression;
|
||||
exports.isInStrictMode = isInStrictMode;
|
||||
exports.is = void 0;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function matchesPattern(pattern, allowPartial) {
|
||||
return t.matchesPattern(this.node, pattern, allowPartial);
|
||||
}
|
||||
|
||||
function has(key) {
|
||||
const val = this.node && this.node[key];
|
||||
|
||||
if (val && Array.isArray(val)) {
|
||||
return !!val.length;
|
||||
} else {
|
||||
return !!val;
|
||||
}
|
||||
}
|
||||
|
||||
function isStatic() {
|
||||
return this.scope.isStatic(this.node);
|
||||
}
|
||||
|
||||
const is = has;
|
||||
exports.is = is;
|
||||
|
||||
function isnt(key) {
|
||||
return !this.has(key);
|
||||
}
|
||||
|
||||
function equals(key, value) {
|
||||
return this.node[key] === value;
|
||||
}
|
||||
|
||||
function isNodeType(type) {
|
||||
return t.isType(this.type, type);
|
||||
}
|
||||
|
||||
function canHaveVariableDeclarationOrExpression() {
|
||||
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
|
||||
}
|
||||
|
||||
function canSwapBetweenExpressionAndStatement(replacement) {
|
||||
if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isExpression()) {
|
||||
return t.isBlockStatement(replacement);
|
||||
} else if (this.isBlockStatement()) {
|
||||
return t.isExpression(replacement);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isCompletionRecord(allowInsideFunction) {
|
||||
let path = this;
|
||||
let first = true;
|
||||
|
||||
do {
|
||||
const container = path.container;
|
||||
|
||||
if (path.isFunction() && !first) {
|
||||
return !!allowInsideFunction;
|
||||
}
|
||||
|
||||
first = false;
|
||||
|
||||
if (Array.isArray(container) && path.key !== container.length - 1) {
|
||||
return false;
|
||||
}
|
||||
} while ((path = path.parentPath) && !path.isProgram());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isStatementOrBlock() {
|
||||
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) {
|
||||
return false;
|
||||
} else {
|
||||
return t.STATEMENT_OR_BLOCK_KEYS.includes(this.key);
|
||||
}
|
||||
}
|
||||
|
||||
function referencesImport(moduleSource, importName) {
|
||||
if (!this.isReferencedIdentifier()) {
|
||||
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? t.isStringLiteral(this.node.property, {
|
||||
value: importName
|
||||
}) : this.node.property.name === importName)) {
|
||||
const object = this.get("object");
|
||||
return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const binding = this.scope.getBinding(this.node.name);
|
||||
if (!binding || binding.kind !== "module") return false;
|
||||
const path = binding.path;
|
||||
const parent = path.parentPath;
|
||||
if (!parent.isImportDeclaration()) return false;
|
||||
|
||||
if (parent.node.source.value === moduleSource) {
|
||||
if (!importName) return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (path.isImportDefaultSpecifier() && importName === "default") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (path.isImportSpecifier() && t.isIdentifier(path.node.imported, {
|
||||
name: importName
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSource() {
|
||||
const node = this.node;
|
||||
|
||||
if (node.end) {
|
||||
const code = this.hub.getCode();
|
||||
if (code) return code.slice(node.start, node.end);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
function willIMaybeExecuteBefore(target) {
|
||||
return this._guessExecutionStatusRelativeTo(target) !== "after";
|
||||
}
|
||||
|
||||
function getOuterFunction(path) {
|
||||
return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;
|
||||
}
|
||||
|
||||
function isExecutionUncertain(type, key) {
|
||||
switch (type) {
|
||||
case "LogicalExpression":
|
||||
return key === "right";
|
||||
|
||||
case "ConditionalExpression":
|
||||
case "IfStatement":
|
||||
return key === "consequent" || key === "alternate";
|
||||
|
||||
case "WhileStatement":
|
||||
case "DoWhileStatement":
|
||||
case "ForInStatement":
|
||||
case "ForOfStatement":
|
||||
return key === "body";
|
||||
|
||||
case "ForStatement":
|
||||
return key === "body" || key === "update";
|
||||
|
||||
case "SwitchStatement":
|
||||
return key === "cases";
|
||||
|
||||
case "TryStatement":
|
||||
return key === "handler";
|
||||
|
||||
case "AssignmentPattern":
|
||||
return key === "right";
|
||||
|
||||
case "OptionalMemberExpression":
|
||||
return key === "property";
|
||||
|
||||
case "OptionalCallExpression":
|
||||
return key === "arguments";
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isExecutionUncertainInList(paths, maxIndex) {
|
||||
for (let i = 0; i < maxIndex; i++) {
|
||||
const path = paths[i];
|
||||
|
||||
if (isExecutionUncertain(path.parent.type, path.parentKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _guessExecutionStatusRelativeTo(target) {
|
||||
const funcParent = {
|
||||
this: getOuterFunction(this),
|
||||
target: getOuterFunction(target)
|
||||
};
|
||||
|
||||
if (funcParent.target.node !== funcParent.this.node) {
|
||||
return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
|
||||
}
|
||||
|
||||
const paths = {
|
||||
target: target.getAncestry(),
|
||||
this: this.getAncestry()
|
||||
};
|
||||
if (paths.target.indexOf(this) >= 0) return "after";
|
||||
if (paths.this.indexOf(target) >= 0) return "before";
|
||||
let commonPath;
|
||||
const commonIndex = {
|
||||
target: 0,
|
||||
this: 0
|
||||
};
|
||||
|
||||
while (!commonPath && commonIndex.this < paths.this.length) {
|
||||
const path = paths.this[commonIndex.this];
|
||||
commonIndex.target = paths.target.indexOf(path);
|
||||
|
||||
if (commonIndex.target >= 0) {
|
||||
commonPath = path;
|
||||
} else {
|
||||
commonIndex.this++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!commonPath) {
|
||||
throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
|
||||
}
|
||||
|
||||
if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const divergence = {
|
||||
this: paths.this[commonIndex.this - 1],
|
||||
target: paths.target[commonIndex.target - 1]
|
||||
};
|
||||
|
||||
if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
|
||||
return divergence.target.key > divergence.this.key ? "before" : "after";
|
||||
}
|
||||
|
||||
const keys = t.VISITOR_KEYS[commonPath.type];
|
||||
const keyPosition = {
|
||||
this: keys.indexOf(divergence.this.parentKey),
|
||||
target: keys.indexOf(divergence.target.parentKey)
|
||||
};
|
||||
return keyPosition.target > keyPosition.this ? "before" : "after";
|
||||
}
|
||||
|
||||
const executionOrderCheckedNodes = new WeakSet();
|
||||
|
||||
function _guessExecutionStatusRelativeToDifferentFunctions(target) {
|
||||
if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const binding = target.scope.getBinding(target.node.id.name);
|
||||
if (!binding.references) return "before";
|
||||
const referencePaths = binding.referencePaths;
|
||||
let allStatus;
|
||||
|
||||
for (const path of referencePaths) {
|
||||
const childOfFunction = !!path.find(path => path.node === target.node);
|
||||
if (childOfFunction) continue;
|
||||
|
||||
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
if (executionOrderCheckedNodes.has(path.node)) continue;
|
||||
executionOrderCheckedNodes.add(path.node);
|
||||
|
||||
const status = this._guessExecutionStatusRelativeTo(path);
|
||||
|
||||
executionOrderCheckedNodes.delete(path.node);
|
||||
|
||||
if (allStatus && allStatus !== status) {
|
||||
return "unknown";
|
||||
} else {
|
||||
allStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
return allStatus;
|
||||
}
|
||||
|
||||
function resolve(dangerous, resolved) {
|
||||
return this._resolve(dangerous, resolved) || this;
|
||||
}
|
||||
|
||||
function _resolve(dangerous, resolved) {
|
||||
if (resolved && resolved.indexOf(this) >= 0) return;
|
||||
resolved = resolved || [];
|
||||
resolved.push(this);
|
||||
|
||||
if (this.isVariableDeclarator()) {
|
||||
if (this.get("id").isIdentifier()) {
|
||||
return this.get("init").resolve(dangerous, resolved);
|
||||
} else {}
|
||||
} else if (this.isReferencedIdentifier()) {
|
||||
const binding = this.scope.getBinding(this.node.name);
|
||||
if (!binding) return;
|
||||
if (!binding.constant) return;
|
||||
if (binding.kind === "module") return;
|
||||
|
||||
if (binding.path !== this) {
|
||||
const ret = binding.path.resolve(dangerous, resolved);
|
||||
if (this.find(parent => parent.node === ret.node)) return;
|
||||
return ret;
|
||||
}
|
||||
} else if (this.isTypeCastExpression()) {
|
||||
return this.get("expression").resolve(dangerous, resolved);
|
||||
} else if (dangerous && this.isMemberExpression()) {
|
||||
const targetKey = this.toComputedKey();
|
||||
if (!t.isLiteral(targetKey)) return;
|
||||
const targetName = targetKey.value;
|
||||
const target = this.get("object").resolve(dangerous, resolved);
|
||||
|
||||
if (target.isObjectExpression()) {
|
||||
const props = target.get("properties");
|
||||
|
||||
for (const prop of props) {
|
||||
if (!prop.isProperty()) continue;
|
||||
const key = prop.get("key");
|
||||
let match = prop.isnt("computed") && key.isIdentifier({
|
||||
name: targetName
|
||||
});
|
||||
match = match || key.isLiteral({
|
||||
value: targetName
|
||||
});
|
||||
if (match) return prop.get("value").resolve(dangerous, resolved);
|
||||
}
|
||||
} else if (target.isArrayExpression() && !isNaN(+targetName)) {
|
||||
const elems = target.get("elements");
|
||||
const elem = elems[targetName];
|
||||
if (elem) return elem.resolve(dangerous, resolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isConstantExpression() {
|
||||
if (this.isIdentifier()) {
|
||||
const binding = this.scope.getBinding(this.node.name);
|
||||
if (!binding) return false;
|
||||
return binding.constant;
|
||||
}
|
||||
|
||||
if (this.isLiteral()) {
|
||||
if (this.isRegExpLiteral()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isTemplateLiteral()) {
|
||||
return this.get("expressions").every(expression => expression.isConstantExpression());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.isUnaryExpression()) {
|
||||
if (this.node.operator !== "void") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.get("argument").isConstantExpression();
|
||||
}
|
||||
|
||||
if (this.isBinaryExpression()) {
|
||||
return this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isInStrictMode() {
|
||||
const start = this.isProgram() ? this : this.parentPath;
|
||||
const strictParent = start.find(path => {
|
||||
if (path.isProgram({
|
||||
sourceType: "module"
|
||||
})) return true;
|
||||
if (path.isClass()) return true;
|
||||
if (!path.isProgram() && !path.isFunction()) return false;
|
||||
|
||||
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const body = path.isFunction() ? path.node.body : path.node;
|
||||
|
||||
for (const directive of body.directives) {
|
||||
if (directive.value.value === "use strict") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return !!strictParent;
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const referenceVisitor = {
|
||||
ReferencedIdentifier(path, state) {
|
||||
if (path.isJSXIdentifier() && t.react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.node.name === "this") {
|
||||
let scope = path.scope;
|
||||
|
||||
do {
|
||||
if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
||||
break;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
if (scope) state.breakOnScopePaths.push(scope.path);
|
||||
}
|
||||
|
||||
const binding = path.scope.getBinding(path.node.name);
|
||||
if (!binding) return;
|
||||
|
||||
for (const violation of binding.constantViolations) {
|
||||
if (violation.scope !== binding.path.scope) {
|
||||
state.mutableBinding = true;
|
||||
path.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (binding !== state.scope.getBinding(path.node.name)) return;
|
||||
state.bindings[path.node.name] = binding;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class PathHoister {
|
||||
constructor(path, scope) {
|
||||
this.breakOnScopePaths = void 0;
|
||||
this.bindings = void 0;
|
||||
this.mutableBinding = void 0;
|
||||
this.scopes = void 0;
|
||||
this.scope = void 0;
|
||||
this.path = void 0;
|
||||
this.attachAfter = void 0;
|
||||
this.breakOnScopePaths = [];
|
||||
this.bindings = {};
|
||||
this.mutableBinding = false;
|
||||
this.scopes = [];
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
this.attachAfter = false;
|
||||
}
|
||||
|
||||
isCompatibleScope(scope) {
|
||||
for (const key of Object.keys(this.bindings)) {
|
||||
const binding = this.bindings[key];
|
||||
|
||||
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
getCompatibleScopes() {
|
||||
let scope = this.path.scope;
|
||||
|
||||
do {
|
||||
if (this.isCompatibleScope(scope)) {
|
||||
this.scopes.push(scope);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
||||
break;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
}
|
||||
|
||||
getAttachmentPath() {
|
||||
let path = this._getAttachmentPath();
|
||||
|
||||
if (!path) return;
|
||||
let targetScope = path.scope;
|
||||
|
||||
if (targetScope.path === path) {
|
||||
targetScope = path.scope.parent;
|
||||
}
|
||||
|
||||
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
||||
for (const name of Object.keys(this.bindings)) {
|
||||
if (!targetScope.hasOwnBinding(name)) continue;
|
||||
const binding = this.bindings[name];
|
||||
|
||||
if (binding.kind === "param" || binding.path.parentKey === "params") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const bindingParentPath = this.getAttachmentParentForPath(binding.path);
|
||||
|
||||
if (bindingParentPath.key >= path.key) {
|
||||
this.attachAfter = true;
|
||||
path = binding.path;
|
||||
|
||||
for (const violationPath of binding.constantViolations) {
|
||||
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
||||
path = violationPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
_getAttachmentPath() {
|
||||
const scopes = this.scopes;
|
||||
const scope = scopes.pop();
|
||||
if (!scope) return;
|
||||
|
||||
if (scope.path.isFunction()) {
|
||||
if (this.hasOwnParamBindings(scope)) {
|
||||
if (this.scope === scope) return;
|
||||
const bodies = scope.path.get("body").get("body");
|
||||
|
||||
for (let i = 0; i < bodies.length; i++) {
|
||||
if (bodies[i].node._blockHoist) continue;
|
||||
return bodies[i];
|
||||
}
|
||||
} else {
|
||||
return this.getNextScopeAttachmentParent();
|
||||
}
|
||||
} else if (scope.path.isProgram()) {
|
||||
return this.getNextScopeAttachmentParent();
|
||||
}
|
||||
}
|
||||
|
||||
getNextScopeAttachmentParent() {
|
||||
const scope = this.scopes.pop();
|
||||
if (scope) return this.getAttachmentParentForPath(scope.path);
|
||||
}
|
||||
|
||||
getAttachmentParentForPath(path) {
|
||||
do {
|
||||
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
||||
return path;
|
||||
}
|
||||
} while (path = path.parentPath);
|
||||
}
|
||||
|
||||
hasOwnParamBindings(scope) {
|
||||
for (const name of Object.keys(this.bindings)) {
|
||||
if (!scope.hasOwnBinding(name)) continue;
|
||||
const binding = this.bindings[name];
|
||||
if (binding.kind === "param" && binding.constant) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
run() {
|
||||
this.path.traverse(referenceVisitor, this);
|
||||
if (this.mutableBinding) return;
|
||||
this.getCompatibleScopes();
|
||||
const attachTo = this.getAttachmentPath();
|
||||
if (!attachTo) return;
|
||||
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
||||
let uid = attachTo.scope.generateUidIdentifier("ref");
|
||||
const declarator = t.variableDeclarator(uid, this.path.node);
|
||||
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
||||
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator])]);
|
||||
const parent = this.path.parentPath;
|
||||
|
||||
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
||||
uid = t.jsxExpressionContainer(uid);
|
||||
}
|
||||
|
||||
this.path.replaceWith(t.cloneNode(uid));
|
||||
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = PathHoister;
|
|
@ -1,38 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hooks = void 0;
|
||||
const hooks = [function (self, parent) {
|
||||
const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
|
||||
|
||||
if (removeParent) {
|
||||
parent.remove();
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
||||
parent.replaceWith(parent.node.expressions[0]);
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isBinary()) {
|
||||
if (self.key === "left") {
|
||||
parent.replaceWith(parent.node.right);
|
||||
} else {
|
||||
parent.replaceWith(parent.node.left);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isIfStatement() && (self.key === "consequent" || self.key === "alternate") || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
||||
self.replaceWith({
|
||||
type: "BlockStatement",
|
||||
body: []
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}];
|
||||
exports.hooks = hooks;
|
|
@ -1,206 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const ReferencedIdentifier = {
|
||||
types: ["Identifier", "JSXIdentifier"],
|
||||
|
||||
checkPath(path, opts) {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = path;
|
||||
|
||||
if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) {
|
||||
if (t.isJSXIdentifier(node, opts)) {
|
||||
if (t.react.isCompatTag(node.name)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return t.isReferenced(node, parent, path.parentPath.parent);
|
||||
}
|
||||
|
||||
};
|
||||
exports.ReferencedIdentifier = ReferencedIdentifier;
|
||||
const ReferencedMemberExpression = {
|
||||
types: ["MemberExpression"],
|
||||
|
||||
checkPath({
|
||||
node,
|
||||
parent
|
||||
}) {
|
||||
return t.isMemberExpression(node) && t.isReferenced(node, parent);
|
||||
}
|
||||
|
||||
};
|
||||
exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
||||
const BindingIdentifier = {
|
||||
types: ["Identifier"],
|
||||
|
||||
checkPath(path) {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = path;
|
||||
const grandparent = path.parentPath.parent;
|
||||
return t.isIdentifier(node) && t.isBinding(node, parent, grandparent);
|
||||
}
|
||||
|
||||
};
|
||||
exports.BindingIdentifier = BindingIdentifier;
|
||||
const Statement = {
|
||||
types: ["Statement"],
|
||||
|
||||
checkPath({
|
||||
node,
|
||||
parent
|
||||
}) {
|
||||
if (t.isStatement(node)) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (t.isForXStatement(parent, {
|
||||
left: node
|
||||
})) return false;
|
||||
if (t.isForStatement(parent, {
|
||||
init: node
|
||||
})) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
exports.Statement = Statement;
|
||||
const Expression = {
|
||||
types: ["Expression"],
|
||||
|
||||
checkPath(path) {
|
||||
if (path.isIdentifier()) {
|
||||
return path.isReferencedIdentifier();
|
||||
} else {
|
||||
return t.isExpression(path.node);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
exports.Expression = Expression;
|
||||
const Scope = {
|
||||
types: ["Scopable", "Pattern"],
|
||||
|
||||
checkPath(path) {
|
||||
return t.isScope(path.node, path.parent);
|
||||
}
|
||||
|
||||
};
|
||||
exports.Scope = Scope;
|
||||
const Referenced = {
|
||||
checkPath(path) {
|
||||
return t.isReferenced(path.node, path.parent);
|
||||
}
|
||||
|
||||
};
|
||||
exports.Referenced = Referenced;
|
||||
const BlockScoped = {
|
||||
checkPath(path) {
|
||||
return t.isBlockScoped(path.node);
|
||||
}
|
||||
|
||||
};
|
||||
exports.BlockScoped = BlockScoped;
|
||||
const Var = {
|
||||
types: ["VariableDeclaration"],
|
||||
|
||||
checkPath(path) {
|
||||
return t.isVar(path.node);
|
||||
}
|
||||
|
||||
};
|
||||
exports.Var = Var;
|
||||
const User = {
|
||||
checkPath(path) {
|
||||
return path.node && !!path.node.loc;
|
||||
}
|
||||
|
||||
};
|
||||
exports.User = User;
|
||||
const Generated = {
|
||||
checkPath(path) {
|
||||
return !path.isUser();
|
||||
}
|
||||
|
||||
};
|
||||
exports.Generated = Generated;
|
||||
const Pure = {
|
||||
checkPath(path, opts) {
|
||||
return path.scope.isPure(path.node, opts);
|
||||
}
|
||||
|
||||
};
|
||||
exports.Pure = Pure;
|
||||
const Flow = {
|
||||
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
|
||||
|
||||
checkPath({
|
||||
node
|
||||
}) {
|
||||
if (t.isFlow(node)) {
|
||||
return true;
|
||||
} else if (t.isImportDeclaration(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else if (t.isExportDeclaration(node)) {
|
||||
return node.exportKind === "type";
|
||||
} else if (t.isImportSpecifier(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
exports.Flow = Flow;
|
||||
const RestProperty = {
|
||||
types: ["RestElement"],
|
||||
|
||||
checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectPattern();
|
||||
}
|
||||
|
||||
};
|
||||
exports.RestProperty = RestProperty;
|
||||
const SpreadProperty = {
|
||||
types: ["RestElement"],
|
||||
|
||||
checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectExpression();
|
||||
}
|
||||
|
||||
};
|
||||
exports.SpreadProperty = SpreadProperty;
|
||||
const ExistentialTypeParam = {
|
||||
types: ["ExistsTypeAnnotation"]
|
||||
};
|
||||
exports.ExistentialTypeParam = ExistentialTypeParam;
|
||||
const NumericLiteralTypeAnnotation = {
|
||||
types: ["NumberLiteralTypeAnnotation"]
|
||||
};
|
||||
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
|
||||
const ForAwaitStatement = {
|
||||
types: ["ForOfStatement"],
|
||||
|
||||
checkPath({
|
||||
node
|
||||
}) {
|
||||
return node.await === true;
|
||||
}
|
||||
|
||||
};
|
||||
exports.ForAwaitStatement = ForAwaitStatement;
|
|
@ -1,221 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.insertBefore = insertBefore;
|
||||
exports._containerInsert = _containerInsert;
|
||||
exports._containerInsertBefore = _containerInsertBefore;
|
||||
exports._containerInsertAfter = _containerInsertAfter;
|
||||
exports.insertAfter = insertAfter;
|
||||
exports.updateSiblingKeys = updateSiblingKeys;
|
||||
exports._verifyNodeList = _verifyNodeList;
|
||||
exports.unshiftContainer = unshiftContainer;
|
||||
exports.pushContainer = pushContainer;
|
||||
exports.hoist = hoist;
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
var _hoister = require("./lib/hoister");
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function insertBefore(nodes_) {
|
||||
this._assertUnremoved();
|
||||
|
||||
const nodes = this._verifyNodeList(nodes_);
|
||||
|
||||
const {
|
||||
parentPath
|
||||
} = this;
|
||||
|
||||
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
||||
return parentPath.insertBefore(nodes);
|
||||
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
||||
if (this.node) nodes.push(this.node);
|
||||
return this.replaceExpressionWithStatements(nodes);
|
||||
} else if (Array.isArray(this.container)) {
|
||||
return this._containerInsertBefore(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
const node = this.node;
|
||||
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
||||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
|
||||
return this.unshiftContainer("body", nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
}
|
||||
|
||||
function _containerInsert(from, nodes) {
|
||||
this.updateSiblingKeys(from, nodes.length);
|
||||
const paths = [];
|
||||
this.container.splice(from, 0, ...nodes);
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const to = from + i;
|
||||
const path = this.getSibling(to);
|
||||
paths.push(path);
|
||||
|
||||
if (this.context && this.context.queue) {
|
||||
path.pushContext(this.context);
|
||||
}
|
||||
}
|
||||
|
||||
const contexts = this._getQueueContexts();
|
||||
|
||||
for (const path of paths) {
|
||||
path.setScope();
|
||||
path.debug("Inserted.");
|
||||
|
||||
for (const context of contexts) {
|
||||
context.maybeQueue(path, true);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function _containerInsertBefore(nodes) {
|
||||
return this._containerInsert(this.key, nodes);
|
||||
}
|
||||
|
||||
function _containerInsertAfter(nodes) {
|
||||
return this._containerInsert(this.key + 1, nodes);
|
||||
}
|
||||
|
||||
function insertAfter(nodes_) {
|
||||
this._assertUnremoved();
|
||||
|
||||
const nodes = this._verifyNodeList(nodes_);
|
||||
|
||||
const {
|
||||
parentPath
|
||||
} = this;
|
||||
|
||||
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
||||
return parentPath.insertAfter(nodes.map(node => {
|
||||
return t.isExpression(node) ? t.expressionStatement(node) : node;
|
||||
}));
|
||||
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
||||
if (this.node) {
|
||||
const node = this.node;
|
||||
let {
|
||||
scope
|
||||
} = this;
|
||||
|
||||
if (scope.path.isPattern()) {
|
||||
t.assertExpression(node);
|
||||
this.replaceWith(t.callExpression(t.arrowFunctionExpression([], node), []));
|
||||
this.get("callee.body").insertAfter(nodes);
|
||||
return [this];
|
||||
}
|
||||
|
||||
if (parentPath.isMethod({
|
||||
computed: true,
|
||||
key: node
|
||||
})) {
|
||||
scope = scope.parent;
|
||||
}
|
||||
|
||||
const temp = scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), node)));
|
||||
nodes.push(t.expressionStatement(t.cloneNode(temp)));
|
||||
}
|
||||
|
||||
return this.replaceExpressionWithStatements(nodes);
|
||||
} else if (Array.isArray(this.container)) {
|
||||
return this._containerInsertAfter(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
const node = this.node;
|
||||
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
||||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
|
||||
return this.pushContainer("body", nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
}
|
||||
|
||||
function updateSiblingKeys(fromIndex, incrementBy) {
|
||||
if (!this.parent) return;
|
||||
|
||||
const paths = _cache.path.get(this.parent);
|
||||
|
||||
for (const [, path] of paths) {
|
||||
if (path.key >= fromIndex) {
|
||||
path.key += incrementBy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _verifyNodeList(nodes) {
|
||||
if (!nodes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!Array.isArray(nodes)) {
|
||||
nodes = [nodes];
|
||||
}
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const node = nodes[i];
|
||||
let msg;
|
||||
|
||||
if (!node) {
|
||||
msg = "has falsy node";
|
||||
} else if (typeof node !== "object") {
|
||||
msg = "contains a non-object node";
|
||||
} else if (!node.type) {
|
||||
msg = "without a type";
|
||||
} else if (node instanceof _index.default) {
|
||||
msg = "has a NodePath when it expected a raw object";
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
const type = Array.isArray(node) ? "array" : typeof node;
|
||||
throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function unshiftContainer(listKey, nodes) {
|
||||
this._assertUnremoved();
|
||||
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
|
||||
const path = _index.default.get({
|
||||
parentPath: this,
|
||||
parent: this.node,
|
||||
container: this.node[listKey],
|
||||
listKey,
|
||||
key: 0
|
||||
}).setContext(this.context);
|
||||
|
||||
return path._containerInsertBefore(nodes);
|
||||
}
|
||||
|
||||
function pushContainer(listKey, nodes) {
|
||||
this._assertUnremoved();
|
||||
|
||||
const verifiedNodes = this._verifyNodeList(nodes);
|
||||
|
||||
const container = this.node[listKey];
|
||||
|
||||
const path = _index.default.get({
|
||||
parentPath: this,
|
||||
parent: this.node,
|
||||
container: container,
|
||||
listKey,
|
||||
key: container.length
|
||||
}).setContext(this.context);
|
||||
|
||||
return path.replaceWithMultiple(verifiedNodes);
|
||||
}
|
||||
|
||||
function hoist(scope = this.scope) {
|
||||
const hoister = new _hoister.default(this, scope);
|
||||
return hoister.run();
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.remove = remove;
|
||||
exports._removeFromScope = _removeFromScope;
|
||||
exports._callRemovalHooks = _callRemovalHooks;
|
||||
exports._remove = _remove;
|
||||
exports._markRemoved = _markRemoved;
|
||||
exports._assertUnremoved = _assertUnremoved;
|
||||
|
||||
var _removalHooks = require("./lib/removal-hooks");
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
function remove() {
|
||||
var _this$opts;
|
||||
|
||||
this._assertUnremoved();
|
||||
|
||||
this.resync();
|
||||
|
||||
if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
|
||||
this._removeFromScope();
|
||||
}
|
||||
|
||||
if (this._callRemovalHooks()) {
|
||||
this._markRemoved();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.shareCommentsWithSiblings();
|
||||
|
||||
this._remove();
|
||||
|
||||
this._markRemoved();
|
||||
}
|
||||
|
||||
function _removeFromScope() {
|
||||
const bindings = this.getBindingIdentifiers();
|
||||
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
||||
}
|
||||
|
||||
function _callRemovalHooks() {
|
||||
for (const fn of _removalHooks.hooks) {
|
||||
if (fn(this, this.parentPath)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
function _remove() {
|
||||
if (Array.isArray(this.container)) {
|
||||
this.container.splice(this.key, 1);
|
||||
this.updateSiblingKeys(this.key, -1);
|
||||
} else {
|
||||
this._replaceWith(null);
|
||||
}
|
||||
}
|
||||
|
||||
function _markRemoved() {
|
||||
this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
|
||||
if (this.parent) _cache.path.get(this.parent).delete(this.node);
|
||||
this.node = null;
|
||||
}
|
||||
|
||||
function _assertUnremoved() {
|
||||
if (this.removed) {
|
||||
throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
||||
}
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.replaceWithMultiple = replaceWithMultiple;
|
||||
exports.replaceWithSourceString = replaceWithSourceString;
|
||||
exports.replaceWith = replaceWith;
|
||||
exports._replaceWith = _replaceWith;
|
||||
exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
|
||||
exports.replaceInline = replaceInline;
|
||||
|
||||
var _codeFrame = require("@babel/code-frame");
|
||||
|
||||
var _index = require("../index");
|
||||
|
||||
var _index2 = require("./index");
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
var _parser = require("@babel/parser");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const hoistVariablesVisitor = {
|
||||
Function(path) {
|
||||
path.skip();
|
||||
},
|
||||
|
||||
VariableDeclaration(path) {
|
||||
if (path.node.kind !== "var") return;
|
||||
const bindings = path.getBindingIdentifiers();
|
||||
|
||||
for (const key of Object.keys(bindings)) {
|
||||
path.scope.push({
|
||||
id: bindings[key]
|
||||
});
|
||||
}
|
||||
|
||||
const exprs = [];
|
||||
|
||||
for (const declar of path.node.declarations) {
|
||||
if (declar.init) {
|
||||
exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)));
|
||||
}
|
||||
}
|
||||
|
||||
path.replaceWithMultiple(exprs);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function replaceWithMultiple(nodes) {
|
||||
var _pathCache$get;
|
||||
|
||||
this.resync();
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
t.inheritLeadingComments(nodes[0], this.node);
|
||||
t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
||||
(_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
|
||||
this.node = this.container[this.key] = null;
|
||||
const paths = this.insertAfter(nodes);
|
||||
|
||||
if (this.node) {
|
||||
this.requeue();
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function replaceWithSourceString(replacement) {
|
||||
this.resync();
|
||||
|
||||
try {
|
||||
replacement = `(${replacement})`;
|
||||
replacement = (0, _parser.parse)(replacement);
|
||||
} catch (err) {
|
||||
const loc = err.loc;
|
||||
|
||||
if (loc) {
|
||||
err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, {
|
||||
start: {
|
||||
line: loc.line,
|
||||
column: loc.column + 1
|
||||
}
|
||||
});
|
||||
err.code = "BABEL_REPLACE_SOURCE_ERROR";
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
replacement = replacement.program.body[0].expression;
|
||||
|
||||
_index.default.removeProperties(replacement);
|
||||
|
||||
return this.replaceWith(replacement);
|
||||
}
|
||||
|
||||
function replaceWith(replacement) {
|
||||
this.resync();
|
||||
|
||||
if (this.removed) {
|
||||
throw new Error("You can't replace this node, we've already removed it");
|
||||
}
|
||||
|
||||
if (replacement instanceof _index2.default) {
|
||||
replacement = replacement.node;
|
||||
}
|
||||
|
||||
if (!replacement) {
|
||||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
||||
}
|
||||
|
||||
if (this.node === replacement) {
|
||||
return [this];
|
||||
}
|
||||
|
||||
if (this.isProgram() && !t.isProgram(replacement)) {
|
||||
throw new Error("You can only replace a Program root node with another Program node");
|
||||
}
|
||||
|
||||
if (Array.isArray(replacement)) {
|
||||
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
|
||||
}
|
||||
|
||||
if (typeof replacement === "string") {
|
||||
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
||||
}
|
||||
|
||||
let nodePath = "";
|
||||
|
||||
if (this.isNodeType("Statement") && t.isExpression(replacement)) {
|
||||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
||||
replacement = t.expressionStatement(replacement);
|
||||
nodePath = "expression";
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isNodeType("Expression") && t.isStatement(replacement)) {
|
||||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
||||
return this.replaceExpressionWithStatements([replacement]);
|
||||
}
|
||||
}
|
||||
|
||||
const oldNode = this.node;
|
||||
|
||||
if (oldNode) {
|
||||
t.inheritsComments(replacement, oldNode);
|
||||
t.removeComments(oldNode);
|
||||
}
|
||||
|
||||
this._replaceWith(replacement);
|
||||
|
||||
this.type = replacement.type;
|
||||
this.setScope();
|
||||
this.requeue();
|
||||
return [nodePath ? this.get(nodePath) : this];
|
||||
}
|
||||
|
||||
function _replaceWith(node) {
|
||||
var _pathCache$get2;
|
||||
|
||||
if (!this.container) {
|
||||
throw new ReferenceError("Container is falsy");
|
||||
}
|
||||
|
||||
if (this.inList) {
|
||||
t.validate(this.parent, this.key, [node]);
|
||||
} else {
|
||||
t.validate(this.parent, this.key, node);
|
||||
}
|
||||
|
||||
this.debug(`Replace with ${node == null ? void 0 : node.type}`);
|
||||
(_pathCache$get2 = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node);
|
||||
this.node = this.container[this.key] = node;
|
||||
}
|
||||
|
||||
function replaceExpressionWithStatements(nodes) {
|
||||
this.resync();
|
||||
const toSequenceExpression = t.toSequenceExpression(nodes, this.scope);
|
||||
|
||||
if (toSequenceExpression) {
|
||||
return this.replaceWith(toSequenceExpression)[0].get("expressions");
|
||||
}
|
||||
|
||||
const functionParent = this.getFunctionParent();
|
||||
const isParentAsync = functionParent == null ? void 0 : functionParent.is("async");
|
||||
const isParentGenerator = functionParent == null ? void 0 : functionParent.is("generator");
|
||||
const container = t.arrowFunctionExpression([], t.blockStatement(nodes));
|
||||
this.replaceWith(t.callExpression(container, []));
|
||||
this.traverse(hoistVariablesVisitor);
|
||||
const completionRecords = this.get("callee").getCompletionRecords();
|
||||
|
||||
for (const path of completionRecords) {
|
||||
if (!path.isExpressionStatement()) continue;
|
||||
const loop = path.findParent(path => path.isLoop());
|
||||
|
||||
if (loop) {
|
||||
let uid = loop.getData("expressionReplacementReturnUid");
|
||||
|
||||
if (!uid) {
|
||||
const callee = this.get("callee");
|
||||
uid = callee.scope.generateDeclaredUidIdentifier("ret");
|
||||
callee.get("body").pushContainer("body", t.returnStatement(t.cloneNode(uid)));
|
||||
loop.setData("expressionReplacementReturnUid", uid);
|
||||
} else {
|
||||
uid = t.identifier(uid.name);
|
||||
}
|
||||
|
||||
path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), path.node.expression));
|
||||
} else {
|
||||
path.replaceWith(t.returnStatement(path.node.expression));
|
||||
}
|
||||
}
|
||||
|
||||
const callee = this.get("callee");
|
||||
callee.arrowFunctionToExpression();
|
||||
|
||||
const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t.FUNCTION_TYPES);
|
||||
|
||||
const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", t.FUNCTION_TYPES);
|
||||
|
||||
if (needToAwaitFunction) {
|
||||
callee.set("async", true);
|
||||
|
||||
if (!needToYieldFunction) {
|
||||
this.replaceWith(t.awaitExpression(this.node));
|
||||
}
|
||||
}
|
||||
|
||||
if (needToYieldFunction) {
|
||||
callee.set("generator", true);
|
||||
this.replaceWith(t.yieldExpression(this.node, true));
|
||||
}
|
||||
|
||||
return callee.get("body.body");
|
||||
}
|
||||
|
||||
function replaceInline(nodes) {
|
||||
this.resync();
|
||||
|
||||
if (Array.isArray(nodes)) {
|
||||
if (Array.isArray(this.container)) {
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
|
||||
const paths = this._containerInsertAfter(nodes);
|
||||
|
||||
this.remove();
|
||||
return paths;
|
||||
} else {
|
||||
return this.replaceWithMultiple(nodes);
|
||||
}
|
||||
} else {
|
||||
return this.replaceWith(nodes);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
class Binding {
|
||||
constructor({
|
||||
identifier,
|
||||
scope,
|
||||
path,
|
||||
kind
|
||||
}) {
|
||||
this.identifier = void 0;
|
||||
this.scope = void 0;
|
||||
this.path = void 0;
|
||||
this.kind = void 0;
|
||||
this.constantViolations = [];
|
||||
this.constant = true;
|
||||
this.referencePaths = [];
|
||||
this.referenced = false;
|
||||
this.references = 0;
|
||||
this.identifier = identifier;
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
this.kind = kind;
|
||||
this.clearValue();
|
||||
}
|
||||
|
||||
deoptValue() {
|
||||
this.clearValue();
|
||||
this.hasDeoptedValue = true;
|
||||
}
|
||||
|
||||
setValue(value) {
|
||||
if (this.hasDeoptedValue) return;
|
||||
this.hasValue = true;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
clearValue() {
|
||||
this.hasDeoptedValue = false;
|
||||
this.hasValue = false;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
reassign(path) {
|
||||
this.constant = false;
|
||||
|
||||
if (this.constantViolations.indexOf(path) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.constantViolations.push(path);
|
||||
}
|
||||
|
||||
reference(path) {
|
||||
if (this.referencePaths.indexOf(path) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.referenced = true;
|
||||
this.references++;
|
||||
this.referencePaths.push(path);
|
||||
}
|
||||
|
||||
dereference() {
|
||||
this.references--;
|
||||
this.referenced = !!this.references;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Binding;
|
|
@ -1,963 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _renamer = require("./lib/renamer");
|
||||
|
||||
var _index = require("../index");
|
||||
|
||||
var _binding = require("./binding");
|
||||
|
||||
var _globals = require("globals");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
function gatherNodeParts(node, parts) {
|
||||
switch (node == null ? void 0 : node.type) {
|
||||
default:
|
||||
if (t.isModuleDeclaration(node)) {
|
||||
if ((t.isExportAllDeclaration(node) || t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.source) {
|
||||
gatherNodeParts(node.source, parts);
|
||||
} else if ((t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.specifiers && node.specifiers.length) {
|
||||
for (const e of node.specifiers) gatherNodeParts(e, parts);
|
||||
} else if ((t.isExportDefaultDeclaration(node) || t.isExportNamedDeclaration(node)) && node.declaration) {
|
||||
gatherNodeParts(node.declaration, parts);
|
||||
}
|
||||
} else if (t.isModuleSpecifier(node)) {
|
||||
gatherNodeParts(node.local, parts);
|
||||
} else if (t.isLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "MemberExpression":
|
||||
case "OptionalMemberExpression":
|
||||
case "JSXMemberExpression":
|
||||
gatherNodeParts(node.object, parts);
|
||||
gatherNodeParts(node.property, parts);
|
||||
break;
|
||||
|
||||
case "Identifier":
|
||||
case "JSXIdentifier":
|
||||
parts.push(node.name);
|
||||
break;
|
||||
|
||||
case "CallExpression":
|
||||
case "OptionalCallExpression":
|
||||
case "NewExpression":
|
||||
gatherNodeParts(node.callee, parts);
|
||||
break;
|
||||
|
||||
case "ObjectExpression":
|
||||
case "ObjectPattern":
|
||||
for (const e of node.properties) {
|
||||
gatherNodeParts(e, parts);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "SpreadElement":
|
||||
case "RestElement":
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "ObjectProperty":
|
||||
case "ObjectMethod":
|
||||
case "ClassProperty":
|
||||
case "ClassMethod":
|
||||
case "ClassPrivateProperty":
|
||||
case "ClassPrivateMethod":
|
||||
gatherNodeParts(node.key, parts);
|
||||
break;
|
||||
|
||||
case "ThisExpression":
|
||||
parts.push("this");
|
||||
break;
|
||||
|
||||
case "Super":
|
||||
parts.push("super");
|
||||
break;
|
||||
|
||||
case "Import":
|
||||
parts.push("import");
|
||||
break;
|
||||
|
||||
case "DoExpression":
|
||||
parts.push("do");
|
||||
break;
|
||||
|
||||
case "YieldExpression":
|
||||
parts.push("yield");
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "AwaitExpression":
|
||||
parts.push("await");
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "AssignmentExpression":
|
||||
gatherNodeParts(node.left, parts);
|
||||
break;
|
||||
|
||||
case "VariableDeclarator":
|
||||
gatherNodeParts(node.id, parts);
|
||||
break;
|
||||
|
||||
case "FunctionExpression":
|
||||
case "FunctionDeclaration":
|
||||
case "ClassExpression":
|
||||
case "ClassDeclaration":
|
||||
gatherNodeParts(node.id, parts);
|
||||
break;
|
||||
|
||||
case "PrivateName":
|
||||
gatherNodeParts(node.id, parts);
|
||||
break;
|
||||
|
||||
case "ParenthesizedExpression":
|
||||
gatherNodeParts(node.expression, parts);
|
||||
break;
|
||||
|
||||
case "UnaryExpression":
|
||||
case "UpdateExpression":
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "MetaProperty":
|
||||
gatherNodeParts(node.meta, parts);
|
||||
gatherNodeParts(node.property, parts);
|
||||
break;
|
||||
|
||||
case "JSXElement":
|
||||
gatherNodeParts(node.openingElement, parts);
|
||||
break;
|
||||
|
||||
case "JSXOpeningElement":
|
||||
parts.push(node.name);
|
||||
break;
|
||||
|
||||
case "JSXFragment":
|
||||
gatherNodeParts(node.openingFragment, parts);
|
||||
break;
|
||||
|
||||
case "JSXOpeningFragment":
|
||||
parts.push("Fragment");
|
||||
break;
|
||||
|
||||
case "JSXNamespacedName":
|
||||
gatherNodeParts(node.namespace, parts);
|
||||
gatherNodeParts(node.name, parts);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const collectorVisitor = {
|
||||
For(path) {
|
||||
for (const key of t.FOR_INIT_KEYS) {
|
||||
const declar = path.get(key);
|
||||
|
||||
if (declar.isVar()) {
|
||||
const parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
|
||||
parentScope.registerBinding("var", declar);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Declaration(path) {
|
||||
if (path.isBlockScoped()) return;
|
||||
if (path.isExportDeclaration()) return;
|
||||
const parent = path.scope.getFunctionParent() || path.scope.getProgramParent();
|
||||
parent.registerDeclaration(path);
|
||||
},
|
||||
|
||||
ReferencedIdentifier(path, state) {
|
||||
state.references.push(path);
|
||||
},
|
||||
|
||||
ForXStatement(path, state) {
|
||||
const left = path.get("left");
|
||||
|
||||
if (left.isPattern() || left.isIdentifier()) {
|
||||
state.constantViolations.push(path);
|
||||
}
|
||||
},
|
||||
|
||||
ExportDeclaration: {
|
||||
exit(path) {
|
||||
const {
|
||||
node,
|
||||
scope
|
||||
} = path;
|
||||
if (t.isExportAllDeclaration(node)) return;
|
||||
const declar = node.declaration;
|
||||
|
||||
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
|
||||
const id = declar.id;
|
||||
if (!id) return;
|
||||
const binding = scope.getBinding(id.name);
|
||||
if (binding) binding.reference(path);
|
||||
} else if (t.isVariableDeclaration(declar)) {
|
||||
for (const decl of declar.declarations) {
|
||||
for (const name of Object.keys(t.getBindingIdentifiers(decl))) {
|
||||
const binding = scope.getBinding(name);
|
||||
if (binding) binding.reference(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
LabeledStatement(path) {
|
||||
path.scope.getBlockParent().registerDeclaration(path);
|
||||
},
|
||||
|
||||
AssignmentExpression(path, state) {
|
||||
state.assignments.push(path);
|
||||
},
|
||||
|
||||
UpdateExpression(path, state) {
|
||||
state.constantViolations.push(path);
|
||||
},
|
||||
|
||||
UnaryExpression(path, state) {
|
||||
if (path.node.operator === "delete") {
|
||||
state.constantViolations.push(path);
|
||||
}
|
||||
},
|
||||
|
||||
BlockScoped(path) {
|
||||
let scope = path.scope;
|
||||
if (scope.path === path) scope = scope.parent;
|
||||
const parent = scope.getBlockParent();
|
||||
parent.registerDeclaration(path);
|
||||
|
||||
if (path.isClassDeclaration() && path.node.id) {
|
||||
const id = path.node.id;
|
||||
const name = id.name;
|
||||
path.scope.bindings[name] = path.scope.parent.getBinding(name);
|
||||
}
|
||||
},
|
||||
|
||||
CatchClause(path) {
|
||||
path.scope.registerBinding("let", path);
|
||||
},
|
||||
|
||||
Function(path) {
|
||||
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
||||
path.scope.registerBinding("local", path.get("id"), path);
|
||||
}
|
||||
|
||||
const params = path.get("params");
|
||||
|
||||
for (const param of params) {
|
||||
path.scope.registerBinding("param", param);
|
||||
}
|
||||
},
|
||||
|
||||
ClassExpression(path) {
|
||||
if (path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
||||
path.scope.registerBinding("local", path);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
let uid = 0;
|
||||
|
||||
class Scope {
|
||||
constructor(path) {
|
||||
this.uid = void 0;
|
||||
this.path = void 0;
|
||||
this.block = void 0;
|
||||
this.labels = void 0;
|
||||
this.inited = void 0;
|
||||
this.bindings = void 0;
|
||||
this.references = void 0;
|
||||
this.globals = void 0;
|
||||
this.uids = void 0;
|
||||
this.data = void 0;
|
||||
this.crawling = void 0;
|
||||
const {
|
||||
node
|
||||
} = path;
|
||||
|
||||
const cached = _cache.scope.get(node);
|
||||
|
||||
if ((cached == null ? void 0 : cached.path) === path) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
_cache.scope.set(node, this);
|
||||
|
||||
this.uid = uid++;
|
||||
this.block = node;
|
||||
this.path = path;
|
||||
this.labels = new Map();
|
||||
this.inited = false;
|
||||
}
|
||||
|
||||
get parent() {
|
||||
var _parent;
|
||||
|
||||
let parent,
|
||||
path = this.path;
|
||||
|
||||
do {
|
||||
const isKey = path.key === "key";
|
||||
path = path.parentPath;
|
||||
if (isKey && path.isMethod()) path = path.parentPath;
|
||||
if (path && path.isScope()) parent = path;
|
||||
} while (path && !parent);
|
||||
|
||||
return (_parent = parent) == null ? void 0 : _parent.scope;
|
||||
}
|
||||
|
||||
get parentBlock() {
|
||||
return this.path.parent;
|
||||
}
|
||||
|
||||
get hub() {
|
||||
return this.path.hub;
|
||||
}
|
||||
|
||||
traverse(node, opts, state) {
|
||||
(0, _index.default)(node, opts, this, state, this.path);
|
||||
}
|
||||
|
||||
generateDeclaredUidIdentifier(name) {
|
||||
const id = this.generateUidIdentifier(name);
|
||||
this.push({
|
||||
id
|
||||
});
|
||||
return t.cloneNode(id);
|
||||
}
|
||||
|
||||
generateUidIdentifier(name) {
|
||||
return t.identifier(this.generateUid(name));
|
||||
}
|
||||
|
||||
generateUid(name = "temp") {
|
||||
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
||||
let uid;
|
||||
let i = 1;
|
||||
|
||||
do {
|
||||
uid = this._generateUid(name, i);
|
||||
i++;
|
||||
} while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
|
||||
|
||||
const program = this.getProgramParent();
|
||||
program.references[uid] = true;
|
||||
program.uids[uid] = true;
|
||||
return uid;
|
||||
}
|
||||
|
||||
_generateUid(name, i) {
|
||||
let id = name;
|
||||
if (i > 1) id += i;
|
||||
return `_${id}`;
|
||||
}
|
||||
|
||||
generateUidBasedOnNode(node, defaultName) {
|
||||
const parts = [];
|
||||
gatherNodeParts(node, parts);
|
||||
let id = parts.join("$");
|
||||
id = id.replace(/^_/, "") || defaultName || "ref";
|
||||
return this.generateUid(id.slice(0, 20));
|
||||
}
|
||||
|
||||
generateUidIdentifierBasedOnNode(node, defaultName) {
|
||||
return t.identifier(this.generateUidBasedOnNode(node, defaultName));
|
||||
}
|
||||
|
||||
isStatic(node) {
|
||||
if (t.isThisExpression(node) || t.isSuper(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
|
||||
if (binding) {
|
||||
return binding.constant;
|
||||
} else {
|
||||
return this.hasBinding(node.name);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
maybeGenerateMemoised(node, dontPush) {
|
||||
if (this.isStatic(node)) {
|
||||
return null;
|
||||
} else {
|
||||
const id = this.generateUidIdentifierBasedOnNode(node);
|
||||
|
||||
if (!dontPush) {
|
||||
this.push({
|
||||
id
|
||||
});
|
||||
return t.cloneNode(id);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
checkBlockScopedCollisions(local, kind, name, id) {
|
||||
if (kind === "param") return;
|
||||
if (local.kind === "local") return;
|
||||
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");
|
||||
|
||||
if (duplicate) {
|
||||
throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
|
||||
}
|
||||
}
|
||||
|
||||
rename(oldName, newName, block) {
|
||||
const binding = this.getBinding(oldName);
|
||||
|
||||
if (binding) {
|
||||
newName = newName || this.generateUidIdentifier(oldName).name;
|
||||
return new _renamer.default(binding, oldName, newName).rename(block);
|
||||
}
|
||||
}
|
||||
|
||||
_renameFromMap(map, oldName, newName, value) {
|
||||
if (map[oldName]) {
|
||||
map[newName] = value;
|
||||
map[oldName] = null;
|
||||
}
|
||||
}
|
||||
|
||||
dump() {
|
||||
const sep = "-".repeat(60);
|
||||
console.log(sep);
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
console.log("#", scope.block.type);
|
||||
|
||||
for (const name of Object.keys(scope.bindings)) {
|
||||
const binding = scope.bindings[name];
|
||||
console.log(" -", name, {
|
||||
constant: binding.constant,
|
||||
references: binding.references,
|
||||
violations: binding.constantViolations.length,
|
||||
kind: binding.kind
|
||||
});
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
console.log(sep);
|
||||
}
|
||||
|
||||
toArray(node, i, arrayLikeIsIterable) {
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
|
||||
if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node, {
|
||||
name: "arguments"
|
||||
})) {
|
||||
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
|
||||
}
|
||||
|
||||
let helperName;
|
||||
const args = [node];
|
||||
|
||||
if (i === true) {
|
||||
helperName = "toConsumableArray";
|
||||
} else if (i) {
|
||||
args.push(t.numericLiteral(i));
|
||||
helperName = "slicedToArray";
|
||||
} else {
|
||||
helperName = "toArray";
|
||||
}
|
||||
|
||||
if (arrayLikeIsIterable) {
|
||||
args.unshift(this.hub.addHelper(helperName));
|
||||
helperName = "maybeArrayLike";
|
||||
}
|
||||
|
||||
return t.callExpression(this.hub.addHelper(helperName), args);
|
||||
}
|
||||
|
||||
hasLabel(name) {
|
||||
return !!this.getLabel(name);
|
||||
}
|
||||
|
||||
getLabel(name) {
|
||||
return this.labels.get(name);
|
||||
}
|
||||
|
||||
registerLabel(path) {
|
||||
this.labels.set(path.node.label.name, path);
|
||||
}
|
||||
|
||||
registerDeclaration(path) {
|
||||
if (path.isLabeledStatement()) {
|
||||
this.registerLabel(path);
|
||||
} else if (path.isFunctionDeclaration()) {
|
||||
this.registerBinding("hoisted", path.get("id"), path);
|
||||
} else if (path.isVariableDeclaration()) {
|
||||
const declarations = path.get("declarations");
|
||||
|
||||
for (const declar of declarations) {
|
||||
this.registerBinding(path.node.kind, declar);
|
||||
}
|
||||
} else if (path.isClassDeclaration()) {
|
||||
this.registerBinding("let", path);
|
||||
} else if (path.isImportDeclaration()) {
|
||||
const specifiers = path.get("specifiers");
|
||||
|
||||
for (const specifier of specifiers) {
|
||||
this.registerBinding("module", specifier);
|
||||
}
|
||||
} else if (path.isExportDeclaration()) {
|
||||
const declar = path.get("declaration");
|
||||
|
||||
if (declar.isClassDeclaration() || declar.isFunctionDeclaration() || declar.isVariableDeclaration()) {
|
||||
this.registerDeclaration(declar);
|
||||
}
|
||||
} else {
|
||||
this.registerBinding("unknown", path);
|
||||
}
|
||||
}
|
||||
|
||||
buildUndefinedNode() {
|
||||
return t.unaryExpression("void", t.numericLiteral(0), true);
|
||||
}
|
||||
|
||||
registerConstantViolation(path) {
|
||||
const ids = path.getBindingIdentifiers();
|
||||
|
||||
for (const name of Object.keys(ids)) {
|
||||
const binding = this.getBinding(name);
|
||||
if (binding) binding.reassign(path);
|
||||
}
|
||||
}
|
||||
|
||||
registerBinding(kind, path, bindingPath = path) {
|
||||
if (!kind) throw new ReferenceError("no `kind`");
|
||||
|
||||
if (path.isVariableDeclaration()) {
|
||||
const declarators = path.get("declarations");
|
||||
|
||||
for (const declar of declarators) {
|
||||
this.registerBinding(kind, declar);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const parent = this.getProgramParent();
|
||||
const ids = path.getOuterBindingIdentifiers(true);
|
||||
|
||||
for (const name of Object.keys(ids)) {
|
||||
parent.references[name] = true;
|
||||
|
||||
for (const id of ids[name]) {
|
||||
const local = this.getOwnBinding(name);
|
||||
|
||||
if (local) {
|
||||
if (local.identifier === id) continue;
|
||||
this.checkBlockScopedCollisions(local, kind, name, id);
|
||||
}
|
||||
|
||||
if (local) {
|
||||
this.registerConstantViolation(bindingPath);
|
||||
} else {
|
||||
this.bindings[name] = new _binding.default({
|
||||
identifier: id,
|
||||
scope: this,
|
||||
path: bindingPath,
|
||||
kind: kind
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addGlobal(node) {
|
||||
this.globals[node.name] = node;
|
||||
}
|
||||
|
||||
hasUid(name) {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.uids[name]) return true;
|
||||
} while (scope = scope.parent);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hasGlobal(name) {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.globals[name]) return true;
|
||||
} while (scope = scope.parent);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hasReference(name) {
|
||||
return !!this.getProgramParent().references[name];
|
||||
}
|
||||
|
||||
isPure(node, constantsOnly) {
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
if (!binding) return false;
|
||||
if (constantsOnly) return binding.constant;
|
||||
return true;
|
||||
} else if (t.isClass(node)) {
|
||||
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.isPure(node.body, constantsOnly);
|
||||
} else if (t.isClassBody(node)) {
|
||||
for (const method of node.body) {
|
||||
if (!this.isPure(method, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (t.isBinary(node)) {
|
||||
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
||||
} else if (t.isArrayExpression(node)) {
|
||||
for (const elem of node.elements) {
|
||||
if (!this.isPure(elem, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (t.isObjectExpression(node)) {
|
||||
for (const prop of node.properties) {
|
||||
if (!this.isPure(prop, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (t.isMethod(node)) {
|
||||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
||||
if (node.kind === "get" || node.kind === "set") return false;
|
||||
return true;
|
||||
} else if (t.isProperty(node)) {
|
||||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
||||
return this.isPure(node.value, constantsOnly);
|
||||
} else if (t.isUnaryExpression(node)) {
|
||||
return this.isPure(node.argument, constantsOnly);
|
||||
} else if (t.isTaggedTemplateExpression(node)) {
|
||||
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
||||
} else if (t.isTemplateLiteral(node)) {
|
||||
for (const expression of node.expressions) {
|
||||
if (!this.isPure(expression, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return t.isPureish(node);
|
||||
}
|
||||
}
|
||||
|
||||
setData(key, val) {
|
||||
return this.data[key] = val;
|
||||
}
|
||||
|
||||
getData(key) {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
const data = scope.data[key];
|
||||
if (data != null) return data;
|
||||
} while (scope = scope.parent);
|
||||
}
|
||||
|
||||
removeData(key) {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
const data = scope.data[key];
|
||||
if (data != null) scope.data[key] = null;
|
||||
} while (scope = scope.parent);
|
||||
}
|
||||
|
||||
init() {
|
||||
if (!this.inited) {
|
||||
this.inited = true;
|
||||
this.crawl();
|
||||
}
|
||||
}
|
||||
|
||||
crawl() {
|
||||
const path = this.path;
|
||||
this.references = Object.create(null);
|
||||
this.bindings = Object.create(null);
|
||||
this.globals = Object.create(null);
|
||||
this.uids = Object.create(null);
|
||||
this.data = Object.create(null);
|
||||
const programParent = this.getProgramParent();
|
||||
if (programParent.crawling) return;
|
||||
const state = {
|
||||
references: [],
|
||||
constantViolations: [],
|
||||
assignments: []
|
||||
};
|
||||
this.crawling = true;
|
||||
|
||||
if (path.type !== "Program" && collectorVisitor._exploded) {
|
||||
for (const visit of collectorVisitor.enter) {
|
||||
visit(path, state);
|
||||
}
|
||||
|
||||
const typeVisitors = collectorVisitor[path.type];
|
||||
|
||||
if (typeVisitors) {
|
||||
for (const visit of typeVisitors.enter) {
|
||||
visit(path, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path.traverse(collectorVisitor, state);
|
||||
this.crawling = false;
|
||||
|
||||
for (const path of state.assignments) {
|
||||
const ids = path.getBindingIdentifiers();
|
||||
|
||||
for (const name of Object.keys(ids)) {
|
||||
if (path.scope.getBinding(name)) continue;
|
||||
programParent.addGlobal(ids[name]);
|
||||
}
|
||||
|
||||
path.scope.registerConstantViolation(path);
|
||||
}
|
||||
|
||||
for (const ref of state.references) {
|
||||
const binding = ref.scope.getBinding(ref.node.name);
|
||||
|
||||
if (binding) {
|
||||
binding.reference(ref);
|
||||
} else {
|
||||
programParent.addGlobal(ref.node);
|
||||
}
|
||||
}
|
||||
|
||||
for (const path of state.constantViolations) {
|
||||
path.scope.registerConstantViolation(path);
|
||||
}
|
||||
}
|
||||
|
||||
push(opts) {
|
||||
let path = this.path;
|
||||
|
||||
if (!path.isBlockStatement() && !path.isProgram()) {
|
||||
path = this.getBlockParent().path;
|
||||
}
|
||||
|
||||
if (path.isSwitchStatement()) {
|
||||
path = (this.getFunctionParent() || this.getProgramParent()).path;
|
||||
}
|
||||
|
||||
if (path.isLoop() || path.isCatchClause() || path.isFunction()) {
|
||||
path.ensureBlock();
|
||||
path = path.get("body");
|
||||
}
|
||||
|
||||
const unique = opts.unique;
|
||||
const kind = opts.kind || "var";
|
||||
const blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;
|
||||
const dataKey = `declaration:${kind}:${blockHoist}`;
|
||||
let declarPath = !unique && path.getData(dataKey);
|
||||
|
||||
if (!declarPath) {
|
||||
const declar = t.variableDeclaration(kind, []);
|
||||
declar._blockHoist = blockHoist;
|
||||
[declarPath] = path.unshiftContainer("body", [declar]);
|
||||
if (!unique) path.setData(dataKey, declarPath);
|
||||
}
|
||||
|
||||
const declarator = t.variableDeclarator(opts.id, opts.init);
|
||||
declarPath.node.declarations.push(declarator);
|
||||
this.registerBinding(kind, declarPath.get("declarations").pop());
|
||||
}
|
||||
|
||||
getProgramParent() {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.path.isProgram()) {
|
||||
return scope;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
throw new Error("Couldn't find a Program");
|
||||
}
|
||||
|
||||
getFunctionParent() {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.path.isFunctionParent()) {
|
||||
return scope;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getBlockParent() {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.path.isBlockParent()) {
|
||||
return scope;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
||||
}
|
||||
|
||||
getAllBindings() {
|
||||
const ids = Object.create(null);
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
for (const key of Object.keys(scope.bindings)) {
|
||||
if (key in ids === false) {
|
||||
ids[key] = scope.bindings[key];
|
||||
}
|
||||
}
|
||||
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
getAllBindingsOfKind(...kinds) {
|
||||
const ids = Object.create(null);
|
||||
|
||||
for (const kind of kinds) {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
for (const name of Object.keys(scope.bindings)) {
|
||||
const binding = scope.bindings[name];
|
||||
if (binding.kind === kind) ids[name] = binding;
|
||||
}
|
||||
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
bindingIdentifierEquals(name, node) {
|
||||
return this.getBindingIdentifier(name) === node;
|
||||
}
|
||||
|
||||
getBinding(name) {
|
||||
let scope = this;
|
||||
let previousPath;
|
||||
|
||||
do {
|
||||
const binding = scope.getOwnBinding(name);
|
||||
|
||||
if (binding) {
|
||||
var _previousPath;
|
||||
|
||||
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param") {} else {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
||||
previousPath = scope.path;
|
||||
} while (scope = scope.parent);
|
||||
}
|
||||
|
||||
getOwnBinding(name) {
|
||||
return this.bindings[name];
|
||||
}
|
||||
|
||||
getBindingIdentifier(name) {
|
||||
var _this$getBinding;
|
||||
|
||||
return (_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.identifier;
|
||||
}
|
||||
|
||||
getOwnBindingIdentifier(name) {
|
||||
const binding = this.bindings[name];
|
||||
return binding == null ? void 0 : binding.identifier;
|
||||
}
|
||||
|
||||
hasOwnBinding(name) {
|
||||
return !!this.getOwnBinding(name);
|
||||
}
|
||||
|
||||
hasBinding(name, noGlobals) {
|
||||
if (!name) return false;
|
||||
if (this.hasOwnBinding(name)) return true;
|
||||
if (this.parentHasBinding(name, noGlobals)) return true;
|
||||
if (this.hasUid(name)) return true;
|
||||
if (!noGlobals && Scope.globals.includes(name)) return true;
|
||||
if (!noGlobals && Scope.contextVariables.includes(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
parentHasBinding(name, noGlobals) {
|
||||
var _this$parent;
|
||||
|
||||
return (_this$parent = this.parent) == null ? void 0 : _this$parent.hasBinding(name, noGlobals);
|
||||
}
|
||||
|
||||
moveBindingTo(name, scope) {
|
||||
const info = this.getBinding(name);
|
||||
|
||||
if (info) {
|
||||
info.scope.removeOwnBinding(name);
|
||||
info.scope = scope;
|
||||
scope.bindings[name] = info;
|
||||
}
|
||||
}
|
||||
|
||||
removeOwnBinding(name) {
|
||||
delete this.bindings[name];
|
||||
}
|
||||
|
||||
removeBinding(name) {
|
||||
var _this$getBinding2;
|
||||
|
||||
(_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.scope.removeOwnBinding(name);
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.uids[name]) {
|
||||
scope.uids[name] = false;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Scope;
|
||||
Scope.globals = Object.keys(_globals.builtin);
|
||||
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|
|
@ -1,138 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _binding = require("../binding");
|
||||
|
||||
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
const renameVisitor = {
|
||||
ReferencedIdentifier({
|
||||
node
|
||||
}, state) {
|
||||
if (node.name === state.oldName) {
|
||||
node.name = state.newName;
|
||||
}
|
||||
},
|
||||
|
||||
Scope(path, state) {
|
||||
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
|
||||
skipAllButComputedMethodKey(path);
|
||||
}
|
||||
},
|
||||
|
||||
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
|
||||
if (path.isVariableDeclaration()) return;
|
||||
const ids = path.getOuterBindingIdentifiers();
|
||||
|
||||
for (const name in ids) {
|
||||
if (name === state.oldName) ids[name].name = state.newName;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Renamer {
|
||||
constructor(binding, oldName, newName) {
|
||||
this.newName = newName;
|
||||
this.oldName = oldName;
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
maybeConvertFromExportDeclaration(parentDeclar) {
|
||||
const maybeExportDeclar = parentDeclar.parentPath;
|
||||
|
||||
if (!maybeExportDeclar.isExportDeclaration()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (maybeExportDeclar.isExportDefaultDeclaration() && !maybeExportDeclar.get("declaration").node.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar);
|
||||
}
|
||||
|
||||
maybeConvertFromClassFunctionDeclaration(path) {
|
||||
return;
|
||||
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
||||
if (this.binding.kind !== "hoisted") return;
|
||||
path.node.id = t.identifier(this.oldName);
|
||||
path.node._blockHoist = 3;
|
||||
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))]));
|
||||
}
|
||||
|
||||
maybeConvertFromClassFunctionExpression(path) {
|
||||
return;
|
||||
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
||||
if (this.binding.kind !== "local") return;
|
||||
path.node.id = t.identifier(this.oldName);
|
||||
this.binding.scope.parent.push({
|
||||
id: t.identifier(this.newName)
|
||||
});
|
||||
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node));
|
||||
}
|
||||
|
||||
rename(block) {
|
||||
const {
|
||||
binding,
|
||||
oldName,
|
||||
newName
|
||||
} = this;
|
||||
const {
|
||||
scope,
|
||||
path
|
||||
} = binding;
|
||||
const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression());
|
||||
|
||||
if (parentDeclar) {
|
||||
const bindingIds = parentDeclar.getOuterBindingIdentifiers();
|
||||
|
||||
if (bindingIds[oldName] === binding.identifier) {
|
||||
this.maybeConvertFromExportDeclaration(parentDeclar);
|
||||
}
|
||||
}
|
||||
|
||||
const blockToTraverse = block || scope.block;
|
||||
|
||||
if ((blockToTraverse == null ? void 0 : blockToTraverse.type) === "SwitchStatement") {
|
||||
blockToTraverse.cases.forEach(c => {
|
||||
scope.traverse(c, renameVisitor, this);
|
||||
});
|
||||
} else {
|
||||
scope.traverse(blockToTraverse, renameVisitor, this);
|
||||
}
|
||||
|
||||
if (!block) {
|
||||
scope.removeOwnBinding(oldName);
|
||||
scope.bindings[newName] = binding;
|
||||
this.binding.identifier.name = newName;
|
||||
}
|
||||
|
||||
if (parentDeclar) {
|
||||
this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
|
||||
this.maybeConvertFromClassFunctionExpression(parentDeclar);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Renamer;
|
||||
|
||||
function skipAllButComputedMethodKey(path) {
|
||||
if (!path.isMethod() || !path.node.computed) {
|
||||
path.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
const keys = t.VISITOR_KEYS[path.type];
|
||||
|
||||
for (const key of keys) {
|
||||
if (key !== "key") path.skipKey(key);
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
var _virtualTypes = require("./path/generated/virtual-types");
|
|
@ -1,236 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.explode = explode;
|
||||
exports.verify = verify;
|
||||
exports.merge = merge;
|
||||
|
||||
var virtualTypes = require("./path/lib/virtual-types");
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
function explode(visitor) {
|
||||
if (visitor._exploded) return visitor;
|
||||
visitor._exploded = true;
|
||||
|
||||
for (const nodeType of Object.keys(visitor)) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
const parts = nodeType.split("|");
|
||||
if (parts.length === 1) continue;
|
||||
const fns = visitor[nodeType];
|
||||
delete visitor[nodeType];
|
||||
|
||||
for (const part of parts) {
|
||||
visitor[part] = fns;
|
||||
}
|
||||
}
|
||||
|
||||
verify(visitor);
|
||||
delete visitor.__esModule;
|
||||
ensureEntranceObjects(visitor);
|
||||
ensureCallbackArrays(visitor);
|
||||
|
||||
for (const nodeType of Object.keys(visitor)) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
const wrapper = virtualTypes[nodeType];
|
||||
if (!wrapper) continue;
|
||||
const fns = visitor[nodeType];
|
||||
|
||||
for (const type of Object.keys(fns)) {
|
||||
fns[type] = wrapCheck(wrapper, fns[type]);
|
||||
}
|
||||
|
||||
delete visitor[nodeType];
|
||||
|
||||
if (wrapper.types) {
|
||||
for (const type of wrapper.types) {
|
||||
if (visitor[type]) {
|
||||
mergePair(visitor[type], fns);
|
||||
} else {
|
||||
visitor[type] = fns;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mergePair(visitor, fns);
|
||||
}
|
||||
}
|
||||
|
||||
for (const nodeType of Object.keys(visitor)) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
const fns = visitor[nodeType];
|
||||
let aliases = t.FLIPPED_ALIAS_KEYS[nodeType];
|
||||
const deprecatedKey = t.DEPRECATED_KEYS[nodeType];
|
||||
|
||||
if (deprecatedKey) {
|
||||
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecatedKey}`);
|
||||
aliases = [deprecatedKey];
|
||||
}
|
||||
|
||||
if (!aliases) continue;
|
||||
delete visitor[nodeType];
|
||||
|
||||
for (const alias of aliases) {
|
||||
const existing = visitor[alias];
|
||||
|
||||
if (existing) {
|
||||
mergePair(existing, fns);
|
||||
} else {
|
||||
visitor[alias] = Object.assign({}, fns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const nodeType of Object.keys(visitor)) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
ensureCallbackArrays(visitor[nodeType]);
|
||||
}
|
||||
|
||||
return visitor;
|
||||
}
|
||||
|
||||
function verify(visitor) {
|
||||
if (visitor._verified) return;
|
||||
|
||||
if (typeof visitor === "function") {
|
||||
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
|
||||
}
|
||||
|
||||
for (const nodeType of Object.keys(visitor)) {
|
||||
if (nodeType === "enter" || nodeType === "exit") {
|
||||
validateVisitorMethods(nodeType, visitor[nodeType]);
|
||||
}
|
||||
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
|
||||
if (t.TYPES.indexOf(nodeType) < 0) {
|
||||
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
|
||||
}
|
||||
|
||||
const visitors = visitor[nodeType];
|
||||
|
||||
if (typeof visitors === "object") {
|
||||
for (const visitorKey of Object.keys(visitors)) {
|
||||
if (visitorKey === "enter" || visitorKey === "exit") {
|
||||
validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
|
||||
} else {
|
||||
throw new Error("You passed `traverse()` a visitor object with the property " + `${nodeType} that has the invalid property ${visitorKey}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitor._verified = true;
|
||||
}
|
||||
|
||||
function validateVisitorMethods(path, val) {
|
||||
const fns = [].concat(val);
|
||||
|
||||
for (const fn of fns) {
|
||||
if (typeof fn !== "function") {
|
||||
throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function merge(visitors, states = [], wrapper) {
|
||||
const rootVisitor = {};
|
||||
|
||||
for (let i = 0; i < visitors.length; i++) {
|
||||
const visitor = visitors[i];
|
||||
const state = states[i];
|
||||
explode(visitor);
|
||||
|
||||
for (const type of Object.keys(visitor)) {
|
||||
let visitorType = visitor[type];
|
||||
|
||||
if (state || wrapper) {
|
||||
visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
|
||||
}
|
||||
|
||||
const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
|
||||
mergePair(nodeVisitor, visitorType);
|
||||
}
|
||||
}
|
||||
|
||||
return rootVisitor;
|
||||
}
|
||||
|
||||
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
|
||||
const newVisitor = {};
|
||||
|
||||
for (const key of Object.keys(oldVisitor)) {
|
||||
let fns = oldVisitor[key];
|
||||
if (!Array.isArray(fns)) continue;
|
||||
fns = fns.map(function (fn) {
|
||||
let newFn = fn;
|
||||
|
||||
if (state) {
|
||||
newFn = function (path) {
|
||||
return fn.call(state, path, state);
|
||||
};
|
||||
}
|
||||
|
||||
if (wrapper) {
|
||||
newFn = wrapper(state.key, key, newFn);
|
||||
}
|
||||
|
||||
if (newFn !== fn) {
|
||||
newFn.toString = () => fn.toString();
|
||||
}
|
||||
|
||||
return newFn;
|
||||
});
|
||||
newVisitor[key] = fns;
|
||||
}
|
||||
|
||||
return newVisitor;
|
||||
}
|
||||
|
||||
function ensureEntranceObjects(obj) {
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (shouldIgnoreKey(key)) continue;
|
||||
const fns = obj[key];
|
||||
|
||||
if (typeof fns === "function") {
|
||||
obj[key] = {
|
||||
enter: fns
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ensureCallbackArrays(obj) {
|
||||
if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter];
|
||||
if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
|
||||
}
|
||||
|
||||
function wrapCheck(wrapper, fn) {
|
||||
const newFn = function (path) {
|
||||
if (wrapper.checkPath(path)) {
|
||||
return fn.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
newFn.toString = () => fn.toString();
|
||||
|
||||
return newFn;
|
||||
}
|
||||
|
||||
function shouldIgnoreKey(key) {
|
||||
if (key[0] === "_") return true;
|
||||
if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
|
||||
|
||||
if (key === "denylist" || key === "noScope" || key === "skipKeys" || key === "blacklist") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function mergePair(dest, src) {
|
||||
for (const key of Object.keys(src)) {
|
||||
dest[key] = [].concat(dest[key] || [], src[key]);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue