1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 1 1 1 1 4 2 2 2 2 2 2 1 55 55 2 2 2 1 1 2 2 2 2 1 27 27 2 2 2 1 179 179 4 4 4 4 2 2 1 1 1 6 9 | // https://github.com/zenparsing/es-abstract-refs var util = require("../../util"); var t = require("../../types"); exports.experimental = true; var container = function (parent, call, ret) { if (t.isExpressionStatement(parent)) { // we don't need to worry about return values return call; } else { var exprs = []; Iif (t.isSequenceExpression(call)) { exprs = call.expressions; } else { exprs.push(call); } exprs.push(ret); return t.sequenceExpression(exprs); } }; exports.AssignmentExpression = function (node, parent, file, scope) { var left = node.left; if (!t.isVirtualPropertyExpression(left)) return; var value = node.right; var temp; // we need to return `node.right` if (!t.isExpressionStatement(parent)) { temp = scope.generateTempBasedOnNode(node.right, file); Iif (temp) value = temp; } Iif (node.operator !== "=") { value = t.binaryExpression( node.operator[0], util.template("abstract-expression-get", { PROPERTY: node.property, OBJECT: node.object }), value ); } var call = util.template("abstract-expression-set", { PROPERTY: left.property, OBJECT: left.object, VALUE: value }); Iif (temp) { call = t.sequenceExpression([ t.assignmentExpression("=", temp, node.right), call ]); } return container(parent, call, value); }; exports.UnaryExpression = function (node, parent) { var arg = node.argument; if (!t.isVirtualPropertyExpression(arg)) return; Iif (node.operator !== "delete") return; var call = util.template("abstract-expression-delete", { PROPERTY: arg.property, OBJECT: arg.object }); return container(parent, call, t.literal(true)); }; exports.CallExpression = function (node, parent, file, scope) { var callee = node.callee; if (!t.isVirtualPropertyExpression(callee)) return; var temp = scope.generateTempBasedOnNode(callee.object, file); var call = util.template("abstract-expression-call", { PROPERTY: callee.property, OBJECT: temp || callee.object }); call.arguments = call.arguments.concat(node.arguments); if (temp) { return t.sequenceExpression([ t.assignmentExpression("=", temp, callee.object), call ]); } else { return call; } }; exports.VirtualPropertyExpression = function (node) { return util.template("abstract-expression-get", { PROPERTY: node.property, OBJECT: node.object }); }; exports.PrivateDeclaration = function (node) { return t.variableDeclaration("const", node.declarations.map(function (id) { return t.variableDeclarator(id, t.newExpression(t.identifier("WeakMap"), [])); })); }; |