| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.LogicalExpression = exports.AssignmentExpression = AssignmentExpression;
|
|---|
| 7 | exports.AssignmentPattern = AssignmentPattern;
|
|---|
| 8 | exports.AwaitExpression = AwaitExpression;
|
|---|
| 9 | exports.BinaryExpression = BinaryExpression;
|
|---|
| 10 | exports.BindExpression = BindExpression;
|
|---|
| 11 | exports.CallExpression = CallExpression;
|
|---|
| 12 | exports.ConditionalExpression = ConditionalExpression;
|
|---|
| 13 | exports.Decorator = Decorator;
|
|---|
| 14 | exports.DoExpression = DoExpression;
|
|---|
| 15 | exports.EmptyStatement = EmptyStatement;
|
|---|
| 16 | exports.ExpressionStatement = ExpressionStatement;
|
|---|
| 17 | exports.Import = Import;
|
|---|
| 18 | exports.MemberExpression = MemberExpression;
|
|---|
| 19 | exports.MetaProperty = MetaProperty;
|
|---|
| 20 | exports.ModuleExpression = ModuleExpression;
|
|---|
| 21 | exports.NewExpression = NewExpression;
|
|---|
| 22 | exports.OptionalCallExpression = OptionalCallExpression;
|
|---|
| 23 | exports.OptionalMemberExpression = OptionalMemberExpression;
|
|---|
| 24 | exports.ParenthesizedExpression = ParenthesizedExpression;
|
|---|
| 25 | exports.PrivateName = PrivateName;
|
|---|
| 26 | exports.SequenceExpression = SequenceExpression;
|
|---|
| 27 | exports.Super = Super;
|
|---|
| 28 | exports.ThisExpression = ThisExpression;
|
|---|
| 29 | exports.UnaryExpression = UnaryExpression;
|
|---|
| 30 | exports.UpdateExpression = UpdateExpression;
|
|---|
| 31 | exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier;
|
|---|
| 32 | exports.YieldExpression = YieldExpression;
|
|---|
| 33 | exports._shouldPrintDecoratorsBeforeExport = _shouldPrintDecoratorsBeforeExport;
|
|---|
| 34 | var _t = require("@babel/types");
|
|---|
| 35 | var _index = require("../node/index.js");
|
|---|
| 36 | const {
|
|---|
| 37 | isCallExpression,
|
|---|
| 38 | isLiteral,
|
|---|
| 39 | isMemberExpression,
|
|---|
| 40 | isNewExpression,
|
|---|
| 41 | isPattern
|
|---|
| 42 | } = _t;
|
|---|
| 43 | function UnaryExpression(node) {
|
|---|
| 44 | const {
|
|---|
| 45 | operator
|
|---|
| 46 | } = node;
|
|---|
| 47 | const firstChar = operator.charCodeAt(0);
|
|---|
| 48 | if (firstChar >= 97 && firstChar <= 122) {
|
|---|
| 49 | this.word(operator);
|
|---|
| 50 | this.space();
|
|---|
| 51 | } else {
|
|---|
| 52 | this.tokenChar(firstChar);
|
|---|
| 53 | }
|
|---|
| 54 | this.print(node.argument);
|
|---|
| 55 | }
|
|---|
| 56 | function DoExpression(node) {
|
|---|
| 57 | if (node.async) {
|
|---|
| 58 | this.word("async", true);
|
|---|
| 59 | this.space();
|
|---|
| 60 | }
|
|---|
| 61 | this.word("do");
|
|---|
| 62 | this.space();
|
|---|
| 63 | this.print(node.body);
|
|---|
| 64 | }
|
|---|
| 65 | function ParenthesizedExpression(node) {
|
|---|
| 66 | this.tokenChar(40);
|
|---|
| 67 | const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|---|
| 68 | this.print(node.expression, undefined, true);
|
|---|
| 69 | this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|---|
| 70 | this.rightParens(node);
|
|---|
| 71 | }
|
|---|
| 72 | function UpdateExpression(node) {
|
|---|
| 73 | if (node.prefix) {
|
|---|
| 74 | this.token(node.operator, false, 0, true);
|
|---|
| 75 | this.print(node.argument);
|
|---|
| 76 | } else {
|
|---|
| 77 | this.print(node.argument, true);
|
|---|
| 78 | this.token(node.operator, false, 0, true);
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | function ConditionalExpression(node) {
|
|---|
| 82 | this.print(node.test);
|
|---|
| 83 | this.space();
|
|---|
| 84 | this.tokenChar(63);
|
|---|
| 85 | this.space();
|
|---|
| 86 | this.print(node.consequent);
|
|---|
| 87 | this.space();
|
|---|
| 88 | this.tokenChar(58);
|
|---|
| 89 | this.space();
|
|---|
| 90 | this.print(node.alternate);
|
|---|
| 91 | }
|
|---|
| 92 | function NewExpression(node, parent) {
|
|---|
| 93 | this.word("new");
|
|---|
| 94 | this.space();
|
|---|
| 95 | this.print(node.callee);
|
|---|
| 96 | if (this.format.minified && node.arguments.length === 0 && !node.optional && !isCallExpression(parent, {
|
|---|
| 97 | callee: node
|
|---|
| 98 | }) && !isMemberExpression(parent) && !isNewExpression(parent)) {
|
|---|
| 99 | return;
|
|---|
| 100 | }
|
|---|
| 101 | this.print(node.typeArguments);
|
|---|
| 102 | this.print(node.typeParameters);
|
|---|
| 103 | if (node.optional) {
|
|---|
| 104 | this.token("?.");
|
|---|
| 105 | }
|
|---|
| 106 | if (node.arguments.length === 0 && this.tokenMap && !this.tokenMap.endMatches(node, ")")) {
|
|---|
| 107 | return;
|
|---|
| 108 | }
|
|---|
| 109 | this.tokenChar(40);
|
|---|
| 110 | const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|---|
| 111 | this.printList(node.arguments, this.shouldPrintTrailingComma(")"), undefined, undefined, undefined, true);
|
|---|
| 112 | this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|---|
| 113 | this.rightParens(node);
|
|---|
| 114 | }
|
|---|
| 115 | function SequenceExpression(node) {
|
|---|
| 116 | this.printList(node.expressions);
|
|---|
| 117 | }
|
|---|
| 118 | function ThisExpression() {
|
|---|
| 119 | this.word("this");
|
|---|
| 120 | }
|
|---|
| 121 | function Super() {
|
|---|
| 122 | this.word("super");
|
|---|
| 123 | }
|
|---|
| 124 | function _shouldPrintDecoratorsBeforeExport(node) {
|
|---|
| 125 | if (typeof this.format.decoratorsBeforeExport === "boolean") {
|
|---|
| 126 | return this.format.decoratorsBeforeExport;
|
|---|
| 127 | }
|
|---|
| 128 | return typeof node.start === "number" && node.start === node.declaration.start;
|
|---|
| 129 | }
|
|---|
| 130 | function Decorator(node) {
|
|---|
| 131 | this.tokenChar(64);
|
|---|
| 132 | const {
|
|---|
| 133 | expression
|
|---|
| 134 | } = node;
|
|---|
| 135 | this.print(expression);
|
|---|
| 136 | this.newline();
|
|---|
| 137 | }
|
|---|
| 138 | function OptionalMemberExpression(node) {
|
|---|
| 139 | let {
|
|---|
| 140 | computed
|
|---|
| 141 | } = node;
|
|---|
| 142 | const {
|
|---|
| 143 | optional,
|
|---|
| 144 | property
|
|---|
| 145 | } = node;
|
|---|
| 146 | this.print(node.object);
|
|---|
| 147 | if (!computed && isMemberExpression(property)) {
|
|---|
| 148 | throw new TypeError("Got a MemberExpression for MemberExpression property");
|
|---|
| 149 | }
|
|---|
| 150 | if (isLiteral(property) && typeof property.value === "number") {
|
|---|
| 151 | computed = true;
|
|---|
| 152 | }
|
|---|
| 153 | if (optional) {
|
|---|
| 154 | this.token("?.");
|
|---|
| 155 | }
|
|---|
| 156 | if (computed) {
|
|---|
| 157 | this.tokenChar(91);
|
|---|
| 158 | this.print(property);
|
|---|
| 159 | this.tokenChar(93);
|
|---|
| 160 | } else {
|
|---|
| 161 | if (!optional) {
|
|---|
| 162 | this.tokenChar(46);
|
|---|
| 163 | }
|
|---|
| 164 | this.print(property);
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 | function OptionalCallExpression(node) {
|
|---|
| 168 | this.print(node.callee);
|
|---|
| 169 | this.print(node.typeParameters);
|
|---|
| 170 | if (node.optional) {
|
|---|
| 171 | this.token("?.");
|
|---|
| 172 | }
|
|---|
| 173 | this.print(node.typeArguments);
|
|---|
| 174 | this.tokenChar(40);
|
|---|
| 175 | const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|---|
| 176 | this.printList(node.arguments, undefined, undefined, undefined, undefined, true);
|
|---|
| 177 | this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|---|
| 178 | this.rightParens(node);
|
|---|
| 179 | }
|
|---|
| 180 | function CallExpression(node) {
|
|---|
| 181 | this.print(node.callee);
|
|---|
| 182 | this.print(node.typeArguments);
|
|---|
| 183 | this.print(node.typeParameters);
|
|---|
| 184 | this.tokenChar(40);
|
|---|
| 185 | const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|---|
| 186 | this.printList(node.arguments, this.shouldPrintTrailingComma(")"), undefined, undefined, undefined, true);
|
|---|
| 187 | this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|---|
| 188 | this.rightParens(node);
|
|---|
| 189 | }
|
|---|
| 190 | function Import() {
|
|---|
| 191 | this.word("import");
|
|---|
| 192 | }
|
|---|
| 193 | function AwaitExpression(node) {
|
|---|
| 194 | this.word("await");
|
|---|
| 195 | this.space();
|
|---|
| 196 | this.print(node.argument);
|
|---|
| 197 | }
|
|---|
| 198 | function YieldExpression(node) {
|
|---|
| 199 | if (node.delegate) {
|
|---|
| 200 | this.word("yield", true);
|
|---|
| 201 | this.tokenChar(42);
|
|---|
| 202 | if (node.argument) {
|
|---|
| 203 | this.space();
|
|---|
| 204 | this.print(node.argument);
|
|---|
| 205 | }
|
|---|
| 206 | } else if (node.argument) {
|
|---|
| 207 | this.word("yield", true);
|
|---|
| 208 | this.space();
|
|---|
| 209 | this.print(node.argument);
|
|---|
| 210 | } else {
|
|---|
| 211 | this.word("yield");
|
|---|
| 212 | }
|
|---|
| 213 | }
|
|---|
| 214 | function EmptyStatement() {
|
|---|
| 215 | this.semicolon(true);
|
|---|
| 216 | }
|
|---|
| 217 | function ExpressionStatement(node) {
|
|---|
| 218 | this.tokenContext |= _index.TokenContext.expressionStatement;
|
|---|
| 219 | this.print(node.expression);
|
|---|
| 220 | this.semicolon();
|
|---|
| 221 | }
|
|---|
| 222 | function AssignmentPattern(node) {
|
|---|
| 223 | this.print(node.left);
|
|---|
| 224 | if (node.left.type === "Identifier" || isPattern(node.left)) {
|
|---|
| 225 | if (node.left.optional) this.tokenChar(63);
|
|---|
| 226 | this.print(node.left.typeAnnotation);
|
|---|
| 227 | }
|
|---|
| 228 | this.space();
|
|---|
| 229 | this.tokenChar(61);
|
|---|
| 230 | this.space();
|
|---|
| 231 | this.print(node.right);
|
|---|
| 232 | }
|
|---|
| 233 | function AssignmentExpression(node) {
|
|---|
| 234 | this.print(node.left);
|
|---|
| 235 | this.space();
|
|---|
| 236 | this.token(node.operator, false, 0, true);
|
|---|
| 237 | this.space();
|
|---|
| 238 | this.print(node.right);
|
|---|
| 239 | }
|
|---|
| 240 | function BinaryExpression(node) {
|
|---|
| 241 | this.print(node.left);
|
|---|
| 242 | this.space();
|
|---|
| 243 | const {
|
|---|
| 244 | operator
|
|---|
| 245 | } = node;
|
|---|
| 246 | if (operator.charCodeAt(0) === 105) {
|
|---|
| 247 | this.word(operator);
|
|---|
| 248 | } else {
|
|---|
| 249 | this.token(operator, false, 0, true);
|
|---|
| 250 | this.setLastChar(operator.charCodeAt(operator.length - 1));
|
|---|
| 251 | }
|
|---|
| 252 | this.space();
|
|---|
| 253 | this.print(node.right);
|
|---|
| 254 | }
|
|---|
| 255 | function BindExpression(node) {
|
|---|
| 256 | this.print(node.object);
|
|---|
| 257 | this.token("::");
|
|---|
| 258 | this.print(node.callee);
|
|---|
| 259 | }
|
|---|
| 260 | function MemberExpression(node) {
|
|---|
| 261 | this.print(node.object);
|
|---|
| 262 | if (!node.computed && isMemberExpression(node.property)) {
|
|---|
| 263 | throw new TypeError("Got a MemberExpression for MemberExpression property");
|
|---|
| 264 | }
|
|---|
| 265 | let computed = node.computed;
|
|---|
| 266 | if (isLiteral(node.property) && typeof node.property.value === "number") {
|
|---|
| 267 | computed = true;
|
|---|
| 268 | }
|
|---|
| 269 | if (computed) {
|
|---|
| 270 | const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|---|
| 271 | this.tokenChar(91);
|
|---|
| 272 | this.print(node.property, undefined, true);
|
|---|
| 273 | this.tokenChar(93);
|
|---|
| 274 | this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|---|
| 275 | } else {
|
|---|
| 276 | this.tokenChar(46);
|
|---|
| 277 | this.print(node.property);
|
|---|
| 278 | }
|
|---|
| 279 | }
|
|---|
| 280 | function MetaProperty(node) {
|
|---|
| 281 | this.print(node.meta);
|
|---|
| 282 | this.tokenChar(46);
|
|---|
| 283 | this.print(node.property);
|
|---|
| 284 | }
|
|---|
| 285 | function PrivateName(node) {
|
|---|
| 286 | this.tokenChar(35);
|
|---|
| 287 | this.print(node.id);
|
|---|
| 288 | }
|
|---|
| 289 | function V8IntrinsicIdentifier(node) {
|
|---|
| 290 | this.tokenChar(37);
|
|---|
| 291 | this.word(node.name);
|
|---|
| 292 | }
|
|---|
| 293 | function ModuleExpression(node) {
|
|---|
| 294 | this.word("module", true);
|
|---|
| 295 | this.space();
|
|---|
| 296 | this.tokenChar(123);
|
|---|
| 297 | this.indent();
|
|---|
| 298 | const {
|
|---|
| 299 | body
|
|---|
| 300 | } = node;
|
|---|
| 301 | if (body.body.length || body.directives.length) {
|
|---|
| 302 | this.newline();
|
|---|
| 303 | }
|
|---|
| 304 | this.print(body);
|
|---|
| 305 | this.dedent();
|
|---|
| 306 | this.rightBrace(node);
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | //# sourceMappingURL=expressions.js.map
|
|---|