v3 new release (#84)

swap to graphql
This commit is contained in:
github-actions[bot]
2022-07-11 13:48:02 -04:00
committed by GitHub
parent 20d2b4f98d
commit e4f3964f67
1492 changed files with 63799 additions and 63001 deletions

View File

@@ -4,6 +4,16 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function SourcePos() {
return {
identifierName: undefined,
line: undefined,
column: undefined,
filename: undefined
};
}
const SPACES_RE = /^[ \t]+$/;
class Buffer {
@@ -16,12 +26,7 @@ class Buffer {
line: 1,
column: 0
};
this._sourcePosition = {
identifierName: null,
line: null,
column: null,
filename: null
};
this._sourcePosition = SourcePos();
this._disallowedPop = null;
this._map = map;
}
@@ -32,29 +37,35 @@ class Buffer {
const map = this._map;
const result = {
code: this._buf.trimRight(),
map: null,
rawMappings: map == null ? void 0 : map.getRawMappings()
decodedMap: map == null ? void 0 : map.getDecoded(),
get map() {
const resultMap = map ? map.get() : null;
result.map = resultMap;
return resultMap;
},
set map(value) {
Object.defineProperty(result, "map", {
value,
writable: true
});
},
get rawMappings() {
const mappings = map == null ? void 0 : map.getRawMappings();
result.rawMappings = mappings;
return mappings;
},
set rawMappings(value) {
Object.defineProperty(result, "rawMappings", {
value,
writable: true
});
}
};
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;
}
@@ -65,11 +76,10 @@ class Buffer {
line,
column,
filename,
identifierName,
force
identifierName
} = this._sourcePosition;
this._append(str, line, column, identifierName, filename, force);
this._append(str, line, column, identifierName, filename);
}
queue(str) {
@@ -83,11 +93,14 @@ class Buffer {
line,
column,
filename,
identifierName,
force
identifierName
} = this._sourcePosition;
this._queue.unshift([str, line, column, identifierName, filename, force]);
this._queue.unshift([str, line, column, identifierName, filename]);
}
queueIndentation(str) {
this._queue.unshift([str, undefined, undefined, undefined, undefined]);
}
_flush() {
@@ -98,14 +111,14 @@ class Buffer {
}
}
_append(str, line, column, identifierName, filename, force) {
_append(str, line, column, identifierName, filename) {
this._buf += str;
this._last = str.charCodeAt(str.length - 1);
let i = str.indexOf("\n");
let last = 0;
if (i !== 0) {
this._mark(line, column, identifierName, filename, force);
this._mark(line, column, identifierName, filename);
}
while (i !== -1) {
@@ -114,7 +127,7 @@ class Buffer {
last = i + 1;
if (last < str.length) {
this._mark(++line, 0, identifierName, filename, force);
this._mark(++line, 0, identifierName, filename);
}
i = str.indexOf("\n", last);
@@ -123,10 +136,10 @@ class Buffer {
this._position.column += str.length - last;
}
_mark(line, column, identifierName, filename, force) {
_mark(line, column, identifierName, filename) {
var _this$_map;
(_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force);
(_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position, line, column, identifierName, filename);
}
removeTrailingNewline() {
@@ -176,17 +189,17 @@ class Buffer {
}
exactSource(loc, cb) {
this.source("start", loc, true);
this.source("start", loc);
cb();
this.source("end", loc);
this._disallowPop("start", loc);
}
source(prop, loc, force) {
source(prop, loc) {
if (prop && !loc) return;
this._normalizePosition(prop, loc, this._sourcePosition, force);
this._normalizePosition(prop, loc, this._sourcePosition);
}
withSource(prop, loc, cb) {
@@ -198,46 +211,26 @@ class Buffer {
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)) {
if (!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);
this._disallowedPop = this._normalizePosition(prop, loc, SourcePos());
}
_normalizePosition(prop, loc, targetObj, force) {
_normalizePosition(prop, loc, targetObj) {
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.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || undefined;
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;
}

View File

@@ -63,7 +63,7 @@ const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
function DirectiveLiteral(node) {
const raw = this.getPossibleRaw(node);
if (!this.format.minified && raw != null) {
if (!this.format.minified && raw !== undefined) {
this.token(raw);
return;
}

View File

@@ -3,6 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ClassAccessorProperty = ClassAccessorProperty;
exports.ClassBody = ClassBody;
exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
exports.ClassMethod = ClassMethod;
@@ -20,8 +21,10 @@ const {
} = _t;
function ClassDeclaration(node, parent) {
if (!this.format.decoratorsBeforeExport || !isExportDefaultDeclaration(parent) && !isExportNamedDeclaration(parent)) {
this.printJoin(node.decorators, node);
{
if (!this.format.decoratorsBeforeExport || !isExportDefaultDeclaration(parent) && !isExportNamedDeclaration(parent)) {
this.printJoin(node.decorators, node);
}
}
if (node.declare) {
@@ -82,7 +85,45 @@ function ClassBody(node) {
function ClassProperty(node) {
this.printJoin(node.decorators, node);
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node, true);
this.tsPrintClassMemberModifiers(node);
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 ClassAccessorProperty(node) {
this.printJoin(node.decorators, node);
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node);
this.word("accessor");
this.printInnerComments(node);
this.space();
if (node.computed) {
this.token("[");
@@ -152,7 +193,7 @@ function ClassPrivateMethod(node) {
function _classMethodHead(node) {
this.printJoin(node.decorators, node);
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node, false);
this.tsPrintClassMemberModifiers(node);
this._methodHead(node);
}

View File

@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.LogicalExpression = exports.BinaryExpression = exports.AssignmentExpression = AssignmentExpression;
exports.AssignmentPattern = AssignmentPattern;
exports.AwaitExpression = void 0;
exports.AwaitExpression = AwaitExpression;
exports.BindExpression = BindExpression;
exports.CallExpression = CallExpression;
exports.ConditionalExpression = ConditionalExpression;
@@ -28,7 +28,7 @@ exports.ThisExpression = ThisExpression;
exports.UnaryExpression = UnaryExpression;
exports.UpdateExpression = UpdateExpression;
exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier;
exports.YieldExpression = void 0;
exports.YieldExpression = YieldExpression;
var _t = require("@babel/types");
@@ -74,9 +74,7 @@ function UpdateExpression(node) {
this.token(node.operator);
this.print(node.argument, node);
} else {
this.startTerminatorless(true);
this.print(node.argument, node);
this.endTerminatorless();
this.printTerminatorless(node.argument, node, true);
this.token(node.operator);
}
}
@@ -128,9 +126,45 @@ function Super() {
this.word("super");
}
function isDecoratorMemberExpression(node) {
switch (node.type) {
case "Identifier":
return true;
case "MemberExpression":
return !node.computed && node.property.type === "Identifier" && isDecoratorMemberExpression(node.object);
default:
return false;
}
}
function shouldParenthesizeDecoratorExpression(node) {
if (node.type === "CallExpression") {
node = node.callee;
}
if (node.type === "ParenthesizedExpression") {
return false;
}
return !isDecoratorMemberExpression(node);
}
function Decorator(node) {
this.token("@");
this.print(node.expression, node);
const {
expression
} = node;
if (shouldParenthesizeDecoratorExpression(expression)) {
this.token("(");
this.print(expression, node);
this.token(")");
} else {
this.print(expression, node);
}
this.newline();
}
@@ -191,27 +225,27 @@ function Import() {
this.word("import");
}
function buildYieldAwait(keyword) {
return function (node) {
this.word(keyword);
function AwaitExpression(node) {
this.word("await");
if (node.delegate) {
this.token("*");
}
if (node.argument) {
this.space();
const terminatorState = this.startTerminatorless();
this.print(node.argument, node);
this.endTerminatorless(terminatorState);
}
};
if (node.argument) {
this.space();
this.printTerminatorless(node.argument, node, false);
}
}
const YieldExpression = buildYieldAwait("yield");
exports.YieldExpression = YieldExpression;
const AwaitExpression = buildYieldAwait("await");
exports.AwaitExpression = AwaitExpression;
function YieldExpression(node) {
this.word("yield");
if (node.delegate) {
this.token("*");
}
if (node.argument) {
this.space();
this.printTerminatorless(node.argument, node, false);
}
}
function EmptyStatement() {
this.semicolon(true);

View File

@@ -219,14 +219,14 @@ function DeclareExportDeclaration(node) {
this.space();
}
FlowExportDeclaration.apply(this, arguments);
FlowExportDeclaration.call(this, node);
}
function DeclareExportAllDeclaration() {
function DeclareExportAllDeclaration(node) {
this.word("declare");
this.space();
_modules.ExportAllDeclaration.apply(this, arguments);
_modules.ExportAllDeclaration.call(this, node);
}
function EnumDeclaration(node) {

View File

@@ -67,7 +67,7 @@ function JSXSpreadChild(node) {
function JSXText(node) {
const raw = this.getPossibleRaw(node);
if (raw != null) {
if (raw !== undefined) {
this.token(raw);
} else {
this.token(node.value);

View File

@@ -42,7 +42,11 @@ function _parameters(parameters, parent) {
function _param(parameter, parent) {
this.printJoin(parameter.decorators, parameter);
this.print(parameter, parent);
if (parameter.optional) this.token("?");
if (parameter.optional) {
this.token("?");
}
this.print(parameter.typeAnnotation, parameter);
}
@@ -111,7 +115,9 @@ function _functionHead(node) {
this._params(node);
this._predicate(node);
if (node.type !== "TSDeclareFunction") {
this._predicate(node);
}
}
function FunctionExpression(node) {

View File

@@ -93,28 +93,14 @@ function ExportAllDeclaration(node) {
}
function ExportNamedDeclaration(node) {
if (this.format.decoratorsBeforeExport && isClassDeclaration(node.declaration)) {
this.printJoin(node.declaration.decorators, node);
{
if (this.format.decoratorsBeforeExport && 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 && 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);
@@ -168,41 +154,61 @@ function ExportDeclaration(node) {
}
}
function ExportDefaultDeclaration(node) {
{
if (this.format.decoratorsBeforeExport && isClassDeclaration(node.declaration)) {
this.printJoin(node.declaration.decorators, node);
}
}
this.word("export");
this.space();
this.word("default");
this.space();
const declar = node.declaration;
this.print(declar, node);
if (!isStatement(declar)) this.semicolon();
}
function ImportDeclaration(node) {
this.word("import");
this.space();
const isTypeKind = node.importKind === "type" || node.importKind === "typeof";
if (node.importKind === "type" || node.importKind === "typeof") {
if (isTypeKind) {
this.word(node.importKind);
this.space();
}
const specifiers = node.specifiers.slice(0);
const hasSpecifiers = !!specifiers.length;
if (specifiers != null && specifiers.length) {
for (;;) {
const first = specifiers[0];
while (hasSpecifiers) {
const first = specifiers[0];
if (isImportDefaultSpecifier(first) || isImportNamespaceSpecifier(first)) {
this.print(specifiers.shift(), node);
if (isImportDefaultSpecifier(first) || isImportNamespaceSpecifier(first)) {
this.print(specifiers.shift(), node);
if (specifiers.length) {
this.token(",");
this.space();
}
} else {
break;
if (specifiers.length) {
this.token(",");
this.space();
}
} else {
break;
}
}
if (specifiers.length) {
this.token("{");
this.space();
this.printList(specifiers, node);
this.space();
this.token("}");
}
if (specifiers.length) {
this.token("{");
this.space();
this.printList(specifiers, node);
this.space();
this.token("}");
} else if (isTypeKind && !hasSpecifiers) {
this.token("{");
this.token("}");
}
if (hasSpecifiers || isTypeKind) {
this.space();
this.word("from");
this.space();

View File

@@ -3,19 +3,19 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BreakStatement = void 0;
exports.BreakStatement = BreakStatement;
exports.CatchClause = CatchClause;
exports.ContinueStatement = void 0;
exports.ContinueStatement = ContinueStatement;
exports.DebuggerStatement = DebuggerStatement;
exports.DoWhileStatement = DoWhileStatement;
exports.ForOfStatement = exports.ForInStatement = void 0;
exports.ForStatement = ForStatement;
exports.IfStatement = IfStatement;
exports.LabeledStatement = LabeledStatement;
exports.ReturnStatement = void 0;
exports.ReturnStatement = ReturnStatement;
exports.SwitchCase = SwitchCase;
exports.SwitchStatement = SwitchStatement;
exports.ThrowStatement = void 0;
exports.ThrowStatement = ThrowStatement;
exports.TryStatement = TryStatement;
exports.VariableDeclaration = VariableDeclaration;
exports.VariableDeclarator = VariableDeclarator;
@@ -72,8 +72,15 @@ function IfStatement(node) {
}
function getLastStatement(statement) {
if (!isStatement(statement.body)) return statement;
return getLastStatement(statement.body);
const {
body
} = statement;
if (isStatement(body) === false) {
return statement;
}
return getLastStatement(body);
}
function ForStatement(node) {
@@ -110,30 +117,29 @@ function WhileStatement(node) {
this.printBlock(node);
}
const buildForXStatement = function (op) {
return function (node) {
this.word("for");
this.space();
function ForXStatement(node) {
this.word("for");
this.space();
const isForOf = node.type === "ForOfStatement";
if (op === "of" && node.await) {
this.word("await");
this.space();
}
this.token("(");
this.print(node.left, node);
if (isForOf && node.await) {
this.word("await");
this.space();
this.word(op);
this.space();
this.print(node.right, node);
this.token(")");
this.printBlock(node);
};
};
}
const ForInStatement = buildForXStatement("in");
this.token("(");
this.print(node.left, node);
this.space();
this.word(isForOf ? "of" : "in");
this.space();
this.print(node.right, node);
this.token(")");
this.printBlock(node);
}
const ForInStatement = ForXStatement;
exports.ForInStatement = ForInStatement;
const ForOfStatement = buildForXStatement("of");
const ForOfStatement = ForXStatement;
exports.ForOfStatement = ForOfStatement;
function DoWhileStatement(node) {
@@ -149,31 +155,34 @@ function DoWhileStatement(node) {
this.semicolon();
}
function buildLabelStatement(prefix, key = "label") {
return function (node) {
this.word(prefix);
const label = node[key];
function printStatementAfterKeyword(printer, node, parent, isLabel) {
if (node) {
printer.space();
printer.printTerminatorless(node, parent, isLabel);
}
if (label) {
this.space();
const isLabel = key == "label";
const terminatorState = this.startTerminatorless(isLabel);
this.print(label, node);
this.endTerminatorless(terminatorState);
}
this.semicolon();
};
printer.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 BreakStatement(node) {
this.word("break");
printStatementAfterKeyword(this, node.label, node, true);
}
function ContinueStatement(node) {
this.word("continue");
printStatementAfterKeyword(this, node.label, node, true);
}
function ReturnStatement(node) {
this.word("return");
printStatementAfterKeyword(this, node.argument, node, false);
}
function ThrowStatement(node) {
this.word("throw");
printStatementAfterKeyword(this, node.argument, node, false);
}
function LabeledStatement(node) {
this.print(node.label, node);

View File

@@ -213,7 +213,7 @@ function NumericLiteral(node) {
function StringLiteral(node) {
const raw = this.getPossibleRaw(node);
if (!this.format.minified && raw != null) {
if (!this.format.minified && raw !== undefined) {
this.token(raw);
return;
}
@@ -228,7 +228,7 @@ function StringLiteral(node) {
function BigIntLiteral(node) {
const raw = this.getPossibleRaw(node);
if (!this.format.minified && raw != null) {
if (!this.format.minified && raw !== undefined) {
this.word(raw);
return;
}
@@ -239,7 +239,7 @@ function BigIntLiteral(node) {
function DecimalLiteral(node) {
const raw = this.getPossibleRaw(node);
if (!this.format.minified && raw != null) {
if (!this.format.minified && raw !== undefined) {
this.word(raw);
return;
}
@@ -247,7 +247,7 @@ function DecimalLiteral(node) {
this.word(node.value + "m");
}
const validTopicTokenSet = new Set(["^", "%", "#"]);
const validTopicTokenSet = new Set(["^^", "@@", "^", "%", "#"]);
function TopicReference() {
const {

View File

@@ -25,6 +25,7 @@ exports.TSImportType = TSImportType;
exports.TSIndexSignature = TSIndexSignature;
exports.TSIndexedAccessType = TSIndexedAccessType;
exports.TSInferType = TSInferType;
exports.TSInstantiationExpression = TSInstantiationExpression;
exports.TSInterfaceBody = TSInterfaceBody;
exports.TSInterfaceDeclaration = TSInterfaceDeclaration;
exports.TSIntersectionType = TSIntersectionType;
@@ -65,13 +66,11 @@ exports.TSUndefinedKeyword = TSUndefinedKeyword;
exports.TSUnionType = TSUnionType;
exports.TSUnknownKeyword = TSUnknownKeyword;
exports.TSVoidKeyword = TSVoidKeyword;
exports.tsPrintBraced = tsPrintBraced;
exports.tsPrintClassMemberModifiers = tsPrintClassMemberModifiers;
exports.tsPrintFunctionOrConstructorType = tsPrintFunctionOrConstructorType;
exports.tsPrintPropertyOrMethodName = tsPrintPropertyOrMethodName;
exports.tsPrintSignatureDeclarationBase = tsPrintSignatureDeclarationBase;
exports.tsPrintTypeLiteralOrInterfaceBody = tsPrintTypeLiteralOrInterfaceBody;
exports.tsPrintUnionOrIntersectionType = tsPrintUnionOrIntersectionType;
function TSTypeAnnotation(node) {
this.token(":");
@@ -92,6 +91,16 @@ function TSTypeParameterInstantiation(node, parent) {
}
function TSTypeParameter(node) {
if (node.in) {
this.word("in");
this.space();
}
if (node.out) {
this.word("out");
this.space();
}
this.word(node.name);
if (node.constraint) {
@@ -352,6 +361,10 @@ function TSTypeQuery(node) {
this.word("typeof");
this.space();
this.print(node.exprName);
if (node.typeParameters) {
this.print(node.typeParameters, node);
}
}
function TSTypeLiteral(node) {
@@ -359,25 +372,25 @@ function TSTypeLiteral(node) {
}
function tsPrintTypeLiteralOrInterfaceBody(members, node) {
this.tsPrintBraced(members, node);
tsPrintBraced(this, members, node);
}
function tsPrintBraced(members, node) {
this.token("{");
function tsPrintBraced(printer, members, node) {
printer.token("{");
if (members.length) {
this.indent();
this.newline();
printer.indent();
printer.newline();
for (const member of members) {
this.print(member, node);
this.newline();
printer.print(member, node);
printer.newline();
}
this.dedent();
this.rightBrace();
printer.dedent();
printer.rightBrace();
} else {
this.token("}");
printer.token("}");
}
}
@@ -411,15 +424,15 @@ function TSNamedTupleMember(node) {
}
function TSUnionType(node) {
this.tsPrintUnionOrIntersectionType(node, "|");
tsPrintUnionOrIntersectionType(this, node, "|");
}
function TSIntersectionType(node) {
this.tsPrintUnionOrIntersectionType(node, "&");
tsPrintUnionOrIntersectionType(this, node, "&");
}
function tsPrintUnionOrIntersectionType(node, sep) {
this.printJoin(node.types, node, {
function tsPrintUnionOrIntersectionType(printer, node, sep) {
printer.printJoin(node.types, node, {
separator() {
this.space();
this.token(sep);
@@ -611,6 +624,11 @@ function TSTypeAssertion(node) {
this.print(expression, node);
}
function TSInstantiationExpression(node) {
this.print(node.expression, node);
this.print(node.typeParameters, node);
}
function TSEnumDeclaration(node) {
const {
declare,
@@ -633,7 +651,7 @@ function TSEnumDeclaration(node) {
this.space();
this.print(id, node);
this.space();
this.tsPrintBraced(members, node);
tsPrintBraced(this, members, node);
}
function TSEnumMember(node) {
@@ -689,7 +707,7 @@ function TSModuleDeclaration(node) {
}
function TSModuleBlock(node) {
this.tsPrintBraced(node.body, node);
tsPrintBraced(this, node.body, node);
}
function TSImportType(node) {
@@ -780,7 +798,9 @@ function tsPrintSignatureDeclarationBase(node) {
this.print(returnType, node);
}
function tsPrintClassMemberModifiers(node, isField) {
function tsPrintClassMemberModifiers(node) {
const isField = node.type === "ClassAccessorProperty" || node.type === "ClassProperty";
if (isField && node.declare) {
this.word("declare");
this.space();

View File

@@ -41,7 +41,6 @@ function normalizeOptions(code, opts) {
style: " ",
base: 0
},
decoratorsBeforeExport: !!opts.decoratorsBeforeExport,
jsescOption: Object.assign({
quotes: "double",
wrap: true,
@@ -51,6 +50,7 @@ function normalizeOptions(code, opts) {
topicToken: opts.topicToken
};
{
format.decoratorsBeforeExport = !!opts.decoratorsBeforeExport;
format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
}

View File

@@ -66,7 +66,7 @@ function isOrHasCallExpression(node) {
}
function needsWhitespace(node, parent, type) {
if (!node) return 0;
if (!node) return false;
if (isExpressionStatement(node)) {
node = node.expression;
@@ -86,10 +86,10 @@ function needsWhitespace(node, parent, type) {
}
if (typeof linesInfo === "object" && linesInfo !== null) {
return linesInfo[type] || 0;
return linesInfo[type] || false;
}
return 0;
return false;
}
function needsWhitespaceBefore(node, parent) {

View File

@@ -21,6 +21,7 @@ exports.OptionalCallExpression = exports.OptionalMemberExpression = OptionalMemb
exports.SequenceExpression = SequenceExpression;
exports.TSAsExpression = TSAsExpression;
exports.TSInferType = TSInferType;
exports.TSInstantiationExpression = TSInstantiationExpression;
exports.TSTypeAssertion = TSTypeAssertion;
exports.TSIntersectionType = exports.TSUnionType = TSUnionType;
exports.UnaryLike = UnaryLike;
@@ -37,8 +38,9 @@ const {
isAwaitExpression,
isBinary,
isBinaryExpression,
isUpdateExpression,
isCallExpression,
isClassDeclaration,
isClass,
isClassExpression,
isConditional,
isConditionalExpression,
@@ -49,6 +51,7 @@ const {
isForInStatement,
isForOfStatement,
isForStatement,
isFunctionExpression,
isIfStatement,
isIndexedAccessType,
isIntersectionTypeAnnotation,
@@ -64,6 +67,7 @@ const {
isSwitchStatement,
isTSArrayType,
isTSAsExpression,
isTSInstantiationExpression,
isTSIntersectionType,
isTSNonNullExpression,
isTSOptionalType,
@@ -82,6 +86,7 @@ const {
const PRECEDENCE = {
"||": 0,
"??": 0,
"|>": 0,
"&&": 1,
"|": 2,
"^": 3,
@@ -107,7 +112,9 @@ const PRECEDENCE = {
"**": 10
};
const isClassExtendsClause = (node, parent) => (isClassDeclaration(parent) || isClassExpression(parent)) && parent.superClass === node;
const isClassExtendsClause = (node, parent) => isClass(parent, {
superClass: node
});
const hasPostfixPart = (node, parent) => (isMemberExpression(parent) || isOptionalMemberExpression(parent)) && parent.object === node || (isCallExpression(parent) || isOptionalCallExpression(parent) || isNewExpression(parent)) && parent.callee === node || isTaggedTemplateExpression(parent) && parent.tag === node || isTSNonNullExpression(parent);
@@ -189,6 +196,10 @@ function TSInferType(node, parent) {
return isTSArrayType(parent) || isTSOptionalType(parent);
}
function TSInstantiationExpression(node, parent) {
return (isCallExpression(parent) || isOptionalCallExpression(parent) || isNewExpression(parent) || isTSInstantiationExpression(parent)) && !!parent.typeParameters;
}
function BinaryExpression(node, parent) {
return node.operator === "in" && (isVariableDeclarator(parent) || isFor(parent));
}
@@ -273,6 +284,14 @@ function LogicalExpression(node, parent) {
}
function Identifier(node, parent, printStack) {
var _node$extra;
if ((_node$extra = node.extra) != null && _node$extra.parenthesized && isAssignmentExpression(parent, {
left: node
}) && (isFunctionExpression(parent.right) || isClassExpression(parent.right)) && parent.right.id == null) {
return true;
}
if (node.name === "let") {
const isFollowedByBracket = isMemberExpression(parent, {
object: node,
@@ -323,7 +342,7 @@ function isFirstInContext(printStack, {
return true;
}
if (hasPostfixPart(node, parent) && !isNewExpression(parent) || isSequenceExpression(parent) && parent.expressions[0] === node || isConditional(parent, {
if (hasPostfixPart(node, parent) && !isNewExpression(parent) || isSequenceExpression(parent) && parent.expressions[0] === node || isUpdateExpression(parent) && !parent.prefix || isConditional(parent, {
test: node
}) || isBinary(parent, {
left: node

View File

@@ -199,16 +199,12 @@ const list = {
};
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(FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) {
nodes[type] = function () {
return amounts;
return {
after: amounts,
before: amounts
};
};
});
});

View File

@@ -196,7 +196,7 @@ class Printer {
_maybeIndent(str) {
if (this._indent && this.endsWith(10) && str.charCodeAt(0) !== 10) {
this._buf.queue(this._getIndent());
this._buf.queueIndentation(this._getIndent());
}
}
@@ -253,24 +253,23 @@ class Printer {
return this.format.indent.style.repeat(this._indent);
}
startTerminatorless(isLabel = false) {
printTerminatorless(node, parent, isLabel) {
if (isLabel) {
this._noLineTerminator = true;
return null;
this.print(node, parent);
this._noLineTerminator = false;
} else {
return this._parenPushNewlineState = {
const terminatorState = {
printed: false
};
}
}
this._parenPushNewlineState = terminatorState;
this.print(node, parent);
endTerminatorless(state) {
this._noLineTerminator = false;
if (state != null && state.printed) {
this.dedent();
this.newline();
this.token(")");
if (terminatorState.printed) {
this.dedent();
this.newline();
this.token(")");
}
}
}

View File

@@ -5,67 +5,51 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var _sourceMap = require("source-map");
var _genMapping = require("@jridgewell/gen-mapping");
class SourceMap {
constructor(opts, code) {
this._cachedMap = void 0;
this._code = void 0;
this._opts = void 0;
var _opts$sourceFileName;
this._map = 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 = [];
this._sourceFileName = void 0;
this._lastGenLine = 0;
this._lastSourceLine = 0;
this._lastSourceColumn = 0;
const map = this._map = new _genMapping.GenMapping({
sourceRoot: opts.sourceRoot
});
this._sourceFileName = (_opts$sourceFileName = opts.sourceFileName) == null ? void 0 : _opts$sourceFileName.replace(/\\/g, "/");
this._rawMappings = undefined;
if (typeof code === "string") {
(0, _genMapping.setSourceContent)(map, this._sourceFileName, code);
} else if (typeof code === "object") {
Object.keys(code).forEach(sourceFileName => {
(0, _genMapping.setSourceContent)(map, sourceFileName.replace(/\\/g, "/"), code[sourceFileName]);
});
}
}
get() {
if (!this._cachedMap) {
const map = this._cachedMap = new _sourceMap.SourceMapGenerator({
sourceRoot: this._opts.sourceRoot
});
const code = this._code;
return (0, _genMapping.toEncodedMap)(this._map);
}
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();
getDecoded() {
return (0, _genMapping.toDecodedMap)(this._map);
}
getRawMappings() {
return this._rawMappings.slice();
return this._rawMappings || (this._rawMappings = (0, _genMapping.allMappings)(this._map));
}
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, "/"),
mark(generated, line, column, identifierName, filename) {
this._rawMappings = undefined;
(0, _genMapping.maybeAddMapping)(this._map, {
name: identifierName,
generated,
source: line == null ? undefined : (filename == null ? void 0 : filename.replace(/\\/g, "/")) || this._sourceFileName,
original: line == null ? undefined : {
line: line,
column: column