Commit 99033d7d authored by Patrick's avatar Patrick
Browse files

first commit

parents
Showing with 1663 additions and 0 deletions
+1663 -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.TSAsExpression = TSAsExpression;
exports.TSTypeAssertion = TSTypeAssertion;
exports.TSIntersectionType = exports.TSUnionType = TSUnionType;
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.OptionalMemberExpression = OptionalMemberExpression;
exports.AssignmentExpression = AssignmentExpression;
exports.NewExpression = NewExpression;
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 PRECEDENCE = {
"||": 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;
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 t.isMemberExpression(parent, {
object: node
}) || t.isCallExpression(parent, {
callee: node
}) || t.isNewExpression(parent, {
callee: node
}) || isClassExtendsClause(node, parent);
}
function ObjectExpression(node, parent, printStack) {
return isFirstInStatement(printStack, {
considerArrow: true
});
}
function DoExpression(node, parent, printStack) {
return isFirstInStatement(printStack);
}
function Binary(node, parent) {
if (node.operator === "**" && t.isBinaryExpression(parent, {
operator: "**"
})) {
return parent.left === node;
}
if (isClassExtendsClause(node, parent)) {
return true;
}
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node || t.isUnaryLike(parent) || t.isMemberExpression(parent) && parent.object === node || 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;
}
}
return false;
}
function UnionTypeAnnotation(node, parent) {
return t.isArrayTypeAnnotation(parent) || t.isNullableTypeAnnotation(parent) || t.isIntersectionTypeAnnotation(parent) || t.isUnionTypeAnnotation(parent);
}
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 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) || t.isCallExpression(parent) || t.isMemberExpression(parent) || t.isNewExpression(parent) || t.isAwaitExpression(parent) && t.isYieldExpression(node) || t.isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent);
}
function ClassExpression(node, parent, printStack) {
return isFirstInStatement(printStack, {
considerDefaultExports: true
});
}
function UnaryLike(node, parent) {
return t.isMemberExpression(parent, {
object: node
}) || t.isCallExpression(parent, {
callee: node
}) || t.isNewExpression(parent, {
callee: node
}) || t.isBinaryExpression(parent, {
operator: "**",
left: node
}) || isClassExtendsClause(node, parent);
}
function FunctionExpression(node, parent, printStack) {
return isFirstInStatement(printStack, {
considerDefaultExports: 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.isOptionalMemberExpression(parent) || t.isTaggedTemplateExpression(parent) || t.isTSTypeAssertion(parent) || t.isTSAsExpression(parent)) {
return true;
}
return UnaryLike(node, parent);
}
function OptionalMemberExpression(node, parent) {
return t.isCallExpression(parent) || t.isMemberExpression(parent);
}
function AssignmentExpression(node) {
if (t.isObjectPattern(node.left)) {
return true;
} else {
return ConditionalExpression(...arguments);
}
}
function NewExpression(node, parent) {
return isClassExtendsClause(node, parent);
}
function isFirstInStatement(printStack, {
considerArrow = false,
considerDefaultExports = false
} = {}) {
let i = printStack.length - 1;
let node = printStack[i];
i--;
let parent = printStack[i];
while (i > 0) {
if (t.isExpressionStatement(parent, {
expression: node
}) || t.isTaggedTemplateExpression(parent) || considerDefaultExports && t.isExportDefaultDeclaration(parent, {
declaration: node
}) || considerArrow && t.isArrowFunctionExpression(parent, {
body: node
})) {
return true;
}
if (t.isCallExpression(parent, {
callee: node
}) || t.isSequenceExpression(parent) && parent.expressions[0] === node || t.isMemberExpression(parent, {
object: 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;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.list = exports.nodes = 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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 crawl(node, state = {}) {
if (t.isMemberExpression(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)) {
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 (node.value === "use strict") {
return {
after: true
};
}
},
CallExpression(node) {
if (t.isFunction(node.callee) || isHelper(node)) {
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) {
if (parent.callProperties[0] === node && (!parent.properties || !parent.properties.length)) {
return {
before: true
};
}
};
nodes.ObjectTypeIndexer = function (node, parent) {
if (parent.indexers[0] === node && (!parent.properties || !parent.properties.length) && (!parent.callProperties || !parent.callProperties.length)) {
return {
before: true
};
}
};
nodes.ObjectTypeInternalSlot = function (node, parent) {
if (parent.internalSlots[0] === node && (!parent.properties || !parent.properties.length) && (!parent.callProperties || !parent.callProperties.length) && (!parent.indexers || !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;
};
});
});
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _isInteger = _interopRequireDefault(require("lodash/isInteger"));
var _repeat = _interopRequireDefault(require("lodash/repeat"));
var _buffer = _interopRequireDefault(require("./buffer"));
var n = _interopRequireWildcard(require("./node"));
var t = _interopRequireWildcard(require("@babel/types"));
var generatorFunctions = _interopRequireWildcard(require("./generators"));
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const SCIENTIFIC_NOTATION = /e/i;
const ZERO_DECIMAL_INTEGER = /\.0+$/;
const NON_DECIMAL_LITERAL = /^0[box]/;
class Printer {
constructor(format, map) {
this.inForStatementInitCounter = 0;
this._printStack = [];
this._indent = 0;
this._insideAux = false;
this._printedCommentStarts = {};
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 = (0, _isInteger.default)(+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;
this._parenPushNewlineState = null;
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 !== "/") return;
if (i + 1 === str.length) return;
const chaPost = str[i + 1];
if (chaPost !== "/" && chaPost !== "*") return;
}
this.token("(");
this.indent();
parenPushNewlineState.printed = true;
}
_catchUp(prop, loc) {
if (!this.format.retainLines) return;
const pos = loc ? loc[prop] : null;
if (pos && pos.line !== null) {
const count = pos.line - this._buf.getCurrentLine();
for (let i = 0; i < count; i++) {
this._newline();
}
}
}
_getIndent() {
return (0, _repeat.default)(this.format.indent.style, 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 && 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 && 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 || !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));
}
printInnerComments(node, indent = true) {
if (!node.innerComments || !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) {
if (!this.format.shouldPrintComment(comment.value)) return;
if (comment.ignore) return;
if (this._printedComments.has(comment)) return;
this._printedComments.add(comment);
if (comment.start != null) {
if (this._printedCommentStarts[comment.start]) return;
this._printedCommentStarts[comment.start] = true;
}
const isBlockComment = comment.type === "CommentBlock";
this.newline(this._buf.hasContent() && !this._noLineTerminator && isBlockComment ? 1 : 0);
if (!this.endsWith("[") && !this.endsWith("{")) this.space();
let val = !isBlockComment && !this._noLineTerminator ? `//${comment.value}\n` : `/*${comment.value}*/`;
if (isBlockComment && this.format.indent.adjustMultilineComment) {
const offset = comment.loc && 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._buf.getCurrentColumn());
val = val.replace(/\n(?!$)/g, `\n${(0, _repeat.default)(" ", indentSize)}`);
}
if (this.endsWith("/")) this._space();
this.withSource("start", comment.loc, () => {
this._append(val);
});
this.newline(isBlockComment && !this._noLineTerminator ? 1 : 0);
}
_printComments(comments) {
if (!comments || !comments.length) return;
for (const comment of comments) {
this._printComment(comment);
}
}
}
exports.default = Printer;
Object.assign(Printer.prototype, generatorFunctions);
function commaSeparator() {
this.token(",");
this.space();
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _sourceMap = _interopRequireDefault(require("source-map"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class SourceMap {
constructor(opts, code) {
this._cachedMap = null;
this._code = code;
this._opts = opts;
this._rawMappings = [];
}
get() {
if (!this._cachedMap) {
const map = this._cachedMap = new _sourceMap.default.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;
\ No newline at end of file
{
"_from": "@babel/generator@^7.7.2",
"_id": "@babel/generator@7.7.2",
"_inBundle": false,
"_integrity": "sha512-WthSArvAjYLz4TcbKOi88me+KmDJdKSlfwwN8CnUYn9jBkzhq0ZEPuBfkAWIvjJ3AdEV1Cf/+eSQTnp3IDJKlQ==",
"_location": "/@babel/generator",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/generator@^7.7.2",
"name": "@babel/generator",
"escapedName": "@babel%2fgenerator",
"scope": "@babel",
"rawSpec": "^7.7.2",
"saveSpec": null,
"fetchSpec": "^7.7.2"
},
"_requiredBy": [
"/@babel/core",
"/@babel/traverse"
],
"_resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.7.2.tgz",
"_shasum": "2f4852d04131a5e17ea4f6645488b5da66ebf3af",
"_spec": "@babel/generator@^7.7.2",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\core",
"author": {
"name": "Sebastian McKenzie",
"email": "sebmck@gmail.com"
},
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.7.2",
"jsesc": "^2.5.1",
"lodash": "^4.17.13",
"source-map": "^0.5.0"
},
"deprecated": false,
"description": "Turns an AST into code.",
"devDependencies": {
"@babel/helper-fixtures": "^7.6.3",
"@babel/parser": "^7.7.2"
},
"files": [
"lib"
],
"gitHead": "35f4d1276310bac6fede4a6f86a5c76f951e179e",
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/generator",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-generator"
},
"version": "7.7.2"
}
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.
# @babel/helper-annotate-as-pure
> Helper function to annotate paths and nodes with #__PURE__ comment
See our website [@babel/helper-annotate-as-pure](https://babeljs.io/docs/en/next/babel-helper-annotate-as-pure.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/helper-annotate-as-pure
```
or using yarn:
```sh
yarn add @babel/helper-annotate-as-pure --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = annotateAsPure;
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 PURE_ANNOTATION = "#__PURE__";
const isPureAnnotated = ({
leadingComments
}) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
function annotateAsPure(pathOrNode) {
const node = pathOrNode.node || pathOrNode;
if (isPureAnnotated(node)) {
return;
}
t.addComment(node, "leading", PURE_ANNOTATION);
}
\ No newline at end of file
{
"_from": "@babel/helper-annotate-as-pure@^7.7.0",
"_id": "@babel/helper-annotate-as-pure@7.7.0",
"_inBundle": false,
"_integrity": "sha512-k50CQxMlYTYo+GGyUGFwpxKVtxVJi9yh61sXZji3zYHccK9RYliZGSTOgci85T+r+0VFN2nWbGM04PIqwfrpMg==",
"_location": "/@babel/helper-annotate-as-pure",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-annotate-as-pure@^7.7.0",
"name": "@babel/helper-annotate-as-pure",
"escapedName": "@babel%2fhelper-annotate-as-pure",
"scope": "@babel",
"rawSpec": "^7.7.0",
"saveSpec": null,
"fetchSpec": "^7.7.0"
},
"_requiredBy": [
"/@babel/helper-remap-async-to-generator",
"/@babel/plugin-transform-classes",
"/@babel/plugin-transform-template-literals"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.7.0.tgz",
"_shasum": "efc54032d43891fe267679e63f6860aa7dbf4a5e",
"_spec": "@babel/helper-annotate-as-pure@^7.7.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\helper-remap-async-to-generator",
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.7.0"
},
"deprecated": false,
"description": "Helper function to annotate paths and nodes with #__PURE__ comment",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-annotate-as-pure",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-annotate-as-pure"
},
"version": "7.7.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.
# @babel/helper-builder-binary-assignment-operator-visitor
> Helper function to build binary assignment operator visitors
See our website [@babel/helper-builder-binary-assignment-operator-visitor](https://babeljs.io/docs/en/next/babel-helper-builder-binary-assignment-operator-visitor.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/helper-builder-binary-assignment-operator-visitor
```
or using yarn:
```sh
yarn add @babel/helper-builder-binary-assignment-operator-visitor --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _helperExplodeAssignableExpression = _interopRequireDefault(require("@babel/helper-explode-assignable-expression"));
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _default(opts) {
const {
build,
operator
} = opts;
return {
AssignmentExpression(path) {
const {
node,
scope
} = path;
if (node.operator !== operator + "=") return;
const nodes = [];
const exploded = (0, _helperExplodeAssignableExpression.default)(node.left, nodes, this, scope);
nodes.push(t.assignmentExpression("=", exploded.ref, build(exploded.uid, node.right)));
path.replaceWith(t.sequenceExpression(nodes));
},
BinaryExpression(path) {
const {
node
} = path;
if (node.operator === operator) {
path.replaceWith(build(node.left, node.right));
}
}
};
}
\ No newline at end of file
{
"_from": "@babel/helper-builder-binary-assignment-operator-visitor@^7.1.0",
"_id": "@babel/helper-builder-binary-assignment-operator-visitor@7.7.0",
"_inBundle": false,
"_integrity": "sha512-Cd8r8zs4RKDwMG/92lpZcnn5WPQ3LAMQbCw42oqUh4s7vsSN5ANUZjMel0OOnxDLq57hoDDbai+ryygYfCTOsw==",
"_location": "/@babel/helper-builder-binary-assignment-operator-visitor",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-builder-binary-assignment-operator-visitor@^7.1.0",
"name": "@babel/helper-builder-binary-assignment-operator-visitor",
"escapedName": "@babel%2fhelper-builder-binary-assignment-operator-visitor",
"scope": "@babel",
"rawSpec": "^7.1.0",
"saveSpec": null,
"fetchSpec": "^7.1.0"
},
"_requiredBy": [
"/@babel/plugin-transform-exponentiation-operator"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.7.0.tgz",
"_shasum": "32dd9551d6ed3a5fc2edc50d6912852aa18274d9",
"_spec": "@babel/helper-builder-binary-assignment-operator-visitor@^7.1.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\plugin-transform-exponentiation-operator",
"bundleDependencies": false,
"dependencies": {
"@babel/helper-explode-assignable-expression": "^7.7.0",
"@babel/types": "^7.7.0"
},
"deprecated": false,
"description": "Helper function to build binary assignment operator visitors",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-builder-binary-assignment-operator-visitor",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-binary-assignment-operator-visitor"
},
"version": "7.7.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.
# @babel/helper-call-delegate
> Helper function to call delegate
See our website [@babel/helper-call-delegate](https://babeljs.io/docs/en/next/babel-helper-call-delegate.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/helper-call-delegate
```
or using yarn:
```sh
yarn add @babel/helper-call-delegate --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _helperHoistVariables = _interopRequireDefault(require("@babel/helper-hoist-variables"));
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const visitor = {
enter(path, state) {
if (path.isThisExpression()) {
state.foundThis = true;
}
if (path.isReferencedIdentifier({
name: "arguments"
})) {
state.foundArguments = true;
}
},
Function(path) {
path.skip();
}
};
function _default(path, scope = path.scope) {
const {
node
} = path;
const container = t.functionExpression(null, [], node.body, node.generator, node.async);
let callee = container;
let args = [];
(0, _helperHoistVariables.default)(path, id => scope.push({
id
}));
const state = {
foundThis: false,
foundArguments: false
};
path.traverse(visitor, state);
if (state.foundArguments || state.foundThis) {
callee = t.memberExpression(container, t.identifier("apply"));
args = [];
if (state.foundThis) {
args.push(t.thisExpression());
}
if (state.foundArguments) {
if (!state.foundThis) args.push(t.nullLiteral());
args.push(t.identifier("arguments"));
}
}
let call = t.callExpression(callee, args);
if (node.generator) call = t.yieldExpression(call, true);
return t.returnStatement(call);
}
\ No newline at end of file
{
"_from": "@babel/helper-call-delegate@^7.4.4",
"_id": "@babel/helper-call-delegate@7.7.0",
"_inBundle": false,
"_integrity": "sha512-Su0Mdq7uSSWGZayGMMQ+z6lnL00mMCnGAbO/R0ZO9odIdB/WNU/VfQKqMQU0fdIsxQYbRjDM4BixIa93SQIpvw==",
"_location": "/@babel/helper-call-delegate",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-call-delegate@^7.4.4",
"name": "@babel/helper-call-delegate",
"escapedName": "@babel%2fhelper-call-delegate",
"scope": "@babel",
"rawSpec": "^7.4.4",
"saveSpec": null,
"fetchSpec": "^7.4.4"
},
"_requiredBy": [
"/@babel/plugin-transform-parameters"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-call-delegate/-/helper-call-delegate-7.7.0.tgz",
"_shasum": "df8942452c2c1a217335ca7e393b9afc67f668dc",
"_spec": "@babel/helper-call-delegate@^7.4.4",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\plugin-transform-parameters",
"bundleDependencies": false,
"dependencies": {
"@babel/helper-hoist-variables": "^7.7.0",
"@babel/traverse": "^7.7.0",
"@babel/types": "^7.7.0"
},
"deprecated": false,
"description": "Helper function to call delegate",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-call-delegate",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-call-delegate"
},
"version": "7.7.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.
# @babel/helper-create-class-features-plugin
> Compile class public and private fields, private methods and decorators to ES6
See our website [@babel/helper-create-class-features-plugin](https://babeljs.io/docs/en/next/babel-helper-create-class-features-plugin.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/helper-create-class-features-plugin
```
or using yarn:
```sh
yarn add @babel/helper-create-class-features-plugin --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hasOwnDecorators = hasOwnDecorators;
exports.hasDecorators = hasDecorators;
exports.buildDecoratedClass = buildDecoratedClass;
var _core = require("@babel/core");
var _helperReplaceSupers = _interopRequireDefault(require("@babel/helper-replace-supers"));
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function hasOwnDecorators(node) {
return !!(node.decorators && node.decorators.length);
}
function hasDecorators(node) {
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators);
}
function prop(key, value) {
if (!value) return null;
return _core.types.objectProperty(_core.types.identifier(key), value);
}
function method(key, body) {
return _core.types.objectMethod("method", _core.types.identifier(key), [], _core.types.blockStatement(body));
}
function takeDecorators(node) {
let result;
if (node.decorators && node.decorators.length > 0) {
result = _core.types.arrayExpression(node.decorators.map(decorator => decorator.expression));
}
node.decorators = undefined;
return result;
}
function getKey(node) {
if (node.computed) {
return node.key;
} else if (_core.types.isIdentifier(node.key)) {
return _core.types.stringLiteral(node.key.name);
} else {
return _core.types.stringLiteral(String(node.key.value));
}
}
function extractElementDescriptor(classRef, superRef, path) {
const {
node,
scope
} = path;
const isMethod = path.isClassMethod();
if (path.isPrivate()) {
throw path.buildCodeFrameError(`Private ${isMethod ? "methods" : "fields"} in decorated classes are not supported yet.`);
}
new _helperReplaceSupers.default({
methodPath: path,
methodNode: node,
objectRef: classRef,
isStatic: node.static,
superRef,
scope,
file: this
}, true).replace();
const properties = [prop("kind", _core.types.stringLiteral(isMethod ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && _core.types.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean);
if (isMethod) {
const id = node.computed ? null : node.key;
_core.types.toExpression(node);
properties.push(prop("value", (0, _helperFunctionName.default)({
node,
id,
scope
}) || node));
} else if (node.value) {
properties.push(method("value", _core.template.statements.ast`return ${node.value}`));
} else {
properties.push(prop("value", scope.buildUndefinedNode()));
}
path.remove();
return _core.types.objectExpression(properties);
}
function addDecorateHelper(file) {
try {
return file.addHelper("decorate");
} catch (err) {
if (err.code === "BABEL_HELPER_UNKNOWN") {
err.message += "\n '@babel/plugin-transform-decorators' in non-legacy mode" + " requires '@babel/core' version ^7.0.2 and you appear to be using" + " an older version.";
}
throw err;
}
}
function buildDecoratedClass(ref, path, elements, file) {
const {
node,
scope
} = path;
const initializeId = scope.generateUidIdentifier("initialize");
const isDeclaration = node.id && path.isDeclaration();
const isStrict = path.isInStrictMode();
const {
superClass
} = node;
node.type = "ClassDeclaration";
if (!node.id) node.id = _core.types.cloneNode(ref);
let superId;
if (superClass) {
superId = scope.generateUidIdentifierBasedOnNode(node.superClass, "super");
node.superClass = superId;
}
const classDecorators = takeDecorators(node);
const definitions = _core.types.arrayExpression(elements.map(extractElementDescriptor.bind(file, node.id, superId)));
let replacement = _core.template.expression.ast`
${addDecorateHelper(file)}(
${classDecorators || _core.types.nullLiteral()},
function (${initializeId}, ${superClass ? superId : null}) {
${node}
return { F: ${_core.types.cloneNode(node.id)}, d: ${definitions} };
},
${superClass}
)
`;
let classPathDesc = "arguments.1.body.body.0";
if (!isStrict) {
replacement.arguments[1].body.directives.push(_core.types.directive(_core.types.directiveLiteral("use strict")));
}
if (isDeclaration) {
replacement = _core.template.ast`let ${ref} = ${replacement}`;
classPathDesc = "declarations.0.init." + classPathDesc;
}
return {
instanceNodes: [_core.template.statement.ast`${initializeId}(this)`],
wrapClass(path) {
path.replaceWith(replacement);
return path.get(classPathDesc);
}
};
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment