diff options
Diffstat (limited to 'node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib')
4 files changed, 119 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/explode-assignable-expression.js b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/explode-assignable-expression.js new file mode 100644 index 00000000..649b9836 --- /dev/null +++ b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/explode-assignable-expression.js @@ -0,0 +1,75 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = explode; +var _t = require("@babel/types"); +const { + assignmentExpression, + cloneNode, + isIdentifier, + isLiteral, + isMemberExpression, + isPrivateName, + isPureish, + isSuper, + memberExpression, + toComputedKey +} = _t; +function getObjRef(node, nodes, scope) { + let ref; + if (isIdentifier(node)) { + if (scope.hasBinding(node.name)) { + return node; + } else { + ref = node; + } + } else if (isMemberExpression(node)) { + ref = node.object; + if (isSuper(ref) || isIdentifier(ref) && scope.hasBinding(ref.name)) { + return ref; + } + } else { + throw new Error(`We can't explode this node type ${node["type"]}`); + } + const temp = scope.generateUidIdentifierBasedOnNode(ref); + scope.push({ + id: temp + }); + nodes.push(assignmentExpression("=", cloneNode(temp), cloneNode(ref))); + return temp; +} +function getPropRef(node, nodes, scope) { + const prop = node.property; + if (isPrivateName(prop)) { + throw new Error("We can't generate property ref for private name, please install `@babel/plugin-transform-class-properties`"); + } + const key = toComputedKey(node, prop); + if (isLiteral(key) && isPureish(key)) return key; + const temp = scope.generateUidIdentifierBasedOnNode(prop); + scope.push({ + id: temp + }); + nodes.push(assignmentExpression("=", cloneNode(temp), cloneNode(prop))); + return temp; +} +function explode(node, nodes, scope) { + const obj = getObjRef(node, nodes, scope); + let ref, uid; + if (isIdentifier(node)) { + ref = cloneNode(node); + uid = obj; + } else { + const prop = getPropRef(node, nodes, scope); + const computed = node.computed || isLiteral(prop); + uid = memberExpression(cloneNode(obj), cloneNode(prop), computed); + ref = memberExpression(cloneNode(obj), cloneNode(prop), computed); + } + return { + uid: uid, + ref: ref + }; +} + +//# sourceMappingURL=explode-assignable-expression.js.map diff --git a/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/explode-assignable-expression.js.map b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/explode-assignable-expression.js.map new file mode 100644 index 00000000..e3d73c56 --- /dev/null +++ b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/explode-assignable-expression.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_t","require","assignmentExpression","cloneNode","isIdentifier","isLiteral","isMemberExpression","isPrivateName","isPureish","isSuper","memberExpression","toComputedKey","getObjRef","node","nodes","scope","ref","hasBinding","name","object","Error","temp","generateUidIdentifierBasedOnNode","push","id","getPropRef","prop","property","key","explode","obj","uid","computed"],"sources":["../src/explode-assignable-expression.ts"],"sourcesContent":["import type { Scope } from \"@babel/traverse\";\nimport {\n assignmentExpression,\n cloneNode,\n isIdentifier,\n isLiteral,\n isMemberExpression,\n isPrivateName,\n isPureish,\n isSuper,\n memberExpression,\n toComputedKey,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nfunction getObjRef(\n node: t.Identifier | t.MemberExpression,\n nodes: Array<t.AssignmentExpression>,\n scope: Scope,\n): t.Identifier | t.Super {\n let ref;\n if (isIdentifier(node)) {\n if (scope.hasBinding(node.name)) {\n // this variable is declared in scope so we can be 100% sure\n // that evaluating it multiple times won't trigger a getter\n // or something else\n return node;\n } else {\n // could possibly trigger a getter so we need to only evaluate\n // it once\n ref = node;\n }\n } else if (isMemberExpression(node)) {\n ref = node.object;\n\n if (isSuper(ref) || (isIdentifier(ref) && scope.hasBinding(ref.name))) {\n // the object reference that we need to save is locally declared\n // so as per the previous comment we can be 100% sure evaluating\n // it multiple times will be safe\n // Super cannot be directly assigned so lets return it also\n return ref;\n }\n } else {\n throw new Error(`We can't explode this node type ${node[\"type\"]}`);\n }\n\n const temp = scope.generateUidIdentifierBasedOnNode(ref);\n scope.push({ id: temp });\n nodes.push(assignmentExpression(\"=\", cloneNode(temp), cloneNode(ref)));\n return temp;\n}\n\nfunction getPropRef(\n node: t.MemberExpression,\n nodes: Array<t.AssignmentExpression>,\n scope: Scope,\n): t.Identifier | t.Literal {\n const prop = node.property;\n if (isPrivateName(prop)) {\n throw new Error(\n \"We can't generate property ref for private name, please install `@babel/plugin-transform-class-properties`\",\n );\n }\n const key = toComputedKey(node, prop);\n if (isLiteral(key) && isPureish(key)) return key;\n\n const temp = scope.generateUidIdentifierBasedOnNode(prop);\n scope.push({ id: temp });\n nodes.push(assignmentExpression(\"=\", cloneNode(temp), cloneNode(prop)));\n return temp;\n}\n\nexport default function explode(\n node: t.Identifier | t.MemberExpression,\n nodes: Array<t.AssignmentExpression>,\n scope: Scope,\n): {\n uid: t.Identifier | t.MemberExpression | t.Super;\n ref: t.Identifier | t.MemberExpression;\n} {\n const obj = getObjRef(node, nodes, scope);\n\n let ref, uid;\n\n if (isIdentifier(node)) {\n ref = cloneNode(node);\n uid = obj;\n } else {\n const prop = getPropRef(node, nodes, scope);\n const computed = node.computed || isLiteral(prop);\n uid = memberExpression(cloneNode(obj), cloneNode(prop), computed);\n ref = memberExpression(cloneNode(obj), cloneNode(prop), computed);\n }\n\n return {\n uid: uid,\n ref: ref,\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,EAAA,GAAAC,OAAA;AAWsB;EAVpBC,oBAAoB;EACpBC,SAAS;EACTC,YAAY;EACZC,SAAS;EACTC,kBAAkB;EAClBC,aAAa;EACbC,SAAS;EACTC,OAAO;EACPC,gBAAgB;EAChBC;AAAa,IAAAX,EAAA;AAIf,SAASY,SAASA,CAChBC,IAAuC,EACvCC,KAAoC,EACpCC,KAAY,EACY;EACxB,IAAIC,GAAG;EACP,IAAIZ,YAAY,CAACS,IAAI,CAAC,EAAE;IACtB,IAAIE,KAAK,CAACE,UAAU,CAACJ,IAAI,CAACK,IAAI,CAAC,EAAE;MAI/B,OAAOL,IAAI;IACb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AC,GAAG,EAAEC,SAAS,CAACkB,IAAI,CAAC,EAAElB,SAAS,CAACuB,IAAI,CAAC,CAAC,CAAC;EACvE,OAAOL,IAAI;AACb;AAEe,SAASQ,OAAOA,CAC7BhB,IAAuC,EACvCC,KAAoC,EACpCC,KAAY,EAIZ;EACA,MAAMe,GAAG,GAAGlB,SAAS,CAACC,IAAI,EAAEC,KAAK,EAAEC,KAAK,CAAC;EAEzC,IAAIC,GAAG,EAAEe,GAAG;EAEZ,IAAI3B,YAAY,CAACS,IAAI,CAAC,EAAE;IACtBG,GAAG,GAAGb,SAAS,CAACU,IAAI,CAAC;IACrBkB,GAAG,GAAGD,GAAG;EACX,CAAC,MAAM;IACL,MAAMJ,IAAI,GAAGD,UAAU,CAACZ,IAAI,EAAEC,KAAK,EAAEC,KAAK,CAAC;IAC3C,MAAMiB,QAAQ,GAAGnB,IAAI,CAACmB,QAAQ,IAAI3B,SAAS,CAACqB,IAAI,CAAC;IACjDK,GAAG,GAAGrB,gBAAgB,CAACP,SAAS,CAAC2B,GAAG,CAAC,EAAE3B,SAAS,CAACuB,IAAI,CAAC,EAAEM,QAAQ,CAAC;IACjEhB,GAAG,GAAGN,gBAAgB,CAACP,SAAS,CAAC2B,GAAG,CAAC,EAAE3B,SAAS,CAACuB,IAAI,CAAC,EAAEM,QAAQ,CAAC;EACnE;EAEA,OAAO;IACLD,GAAG,EAAEA,GAAG;IACRf,GAAG,EAAEA;EACP,CAAC;AACH"}
\ No newline at end of file diff --git a/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/index.js b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/index.js new file mode 100644 index 00000000..d4d28127 --- /dev/null +++ b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/index.js @@ -0,0 +1,42 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = _default; +var _t = require("@babel/types"); +var _explodeAssignableExpression = require("./explode-assignable-expression.js"); +const { + assignmentExpression, + sequenceExpression +} = _t; +function _default(opts) { + const { + build, + operator + } = opts; + const visitor = { + AssignmentExpression(path) { + const { + node, + scope + } = path; + if (node.operator !== operator + "=") return; + const nodes = []; + const exploded = (0, _explodeAssignableExpression.default)(node.left, nodes, scope); + nodes.push(assignmentExpression("=", exploded.ref, build(exploded.uid, node.right))); + path.replaceWith(sequenceExpression(nodes)); + }, + BinaryExpression(path) { + const { + node + } = path; + if (node.operator === operator) { + path.replaceWith(build(node.left, node.right)); + } + } + }; + return visitor; +} + +//# sourceMappingURL=index.js.map diff --git a/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/index.js.map b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/index.js.map new file mode 100644 index 00000000..ce29f010 --- /dev/null +++ b/node_modules/@babel/helper-builder-binary-assignment-operator-visitor/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_t","require","_explodeAssignableExpression","assignmentExpression","sequenceExpression","_default","opts","build","operator","visitor","AssignmentExpression","path","node","scope","nodes","exploded","explode","left","push","ref","uid","right","replaceWith","BinaryExpression"],"sources":["../src/index.ts"],"sourcesContent":["import { assignmentExpression, sequenceExpression } from \"@babel/types\";\nimport type { Visitor } from \"@babel/traverse\";\nimport type * as t from \"@babel/types\";\n\nimport explode from \"./explode-assignable-expression.ts\";\n\nexport default function (opts: {\n build: (\n left: t.Expression | t.PrivateName | t.Super,\n right: t.Expression,\n ) => t.Expression;\n operator: t.BinaryExpression[\"operator\"];\n}) {\n const { build, operator } = opts;\n\n const visitor: Visitor = {\n AssignmentExpression(path) {\n const { node, scope } = path;\n if (node.operator !== operator + \"=\") return;\n\n const nodes: t.AssignmentExpression[] = [];\n // @ts-expect-error Fixme: node.left can be a TSAsExpression\n const exploded = explode(node.left, nodes, scope);\n nodes.push(\n assignmentExpression(\n \"=\",\n exploded.ref,\n build(exploded.uid, node.right),\n ),\n );\n path.replaceWith(sequenceExpression(nodes));\n },\n\n BinaryExpression(path) {\n const { node } = path;\n if (node.operator === operator) {\n path.replaceWith(build(node.left, node.right));\n }\n },\n };\n return visitor;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,EAAA,GAAAC,OAAA;AAIA,IAAAC,4BAAA,GAAAD,OAAA;AAAyD;EAJhDE,oBAAoB;EAAEC;AAAkB,IAAAJ,EAAA;AAMlC,SAAAK,SAAUC,IAMxB,EAAE;EACD,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAGF,IAAI;EAEhC,MAAMG,OAAgB,GAAG;IACvBC,oBAAoBA,CAACC,IAAI,EAAE;MACzB,MAAM;QAAEC,IAAI;QAAEC;MAAM,CAAC,GAAGF,IAAI;MAC5B,IAAIC,IAAI,CAACJ,QAAQ,KAAKA,QAAQ,GAAG,GAAG,EAAE;MAEtC,MAAMM,KAA+B,GAAG,EAAE;MAE1C,MAAMC,QAAQ,GAAG,IAAAC,oCAAO,EAACJ,IAAI,CAACK,IAAI,EAAEH,KAAK,EAAED,KAAK,CAAC;MACjDC,KAAK,CAACI,IAAI,CACRf,oBAAoB,CAClB,GAAG,EACHY,QAAQ,CAACI,GAAG,EACZZ,KAAK,CAACQ,QAAQ,CAACK,GAAG,EAAER,IAAI,CAACS,KAAK,CAChC,CACF,CAAC;MACDV,IAAI,CAACW,WAAW,CAAClB,kBAAkB,CAACU,KAAK,CAAC,CAAC;IAC7C,CAAC;IAEDS,gBAAgBA,CAACZ,IAAI,EAAE;MACrB,MAAM;QAAEC;MAAK,CAAC,GAAGD,IAAI;MACrB,IAAIC,IAAI,CAACJ,QAAQ,KAAKA,QAAQ,EAAE;QAC9BG,IAAI,CAACW,WAAW,CAACf,KAAK,CAACK,IAAI,CAACK,IAAI,EAAEL,IAAI,CAACS,KAAK,CAAC,CAAC;MAChD;IACF;EACF,CAAC;EACD,OAAOZ,OAAO;AAChB"}
\ No newline at end of file |
